aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2011-05-12 10:40:53 +0200
committerShauren <shauren.trinity@gmail.com>2011-05-12 10:40:53 +0200
commit339e8cb7e08295579fa21afbfd11ae620c78861f (patch)
tree55867fd8196c0c4e896900475938788a02f2fc65 /src
parentbca01dd419deff63cfc96a6126b0a820e5f8afde (diff)
Core/SAI/EAI: Pass struct parameters by reference instead of value, saves unneeded copying
Diffstat (limited to 'src')
-rwxr-xr-xsrc/server/game/AI/CoreAI/UnitAI.h4
-rwxr-xr-xsrc/server/game/AI/EventAI/CreatureEventAI.cpp12
-rwxr-xr-xsrc/server/game/AI/EventAI/CreatureEventAI.h2
-rwxr-xr-xsrc/server/game/AI/EventAI/CreatureEventAIMgr.cpp2
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp18
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.cpp4
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.h40
7 files changed, 43 insertions, 39 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h
index f64f25250c2..bfc87c8db8c 100755
--- a/src/server/game/AI/CoreAI/UnitAI.h
+++ b/src/server/game/AI/CoreAI/UnitAI.h
@@ -126,7 +126,7 @@ class UnitAI
Unit* SelectTarget(SelectAggroTarget targetType, uint32 position = 0, float dist = 0.0f, bool playerOnly = false, int32 aura = 0);
// Select the targets satifying the predicate.
// 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();
if (position >= threatlist.size())
@@ -176,7 +176,7 @@ class UnitAI
// Select the targets satifying the predicate.
// 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();
if (threatlist.empty())
diff --git a/src/server/game/AI/EventAI/CreatureEventAI.cpp b/src/server/game/AI/EventAI/CreatureEventAI.cpp
index f201fb9eb31..2dd99904ddf 100755
--- a/src/server/game/AI/EventAI/CreatureEventAI.cpp
+++ b/src/server/game/AI/EventAI/CreatureEventAI.cpp
@@ -350,14 +350,12 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
if (!action.text.TextId1)
return;
- int32 temp = 0;
+ int32 temp = action.text.TextId1;
if (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))
temp = action.text.TextId2;
- else
- temp = action.text.TextId1;
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)))
return false;
- SpellRangeEntry const *TempRange = NULL;
-
- TempRange = GetSpellRangeStore()->LookupEntry(Spell->rangeIndex);
+ SpellRangeEntry const* tempRange = sSpellRangeStore.LookupEntry(Spell->rangeIndex);
//Spell has invalid range store so we can't use it
- if (!TempRange)
+ if (!tempRange)
return false;
//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 true;
diff --git a/src/server/game/AI/EventAI/CreatureEventAI.h b/src/server/game/AI/EventAI/CreatureEventAI.h
index 7b8d3e04e9f..779e0d5ce37 100755
--- a/src/server/game/AI/EventAI/CreatureEventAI.h
+++ b/src/server/game/AI/EventAI/CreatureEventAI.h
@@ -577,7 +577,7 @@ typedef UNORDERED_MAP<uint32, CreatureEventAI_Summon> CreatureEventAI_Summon_Map
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;
uint32 Time;
diff --git a/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp b/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp
index a4bb08bf905..d0f02fc37ff 100755
--- a/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp
+++ b/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp
@@ -721,7 +721,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
break;
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;
}
}
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index 624e0e40da1..a00552865d0 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -1025,9 +1025,6 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
case SMART_ACTION_SUMMON_CREATURE:
{
- WorldObject* obj = GetBaseObject();
- if (!obj)
- obj = unit;
float x, y, z, o;
ObjectList* targets = GetTargets(e, unit);
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.repeatMax = e.action.timeEvent.repeatMax;
+ ne.event_flags = 0;
if (!ne.minMaxRepeat.repeatMin && !ne.minMaxRepeat.repeatMax)
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;
go = NULL;
me = (*itr)->ToCreature();
-
- delete targets;
- return;
+ break;
}
else if (IsGameObject(*itr))
{
@@ -1407,9 +1403,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
goOrigGUID = go ? go->GetGUID() : 0;
go = (*itr)->ToGameObject();
me = NULL;
-
- delete targets;
- return;
+ break;
}
}
@@ -1532,7 +1526,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (e.action.cast.flags & SMARTCAST_INTERRUPT_PREVIOUS)
(*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))
(*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())
return;
@@ -1814,7 +1808,7 @@ SmartScriptHolder SmartScript::CreateEvent(SMART_EVENT e, uint32 event_flags, ui
return script;
}
-ObjectList* SmartScript::GetTargets(SmartScriptHolder e, Unit* invoker)
+ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*= NULL*/)
{
Unit* trigger = NULL;
if (invoker)
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
index f63d433c278..61f118a9f93 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
@@ -221,7 +221,7 @@ void SmartAIMgr::LoadSmartAIFromDB()
sLog->outString();
}
-bool SmartAIMgr::IsTargetValid(SmartScriptHolder e)
+bool SmartAIMgr::IsTargetValid(SmartScriptHolder const& e)
{
if (e.GetActionType() == SMART_ACTION_INSTALL_AI_TEMPLATE)
return true; //AI template has special handling
@@ -780,7 +780,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder &e)
return true;
}
-bool SmartAIMgr::IsTextValid(SmartScriptHolder e, uint32 id)
+bool SmartAIMgr::IsTextValid(SmartScriptHolder const& e, uint32 id)
{
bool error = false;
uint32 entry = 0;
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
index 21cfb92a75a..239876a24d0 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
@@ -1225,7 +1225,8 @@ class SmartAIMgr
SmartAIEventMap mEventMap[SMART_SCRIPT_TYPE_MAX];
bool IsEventValid(SmartScriptHolder &e);
- bool IsTargetValid(SmartScriptHolder e);
+ bool IsTargetValid(SmartScriptHolder const& e);
+
/*inline bool IsTargetValid(SmartScriptHolder e, int32 target)
{
if (target < SMART_TARGET_NONE || target >= SMART_TARGET_END)
@@ -1235,7 +1236,8 @@ class SmartAIMgr
}
return true;
}*/
- inline bool IsMinMaxValid(SmartScriptHolder e, uint32 min, uint32 max)
+
+ bool IsMinMaxValid(SmartScriptHolder const& e, uint32 min, uint32 max)
{
if (max < min)
{
@@ -1244,6 +1246,7 @@ class SmartAIMgr
}
return true;
}
+
/*inline bool IsPercentValid(SmartScriptHolder e, int32 pct)
{
if (pct < -100 || pct > 100)
@@ -1253,7 +1256,8 @@ class SmartAIMgr
}
return true;
}*/
- inline bool NotNULL(SmartScriptHolder e, uint32 data)
+
+ bool NotNULL(SmartScriptHolder const& e, uint32 data)
{
if (!data)
{
@@ -1262,7 +1266,8 @@ class SmartAIMgr
}
return true;
}
- inline bool IsCreatureValid(SmartScriptHolder e, uint32 entry)
+
+ bool IsCreatureValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sObjectMgr->GetCreatureTemplate(entry))
{
@@ -1271,7 +1276,8 @@ class SmartAIMgr
}
return true;
}
- inline bool IsQuestValid(SmartScriptHolder e, uint32 entry)
+
+ bool IsQuestValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sObjectMgr->GetQuestTemplate(entry))
{
@@ -1280,7 +1286,8 @@ class SmartAIMgr
}
return true;
}
- inline bool IsGameObjectValid(SmartScriptHolder e, uint32 entry)
+
+ bool IsGameObjectValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sObjectMgr->GetGameObjectTemplate(entry))
{
@@ -1289,7 +1296,8 @@ class SmartAIMgr
}
return true;
}
- inline bool IsSpellValid(SmartScriptHolder e, uint32 entry)
+
+ bool IsSpellValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sSpellStore.LookupEntry(entry))
{
@@ -1298,7 +1306,8 @@ class SmartAIMgr
}
return true;
}
- inline bool IsItemValid(SmartScriptHolder e, uint32 entry)
+
+ bool IsItemValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sItemStore.LookupEntry(entry))
{
@@ -1327,7 +1336,8 @@ class SmartAIMgr
}
return true;
}*/
- inline bool IsTextEmoteValid(SmartScriptHolder e, uint32 entry)
+
+ bool IsTextEmoteValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sEmotesTextStore.LookupEntry(entry))
{
@@ -1336,7 +1346,8 @@ class SmartAIMgr
}
return true;
}
- inline bool IsEmoteValid(SmartScriptHolder e, uint32 entry)
+
+ bool IsEmoteValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sEmotesStore.LookupEntry(entry))
{
@@ -1345,7 +1356,8 @@ class SmartAIMgr
}
return true;
}
- inline bool IsAreaTriggerValid(SmartScriptHolder e, uint32 entry)
+
+ bool IsAreaTriggerValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sAreaTriggerStore.LookupEntry(entry))
{
@@ -1354,7 +1366,8 @@ class SmartAIMgr
}
return true;
}
- inline bool IsSoundValid(SmartScriptHolder e, uint32 entry)
+
+ bool IsSoundValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sSoundEntriesStore.LookupEntry(entry))
{
@@ -1363,7 +1376,8 @@ class SmartAIMgr
}
return true;
}
- bool IsTextValid(SmartScriptHolder e, uint32 id);
+
+ bool IsTextValid(SmartScriptHolder const& e, uint32 id);
};
#define sSmartScriptMgr ACE_Singleton<SmartAIMgr, ACE_Null_Mutex>::instance()