From 7b43005f9bd63feaf8a49f6c1fa3f0d2ac6686b6 Mon Sep 17 00:00:00 2001 From: Dusknior Date: Tue, 2 Aug 2022 03:45:00 +0800 Subject: [PATCH] Fix the issue which may cause a trigger-operation effect repointed incorrectly. --- model/aoe2scenario.cpp | 40 +++++++++++++++++++++++++++------------- model/aoe2scenario.h | 2 +- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/model/aoe2scenario.cpp b/model/aoe2scenario.cpp index 0da3acd..be39fe3 100644 --- a/model/aoe2scenario.cpp +++ b/model/aoe2scenario.cpp @@ -413,26 +413,21 @@ namespace AoE2ScenarioNamespace { //sort to ensure the trigger which id is greater deleted first std::sort(list_deleted.begin(), list_deleted.end()); + //the trigger id which effect called should be repointed. + for (size_t i = 0; i < list_by_order.size(); ++i) + { + trigger_repoint(id_list[i], list_deleted); + } while (!list_deleted.empty()) { for (auto& trig_idx : list_by_order) { - //deleted id call shall repoint to -1 - trigger_repoint(id_list[trig_idx], list_deleted.back(), -1); //decrease the index which greater than deleted if (trig_idx > list_deleted.back()) { --trig_idx; } } - //decrease called id which greater than deleted - for (auto i = list_deleted.back() + 1; i < list_by_order.size(); ++i) - { - for (size_t j = 0; j < list_by_order.size(); ++j) - { - trigger_repoint(id_list[j], i, i - 1); - } - } id_list.erase(id_list.begin() + list_deleted.back()); list_deleted.pop_back(); } @@ -444,13 +439,32 @@ namespace AoE2ScenarioNamespace scen->body.Options.number_of_triggers = order_list.size(); scen->body.Triggers.number_of_triggers = order_list.size(); } - void TriggerManager::trigger_repoint(TriggerStruct& trig, uint32_t old_id, int32_t new_id) + void TriggerManager::trigger_repoint(TriggerStruct& trig, const vector& list_deleted_sorted) { for (auto& effect : trig.effect_data) { - if (effect.trigger_id == old_id) + if (effect.trigger_id != -1) { - effect.trigger_id = new_id; + for (size_t i = 0; i <= list_deleted_sorted.size(); ++i) + { + //decrease called id which greater than deleted + if (i == list_deleted_sorted.size()) + { + effect.trigger_id -= list_deleted_sorted.size(); + break; + } + if (effect.trigger_id < list_deleted_sorted[i]) + { + effect.trigger_id -= i; + break; + } + //deleted id call shall repoint to -1 + else if(effect.trigger_id == list_deleted_sorted[i]) + { + effect.trigger_id = -1; + break; + } + } } } } diff --git a/model/aoe2scenario.h b/model/aoe2scenario.h index 6815be3..bb87c9c 100644 --- a/model/aoe2scenario.h +++ b/model/aoe2scenario.h @@ -120,7 +120,7 @@ namespace AoE2ScenarioNamespace void load(); void confirm(); private: - void trigger_repoint(TriggerStruct& trig, uint32_t old_id, int32_t new_id); + void trigger_repoint(TriggerStruct& trig, const vector& list_deleted_sorted); void change_player(TriggerStruct& trig, int32_t base_player, int32_t player, uint32_t mode); void change_player_judge(int32_t base_player, int32_t player, uint32_t mode, int32_t& current_attr); void del(vector::iterator to_del);