From a8cfca2aabcd30eeb31dcc75108efa4d67167271 Mon Sep 17 00:00:00 2001 From: Steve Cotton Date: Mon, 15 Jan 2024 05:08:22 +0100 Subject: [PATCH] Make event_test_filter_condition check when the filters run Also add the missing first_time_only=no, which is why the three [moveto] events didn't trigger the third event three times. --- .../EventWML/events-test_filters.cfg | 36 ++++++++----- src/game_board.cpp | 51 ++++--------------- src/game_board.hpp | 12 ++--- src/mouse_events.cpp | 2 +- src/units/map.cpp | 3 ++ src/whiteboard/move.cpp | 2 +- 6 files changed, 41 insertions(+), 65 deletions(-) diff --git a/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filters.cfg b/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filters.cfg index 19c1fcd001a65..906c0bfea35c4 100644 --- a/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filters.cfg +++ b/data/test/scenarios/wml_tests/ScenarioWML/EventWML/events-test_filters.cfg @@ -10,58 +10,70 @@ # The third moveto event's condition is enabled by the second moveto event. ## # Expected end state: -# All three moveto events each trigger once. +# All three moveto events each trigger once when the first move happens. +# A second move (without resetting the condition) triggers the third moveto again. ##### {GENERIC_UNIT_TEST event_test_filter_condition ( [event] name=start {VARIABLE var 1} - {VARIABLE triggers 0} + {VARIABLE triggers_first 0} + {VARIABLE triggers_second 0} + {VARIABLE triggers_third 0} + + # A single move triggers all three events, because the filter for the second + # event is tested after the first event has already run. [do_command] [move] x=7,8 y=3,3 [/move] [/do_command] + {ASSERT ({VARIABLE_CONDITIONAL triggers_first equals 1})} + {ASSERT ({VARIABLE_CONDITIONAL triggers_second equals 1})} + {ASSERT ({VARIABLE_CONDITIONAL triggers_third equals 1})} + + # At this point var equals 3, so only the third event triggers. [do_command] [move] x=8,9 y=3,4 [/move] [/do_command] - [do_command] - [move] - x=9,8 - y=4,4 - [/move] - [/do_command] - {RETURN ({VARIABLE_CONDITIONAL triggers equals 3})} + {ASSERT ({VARIABLE_CONDITIONAL triggers_first equals 1})} + {ASSERT ({VARIABLE_CONDITIONAL triggers_second equals 1})} + {ASSERT ({VARIABLE_CONDITIONAL triggers_third equals 2})} + + {SUCCEED} [/event] [event] name=moveto + first_time_only=no [filter_condition] {VARIABLE_CONDITIONAL var equals 1} [/filter_condition] {ASSERT ({VARIABLE_CONDITIONAL var equals 1})} {VARIABLE var 2} - {VARIABLE_OP triggers add 1} + {VARIABLE_OP triggers_first add 1} [/event] [event] name=moveto + first_time_only=no [filter_condition] {VARIABLE_CONDITIONAL var equals 2} [/filter_condition] {ASSERT ({VARIABLE_CONDITIONAL var equals 2})} {VARIABLE var 3} - {VARIABLE_OP triggers add 1} + {VARIABLE_OP triggers_second add 1} [/event] [event] name=moveto + first_time_only=no [filter_condition] {VARIABLE_CONDITIONAL var equals 3} [/filter_condition] {ASSERT ({VARIABLE_CONDITIONAL var equals 3})} - {VARIABLE_OP triggers add 1} + {VARIABLE_OP triggers_third add 1} [/event] )} diff --git a/src/game_board.cpp b/src/game_board.cpp index 8f336cc0c5cb0..a96a24649d6e9 100644 --- a/src/game_board.cpp +++ b/src/game_board.cpp @@ -20,6 +20,7 @@ #include "preferences/game.hpp" #include "recall_list_manager.hpp" #include "units/unit.hpp" +#include "units/animation_component.hpp" #include "utils/general.hpp" #include @@ -470,12 +471,13 @@ temporary_unit_remover::~temporary_unit_remover() * the unit is moved (and restored to its previous value upon this object's * destruction). */ -temporary_unit_mover::temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst, int new_moves) +temporary_unit_mover::temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst, int new_moves, bool stand) : m_(m) , src_(src) , dst_(dst) , old_moves_(-1) , temp_(src == dst ? unit_ptr() : m_.extract(dst)) + , stand_(stand) { auto [iter, success] = m_.move(src_, dst_); @@ -483,50 +485,12 @@ temporary_unit_mover::temporary_unit_mover(unit_map& m, const map_location& src, if(success) { old_moves_ = iter->movement_left(true); iter->set_movement(new_moves); + if(stand_) { + m_.find_unit_ptr(dst_)->anim_comp().set_standing(); + } } } -temporary_unit_mover::temporary_unit_mover( - game_board& b, const map_location& src, const map_location& dst, int new_moves) - : m_(b.units_) - , src_(src) - , dst_(dst) - , old_moves_(-1) - , temp_(src == dst ? unit_ptr() : m_.extract(dst)) -{ - auto [iter, success] = m_.move(src_, dst_); - - // Set the movement. - if(success) { - old_moves_ = iter->movement_left(true); - iter->set_movement(new_moves); - } -} - -/** - * Constructor - * This version does not change (nor restore) the unit's movement. - */ -temporary_unit_mover::temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst) - : m_(m) - , src_(src) - , dst_(dst) - , old_moves_(-1) - , temp_(src == dst ? unit_ptr() : m_.extract(dst)) -{ - m_.move(src_, dst_); -} - -temporary_unit_mover::temporary_unit_mover(game_board& b, const map_location& src, const map_location& dst) - : m_(b.units_) - , src_(src) - , dst_(dst) - , old_moves_(-1) - , temp_(src == dst ? unit_ptr() : m_.extract(dst)) -{ - m_.move(src_, dst_); -} - temporary_unit_mover::~temporary_unit_mover() { try { @@ -535,6 +499,9 @@ temporary_unit_mover::~temporary_unit_mover() // Restore the movement? if(success && old_moves_ >= 0) { iter->set_movement(old_moves_); + if(stand_) { + m_.find_unit_ptr(src_)->anim_comp().set_standing(); + } } // Restore the extracted unit? diff --git a/src/game_board.hpp b/src/game_board.hpp index 1179a189af282..2560ea5021961 100644 --- a/src/game_board.hpp +++ b/src/game_board.hpp @@ -229,15 +229,8 @@ struct temporary_unit_remover */ struct temporary_unit_mover { - temporary_unit_mover(unit_map& m, const map_location& src, - const map_location& dst, int new_moves); - temporary_unit_mover(unit_map& m, const map_location& src, - const map_location& dst); - temporary_unit_mover(game_board& b, const map_location& src, - const map_location& dst, int new_moves); - temporary_unit_mover(game_board& b, const map_location& src, - const map_location& dst); - virtual ~temporary_unit_mover(); + temporary_unit_mover(unit_map& m, const map_location& src, const map_location& dst, int new_moves, bool stand); + virtual ~temporary_unit_mover(); private: unit_map& m_; @@ -245,4 +238,5 @@ struct temporary_unit_mover const map_location dst_; int old_moves_; unit_ptr temp_; + bool stand_; }; diff --git a/src/mouse_events.cpp b/src/mouse_events.cpp index 5e15510bebef8..62576c4c5a2e8 100644 --- a/src/mouse_events.cpp +++ b/src/mouse_events.cpp @@ -935,7 +935,7 @@ void mouse_handler::move_action(bool browse) // block where we temporary move the unit { - temporary_unit_mover temp_mover(pc_.get_units(), src, attack_from, itor->move_left); + temporary_unit_mover temp_mover(pc_.get_units(), src, attack_from, itor->move_left, true); choice = show_attack_dialog(attack_from, clicked_u->get_location()); } diff --git a/src/units/map.cpp b/src/units/map.cpp index 553796b4b0daf..9dbc33582a796 100644 --- a/src/units/map.cpp +++ b/src/units/map.cpp @@ -14,6 +14,7 @@ See the COPYING file for more details. */ +#include "display.hpp" #include "log.hpp" #include "units/id.hpp" #include "units/unit.hpp" @@ -126,6 +127,8 @@ unit_map::umap_retval_pair_t unit_map::move(const map_location& src, const map_l return std::pair(make_unit_iterator(uit), false); } + display::get_singleton()->invalidate(src); + self_check(); return std::pair(make_unit_iterator(uit), true); diff --git a/src/whiteboard/move.cpp b/src/whiteboard/move.cpp index a2ed86c66e5f9..1ef28b6b1c655 100644 --- a/src/whiteboard/move.cpp +++ b/src/whiteboard/move.cpp @@ -364,7 +364,7 @@ void move::apply_temp_modifier(unit_map& unit_map) // Move the unit DBG_WB << "Move: Temporarily moving unit " << unit->name() << " [" << unit->id() << "] from (" << get_source_hex() << ") to (" << get_dest_hex() <<")"; - mover_.reset(new temporary_unit_mover(unit_map, get_source_hex(), get_dest_hex(), calculate_moves_left(*unit))); + mover_.reset(new temporary_unit_mover(unit_map, get_source_hex(), get_dest_hex(), calculate_moves_left(*unit), false)); //Update status of fake unit (not undone by remove_temp_modifiers) //@todo this contradicts the name "temp_modifiers"