Fix an assertion failure caused by doing [move_unit_fake]...

...with unit_types that cannot pass over terrains that are part of a
explicit path given.
This commit is contained in:
Ignacio R. Morelle 2008-11-01 17:49:53 +00:00
parent 7d5bc09097
commit 0c98e1d754
3 changed files with 28 additions and 1 deletions

View file

@ -919,7 +919,15 @@ namespace {
route = a_star_search(src, dst, 10000, &calc,
game_map->w(), game_map->h());
assert(route.steps.size() > 0);
if(route.steps.size() == 0) {
// This would occur when trying to do a MUF of a unit
// over locations which are unreachable to it (infinite movement
// costs). This really cannot fail.
WRN_NG << "Could not find move_unit_fake route from " << src << " to " << dst << ": ignoring terrain\n";
dummy_path_calculator calc(dummy_unit, *game_map);
route = a_star_search(src, dst, 10000, &calc, game_map->w(), game_map->h());
assert(route.steps.size() > 0);
}
}
unit_display::move_unit(route.steps, dummy_unit, *teams);

View file

@ -383,6 +383,15 @@ double emergency_path_calculator::cost(const map_location&,const map_location& l
return unit_.movement_cost(map_[loc]);
}
dummy_path_calculator::dummy_path_calculator(const unit&, const gamemap&)
{
}
double dummy_path_calculator::cost(const map_location&, const map_location&, const double) const
{
return 0.0;
}
std::ostream& operator << (std::ostream& outstream, const paths::route& rt) {
outstream << "\n[route]\n\tsteps=\"";
bool first_loop = true;

View file

@ -174,4 +174,14 @@ private:
gamemap const &map_;
};
/**
* Function which doesn't take anything into account. Used by
* move_unit_fake for the last-chance case.
*/
struct dummy_path_calculator : cost_calculator
{
dummy_path_calculator(const unit& u, const gamemap& map);
virtual double cost(const map_location& src, const map_location& loc, const double so_far) const;
};
#endif