From 0745eb94a396e292fc83a3bb60107347c800f22f Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Wed, 2 May 2018 21:47:04 +0200 Subject: [PATCH] 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(). --- src/whiteboard/action.hpp | 2 +- src/whiteboard/highlighter.cpp | 11 +++++++---- src/whiteboard/manager.cpp | 5 +++-- src/whiteboard/move.hpp | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/whiteboard/action.hpp b/src/whiteboard/action.hpp index 603078510b31..41f73bd935fa 100644 --- a/src/whiteboard/action.hpp +++ b/src/whiteboard/action.hpp @@ -73,7 +73,7 @@ class action : public std::enable_shared_from_this * Returns the id of the unit targeted by this action. * @retval 0 no unit is targeted. */ - size_t get_unit_id() const; + virtual size_t get_unit_id() const; /** @return pointer to the fake unit used only for visuals */ virtual fake_unit_ptr get_fake_unit() = 0; diff --git a/src/whiteboard/highlighter.cpp b/src/whiteboard/highlighter.cpp index bc43c0a975bb..a81f797dffb5 100644 --- a/src/whiteboard/highlighter.cpp +++ b/src/whiteboard/highlighter.cpp @@ -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(); } diff --git a/src/whiteboard/manager.cpp b/src/whiteboard/manager.cpp index 553c2933e435..b1bd632c5960 100644 --- a/src/whiteboard/manager.cpp +++ b/src/whiteboard/manager.cpp @@ -535,8 +535,9 @@ void manager::pre_draw() for (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); + } } } } diff --git a/src/whiteboard/move.hpp b/src/whiteboard/move.hpp index 135dc9636140..47dd2718cc1b 100644 --- a/src/whiteboard/move.hpp +++ b/src/whiteboard/move.hpp @@ -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_; }