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"
33 #define TIME_INTERVAL_LOOK 5000
34 #define VISIBILITY_RANGE 10000
36 class MANGOS_DLL_SPEC CreatureAI
39 explicit CreatureAI(Creature
* creature
) : m_creature(creature
) {}
41 virtual ~CreatureAI();
43 ///== Reactions At =================================
45 // Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter
46 virtual void MoveInLineOfSight(Unit
*) {}
48 // Called for reaction at stopping attack at no attackers or targets
49 virtual void EnterEvadeMode() {}
51 // Called at reaching home after evade
52 virtual void JustReachedHome() {}
54 // Called at any heal cast/item used (call non implemented)
55 virtual void HealBy(Unit
* /*healer*/, uint32
/*amount_healed*/) {}
57 // Called at any Damage to any victim (before damage apply)
58 virtual void DamageDeal(Unit
* /*done_to*/, uint32
& /*damage*/) {}
60 // Called at any Damage from any attacker (before damage apply)
61 // Note: it for recalculation damage or special reaction at damage
62 // for attack reaction use AttackedBy called for not DOT damage in Unit::DealDamage also
63 virtual void DamageTaken(Unit
*done_by
, uint32
& /*damage*/) {}
65 // Called when the creature is killed
66 virtual void JustDied(Unit
*) {}
68 // Called when the creature kills a unit
69 virtual void KilledUnit(Unit
*) {}
71 // Called when the creature summon successfully other creature
72 virtual void JustSummoned(Creature
* ) {}
74 virtual void SummonedCreatureDespawn(Creature
* /*unit*/) {}
76 // Called when hit by a spell
77 virtual void SpellHit(Unit
*, const SpellEntry
*) {}
79 // Called when spell hits creature's target
80 virtual void SpellHitTarget(Unit
*, const SpellEntry
*) {}
82 // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
83 virtual void AttackedBy(Unit
* attacker
);
85 // Called when creature is spawned or respawned (for reseting variables)
86 virtual void JustRespawned() {}
88 // Called at waypoint reached or point movement finished
89 virtual void MovementInform(uint32
/*MovementType*/, uint32
/*Data*/) {}
91 ///== Triggered Actions Requested ==================
93 // Called when creature attack expected (if creature can and no have current victim)
94 // Note: for reaction at hostile action must be called AttackedBy function.
95 virtual void AttackStart(Unit
*) {}
97 // Called at World update tick
98 virtual void UpdateAI(const uint32 diff
) {}
100 ///== State checks =================================
102 // Is unit visible for MoveInLineOfSight
103 virtual bool IsVisible(Unit
*) const { return false; }
105 // Called when victim entered water and creature can not enter water
106 virtual bool canReachByRangeAttack(Unit
*) { return false; }
108 ///== Fields =======================================
110 // Pointer to controlled by AI creature
111 Creature
* const m_creature
;
114 struct SelectableAI
: public FactoryHolder
<CreatureAI
>, public Permissible
<Creature
>
117 SelectableAI(const char *id
) : FactoryHolder
<CreatureAI
>(id
) {}
120 template<class REAL_AI
>
121 struct CreatureAIFactory
: public SelectableAI
123 CreatureAIFactory(const char *name
) : SelectableAI(name
) {}
125 CreatureAI
* Create(void *) const;
127 int Permit(const Creature
*c
) const { return REAL_AI::Permissible(c
); }
133 PERMIT_BASE_IDLE
= 1,
134 PERMIT_BASE_REACTIVE
= 100,
135 PERMIT_BASE_PROACTIVE
= 200,
136 PERMIT_BASE_FACTION_SPECIFIC
= 400,
137 PERMIT_BASE_SPECIAL
= 800
140 typedef FactoryHolder
<CreatureAI
> CreatureAICreator
;
141 typedef FactoryHolder
<CreatureAI
>::FactoryHolderRegistry CreatureAIRegistry
;
142 typedef FactoryHolder
<CreatureAI
>::FactoryHolderRepository CreatureAIRepository
;