Re-sets the standing animation before and after the temporary_unit_mover moves the unit
Fixes #6960
This commit is contained in:
parent
10733b1071
commit
dcde7c541e
5 changed files with 17 additions and 53 deletions
|
@ -20,6 +20,7 @@
|
|||
#include "preferences/game.hpp"
|
||||
#include "recall_list_manager.hpp"
|
||||
#include "units/unit.hpp"
|
||||
#include "units/animation_component.hpp"
|
||||
#include "utils/general.hpp"
|
||||
|
||||
#include <set>
|
||||
|
@ -470,12 +471,13 @@ temporary_unit_remover::~temporary_unit_remover()
|
|||
* the unit is moved (and restored to its previous value upon this object's
|
||||
* destruction).
|
||||
*/
|
||||
temporary_unit_mover::temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst, int new_moves)
|
||||
temporary_unit_mover::temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst, int new_moves, bool stand)
|
||||
: m_(m)
|
||||
, src_(src)
|
||||
, dst_(dst)
|
||||
, old_moves_(-1)
|
||||
, temp_(src == dst ? unit_ptr() : m_.extract(dst))
|
||||
, stand_(stand)
|
||||
{
|
||||
auto [iter, success] = m_.move(src_, dst_);
|
||||
|
||||
|
@ -483,48 +485,10 @@ temporary_unit_mover::temporary_unit_mover(unit_map& m, const map_location& src,
|
|||
if(success) {
|
||||
old_moves_ = iter->movement_left(true);
|
||||
iter->set_movement(new_moves);
|
||||
if(stand_) {
|
||||
m_.find_unit_ptr(dst_)->anim_comp().set_standing();
|
||||
}
|
||||
}
|
||||
|
||||
temporary_unit_mover::temporary_unit_mover(
|
||||
game_board& b, const map_location& src, const map_location& dst, int new_moves)
|
||||
: m_(b.units_)
|
||||
, src_(src)
|
||||
, dst_(dst)
|
||||
, old_moves_(-1)
|
||||
, temp_(src == dst ? unit_ptr() : m_.extract(dst))
|
||||
{
|
||||
auto [iter, success] = m_.move(src_, dst_);
|
||||
|
||||
// Set the movement.
|
||||
if(success) {
|
||||
old_moves_ = iter->movement_left(true);
|
||||
iter->set_movement(new_moves);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* This version does not change (nor restore) the unit's movement.
|
||||
*/
|
||||
temporary_unit_mover::temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst)
|
||||
: m_(m)
|
||||
, src_(src)
|
||||
, dst_(dst)
|
||||
, old_moves_(-1)
|
||||
, temp_(src == dst ? unit_ptr() : m_.extract(dst))
|
||||
{
|
||||
m_.move(src_, dst_);
|
||||
}
|
||||
|
||||
temporary_unit_mover::temporary_unit_mover(game_board& b, const map_location& src, const map_location& dst)
|
||||
: m_(b.units_)
|
||||
, src_(src)
|
||||
, dst_(dst)
|
||||
, old_moves_(-1)
|
||||
, temp_(src == dst ? unit_ptr() : m_.extract(dst))
|
||||
{
|
||||
m_.move(src_, dst_);
|
||||
}
|
||||
|
||||
temporary_unit_mover::~temporary_unit_mover()
|
||||
|
@ -535,6 +499,9 @@ temporary_unit_mover::~temporary_unit_mover()
|
|||
// Restore the movement?
|
||||
if(success && old_moves_ >= 0) {
|
||||
iter->set_movement(old_moves_);
|
||||
if(stand_) {
|
||||
m_.find_unit_ptr(src_)->anim_comp().set_standing();
|
||||
}
|
||||
}
|
||||
|
||||
// Restore the extracted unit?
|
||||
|
|
|
@ -229,14 +229,7 @@ private:
|
|||
*/
|
||||
struct temporary_unit_mover
|
||||
{
|
||||
temporary_unit_mover(unit_map& m, const map_location& src,
|
||||
const map_location& dst, int new_moves);
|
||||
temporary_unit_mover(unit_map& m, const map_location& src,
|
||||
const map_location& dst);
|
||||
temporary_unit_mover(game_board& b, const map_location& src,
|
||||
const map_location& dst, int new_moves);
|
||||
temporary_unit_mover(game_board& b, const map_location& src,
|
||||
const map_location& dst);
|
||||
temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst, int new_moves, bool stand);
|
||||
virtual ~temporary_unit_mover();
|
||||
|
||||
private:
|
||||
|
@ -245,4 +238,5 @@ private:
|
|||
const map_location dst_;
|
||||
int old_moves_;
|
||||
unit_ptr temp_;
|
||||
bool stand_;
|
||||
};
|
||||
|
|
|
@ -935,7 +935,7 @@ void mouse_handler::move_action(bool browse)
|
|||
|
||||
// block where we temporary move the unit
|
||||
{
|
||||
temporary_unit_mover temp_mover(pc_.get_units(), src, attack_from, itor->move_left);
|
||||
temporary_unit_mover temp_mover(pc_.get_units(), src, attack_from, itor->move_left, true);
|
||||
choice = show_attack_dialog(attack_from, clicked_u->get_location());
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "display.hpp"
|
||||
#include "log.hpp"
|
||||
#include "units/id.hpp"
|
||||
#include "units/unit.hpp"
|
||||
|
@ -126,6 +127,8 @@ unit_map::umap_retval_pair_t unit_map::move(const map_location& src, const map_l
|
|||
return std::pair(make_unit_iterator(uit), false);
|
||||
}
|
||||
|
||||
display::get_singleton()->invalidate(src);
|
||||
|
||||
self_check();
|
||||
|
||||
return std::pair(make_unit_iterator(uit), true);
|
||||
|
|
|
@ -364,7 +364,7 @@ void move::apply_temp_modifier(unit_map& unit_map)
|
|||
// Move the unit
|
||||
DBG_WB << "Move: Temporarily moving unit " << unit->name() << " [" << unit->id()
|
||||
<< "] from (" << get_source_hex() << ") to (" << get_dest_hex() <<")";
|
||||
mover_.reset(new temporary_unit_mover(unit_map, get_source_hex(), get_dest_hex(), calculate_moves_left(*unit)));
|
||||
mover_.reset(new temporary_unit_mover(unit_map, get_source_hex(), get_dest_hex(), calculate_moves_left(*unit), false));
|
||||
|
||||
//Update status of fake unit (not undone by remove_temp_modifiers)
|
||||
//@todo this contradicts the name "temp_modifiers"
|
||||
|
|
Loading…
Add table
Reference in a new issue