Skip to content

Commit

Permalink
replace fight_on_without_leader with defeat_condition
Browse files Browse the repository at this point in the history
[side] now has an attribute defeat_condition which can be "no_leader"(default), "no_units" or "never"
"no_leader" behaves liek it behaved before.
"no_units" behaves like fight_on_without_leader=yes behaved before
"never" is new and causes the side to never get defeated, this usually means the scenariodesigner has to end the scenario with [endlevel]

Conflicts:
	src/play_controller.cpp
	src/team.cpp
  • Loading branch information
gfgtdf committed May 22, 2014
1 parent 31e140d commit aabeae6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
26 changes: 15 additions & 11 deletions src/play_controller.cpp
Expand Up @@ -1390,25 +1390,29 @@ void play_controller::check_victory()
if (i->can_recruit()) {
DBG_NG << "seen leader for side " << i->side() << "\n";
not_defeated.insert(i->side());
} else if (teams_[i->side()-1].fight_on_without_leader()) {
} else if (teams_[i->side()-1].defeat_condition() == team::NO_UNITS) {
DBG_NG << "side doesn't require leader " << i->side() << "\n";
not_defeated.insert(i->side());
}
}

// Clear villages for teams that have no leader and
// mark side as lost if it should be removed from carryover.
for (std::vector<team>::iterator tm_beg = teams_.begin(), tm = tm_beg,
tm_end = teams_.end(); tm != tm_end; ++tm)
BOOST_FOREACH(team& tm, this->teams_)
{
if (not_defeated.find(tm - tm_beg + 1) == not_defeated.end()) {
tm->clear_villages();
if(tm.defeat_condition() == team::NEVER)
{
not_defeated.insert(tm.side());
}
// Clear villages for teams that have no leader and
// mark side as lost if it should be removed from carryover.
if (not_defeated.find(tm.side()) == not_defeated.end())
{
tm.clear_villages();
// invalidate_all() is overkill and expensive but this code is
// run rarely so do it the expensive way.
gui_->invalidate_all();

if (!tm->fight_on_without_leader() && remove_from_carryover_on_leaders_loss_) {
tm->set_lost();

if (remove_from_carryover_on_leaders_loss_)
{
tm.set_lost();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/scripting/lua.cpp
Expand Up @@ -1177,9 +1177,9 @@ static int impl_side_get(lua_State *L)
return_string_attrib("name", t.name());
return_string_attrib("color", t.color());
return_cstring_attrib("controller", t.controller_string());
return_bool_attrib("fight_on_without_leader", t.fight_on_without_leader());
return_string_attrib("defeat_condition", team::defeat_condition_to_string(t.defeat_condition()));
return_bool_attrib("lost", t.lost());

if (strcmp(m, "recruit") == 0) {
std::set<std::string> const &recruits = t.recruits();
lua_createtable(L, recruits.size(), 0);
Expand Down Expand Up @@ -1221,7 +1221,7 @@ static int impl_side_set(lua_State *L)
modify_string_attrib("team_name", t.change_team(value, t.user_team_name()));
modify_string_attrib("controller", t.change_controller(value));
modify_string_attrib("color", t.set_color(value));
modify_bool_attrib("fight_on_without_leader", t.set_fight_on_without_leader(value));
modify_string_attrib("defeat_condition", t.set_defeat_condition_string(value));
modify_bool_attrib("lost", t.set_lost(value));

if (strcmp(m, "recruit") == 0) {
Expand Down
34 changes: 30 additions & 4 deletions src/team.cpp
Expand Up @@ -49,7 +49,7 @@ const int team::default_team_gold_ = 100;
// (excluding those attributes used to define the side's leader).
const char * const team::attributes[] = {
"ai_config", "color", "controller", "current_player",
"fight_on_without_leader", "flag",
"defeat_condition", "flag",
"flag_icon", "fog", "fog_data", "gold", "hidden", "income",
"no_leader", "objectives", "objectives_changed", "persistent", "lost",
"recall_cost", "recruit", "save_id", "scroll_to_leader",
Expand All @@ -72,6 +72,32 @@ const std::vector<team>& teams_manager::get_teams()
return *teams;
}

team::DEFEAT_CONDITION team::parse_defeat_condition(const std::string& cond, team::DEFEAT_CONDITION def)
{
if(cond == "no_leader")
return team::NO_LEADER;
else if (cond == "no_unit")
return team::NO_UNITS;
else if (cond == "never")
return team::NEVER;
else
return def;
//throw game::game_error("Cannot parse string " + cond +" to a DEFEAT_CONDITION");
}
std::string team::defeat_condition_to_string(DEFEAT_CONDITION cond)
{
switch(cond)
{
case team::NO_LEADER:
return "no_leader";
case team::NO_UNITS:
return "no_unit";
case team::NEVER:
return "never";
default:
throw game::game_error("Found corrupted DEFEAT_CONDITION");
}
}
team::team_info::team_info() :
name(),
gold(0),
Expand Down Expand Up @@ -102,7 +128,7 @@ team::team_info::team_info() :
allow_player(false),
chose_random(false),
no_leader(true),
fight_on_without_leader(false),
defeat_condition(team::NO_LEADER),
hidden(true),
no_turn_confirmation(false),
color(),
Expand Down Expand Up @@ -133,7 +159,7 @@ void team::team_info::read(const config &cfg)
allow_player = cfg["allow_player"].to_bool(true);
chose_random = cfg["chose_random"].to_bool(false);
no_leader = cfg["no_leader"].to_bool();
fight_on_without_leader = cfg["fight_on_without_leader"].to_bool(false);
defeat_condition = team::parse_defeat_condition(cfg["defeat_condition"], team::NO_LEADER);
hidden = cfg["hidden"].to_bool();
no_turn_confirmation = cfg["suppress_end_turn_confirmation"].to_bool();
side = cfg["side"].to_int(1);
Expand Down Expand Up @@ -260,7 +286,7 @@ void team::team_info::write(config& cfg) const
cfg["allow_player"] = allow_player;
cfg["chose_random"] = chose_random;
cfg["no_leader"] = no_leader;
cfg["fight_on_without_leader"] = fight_on_without_leader;
cfg["defeat_condition"] = team::defeat_condition_to_string(defeat_condition);
cfg["hidden"] = hidden;
cfg["suppress_end_turn_confirmation"] = no_turn_confirmation;
cfg["scroll_to_leader"] = scroll_to_leader;
Expand Down
12 changes: 8 additions & 4 deletions src/team.hpp
Expand Up @@ -33,7 +33,9 @@ class team : public savegame::savegame_config
{
public:
enum CONTROLLER { HUMAN, AI, NETWORK, NETWORK_AI, IDLE, EMPTY };

enum DEFEAT_CONDITION {NO_LEADER, NO_UNITS, NEVER};
static DEFEAT_CONDITION parse_defeat_condition(const std::string& cond, team::DEFEAT_CONDITION def);
static std::string defeat_condition_to_string(DEFEAT_CONDITION cond);
private:
class shroud_map {
public:
Expand Down Expand Up @@ -104,7 +106,7 @@ class team : public savegame::savegame_config
bool allow_player;
bool chose_random;
bool no_leader;
bool fight_on_without_leader;
DEFEAT_CONDITION defeat_condition;
bool hidden;
bool no_turn_confirmation; // Can suppress confirmations when ending a turn.

Expand Down Expand Up @@ -265,8 +267,10 @@ class team : public savegame::savegame_config
void set_auto_shroud_updates(bool value) { auto_shroud_updates_ = value; }
bool get_disallow_observers() const {return info_.disallow_observers; }
bool no_leader() const { return info_.no_leader; }
bool fight_on_without_leader() const { return info_.fight_on_without_leader; }
void set_fight_on_without_leader(bool value) { info_.fight_on_without_leader = value; }
DEFEAT_CONDITION defeat_condition() const { return info_.defeat_condition; }
void set_defeat_condition(DEFEAT_CONDITION value) { info_.defeat_condition = value; }
///sets the defeat condition if @param value is a valid defeat condition, otherwise nothing happes.
void set_defeat_condition_string(const std::string& value) { info_.defeat_condition = parse_defeat_condition(value, info_.defeat_condition); }
void have_leader(bool value=true) { info_.no_leader = !value; }
bool hidden() const { return info_.hidden; }
void set_hidden(bool value) { info_.hidden=value; }
Expand Down

0 comments on commit aabeae6

Please sign in to comment.