From ca06378c990644704bea21869b25560c7bf58c1f Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Wed, 25 Oct 2017 05:20:10 +1100 Subject: [PATCH] Team: formatting cleanup --- src/team.cpp | 521 ++++++++++++++++++++++++++++----------------------- 1 file changed, 289 insertions(+), 232 deletions(-) diff --git a/src/team.cpp b/src/team.cpp index 896132464098f..a91914586461c 100644 --- a/src/team.cpp +++ b/src/team.cpp @@ -20,19 +20,20 @@ #include "team.hpp" #include "ai/manager.hpp" +#include "color.hpp" #include "font/text_formatting.hpp" #include "formula/string_utils.hpp" -#include "game_events/pump.hpp" #include "game_data.hpp" +#include "game_events/pump.hpp" #include "map/map.hpp" -#include "resources.hpp" #include "play_controller.hpp" #include "preferences/game.hpp" -#include "color.hpp" -#include "units/types.hpp" +#include "resources.hpp" +#include "serialization/string_utils.hpp" #include "synced_context.hpp" +#include "units/types.hpp" #include "whiteboard/side_actions.hpp" -#include "serialization/string_utils.hpp" + #include static lg::log_domain log_engine("engine"); @@ -46,7 +47,7 @@ static lg::log_domain log_engine_enemies("engine/enemies"); #define LOG_NGE LOG_STREAM(info, log_engine_enemies) #define WRN_NGE LOG_STREAM(warn, log_engine_enemies) -//static member initialization +// Static member initialization const int team::default_team_gold_ = 100; // Update this list of attributes if you change what is used to define a side @@ -115,53 +116,53 @@ const std::set team::attributes { "description" }; -team::team_info::team_info() : - gold(0), - start_gold(0), - income(0), - income_per_village(0), - support_per_village(1), - minimum_recruit_price(0), - recall_cost(0), - can_recruit(), - team_name(), - user_team_name(), - side_name(), - faction(), - faction_name(), - save_id(), - current_player(), - countdown_time(), - action_bonus_count(0), - flag(), - flag_icon(), - id(), - scroll_to_leader(true), - objectives(), - objectives_changed(false), - controller(), - is_local(true), - defeat_condition(team::DEFEAT_CONDITION::NO_LEADER), - proxy_controller(team::PROXY_CONTROLLER::PROXY_HUMAN), - share_vision(team::SHARE_VISION::ALL), - disallow_observers(false), - allow_player(false), - chose_random(false), - no_leader(true), - hidden(true), - no_turn_confirmation(false), - color(), - side(1), - persistent(false), - lost(false), - carryover_percentage(game_config::gold_carryover_percentage), - carryover_add(false), - carryover_bonus(0), - carryover_gold(0) -{ -} - -void team::team_info::read(const config &cfg) +team::team_info::team_info() + : gold(0) + , start_gold(0) + , income(0) + , income_per_village(0) + , support_per_village(1) + , minimum_recruit_price(0) + , recall_cost(0) + , can_recruit() + , team_name() + , user_team_name() + , side_name() + , faction() + , faction_name() + , save_id() + , current_player() + , countdown_time() + , action_bonus_count(0) + , flag() + , flag_icon() + , id() + , scroll_to_leader(true) + , objectives() + , objectives_changed(false) + , controller() + , is_local(true) + , defeat_condition(team::DEFEAT_CONDITION::NO_LEADER) + , proxy_controller(team::PROXY_CONTROLLER::PROXY_HUMAN) + , share_vision(team::SHARE_VISION::ALL) + , disallow_observers(false) + , allow_player(false) + , chose_random(false) + , no_leader(true) + , hidden(true) + , no_turn_confirmation(false) + , color() + , side(1) + , persistent(false) + , lost(false) + , carryover_percentage(game_config::gold_carryover_percentage) + , carryover_add(false) + , carryover_bonus(0) + , carryover_gold(0) +{ +} + +void team::team_info::read(const config& cfg) { gold = cfg["gold"]; income = cfg["income"]; @@ -202,8 +203,8 @@ void team::team_info::read(const config &cfg) color = cfg["side"].str(); } - // If arel starting new scenario override settings from [ai] tags - if (!user_team_name.translatable()) + // If starting new scenario override settings from [ai] tags + if(!user_team_name.translatable()) user_team_name = t_string::from_serialized(user_team_name); if(cfg.has_attribute("ai_config")) { @@ -217,12 +218,13 @@ void team::team_info::read(const config &cfg) // at the start of a scenario "start_gold" is not set, we need to take the // value from the gold setting (or fall back to the gold default) - if (!cfg["start_gold"].empty()) + if(!cfg["start_gold"].empty()) { start_gold = cfg["start_gold"]; - else if (!cfg["gold"].empty()) + } else if(!cfg["gold"].empty()) { start_gold = gold; - else + } else { start_gold = default_team_gold_; + } if(team_name.empty()) { team_name = cfg["side"].str(); @@ -236,44 +238,43 @@ void team::team_info::read(const config &cfg) recall_cost = cfg["recall_cost"].to_int(game_config::recall_cost); const std::string& village_support = cfg["village_support"]; - if(village_support.empty()) + if(village_support.empty()) { support_per_village = game_config::village_support; - else + } else { support_per_village = lexical_cast_default(village_support, game_config::village_support); + } controller = team::CONTROLLER::AI; controller.parse(cfg["controller"].str()); - //TODO: Why do we read disallow observers differently when controller is empty? - if (controller == CONTROLLER::EMPTY) { + // TODO: Why do we read disallow observers differently when controller is empty? + if(controller == CONTROLLER::EMPTY) { disallow_observers = cfg["disallow_observers"].to_bool(true); } - //override persistence flag if it is explicitly defined in the config - //by default, persistence of a team is set depending on the controller + + // override persistence flag if it is explicitly defined in the config + // by default, persistence of a team is set depending on the controller persistent = cfg["persistent"].to_bool(this->controller == CONTROLLER::HUMAN); //======================================================== - //END OF MESSY CODE + // END OF MESSY CODE // Share_view and share_maps can't both be enabled, // so share_view overrides share_maps. share_vision = cfg["share_vision"].to_enum(team::SHARE_VISION::ALL); handle_legacy_share_vision(cfg); - LOG_NG << "team_info::team_info(...): team_name: " << team_name - << ", share_vision: " << share_vision << ".\n"; + + LOG_NG << "team_info::team_info(...): team_name: " << team_name << ", share_vision: " << share_vision << ".\n"; } void team::team_info::handle_legacy_share_vision(const config& cfg) { - if(cfg.has_attribute("share_view") || cfg.has_attribute("share_maps")) - { + if(cfg.has_attribute("share_view") || cfg.has_attribute("share_maps")) { if(cfg["share_view"].to_bool()) { share_vision = team::SHARE_VISION::ALL; - } - else if(cfg["share_maps"].to_bool(true)) { + } else if(cfg["share_maps"].to_bool(true)) { share_vision = team::SHARE_VISION::SHROUD; - } - else { + } else { share_vision = team::SHARE_VISION::NONE; } } @@ -296,8 +297,8 @@ void team::team_info::write(config& cfg) const cfg["id"] = id; cfg["objectives"] = objectives; cfg["objectives_changed"] = objectives_changed; - cfg["countdown_time"]= countdown_time; - cfg["action_bonus_count"]= action_bonus_count; + cfg["countdown_time"] = countdown_time; + cfg["action_bonus_count"] = action_bonus_count; cfg["village_gold"] = income_per_village; cfg["village_support"] = support_per_village; cfg["recall_cost"] = recall_cost; @@ -328,22 +329,22 @@ void team::team_info::write(config& cfg) const cfg.add_child("ai", ai::manager::to_config(side)); } -team::team() : - gold_(0), - villages_(), - shroud_(), - fog_(), - fog_clearer_(), - auto_shroud_updates_(true), - info_(), - countdown_time_(0), - action_bonus_count_(0), - recall_list_(), - last_recruit_(), - enemies_(), - ally_shroud_(), - ally_fog_(), - planned_actions_() +team::team() + : gold_(0) + , villages_() + , shroud_() + , fog_() + , fog_clearer_() + , auto_shroud_updates_(true) + , info_() + , countdown_time_(0) + , action_bonus_count_(0) + , recall_list_() + , last_recruit_() + , enemies_() + , ally_shroud_() + , ally_fog_() + , planned_actions_() { } @@ -351,7 +352,7 @@ team::~team() { } -void team::build(const config &cfg, const gamemap& map, int gold) +void team::build(const config& cfg, const gamemap& map, int gold) { gold_ = gold; info_.read(cfg); @@ -362,34 +363,36 @@ void team::build(const config &cfg, const gamemap& map, int gold) shroud_.read(cfg["shroud_data"]); auto_shroud_updates_ = cfg["auto_shroud"].to_bool(auto_shroud_updates_); - LOG_NG << "team::team(...): team_name: " << info_.team_name - << ", shroud: " << uses_shroud() << ", fog: " << uses_fog() << ".\n"; + LOG_NG << "team::team(...): team_name: " << info_.team_name << ", shroud: " << uses_shroud() + << ", fog: " << uses_fog() << ".\n"; // Load the WML-cleared fog. - const config &fog_override = cfg.child("fog_override"); - if ( fog_override ) { - const std::vector fog_vector = - map.parse_location_range(fog_override["x"], fog_override["y"], true); + const config& fog_override = cfg.child("fog_override"); + if(fog_override) { + const std::vector fog_vector + = map.parse_location_range(fog_override["x"], fog_override["y"], true); fog_clearer_.insert(fog_vector.begin(), fog_vector.end()); } // To ensure some minimum starting gold, // gold is the maximum of 'gold' and what is given in the config file gold_ = std::max(gold, info_.gold); - if (gold_ != info_.gold) + if(gold_ != info_.gold) { info_.start_gold = gold; + } + // Old code was doing: // info_.start_gold = std::to_string(gold) + " (" + info_.start_gold + ")"; // Was it correct? // Load in the villages the side controls at the start - for (const config &v : cfg.child_range("village")) - { + for(const config& v : cfg.child_range("village")) { map_location loc(v); - if (map.is_village(loc)) { + if(map.is_village(loc)) { villages_.insert(loc); } else { - WRN_NG << "[side] " << current_player() << " [village] points to a non-village location " << loc << std::endl; + WRN_NG << "[side] " << current_player() << " [village] points to a non-village location " << loc + << std::endl; } } @@ -415,32 +418,36 @@ void team::write(config& cfg) const cfg["shroud_data"] = shroud_.write(); cfg["fog_data"] = fog_.write(); - if ( !fog_clearer_.empty() ) + if(!fog_clearer_.empty()) write_location_range(fog_clearer_, cfg.add_child("fog_override")); cfg["countdown_time"] = countdown_time_; cfg["action_bonus_count"] = action_bonus_count_; } -game_events::pump_result_t team::get_village(const map_location& loc, const int owner_side, game_data * gamedata) +game_events::pump_result_t team::get_village(const map_location& loc, const int owner_side, game_data* gamedata) { villages_.insert(loc); game_events::pump_result_t res; + if(gamedata) { config::attribute_value& var = gamedata->get_variable("owner_side"); const config::attribute_value old_value = var; var = owner_side; - // During team building, game_events pump is not guaranteed to exist yet. (At current revision.) We skip capture events in this case. - if (resources::game_events) { + // During team building, game_events pump is not guaranteed to exist yet. (At current revision.) We skip capture + // events in this case. + if(resources::game_events) { res = resources::game_events->pump().fire("capture", loc); } - if(old_value.blank()) + if(old_value.blank()) { gamedata->clear_variable("owner_side"); - else + } else { var = old_value; + } } + return res; } @@ -458,7 +465,7 @@ void team::set_recruits(const std::set& recruits) ai::manager::raise_recruit_list_changed(); } -void team::add_recruit(const std::string &recruit) +void team::add_recruit(const std::string& recruit) { info_.can_recruit.insert(recruit); info_.minimum_recruit_price = 0; @@ -467,22 +474,23 @@ void team::add_recruit(const std::string &recruit) int team::minimum_recruit_price() const { - if(info_.minimum_recruit_price){ + if(info_.minimum_recruit_price) { return info_.minimum_recruit_price; - }else{ - int min = 20; - for(std::string recruit : info_.can_recruit) { - const unit_type *ut = unit_types.find(recruit); - if(!ut) - continue; - else{ - if(ut->cost() < min) - min = ut->cost(); + } + int min = 20; + for(std::string recruit : info_.can_recruit) { + const unit_type* ut = unit_types.find(recruit); + if(!ut) { + continue; + } else { + if(ut->cost() < min) { + min = ut->cost(); } - } - info_.minimum_recruit_price = min; } + + info_.minimum_recruit_price = min; + return info_.minimum_recruit_price; } @@ -505,56 +513,63 @@ bool team::calculate_is_enemy(size_t index) const } // We are friends with anyone who we share a teamname with - std::vector our_teams = utils::split(info_.team_name), - their_teams = utils::split(resources::gameboard->teams()[index].info_.team_name); + std::vector our_teams = utils::split(info_.team_name); + std::vector their_teams = utils::split(resources::gameboard->teams()[index].info_.team_name); + + LOG_NGE << "team " << info_.side << " calculates if it has enemy in team " << index + 1 << "; our team_name [" + << info_.team_name << "], their team_name is [" << resources::gameboard->teams()[index].info_.team_name + << "]" << std::endl; - LOG_NGE << "team " << info_.side << " calculates if it has enemy in team "<teams()[index].info_.team_name<<"]"<< std::endl; for(std::vector::const_iterator t = our_teams.begin(); t != our_teams.end(); ++t) { - if(std::find(their_teams.begin(), their_teams.end(), *t) != their_teams.end()) - { - LOG_NGE << "team " << info_.side << " found same team name [" << *t << "] in team "<< index+1 << std::endl; + if(std::find(their_teams.begin(), their_teams.end(), *t) != their_teams.end()) { + LOG_NGE << "team " << info_.side << " found same team name [" << *t << "] in team " << index + 1 + << std::endl; return false; } else { - LOG_NGE << "team " << info_.side << " not found same team name [" << *t << "] in team "<< index+1 << std::endl; + LOG_NGE << "team " << info_.side << " not found same team name [" << *t << "] in team " << index + 1 + << std::endl; } } - LOG_NGE << "team " << info_.side << " has enemy in team " << index+1 << std::endl; + + LOG_NGE << "team " << info_.side << " has enemy in team " << index + 1 << std::endl; return true; } namespace { - class controller_server_choice : public synced_context::server_choice +class controller_server_choice : public synced_context::server_choice +{ +public: + controller_server_choice(team::CONTROLLER new_controller, const team& team) + : new_controller_(new_controller) + , team_(team) { - public: - controller_server_choice(team::CONTROLLER new_controller, const team& team) - : new_controller_(new_controller) - , team_(team) - { - } - /// We are in a game with no mp server and need to do this choice locally - virtual config local_choice() const - { - return config {"controller", new_controller_, "is_local", true}; - } - /// the request which is sended to the mp server. - virtual config request() const - { - return config { - "new_controller", new_controller_, - "old_controller", team_.controller(), - "side", team_.side(), - }; - } - virtual const char* name() const - { - return "change_controller_wml"; - } - private: - team::CONTROLLER new_controller_; - const team& team_; - }; -} + } + + /// We are in a game with no mp server and need to do this choice locally + virtual config local_choice() const + { + return config{"controller", new_controller_, "is_local", true}; + } + + /// tThe request which is sent to the mp server. + virtual config request() const + { + return config{ + "new_controller", new_controller_, "old_controller", team_.controller(), "side", team_.side(), + }; + } + + virtual const char* name() const + { + return "change_controller_wml"; + } + +private: + team::CONTROLLER new_controller_; + const team& team_; +}; +} // end anon namespace void team::change_controller_by_wml(const std::string& new_controller_string) { @@ -563,38 +578,41 @@ void team::change_controller_by_wml(const std::string& new_controller_string) WRN_NG << "ignored attempt to change controller to " << new_controller_string << std::endl; return; } + if(new_controller == CONTROLLER::EMPTY && resources::controller->current_side() == this->side()) { WRN_NG << "ignored attempt to change the currently playing side's controller to 'null'" << std::endl; return; } + config choice = synced_context::ask_server_choice(controller_server_choice(new_controller, *this)); if(!new_controller.parse(choice["controller"])) { - //TODO: this should be more than a ERR_NG message. + // TODO: this should be more than a ERR_NG message. // GL-2016SEP02 Oh? So why was ERR_NG defined as warning level? Making the call fit the definition. - WRN_NG << "recieved an invalid controller string from the server" << choice["controller"] << std::endl; + WRN_NG << "Received an invalid controller string from the server" << choice["controller"] << std::endl; } + if(!resources::controller->is_replay()) { set_local(choice["is_local"].to_bool()); } + change_controller(new_controller); } -void team::change_team(const std::string &name, const t_string &user_name) +void team::change_team(const std::string& name, const t_string& user_name) { info_.team_name = name; - if (!user_name.empty()) - { + + if(!user_name.empty()) { info_.user_team_name = user_name; - } - else - { + } else { info_.user_team_name = name; } clear_caches(); } -void team::clear_caches(){ +void team::clear_caches() +{ // Reset the cache of allies for all teams if(resources::gameboard) { for(auto& t : resources::gameboard->teams()) { @@ -608,30 +626,37 @@ void team::clear_caches(){ void team::set_objectives(const t_string& new_objectives, bool silently) { info_.objectives = new_objectives; - if(!silently) + + if(!silently) { info_.objectives_changed = true; + } } bool team::shrouded(const map_location& loc) const { - if(!resources::gameboard) - return shroud_.value(loc.wml_x(),loc.wml_y()); + if(!resources::gameboard) { + return shroud_.value(loc.wml_x(), loc.wml_y()); + } - return shroud_.shared_value(ally_shroud(resources::gameboard->teams()),loc.wml_x(),loc.wml_y()); + return shroud_.shared_value(ally_shroud(resources::gameboard->teams()), loc.wml_x(), loc.wml_y()); } bool team::fogged(const map_location& loc) const { - if(shrouded(loc)) return true; + if(shrouded(loc)) { + return true; + } // Check for an override of fog. - if ( fog_clearer_.count(loc) > 0 ) + if(fog_clearer_.count(loc) > 0) { return false; + } - if(!resources::gameboard) - return fog_.value(loc.wml_x(),loc.wml_y()); + if(!resources::gameboard) { + return fog_.value(loc.wml_x(), loc.wml_y()); + } - return fog_.shared_value(ally_fog(resources::gameboard->teams()),loc.wml_x(),loc.wml_y()); + return fog_.shared_value(ally_fog(resources::gameboard->teams()), loc.wml_x(), loc.wml_y()); } const std::vector& team::ally_shroud(const std::vector& teams) const @@ -665,22 +690,34 @@ bool team::knows_about_team(size_t index) const const team& t = resources::gameboard->teams()[index]; // We know about our own team - if(this == &t) return true; + if(this == &t) { + return true; + } // If we aren't using shroud or fog, then we know about everyone - if(!uses_shroud() && !uses_fog()) return true; + if(!uses_shroud() && !uses_fog()) { + return true; + } // We don't know about enemies - if(is_enemy(index+1)) return false; + if(is_enemy(index + 1)) { + return false; + } // We know our human allies. - if (t.is_human()) return true; + if(t.is_human()) { + return true; + } // We know about allies we're sharing maps with - if(share_maps() && t.uses_shroud()) return true; + if(share_maps() && t.uses_shroud()) { + return true; + } // We know about allies we're sharing view with - if(share_view() && (t.uses_fog() || t.uses_shroud())) return true; + if(share_view() && (t.uses_fog() || t.uses_shroud())) { + return true; + } return false; } @@ -689,13 +726,12 @@ bool team::knows_about_team(size_t index) const * Removes the record of hexes that were cleared of fog via WML. * @param[in] hexes The hexes to no longer keep clear. */ -void team::remove_fog_override(const std::set &hexes) +void team::remove_fog_override(const std::set& hexes) { // Take a set difference. std::vector result(fog_clearer_.size()); std::vector::iterator result_end = - std::set_difference(fog_clearer_.begin(), fog_clearer_.end(), - hexes.begin(), hexes.end(), result.begin()); + std::set_difference(fog_clearer_.begin(), fog_clearer_.end(), hexes.begin(), hexes.end(), result.begin()); // Put the result into fog_clearer_. fog_clearer_.clear(); @@ -715,34 +751,38 @@ void validate_side(int side) bool team::shroud_map::clear(int x, int y) { - if(enabled_ == false || x < 0 || y < 0) + if(enabled_ == false || x < 0 || y < 0) { return false; + } - if(x >= static_cast(data_.size())) - data_.resize(x+1); + if(x >= static_cast(data_.size())) { + data_.resize(x + 1); + } - if(y >= static_cast(data_[x].size())) - data_[x].resize(y+1); + if(y >= static_cast(data_[x].size())) { + data_[x].resize(y + 1); + } if(data_[x][y] == false) { data_[x][y] = true; return true; - } else { - return false; } + + return false; } void team::shroud_map::place(int x, int y) { - if(enabled_ == false || x < 0 || y < 0) + if(enabled_ == false || x < 0 || y < 0) { return; + } - if (x >= static_cast(data_.size())) { - DBG_NG << "Couldn't place shroud on invalid x coordinate: (" - << x << ", " << y << ") - max x: " << data_.size() - 1 << "\n"; - } else if (y >= static_cast(data_[x].size())) { - DBG_NG << "Couldn't place shroud on invalid y coordinate: (" - << x << ", " << y << ") - max y: " << data_[x].size() - 1 << "\n"; + if(x >= static_cast(data_.size())) { + DBG_NG << "Couldn't place shroud on invalid x coordinate: (" << x << ", " << y + << ") - max x: " << data_.size() - 1 << "\n"; + } else if(y >= static_cast(data_[x].size())) { + DBG_NG << "Couldn't place shroud on invalid y coordinate: (" << x << ", " << y + << ") - max y: " << data_[x].size() - 1 << "\n"; } else { data_[x][y] = false; } @@ -750,24 +790,29 @@ void team::shroud_map::place(int x, int y) void team::shroud_map::reset() { - if(enabled_ == false) + if(enabled_ == false) { return; + } - for(std::vector >::iterator i = data_.begin(); i != data_.end(); ++i) { - std::fill(i->begin(),i->end(),false); + for(std::vector>::iterator i = data_.begin(); i != data_.end(); ++i) { + std::fill(i->begin(), i->end(), false); } } bool team::shroud_map::value(int x, int y) const { - if ( !enabled_ ) + if(!enabled_) { return false; + } // Locations for which we have no data are assumed to still be covered. - if ( x < 0 || x >= static_cast(data_.size()) ) + if(x < 0 || x >= static_cast(data_.size())) { return true; - if ( y < 0 || y >= static_cast(data_[x].size()) ) + } + + if(y < 0 || y >= static_cast(data_[x].size())) { return true; + } // data_ stores whether or not a location has been cleared, while // we want to return whether or not a location is covered. @@ -776,25 +821,29 @@ bool team::shroud_map::value(int x, int y) const bool team::shroud_map::shared_value(const std::vector& maps, int x, int y) const { - if ( !enabled_ ) + if(!enabled_) { return false; + } // A quick abort: - if ( x < 0 || y < 0 ) + if(x < 0 || y < 0) { return true; + } // A tile is uncovered if it is uncovered on any shared map. - for (const shroud_map * const shared_map : maps) { - if ( shared_map->enabled_ && !shared_map->value(x,y) ) + for(const shroud_map* const shared_map : maps) { + if(shared_map->enabled_ && !shared_map->value(x, y)) { return false; + } } + return true; } std::string team::shroud_map::write() const { std::stringstream shroud_str; - for(std::vector >::const_iterator sh = data_.begin(); sh != data_.end(); ++sh) { + for(std::vector>::const_iterator sh = data_.begin(); sh != data_.end(); ++sh) { shroud_str << '|'; for(std::vector::const_iterator i = sh->begin(); i != sh->end(); ++i) { @@ -810,28 +859,31 @@ std::string team::shroud_map::write() const void team::shroud_map::read(const std::string& str) { data_.clear(); + for(std::string::const_iterator sh = str.begin(); sh != str.end(); ++sh) { - if(*sh == '|') - data_.resize(data_.size()+1); + if(*sh == '|') { + data_.resize(data_.size() + 1); + } if(data_.empty() == false) { - if(*sh == '1') + if(*sh == '1') { data_.back().push_back(true); - else if(*sh == '0') + } else if(*sh == '0') { data_.back().push_back(false); + } } } } void team::shroud_map::merge(const std::string& str) { - int x=0, y=0; + int x = 0, y = 0; for(std::string::const_iterator sh = str.begin(); sh != str.end(); ++sh) { if(*sh == '|' && sh != str.begin()) { - y=0; + y = 0; x++; } else if(*sh == '1') { - clear(x,y); + clear(x, y); y++; } else if(*sh == '0') { y++; @@ -841,33 +893,36 @@ void team::shroud_map::merge(const std::string& str) bool team::shroud_map::copy_from(const std::vector& maps) { - if(enabled_ == false) + if(enabled_ == false) { return false; + } bool cleared = false; for(std::vector::const_iterator i = maps.begin(); i != maps.end(); ++i) { - if((*i)->enabled_ == false) + if((*i)->enabled_ == false) { continue; + } - const std::vector >& v = (*i)->data_; + const std::vector>& v = (*i)->data_; for(size_t x = 0; x != v.size(); ++x) { for(size_t y = 0; y != v[x].size(); ++y) { if(v[x][y]) { - cleared |= clear(x,y); + cleared |= clear(x, y); } } } } + return cleared; } const color_range team::get_side_color_range(int side) { std::string index = get_side_color_index(side); - std::map::iterator gp=game_config::team_rgb_range.find(index); + std::map::iterator gp = game_config::team_rgb_range.find(index); - if(gp != game_config::team_rgb_range.end()){ - return(gp->second); + if(gp != game_config::team_rgb_range.end()) { + return (gp->second); } return color_range({255, 0, 0}, {255, 255, 255}, {0, 0, 0}, {255, 0, 0}); @@ -887,7 +942,7 @@ color_t team::get_minimap_color(int side) std::string team::get_side_color_index(int side) { - size_t index = size_t(side-1); + size_t index = size_t(side - 1); if(resources::gameboard && index < resources::gameboard->teams().size()) { const std::string side_map = resources::gameboard->teams()[index].color(); @@ -895,6 +950,7 @@ std::string team::get_side_color_index(int side) return side_map; } } + return std::to_string(side); } @@ -903,12 +959,13 @@ std::string team::get_side_highlight_pango(int side) return get_side_color_range(side + 1).mid().to_hex_string(); } -void team::log_recruitable() const { +void team::log_recruitable() const +{ LOG_NG << "Adding recruitable units: \n"; - for (std::set::const_iterator it = info_.can_recruit.begin(); - it != info_.can_recruit.end(); ++it) { + for(std::set::const_iterator it = info_.can_recruit.begin(); it != info_.can_recruit.end(); ++it) { LOG_NG << *it << std::endl; } + LOG_NG << "Added all recruitable units\n"; } @@ -923,11 +980,11 @@ config team::to_config() const std::string team::allied_human_teams() const { std::vector res; - for(const team& t : resources::gameboard->teams()) - { + for(const team& t : resources::gameboard->teams()) { if(!t.is_enemy(this->side()) && t.is_human()) { res.push_back(t.side()); } } + return utils::join(res); }