Optimization when moving big army into fog/shroud.
Avoid creating a little world with only a copy of the unit to make him ignore the others (since copy each units of your army after each fog refresh is bad) Instead simply add a "ignore_units" flag in the pathfinding function
This commit is contained in:
parent
fd4525fc7e
commit
1a85f2326d
3 changed files with 21 additions and 21 deletions
|
@ -1798,9 +1798,7 @@ bool clear_shroud_unit(const gamemap& map,
|
|||
return false;
|
||||
}
|
||||
|
||||
unit_map temp_units(u->first, u->second);
|
||||
|
||||
paths p(map,status,gamedata,temp_units,loc,teams,true,false,teams[team]);
|
||||
paths p(map,status,gamedata,units,loc,teams,true,false,teams[team],0,false,true);
|
||||
for(paths::routes_map::const_iterator i = p.routes.begin();
|
||||
i != p.routes.end(); ++i) {
|
||||
clear_shroud_loc(map,teams[team],i->first,&cleared_locations);
|
||||
|
|
|
@ -107,7 +107,8 @@ static void find_routes(const gamemap& map, const unit_map& units,
|
|||
int move_left, std::map<gamemap::location,paths::route>& routes,
|
||||
std::vector<team> const &teams,
|
||||
bool force_ignore_zocs, bool allow_teleport, int turns_left,
|
||||
bool starting_pos, const team &viewing_team, bool see_all)
|
||||
bool starting_pos, const team &viewing_team,
|
||||
bool see_all, bool ignore_units)
|
||||
{
|
||||
if(size_t(u.side()-1) >= teams.size()) {
|
||||
return;
|
||||
|
@ -122,10 +123,9 @@ static void find_routes(const gamemap& map, const unit_map& units,
|
|||
// Check for teleporting units -- we must be on a vacant village
|
||||
// (or occupied by this unit), that is controlled by our team
|
||||
// to be able to teleport.
|
||||
if (allow_teleport && map.is_village(loc) &&
|
||||
current_team.owns_village(loc) &&
|
||||
(starting_pos || find_visible_unit(units, loc, map,
|
||||
teams, viewing_team,see_all) == units.end())) {
|
||||
if (allow_teleport && map.is_village(loc) && current_team.owns_village(loc) &&
|
||||
(starting_pos || ignore_units ||
|
||||
find_visible_unit(units, loc, map, teams, viewing_team,see_all) == units.end())) {
|
||||
|
||||
|
||||
// If we are on a village, search all known empty friendly villages
|
||||
|
@ -133,7 +133,7 @@ static void find_routes(const gamemap& map, const unit_map& units,
|
|||
const std::set<gamemap::location>& villages = current_team.villages();
|
||||
for(std::set<gamemap::location>::const_iterator t = villages.begin(); t != villages.end(); ++t) {
|
||||
if ((see_all || !viewing_team.is_enemy(u.side()) || !viewing_team.fogged(*t))
|
||||
&& find_visible_unit(units, *t, map, teams, viewing_team, see_all) == units.end()) {
|
||||
&& (ignore_units || find_visible_unit(units, *t, map, teams, viewing_team, see_all) == units.end())) {
|
||||
locs.push_back(*t);
|
||||
}
|
||||
}
|
||||
|
@ -148,13 +148,13 @@ static void find_routes(const gamemap& map, const unit_map& units,
|
|||
currentloc.x >= map.w() || currentloc.y >= map.h())
|
||||
continue;
|
||||
|
||||
// See if the tile is on top of an enemy unit
|
||||
const unit_map::const_iterator unit_it =
|
||||
find_visible_unit(units, locs[i], map, teams, viewing_team,see_all);
|
||||
|
||||
if (unit_it != units.end() &&
|
||||
current_team.is_enemy(unit_it->second.side()))
|
||||
continue;
|
||||
if (!ignore_units) {
|
||||
// See if the tile is on top of an enemy unit
|
||||
const unit_map::const_iterator unit_it =
|
||||
find_visible_unit(units, locs[i], map, teams, viewing_team,see_all);
|
||||
if (unit_it != units.end() && current_team.is_enemy(unit_it->second.side()))
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find the terrain of the adjacent location
|
||||
const t_translation::t_letter terrain = map[currentloc];
|
||||
|
@ -178,7 +178,7 @@ static void find_routes(const gamemap& map, const unit_map& units,
|
|||
old_move_left = old_rt->second.move_left;
|
||||
|
||||
// Only check ZoC if asked and if there is move to remove
|
||||
if (!force_ignore_zocs && new_move_left > 0) {
|
||||
if (!ignore_units && !force_ignore_zocs && new_move_left > 0) {
|
||||
// Test if, even with no ZoC, we already have a better route,
|
||||
// so no need to try with ZoC (and thus no need to search ZoC)
|
||||
const int total_move_no_zoc = new_turns_left * u.total_movement() + new_move_left;
|
||||
|
@ -208,7 +208,8 @@ static void find_routes(const gamemap& map, const unit_map& units,
|
|||
if (new_route.move_left > 0) {
|
||||
find_routes(map, units, u, currentloc,
|
||||
new_move_left, routes, teams, force_ignore_zocs,
|
||||
allow_teleport, new_turns_left, false, viewing_team, see_all);
|
||||
allow_teleport, new_turns_left, false, viewing_team,
|
||||
see_all, ignore_units);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -221,7 +222,7 @@ paths::paths(gamemap const &map, gamestatus const &/*status*/,
|
|||
std::vector<team> const &teams,
|
||||
bool force_ignore_zoc,
|
||||
bool allow_teleport, const team &viewing_team,
|
||||
int additional_turns, bool see_all)
|
||||
int additional_turns, bool see_all, bool ignore_units)
|
||||
{
|
||||
const unit_map::const_iterator i = units.find(loc);
|
||||
if(i == units.end()) {
|
||||
|
@ -232,7 +233,8 @@ paths::paths(gamemap const &map, gamestatus const &/*status*/,
|
|||
routes[loc].move_left = i->second.movement_left();
|
||||
find_routes(map,units,i->second,loc,
|
||||
i->second.movement_left(),routes,teams,force_ignore_zoc,
|
||||
allow_teleport,additional_turns,true,viewing_team, see_all);
|
||||
allow_teleport,additional_turns,true,viewing_team,
|
||||
see_all, ignore_units);
|
||||
}
|
||||
|
||||
int route_turns_to_complete(const unit& u, paths::route& rt, const team &viewing_team,
|
||||
|
|
|
@ -101,7 +101,7 @@ struct paths
|
|||
gamemap::location const &loc, std::vector<team> const &teams,
|
||||
bool force_ignore_zocs,bool allow_teleport,
|
||||
const team &viewing_team,int additional_turns = 0,
|
||||
bool see_all = false);
|
||||
bool see_all = false, bool ignore_units = false);
|
||||
|
||||
//! Structure which holds a single route between one location and another.
|
||||
struct route
|
||||
|
|
Loading…
Add table
Reference in a new issue