[2771] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / Creature.h
bloba906cb075bd51cb9a40b197a748f62472e44f1c4
1 /*
2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
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 MANGOSSERVER_CREATURE_H
20 #define MANGOSSERVER_CREATURE_H
22 #include "Common.h"
23 #include "Unit.h"
24 #include "UpdateMask.h"
25 #include "MotionMaster.h"
26 #include "MovementGenerator.h"
27 #include "ItemPrototype.h"
28 #include "LootMgr.h"
29 #include "Database/DatabaseEnv.h"
30 #include "Cell.h"
32 struct SpellEntry;
34 class CreatureAI;
35 class Quest;
36 class Player;
37 class WorldSession;
39 #define UNIT_MOVEMENT_INTERPOLATE_INTERVAL 300
40 #define MAX_CREATURE_WAYPOINTS 16
41 #define MAX_CREATURE_ITEMS 128
43 enum Gossip_Option
45 GOSSIP_OPTION_NONE = 0, //UNIT_NPC_FLAG_NONE = 0,
46 GOSSIP_OPTION_GOSSIP = 1, //UNIT_NPC_FLAG_GOSSIP = 1,
47 GOSSIP_OPTION_QUESTGIVER = 2, //UNIT_NPC_FLAG_QUESTGIVER = 2,
48 GOSSIP_OPTION_VENDOR = 3, //UNIT_NPC_FLAG_VENDOR = 4,
49 GOSSIP_OPTION_TAXIVENDOR = 4, //UNIT_NPC_FLAG_TAXIVENDOR = 8,
50 GOSSIP_OPTION_TRAINER = 5, //UNIT_NPC_FLAG_TRAINER = 16,
51 GOSSIP_OPTION_SPIRITHEALER = 6, //UNIT_NPC_FLAG_SPIRITHEALER = 32,
52 GOSSIP_OPTION_GUARD = 7, //UNIT_NPC_FLAG_GUARD = 64,
53 GOSSIP_OPTION_INNKEEPER = 8, //UNIT_NPC_FLAG_INNKEEPER = 128,
54 GOSSIP_OPTION_BANKER = 9, //UNIT_NPC_FLAG_BANKER = 256,
55 GOSSIP_OPTION_PETITIONER = 10, //UNIT_NPC_FLAG_PETITIONER = 512,
56 GOSSIP_OPTION_TABARDVENDOR = 11, //UNIT_NPC_FLAG_TABARDVENDOR = 1024,
57 GOSSIP_OPTION_BATTLEFIELD = 12, //UNIT_NPC_FLAG_BATTLEFIELDPERSON = 2048,
58 GOSSIP_OPTION_AUCTIONEER = 13, //UNIT_NPC_FLAG_AUCTIONEER = 4096,
59 GOSSIP_OPTION_STABLEPET = 14, //UNIT_NPC_FLAG_STABLE = 8192,
60 GOSSIP_OPTION_ARMORER = 15, //UNIT_NPC_FLAG_ARMORER = 16384,
61 GOSSIP_OPTION_UNLEARNTALENTS = 16 //UNIT_NPC_FLAG_TRAINER (bonus option for GOSSIP_OPTION_TRAINER)
64 enum Gossip_Guard
66 GOSSIP_GUARD_BANK = 32,
67 GOSSIP_GUARD_RIDE = 33,
68 GOSSIP_GUARD_GUILD = 34,
69 GOSSIP_GUARD_INN = 35,
70 GOSSIP_GUARD_MAIL = 36,
71 GOSSIP_GUARD_AUCTION = 37,
72 GOSSIP_GUARD_WEAPON = 38,
73 GOSSIP_GUARD_STABLE = 39,
74 GOSSIP_GUARD_BATTLE = 40,
75 GOSSIP_GUARD_SPELLTRAINER = 41,
76 GOSSIP_GUARD_SKILLTRAINER = 42
79 enum Gossip_Guard_Spell
81 GOSSIP_GUARD_SPELL_WARRIOR = 64,
82 GOSSIP_GUARD_SPELL_PALADIN = 65,
83 GOSSIP_GUARD_SPELL_HUNTER = 66,
84 GOSSIP_GUARD_SPELL_ROGUE = 67,
85 GOSSIP_GUARD_SPELL_PRIEST = 68,
86 GOSSIP_GUARD_SPELL_UNKNOWN1 = 69,
87 GOSSIP_GUARD_SPELL_SHAMAN = 70,
88 GOSSIP_GUARD_SPELL_MAGE = 71,
89 GOSSIP_GUARD_SPELL_WARLOCK = 72,
90 GOSSIP_GUARD_SPELL_UNKNOWN2 = 73,
91 GOSSIP_GUARD_SPELL_DRUID = 74
94 enum Gossip_Guard_Skill
96 GOSSIP_GUARD_SKILL_ALCHEMY = 80,
97 GOSSIP_GUARD_SKILL_BLACKSMITH = 81,
98 GOSSIP_GUARD_SKILL_COOKING = 82,
99 GOSSIP_GUARD_SKILL_ENCHANT = 83,
100 GOSSIP_GUARD_SKILL_FIRSTAID = 84,
101 GOSSIP_GUARD_SKILL_FISHING = 85,
102 GOSSIP_GUARD_SKILL_HERBALISM = 86,
103 GOSSIP_GUARD_SKILL_LEATHER = 87,
104 GOSSIP_GUARD_SKILL_MINING = 88,
105 GOSSIP_GUARD_SKILL_SKINNING = 89,
106 GOSSIP_GUARD_SKILL_TAILORING = 90,
107 GOSSIP_GUARD_SKILL_ENGINERING = 91
110 struct GossipOption
112 uint32 Id;
113 uint32 GossipId;
114 uint32 NpcFlag;
115 uint32 Icon;
116 uint32 Action;
117 std::string Option;
120 struct CreatureItem
122 uint32 id;
123 uint32 count;
124 uint32 maxcount;
125 uint32 incrtime;
126 uint32 lastincr;
129 struct TrainerSpell
131 SpellEntry* spell;
132 uint32 spellcost;
133 uint32 reqspell;
134 uint32 reqskill;
135 uint32 reqskillvalue;
136 uint32 reqlevel;
139 // Only GCC 4.1.0 and later support #pragma pack(push,1) syntax
140 #if defined( __GNUC__ ) && (GCC_MAJOR < 4 || GCC_MAJOR == 4 && GCC_MINOR < 1)
141 #pragma pack(1)
142 #else
143 #pragma pack(push,1)
144 #endif
146 struct CreatureInfo
148 uint32 Entry;
149 uint32 DisplayID_m;
150 uint32 DisplayID_f;
151 char* Name;
152 char* SubName;
153 uint32 minlevel;
154 uint32 maxlevel;
155 uint32 minhealth;
156 uint32 maxhealth;
157 uint32 minmana;
158 uint32 maxmana;
159 uint32 armor;
160 uint32 faction;
161 uint32 npcflag;
162 float speed;
163 uint32 rank;
164 float mindmg;
165 float maxdmg;
166 uint32 attackpower;
167 uint32 baseattacktime;
168 uint32 rangeattacktime;
169 uint32 Flags;
170 uint32 mount;
171 uint32 dynamicflags;
172 float size;
173 uint32 family;
174 float bounding_radius;
175 uint32 trainer_type;
176 uint32 trainer_spell;
177 uint32 classNum;
178 uint32 race;
179 float minrangedmg;
180 float maxrangedmg;
181 uint32 rangedattackpower;
182 float combat_reach;
183 uint32 type;
184 uint32 civilian;
185 uint32 flag1;
186 uint32 equipmodel[3];
187 uint32 equipinfo[3];
188 uint32 equipslot[3];
189 uint32 lootid;
190 uint32 SkinLootId;
191 uint32 resistance1;
192 uint32 resistance2;
193 uint32 resistance3;
194 uint32 resistance4;
195 uint32 resistance5;
196 uint32 resistance6;
197 uint32 spell1;
198 uint32 spell2;
199 uint32 spell3;
200 uint32 spell4;
201 uint32 mingold;
202 uint32 maxgold;
203 char const* AIName;
204 uint32 MovementType;
205 char const* ScriptName;
207 uint32 randomDisplayID() const;
210 #if defined( __GNUC__ ) && (GCC_MAJOR < 4 || GCC_MAJOR == 4 && GCC_MINOR < 1)
211 #pragma pack()
212 #else
213 #pragma pack(pop)
214 #endif
216 enum UNIT_TYPE
218 NOUNITTYPE = 0,
219 BEAST = 1,
220 DRAGONSKIN = 2,
221 DEMON = 3,
222 ELEMENTAL = 4,
223 GIANT = 5,
224 UNDEAD = 6,
225 HUMANOID = 7,
226 CRITTER = 8,
227 MECHANICAL = 9,
230 // max different by z coordinate for creature aggro reaction
231 #define CREATURE_Z_ATTACK_RANGE 3
233 class MANGOS_DLL_SPEC Creature : public Unit
235 CreatureAI *i_AI;
236 MotionMaster i_motionMaster;
238 public:
240 Creature();
241 virtual ~Creature();
243 typedef std::list<TrainerSpell*> SpellsList;
245 bool Create (uint32 guidlow, uint32 mapid, float x, float y, float z, float ang, uint32 Entry);
246 bool CreateFromProto(uint32 guidlow,uint32 Entry);
247 void SelectLevel(const CreatureInfo *cinfo);
249 virtual void Update( uint32 time );
250 inline void GetRespawnCoord(float &x, float &y, float &z) const { x = respawn_cord[0]; y = respawn_cord[1]; z = respawn_cord[2]; }
251 inline void GetRespawnDist(float &d) const { d = m_respawnradius; }
253 bool isTamed() const { return m_isTamed; }
254 void SaveAsPet();
255 void SetTamed(bool isTamed) { m_isTamed = isTamed; }
256 void Untamed();
257 void GivePetXP(uint32 xp);
259 bool isPet() const { return m_isPet; }
260 bool isTotem() const { return m_isTotem; }
261 bool isCivilian() const { return GetCreatureInfo()->civilian != 0; }
262 bool isCanSwimOrFly() const;
263 bool isCanWalkOrFly() const;
264 bool isCanTrainingOf(Player* player, bool msg) const;
265 bool isCanTrainingAndResetTalentsOf(Player* pPlayer) const;
267 bool isElite() const
269 uint32 rank = GetCreatureInfo()->rank;
270 return rank != CREATURE_ELITE_NORMAL && rank != CREATURE_ELITE_RARE;
273 void AIM_Update(const uint32 &);
274 void AIM_Initialize(void);
275 MotionMaster* operator->(void) { return &i_motionMaster; }
277 void AI_SendMoveToPacket(float x, float y, float z, uint32 time, bool run, bool WalkBack);
278 inline CreatureAI &AI(void) { return *i_AI; }
280 inline void setMoveRandomFlag(bool f) { m_moveRandom = f; }
281 inline void setMoveRunFlag(bool f) { m_moveRun = f; }
282 inline bool getMoveRandomFlag() { return m_moveRandom; }
283 inline bool getMoveRunFlag() { return m_moveRun; }
284 inline bool IsStopped(void) const { return !(hasUnitState(UNIT_STAT_MOVING)); }
285 inline void StopMoving(void)
287 clearUnitState(UNIT_STAT_MOVING);
288 AI_SendMoveToPacket(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, false);
291 uint32 GetBlockValue() const //dunno mob block value
293 return getLevel()/2 + 1;
296 /*********************************************************/
297 /*** VENDOR SYSTEM ***/
298 /*********************************************************/
300 uint8 GetItemCount() const { return itemcount; }
301 uint32 GetItemId( uint32 slot ) const { return item_list[slot].id; }
302 uint32 GetItemCount( uint32 slot ) const { return item_list[slot].count; }
303 uint32 GetMaxItemCount( uint32 slot ) const { return item_list[slot].maxcount; }
304 uint32 GetItemIncrTime( uint32 slot ) const { return item_list[slot].incrtime; }
305 uint32 GetItemLastIncr( uint32 slot ) const { return item_list[slot].lastincr; }
306 void SetItemCount( uint32 slot, uint32 count ) { item_list[slot].count = count; }
307 void SetItemLastIncr( uint32 slot, uint32 ptime ) { item_list[slot].lastincr = ptime; }
308 void AddItem( uint32 item, uint32 maxcount, uint32 ptime)
310 item_list[itemcount].id = item;
311 item_list[itemcount].count = maxcount;
312 item_list[itemcount].maxcount = maxcount;
313 item_list[itemcount].incrtime = ptime;
314 item_list[itemcount].lastincr = (uint32)time(NULL);
315 itemcount++;
318 CreatureInfo const *GetCreatureInfo() const;
320 void CreateTrainerSpells();
321 uint32 GetTrainerSpellsSize() const { return m_tspells.size(); }
322 std::list<TrainerSpell*>::iterator GetTspellsBegin(){ return m_tspells.begin(); }
323 std::list<TrainerSpell*>::iterator GetTspellsEnd(){ return m_tspells.end(); }
325 uint32 getDialogStatus(Player *pPlayer, uint32 defstatus);
327 void prepareGossipMenu( Player *pPlayer,uint32 gossipid );
328 void sendPreparedGossip( Player* player);
329 void OnGossipSelect(Player* player, uint32 option);
330 void OnPoiSelect(Player* player, GossipOption *gossip);
332 uint32 GetGossipTextId(uint32 action, uint32 zoneid);
333 uint32 GetNpcTextId();
334 void LoadGossipOptions();
335 std::string GetGossipTitle(uint8 type, uint32 id);
336 GossipOption* GetGossipOption( uint32 id );
337 uint32 GetGossipCount( uint32 gossipid );
338 void addGossipOption(GossipOption *gso) { m_goptions.push_back(gso); }
340 inline void setEmoteState(uint8 emote) { m_emoteState = emote; };
342 void setDeathState(DeathState s); // overwrite virtual Unit::setDeathState
344 void Say(char const* text, uint32 language);
345 void MonsterSay(char const *text, uint32 language, uint64 targetGUID);
347 bool LoadFromDB(uint32 guid, QueryResult *result = NULL);
348 virtual void SaveToDB(); // overwrited in Pet
349 virtual void DeleteFromDB(); // overwrited in Pet
351 Loot loot;
352 bool lootForPickPocketed;
353 bool lootForBody;
354 void generateMoneyLoot();
355 Player *GetLootRecipient() const;
356 void SetLootRecipient (Player *player);
358 SpellEntry *reachWithSpellAttack(Unit *pVictim);
359 SpellEntry *reachWithSpellCure(Unit *pVictim);
361 uint32 m_spells[CREATURE_MAX_SPELLS];
363 float GetAttackDistance(Unit *pl) const;
364 uint32 getloyalty(){ return ((GetUInt32Value(UNIT_FIELD_BYTES_1) >> 8) & 0xFF);};
365 uint32 getUsedTrainPoint(){ return (GetUInt32Value(UNIT_TRAINING_POINTS) & 0xFFFF);};
366 void GivePetLevel(uint32 level);
368 void CallAssistence();
369 void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; }
371 MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }
372 void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
374 // for use only in LoadHelper, Map::Add Map::CreatureCellRelocation
375 Cell const& GetCurrentCell() const { return m_currentCell; }
376 void SetCurrentCell(Cell const& cell) { m_currentCell = cell; }
378 bool IsVisibleInGridForPlayer(Player* pl) const;
379 protected:
380 void _LoadGoods();
381 void _LoadQuests();
382 void _LoadMovement();
383 void _RealtimeSetCreatureInfo();
385 float _GetHealthMod(int32 Rank);
386 float _GetDamageMod(int32 Rank);
388 uint32 m_lootMoney;
389 uint64 m_lootRecipient;
391 /// Timers
392 uint32 m_deathTimer; // timer for death or corpse disappearance
393 uint32 m_respawnTimer; // timer for respawn to happen
394 uint32 m_respawnDelay; // delay between corpse disappearance and respawning
395 uint32 m_corpseDelay; // delay between death and corpse disappearance
396 float m_respawnradius;
397 CreatureItem item_list[MAX_CREATURE_ITEMS];
398 int itemcount;
400 SpellsList m_tspells;
402 uint32 mTaxiNode;
404 std::list<GossipOption*> m_goptions;
406 float respawn_cord[3];
407 bool m_moveBackward;
408 bool m_moveRandom;
409 bool m_moveRun;
411 uint8 m_emoteState;
412 bool m_isPet; // set only in Pet::Pet
413 bool m_isTotem; // set only in Totem::Totem
414 bool m_isTamed;
415 void RegenerateMana();
416 void RegenerateHealth();
417 uint32 m_regenTimer;
418 MovementGeneratorType m_defaultMovementType;
419 Cell m_currentCell; // store current cell where creature listed
420 bool m_AlreadyCallAssistence;
422 #endif