Removed redundant parameters from check_victory.

This commit is contained in:
Guillaume Melquiond 2009-07-18 12:06:31 +00:00
parent 64088955a9
commit 61d287fcfa
7 changed files with 19 additions and 18 deletions

View File

@ -1954,11 +1954,12 @@ void advance_unit(unit_map& units,
game_events::fire("post_advance",loc);
}
void check_victory(unit_map& units, std::vector<team>& teams, display& disp)
void check_victory()
{
std::vector<unsigned int> seen_leaders;
for(unit_map::const_iterator i = units.begin();
i != units.end(); ++i) {
for (unit_map::const_iterator i = resources::units->begin(),
i_end = resources::units->end(); i != i_end; ++i)
{
if(i->second.can_recruit()) {
DBG_NG << "seen leader for side " << i->second.side() << "\n";
seen_leaders.push_back(i->second.side());
@ -1966,12 +1967,14 @@ void check_victory(unit_map& units, std::vector<team>& teams, display& disp)
}
// Clear villages for teams that have no leader
for(std::vector<team>::iterator tm = teams.begin(); tm != teams.end(); ++tm) {
if(std::find(seen_leaders.begin(),seen_leaders.end(),tm-teams.begin() + 1) == seen_leaders.end()) {
for (std::vector<team>::iterator tm_beg = resources::teams->begin(), tm = tm_beg,
tm_end = resources::teams->end(); tm != tm_end; ++tm)
{
if (std::find(seen_leaders.begin(), seen_leaders.end(), tm - tm_beg + 1) == seen_leaders.end()) {
tm->clear_villages();
// invalidate_all() is overkill and expensive but this code is
// run rarely so do it the expensive way.
disp.invalidate_all();
resources::screen->invalidate_all();
}
}
@ -1981,15 +1984,13 @@ void check_victory(unit_map& units, std::vector<team>& teams, display& disp)
for(size_t n = 0; n != seen_leaders.size(); ++n) {
const size_t side = seen_leaders[n]-1;
assert(side < teams.size());
for(size_t m = n+1; m != seen_leaders.size(); ++m) {
if(side < teams.size() && teams[side].is_enemy(seen_leaders[m])) {
if ((*resources::teams)[side].is_enemy(seen_leaders[m])) {
found_enemies = true;
}
}
if (teams[side].is_human()) {
if ((*resources::teams)[side].is_human()) {
found_player = true;
}
}
@ -2008,7 +2009,7 @@ void check_victory(unit_map& units, std::vector<team>& teams, display& disp)
if(non_interactive()) {
std::cout << "winner: ";
for(std::vector<unsigned int>::const_iterator i = seen_leaders.begin(); i != seen_leaders.end(); ++i) {
std::string ai = teams[*i - 1].ai_algorithm();
std::string ai = (*resources::teams)[*i - 1].ai_algorithm();
if (ai == "") ai = "default ai";
std::cout << *i << " (using " << ai << ") ";
}

View File

@ -332,7 +332,7 @@ map_location under_leadership(const unit_map& units,
* an end_level_exception if one has.
* Will also remove control of villages from sides with dead leaders.
*/
void check_victory(unit_map& units, std::vector<team>& teams, display& disp);
void check_victory();
/**
* Gets the time of day at a certain tile.

View File

@ -283,7 +283,7 @@ void attack_result::do_execute()
}
}
check_victory(get_info().units,get_info().teams, get_info().disp);
check_victory();
set_gamestate_changed();
manager::raise_enemy_attacked();
}

View File

@ -572,7 +572,7 @@ void readwrite_context_impl::attack_enemy(const map_location u,
}
}
check_victory(get_info().units,get_info().teams, get_info().disp);
check_victory();
raise_enemy_attacked();
}

View File

@ -695,7 +695,7 @@ bool mouse_handler::attack_enemy_(unit_map::iterator attacker, unit_map::iterato
dialogs::advance_unit(defender_loc, !defender_human);
}
check_victory(units_, teams_, gui());
check_victory();
gui().draw();

View File

@ -556,7 +556,7 @@ void playsingle_controller::play_turn(bool save)
ai_testing::log_turn_end(player_number_);
}
check_victory(units_, teams_, *gui_);
check_victory();
}
// Time has run out

View File

@ -806,7 +806,7 @@ bool do_replay_handle(game_display& disp, const gamemap& map,
//if there are no more advancing units, then we check for victory,
//in case the battle that led to advancement caused the end of scenario
if(advancing_units.empty()) {
check_victory(units, teams, disp);
check_victory();
}
continue;
@ -1134,7 +1134,7 @@ bool do_replay_handle(game_display& disp, const gamemap& map,
//check victory now if we don't have any advancements. If we do have advancements,
//we don't check until the advancements are processed.
if(advancing_units.empty()) {
check_victory(units, teams, disp);
check_victory();
}
fix_shroud = !get_replay_source().is_skipping();
}