From a41ebc7823b3435bd45af6dc0ab62413ca429089 Mon Sep 17 00:00:00 2001 From: Dave White Date: Mon, 19 Apr 2004 19:06:58 +0000 Subject: [PATCH] Cedric's patch which allows changing some side details mid-scenario --- src/game_events.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++ src/team.cpp | 10 +++++++ src/team.hpp | 2 ++ 3 files changed, 84 insertions(+) diff --git a/src/game_events.cpp b/src/game_events.cpp index 2800f2c08cd..4afa96d5013 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -374,6 +374,78 @@ bool event_handler::handle_event_command(const queued_event& event_info, const s } } + //modifications of some attributes of a side: gold, income, team name + else if(cmd == "modify_side") { + const std::string& side = cfg["side"]; + const std::string& income = cfg["income"]; + const std::string& team_name = cfg["team_name"]; + const std::string& gold = cfg["gold"]; + const int side_num = lexical_cast_default(side.c_str(),1); + const size_t team_index = side_num-1; + + if(team_index < teams->size()) { + if(!team_name.empty()) { + (*teams)[team_index].change_team(team_name); + } + + if(!income.empty()) { + (*teams)[team_index].set_income(lexical_cast_default(income)); + } + + if(!gold.empty()) { + (*teams)[team_index].spend_gold((*teams)[team_index].gold()-lexical_cast_default(gold)); + } + } + } + + //modifications of some attributes of a side: gold, income, team name + else if(cmd == "modify_side") { + const std::string& side = cfg["side"]; + const std::string& income = cfg["income"]; + const std::string& team_name = cfg["team_name"]; + const std::string& gold = cfg["gold"]; + const int side_num = lexical_cast_default(side.c_str(),1); + const size_t team_index = side_num-1; + + if(team_index < teams->size()) { + if(!team_name.empty()) { + (*teams)[team_index].change_team(team_name); + } + + if(!income.empty()) { + (*teams)[team_index].set_income(lexical_cast_default(income)); + } + + if(!gold.empty()) { + (*teams)[team_index].spend_gold((*teams)[team_index].gold()-lexical_cast_default(gold)); + } + } + } + + //modifications of some attributes of a side: gold, income, team name + else if(cmd == "modify_side") { + const std::string& side = cfg["side"]; + const std::string& income = cfg["income"]; + const std::string& team_name = cfg["team_name"]; + const std::string& gold = cfg["gold"]; + const int side_num = lexical_cast_default(side.c_str(),1); + const size_t team_index = side_num-1; + + if(team_index < teams->size()) { + if(!team_name.empty()) { + (*teams)[team_index].change_team(team_name); + } + + if(!income.empty()) { + (*teams)[team_index].set_income(lexical_cast_default(income)); + } + + if(!gold.empty()) { + (*teams)[team_index].spend_gold((*teams)[team_index].gold()-lexical_cast_default(gold)); + } + } + } + //command to store gold into a variable else if(cmd == "store_gold") { const std::string& side = cfg["side"]; diff --git a/src/team.cpp b/src/team.cpp index 09ff8a42074..1ec8a7fa644 100644 --- a/src/team.cpp +++ b/src/team.cpp @@ -340,6 +340,11 @@ void team::spend_gold(int amount) gold_ -= amount; } +void team::set_income(int amount) +{ + info_.income = lexical_cast(amount); +} + const std::set& team::recruits() const { return info_.can_recruit; @@ -415,6 +420,11 @@ const std::string& team::team_name() const return info_.team_name; } +void team::change_team(const std::string& name) +{ + info_.team_name = name; +} + const std::string& team::ai_algorithm() const { return info_.ai_algorithm; diff --git a/src/team.hpp b/src/team.hpp index 8fec60cbbd7..002a0ce2aa6 100644 --- a/src/team.hpp +++ b/src/team.hpp @@ -79,6 +79,7 @@ public: void new_turn(); void get_shared_maps(); void spend_gold(int amount); + void set_income(int amount); const std::set& recruits() const; std::set& recruits(); @@ -98,6 +99,7 @@ public: void make_ai(); const std::string& team_name() const; + void change_team(const std::string& name); const std::string& ai_algorithm() const; const config& ai_parameters() const;