OregonCore  revision be9e804-git
Your Favourite TBC server
CreatureAI.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGON_CREATUREAI_H
19 #define OREGON_CREATUREAI_H
20 
21 #include "Creature.h"
22 #include "UnitAI.h"
23 #include "Common.h"
24 
25 class WorldObject;
26 class Unit;
27 class Creature;
28 class Player;
29 struct SpellEntry;
30 
31 #define TIME_INTERVAL_LOOK 5000
32 #define VISIBILITY_RANGE 10000
33 
34 //Spell targets used by SelectSpell
36 {
37  SELECT_TARGET_DONTCARE = 0, //All target types allowed
38 
39  SELECT_TARGET_SELF, //Only Self casting
40 
41  SELECT_TARGET_SINGLE_ENEMY, //Only Single Enemy
42  SELECT_TARGET_AOE_ENEMY, //Only AoE Enemy
43  SELECT_TARGET_ANY_ENEMY, //AoE or Single Enemy
44 
45  SELECT_TARGET_SINGLE_FRIEND, //Only Single Friend
46  SELECT_TARGET_AOE_FRIEND, //Only AoE Friend
47  SELECT_TARGET_ANY_FRIEND, //AoE or Single Friend
48 };
49 
50 //Spell Effects used by SelectSpell
52 {
53  SELECT_EFFECT_DONTCARE = 0, //All spell effects allowed
54  SELECT_EFFECT_DAMAGE, //Spell does damage
55  SELECT_EFFECT_HEALING, //Spell does healing
56  SELECT_EFFECT_AURA, //Spell applies an aura
57 };
58 
59 enum SCEquip
60 {
63 };
64 
65 class CreatureAI : public UnitAI
66 {
67  protected:
68  Creature* const me;
69 
70  bool UpdateVictim();
71  bool UpdateVictimByReact();
72  bool UpdateVictimWithGaze();
73  bool UpdateCombatState();
74 
75  void SetGazeOn(Unit* target);
76 
77  Creature* DoSummon(uint32 uiEntry, const Position& pos, uint32 uiDespawntime = 30000, TempSummonType uiType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
78  Creature* DoSummon(uint32 uiEntry, WorldObject* obj, float fRadius = 5.0f, uint32 uiDespawntime = 30000, TempSummonType uiType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
79  Creature* DoSummonFlyer(uint32 uiEntry, WorldObject* obj, float fZ, float fRadius = 5.0f, uint32 uiDespawntime = 30000, TempSummonType uiType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
80 
81  public:
82  explicit CreatureAI(Creature* c) :
83  UnitAI((Unit*)c),
84  me(c),
87  AttackDistance(0.0f),
88  AttackAngle(0.0f)
89  {}
90 
91  ~CreatureAI() override {}
92 
93  // == Reactions At =================================
94 
95  // Called if IsVisible(Unit* who) is true at each *who move, reaction at visibility zone enter
96  void MoveInLineOfSight_Safe(Unit* who);
97 
98  // Trigger Creature "Alert" state (creature can see stealthed unit)
99  void TriggerAlert(Unit const* who) const;
100 
101  // Called for reaction at stopping attack at no attackers or targets
102  virtual void EnterEvadeMode();
103 
104  // Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
105  virtual void EnterCombat(Unit* /*enemy*/) {}
106 
107  // Called at any Damage from any attacker (before damage apply)
108  // Note: it for recalculation damage or special reaction at damage
109  // for attack reaction use AttackedBy called for not DOT damage in Unit::DealDamage also
110  virtual void DamageTaken(Unit* /*done_by*/, uint32& /*damage*/) {}
111 
112  // Called when the creature is killed
113  virtual void JustDied(Unit*) {}
114 
115  // Called when the creature kills a unit
116  virtual void KilledUnit(Unit*) {}
117 
118  // Called when the creature summon successfully other creature
119  virtual void JustSummoned(Creature*) {}
120  virtual void IsSummonedBy(Unit* /*summoner*/) {}
121 
122  virtual void SummonedCreatureDespawn(Creature* /*unit*/) {}
123 
124  // Called when hit by a spell
125  virtual void SpellHit(Unit*, const SpellEntry*) {}
126 
127  // Called when spell hits a target
128  virtual void SpellHitTarget(Unit* /*target*/, const SpellEntry*) {}
129 
130  // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
131  virtual void AttackedBy(Unit* attacker) {}
132 
133  virtual bool IsEscorted()
134  {
135  return false;
136  }
137 
138  // Called when creature is spawned or respawned (for reseting variables)
139  virtual void JustRespawned()
140  {
141  Reset();
142  }
143 
144  // Called at waypoint reached or point movement finished
145  virtual void MovementInform(uint32 /*MovementType*/, uint32 /*Data*/) {}
146 
147  // Called if a temporary summoned of m_creature reach a move point
148  virtual void SummonedMovementInform(Creature* /*pSummoned*/, uint32 /*uiMotionType*/, uint32 /*uiData*/) {}
149 
150  void OnCharmed(bool apply) override;
151 
152  //virtual void SpellClick(Player* player) {}
153 
154  // Called at reaching home after evade
155  virtual void JustReachedHome() {}
156 
157  void DoZoneInCombat(Creature* creature = NULL, float maxRangeToNearestTarget = 50.0f);
158  void DoZoneInCombatWithPlayers(bool force = false);
159 
160  // Called at text emote receive from player
161  virtual void ReceiveEmote(Player* /*pPlayer*/, uint32 /*text_emote*/) {}
162 
163  // Called when owner takes damage
164  virtual void OwnerAttackedBy(Unit* /*attacker*/) {}
165 
166  // Called when owner attacks something
167  virtual void OwnerAttacked(Unit* /*target*/) {}
168 
169  // == Triggered Actions Requested ==================
170 
171  // Called when creature attack expected (if creature can and no have current victim)
172  // Note: for reaction at hostile action must be called AttackedBy function.
173  //virtual void AttackStart(Unit* ) {}
174 
175  // Called at World update tick
176  //virtual void UpdateAI(const uint32 /*diff*/) {}
177 
178  // == State checks =================================
179 
180  // Is unit visible for MoveInLineOfSight
181  //virtual bool IsVisible(Unit* ) const { return false; }
182 
183  // Called when victim entered water and creature can not enter water
184  //virtual bool canReachByRangeAttack(Unit*) { return false; }
185 
187  void SetCombatMovement(bool enable);
188  bool IsCombatMovement() const { return CombatMovementEnabled; }
189 
190  // == Fields =======================================
191 
192  // Pointer to controlled by AI creature
193  //Creature* const me;
194 
195  virtual void PassengerBoarded(Unit* /*who*/, int8 /*seatId*/, bool /*apply*/) {}
196 
197  // called when the corpse of this creature gets removed
198  virtual void CorpseRemoved(time_t /*respawnDelay*/) { }
199 
200  virtual void OnSpellClick(Unit* /*clicker*/) { }
201 
202  virtual bool CanSeeAlways(WorldObject const* /*obj*/) { return false; }
203  protected:
204  virtual void MoveInLineOfSight(Unit*);
205 
206  bool _EnterEvadeMode();
207 
212  float AttackAngle;
213 
214  private:
216 };
217 
219 {
226 };
227 
228 #endif
229 
virtual void PassengerBoarded(Unit *, int8, bool)
Definition: CreatureAI.h:195
virtual void EnterEvadeMode()
Definition: CreatureAI.cpp:219
bool IsCombatMovement() const
Definition: CreatureAI.h:188
float AttackAngle
Definition: CreatureAI.h:212
bool UpdateVictim()
Definition: CreatureAI.cpp:276
virtual void ReceiveEmote(Player *, uint32)
Definition: CreatureAI.h:161
void SetCombatMovement(bool enable)
Set combat movement (on/off)
Definition: CreatureAI.cpp:317
void DoZoneInCombat(Creature *creature=NULL, float maxRangeToNearestTarget=50.0f)
Definition: CreatureAI.cpp:78
Creature * DoSummon(uint32 uiEntry, const Position &pos, uint32 uiDespawntime=30000, TempSummonType uiType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
Definition: CreatureAI.cpp:334
virtual void IsSummonedBy(Unit *)
Definition: CreatureAI.h:120
void OnCharmed(bool apply) override
Definition: CreatureAI.cpp:27
virtual void JustRespawned()
Definition: CreatureAI.h:139
NULL Dbg ErrDB Arena Chat Char Map MMap false
Definition: Log.cpp:556
void SetGazeOn(Unit *target)
Definition: CreatureAI.cpp:249
virtual void DamageTaken(Unit *, uint32 &)
Definition: CreatureAI.h:110
~CreatureAI() override
Definition: CreatureAI.h:91
void apply(T *val)
Definition: ByteConverter.h:41
virtual bool IsEscorted()
Definition: CreatureAI.h:133
CreatureAI(Creature *c)
Definition: CreatureAI.h:82
virtual void OwnerAttacked(Unit *)
Definition: CreatureAI.h:167
bool m_MoveInLineOfSight_locked
Definition: CreatureAI.h:215
ACE_INT8 int8
Definition: Define.h:69
virtual bool CanSeeAlways(WorldObject const *)
Definition: CreatureAI.h:202
void DoZoneInCombatWithPlayers(bool force=false)
Definition: CreatureAI.cpp:41
virtual void EnterCombat(Unit *)
Definition: CreatureAI.h:105
Creature *const me
Definition: CreatureAI.h:68
void TriggerAlert(Unit const *who) const
Definition: CreatureAI.cpp:176
virtual void SpellHit(Unit *, const SpellEntry *)
Definition: CreatureAI.h:125
virtual void OnSpellClick(Unit *)
Definition: CreatureAI.h:200
virtual void KilledUnit(Unit *)
Definition: CreatureAI.h:116
virtual void JustDied(Unit *)
Definition: CreatureAI.h:113
SCEquip
Definition: CreatureAI.h:59
TempSummonType
virtual void CorpseRemoved(time_t)
Definition: CreatureAI.h:198
bool _EnterEvadeMode()
Definition: CreatureAI.cpp:296
bool CombatMovementEnabled
Combat movement currently enabled.
Definition: CreatureAI.h:209
virtual void SpellHitTarget(Unit *, const SpellEntry *)
Definition: CreatureAI.h:128
void MoveInLineOfSight_Safe(Unit *who)
Definition: CreatureAI.cpp:150
Creature * DoSummonFlyer(uint32 uiEntry, WorldObject *obj, float fZ, float fRadius=5.0f, uint32 uiDespawntime=30000, TempSummonType uiType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
Definition: CreatureAI.cpp:345
virtual void AttackedBy(Unit *attacker)
Definition: CreatureAI.h:131
despawns after a specified time after death
bool UpdateVictimByReact()
Definition: CreatureAI.cpp:199
SelectEffect
Definition: CreatureAI.h:51
virtual void JustReachedHome()
Definition: CreatureAI.h:155
virtual void MoveInLineOfSight(Unit *)
Definition: CreatureAI.cpp:159
ACE_UINT32 uint32
Definition: Define.h:71
virtual void SummonedCreatureDespawn(Creature *)
Definition: CreatureAI.h:122
true
Definition: Log.cpp:534
virtual void Reset()
Definition: UnitAI.h:61
Definition: Unit.h:908
virtual void SummonedMovementInform(Creature *, uint32, uint32)
Definition: CreatureAI.h:148
bool UpdateVictimWithGaze()
Definition: CreatureAI.cpp:258
bool UpdateCombatState()
Definition: Player.h:923
virtual void MovementInform(uint32, uint32)
Definition: CreatureAI.h:145
float AttackDistance
How should an enemy be chased.
Definition: CreatureAI.h:211
virtual void OwnerAttackedBy(Unit *)
Definition: CreatureAI.h:164
virtual void JustSummoned(Creature *)
Definition: CreatureAI.h:119
SelectTargetType
Definition: CreatureAI.h:35
Definition: UnitAI.h:41
Permitions
Definition: CreatureAI.h:218