root/trunk/src/game/CreatureAI.h @ 18

Revision 13, 5.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Moved Script grid_searchers to core
* Moved an enum from sc_creature.h to CreatureAI.h

Original author: Neo2003
Date: 2008-10-05 11:56:30-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef MANGOS_CREATUREAI_H
20#define MANGOS_CREATUREAI_H
21
22#include "Common.h"
23#include "Platform/Define.h"
24#include "Policies/Singleton.h"
25#include "Dynamic/ObjectRegistry.h"
26#include "Dynamic/FactoryHolder.h"
27
28class Unit;
29class Creature;
30struct SpellEntry;
31
32#define TIME_INTERVAL_LOOK   5000
33#define VISIBILITY_RANGE    10000
34
35//Spell targets used by SelectSpell
36enum SelectTarget
37{
38    SELECT_TARGET_DONTCARE = 0,                             //All target types allowed
39
40    SELECT_TARGET_SELF,                                     //Only Self casting
41
42    SELECT_TARGET_SINGLE_ENEMY,                             //Only Single Enemy
43    SELECT_TARGET_AOE_ENEMY,                                //Only AoE Enemy
44    SELECT_TARGET_ANY_ENEMY,                                //AoE or Single Enemy
45
46    SELECT_TARGET_SINGLE_FRIEND,                            //Only Single Friend
47    SELECT_TARGET_AOE_FRIEND,                               //Only AoE Friend
48    SELECT_TARGET_ANY_FRIEND,                               //AoE or Single Friend
49};
50
51//Spell Effects used by SelectSpell
52enum SelectEffect
53{
54    SELECT_EFFECT_DONTCARE = 0,                             //All spell effects allowed
55    SELECT_EFFECT_DAMAGE,                                   //Spell does damage
56    SELECT_EFFECT_HEALING,                                  //Spell does healing
57    SELECT_EFFECT_AURA,                                     //Spell applies an aura
58};
59
60//Selection method used by SelectTarget
61enum SelectAggroTarget
62{
63    SELECT_TARGET_RANDOM = 0,                               //Just selects a random target
64    SELECT_TARGET_TOPAGGRO,                                 //Selects targes from top aggro to bottom
65    SELECT_TARGET_BOTTOMAGGRO,                              //Selects targets from bottom aggro to top
66};
67
68class MANGOS_DLL_SPEC CreatureAI
69{
70    public:
71
72        virtual ~CreatureAI();
73
74        // Called if IsVisible(Unit *who) is true at each *who move
75        virtual void MoveInLineOfSight(Unit *) = 0;
76
77        // Called at each attack of m_creature by any victim
78        virtual void AttackStart(Unit *) = 0;
79
80        // Called at stopping attack by any attacker
81        virtual void EnterEvadeMode() = 0;
82
83        // Called at any heal cast/item used (call non implemented)
84        virtual void HealBy(Unit * /*healer*/, uint32 /*amount_healed*/) {}
85
86        // Called at any Damage to any victim (before damage apply)
87        virtual void DamageDeal(Unit * /*done_to*/, uint32 & /*damage*/) {}
88
89        // Called at any Damage from any attacker (before damage apply)
90        virtual void DamageTaken(Unit *done_by, uint32 & /*damage*/) { AttackedBy(done_by); }
91
92        // Is unit visible for MoveInLineOfSight
93        virtual bool IsVisible(Unit *) const = 0;
94
95        // Called at World update tick
96        virtual void UpdateAI(const uint32 diff ) = 0;
97
98        // Called when the creature is killed
99        virtual void JustDied(Unit *) {}
100
101        // Called when the creature kills a unit
102        virtual void KilledUnit(Unit *) {}
103
104        // Called when the creature summon successfully other creature
105        virtual void JustSummoned(Creature* ) {}
106
107        virtual void SummonedCreatureDespawn(Creature* /*unit*/) {}
108
109        // Called when hit by a spell
110        virtual void SpellHit(Unit*, const SpellEntry*) {}
111
112        // Called when vitim entered water and creature can not enter water
113        virtual bool canReachByRangeAttack(Unit*) { return false; }
114
115        // Called when the creature is attacked
116        virtual void AttackedBy(Unit * /*attacker*/) {}
117
118        // Called when creature is spawned or respawned (for reseting variables)
119        virtual void JustRespawned() {}
120
121        // Called at waypoint reached or point movement finished
122        virtual void MovementInform(uint32 /*MovementType*/, uint32 /*Data*/) {}
123};
124
125struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature>
126{
127
128    SelectableAI(const char *id) : FactoryHolder<CreatureAI>(id) {}
129};
130
131template<class REAL_AI>
132struct CreatureAIFactory : public SelectableAI
133{
134    CreatureAIFactory(const char *name) : SelectableAI(name) {}
135
136    CreatureAI* Create(void *) const;
137
138    int Permit(const Creature *c) const { return REAL_AI::Permissible(c); }
139};
140
141enum Permitions
142{
143    PERMIT_BASE_NO                 = -1,
144    PERMIT_BASE_IDLE               = 1,
145    PERMIT_BASE_REACTIVE           = 100,
146    PERMIT_BASE_PROACTIVE          = 200,
147    PERMIT_BASE_FACTION_SPECIFIC   = 400,
148    PERMIT_BASE_SPECIAL            = 800
149};
150
151typedef FactoryHolder<CreatureAI> CreatureAICreator;
152typedef FactoryHolder<CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
153typedef FactoryHolder<CreatureAI>::FactoryHolderRepository CreatureAIRepository;
154#endif
Note: See TracBrowser for help on using the browser.