Skip to content

Commit

Permalink
wb: fix moves for planned recruits
Browse files Browse the repository at this point in the history
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().

(cherry-picked from commit 04d0dcd)
  • Loading branch information
gfgtdf authored and Vultraz committed Oct 7, 2018
1 parent 620cb03 commit 7c2df13
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/whiteboard/action.hpp
Expand Up @@ -73,7 +73,7 @@ class action : public std::enable_shared_from_this<action>
* 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;
Expand Down
11 changes: 7 additions & 4 deletions src/whiteboard/highlighter.cpp
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -256,15 +259,15 @@ 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();
}
}
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();
}
Expand Down
5 changes: 3 additions & 2 deletions src/whiteboard/manager.cpp
Expand Up @@ -535,8 +535,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);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/whiteboard/move.hpp
Expand Up @@ -53,6 +53,7 @@ class move : public action

/** 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_; }

Expand Down

0 comments on commit 7c2df13

Please sign in to comment.