diff options
| author | megamage <none@none> | 2009-08-23 14:20:07 -0500 |
|---|---|---|
| committer | megamage <none@none> | 2009-08-23 14:20:07 -0500 |
| commit | 08539ec0a4eabc903d8fbaf34aba465f20e0b698 (patch) | |
| tree | 8869c354aef81032c26aa085bd201b5ff94e8946 /src/game | |
| parent | 4a85a779c1c3fc26b0b7a61115fc2e5b47d1840f (diff) | |
*Rename some ai functions.
--HG--
branch : trunk
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/CombatAI.cpp (renamed from src/game/AggressorAI.cpp) | 89 | ||||
| -rw-r--r-- | src/game/CombatAI.h (renamed from src/game/AggressorAI.h) | 26 | ||||
| -rw-r--r-- | src/game/CreatureAIRegistry.cpp | 6 | ||||
| -rw-r--r-- | src/game/CreatureAISelector.cpp | 4 | ||||
| -rw-r--r-- | src/game/PassiveAI.cpp (renamed from src/game/NullCreatureAI.cpp) | 2 | ||||
| -rw-r--r-- | src/game/PassiveAI.h (renamed from src/game/NullCreatureAI.h) | 6 | ||||
| -rw-r--r-- | src/game/SpellMgr.h | 10 | ||||
| -rw-r--r-- | src/game/Unit.cpp | 2 |
8 files changed, 114 insertions, 31 deletions
diff --git a/src/game/AggressorAI.cpp b/src/game/CombatAI.cpp index 3ede976a229..89628ccef57 100644 --- a/src/game/AggressorAI.cpp +++ b/src/game/CombatAI.cpp @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "AggressorAI.h" +#include "CombatAI.h" #include "SpellMgr.h" int AggressorAI::Permissible(const Creature *creature) @@ -38,12 +38,12 @@ void AggressorAI::UpdateAI(const uint32 /*diff*/) DoMeleeAttackIfReady(); } -int SpellAI::Permissible(const Creature *creature) +int CombatAI::Permissible(const Creature *creature) { return PERMIT_BASE_NO; } -void SpellAI::InitializeAI() +void CombatAI::InitializeAI() { for(uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i) if(me->m_spells[i] && GetSpellStore()->LookupEntry(me->m_spells[i])) @@ -52,19 +52,19 @@ void SpellAI::InitializeAI() CreatureAI::InitializeAI(); } -void SpellAI::Reset() +void CombatAI::Reset() { events.Reset(); } -void SpellAI::JustDied(Unit *killer) +void CombatAI::JustDied(Unit *killer) { for(SpellVct::iterator i = spells.begin(); i != spells.end(); ++i) if(AISpellInfo[*i].condition == AICOND_DIE) me->CastSpell(killer, *i, true); } -void SpellAI::EnterCombat(Unit *who) +void CombatAI::EnterCombat(Unit *who) { for(SpellVct::iterator i = spells.begin(); i != spells.end(); ++i) { @@ -75,7 +75,7 @@ void SpellAI::EnterCombat(Unit *who) } } -void SpellAI::UpdateAI(const uint32 diff) +void CombatAI::UpdateAI(const uint32 diff) { if(!UpdateVictim()) return; @@ -94,25 +94,29 @@ void SpellAI::UpdateAI(const uint32 diff) DoMeleeAttackIfReady(); } -void SpellCasterAI::InitializeAI() + +///////////////// +//CasterAI +///////////////// + +void CasterAI::InitializeAI() { - SpellAI::InitializeAI(); + CombatAI::InitializeAI(); + float m_attackDist = 30.0f; for(SpellVct::iterator itr = spells.begin(); itr != spells.end(); ++itr) - { if (AISpellInfo[*itr].condition == AICOND_COMBAT && m_attackDist > GetAISpellInfo(*itr)->maxRange) m_attackDist = GetAISpellInfo(*itr)->maxRange; - } if (m_attackDist == 30.0f) m_attackDist = MELEE_RANGE; } -void SpellCasterAI::EnterCombat(Unit *who) +void CasterAI::EnterCombat(Unit *who) { if (spells.empty()) return; - uint32 spell = rand() % spells.size(); + uint32 spell = rand()%spells.size(); uint32 count = 0; for(SpellVct::iterator itr = spells.begin(); itr != spells.end(); ++itr, ++count) { @@ -131,7 +135,7 @@ void SpellCasterAI::EnterCombat(Unit *who) } } -void SpellCasterAI::UpdateAI(const uint32 diff) +void CasterAI::UpdateAI(const uint32 diff) { if(!UpdateVictim()) return; @@ -148,3 +152,60 @@ void SpellCasterAI::UpdateAI(const uint32 diff) events.ScheduleEvent(spellId, (casttime ? casttime : 500) + GetAISpellInfo(spellId)->realCooldown); } } + + +////////////// +//ArchorAI +////////////// + +ArchorAI::ArchorAI(Creature *c) : CreatureAI(c), m_canMelee(true) +{ + assert(me->m_spells[0]); + m_minRange = GetSpellMinRange(me->m_spells[0], false); + m_maxRange = GetSpellMaxRange(me->m_spells[0], false); + if(!m_minRange) + m_minRange = MELEE_RANGE; +} + +void ArchorAI::MoveInLineOfSight(Unit *who) +{ + if(!me->getVictim() && me->canAttack(who) + && me->IsWithinCombatRange(who, m_maxRange) + && me->IsWithinLOSInMap(who)) + AttackStart(who); +} + +void ArchorAI::AttackStart(Unit *who) +{ + if(who->IsFlying() || !me->IsWithinCombatRange(who, m_minRange)) + { + if(me->Attack(who, false)) + me->GetMotionMaster()->MoveIdle(); + } + else if(m_canMelee) + { + if(me->Attack(who, true)) + me->GetMotionMaster()->MoveChase(who); + } +} + +void ArchorAI::UpdateAI(const uint32 diff) +{ + if(!UpdateVictim()) + return; + + if(me->getVictim()->IsFlying() || !me->IsWithinCombatRange(me->getVictim(), m_minRange)) + { + if(!DoSpellAttackIfReady(me->m_spells[0])) + { + if(HostilReference *ref = me->getThreatManager().getCurrentVictim()) + ref->removeReference(); + else // i do not know when this could happen + EnterEvadeMode(); + } + } + else if(m_canMelee) + DoMeleeAttackIfReady(); + else if(HostilReference *ref = me->getThreatManager().getCurrentVictim()) + ref->removeReference(); +} diff --git a/src/game/AggressorAI.h b/src/game/CombatAI.h index cec11c0fb22..240d318d622 100644 --- a/src/game/AggressorAI.h +++ b/src/game/CombatAI.h @@ -18,8 +18,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef TRINITY_AGGRESSORAI_H -#define TRINITY_AGGRESSORAI_H +#ifndef TRINITY_COMBATAI_H +#define TRINITY_COMBATAI_H #include "CreatureAI.h" #include "CreatureAIImpl.h" @@ -37,10 +37,10 @@ class TRINITY_DLL_DECL AggressorAI : public CreatureAI typedef std::vector<uint32> SpellVct; -class TRINITY_DLL_SPEC SpellAI : public CreatureAI +class TRINITY_DLL_SPEC CombatAI : public CreatureAI { public: - explicit SpellAI(Creature *c) : CreatureAI(c) {} + explicit CombatAI(Creature *c) : CreatureAI(c) {} void InitializeAI(); void Reset(); @@ -53,16 +53,28 @@ class TRINITY_DLL_SPEC SpellAI : public CreatureAI SpellVct spells; }; -class TRINITY_DLL_SPEC SpellCasterAI : public SpellAI +class TRINITY_DLL_SPEC CasterAI : public CombatAI { public: - explicit SpellCasterAI(Creature *c) : SpellAI(c) {m_attackDist = MELEE_RANGE;} + explicit CasterAI(Creature *c) : CombatAI(c) { m_attackDist = MELEE_RANGE; } void InitializeAI(); - void AttackStart(Unit * victim){SpellAI::AttackStartCaster(victim, m_attackDist);} + void AttackStart(Unit * victim) { AttackStartCaster(victim, m_attackDist); } void UpdateAI(const uint32 diff); void EnterCombat(Unit *who); private: float m_attackDist; }; +struct TRINITY_DLL_SPEC ArchorAI : public CreatureAI +{ + public: + explicit ArchorAI(Creature *c); + void MoveInLineOfSight(Unit *who); + void AttackStart(Unit *who); + void UpdateAI(const uint32 diff); + protected: + float m_maxRange, m_minRange; + bool m_canMelee; +}; + #endif diff --git a/src/game/CreatureAIRegistry.cpp b/src/game/CreatureAIRegistry.cpp index 03c12afaaf6..f8d500cee59 100644 --- a/src/game/CreatureAIRegistry.cpp +++ b/src/game/CreatureAIRegistry.cpp @@ -18,9 +18,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "NullCreatureAI.h" +#include "PassiveAI.h" #include "ReactorAI.h" -#include "AggressorAI.h" +#include "CombatAI.h" #include "GuardAI.h" #include "PetAI.h" #include "TotemAI.h" @@ -45,7 +45,7 @@ namespace AIRegistry (new CreatureAIFactory<GuardAI>("GuardAI"))->RegisterSelf(); (new CreatureAIFactory<PetAI>("PetAI"))->RegisterSelf(); (new CreatureAIFactory<TotemAI>("TotemAI"))->RegisterSelf(); - (new CreatureAIFactory<SpellAI>("SpellAI"))->RegisterSelf(); + (new CreatureAIFactory<CombatAI>("CombatAI"))->RegisterSelf(); (new CreatureAIFactory<CreatureEventAI>("EventAI"))->RegisterSelf(); (new MovementGeneratorFactory<RandomMovementGenerator<Creature> >(RANDOM_MOTION_TYPE))->RegisterSelf(); diff --git a/src/game/CreatureAISelector.cpp b/src/game/CreatureAISelector.cpp index 68055bcddd3..b268391f260 100644 --- a/src/game/CreatureAISelector.cpp +++ b/src/game/CreatureAISelector.cpp @@ -20,7 +20,7 @@ #include "Creature.h" #include "CreatureAISelector.h" -#include "NullCreatureAI.h" +#include "PassiveAI.h" #include "Policies/SingletonImp.h" #include "MovementGenerator.h" #include "ScriptCalls.h" @@ -81,7 +81,7 @@ namespace FactorySelector { if(creature->m_spells[i]) { - ai_factory = ai_registry.GetRegistryItem("SpellAI"); + ai_factory = ai_registry.GetRegistryItem("CombatAI"); break; } } diff --git a/src/game/NullCreatureAI.cpp b/src/game/PassiveAI.cpp index cb06e1918ad..65d424e7bed 100644 --- a/src/game/NullCreatureAI.cpp +++ b/src/game/PassiveAI.cpp @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "NullCreatureAI.h" +#include "PassiveAI.h" #include "Creature.h" #include "TemporarySummon.h" diff --git a/src/game/NullCreatureAI.h b/src/game/PassiveAI.h index edc19f5cf57..19ea9938320 100644 --- a/src/game/NullCreatureAI.h +++ b/src/game/PassiveAI.h @@ -18,11 +18,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef TRINITY_NULLCREATUREAI_H -#define TRINITY_NULLCREATUREAI_H +#ifndef TRINITY_PASSIVEAI_H +#define TRINITY_PASSIVEAI_H #include "CreatureAI.h" -#include "CreatureAIImpl.h" +//#include "CreatureAIImpl.h" class TRINITY_DLL_SPEC PassiveAI : public CreatureAI { diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h index b8dca34edf0..4a3a4329b44 100644 --- a/src/game/SpellMgr.h +++ b/src/game/SpellMgr.h @@ -160,18 +160,28 @@ inline float GetSpellRadius(SpellEntry const *spellInfo, uint32 effectIdx, bool ? GetSpellRadiusForFriend(sSpellRadiusStore.LookupEntry(spellInfo->EffectRadiusIndex[effectIdx])) : GetSpellRadiusForHostile(sSpellRadiusStore.LookupEntry(spellInfo->EffectRadiusIndex[effectIdx])); } + inline float GetSpellMaxRange(SpellEntry const *spellInfo, bool positive) { return positive ? GetSpellMaxRangeForFriend(sSpellRangeStore.LookupEntry(spellInfo->rangeIndex)) : GetSpellMaxRangeForHostile(sSpellRangeStore.LookupEntry(spellInfo->rangeIndex)); } + inline float GetSpellMinRange(SpellEntry const *spellInfo, bool positive) { return positive ? GetSpellMinRangeForFriend(sSpellRangeStore.LookupEntry(spellInfo->rangeIndex)) : GetSpellMinRangeForHostile(sSpellRangeStore.LookupEntry(spellInfo->rangeIndex)); } + +inline float GetSpellMinRange(uint32 id, bool positive) +{ + SpellEntry const *spellInfo = GetSpellStore()->LookupEntry(id); + if(!spellInfo) return 0; + return GetSpellMinRange(spellInfo, positive); +} + inline float GetSpellMaxRange(uint32 id, bool positive) { SpellEntry const *spellInfo = GetSpellStore()->LookupEntry(id); diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 16fbbff3eb5..d55395bce52 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -48,7 +48,7 @@ #include "Path.h" #include "CreatureGroups.h" #include "PetAI.h" -#include "NullCreatureAI.h" +#include "PassiveAI.h" #include "Traveller.h" #include "TemporarySummon.h" #include "Vehicle.h" |
