[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / CreatureAI.h
blob5b4ed0545b4f279475a1e930b5b452b868a72832
1 /*
2 * Copyright (C) 2005-2008 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 any heal cast/item used (call non implemented)
51 virtual void HealBy(Unit * /*healer*/, uint32 /*amount_healed*/) {}
53 // Called at any Damage to any victim (before damage apply)
54 virtual void DamageDeal(Unit * /*done_to*/, uint32 & /*damage*/) {}
56 // Called at any Damage from any attacker (before damage apply)
57 virtual void DamageTaken(Unit *done_by, uint32 & /*damage*/) { AttackedBy(done_by); }
59 // Is unit visible for MoveInLineOfSight
60 virtual bool IsVisible(Unit *) const = 0;
62 // Called at World update tick
63 virtual void UpdateAI(const uint32 diff ) = 0;
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 vitim entered water and creature can not enter water
80 virtual bool canReachByRangeAttack(Unit*) { return false; }
82 // Called when the creature is attacked
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*/) {}
92 struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature>
95 SelectableAI(const char *id) : FactoryHolder<CreatureAI>(id) {}
98 template<class REAL_AI>
99 struct CreatureAIFactory : public SelectableAI
101 CreatureAIFactory(const char *name) : SelectableAI(name) {}
103 CreatureAI* Create(void *) const;
105 int Permit(const Creature *c) const { return REAL_AI::Permissible(c); }
108 enum Permitions
110 PERMIT_BASE_NO = -1,
111 PERMIT_BASE_IDLE = 1,
112 PERMIT_BASE_REACTIVE = 100,
113 PERMIT_BASE_PROACTIVE = 200,
114 PERMIT_BASE_FACTION_SPECIFIC = 400,
115 PERMIT_BASE_SPECIAL = 800
118 typedef FactoryHolder<CreatureAI> CreatureAICreator;
119 typedef FactoryHolder<CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
120 typedef FactoryHolder<CreatureAI>::FactoryHolderRepository CreatureAIRepository;
121 #endif