Fixed a problem where the AI would get stuck...

...and never finish making its move. This problem was easily
reproducible on some scenarios, such as e.g.  the first turn of Hasty
Alliance.

Developer info: ai::get_villages was refactored from version 0.7.6 to 0.7.7.
One of the changes caused its return value to be dependent on whether the new
function ai::get_village_combinations(...) finds any moves. However, some of
these moves are not necessarily valid because the destination is taken by
another unit. I'm not sure the cause of that. In any case, the resolution is
for get_villages(...) to only return "true" if it actually makes any moves,
ignoring the invalid ones. This is accomplished with a simple "moves_made"
variable.

TODO: look into get_village_combinations(...) and figure out why we're trying
to take a village that already has a unit on it.
This commit is contained in:
John B. Messerly 2004-05-24 05:44:45 +00:00
parent 818ec41e4a
commit 24d10d1885

View file

@ -816,12 +816,14 @@ bool ai::get_villages(std::map<gamemap::location,paths>& possible_moves, const m
//if it wants to stop to recruit along the way.
std::pair<location,location> leader_move;
int moves_made = 0;
for(std::vector<std::pair<location,location> >::const_iterator i = moves.begin(); i != moves.end(); ++i) {
if(leader != units_.end() && leader->first == i->second) {
leader_move = *i;
} else {
if(units_.count(i->first) == 0) {
move_unit(i->second,i->first,possible_moves);
++moves_made;
}
}
}
@ -829,10 +831,11 @@ bool ai::get_villages(std::map<gamemap::location,paths>& possible_moves, const m
if(leader_move.second.valid()) {
if(units_.count(leader_move.first) == 0) {
move_unit(leader_move.second,leader_move.first,possible_moves);
++moves_made;
}
}
return moves.empty() == false;
return moves_made > 0;
}
bool ai::get_healing(std::map<gamemap::location,paths>& possible_moves, const move_map& srcdst, const move_map& dstsrc, const move_map& enemy_srcdst, const move_map& enemy_dstsrc)