Author: alink
Date: Tue Apr 14 17:59:44 2009
New Revision: 34910

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34910&view=rev
Log:
Small optimization of pathfinding (paths() version) by skipping backwards moves

Modified:
    trunk/src/pathfind.cpp

Modified: trunk/src/pathfind.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind.cpp?rev=34910&r1=34909&r2=34910&view=diff
==============================================================================
--- trunk/src/pathfind.cpp (original)
+++ trunk/src/pathfind.cpp Tue Apr 14 17:59:44 2009
@@ -101,7 +101,7 @@
 }
 
 static void find_routes(const gamemap& map, const unit_map& units,
-               const unit& u, const map_location& loc,
+               const unit& u, const map_location& loc, const map_location& 
previous_loc,
                int move_left, paths::routes_map& routes,
                std::vector<team> const &teams,
                bool force_ignore_zocs, bool allow_teleport, int turns_left,
@@ -137,6 +137,12 @@
                const map_location& currentloc = *i;
 
                if (!map.on_board(currentloc))
+                       continue;
+
+               // we skip locations adjacent to the previous_loc (before loc)
+               // because previous_loc -> currentloc is always shorter
+               // than previous_loc -> loc -> currentloc
+               if(tiles_adjacent(currentloc, previous_loc))
                        continue;
 
                // check if we can move on this terrain
@@ -196,7 +202,7 @@
                new_route.move_left = new_turns_moves + new_move_left;
 
                if (new_route.move_left > 0) {
-                       find_routes(map, units, u, currentloc,
+                       find_routes(map, units, u, currentloc, loc,
                                                new_move_left, routes, teams, 
force_ignore_zocs,
                                                allow_teleport, new_turns_left, 
false, viewing_team,
                                                see_all, ignore_units);
@@ -220,8 +226,13 @@
                return;
        }
 
+
+       const map_location previous_loc = map_location();
+       // dummy map_location() must not be adjacent to real hexes
+       assert(previous_loc.x < -1);
+
        routes[loc].move_left = i->second.movement_left();
-       find_routes(map,units,i->second,loc,
+       find_routes(map,units,i->second,loc,previous_loc,
                i->second.movement_left(),routes,teams,force_ignore_zoc,
                allow_teleport,additional_turns,true,viewing_team,
                see_all, ignore_units);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to