Continue to clean and uniformize the code around the calls...
...of unit_display::move_unit() (including undo/redo and WML teleport event)
This commit is contained in:
parent
ffee633461
commit
6fd2a80f58
3 changed files with 39 additions and 26 deletions
|
@ -2409,13 +2409,13 @@ size_t move_unit(move_unit_spectator *move_spectator,
|
|||
|
||||
// move the real unit
|
||||
units.move(ui->first, steps.back());
|
||||
unit::clear_status_caches();
|
||||
|
||||
ui = units.find(steps.back());
|
||||
ui->second.set_location(steps.back());
|
||||
ui->second.set_movement(moves_left);
|
||||
ui->second.set_standing();
|
||||
|
||||
disp.invalidate_unit_after_move(steps.front(), steps.back());
|
||||
unit::clear_status_caches();
|
||||
|
||||
if(move_recorder != NULL) {
|
||||
move_recorder->add_movement(steps);
|
||||
|
|
|
@ -628,27 +628,35 @@ WML_HANDLER_FUNCTION(teleport, event_info, cfg)
|
|||
if (!resources::game_map->on_board(vacant_dst)) return;
|
||||
|
||||
const int side = u->second.side();
|
||||
const map_location src_loc = u->first;
|
||||
|
||||
resources::units->move(src_loc, vacant_dst);
|
||||
if (resources::game_map->is_village(vacant_dst)) {
|
||||
get_village(vacant_dst, *resources::screen, *resources::teams, side - 1, *resources::units);
|
||||
}
|
||||
|
||||
if (utils::string_bool(cfg["clear_shroud"], true)) {
|
||||
clear_shroud(side);
|
||||
}
|
||||
|
||||
const map_location src_loc = u->first;
|
||||
|
||||
if (utils::string_bool(cfg["animate"])) {
|
||||
std::vector<map_location> teleport_path;
|
||||
teleport_path.push_back(src_loc);
|
||||
teleport_path.push_back(vacant_dst);
|
||||
unit_display::move_unit(teleport_path, u->second, *resources::teams);
|
||||
} else {
|
||||
u->second.set_standing();
|
||||
resources::screen->invalidate(src_loc);
|
||||
resources::screen->invalidate(dst);
|
||||
resources::screen->draw();
|
||||
}
|
||||
|
||||
resources::units->move(src_loc, vacant_dst);
|
||||
unit::clear_status_caches();
|
||||
|
||||
u = resources::units->find(vacant_dst);
|
||||
u->second.set_standing();
|
||||
|
||||
if (resources::game_map->is_village(vacant_dst)) {
|
||||
get_village(vacant_dst, *resources::screen, *resources::teams, side - 1, *resources::units);
|
||||
}
|
||||
|
||||
resources::screen->invalidate_unit_after_move(src_loc, dst);
|
||||
|
||||
resources::screen->draw();
|
||||
}
|
||||
|
||||
WML_HANDLER_FUNCTION(unpetrify, /*event_info*/, cfg)
|
||||
|
|
|
@ -1032,7 +1032,7 @@ private:
|
|||
const int starting_moves = action.starting_moves;
|
||||
std::vector<map_location> route = action.route;
|
||||
std::reverse(route.begin(),route.end());
|
||||
const unit_map::iterator u = units_.find(route.front());
|
||||
unit_map::iterator u = units_.find(route.front());
|
||||
const unit_map::iterator u_end = units_.find(route.back());
|
||||
if(u == units_.end() || u_end != units_.end()) {
|
||||
//this can actually happen if the scenario designer has abused the [allow_undo] command
|
||||
|
@ -1052,13 +1052,16 @@ private:
|
|||
action.starting_moves = u->second.movement_left();
|
||||
|
||||
unit_display::move_unit(route,u->second,teams_);
|
||||
std::pair<map_location,unit> *up = units_.extract(u->first);
|
||||
up->second.set_goto(map_location());
|
||||
up->second.set_movement(starting_moves);
|
||||
up->first = route.back();
|
||||
units_.insert(up);
|
||||
|
||||
units_.move(u->first, route.back());
|
||||
unit::clear_status_caches();
|
||||
up->second.set_standing();
|
||||
|
||||
u = units_.find(route.back());
|
||||
u->second.set_goto(map_location());
|
||||
u->second.set_movement(starting_moves);
|
||||
u->second.set_standing();
|
||||
|
||||
gui_->invalidate_unit_after_move(route.front(), route.back());
|
||||
gui_->invalidate(route.back());
|
||||
gui_->draw();
|
||||
}
|
||||
|
@ -1179,7 +1182,7 @@ private:
|
|||
// Redo movement action
|
||||
const int starting_moves = action.starting_moves;
|
||||
std::vector<map_location> route = action.route;
|
||||
const unit_map::iterator u = units_.find(route.front());
|
||||
unit_map::iterator u = units_.find(route.front());
|
||||
if(u == units_.end()) {
|
||||
assert(false);
|
||||
return;
|
||||
|
@ -1188,16 +1191,17 @@ private:
|
|||
action.starting_moves = u->second.movement_left();
|
||||
|
||||
unit_display::move_unit(route,u->second,teams_);
|
||||
std::pair<map_location,unit> *up = units_.extract(u->first);
|
||||
up->second.set_goto(map_location());
|
||||
up->second.set_movement(starting_moves);
|
||||
up->first = route.back();
|
||||
units_.insert(up);
|
||||
|
||||
units_.move(u->first, route.back());
|
||||
u = units_.find(route.back());
|
||||
|
||||
unit::clear_status_caches();
|
||||
up->second.set_standing();
|
||||
u->second.set_goto(map_location());
|
||||
u->second.set_movement(starting_moves);
|
||||
u->second.set_standing();
|
||||
|
||||
if(map_.is_village(route.back())) {
|
||||
get_village(route.back(),*gui_,teams_,up->second.side()-1,units_);
|
||||
get_village(route.back(),*gui_,teams_,u->second.side()-1,units_);
|
||||
//MP_COUNTDOWN restore capture bonus
|
||||
if(action.countdown_time_bonus)
|
||||
{
|
||||
|
@ -1205,6 +1209,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
gui_->invalidate_unit_after_move(route.front(), route.back());
|
||||
gui_->invalidate(route.back());
|
||||
gui_->draw();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue