TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CreatureAI.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_CREATUREAI_H
20 #define TRINITY_CREATUREAI_H
21 
22 #include "Creature.h"
23 #include "UnitAI.h"
24 #include "AreaBoundary.h"
25 #include "Common.h"
26 
27 class WorldObject;
28 class Unit;
29 class Creature;
30 class Player;
31 class SpellInfo;
32 
33 #define TIME_INTERVAL_LOOK 5000
34 #define VISIBILITY_RANGE 10000
35 
36 //Spell targets used by SelectSpell
38 {
39  SELECT_TARGET_DONTCARE = 0, //All target types allowed
40 
41  SELECT_TARGET_SELF, //Only Self casting
42 
43  SELECT_TARGET_SINGLE_ENEMY, //Only Single Enemy
44  SELECT_TARGET_AOE_ENEMY, //Only AoE Enemy
45  SELECT_TARGET_ANY_ENEMY, //AoE or Single Enemy
46 
47  SELECT_TARGET_SINGLE_FRIEND, //Only Single Friend
48  SELECT_TARGET_AOE_FRIEND, //Only AoE Friend
49  SELECT_TARGET_ANY_FRIEND //AoE or Single Friend
50 };
51 
52 //Spell Effects used by SelectSpell
54 {
55  SELECT_EFFECT_DONTCARE = 0, //All spell effects allowed
56  SELECT_EFFECT_DAMAGE, //Spell does damage
57  SELECT_EFFECT_HEALING, //Spell does healing
58  SELECT_EFFECT_AURA //Spell applies an aura
59 };
60 
61 enum SCEquip
62 {
65 };
66 
67 typedef std::set<AreaBoundary const*> CreatureBoundary;
69 {
70  protected:
71  Creature* const me;
72 
73  bool UpdateVictim();
74  bool UpdateVictimWithGaze();
75 
76  void SetGazeOn(Unit* target);
77 
78  Creature* DoSummon(uint32 entry, Position const& pos, uint32 despawnTime = 30000, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
79  Creature* DoSummon(uint32 entry, WorldObject* obj, float radius = 5.0f, uint32 despawnTime = 30000, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
80  Creature* DoSummonFlyer(uint32 entry, WorldObject* obj, float flightZ, float radius = 5.0f, uint32 despawnTime = 30000, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
81 
82  bool CheckBoundary(Position const* who = nullptr) const;
83  void SetBoundary(CreatureBoundary const* boundary) { _boundary = boundary; me->DoImmediateBoundaryCheck(); }
84  public:
86  {
87  EVADE_REASON_NO_HOSTILES, // the creature's threat list is empty
88  EVADE_REASON_BOUNDARY, // the creature has moved outside its evade boundary
89  EVADE_REASON_SEQUENCE_BREAK, // this is a boss and the pre-requisite encounters for engaging it are not defeated yet
90  EVADE_REASON_OTHER
91  };
92 
93  void Talk(uint8 id, WorldObject const* whisperTarget = nullptr);
94 
95  explicit CreatureAI(Creature* creature) : UnitAI(creature), me(creature), _boundary(nullptr), m_MoveInLineOfSight_locked(false) { }
96 
97  virtual ~CreatureAI() { }
98 
100 
101  // Called if IsVisible(Unit* who) is true at each who move, reaction at visibility zone enter
102  void MoveInLineOfSight_Safe(Unit* who);
103 
104  // Trigger Creature "Alert" state (creature can see stealthed unit)
105  void TriggerAlert(Unit const* who) const;
106 
107  // Called in Creature::Update when deathstate = DEAD. Inherited classes may maniuplate the ability to respawn based on scripted events.
108  virtual bool CanRespawn() { return true; }
109 
110  // Called for reaction at stopping attack at no attackers or targets
111  virtual void EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER);
112 
113  // Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
114  virtual void EnterCombat(Unit* /*victim*/) { }
115 
116  // Called when the creature is killed
117  virtual void JustDied(Unit* /*killer*/) { }
118 
119  // Called when the creature kills a unit
120  virtual void KilledUnit(Unit* /*victim*/) { }
121 
122  // Called when the creature summon successfully other creature
123  virtual void JustSummoned(Creature* /*summon*/) { }
124  virtual void IsSummonedBy(Unit* /*summoner*/) { }
125 
126  virtual void SummonedCreatureDespawn(Creature* /*summon*/) { }
127  virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) { }
128 
129  // Called when hit by a spell
130  virtual void SpellHit(Unit* /*caster*/, SpellInfo const* /*spell*/) { }
131 
132  // Called when spell hits a target
133  virtual void SpellHitTarget(Unit* /*target*/, SpellInfo const* /*spell*/) { }
134 
135  // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
136  virtual void AttackedBy(Unit* /*attacker*/) { }
137  virtual bool IsEscorted() const { return false; }
138 
139  // Called when creature is spawned or respawned
140  virtual void JustRespawned() { }
141 
142  // Called at waypoint reached or point movement finished
143  virtual void MovementInform(uint32 /*type*/, uint32 /*id*/) { }
144 
145  void OnCharmed(bool apply) override;
146 
147  // Called at reaching home after evade
148  virtual void JustReachedHome() { }
149 
150  void DoZoneInCombat(Creature* creature = NULL, float maxRangeToNearestTarget = 50.0f);
151 
152  // Called at text emote receive from player
153  virtual void ReceiveEmote(Player* /*player*/, uint32 /*emoteId*/) { }
154 
155  // Called when owner takes damage
156  virtual void OwnerAttackedBy(Unit* /*attacker*/) { }
157 
158  // Called when owner attacks something
159  virtual void OwnerAttacked(Unit* /*target*/) { }
160 
162 
163  // Called when creature attack expected (if creature can and no have current victim)
164  // Note: for reaction at hostile action must be called AttackedBy function.
165  //virtual void AttackStart(Unit*) { }
166 
167  // Called at World update tick
168  //virtual void UpdateAI(const uint32 /*diff*/) { }
169 
171 
172  // Is unit visible for MoveInLineOfSight
173  //virtual bool IsVisible(Unit*) const { return false; }
174 
175  // called when the corpse of this creature gets removed
176  virtual void CorpseRemoved(uint32& /*respawnDelay*/) { }
177 
178  // Called when victim entered water and creature can not enter water
179  //virtual bool CanReachByRangeAttack(Unit*) { return false; }
180 
182 
183  virtual void PassengerBoarded(Unit* /*passenger*/, int8 /*seatId*/, bool /*apply*/) { }
184 
185  virtual void OnSpellClick(Unit* /*clicker*/, bool& /*result*/) { }
186 
187  virtual bool CanSeeAlways(WorldObject const* /*obj*/) { return false; }
188 
189  // intended for encounter design/debugging. do not use for other purposes. expensive.
190  int32 VisualizeBoundary(uint32 duration, Unit* owner=nullptr, bool fill=false) const;
191  virtual bool CheckInRoom();
192  CreatureBoundary const* GetBoundary() const { return _boundary; }
193 
194  protected:
195  virtual void MoveInLineOfSight(Unit* /*who*/);
196 
197  bool _EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER);
198 
200 
201  private:
203 };
204 
206 {
213 };
214 
215 #endif
virtual void PassengerBoarded(Unit *, int8, bool)
== Fields =======================================
Definition: CreatureAI.h:183
int8_t int8
Definition: Define.h:148
virtual void SpellHitTarget(Unit *, SpellInfo const *)
Definition: CreatureAI.h:133
Definition: SpellInfo.h:326
virtual void ReceiveEmote(Player *, uint32)
Definition: CreatureAI.h:153
virtual void IsSummonedBy(Unit *)
Definition: CreatureAI.h:124
Definition: CreatureAI.h:207
Definition: CreatureAI.h:48
Talk
Definition: boss_noth.cpp:41
virtual void AttackedBy(Unit *)
Definition: CreatureAI.h:136
Definition: CreatureAI.h:209
Definition: CreatureAI.h:210
arena_t NULL
Definition: jemalloc_internal.h:624
virtual void JustRespawned()
Definition: CreatureAI.h:140
EvadeReason
Definition: CreatureAI.h:85
#define false
Definition: CascPort.h:18
Definition: CreatureAI.h:55
Definition: CreatureAI.h:56
Definition: Object.h:423
Definition: Creature.h:467
Definition: CreatureAI.h:47
TempSummonType
Definition: Object.h:52
void apply(T *val)
Definition: ByteConverter.h:41
virtual bool IsEscorted() const
Definition: CreatureAI.h:137
Definition: CreatureAI.h:212
Definition: CreatureAI.h:45
virtual void OwnerAttacked(Unit *)
Definition: CreatureAI.h:159
bool m_MoveInLineOfSight_locked
Definition: CreatureAI.h:202
virtual bool CanSeeAlways(WorldObject const *)
Definition: CreatureAI.h:187
Definition: CreatureAI.h:63
virtual void EnterCombat(Unit *)
Definition: CreatureAI.h:114
Creature *const me
Definition: CreatureAI.h:71
Definition: CreatureAI.h:89
Definition: CreatureAI.h:208
Definition: CreatureAI.h:88
virtual void SpellHit(Unit *, SpellInfo const *)
Definition: CreatureAI.h:130
Definition: CreatureAI.h:44
Definition: CreatureAI.h:39
std::set< AreaBoundary const * > CreatureBoundary
Definition: CreatureAI.h:67
Definition: CreatureAI.h:57
Definition: CreatureAI.h:49
virtual void KilledUnit(Unit *)
Definition: CreatureAI.h:120
int32_t int32
Definition: Define.h:146
Definition: CreatureAI.h:68
virtual void JustDied(Unit *)
Definition: CreatureAI.h:117
SCEquip
Definition: CreatureAI.h:61
uint32_t uint32
Definition: Define.h:150
Definition: CreatureAI.h:87
virtual void SummonedCreatureDies(Creature *, Unit *)
Definition: CreatureAI.h:127
Definition: CreatureAI.h:43
void SetBoundary(CreatureBoundary const *boundary)
Definition: CreatureAI.h:83
CreatureBoundary const * GetBoundary() const
Definition: CreatureAI.h:192
Definition: CreatureAI.h:41
void DoImmediateBoundaryCheck()
Definition: Creature.h:643
virtual bool CanRespawn()
Definition: CreatureAI.h:108
virtual void OnSpellClick(Unit *, bool &)
Definition: CreatureAI.h:185
CreatureBoundary const * _boundary
Definition: CreatureAI.h:199
#define TC_GAME_API
Definition: Define.h:134
CreatureAI(Creature *creature)
Definition: CreatureAI.h:95
Definition: Object.h:59
SelectEffect
Definition: CreatureAI.h:53
virtual ~CreatureAI()
Definition: CreatureAI.h:97
virtual void JustReachedHome()
Definition: CreatureAI.h:148
Definition: CreatureAI.h:58
uint8_t uint8
Definition: Define.h:152
Definition: Position.h:27
Definition: CreatureAI.h:211
virtual void CorpseRemoved(uint32 &)
== Triggered Actions Requested ==================
Definition: CreatureAI.h:176
virtual void OnCharmed(bool apply)=0
virtual void SummonedCreatureDespawn(Creature *)
Definition: CreatureAI.h:126
Definition: Unit.h:1305
virtual void MovementInform(uint32, uint32)
Definition: CreatureAI.h:143
virtual void OwnerAttackedBy(Unit *)
Definition: CreatureAI.h:156
virtual void JustSummoned(Creature *)
Definition: CreatureAI.h:123
SelectTargetType
Definition: CreatureAI.h:37
Definition: UnitAI.h:118
Definition: CreatureAI.h:64
Permitions
Definition: CreatureAI.h:205