From 08539ec0a4eabc903d8fbaf34aba465f20e0b698 Mon Sep 17 00:00:00 2001 From: megamage Date: Sun, 23 Aug 2009 14:20:07 -0500 Subject: *Rename some ai functions. --HG-- branch : trunk --- src/bindings/scripts/include/precompiled.h | 4 +- .../eastern_kingdoms/scarlet_enclave/chapter1.cpp | 8 +- .../scripts/northrend/naxxramas/boss_gothik.cpp | 10 +- .../scripts/scripts/world/npcs_special.cpp | 14 +- src/game/AggressorAI.cpp | 150 --------------- src/game/AggressorAI.h | 68 ------- src/game/CombatAI.cpp | 211 +++++++++++++++++++++ src/game/CombatAI.h | 80 ++++++++ src/game/CreatureAIRegistry.cpp | 6 +- src/game/CreatureAISelector.cpp | 4 +- src/game/NullCreatureAI.cpp | 81 -------- src/game/NullCreatureAI.h | 86 --------- src/game/PassiveAI.cpp | 81 ++++++++ src/game/PassiveAI.h | 86 +++++++++ src/game/SpellMgr.h | 10 + src/game/Unit.cpp | 2 +- 16 files changed, 492 insertions(+), 409 deletions(-) delete mode 100644 src/game/AggressorAI.cpp delete mode 100644 src/game/AggressorAI.h create mode 100644 src/game/CombatAI.cpp create mode 100644 src/game/CombatAI.h delete mode 100644 src/game/NullCreatureAI.cpp delete mode 100644 src/game/NullCreatureAI.h create mode 100644 src/game/PassiveAI.cpp create mode 100644 src/game/PassiveAI.h (limited to 'src') 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 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/AggressorAI.cpp deleted file mode 100644 index 3ede976a229..00000000000 --- a/src/game/AggressorAI.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS - * - * Copyright (C) 2008-2009 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "AggressorAI.h" -#include "SpellMgr.h" - -int AggressorAI::Permissible(const Creature *creature) -{ - // have some hostile factions, it will be selected by IsHostileTo check at MoveInLineOfSight - if( !creature->isCivilian() && !creature->IsNeutralToAll() ) - return PERMIT_BASE_PROACTIVE; - - return PERMIT_BASE_NO; -} - -void AggressorAI::UpdateAI(const uint32 /*diff*/) -{ - if(!UpdateVictim()) - return; - - DoMeleeAttackIfReady(); -} - -int SpellAI::Permissible(const Creature *creature) -{ - return PERMIT_BASE_NO; -} - -void SpellAI::InitializeAI() -{ - for(uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i) - if(me->m_spells[i] && GetSpellStore()->LookupEntry(me->m_spells[i])) - spells.push_back(me->m_spells[i]); - - CreatureAI::InitializeAI(); -} - -void SpellAI::Reset() -{ - events.Reset(); -} - -void SpellAI::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) -{ - for(SpellVct::iterator i = spells.begin(); i != spells.end(); ++i) - { - if(AISpellInfo[*i].condition == AICOND_AGGRO) - me->CastSpell(who, *i, false); - else if(AISpellInfo[*i].condition == AICOND_COMBAT) - events.ScheduleEvent(*i, AISpellInfo[*i].cooldown + rand()%AISpellInfo[*i].cooldown); - } -} - -void SpellAI::UpdateAI(const uint32 diff) -{ - if(!UpdateVictim()) - return; - - events.Update(diff); - - if(me->hasUnitState(UNIT_STAT_CASTING)) - return; - - if(uint32 spellId = events.ExecuteEvent()) - { - DoCast(spellId); - events.ScheduleEvent(spellId, AISpellInfo[spellId].cooldown + rand()%AISpellInfo[spellId].cooldown); - } - else - DoMeleeAttackIfReady(); -} - -void SpellCasterAI::InitializeAI() -{ - SpellAI::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) -{ - if (spells.empty()) - return; - - uint32 spell = rand() % spells.size(); - uint32 count = 0; - for(SpellVct::iterator itr = spells.begin(); itr != spells.end(); ++itr, ++count) - { - if(AISpellInfo[*itr].condition == AICOND_AGGRO) - me->CastSpell(who, *itr, false); - else if (AISpellInfo[*itr].condition == AICOND_COMBAT) - { - uint32 cooldown = GetAISpellInfo(*itr)->realCooldown; - if (count == spell) - { - DoCast(spells[spell]); - cooldown += me->GetCurrentSpellCastTime(*itr); - } - events.ScheduleEvent(*itr, cooldown); - } - } -} - -void SpellCasterAI::UpdateAI(const uint32 diff) -{ - if(!UpdateVictim()) - return; - - events.Update(diff); - - if(me->hasUnitState(UNIT_STAT_CASTING)) - return; - - if(uint32 spellId = events.ExecuteEvent()) - { - DoCast(spellId); - uint32 casttime = me->GetCurrentSpellCastTime(spellId); - events.ScheduleEvent(spellId, (casttime ? casttime : 500) + GetAISpellInfo(spellId)->realCooldown); - } -} diff --git a/src/game/AggressorAI.h b/src/game/AggressorAI.h deleted file mode 100644 index cec11c0fb22..00000000000 --- a/src/game/AggressorAI.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS - * - * Copyright (C) 2008-2009 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_AGGRESSORAI_H -#define TRINITY_AGGRESSORAI_H - -#include "CreatureAI.h" -#include "CreatureAIImpl.h" - -class Creature; - -class TRINITY_DLL_DECL AggressorAI : public CreatureAI -{ - public: - explicit AggressorAI(Creature *c) : CreatureAI(c) {} - - void UpdateAI(const uint32); - static int Permissible(const Creature *); -}; - -typedef std::vector SpellVct; - -class TRINITY_DLL_SPEC SpellAI : public CreatureAI -{ - public: - explicit SpellAI(Creature *c) : CreatureAI(c) {} - - void InitializeAI(); - void Reset(); - void EnterCombat(Unit* who); - void JustDied(Unit *killer); - void UpdateAI(const uint32 diff); - static int Permissible(const Creature *); - protected: - EventMap events; - SpellVct spells; -}; - -class TRINITY_DLL_SPEC SpellCasterAI : public SpellAI -{ - public: - explicit SpellCasterAI(Creature *c) : SpellAI(c) {m_attackDist = MELEE_RANGE;} - void InitializeAI(); - void AttackStart(Unit * victim){SpellAI::AttackStartCaster(victim, m_attackDist);} - void UpdateAI(const uint32 diff); - void EnterCombat(Unit *who); - private: - float m_attackDist; -}; - -#endif diff --git a/src/game/CombatAI.cpp b/src/game/CombatAI.cpp new file mode 100644 index 00000000000..89628ccef57 --- /dev/null +++ b/src/game/CombatAI.cpp @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2005-2009 MaNGOS + * + * Copyright (C) 2008-2009 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "CombatAI.h" +#include "SpellMgr.h" + +int AggressorAI::Permissible(const Creature *creature) +{ + // have some hostile factions, it will be selected by IsHostileTo check at MoveInLineOfSight + if( !creature->isCivilian() && !creature->IsNeutralToAll() ) + return PERMIT_BASE_PROACTIVE; + + return PERMIT_BASE_NO; +} + +void AggressorAI::UpdateAI(const uint32 /*diff*/) +{ + if(!UpdateVictim()) + return; + + DoMeleeAttackIfReady(); +} + +int CombatAI::Permissible(const Creature *creature) +{ + return PERMIT_BASE_NO; +} + +void CombatAI::InitializeAI() +{ + for(uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i) + if(me->m_spells[i] && GetSpellStore()->LookupEntry(me->m_spells[i])) + spells.push_back(me->m_spells[i]); + + CreatureAI::InitializeAI(); +} + +void CombatAI::Reset() +{ + events.Reset(); +} + +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 CombatAI::EnterCombat(Unit *who) +{ + for(SpellVct::iterator i = spells.begin(); i != spells.end(); ++i) + { + if(AISpellInfo[*i].condition == AICOND_AGGRO) + me->CastSpell(who, *i, false); + else if(AISpellInfo[*i].condition == AICOND_COMBAT) + events.ScheduleEvent(*i, AISpellInfo[*i].cooldown + rand()%AISpellInfo[*i].cooldown); + } +} + +void CombatAI::UpdateAI(const uint32 diff) +{ + if(!UpdateVictim()) + return; + + events.Update(diff); + + if(me->hasUnitState(UNIT_STAT_CASTING)) + return; + + if(uint32 spellId = events.ExecuteEvent()) + { + DoCast(spellId); + events.ScheduleEvent(spellId, AISpellInfo[spellId].cooldown + rand()%AISpellInfo[spellId].cooldown); + } + else + DoMeleeAttackIfReady(); +} + + +///////////////// +//CasterAI +///////////////// + +void CasterAI::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 CasterAI::EnterCombat(Unit *who) +{ + if (spells.empty()) + return; + + uint32 spell = rand()%spells.size(); + uint32 count = 0; + for(SpellVct::iterator itr = spells.begin(); itr != spells.end(); ++itr, ++count) + { + if(AISpellInfo[*itr].condition == AICOND_AGGRO) + me->CastSpell(who, *itr, false); + else if (AISpellInfo[*itr].condition == AICOND_COMBAT) + { + uint32 cooldown = GetAISpellInfo(*itr)->realCooldown; + if (count == spell) + { + DoCast(spells[spell]); + cooldown += me->GetCurrentSpellCastTime(*itr); + } + events.ScheduleEvent(*itr, cooldown); + } + } +} + +void CasterAI::UpdateAI(const uint32 diff) +{ + if(!UpdateVictim()) + return; + + events.Update(diff); + + if(me->hasUnitState(UNIT_STAT_CASTING)) + return; + + if(uint32 spellId = events.ExecuteEvent()) + { + DoCast(spellId); + uint32 casttime = me->GetCurrentSpellCastTime(spellId); + 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/CombatAI.h b/src/game/CombatAI.h new file mode 100644 index 00000000000..240d318d622 --- /dev/null +++ b/src/game/CombatAI.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2005-2009 MaNGOS + * + * Copyright (C) 2008-2009 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TRINITY_COMBATAI_H +#define TRINITY_COMBATAI_H + +#include "CreatureAI.h" +#include "CreatureAIImpl.h" + +class Creature; + +class TRINITY_DLL_DECL AggressorAI : public CreatureAI +{ + public: + explicit AggressorAI(Creature *c) : CreatureAI(c) {} + + void UpdateAI(const uint32); + static int Permissible(const Creature *); +}; + +typedef std::vector SpellVct; + +class TRINITY_DLL_SPEC CombatAI : public CreatureAI +{ + public: + explicit CombatAI(Creature *c) : CreatureAI(c) {} + + void InitializeAI(); + void Reset(); + void EnterCombat(Unit* who); + void JustDied(Unit *killer); + void UpdateAI(const uint32 diff); + static int Permissible(const Creature *); + protected: + EventMap events; + SpellVct spells; +}; + +class TRINITY_DLL_SPEC CasterAI : public CombatAI +{ + public: + explicit CasterAI(Creature *c) : CombatAI(c) { m_attackDist = MELEE_RANGE; } + void InitializeAI(); + 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"))->RegisterSelf(); (new CreatureAIFactory("PetAI"))->RegisterSelf(); (new CreatureAIFactory("TotemAI"))->RegisterSelf(); - (new CreatureAIFactory("SpellAI"))->RegisterSelf(); + (new CreatureAIFactory("CombatAI"))->RegisterSelf(); (new CreatureAIFactory("EventAI"))->RegisterSelf(); (new MovementGeneratorFactory >(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/NullCreatureAI.cpp deleted file mode 100644 index cb06e1918ad..00000000000 --- a/src/game/NullCreatureAI.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS - * - * Copyright (C) 2008-2009 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "NullCreatureAI.h" -#include "Creature.h" -#include "TemporarySummon.h" - -PassiveAI::PassiveAI(Creature *c) : CreatureAI(c) { me->SetReactState(REACT_PASSIVE); } -PossessedAI::PossessedAI(Creature *c) : CreatureAI(c) { me->SetReactState(REACT_PASSIVE); } -NullCreatureAI::NullCreatureAI(Creature *c) : CreatureAI(c) { me->SetReactState(REACT_PASSIVE); } - -void PassiveAI::UpdateAI(const uint32) -{ - if(me->isInCombat() && me->getAttackers().empty()) - EnterEvadeMode(); -} - -void PossessedAI::AttackStart(Unit *target) -{ - me->Attack(target, true); -} - -void PossessedAI::UpdateAI(const uint32 diff) -{ - if(me->getVictim()) - { - if(!me->canAttack(me->getVictim())) - me->AttackStop(); - else - DoMeleeAttackIfReady(); - } -} - -void PossessedAI::JustDied(Unit *u) -{ - // We died while possessed, disable our loot - me->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); -} - -void PossessedAI::KilledUnit(Unit* victim) -{ - // We killed a creature, disable victim's loot - if (victim->GetTypeId() == TYPEID_UNIT) - victim->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); -} - -void CritterAI::DamageTaken(Unit *done_by, uint32 &) -{ - if(!me->hasUnitState(UNIT_STAT_FLEEING)) - me->SetControlled(true, UNIT_STAT_FLEEING); -} - -void CritterAI::EnterEvadeMode() -{ - if(me->hasUnitState(UNIT_STAT_FLEEING)) - me->SetControlled(false, UNIT_STAT_FLEEING); - CreatureAI::EnterEvadeMode(); -} - -void TriggerAI::IsSummonedBy(Unit *summoner) -{ - if(me->m_spells[0]) - me->CastSpell(me, me->m_spells[0], false, 0, 0, summoner->GetGUID()); -} diff --git a/src/game/NullCreatureAI.h b/src/game/NullCreatureAI.h deleted file mode 100644 index edc19f5cf57..00000000000 --- a/src/game/NullCreatureAI.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS - * - * Copyright (C) 2008-2009 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_NULLCREATUREAI_H -#define TRINITY_NULLCREATUREAI_H - -#include "CreatureAI.h" -#include "CreatureAIImpl.h" - -class TRINITY_DLL_SPEC PassiveAI : public CreatureAI -{ - public: - explicit PassiveAI(Creature *c); - - void MoveInLineOfSight(Unit *) {} - void AttackStart(Unit *) {} - void UpdateAI(const uint32); - - static int Permissible(const Creature *) { return PERMIT_BASE_IDLE; } -}; - -class TRINITY_DLL_DECL PossessedAI : public CreatureAI -{ - public: - explicit PossessedAI(Creature *c); - - void MoveInLineOfSight(Unit *) {} - void AttackStart(Unit *target); - void UpdateAI(const uint32); - void EnterEvadeMode() {} - - void JustDied(Unit*); - void KilledUnit(Unit* victim); - - static int Permissible(const Creature *) { return PERMIT_BASE_IDLE; } -}; - -class TRINITY_DLL_SPEC NullCreatureAI : public CreatureAI -{ - public: - explicit NullCreatureAI(Creature *c); - - void MoveInLineOfSight(Unit *) {} - void AttackStart(Unit *) {} - void UpdateAI(const uint32) {} - void EnterEvadeMode() {} - void OnCharmed(bool apply) {} - - static int Permissible(const Creature *) { return PERMIT_BASE_IDLE; } -}; - -class TRINITY_DLL_DECL CritterAI : public PassiveAI -{ - public: - explicit CritterAI(Creature *c) : PassiveAI(c) {} - - void DamageTaken(Unit *done_by, uint32 & /*damage*/); - void EnterEvadeMode(); -}; - -class TRINITY_DLL_SPEC TriggerAI : public NullCreatureAI -{ - public: - explicit TriggerAI(Creature *c) : NullCreatureAI(c) {} - void IsSummonedBy(Unit *summoner); -}; - -#endif - diff --git a/src/game/PassiveAI.cpp b/src/game/PassiveAI.cpp new file mode 100644 index 00000000000..65d424e7bed --- /dev/null +++ b/src/game/PassiveAI.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2005-2009 MaNGOS + * + * Copyright (C) 2008-2009 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "PassiveAI.h" +#include "Creature.h" +#include "TemporarySummon.h" + +PassiveAI::PassiveAI(Creature *c) : CreatureAI(c) { me->SetReactState(REACT_PASSIVE); } +PossessedAI::PossessedAI(Creature *c) : CreatureAI(c) { me->SetReactState(REACT_PASSIVE); } +NullCreatureAI::NullCreatureAI(Creature *c) : CreatureAI(c) { me->SetReactState(REACT_PASSIVE); } + +void PassiveAI::UpdateAI(const uint32) +{ + if(me->isInCombat() && me->getAttackers().empty()) + EnterEvadeMode(); +} + +void PossessedAI::AttackStart(Unit *target) +{ + me->Attack(target, true); +} + +void PossessedAI::UpdateAI(const uint32 diff) +{ + if(me->getVictim()) + { + if(!me->canAttack(me->getVictim())) + me->AttackStop(); + else + DoMeleeAttackIfReady(); + } +} + +void PossessedAI::JustDied(Unit *u) +{ + // We died while possessed, disable our loot + me->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); +} + +void PossessedAI::KilledUnit(Unit* victim) +{ + // We killed a creature, disable victim's loot + if (victim->GetTypeId() == TYPEID_UNIT) + victim->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); +} + +void CritterAI::DamageTaken(Unit *done_by, uint32 &) +{ + if(!me->hasUnitState(UNIT_STAT_FLEEING)) + me->SetControlled(true, UNIT_STAT_FLEEING); +} + +void CritterAI::EnterEvadeMode() +{ + if(me->hasUnitState(UNIT_STAT_FLEEING)) + me->SetControlled(false, UNIT_STAT_FLEEING); + CreatureAI::EnterEvadeMode(); +} + +void TriggerAI::IsSummonedBy(Unit *summoner) +{ + if(me->m_spells[0]) + me->CastSpell(me, me->m_spells[0], false, 0, 0, summoner->GetGUID()); +} diff --git a/src/game/PassiveAI.h b/src/game/PassiveAI.h new file mode 100644 index 00000000000..19ea9938320 --- /dev/null +++ b/src/game/PassiveAI.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2005-2009 MaNGOS + * + * Copyright (C) 2008-2009 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TRINITY_PASSIVEAI_H +#define TRINITY_PASSIVEAI_H + +#include "CreatureAI.h" +//#include "CreatureAIImpl.h" + +class TRINITY_DLL_SPEC PassiveAI : public CreatureAI +{ + public: + explicit PassiveAI(Creature *c); + + void MoveInLineOfSight(Unit *) {} + void AttackStart(Unit *) {} + void UpdateAI(const uint32); + + static int Permissible(const Creature *) { return PERMIT_BASE_IDLE; } +}; + +class TRINITY_DLL_DECL PossessedAI : public CreatureAI +{ + public: + explicit PossessedAI(Creature *c); + + void MoveInLineOfSight(Unit *) {} + void AttackStart(Unit *target); + void UpdateAI(const uint32); + void EnterEvadeMode() {} + + void JustDied(Unit*); + void KilledUnit(Unit* victim); + + static int Permissible(const Creature *) { return PERMIT_BASE_IDLE; } +}; + +class TRINITY_DLL_SPEC NullCreatureAI : public CreatureAI +{ + public: + explicit NullCreatureAI(Creature *c); + + void MoveInLineOfSight(Unit *) {} + void AttackStart(Unit *) {} + void UpdateAI(const uint32) {} + void EnterEvadeMode() {} + void OnCharmed(bool apply) {} + + static int Permissible(const Creature *) { return PERMIT_BASE_IDLE; } +}; + +class TRINITY_DLL_DECL CritterAI : public PassiveAI +{ + public: + explicit CritterAI(Creature *c) : PassiveAI(c) {} + + void DamageTaken(Unit *done_by, uint32 & /*damage*/); + void EnterEvadeMode(); +}; + +class TRINITY_DLL_SPEC TriggerAI : public NullCreatureAI +{ + public: + explicit TriggerAI(Creature *c) : NullCreatureAI(c) {} + void IsSummonedBy(Unit *summoner); +}; + +#endif + 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" -- cgit v1.2.3