Skip to content

Commit

Permalink
Fix the issue which may cause a trigger-operation effect repointed in…
Browse files Browse the repository at this point in the history
…correctly.
  • Loading branch information
MegaDusknoir committed Aug 1, 2022
1 parent 39bdaf2 commit 7b43005
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
40 changes: 27 additions & 13 deletions model/aoe2scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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<TriggerStructIdx>& 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;
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion model/aoe2scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<TriggerStructIdx>& 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<TriggerStructIdx>::iterator to_del);
Expand Down

0 comments on commit 7b43005

Please sign in to comment.