[2406] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / Creature.h
bloba7d10f82f7d37a21250e4e1143381b926506e119
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 "Cell.h"
31 struct SpellEntry;
33 class CreatureAI;
34 class Quest;
35 class Player;
36 class WorldSession;
38 #define UNIT_MOVEMENT_INTERPOLATE_INTERVAL 300
39 #define MAX_CREATURE_WAYPOINTS 16
40 #define MAX_CREATURE_ITEMS 128
42 enum Gossip_Option
44 GOSSIP_OPTION_NONE = 0, //UNIT_NPC_FLAG_NONE = 0,
45 GOSSIP_OPTION_GOSSIP = 1, //UNIT_NPC_FLAG_GOSSIP = 1,
46 GOSSIP_OPTION_QUESTGIVER = 2, //UNIT_NPC_FLAG_QUESTGIVER = 2,
47 GOSSIP_OPTION_VENDOR = 3, //UNIT_NPC_FLAG_VENDOR = 4,
48 GOSSIP_OPTION_TAXIVENDOR = 4, //UNIT_NPC_FLAG_TAXIVENDOR = 8,
49 GOSSIP_OPTION_TRAINER = 5, //UNIT_NPC_FLAG_TRAINER = 16,
50 GOSSIP_OPTION_SPIRITHEALER = 6, //UNIT_NPC_FLAG_SPIRITHEALER = 32,
51 GOSSIP_OPTION_GUARD = 7, //UNIT_NPC_FLAG_GUARD = 64,
52 GOSSIP_OPTION_INNKEEPER = 8, //UNIT_NPC_FLAG_INNKEEPER = 128,
53 GOSSIP_OPTION_BANKER = 9, //UNIT_NPC_FLAG_BANKER = 256,
54 GOSSIP_OPTION_PETITIONER = 10, //UNIT_NPC_FLAG_PETITIONER = 512,
55 GOSSIP_OPTION_TABARDVENDOR = 11, //UNIT_NPC_FLAG_TABARDVENDOR = 1024,
56 GOSSIP_OPTION_BATTLEFIELD = 12, //UNIT_NPC_FLAG_BATTLEFIELDPERSON = 2048,
57 GOSSIP_OPTION_AUCTIONEER = 13, //UNIT_NPC_FLAG_AUCTIONEER = 4096,
58 GOSSIP_OPTION_STABLEPET = 14, //UNIT_NPC_FLAG_STABLE = 8192,
59 GOSSIP_OPTION_ARMORER = 15 //UNIT_NPC_FLAG_ARMORER = 16384,
62 enum Gossip_Guard
64 GOSSIP_GUARD_BANK = 32,
65 GOSSIP_GUARD_RIDE = 33,
66 GOSSIP_GUARD_GUILD = 34,
67 GOSSIP_GUARD_INN = 35,
68 GOSSIP_GUARD_MAIL = 36,
69 GOSSIP_GUARD_AUCTION = 37,
70 GOSSIP_GUARD_WEAPON = 38,
71 GOSSIP_GUARD_STABLE = 39,
72 GOSSIP_GUARD_BATTLE = 40,
73 GOSSIP_GUARD_SPELLTRAINER = 41,
74 GOSSIP_GUARD_SKILLTRAINER = 42
77 enum Gossip_Guard_Spell
79 GOSSIP_GUARD_SPELL_WARRIOR = 64,
80 GOSSIP_GUARD_SPELL_PALADIN = 65,
81 GOSSIP_GUARD_SPELL_HUNTER = 66,
82 GOSSIP_GUARD_SPELL_ROGUE = 67,
83 GOSSIP_GUARD_SPELL_PRIEST = 68,
84 GOSSIP_GUARD_SPELL_UNKNOWN1 = 69,
85 GOSSIP_GUARD_SPELL_SHAMAN = 70,
86 GOSSIP_GUARD_SPELL_MAGE = 71,
87 GOSSIP_GUARD_SPELL_WARLOCK = 72,
88 GOSSIP_GUARD_SPELL_UNKNOWN2 = 73,
89 GOSSIP_GUARD_SPELL_DRUID = 74
92 enum Gossip_Guard_Skill
94 GOSSIP_GUARD_SKILL_ALCHEMY = 80,
95 GOSSIP_GUARD_SKILL_BLACKSMITH = 81,
96 GOSSIP_GUARD_SKILL_COOKING = 82,
97 GOSSIP_GUARD_SKILL_ENCHANT = 83,
98 GOSSIP_GUARD_SKILL_FIRSTAID = 84,
99 GOSSIP_GUARD_SKILL_FISHING = 85,
100 GOSSIP_GUARD_SKILL_HERBALISM = 86,
101 GOSSIP_GUARD_SKILL_LEATHER = 87,
102 GOSSIP_GUARD_SKILL_MINING = 88,
103 GOSSIP_GUARD_SKILL_SKINNING = 89,
104 GOSSIP_GUARD_SKILL_TAILORING = 90,
105 GOSSIP_GUARD_SKILL_ENGINERING = 91
108 struct GossipOption
110 uint32 Id;
111 uint32 GossipId;
112 uint32 NpcFlag;
113 uint32 Icon;
114 uint32 Action;
115 std::string Option;
118 struct CreatureItem
120 uint32 id;
121 uint32 count;
122 uint32 maxcount;
123 uint32 incrtime;
124 uint32 lastincr;
127 struct TrainerSpell
129 SpellEntry* spell;
130 uint32 spellcost;
131 uint32 reqspell;
132 uint32 reqskill;
133 uint32 reqskillvalue;
134 uint32 reqlevel;
137 // Only GCC 4.1.0 and later support #pragma pack(push,1) syntax
138 #if defined( __GNUC__ ) && (GCC_MAJOR < 4 || GCC_MAJOR == 4 && GCC_MINOR < 1)
139 #pragma pack(1)
140 #else
141 #pragma pack(push,1)
142 #endif
144 struct CreatureInfo
146 uint32 Entry;
147 uint32 DisplayID;
148 char* Name;
149 char* SubName;
150 uint32 minlevel;
151 uint32 maxlevel;
152 uint32 minhealth;
153 uint32 maxhealth;
154 uint32 minmana;
155 uint32 maxmana;
156 uint32 armor;
157 uint32 faction;
158 uint32 npcflag;
159 float speed;
160 uint32 rank;
161 float mindmg;
162 float maxdmg;
163 uint32 attackpower;
164 uint32 baseattacktime;
165 uint32 rangeattacktime;
166 uint32 Flags;
167 uint32 mount;
168 uint32 dynamicflags;
169 float size;
170 uint32 family;
171 float bounding_radius;
172 uint32 trainer_type;
173 uint32 trainer_spell;
174 uint32 classNum;
175 uint32 race;
176 float minrangedmg;
177 float maxrangedmg;
178 uint32 rangedattackpower;
179 float combat_reach;
180 uint32 type;
181 uint32 civilian;
182 uint32 flag1;
183 uint32 equipmodel[3];
184 uint32 equipinfo[3];
185 uint32 equipslot[3];
186 uint32 lootid;
187 uint32 SkinLootId;
188 uint32 resistance1;
189 uint32 resistance2;
190 uint32 resistance3;
191 uint32 resistance4;
192 uint32 resistance5;
193 uint32 resistance6;
194 uint32 spell1;
195 uint32 spell2;
196 uint32 spell3;
197 uint32 spell4;
198 uint32 mingold;
199 uint32 maxgold;
200 char const* AIName;
201 uint32 MovementType;
202 char const* ScriptName;
205 #if defined( __GNUC__ ) && (GCC_MAJOR < 4 || GCC_MAJOR == 4 && GCC_MINOR < 1)
206 #pragma pack()
207 #else
208 #pragma pack(pop)
209 #endif
211 enum UNIT_TYPE
213 NOUNITTYPE = 0,
214 BEAST = 1,
215 DRAGONSKIN = 2,
216 DEMON = 3,
217 ELEMENTAL = 4,
218 GIANT = 5,
219 UNDEAD = 6,
220 HUMANOID = 7,
221 CRITTER = 8,
222 MECHANICAL = 9,
225 class MANGOS_DLL_SPEC Creature : public Unit
227 CreatureAI *i_AI;
228 MotionMaster i_motionMaster;
230 public:
232 Creature();
233 virtual ~Creature();
235 typedef std::list<TrainerSpell*> SpellsList;
237 bool Create (uint32 guidlow, uint32 mapid, float x, float y, float z, float ang, uint32 Entry);
238 bool CreateFromProto(uint32 guidlow,uint32 Entry);
240 virtual void Update( uint32 time );
241 inline void GetRespawnCoord(float &x, float &y, float &z) const { x = respawn_cord[0]; y = respawn_cord[1]; z = respawn_cord[2]; }
242 inline void GetRespawnDist(float &d) const { d = m_respawnradius; }
244 bool isTamed() const { return m_isTamed; }
245 void SaveAsPet();
246 void SetTamed(bool isTamed) { m_isTamed = isTamed; }
247 void Untamed();
248 void GivePetXP(uint32 xp);
250 bool isPet() const { return m_isPet; }
251 bool isTotem() const { return m_isTotem; }
252 bool isCivilian() const { return GetCreatureInfo()->civilian != 0; }
253 bool isCanSwimOrFly() const;
254 bool isCanWalkOrFly() const;
255 bool isCanTrainingOf(Player* player, bool msg) const;
257 bool isElite() const
259 uint32 rank = GetCreatureInfo()->rank;
260 return rank != CREATURE_ELITE_NORMAL && rank != CREATURE_ELITE_RARE;
263 Unit* GetOwner();
265 void AIM_Update(const uint32 &);
266 void AIM_Initialize(void);
267 MotionMaster* operator->(void) { return &i_motionMaster; }
269 void AI_SendMoveToPacket(float x, float y, float z, uint32 time, bool run, bool WalkBack);
270 inline CreatureAI &AI(void) { return *i_AI; }
272 inline void setMoveRandomFlag(bool f) { m_moveRandom = f; }
273 inline void setMoveRunFlag(bool f) { m_moveRun = f; }
274 inline bool getMoveRandomFlag() { return m_moveRandom; }
275 inline bool getMoveRunFlag() { return m_moveRun; }
276 inline bool IsStopped(void) const { return !(hasUnitState(UNIT_STAT_MOVING)); }
277 inline void StopMoving(void)
279 clearUnitState(UNIT_STAT_MOVING);
280 AI_SendMoveToPacket(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, false);
283 uint32 GetBlockValue() const //dunno mob block value
285 return getLevel()/2 + 1;
288 /*********************************************************/
289 /*** VENDOR SYSTEM ***/
290 /*********************************************************/
292 uint8 GetItemCount() const { return itemcount; }
293 uint32 GetItemId( uint32 slot ) const { return item_list[slot].id; }
294 uint32 GetItemCount( uint32 slot ) const { return item_list[slot].count; }
295 uint32 GetMaxItemCount( uint32 slot ) const { return item_list[slot].maxcount; }
296 uint32 GetItemIncrTime( uint32 slot ) const { return item_list[slot].incrtime; }
297 uint32 GetItemLastIncr( uint32 slot ) const { return item_list[slot].lastincr; }
298 void SetItemCount( uint32 slot, uint32 count ) { item_list[slot].count = count; }
299 void SetItemLastIncr( uint32 slot, uint32 ptime ) { item_list[slot].lastincr = ptime; }
300 void AddItem( uint32 item, uint32 maxcount, uint32 ptime)
302 item_list[itemcount].id = item;
303 item_list[itemcount].count = maxcount;
304 item_list[itemcount].maxcount = maxcount;
305 item_list[itemcount].incrtime = ptime;
306 item_list[itemcount].lastincr = (uint32)time(NULL);
307 itemcount++;
310 CreatureInfo const *GetCreatureInfo() const;
312 void CreateTrainerSpells();
313 uint32 GetTrainerSpellsSize() const { return m_tspells.size(); }
314 std::list<TrainerSpell*>::iterator GetTspellsBegin(){ return m_tspells.begin(); }
315 std::list<TrainerSpell*>::iterator GetTspellsEnd(){ return m_tspells.end(); }
317 uint32 getDialogStatus(Player *pPlayer, uint32 defstatus);
319 bool hasQuest(uint32 quest_id);
320 bool hasInvolvedQuest(uint32 quest_id);
322 void prepareGossipMenu( Player *pPlayer,uint32 gossipid );
323 void sendPreparedGossip( Player* player);
324 void OnGossipSelect(Player* player, uint32 option);
325 void OnPoiSelect(Player* player, GossipOption *gossip);
327 uint32 GetGossipTextId(uint32 action, uint32 zoneid);
328 uint32 GetNpcTextId();
329 void LoadGossipOptions();
330 std::string GetGossipTitle(uint8 type, uint32 id);
331 GossipOption* GetGossipOption( uint32 id );
332 uint32 GetGossipCount( uint32 gossipid );
333 void addGossipOption(GossipOption *gso) { m_goptions.push_back(gso); }
335 void generateMoneyLoot();
336 void getSkinLoot();
338 inline void setEmoteState(uint8 emote) { m_emoteState = emote; };
340 void setDeathState(DeathState s) // overwrite virtual Unit::setDeathState
342 if(s == JUST_DIED)
344 m_deathTimer = m_corpseDelay;
346 if(!IsStopped()) StopMoving();
348 Unit::setDeathState(s);
350 if(s == JUST_DIED)
351 Unit::setDeathState(CORPSE);
354 void Say(char const* text, uint32 language);
356 bool LoadFromDB(uint32 guid);
357 virtual void SaveToDB(); // overwrited in Pet
358 virtual void DeleteFromDB(); // overwrited in Pet
360 Loot loot;
361 bool lootForPickPocketed;
362 bool lootForBody;
363 bool lootForSkinning;
365 SpellEntry *reachWithSpellAttack(Unit *pVictim);
366 uint32 m_spells[CREATURE_MAX_SPELLS];
368 float GetAttackDistance(Unit *pl);
369 uint32 getloyalty(){ return ((GetUInt32Value(UNIT_FIELD_BYTES_1) >> 8) & 0xFF);};
370 uint32 getUsedTrainPoint(){ return (GetUInt32Value(UNIT_TRAINING_POINTS) & 0xFFFF);};
371 void GivePetLevel(uint32 level);
373 MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }
374 void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
376 // for use only in LoadHelper, Map::Add Map::CreatureCellRelocation
377 Cell const& GetCurrentCell() const { return m_currentCell; }
378 void SetCurrentCell(Cell const& cell) { m_currentCell = cell; }
379 protected:
380 void _LoadGoods();
381 void _LoadQuests();
382 void _LoadMovement();
383 void _RealtimeSetCreatureInfo();
385 uint32 m_lootMoney;
387 /// Timers
388 uint32 m_deathTimer; // timer for death or corpse disappearance
389 uint32 m_respawnTimer; // timer for respawn to happen
390 uint32 m_respawnDelay; // delay between corpse disappearance and respawning
391 uint32 m_corpseDelay; // delay between death and corpse disappearance
392 float m_respawnradius;
393 CreatureItem item_list[MAX_CREATURE_ITEMS];
394 int itemcount;
396 SpellsList m_tspells;
398 uint32 mTaxiNode;
400 std::list<GossipOption*> m_goptions;
402 float respawn_cord[3];
403 bool m_moveBackward;
404 bool m_moveRandom;
405 bool m_moveRun;
407 uint8 m_emoteState;
408 bool m_isPet; // set only in Pet::Pet
409 bool m_isTotem; // set only in Totem::Totem
410 bool m_isTamed;
411 void RegenerateMana();
412 void RegenerateHealth();
413 uint32 m_regenTimer;
414 MovementGeneratorType m_defaultMovementType;
415 Cell m_currentCell; // store current cell where creature listed
417 #endif