diff --git a/src/LuaEngine/methods/CreatureMethods.h b/src/LuaEngine/methods/CreatureMethods.h index f96ad37681..101bb49dfa 100644 --- a/src/LuaEngine/methods/CreatureMethods.h +++ b/src/LuaEngine/methods/CreatureMethods.h @@ -649,18 +649,18 @@ namespace LuaCreature float dist = ALE::CHECKVAL(L, 5, 0.0f); int32 aura = ALE::CHECKVAL(L, 6, 0); - auto const& threatlist = creature->GetThreatMgr().GetThreatList(); + ThreatManager const& threatMgr = creature->GetThreatMgr(); - if (threatlist.empty()) + if (threatMgr.IsThreatListEmpty()) return 1; - if (position >= threatlist.size()) + if (position >= threatMgr.GetThreatListSize()) return 1; std::list targetList; - for (auto itr = threatlist.begin(); itr != threatlist.end(); ++itr) + for (ThreatReference const* ref : threatMgr.GetSortedThreatList()) { - Unit* target = (*itr)->getTarget(); + Unit* target = ref->GetVictim(); if (!target) continue; @@ -730,19 +730,14 @@ namespace LuaCreature */ int GetAITargets(lua_State* L, Creature* creature) { - auto const& threatlist = creature->GetThreatMgr().GetThreatList(); + ThreatManager const& threatMgr = creature->GetThreatMgr(); - lua_createtable(L, threatlist.size(), 0); + lua_createtable(L, threatMgr.GetThreatListSize(), 0); int tbl = lua_gettop(L); uint32 i = 0; - for (auto itr = threatlist.begin(); itr != threatlist.end(); ++itr) + for (ThreatReference const* ref : threatMgr.GetSortedThreatList()) { - Unit* target = (*itr)->getTarget(); - - if (!target) - continue; - - ALE::Push(L, target); + ALE::Push(L, ref->GetVictim()); lua_rawseti(L, tbl, ++i); } diff --git a/src/LuaEngine/methods/UnitMethods.h b/src/LuaEngine/methods/UnitMethods.h index 9e135f4e96..1ded5af420 100644 --- a/src/LuaEngine/methods/UnitMethods.h +++ b/src/LuaEngine/methods/UnitMethods.h @@ -1885,17 +1885,11 @@ namespace LuaUnit return 1; } - ThreatContainer::StorageType const& list = unit->GetThreatMgr().GetThreatList(); - lua_newtable(L); int table = lua_gettop(L); uint32 i = 1; - for (ThreatReference* item : list) + for (ThreatReference const* item : unit->GetThreatMgr().GetSortedThreatList()) { - if (!item) - { - continue; - } Unit* victim = item->GetVictim(); if (!victim) {