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

Revision 2, 4.0 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-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
35class MANGOS_DLL_SPEC CreatureAI
36{
37    public:
38
39        virtual ~CreatureAI();
40
41        // Called if IsVisible(Unit *who) is true at each *who move
42        virtual void MoveInLineOfSight(Unit *) = 0;
43
44        // Called at each attack of m_creature by any victim
45        virtual void AttackStart(Unit *) = 0;
46
47        // Called at stopping attack by any attacker
48        virtual void EnterEvadeMode() = 0;
49
50        // Called at any heal cast/item used (call non implemented)
51        virtual void HealBy(Unit * /*healer*/, uint32 /*amount_healed*/) {}
52
53        // Called at any Damage to any victim (before damage apply)
54        virtual void DamageDeal(Unit * /*done_to*/, uint32 & /*damage*/) {}
55
56        // Called at any Damage from any attacker (before damage apply)
57        virtual void DamageTaken(Unit *done_by, uint32 & /*damage*/) { AttackedBy(done_by); }
58
59        // Is unit visible for MoveInLineOfSight
60        virtual bool IsVisible(Unit *) const = 0;
61
62        // Called at World update tick
63        virtual void UpdateAI(const uint32 diff ) = 0;
64
65        // Called when the creature is killed
66        virtual void JustDied(Unit *) {}
67
68        // Called when the creature kills a unit
69        virtual void KilledUnit(Unit *) {}
70
71        // Called when the creature summon successfully other creature
72        virtual void JustSummoned(Creature* ) {}
73
74        virtual void SummonedCreatureDespawn(Creature* /*unit*/) {}
75
76        // Called when hit by a spell
77        virtual void SpellHit(Unit*, const SpellEntry*) {}
78
79        // Called when vitim entered water and creature can not enter water
80        virtual bool canReachByRangeAttack(Unit*) { return false; }
81
82        // Called when the creature is attacked
83        virtual void AttackedBy(Unit * /*attacker*/) {}
84
85        // Called when creature is spawned or respawned (for reseting variables)
86        virtual void JustRespawned() {}
87
88        // Called at waypoint reached or point movement finished
89        virtual void MovementInform(uint32 /*MovementType*/, uint32 /*Data*/) {}
90};
91
92struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature>
93{
94
95    SelectableAI(const char *id) : FactoryHolder<CreatureAI>(id) {}
96};
97
98template<class REAL_AI>
99struct CreatureAIFactory : public SelectableAI
100{
101    CreatureAIFactory(const char *name) : SelectableAI(name) {}
102
103    CreatureAI* Create(void *) const;
104
105    int Permit(const Creature *c) const { return REAL_AI::Permissible(c); }
106};
107
108enum Permitions
109{
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
116};
117
118typedef FactoryHolder<CreatureAI> CreatureAICreator;
119typedef FactoryHolder<CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
120typedef FactoryHolder<CreatureAI>::FactoryHolderRepository CreatureAIRepository;
121#endif
Note: See TracBrowser for help on using the browser.