Extended [modify_side] tag to contemplate latest changes to [store_side].

This commit is contained in:
Ignacio R. Morelle 2007-11-05 11:18:29 +00:00
parent edfb8fa7b4
commit 47c8073e4b
3 changed files with 51 additions and 5 deletions

View File

@ -698,31 +698,55 @@ bool event_handler::handle_event_command(const queued_event& event_info,
// Modifications of some attributes of a side: gold, income, team name
else if(cmd == "modify_side") {
LOG_NG << "modifying side...\n";
std::string side = cfg["side"];
std::string income = cfg["income"];
std::string name = cfg["name"];
std::string team_name = cfg["team_name"];
std::string user_team_name = cfg["user_team_name"];
std::string gold = cfg["gold"];
std::string controller = cfg["controller"];
// TODO? std::string recruit = cfg["recruit"];
// I don't know if we should implement the [set_recruit] behavior here
std::string fog = cfg["fog"];
std::string shroud = cfg["shroud"];
std::string village_gold = cfg["village_gold"];
// TODO? std::string colour = cfg["colour"];
wassert(state_of_game != NULL);
const int side_num = lexical_cast_default<int>(side,1);
const size_t team_index = side_num-1;
if(team_index < teams->size()) {
LOG_NG << "modifying team: " << side_num << "\n";
LOG_NG << "modifying side: " << side_num << "\n";
if(!team_name.empty()) {
LOG_NG << "change team to team_name '" << team_name << "'\n";
LOG_NG << "change side's team to team_name '" << team_name << "'\n";
(*teams)[team_index].change_team(team_name,
user_team_name);
}
// Modify income
if(!income.empty()) {
(*teams)[team_index].set_income(lexical_cast_default<int>(income));
}
// Modify total gold
if(!gold.empty()) {
(*teams)[team_index].spend_gold((*teams)[team_index].gold()-lexical_cast_default<int>(gold));
}
// Set controller
if(!controller.empty()) {
(*teams)[team_index].change_controller(controller);
}
// Set shroud
if (!shroud.empty()) {
(*teams)[team_index].set_shroud( utils::string_bool(shroud, true) );
}
// Set fog
if (!fog.empty()) {
(*teams)[team_index].set_fog( utils::string_bool(fog, true) );
}
// Set income per village
if (!village_gold.empty()) {
(*teams)[team_index].set_village_gold(lexical_cast_default<int>(village_gold));
}
}
}
// Stores of some attributes of a side: gold, income, team name

View File

@ -485,6 +485,21 @@ bool team::calculate_is_enemy(size_t index) const
return std::find(info_.enemies.begin(),info_.enemies.end(),int(index+1)) != info_.enemies.end();
}
void team::change_controller(const std::string& controller)
{
team::team_info::CONTROLLER cid;
if (controller == "human")
cid = team::team_info::HUMAN;
else if (controller == "network")
cid = team::team_info::NETWORK;
else if (controller == "null")
cid = team::team_info::EMPTY;
else
cid = team::team_info::AI;
info_.controller = cid;
}
void team::change_team(const std::string& name, const std::string& user_name)
{
info_.team_name = name;

View File

@ -135,6 +135,7 @@ public:
int base_income() const
{ return atoi(info_.income.c_str()) + game_config::base_income; }
int village_gold() const { return info_.income_per_village; }
void set_village_gold(int income) { info_.income_per_village = income; }
int income() const
{ return atoi(info_.income.c_str()) + villages_.size()*info_.income_per_village+game_config::base_income; }
void new_turn() { gold_ += income(); }
@ -205,6 +206,10 @@ public:
void make_human() { info_.controller = team_info::HUMAN; }
void make_network() { info_.controller = team_info::NETWORK; }
void make_ai() { info_.controller = team_info::AI; }
// Should make the above make_*() functions obsolete, as it accepts controller
// by lexical or numerical id
void change_controller(team_info::CONTROLLER controller) { info_.controller = controller; }
void change_controller(const std::string& controller);
const std::string& team_name() const { return info_.team_name; }
const std::string& user_team_name() const { return info_.user_team_name; }
@ -220,7 +225,9 @@ public:
void set_ai_memory(const config& ai_mem);
double leader_value() const { return info_.leader_value; }
void set_leader_value(double value) { info_.leader_value = value; }
double village_value() const { return info_.village_value; }
void set_village_value(double value) { info_.village_value = value; }
int villages_per_scout() const { return info_.villages_per_scout; }