Safer handling of waypoints when WML moveto event removes the moving unit.
This commit is contained in:
parent
cb5bc1f022
commit
0c89bc2c32
3 changed files with 14 additions and 17 deletions
|
@ -2028,6 +2028,7 @@ size_t move_unit(move_unit_spectator *move_spectator,
|
|||
// 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 @@ size_t move_unit(move_unit_spectator *move_spectator,
|
|||
}
|
||||
|
||||
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 @@ size_t move_unit(move_unit_spectator *move_spectator,
|
|||
} 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -285,10 +285,12 @@ int combat_modifier(const unit_map &units, const map_location &loc,
|
|||
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 @@ struct undo_action {
|
|||
{}
|
||||
|
||||
std::vector<map_location> route;
|
||||
std::list<map_location> waypoints;
|
||||
int starting_moves;
|
||||
int original_village_owner;
|
||||
map_location recall_loc;
|
||||
|
|
|
@ -1069,7 +1069,7 @@ void menu_handler::undo(int side_num)
|
|||
|
||||
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 @@ void menu_handler::redo(int side_num)
|
|||
|
||||
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();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue