Added "victory_when_enemies_defeated" to scenarios.
Setting this to "no" will prevent check_victory from throwing the end_level exception when the enemies are defeated. Scenario designers using this will have to explicitly call end_level. The "enemies defeated" game events still gets fired.
This commit is contained in:
parent
589eb3b8c1
commit
1ecaa6af64
3 changed files with 33 additions and 0 deletions
|
@ -48,6 +48,24 @@ private:
|
|||
const gamemap& map_;
|
||||
};
|
||||
|
||||
// Conditions placed on victory must be accessible from the global function
|
||||
// check_victory, but shouldn't be passed to that function as parameters,
|
||||
// since it is called from a variety of places.
|
||||
namespace victory_conditions
|
||||
{
|
||||
bool when_enemies_defeated;
|
||||
|
||||
void set_victory_when_enemies_defeated(bool on)
|
||||
{
|
||||
when_enemies_defeated = on;
|
||||
}
|
||||
|
||||
const bool victory_when_enemies_defeated()
|
||||
{
|
||||
return when_enemies_defeated;
|
||||
}
|
||||
}
|
||||
|
||||
std::string recruit_unit(const gamemap& map, int side,
|
||||
std::map<gamemap::location,unit>& units, unit& new_unit,
|
||||
gamemap::location recruit_location, display* disp, bool need_castle, bool full_movement)
|
||||
|
@ -983,8 +1001,13 @@ void check_victory(std::map<gamemap::location,unit>& units,
|
|||
if(found_enemies == false) {
|
||||
if(found_human) {
|
||||
game_events::fire("enemies defeated");
|
||||
if (victory_conditions::victory_when_enemies_defeated() == false) {
|
||||
// this level has asked not to be ended by this condition
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(non_interactive()) {
|
||||
std::cout << "winner: ";
|
||||
for(std::vector<int>::const_iterator i = seen_leaders.begin(); i != seen_leaders.end(); ++i) {
|
||||
|
|
|
@ -195,4 +195,10 @@ bool clear_shroud(display& disp, const gamestatus& status,
|
|||
bool unit_can_move(const gamemap::location& loc, const unit_map& units,
|
||||
const gamemap& map, const std::vector<team>& teams);
|
||||
|
||||
|
||||
namespace victory_conditions {
|
||||
void set_victory_when_enemies_defeated(bool on);
|
||||
const bool victory_when_enemies_defeated();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -253,6 +253,9 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
|
|||
sound::play_music(music);
|
||||
}
|
||||
|
||||
victory_conditions::set_victory_when_enemies_defeated(
|
||||
(*level)["victory_when_enemies_defeated"] != "no");
|
||||
|
||||
game_events::manager events_manager(*level,gui,map,units,teams,
|
||||
state_of_game,gameinfo);
|
||||
|
||||
|
@ -517,6 +520,7 @@ redo_turn:
|
|||
game_events::pump();
|
||||
|
||||
check_victory(units,teams);
|
||||
|
||||
}
|
||||
|
||||
//time has run out
|
||||
|
|
Loading…
Add table
Reference in a new issue