mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-18 15:46:49 +00:00
All hail structured bindings
This commit is contained in:
parent
144d7667f8
commit
d84f73f4d8
@ -476,8 +476,6 @@ void connect_engine::start_game_commandline(const commandline_options& cmdline_o
|
||||
{
|
||||
DBG_MP << "starting a new game in commandline mode" << std::endl;
|
||||
|
||||
typedef std::tuple<unsigned int, std::string> mp_option;
|
||||
|
||||
randomness::mt_rng rng;
|
||||
|
||||
unsigned num = 0;
|
||||
@ -486,16 +484,16 @@ void connect_engine::start_game_commandline(const commandline_options& cmdline_o
|
||||
|
||||
// Set the faction, if commandline option is given.
|
||||
if(cmdline_opts.multiplayer_side) {
|
||||
for(const mp_option option : *cmdline_opts.multiplayer_side) {
|
||||
|
||||
if(std::get<0>(option) == num) {
|
||||
if(std::find_if(era_factions_.begin(), era_factions_.end(), [&option](const config* faction) { return (*faction)["id"] == std::get<1>(option); }) != era_factions_.end()) {
|
||||
DBG_MP << "\tsetting side " << std::get<0>(option) << "\tfaction: " << std::get<1>(option) << std::endl;
|
||||
|
||||
side->set_faction_commandline(std::get<1>(option));
|
||||
}
|
||||
else {
|
||||
ERR_MP << "failed to set side " << std::get<0>(option) << " to faction " << std::get<1>(option) << std::endl;
|
||||
for(const auto& [side_num, faction_id] : *cmdline_opts.multiplayer_side) {
|
||||
if(side_num == num) {
|
||||
if(std::find_if(era_factions_.begin(), era_factions_.end(),
|
||||
[fid = faction_id](const config* faction) { return (*faction)["id"] == fid; })
|
||||
!= era_factions_.end()
|
||||
) {
|
||||
DBG_MP << "\tsetting side " << side_num << "\tfaction: " << faction_id << std::endl;
|
||||
side->set_faction_commandline(faction_id);
|
||||
} else {
|
||||
ERR_MP << "failed to set side " << side_num << " to faction " << faction_id << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -503,13 +501,10 @@ void connect_engine::start_game_commandline(const commandline_options& cmdline_o
|
||||
|
||||
// Set the controller, if commandline option is given.
|
||||
if(cmdline_opts.multiplayer_controller) {
|
||||
for(const mp_option option : *cmdline_opts.multiplayer_controller) {
|
||||
|
||||
if(std::get<0>(option) == num) {
|
||||
DBG_MP << "\tsetting side " << std::get<0>(option) <<
|
||||
"\tfaction: " << std::get<1>(option) << std::endl;
|
||||
|
||||
side->set_controller_commandline(std::get<1>(option));
|
||||
for(const auto& [side_num, faction_id] : *cmdline_opts.multiplayer_controller) {
|
||||
if(side_num == num) {
|
||||
DBG_MP << "\tsetting side " << side_num << "\tfaction: " << faction_id << std::endl;
|
||||
side->set_controller_commandline(faction_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -518,14 +513,12 @@ void connect_engine::start_game_commandline(const commandline_options& cmdline_o
|
||||
// then override if commandline option was given.
|
||||
std::string ai_algorithm = game_config.child("ais")["default_ai_algorithm"].str();
|
||||
side->set_ai_algorithm(ai_algorithm);
|
||||
|
||||
if(cmdline_opts.multiplayer_algorithm) {
|
||||
for(const mp_option option : *cmdline_opts.multiplayer_algorithm) {
|
||||
|
||||
if(std::get<0>(option) == num) {
|
||||
DBG_MP << "\tsetting side " << std::get<0>(option) <<
|
||||
"\tfaction: " << std::get<1>(option) << std::endl;
|
||||
|
||||
side->set_ai_algorithm(std::get<1>(option));
|
||||
for(const auto& [side_num, faction_id] : *cmdline_opts.multiplayer_algorithm) {
|
||||
if(side_num == num) {
|
||||
DBG_MP << "\tsetting side " << side_num << "\tfaction: " << faction_id << std::endl;
|
||||
side->set_ai_algorithm(faction_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -544,15 +537,12 @@ void connect_engine::start_game_commandline(const commandline_options& cmdline_o
|
||||
scenario()["turns"] = *cmdline_opts.multiplayer_turns;
|
||||
}
|
||||
|
||||
for(config &side : scenario().child_range("side")) {
|
||||
for(config& side : scenario().child_range("side")) {
|
||||
if(cmdline_opts.multiplayer_ai_config) {
|
||||
for(const mp_option option : *cmdline_opts.multiplayer_ai_config) {
|
||||
|
||||
if(std::get<0>(option) == side["side"].to_unsigned()) {
|
||||
DBG_MP << "\tsetting side " << side["side"] <<
|
||||
"\tai_config: " << std::get<1>(option) << std::endl;
|
||||
|
||||
side["ai_config"] = std::get<1>(option);
|
||||
for(const auto& [side_num, faction_id] : *cmdline_opts.multiplayer_ai_config) {
|
||||
if(side_num == side["side"].to_unsigned()) {
|
||||
DBG_MP << "\tsetting side " << side["side"] << "\tai_config: " << faction_id << std::endl;
|
||||
side["ai_config"] = faction_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -566,16 +556,11 @@ void connect_engine::start_game_commandline(const commandline_options& cmdline_o
|
||||
side["income"] = 1;
|
||||
}
|
||||
|
||||
typedef std::tuple<unsigned int, std::string, std::string> mp_parameter;
|
||||
|
||||
if(cmdline_opts.multiplayer_parm) {
|
||||
for(const mp_parameter& parameter : *cmdline_opts.multiplayer_parm) {
|
||||
|
||||
if(std::get<0>(parameter) == side["side"].to_unsigned()) {
|
||||
DBG_MP << "\tsetting side " << side["side"] << " " <<
|
||||
std::get<1>(parameter) << ": " << std::get<2>(parameter) << std::endl;
|
||||
|
||||
side[std::get<1>(parameter)] = std::get<2>(parameter);
|
||||
for(const auto& [side_num, pname, pvalue] : *cmdline_opts.multiplayer_parm) {
|
||||
if(side_num == side["side"].to_unsigned()) {
|
||||
DBG_MP << "\tsetting side " << side["side"] << " " << pname << ": " << pvalue << std::endl;
|
||||
side[pname] = pvalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -766,10 +766,9 @@ void menu_handler::create_unit(mouse_handler& mousehandler)
|
||||
assert(gui_ != nullptr);
|
||||
|
||||
// Let the user select the kind of unit to create.
|
||||
type_gender_variation selection = choose_unit();
|
||||
if(std::get<0>(selection) != nullptr) {
|
||||
if(const auto& [type, gender, variation] = choose_unit(); type != nullptr) {
|
||||
// Make it so.
|
||||
create_and_place(*gui_, pc_.get_map(), pc_.get_units(), destination, *std::get<0>(selection), std::get<1>(selection), std::get<2>(selection));
|
||||
create_and_place(*gui_, pc_.get_map(), pc_.get_units(), destination, *type, gender, variation);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user