mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-10 15:14:16 +00:00
parent
ea6604a912
commit
b8299039e4
@ -1,3 +1,7 @@
|
|||||||
|
Version 1.1.9+svn:
|
||||||
|
* multiplayer
|
||||||
|
* scenarios can set faction, recruit, leader, and some other initial settings previously ignored in multiplayer
|
||||||
|
|
||||||
Version 1.1.9:
|
Version 1.1.9:
|
||||||
* campaigns
|
* campaigns
|
||||||
* Heir to the Throne
|
* Heir to the Throne
|
||||||
|
@ -570,6 +570,23 @@ config config::merge_with(const config& c) const
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void config::prune() {
|
||||||
|
string_map::iterator val = values.begin();
|
||||||
|
while(val != values.end()) {
|
||||||
|
if(val->second.empty()) {
|
||||||
|
values.erase(val++);
|
||||||
|
} else {
|
||||||
|
++val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(child_map::const_iterator list = children.begin(); list != children.end(); ++list) {
|
||||||
|
for(child_list::const_iterator child = list->second.begin(); child != list->second.end(); ++child) {
|
||||||
|
(*child)->prune();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void config::reset_translation() const
|
void config::reset_translation() const
|
||||||
{
|
{
|
||||||
for(string_map::const_iterator val = values.begin(); val != values.end(); ++val) {
|
for(string_map::const_iterator val = values.begin(); val != values.end(); ++val) {
|
||||||
|
@ -125,6 +125,9 @@ public:
|
|||||||
|
|
||||||
config merge_with(const config& c) const;
|
config merge_with(const config& c) const;
|
||||||
|
|
||||||
|
//removes keys with empty values
|
||||||
|
void prune();
|
||||||
|
|
||||||
//append data from another config object to this one. attributes in the
|
//append data from another config object to this one. attributes in the
|
||||||
//latter config object will clobber attributes in this one.
|
//latter config object will clobber attributes in this one.
|
||||||
void append(const config& cfg);
|
void append(const config& cfg);
|
||||||
|
@ -30,10 +30,15 @@ leader_list_manager::leader_list_manager(const config::child_list& side_list,
|
|||||||
|
|
||||||
void leader_list_manager::set_combo(gui::combo* combo)
|
void leader_list_manager::set_combo(gui::combo* combo)
|
||||||
{
|
{
|
||||||
|
int selected = combo_ != NULL ? combo_->selected() : 0;
|
||||||
combo_ = combo;
|
combo_ = combo;
|
||||||
|
|
||||||
if (combo_ != NULL) {
|
if(combo_ != NULL) {
|
||||||
update_leader_list(0);
|
if(leaders_.empty()) {
|
||||||
|
update_leader_list(0);
|
||||||
|
} else {
|
||||||
|
populate_combo(selected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +82,13 @@ void leader_list_manager::update_leader_list(int side_index)
|
|||||||
leaders_.push_back(default_leader);
|
leaders_.push_back(default_leader);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> leader_strings;
|
leaders_.push_back("random");
|
||||||
|
populate_combo(default_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void leader_list_manager::populate_combo(int selected_index) {
|
||||||
|
std::vector<std::string>::const_iterator itor;
|
||||||
|
std::vector<std::string> leader_strings;
|
||||||
for(itor = leaders_.begin(); itor != leaders_.end(); ++itor) {
|
for(itor = leaders_.begin(); itor != leaders_.end(); ++itor) {
|
||||||
|
|
||||||
const game_data::unit_type_map& utypes = data_->unit_types;
|
const game_data::unit_type_map& utypes = data_->unit_types;
|
||||||
@ -90,17 +100,17 @@ void leader_list_manager::update_leader_list(int side_index)
|
|||||||
|
|
||||||
leader_strings.push_back(IMAGE_PREFIX + image + std::string("~TC(1," + utypes.find(*itor)->second.flag_rgb() + ")") + COLUMN_SEPARATOR + name);
|
leader_strings.push_back(IMAGE_PREFIX + image + std::string("~TC(1," + utypes.find(*itor)->second.flag_rgb() + ")") + COLUMN_SEPARATOR + name);
|
||||||
} else {
|
} else {
|
||||||
leader_strings.push_back("?");
|
if(*itor == "random") {
|
||||||
|
leader_strings.push_back(IMAGE_PREFIX + random_enemy_picture + COLUMN_SEPARATOR + _("Random"));
|
||||||
|
} else {
|
||||||
|
leader_strings.push_back("?");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
leaders_.push_back("random");
|
|
||||||
leader_strings.push_back(IMAGE_PREFIX + random_enemy_picture +
|
|
||||||
COLUMN_SEPARATOR + _("Random"));
|
|
||||||
|
|
||||||
if(combo_ != NULL) {
|
if(combo_ != NULL) {
|
||||||
combo_->set_items(leader_strings);
|
combo_->set_items(leader_strings);
|
||||||
combo_->set_selected(default_index);
|
combo_->set_selected(selected_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,8 +122,10 @@ void leader_list_manager::set_leader(const std::string& leader)
|
|||||||
int leader_index = 0;
|
int leader_index = 0;
|
||||||
for(std::vector<std::string>::const_iterator itor = leaders_.begin();
|
for(std::vector<std::string>::const_iterator itor = leaders_.begin();
|
||||||
itor != leaders_.end(); ++itor) {
|
itor != leaders_.end(); ++itor) {
|
||||||
if (leader == *itor)
|
if(leader == *itor) {
|
||||||
combo_->set_selected(leader_index);
|
combo_->set_selected(leader_index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
++leader_index;
|
++leader_index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ public:
|
|||||||
bool is_leader_ok(std::string leader);
|
bool is_leader_ok(std::string leader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void populate_combo(int selected_index);
|
||||||
|
|
||||||
std::vector<std::string> leaders_;
|
std::vector<std::string> leaders_;
|
||||||
config::child_list side_list_;
|
config::child_list side_list_;
|
||||||
const game_data* data_;
|
const game_data* data_;
|
||||||
|
@ -149,6 +149,78 @@ connect::side::side(connect& parent, const config& cfg, int index) :
|
|||||||
}
|
}
|
||||||
combo_leader_.set_items(leader_name_pseudolist);
|
combo_leader_.set_items(leader_name_pseudolist);
|
||||||
combo_leader_.set_selected(0);
|
combo_leader_.set_selected(0);
|
||||||
|
} else if(parent_->params_.use_map_settings) {
|
||||||
|
//lock gold and income sliders if those are set by the scenario
|
||||||
|
if(!cfg_["gold"].empty())
|
||||||
|
slider_gold_.enable(false);
|
||||||
|
if(!cfg_["income"].empty())
|
||||||
|
slider_income_.enable(false);
|
||||||
|
if(!cfg_["team_name"].empty())
|
||||||
|
combo_team_.enable(false);
|
||||||
|
if(!cfg_["colour"].empty())
|
||||||
|
combo_colour_.enable(false);
|
||||||
|
|
||||||
|
//set the leader
|
||||||
|
leader_ = cfg_["type"];
|
||||||
|
if(!leader_.empty()) {
|
||||||
|
combo_leader_.enable(false);
|
||||||
|
llm_.set_combo(NULL);
|
||||||
|
std::vector<std::string> leader_name_pseudolist;
|
||||||
|
game_data::unit_type_map::const_iterator leader_name = parent_->game_data_.unit_types.find(leader_);
|
||||||
|
if(leader_name == parent_->game_data_.unit_types.end()) {
|
||||||
|
leader_name_pseudolist.push_back("?");
|
||||||
|
} else {
|
||||||
|
leader_name_pseudolist.push_back(leader_name->second.language_name());
|
||||||
|
}
|
||||||
|
combo_leader_.set_items(leader_name_pseudolist);
|
||||||
|
combo_leader_.set_selected(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//try to pick a faction for the sake of appearance and for filling in the blanks
|
||||||
|
if(faction_ == 0) {
|
||||||
|
std::vector<std::string> find;
|
||||||
|
std::string search_field;
|
||||||
|
if(!cfg_["faction"].empty()) {
|
||||||
|
//choose based on faction
|
||||||
|
find.push_back(cfg_["faction"]);
|
||||||
|
search_field = "id";
|
||||||
|
} else if(!cfg_["recruit"].empty()) {
|
||||||
|
//choose based on recruit
|
||||||
|
find = utils::split(cfg_["recruit"]);
|
||||||
|
search_field = "recruit";
|
||||||
|
} else if(!leader_.empty()) {
|
||||||
|
//choose based on leader
|
||||||
|
find.push_back(leader_);
|
||||||
|
search_field = "leader";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string>::const_iterator search = find.begin();
|
||||||
|
while(search != find.end()) {
|
||||||
|
int faction_index = 0;
|
||||||
|
std::vector<config*>::const_iterator faction = parent.era_sides_.begin();
|
||||||
|
while(faction_ == 0 && faction != parent.era_sides_.end()) {
|
||||||
|
const config& side = (**faction);
|
||||||
|
std::vector<std::string> recruit;
|
||||||
|
recruit = utils::split(side[search_field]);
|
||||||
|
for(itor = recruit.begin(); itor != recruit.end(); ++itor) {
|
||||||
|
if(*itor == *search) {
|
||||||
|
faction_ = faction_index;
|
||||||
|
llm_.update_leader_list(faction_);
|
||||||
|
combo_faction_.enable(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++faction;
|
||||||
|
faction_index++;
|
||||||
|
}
|
||||||
|
//exit outmost loop if we've found a faction
|
||||||
|
if(!combo_faction_.enabled()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++search;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
combo_faction_.enable(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_ui();
|
update_ui();
|
||||||
@ -170,7 +242,7 @@ connect::side::side(const side& a) :
|
|||||||
label_gold_(a.label_gold_), label_income_(a.label_income_),
|
label_gold_(a.label_gold_), label_income_(a.label_income_),
|
||||||
enabled_(a.enabled_), changed_(a.changed_), llm_(a.llm_)
|
enabled_(a.enabled_), changed_(a.changed_), llm_(a.llm_)
|
||||||
{
|
{
|
||||||
llm_.set_combo(enabled_ ? &combo_leader_ : NULL);
|
llm_.set_combo((enabled_ && leader_.empty()) ? &combo_leader_ : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void connect::side::add_widgets_to_scrollpane(gui::scrollpane& pane, int pos)
|
void connect::side::add_widgets_to_scrollpane(gui::scrollpane& pane, int pos)
|
||||||
@ -369,7 +441,7 @@ void connect::side::update_ui()
|
|||||||
|
|
||||||
config connect::side::get_config() const
|
config connect::side::get_config() const
|
||||||
{
|
{
|
||||||
config res = cfg_;
|
config res(cfg_);
|
||||||
|
|
||||||
// If the user is allowed to change type, faction, leader etc, then
|
// If the user is allowed to change type, faction, leader etc, then
|
||||||
// import their new values in the config.
|
// import their new values in the config.
|
||||||
@ -481,6 +553,17 @@ config connect::side::get_config() const
|
|||||||
res["allow_changes"] = "no";
|
res["allow_changes"] = "no";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(parent_->params_.use_map_settings && enabled_) {
|
||||||
|
config trimmed = cfg_;
|
||||||
|
trimmed["controller"] = "";
|
||||||
|
trimmed["side"] = "";
|
||||||
|
if(controller_ != CNTR_COMPUTER) {
|
||||||
|
//only override names for computer controlled players
|
||||||
|
trimmed["user_description"] = "";
|
||||||
|
}
|
||||||
|
trimmed.prune();
|
||||||
|
return res.merge_with(trimmed);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,12 +628,16 @@ void connect::side::import_network_user(const config& data)
|
|||||||
id_ = data["name"];
|
id_ = data["name"];
|
||||||
controller_ = CNTR_NETWORK;
|
controller_ = CNTR_NETWORK;
|
||||||
|
|
||||||
if (enabled_ && !parent_->era_sides_.empty()) {
|
if(enabled_ && !parent_->era_sides_.empty()) {
|
||||||
faction_ = lexical_cast_default<int>(data["faction"], 0);
|
if(combo_faction_.enabled()) {
|
||||||
if (faction_ > int(parent_->era_sides_.size()))
|
faction_ = lexical_cast_default<int>(data["faction"], 0);
|
||||||
faction_ = 0;
|
if(faction_ > int(parent_->era_sides_.size()))
|
||||||
llm_.update_leader_list(faction_);
|
faction_ = 0;
|
||||||
llm_.set_leader(data["leader"]);
|
llm_.update_leader_list(faction_);
|
||||||
|
}
|
||||||
|
if(combo_leader_.enabled()) {
|
||||||
|
llm_.set_leader(data["leader"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_ui();
|
update_ui();
|
||||||
@ -562,8 +649,10 @@ void connect::side::reset(mp::controller controller)
|
|||||||
controller_ = controller;
|
controller_ = controller;
|
||||||
|
|
||||||
if(enabled_ && !parent_->era_sides_.empty()) {
|
if(enabled_ && !parent_->era_sides_.empty()) {
|
||||||
faction_ = 0;
|
if(combo_faction_.enabled())
|
||||||
llm_.update_leader_list(0);
|
faction_ = 0;
|
||||||
|
if(combo_leader_.enabled())
|
||||||
|
llm_.update_leader_list(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
update_ui();
|
update_ui();
|
||||||
@ -1300,5 +1389,3 @@ void connect::kick_player(const std::string& name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user