2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_CREATUREAI_H
20 #define MANGOS_CREATUREAI_H
23 #include "Platform/Define.h"
24 #include "Policies/Singleton.h"
25 #include "Dynamic/ObjectRegistry.h"
26 #include "Dynamic/FactoryHolder.h"
34 #define TIME_INTERVAL_LOOK 5000
35 #define VISIBILITY_RANGE 10000
37 class MANGOS_DLL_SPEC CreatureAI
40 explicit CreatureAI(Creature
* creature
) : m_creature(creature
) {}
42 virtual ~CreatureAI();
44 ///== Reactions At =================================
46 // Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter
47 virtual void MoveInLineOfSight(Unit
*) {}
49 // Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
50 virtual void EnterCombat(Unit
* /*enemy*/) {}
52 // Called for reaction at stopping attack at no attackers or targets
53 virtual void EnterEvadeMode() {}
55 // Called at reaching home after evade
56 virtual void JustReachedHome() {}
58 // Called at any heal cast/item used (call non implemented)
59 virtual void HealBy(Unit
* /*healer*/, uint32
/*amount_healed*/) {}
61 // Called at any Damage to any victim (before damage apply)
62 virtual void DamageDeal(Unit
* /*done_to*/, uint32
& /*damage*/) {}
64 // Called at any Damage from any attacker (before damage apply)
65 // Note: it for recalculation damage or special reaction at damage
66 // for attack reaction use AttackedBy called for not DOT damage in Unit::DealDamage also
67 virtual void DamageTaken(Unit
* /*done_by*/, uint32
& /*damage*/) {}
69 // Called when the creature is killed
70 virtual void JustDied(Unit
*) {}
72 // Called when the creature kills a unit
73 virtual void KilledUnit(Unit
*) {}
75 // Called when the creature summon successfully other creature
76 virtual void JustSummoned(Creature
* ) {}
78 virtual void SummonedCreatureDespawn(Creature
* /*unit*/) {}
80 // Called when hit by a spell
81 virtual void SpellHit(Unit
*, const SpellEntry
*) {}
83 // Called when spell hits creature's target
84 virtual void SpellHitTarget(Unit
*, const SpellEntry
*) {}
86 // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
87 virtual void AttackedBy(Unit
* attacker
);
89 // Called when creature is spawned or respawned (for reseting variables)
90 virtual void JustRespawned() {}
92 // Called at waypoint reached or point movement finished
93 virtual void MovementInform(uint32
/*MovementType*/, uint32
/*Data*/) {}
95 // Called at text emote receive from player
96 virtual void ReceiveEmote(Player
* /*pPlayer*/, uint32
/*text_emote*/) {}
98 ///== Triggered Actions Requested ==================
100 // Called when creature attack expected (if creature can and no have current victim)
101 // Note: for reaction at hostile action must be called AttackedBy function.
102 virtual void AttackStart(Unit
*) {}
104 // Called at World update tick
105 virtual void UpdateAI(const uint32
/*diff*/) {}
107 ///== State checks =================================
109 // Is unit visible for MoveInLineOfSight
110 virtual bool IsVisible(Unit
*) const { return false; }
112 // Called when victim entered water and creature can not enter water
113 virtual bool canReachByRangeAttack(Unit
*) { return false; }
115 ///== Fields =======================================
117 // Pointer to controlled by AI creature
118 Creature
* const m_creature
;
121 struct SelectableAI
: public FactoryHolder
<CreatureAI
>, public Permissible
<Creature
>
124 SelectableAI(const char *id
) : FactoryHolder
<CreatureAI
>(id
) {}
127 template<class REAL_AI
>
128 struct CreatureAIFactory
: public SelectableAI
130 CreatureAIFactory(const char *name
) : SelectableAI(name
) {}
132 CreatureAI
* Create(void *) const;
134 int Permit(const Creature
*c
) const { return REAL_AI::Permissible(c
); }
140 PERMIT_BASE_IDLE
= 1,
141 PERMIT_BASE_REACTIVE
= 100,
142 PERMIT_BASE_PROACTIVE
= 200,
143 PERMIT_BASE_FACTION_SPECIFIC
= 400,
144 PERMIT_BASE_SPECIAL
= 800
147 typedef FactoryHolder
<CreatureAI
> CreatureAICreator
;
148 typedef FactoryHolder
<CreatureAI
>::FactoryHolderRegistry CreatureAIRegistry
;
149 typedef FactoryHolder
<CreatureAI
>::FactoryHolderRepository CreatureAIRepository
;