[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / CreatureAI.h
blob3bc4e9b34dc8016cbe3e24fa2d0adb34f14476ff
1 /*
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
22 #include "Common.h"
23 #include "Platform/Define.h"
24 #include "Policies/Singleton.h"
25 #include "Dynamic/ObjectRegistry.h"
26 #include "Dynamic/FactoryHolder.h"
28 class Unit;
29 class Creature;
30 struct SpellEntry;
32 #define TIME_INTERVAL_LOOK 5000
33 #define VISIBILITY_RANGE 10000
35 class MANGOS_DLL_SPEC CreatureAI
37 public:
39 virtual ~CreatureAI();
41 // Called if IsVisible(Unit *who) is true at each *who move
42 virtual void MoveInLineOfSight(Unit *) = 0;
44 // Called at each attack of m_creature by any victim
45 virtual void AttackStart(Unit *) = 0;
47 // Called at stopping attack by any attacker
48 virtual void EnterEvadeMode() = 0;
50 // Called at reaching home after evade
51 virtual void JustReachedHome() {}
53 // Called at any heal cast/item used (call non implemented)
54 virtual void HealBy(Unit * /*healer*/, uint32 /*amount_healed*/) {}
56 // Called at any Damage to any victim (before damage apply)
57 virtual void DamageDeal(Unit * /*done_to*/, uint32 & /*damage*/) {}
59 // Called at any Damage from any attacker (before damage apply)
60 virtual void DamageTaken(Unit *done_by, uint32 & /*damage*/) { AttackedBy(done_by); }
62 // Is unit visible for MoveInLineOfSight
63 virtual bool IsVisible(Unit *) const = 0;
65 // Called at World update tick
66 virtual void UpdateAI(const uint32 diff ) = 0;
68 // Called when the creature is killed
69 virtual void JustDied(Unit *) {}
71 // Called when the creature kills a unit
72 virtual void KilledUnit(Unit *) {}
74 // Called when the creature summon successfully other creature
75 virtual void JustSummoned(Creature* ) {}
77 virtual void SummonedCreatureDespawn(Creature* /*unit*/) {}
79 // Called when hit by a spell
80 virtual void SpellHit(Unit*, const SpellEntry*) {}
82 // Called when vitim entered water and creature can not enter water
83 virtual bool canReachByRangeAttack(Unit*) { return false; }
85 // Called when the creature is attacked
86 virtual void AttackedBy(Unit * /*attacker*/) {}
88 // Called when creature is spawned or respawned (for reseting variables)
89 virtual void JustRespawned() {}
91 // Called at waypoint reached or point movement finished
92 virtual void MovementInform(uint32 /*MovementType*/, uint32 /*Data*/) {}
95 struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature>
98 SelectableAI(const char *id) : FactoryHolder<CreatureAI>(id) {}
101 template<class REAL_AI>
102 struct CreatureAIFactory : public SelectableAI
104 CreatureAIFactory(const char *name) : SelectableAI(name) {}
106 CreatureAI* Create(void *) const;
108 int Permit(const Creature *c) const { return REAL_AI::Permissible(c); }
111 enum Permitions
113 PERMIT_BASE_NO = -1,
114 PERMIT_BASE_IDLE = 1,
115 PERMIT_BASE_REACTIVE = 100,
116 PERMIT_BASE_PROACTIVE = 200,
117 PERMIT_BASE_FACTION_SPECIFIC = 400,
118 PERMIT_BASE_SPECIAL = 800
121 typedef FactoryHolder<CreatureAI> CreatureAICreator;
122 typedef FactoryHolder<CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
123 typedef FactoryHolder<CreatureAI>::FactoryHolderRepository CreatureAIRepository;
124 #endif