Cedric's patch which allows changing some side details mid-scenario
This commit is contained in:
parent
3a9b2600cd
commit
a41ebc7823
3 changed files with 84 additions and 0 deletions
|
@ -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<int>(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<int>(income));
|
||||
}
|
||||
|
||||
if(!gold.empty()) {
|
||||
(*teams)[team_index].spend_gold((*teams)[team_index].gold()-lexical_cast_default<int>(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<int>(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<int>(income));
|
||||
}
|
||||
|
||||
if(!gold.empty()) {
|
||||
(*teams)[team_index].spend_gold((*teams)[team_index].gold()-lexical_cast_default<int>(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<int>(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<int>(income));
|
||||
}
|
||||
|
||||
if(!gold.empty()) {
|
||||
(*teams)[team_index].spend_gold((*teams)[team_index].gold()-lexical_cast_default<int>(gold));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//command to store gold into a variable
|
||||
else if(cmd == "store_gold") {
|
||||
const std::string& side = cfg["side"];
|
||||
|
|
10
src/team.cpp
10
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<std::string>(amount);
|
||||
}
|
||||
|
||||
const std::set<std::string>& 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;
|
||||
|
|
|
@ -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<std::string>& recruits() const;
|
||||
std::set<std::string>& 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;
|
||||
|
|
Loading…
Add table
Reference in a new issue