wb: fix moved becoming invalid after recruit is executed 2

turned out 8bdccca7 was not enough because the mapbuilder erroneously
reset the units movement to full directly before it was applied. Since
the `resetters_` code in mapbuilder.cpp does not apply to
recruited/recalled units, we also have to reset the units mp in
remove_temp_modifier.
This commit is contained in:
gfgtdf 2018-05-05 12:24:32 +02:00
parent 688edfa5ee
commit 7d97591f1d
6 changed files with 15 additions and 2 deletions

View file

@ -69,6 +69,8 @@ public:
/** Return the unit targeted by this action. Null if unit doesn't exist. */
virtual unit_ptr get_unit() const = 0;
/** Returns true for recall and recruit actions */
virtual bool places_new_unit() const { return false; };
/**
* Returns the id of the unit targeted by this action.
* @retval 0 no unit is targeted.

View file

@ -122,7 +122,8 @@ void mapbuilder::process(side_actions &sa, side_actions::iterator action_it)
return;
}
if(acted_this_turn_.find(unit.get()) == acted_this_turn_.end()) {
if(acted_this_turn_.find(unit.get()) == acted_this_turn_.end() && !action->places_new_unit()) {
//reset MP
unit->set_movement(unit->total_movement());
acted=true;
@ -162,7 +163,7 @@ void mapbuilder::process(side_actions &sa, side_actions::iterator action_it)
has_invalid_actions_.erase(invalid_it);
}
if(acted) {
if(acted || action->places_new_unit()) {
acted_this_turn_.insert(unit.get());
}

View file

@ -169,6 +169,9 @@ void recall::remove_temp_modifier(unit_map& unit_map)
temp_unit_ = unit_map.extract(recall_hex_);
assert(temp_unit_.get());
temp_unit_->set_movement(0, true);
temp_unit_->set_attacks(0);
//Put unit back into recall list
resources::gameboard->teams().at(team_index()).recall_list().add(temp_unit_);
}

View file

@ -62,6 +62,7 @@ public:
/** @return pointer to a copy of the recall unit. */
virtual unit_ptr get_unit() const { return temp_unit_; }
virtual bool places_new_unit() const { return true; }
/** @return pointer to the fake unit used only for visuals */
virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }

View file

@ -153,6 +153,11 @@ void recruit::remove_temp_modifier(unit_map& unit_map)
{
//Unit map gives back ownership of temp_unit_
temp_unit_ = unit_map.extract(recruit_hex_);
//remove simulated unit refresh on new turn done by mapbuilder.
temp_unit_->set_movement(0, true);
temp_unit_->set_attacks(0);
assert(temp_unit_.get());
}

View file

@ -67,6 +67,7 @@ public:
/** @return pointer to a fake unit representing the one that will eventually be recruited. */
virtual unit_ptr get_unit() const { return temp_unit_; }
virtual bool places_new_unit() const { return true; }
/** @return pointer to the fake unit used only for visuals */
virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }