mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-09 23:52:09 +00:00
Add a 'temporary unit mover'.
This commit is contained in:
parent
c15d9cb2fc
commit
d39556e2d5
14
src/unit.cpp
14
src/unit.cpp
@ -2830,6 +2830,20 @@ temporary_unit_placer::~temporary_unit_placer()
|
||||
}
|
||||
}
|
||||
|
||||
temporary_unit_mover::temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst)
|
||||
: m_(m), src_(src), dst_(dst), temp_(m.extract(dst))
|
||||
{
|
||||
m.move(src_, dst_);
|
||||
}
|
||||
|
||||
temporary_unit_mover::~temporary_unit_mover()
|
||||
{
|
||||
m_.move(dst_, src_);
|
||||
if(temp_) {
|
||||
m_.insert(temp_);
|
||||
}
|
||||
}
|
||||
|
||||
std::string unit::image_mods() const{
|
||||
std::stringstream modifier;
|
||||
if(flag_rgb_.size()){
|
||||
|
17
src/unit.hpp
17
src/unit.hpp
@ -522,6 +522,23 @@ private:
|
||||
std::pair<map_location,unit> *temp_;
|
||||
};
|
||||
|
||||
/**
|
||||
* This object is used to temporary move a unit in the unit map, swapping out
|
||||
* any unit that is already there. On destruction, it restores the unit map to
|
||||
* its original.
|
||||
*/
|
||||
struct temporary_unit_mover
|
||||
{
|
||||
temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst);
|
||||
~temporary_unit_mover();
|
||||
|
||||
private:
|
||||
unit_map& m_;
|
||||
const map_location& src_;
|
||||
const map_location& dst_;
|
||||
std::pair<map_location,unit> *temp_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a checksum for a unit.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user