replace fight_on_without_leader with defeat_condition

[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]
This commit is contained in:
gfgtdf 2014-05-19 00:30:21 +02:00
parent 1fc27bb9e7
commit 26d60c0a8f
4 changed files with 56 additions and 22 deletions

View File

@ -1406,25 +1406,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();
}
}
}

View File

@ -1182,9 +1182,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);
@ -1226,7 +1226,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) {

View File

@ -49,7 +49,7 @@ const int team::default_team_gold_ = 100;
// Update this list of attributes if you change what is used to define a side
// (excluding those attributes used to define the side's leader).
const std::set<std::string> team::attributes = boost::assign::list_of("ai_config")
("color")("controller")("current_player")("fight_on_without_leader")("flag")
("color")("controller")("current_player")("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")
@ -70,6 +70,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),
@ -100,7 +126,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(),
@ -131,7 +157,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);
@ -258,7 +284,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;

View File

@ -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:
@ -104,7 +106,7 @@ private:
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.
@ -265,8 +267,10 @@ public:
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; }