Author: anonymissimus
Date: Sat Feb 26 22:48:59 2011
New Revision: 48649

URL: http://svn.gna.org/viewcvs/wesnoth?rev=48649&view=rev
Log:
Introduced a minimum search radius for pathfind::find_vacant_tile with a 
pass_check. (fix for bug #17769)

Modified:
    trunk/data/lua/wml-tags.lua
    trunk/src/pathfind/pathfind.cpp

Modified: trunk/data/lua/wml-tags.lua
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/lua/wml-tags.lua?rev=48649&r1=48648&r2=48649&view=diff
==============================================================================
--- trunk/data/lua/wml-tags.lua (original)
+++ trunk/data/lua/wml-tags.lua Sat Feb 26 22:48:59 2011
@@ -561,9 +561,8 @@
                        while true do
                                x = tonumber(x) or 
helper.wml_error(coordinate_error)
                                y = tonumber(y) or 
helper.wml_error(coordinate_error)
-                               local move_cost = 
wesnoth.unit_movement_cost(current_unit, wesnoth.get_terrain(x, y))
-                               if move_cost >= 99 then 
helper.wml_error(coordinate_error) end
                                x, y = wesnoth.find_vacant_tile(x, y, 
current_unit)
+                               if not x or not y then helper.wml_error("Could 
not find a reachable vacant hex near to one of the target hexes in 
[move_unit].") end
                                move_string_x = string.format("%s,%u", 
move_string_x, x)
                                move_string_y = string.format("%s,%u", 
move_string_y, y)
                                local next_x, next_y = xs(), ys()

Modified: trunk/src/pathfind/pathfind.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind/pathfind.cpp?rev=48649&r1=48648&r2=48649&view=diff
==============================================================================
--- trunk/src/pathfind/pathfind.cpp (original)
+++ trunk/src/pathfind/pathfind.cpp Sat Feb 26 22:48:59 2011
@@ -61,14 +61,19 @@
                //Iterate over all the hexes we need to check
                foreach (const map_location &loc, tiles_checking)
                {
-                       //If the unit cannot reach this area or it's not a 
castle but should, skip it.
-                       if ((vacancy == pathfind::VACANT_CASTLE && 
!map.is_castle(loc))
-                       || (pass_check && pass_check->movement_cost(map[loc])
-                                       == unit_movement_type::UNREACHABLE))
-                               continue;
-                       //If the hex is empty, return it.
-                       if (units.find(loc) == units.end())
-                               return loc;
+                       //If this area is not a castle but should, skip it.
+                       if (vacancy == pathfind::VACANT_CASTLE && 
!map.is_castle(loc)) continue;
+                       const bool pass_check_and_unreachable = pass_check
+                               && pass_check->movement_cost(map[loc]) == 
unit_movement_type::UNREACHABLE;
+                       //If the unit can't reach the tile and we have searched
+                       //an area of at least radius 10 (arbitrary), skip the 
tile.
+                       //Neccessary for cases such as an unreachable
+                       //starting hex surrounded by 6 other unreachable hexes, 
in which case
+                       //the algorithm would not even search distance==1
+                       //even if there's a reachable hex for distance==2.
+                       if (pass_check_and_unreachable && distance > 10) 
continue;
+                       //If the hex is empty and we do either no pass check or 
the hex is reachable, return it.
+                       if (units.find(loc) == units.end() && 
!pass_check_and_unreachable) return loc;
                        map_location adjs[6];
                        get_adjacent_tiles(loc,adjs);
                        foreach (const map_location &loc, adjs)


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

Reply via email to