fix $owner_side incorrectly set if capture event fired by unit movement

We are deleting the captured village from the set of owned villages of
the previous owner before querying which previous side owned it (and
giving it to the new side + firing the event), thus the result was
always "unowned".

fix for a bug reported in the forums:

http://forums.wesnoth.org/viewtopic.php?f=21&t=36569&p=525789#p525789
This commit is contained in:
Anonymissimus 2012-04-07 16:43:03 +00:00
parent 4aa13e03cd
commit 82bf07fa41
2 changed files with 9 additions and 5 deletions

View file

@ -1923,12 +1923,16 @@ bool get_village(const map_location& loc, int side, int *action_timebonus)
bool has_leader = resources::units->find_leader(side).valid();
bool grants_timebonus = false;
int old_owner_side = 0;
// We strip the village off all other sides, unless it is held by an ally
// and we don't have a leader (and thus can't occupy it)
for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
int i_side = i - teams.begin() + 1;
if (!t || has_leader || t->is_enemy(i_side)) {
i->lose_village(loc);
if(i->owns_village(loc)) {
old_owner_side = i_side;
i->lose_village(loc);
}
if (side != i_side && action_timebonus) {
grants_timebonus = true;
}
@ -1946,7 +1950,7 @@ bool get_village(const map_location& loc, int side, int *action_timebonus)
if (resources::screen != NULL) {
resources::screen->invalidate(loc);
}
return t->get_village(loc, village_owner(loc, *resources::teams) + 1);
return t->get_village(loc, old_owner_side);
}
return false;

View file

@ -379,9 +379,9 @@ bool team::get_village(const map_location& loc, const int owner_side, const bool
void team::lose_village(const map_location& loc)
{
if(owns_village(loc)) {
villages_.erase(villages_.find(loc));
}
const std::set<map_location>::const_iterator vil = villages_.find(loc);
assert(vil != villages_.end());
villages_.erase(vil);
}
void team::set_recruits(const std::set<std::string>& recruits)