wb: fix moves for planned recruits

the for those moves get_unit() might return nullptr when it is
when the future map is not applied and some codes deduced from
that that the action is invalid. So we make sure that code does
not rely on get_unit().
This commit is contained in:
gfgtdf 2018-05-02 21:47:04 +02:00 committed by Charles Dang
parent c9df4bf02a
commit 04d0dcdf65
4 changed files with 12 additions and 7 deletions

View file

@ -73,7 +73,7 @@ public:
* Returns the id of the unit targeted by this action.
* @retval 0 no unit is targeted.
*/
std::size_t get_unit_id() const;
virtual std::size_t get_unit_id() const;
/** @return pointer to the fake unit used only for visuals */
virtual fake_unit_ptr get_fake_unit() = 0;

View file

@ -190,6 +190,9 @@ void highlighter::last_action_redraw(move_ptr move)
if(move->get_fake_unit()) {
side_actions& sa = *resources::gameboard->teams().at(move->team_index()).get_side_actions().get();
#if 0
// Disabled this since for moves of planned recruits get_unit() returns nullptr, een tough they are still valid.
// Units with planned actions may have been killed in the previous turn before all actions were completed.
// In these cases, remove these planned actions for any invalid units and do not redraw anything.
if (move->get_unit() == nullptr)
@ -204,8 +207,8 @@ void highlighter::last_action_redraw(move_ptr move)
return;
}
side_actions::iterator last_action = sa.find_last_action_of(*(move->get_unit()));
#endif
side_actions::iterator last_action = sa.find_last_action_of(move->get_unit_id());
side_actions::iterator second_to_last_action = last_action != sa.end() && last_action != sa.begin() ? last_action - 1 : sa.end();
bool this_is_last_action = last_action != sa.end() && move == *last_action;
@ -256,7 +259,7 @@ void highlighter::find_secondary_highlights()
action_ptr highlighter::get_execute_target()
{
if(action_ptr locked = selected_action_.lock()) {
return *side_actions_->find_first_action_of(*(locked->get_unit()));
return *side_actions_->find_first_action_of(locked->get_unit_id());
} else {
return action_ptr();
}
@ -264,7 +267,7 @@ action_ptr highlighter::get_execute_target()
action_ptr highlighter::get_delete_target()
{
if(action_ptr locked = selected_action_.lock()) {
return *side_actions_->find_last_action_of(*(locked->get_unit()));
return *side_actions_->find_last_action_of(locked->get_unit_id());
} else {
return action_ptr();
}

View file

@ -534,8 +534,9 @@ void manager::pre_draw()
for (std::size_t unit_id : units_owning_moves_) {
unit_map::iterator unit_iter = resources::gameboard->units().find(unit_id);
assert(unit_iter.valid());
ghost_owner_unit(&*unit_iter);
if(unit_iter.valid()) {
ghost_owner_unit(&*unit_iter);
}
}
}
}

View file

@ -53,6 +53,7 @@ public:
/** Return the unit targeted by this action. Null if unit doesn't exist. */
virtual unit_ptr get_unit() const;
virtual size_t get_unit_id() const { return unit_underlying_id_; }
/** @return pointer to the fake unit used only for visuals */
virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }