diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bindings/scripts/include/precompiled.h | 4 | ||||
-rw-r--r-- | src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/chapter1.cpp | 8 | ||||
-rw-r--r-- | src/bindings/scripts/scripts/northrend/naxxramas/boss_gothik.cpp | 10 | ||||
-rw-r--r-- | src/bindings/scripts/scripts/world/npcs_special.cpp | 14 | ||||
-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 |
12 files changed, 132 insertions, 49 deletions
diff --git a/src/bindings/scripts/include/precompiled.h b/src/bindings/scripts/include/precompiled.h index fa676f460ef..b468fbfc2f9 100644 --- a/src/bindings/scripts/include/precompiled.h +++ b/src/bindings/scripts/include/precompiled.h @@ -15,8 +15,8 @@ #include "sc_creature.h" #include "sc_gossip.h" #include "sc_instance.h" -#include "AggressorAI.h" -#include "NullCreatureAI.h" +#include "CombatAI.h" +#include "PassiveAI.h" #ifdef WIN32 #include <windows.h> diff --git a/src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/chapter1.cpp b/src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/chapter1.cpp index 2e8ed47b6fa..9b1b7db6bdd 100644 --- a/src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/chapter1.cpp +++ b/src/bindings/scripts/scripts/eastern_kingdoms/scarlet_enclave/chapter1.cpp @@ -336,9 +336,9 @@ int32 m_auiRandomSay[] = SAY_DUEL_A, SAY_DUEL_B, SAY_DUEL_C, SAY_DUEL_D, SAY_DUEL_E, SAY_DUEL_F, SAY_DUEL_G, SAY_DUEL_H, SAY_DUEL_I }; -struct TRINITY_DLL_DECL npc_death_knight_initiateAI : public SpellAI +struct TRINITY_DLL_DECL npc_death_knight_initiateAI : public CombatAI { - npc_death_knight_initiateAI(Creature* pCreature) : SpellAI(pCreature) + npc_death_knight_initiateAI(Creature* pCreature) : CombatAI(pCreature) { m_bIsDuelInProgress = false; } @@ -352,7 +352,7 @@ struct TRINITY_DLL_DECL npc_death_knight_initiateAI : public SpellAI { lose = false; me->RestoreFaction(); - SpellAI::Reset(); + CombatAI::Reset(); m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_15); @@ -432,7 +432,7 @@ struct TRINITY_DLL_DECL npc_death_knight_initiateAI : public SpellAI // TODO: spells - SpellAI::UpdateAI(uiDiff); + CombatAI::UpdateAI(uiDiff); } }; diff --git a/src/bindings/scripts/scripts/northrend/naxxramas/boss_gothik.cpp b/src/bindings/scripts/scripts/northrend/naxxramas/boss_gothik.cpp index f98e7667e6e..1b9aac9743d 100644 --- a/src/bindings/scripts/scripts/northrend/naxxramas/boss_gothik.cpp +++ b/src/bindings/scripts/scripts/northrend/naxxramas/boss_gothik.cpp @@ -249,9 +249,9 @@ struct TRINITY_DLL_DECL boss_gothikAI : public BossAI } }; -struct TRINITY_DLL_DECL mob_gothik_minionAI : public SpellAI +struct TRINITY_DLL_DECL mob_gothik_minionAI : public CombatAI { - mob_gothik_minionAI(Creature *c) : SpellAI(c) + mob_gothik_minionAI(Creature *c) : CombatAI(c) { liveSide = me->GetPositionY() < POS_Y_GATE; } @@ -277,7 +277,7 @@ struct TRINITY_DLL_DECL mob_gothik_minionAI : public SpellAI if (me->isSummon()) { if (Unit *owner = CAST_SUM(me)->GetSummoner()) - SpellAI::JustDied(owner); + CombatAI::JustDied(owner); } } @@ -285,7 +285,7 @@ struct TRINITY_DLL_DECL mob_gothik_minionAI : public SpellAI { if (!gateClose) { - SpellAI::EnterEvadeMode(); + CombatAI::EnterEvadeMode(); return; } @@ -318,7 +318,7 @@ struct TRINITY_DLL_DECL mob_gothik_minionAI : public SpellAI return; } - SpellAI::UpdateAI(diff); + CombatAI::UpdateAI(diff); } }; diff --git a/src/bindings/scripts/scripts/world/npcs_special.cpp b/src/bindings/scripts/scripts/world/npcs_special.cpp index 20f4f7d7808..8c6d6eee169 100644 --- a/src/bindings/scripts/scripts/world/npcs_special.cpp +++ b/src/bindings/scripts/scripts/world/npcs_special.cpp @@ -1673,13 +1673,13 @@ CreatureAI* GetAI_mob_mojo(Creature* pCreature) return new mob_mojoAI (pCreature); } -struct TRINITY_DLL_DECL npc_mirror_image : SpellCasterAI +struct TRINITY_DLL_DECL npc_mirror_image : CasterAI { - npc_mirror_image(Creature *c) : SpellCasterAI(c) {} + npc_mirror_image(Creature *c) : CasterAI(c) {} void InitializeAI() { - SpellCasterAI::InitializeAI(); + CasterAI::InitializeAI(); Unit * owner = me->GetOwner(); if (!owner) return; @@ -1713,15 +1713,15 @@ CreatureAI* GetAI_npc_mirror_image(Creature* pCreature) return new npc_mirror_image (pCreature); } -struct TRINITY_DLL_DECL npc_ebon_gargoyleAI : SpellCasterAI +struct TRINITY_DLL_DECL npc_ebon_gargoyleAI : CasterAI { - npc_ebon_gargoyleAI(Creature *c) : SpellCasterAI(c) {} + npc_ebon_gargoyleAI(Creature *c) : CasterAI(c) {} int despawnTimer; void InitializeAI() { - SpellCasterAI::InitializeAI(); + CasterAI::InitializeAI(); Unit * owner = me->GetOwner(); if (!owner) return; @@ -1789,7 +1789,7 @@ struct TRINITY_DLL_DECL npc_ebon_gargoyleAI : SpellCasterAI } return; } - SpellCasterAI::UpdateAI(diff); + CasterAI::UpdateAI(diff); } }; 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" |