Core/SAI/EAI: Pass struct parameters by reference instead of value, saves unneeded copying
This commit is contained in:
@@ -126,7 +126,7 @@ class UnitAI
|
|||||||
Unit* SelectTarget(SelectAggroTarget targetType, uint32 position = 0, float dist = 0.0f, bool playerOnly = false, int32 aura = 0);
|
Unit* SelectTarget(SelectAggroTarget targetType, uint32 position = 0, float dist = 0.0f, bool playerOnly = false, int32 aura = 0);
|
||||||
// Select the targets satifying the predicate.
|
// Select the targets satifying the predicate.
|
||||||
// predicate shall extend std::unary_function<Unit* , bool>
|
// predicate shall extend std::unary_function<Unit* , bool>
|
||||||
template <class PREDICATE> Unit* SelectTarget(SelectAggroTarget targetType, uint32 position, PREDICATE predicate)
|
template <class PREDICATE> Unit* SelectTarget(SelectAggroTarget targetType, uint32 position, PREDICATE const& predicate)
|
||||||
{
|
{
|
||||||
const std::list<HostileReference* > &threatlist = me->getThreatManager().getThreatList();
|
const std::list<HostileReference* > &threatlist = me->getThreatManager().getThreatList();
|
||||||
if (position >= threatlist.size())
|
if (position >= threatlist.size())
|
||||||
@@ -176,7 +176,7 @@ class UnitAI
|
|||||||
|
|
||||||
// Select the targets satifying the predicate.
|
// Select the targets satifying the predicate.
|
||||||
// predicate shall extend std::unary_function<Unit* , bool>
|
// predicate shall extend std::unary_function<Unit* , bool>
|
||||||
template <class PREDICATE> void SelectTargetList(std::list<Unit*> &targetList, PREDICATE predicate, uint32 maxTargets, SelectAggroTarget targetType)
|
template <class PREDICATE> void SelectTargetList(std::list<Unit*> &targetList, PREDICATE const& predicate, uint32 maxTargets, SelectAggroTarget targetType)
|
||||||
{
|
{
|
||||||
std::list<HostileReference*> const& threatlist = me->getThreatManager().getThreatList();
|
std::list<HostileReference*> const& threatlist = me->getThreatManager().getThreatList();
|
||||||
if (threatlist.empty())
|
if (threatlist.empty())
|
||||||
|
|||||||
@@ -350,14 +350,12 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||||||
if (!action.text.TextId1)
|
if (!action.text.TextId1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 temp = 0;
|
int32 temp = action.text.TextId1;
|
||||||
|
|
||||||
if (action.text.TextId2 && action.text.TextId3)
|
if (action.text.TextId2 && action.text.TextId3)
|
||||||
temp = RAND(action.text.TextId1, action.text.TextId2, action.text.TextId3);
|
temp = RAND(action.text.TextId1, action.text.TextId2, action.text.TextId3);
|
||||||
else if (action.text.TextId2 && urand(0, 1))
|
else if (action.text.TextId2 && urand(0, 1))
|
||||||
temp = action.text.TextId2;
|
temp = action.text.TextId2;
|
||||||
else
|
|
||||||
temp = action.text.TextId1;
|
|
||||||
|
|
||||||
if (temp)
|
if (temp)
|
||||||
{
|
{
|
||||||
@@ -1320,16 +1318,14 @@ bool CreatureEventAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Trigge
|
|||||||
if (!Triggered && me->GetPower((Powers)Spell->powerType) < CalculatePowerCost(Spell, me, GetSpellSchoolMask(Spell)))
|
if (!Triggered && me->GetPower((Powers)Spell->powerType) < CalculatePowerCost(Spell, me, GetSpellSchoolMask(Spell)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SpellRangeEntry const *TempRange = NULL;
|
SpellRangeEntry const* tempRange = sSpellRangeStore.LookupEntry(Spell->rangeIndex);
|
||||||
|
|
||||||
TempRange = GetSpellRangeStore()->LookupEntry(Spell->rangeIndex);
|
|
||||||
|
|
||||||
//Spell has invalid range store so we can't use it
|
//Spell has invalid range store so we can't use it
|
||||||
if (!TempRange)
|
if (!tempRange)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//Unit is out of range of this spell
|
//Unit is out of range of this spell
|
||||||
if (!me->IsInRange(Target, TempRange->minRangeHostile, TempRange->maxRangeHostile))
|
if (!me->IsInRange(Target, tempRange->minRangeHostile, tempRange->maxRangeHostile))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -577,7 +577,7 @@ typedef UNORDERED_MAP<uint32, CreatureEventAI_Summon> CreatureEventAI_Summon_Map
|
|||||||
|
|
||||||
struct CreatureEventAIHolder
|
struct CreatureEventAIHolder
|
||||||
{
|
{
|
||||||
CreatureEventAIHolder(CreatureEventAI_Event p) : Event(p), Time(0), Enabled(true){}
|
CreatureEventAIHolder(CreatureEventAI_Event const& p) : Event(p), Time(0), Enabled(true){}
|
||||||
|
|
||||||
CreatureEventAI_Event Event;
|
CreatureEventAI_Event Event;
|
||||||
uint32 Time;
|
uint32 Time;
|
||||||
|
|||||||
@@ -721,7 +721,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sLog->outErrorDb("CreatureEventAI: Event %u Action %u have currently not checked at load action type (%u). Need check code update?", i, j+1, temp.action[j].type);
|
sLog->outErrorDb("CreatureEventAI: Event %u Action %u have currently not checked at load action type (%u). Need check code update?", i, j+1, action.type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1025,9 +1025,6 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
|||||||
}
|
}
|
||||||
case SMART_ACTION_SUMMON_CREATURE:
|
case SMART_ACTION_SUMMON_CREATURE:
|
||||||
{
|
{
|
||||||
WorldObject* obj = GetBaseObject();
|
|
||||||
if (!obj)
|
|
||||||
obj = unit;
|
|
||||||
float x, y, z, o;
|
float x, y, z, o;
|
||||||
ObjectList* targets = GetTargets(e, unit);
|
ObjectList* targets = GetTargets(e, unit);
|
||||||
if (targets)
|
if (targets)
|
||||||
@@ -1356,6 +1353,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
|||||||
ne.minMaxRepeat.repeatMin = e.action.timeEvent.repeatMin;
|
ne.minMaxRepeat.repeatMin = e.action.timeEvent.repeatMin;
|
||||||
ne.minMaxRepeat.repeatMax = e.action.timeEvent.repeatMax;
|
ne.minMaxRepeat.repeatMax = e.action.timeEvent.repeatMax;
|
||||||
|
|
||||||
|
ne.event_flags = 0;
|
||||||
if (!ne.minMaxRepeat.repeatMin && !ne.minMaxRepeat.repeatMax)
|
if (!ne.minMaxRepeat.repeatMin && !ne.minMaxRepeat.repeatMax)
|
||||||
ne.event_flags |= SMART_EVENT_FLAG_NOT_REPEATABLE;
|
ne.event_flags |= SMART_EVENT_FLAG_NOT_REPEATABLE;
|
||||||
|
|
||||||
@@ -1395,9 +1393,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
|||||||
goOrigGUID = go ? go->GetGUID() : 0;
|
goOrigGUID = go ? go->GetGUID() : 0;
|
||||||
go = NULL;
|
go = NULL;
|
||||||
me = (*itr)->ToCreature();
|
me = (*itr)->ToCreature();
|
||||||
|
break;
|
||||||
delete targets;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (IsGameObject(*itr))
|
else if (IsGameObject(*itr))
|
||||||
{
|
{
|
||||||
@@ -1407,9 +1403,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
|||||||
goOrigGUID = go ? go->GetGUID() : 0;
|
goOrigGUID = go ? go->GetGUID() : 0;
|
||||||
go = (*itr)->ToGameObject();
|
go = (*itr)->ToGameObject();
|
||||||
me = NULL;
|
me = NULL;
|
||||||
|
break;
|
||||||
delete targets;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1532,7 +1526,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
|||||||
if (e.action.cast.flags & SMARTCAST_INTERRUPT_PREVIOUS)
|
if (e.action.cast.flags & SMARTCAST_INTERRUPT_PREVIOUS)
|
||||||
(*itr)->ToUnit()->InterruptNonMeleeSpells(false);
|
(*itr)->ToUnit()->InterruptNonMeleeSpells(false);
|
||||||
|
|
||||||
for (ObjectList::const_iterator it = targets->begin(); it != targets->end(); it++)
|
for (ObjectList::const_iterator it = targets->begin(); it != targets->end(); ++it)
|
||||||
if (IsUnit(*it))
|
if (IsUnit(*it))
|
||||||
(*itr)->ToUnit()->CastSpell((*it)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) ? true : false);
|
(*itr)->ToUnit()->CastSpell((*it)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) ? true : false);
|
||||||
}
|
}
|
||||||
@@ -1708,7 +1702,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmartScript::InstallTemplate(SmartScriptHolder e)
|
void SmartScript::InstallTemplate(SmartScriptHolder const& e)
|
||||||
{
|
{
|
||||||
if (!GetBaseObject())
|
if (!GetBaseObject())
|
||||||
return;
|
return;
|
||||||
@@ -1814,7 +1808,7 @@ SmartScriptHolder SmartScript::CreateEvent(SMART_EVENT e, uint32 event_flags, ui
|
|||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectList* SmartScript::GetTargets(SmartScriptHolder e, Unit* invoker)
|
ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*= NULL*/)
|
||||||
{
|
{
|
||||||
Unit* trigger = NULL;
|
Unit* trigger = NULL;
|
||||||
if (invoker)
|
if (invoker)
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ void SmartAIMgr::LoadSmartAIFromDB()
|
|||||||
sLog->outString();
|
sLog->outString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SmartAIMgr::IsTargetValid(SmartScriptHolder e)
|
bool SmartAIMgr::IsTargetValid(SmartScriptHolder const& e)
|
||||||
{
|
{
|
||||||
if (e.GetActionType() == SMART_ACTION_INSTALL_AI_TEMPLATE)
|
if (e.GetActionType() == SMART_ACTION_INSTALL_AI_TEMPLATE)
|
||||||
return true; //AI template has special handling
|
return true; //AI template has special handling
|
||||||
@@ -780,7 +780,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder &e)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SmartAIMgr::IsTextValid(SmartScriptHolder e, uint32 id)
|
bool SmartAIMgr::IsTextValid(SmartScriptHolder const& e, uint32 id)
|
||||||
{
|
{
|
||||||
bool error = false;
|
bool error = false;
|
||||||
uint32 entry = 0;
|
uint32 entry = 0;
|
||||||
|
|||||||
@@ -1225,7 +1225,8 @@ class SmartAIMgr
|
|||||||
SmartAIEventMap mEventMap[SMART_SCRIPT_TYPE_MAX];
|
SmartAIEventMap mEventMap[SMART_SCRIPT_TYPE_MAX];
|
||||||
|
|
||||||
bool IsEventValid(SmartScriptHolder &e);
|
bool IsEventValid(SmartScriptHolder &e);
|
||||||
bool IsTargetValid(SmartScriptHolder e);
|
bool IsTargetValid(SmartScriptHolder const& e);
|
||||||
|
|
||||||
/*inline bool IsTargetValid(SmartScriptHolder e, int32 target)
|
/*inline bool IsTargetValid(SmartScriptHolder e, int32 target)
|
||||||
{
|
{
|
||||||
if (target < SMART_TARGET_NONE || target >= SMART_TARGET_END)
|
if (target < SMART_TARGET_NONE || target >= SMART_TARGET_END)
|
||||||
@@ -1235,7 +1236,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}*/
|
}*/
|
||||||
inline bool IsMinMaxValid(SmartScriptHolder e, uint32 min, uint32 max)
|
|
||||||
|
bool IsMinMaxValid(SmartScriptHolder const& e, uint32 min, uint32 max)
|
||||||
{
|
{
|
||||||
if (max < min)
|
if (max < min)
|
||||||
{
|
{
|
||||||
@@ -1244,6 +1246,7 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*inline bool IsPercentValid(SmartScriptHolder e, int32 pct)
|
/*inline bool IsPercentValid(SmartScriptHolder e, int32 pct)
|
||||||
{
|
{
|
||||||
if (pct < -100 || pct > 100)
|
if (pct < -100 || pct > 100)
|
||||||
@@ -1253,7 +1256,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}*/
|
}*/
|
||||||
inline bool NotNULL(SmartScriptHolder e, uint32 data)
|
|
||||||
|
bool NotNULL(SmartScriptHolder const& e, uint32 data)
|
||||||
{
|
{
|
||||||
if (!data)
|
if (!data)
|
||||||
{
|
{
|
||||||
@@ -1262,7 +1266,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool IsCreatureValid(SmartScriptHolder e, uint32 entry)
|
|
||||||
|
bool IsCreatureValid(SmartScriptHolder const& e, uint32 entry)
|
||||||
{
|
{
|
||||||
if (!sObjectMgr->GetCreatureTemplate(entry))
|
if (!sObjectMgr->GetCreatureTemplate(entry))
|
||||||
{
|
{
|
||||||
@@ -1271,7 +1276,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool IsQuestValid(SmartScriptHolder e, uint32 entry)
|
|
||||||
|
bool IsQuestValid(SmartScriptHolder const& e, uint32 entry)
|
||||||
{
|
{
|
||||||
if (!sObjectMgr->GetQuestTemplate(entry))
|
if (!sObjectMgr->GetQuestTemplate(entry))
|
||||||
{
|
{
|
||||||
@@ -1280,7 +1286,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool IsGameObjectValid(SmartScriptHolder e, uint32 entry)
|
|
||||||
|
bool IsGameObjectValid(SmartScriptHolder const& e, uint32 entry)
|
||||||
{
|
{
|
||||||
if (!sObjectMgr->GetGameObjectTemplate(entry))
|
if (!sObjectMgr->GetGameObjectTemplate(entry))
|
||||||
{
|
{
|
||||||
@@ -1289,7 +1296,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool IsSpellValid(SmartScriptHolder e, uint32 entry)
|
|
||||||
|
bool IsSpellValid(SmartScriptHolder const& e, uint32 entry)
|
||||||
{
|
{
|
||||||
if (!sSpellStore.LookupEntry(entry))
|
if (!sSpellStore.LookupEntry(entry))
|
||||||
{
|
{
|
||||||
@@ -1298,7 +1306,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool IsItemValid(SmartScriptHolder e, uint32 entry)
|
|
||||||
|
bool IsItemValid(SmartScriptHolder const& e, uint32 entry)
|
||||||
{
|
{
|
||||||
if (!sItemStore.LookupEntry(entry))
|
if (!sItemStore.LookupEntry(entry))
|
||||||
{
|
{
|
||||||
@@ -1327,7 +1336,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}*/
|
}*/
|
||||||
inline bool IsTextEmoteValid(SmartScriptHolder e, uint32 entry)
|
|
||||||
|
bool IsTextEmoteValid(SmartScriptHolder const& e, uint32 entry)
|
||||||
{
|
{
|
||||||
if (!sEmotesTextStore.LookupEntry(entry))
|
if (!sEmotesTextStore.LookupEntry(entry))
|
||||||
{
|
{
|
||||||
@@ -1336,7 +1346,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool IsEmoteValid(SmartScriptHolder e, uint32 entry)
|
|
||||||
|
bool IsEmoteValid(SmartScriptHolder const& e, uint32 entry)
|
||||||
{
|
{
|
||||||
if (!sEmotesStore.LookupEntry(entry))
|
if (!sEmotesStore.LookupEntry(entry))
|
||||||
{
|
{
|
||||||
@@ -1345,7 +1356,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool IsAreaTriggerValid(SmartScriptHolder e, uint32 entry)
|
|
||||||
|
bool IsAreaTriggerValid(SmartScriptHolder const& e, uint32 entry)
|
||||||
{
|
{
|
||||||
if (!sAreaTriggerStore.LookupEntry(entry))
|
if (!sAreaTriggerStore.LookupEntry(entry))
|
||||||
{
|
{
|
||||||
@@ -1354,7 +1366,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool IsSoundValid(SmartScriptHolder e, uint32 entry)
|
|
||||||
|
bool IsSoundValid(SmartScriptHolder const& e, uint32 entry)
|
||||||
{
|
{
|
||||||
if (!sSoundEntriesStore.LookupEntry(entry))
|
if (!sSoundEntriesStore.LookupEntry(entry))
|
||||||
{
|
{
|
||||||
@@ -1363,7 +1376,8 @@ class SmartAIMgr
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool IsTextValid(SmartScriptHolder e, uint32 id);
|
|
||||||
|
bool IsTextValid(SmartScriptHolder const& e, uint32 id);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define sSmartScriptMgr ACE_Singleton<SmartAIMgr, ACE_Null_Mutex>::instance()
|
#define sSmartScriptMgr ACE_Singleton<SmartAIMgr, ACE_Null_Mutex>::instance()
|
||||||
|
|||||||
Reference in New Issue
Block a user