| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #ifndef TRINITY_CREATUREAI_H |
|---|
| 22 | #define TRINITY_CREATUREAI_H |
|---|
| 23 | |
|---|
| 24 | #include "Common.h" |
|---|
| 25 | #include "Platform/Define.h" |
|---|
| 26 | #include "Policies/Singleton.h" |
|---|
| 27 | #include "Dynamic/ObjectRegistry.h" |
|---|
| 28 | #include "Dynamic/FactoryHolder.h" |
|---|
| 29 | |
|---|
| 30 | class Unit; |
|---|
| 31 | class Creature; |
|---|
| 32 | struct SpellEntry; |
|---|
| 33 | |
|---|
| 34 | #define TIME_INTERVAL_LOOK 5000 |
|---|
| 35 | #define VISIBILITY_RANGE 10000 |
|---|
| 36 | |
|---|
| 37 | //Spell targets used by SelectSpell |
|---|
| 38 | enum SelectTarget |
|---|
| 39 | { |
|---|
| 40 | SELECT_TARGET_DONTCARE = 0, //All target types allowed |
|---|
| 41 | |
|---|
| 42 | SELECT_TARGET_SELF, //Only Self casting |
|---|
| 43 | |
|---|
| 44 | SELECT_TARGET_SINGLE_ENEMY, //Only Single Enemy |
|---|
| 45 | SELECT_TARGET_AOE_ENEMY, //Only AoE Enemy |
|---|
| 46 | SELECT_TARGET_ANY_ENEMY, //AoE or Single Enemy |
|---|
| 47 | |
|---|
| 48 | SELECT_TARGET_SINGLE_FRIEND, //Only Single Friend |
|---|
| 49 | SELECT_TARGET_AOE_FRIEND, //Only AoE Friend |
|---|
| 50 | SELECT_TARGET_ANY_FRIEND, //AoE or Single Friend |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | //Spell Effects used by SelectSpell |
|---|
| 54 | enum SelectEffect |
|---|
| 55 | { |
|---|
| 56 | SELECT_EFFECT_DONTCARE = 0, //All spell effects allowed |
|---|
| 57 | SELECT_EFFECT_DAMAGE, //Spell does damage |
|---|
| 58 | SELECT_EFFECT_HEALING, //Spell does healing |
|---|
| 59 | SELECT_EFFECT_AURA, //Spell applies an aura |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | //Selection method used by SelectTarget |
|---|
| 63 | enum SelectAggroTarget |
|---|
| 64 | { |
|---|
| 65 | SELECT_TARGET_RANDOM = 0, //Just selects a random target |
|---|
| 66 | SELECT_TARGET_TOPAGGRO, //Selects targes from top aggro to bottom |
|---|
| 67 | SELECT_TARGET_BOTTOMAGGRO, //Selects targets from bottom aggro to top |
|---|
| 68 | }; |
|---|
| 69 | |
|---|
| 70 | class TRINITY_DLL_SPEC CreatureAI |
|---|
| 71 | { |
|---|
| 72 | public: |
|---|
| 73 | |
|---|
| 74 | virtual ~CreatureAI(); |
|---|
| 75 | |
|---|
| 76 | // Called if IsVisible(Unit *who) is true at each *who move |
|---|
| 77 | virtual void MoveInLineOfSight(Unit *) = 0; |
|---|
| 78 | |
|---|
| 79 | // Called at each attack of m_creature by any victim |
|---|
| 80 | virtual void AttackStart(Unit *) = 0; |
|---|
| 81 | |
|---|
| 82 | // Called at stopping attack by any attacker |
|---|
| 83 | virtual void EnterEvadeMode() = 0; |
|---|
| 84 | |
|---|
| 85 | // Called at any Damage from any attacker (before damage apply) |
|---|
| 86 | virtual void DamageTaken(Unit *done_by, uint32 & /*damage*/) { AttackedBy(done_by); } |
|---|
| 87 | |
|---|
| 88 | // Is unit visible for MoveInLineOfSight |
|---|
| 89 | virtual bool IsVisible(Unit *) const = 0; |
|---|
| 90 | |
|---|
| 91 | // Called at World update tick |
|---|
| 92 | virtual void UpdateAI(const uint32 diff ) = 0; |
|---|
| 93 | |
|---|
| 94 | // Called when the creature is killed |
|---|
| 95 | virtual void JustDied(Unit *) {} |
|---|
| 96 | |
|---|
| 97 | // Called when the creature kills a unit |
|---|
| 98 | virtual void KilledUnit(Unit *) {} |
|---|
| 99 | |
|---|
| 100 | // Called when the creature summon successfully other creature |
|---|
| 101 | virtual void JustSummoned(Creature* ) {} |
|---|
| 102 | |
|---|
| 103 | virtual void SummonedCreatureDespawn(Creature* /*unit*/) {} |
|---|
| 104 | |
|---|
| 105 | // Called when hit by a spell |
|---|
| 106 | virtual void SpellHit(Unit*, const SpellEntry*) {} |
|---|
| 107 | |
|---|
| 108 | // Called when spell hits a target |
|---|
| 109 | virtual void SpellHitTarget(Unit* target, const SpellEntry*) {} |
|---|
| 110 | |
|---|
| 111 | // Called when vitim entered water and creature can not enter water |
|---|
| 112 | virtual bool canReachByRangeAttack(Unit*) { return false; } |
|---|
| 113 | |
|---|
| 114 | // Called when the creature is attacked |
|---|
| 115 | virtual void AttackedBy(Unit * /*attacker*/) {} |
|---|
| 116 | |
|---|
| 117 | // Called when creature is spawned or respawned (for reseting variables) |
|---|
| 118 | virtual void JustRespawned() {} |
|---|
| 119 | |
|---|
| 120 | // Called at waypoint reached or point movement finished |
|---|
| 121 | virtual void MovementInform(uint32 /*MovementType*/, uint32 /*Data*/) {} |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature> |
|---|
| 125 | { |
|---|
| 126 | |
|---|
| 127 | SelectableAI(const char *id) : FactoryHolder<CreatureAI>(id) {} |
|---|
| 128 | }; |
|---|
| 129 | |
|---|
| 130 | template<class REAL_AI> |
|---|
| 131 | struct CreatureAIFactory : public SelectableAI |
|---|
| 132 | { |
|---|
| 133 | CreatureAIFactory(const char *name) : SelectableAI(name) {} |
|---|
| 134 | |
|---|
| 135 | CreatureAI* Create(void *) const; |
|---|
| 136 | |
|---|
| 137 | int Permit(const Creature *c) const { return REAL_AI::Permissible(c); } |
|---|
| 138 | }; |
|---|
| 139 | |
|---|
| 140 | enum Permitions |
|---|
| 141 | { |
|---|
| 142 | PERMIT_BASE_NO = -1, |
|---|
| 143 | PERMIT_BASE_IDLE = 1, |
|---|
| 144 | PERMIT_BASE_REACTIVE = 100, |
|---|
| 145 | PERMIT_BASE_PROACTIVE = 200, |
|---|
| 146 | PERMIT_BASE_FACTION_SPECIFIC = 400, |
|---|
| 147 | PERMIT_BASE_SPECIAL = 800 |
|---|
| 148 | }; |
|---|
| 149 | |
|---|
| 150 | typedef FactoryHolder<CreatureAI> CreatureAICreator; |
|---|
| 151 | typedef FactoryHolder<CreatureAI>::FactoryHolderRegistry CreatureAIRegistry; |
|---|
| 152 | typedef FactoryHolder<CreatureAI>::FactoryHolderRepository CreatureAIRepository; |
|---|
| 153 | #endif |
|---|