Author: alink
Date: Tue Nov 24 02:49:12 2009
New Revision: 39906

URL: http://svn.gna.org/viewcvs/wesnoth?rev=39906&view=rev
Log:
Safer handling of waypoints when WML moveto event removes the moving unit.

Modified:
    trunk/src/actions.cpp
    trunk/src/actions.hpp
    trunk/src/menu_events.cpp

Modified: trunk/src/actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=39906&r1=39905&r2=39906&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Tue Nov 24 02:49:12 2009
@@ -2028,6 +2028,7 @@
        // See how far along the given path we can move.
        const int starting_moves = ui->second.movement_left();
        int moves_left = starting_moves;
+       std::list<map_location> starting_waypoints = ui->second.waypoints();
        std::set<map_location> seen_units;
        std::set<map_location> petrified_units;
        bool discovered_unit = false;
@@ -2091,6 +2092,10 @@
                }
 
                moves_left -= cost;
+               std::list<map_location>& waypoints = ui->second.waypoints();
+               if(!waypoints.empty() && waypoints.front() == *step) {
+                       waypoints.pop_front();
+               }
 
                // If we use fog or shroud, see if we have sighted an enemy 
unit,
                // in which case we should stop immediately.
@@ -2273,20 +2278,9 @@
                } else {
                        // MP_COUNTDOWN: added param
                        undo_stack->push_back(
-                               undo_action(ui->second,steps, starting_moves, 
action_time_bonus,
-                               orig_village_owner, orig_dir));
-               }
-       }
-
-       //remove used waypoints
-       //TODO:deal with the other case too
-       if(ui != units.end()) {
-               std::list<map_location>& waypoints = ui->second.waypoints();
-               foreach(const map_location& loc, steps) {
-                               if(waypoints.empty())
-                                       break;
-                               if(waypoints.front() == loc)
-                                       waypoints.pop_front();
+                               undo_action(ui->second, steps,
+                                               starting_waypoints, 
starting_moves,
+                                               action_time_bonus, 
orig_village_owner, orig_dir));
                }
        }
 

Modified: trunk/src/actions.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.hpp?rev=39906&r1=39905&r2=39906&view=diff
==============================================================================
--- trunk/src/actions.hpp (original)
+++ trunk/src/actions.hpp Tue Nov 24 02:49:12 2009
@@ -285,10 +285,12 @@
 struct undo_action {
        enum ACTION_TYPE { NONE, RECRUIT, RECALL, DISMISS };
 
-       undo_action(const unit& u, const std::vector<map_location>& rt, int sm,
+       undo_action(const unit& u, const std::vector<map_location>& rt,
+               const std::list<map_location>& wp, int sm,
                int timebonus=0, int orig=-1,
                const map_location::DIRECTION dir=map_location::NDIRECTIONS) :
                        route(rt),
+                       waypoints(wp),
                        starting_moves(sm),
                        original_village_owner(orig),
                        recall_loc(),
@@ -312,6 +314,7 @@
                {}
 
        std::vector<map_location> route;
+       std::list<map_location> waypoints;
        int starting_moves;
        int original_village_owner;
        map_location recall_loc;

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=39906&r1=39905&r2=39906&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Tue Nov 24 02:49:12 2009
@@ -1069,7 +1069,7 @@
 
                u = units_.find(route.back());
                u->second.set_goto(map_location());
-               std::swap(u->second.waypoints(), 
action.affected_unit.waypoints());
+               std::swap(u->second.waypoints(), action.waypoints);
                u->second.set_movement(starting_moves);
                u->second.set_standing();
 
@@ -1207,7 +1207,7 @@
 
                unit::clear_status_caches();
                u->second.set_goto(action.affected_unit.get_goto());
-               std::swap(u->second.waypoints(), 
action.affected_unit.waypoints());
+               std::swap(u->second.waypoints(), action.waypoints);
                u->second.set_movement(starting_moves);
                u->second.set_standing();
 


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

Reply via email to