TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Object.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 _OBJECT_H
20 #define _OBJECT_H
21 
22 #include "Common.h"
23 #include "Position.h"
24 #include "UpdateMask.h"
25 #include "GridReference.h"
26 #include "ObjectDefines.h"
27 #include "Map.h"
28 
29 #include <set>
30 #include <string>
31 #include <sstream>
32 
33 #define CONTACT_DISTANCE 0.5f
34 #define INTERACTION_DISTANCE 5.0f
35 #define ATTACK_DISTANCE 5.0f
36 #define INSPECT_DISTANCE 28.0f
37 #define TRADE_DISTANCE 11.11f
38 #define MAX_VISIBILITY_DISTANCE SIZE_OF_GRIDS // max distance for visible objects
39 #define SIGHT_RANGE_UNIT 50.0f
40 #define DEFAULT_VISIBILITY_DISTANCE 90.0f // default visible distance, 90 yards on continents
41 #define DEFAULT_VISIBILITY_INSTANCE 170.0f // default visible distance in instances, 170 yards
42 #define DEFAULT_VISIBILITY_BGARENAS 533.0f // default visible distance in BG/Arenas, roughly 533 yards
43 
44 #define DEFAULT_WORLD_OBJECT_SIZE 0.388999998569489f // player size, also currently used (correctly?) for any non Unit world objects
45 #define DEFAULT_COMBAT_REACH 1.5f
46 #define MIN_MELEE_REACH 2.0f
47 #define NOMINAL_MELEE_RANGE 5.0f
48 #define MELEE_RANGE (NOMINAL_MELEE_RANGE - MIN_MELEE_REACH * 2) //center to center for players
49 
50 #define DEFAULT_PHASE 169
51 
53 {
54  TEMPSUMMON_TIMED_OR_DEAD_DESPAWN = 1, // despawns after a specified time OR when the creature disappears
55  TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN = 2, // despawns after a specified time OR when the creature dies
56  TEMPSUMMON_TIMED_DESPAWN = 3, // despawns after a specified time
57  TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT = 4, // despawns after a specified time after the creature is out of combat
58  TEMPSUMMON_CORPSE_DESPAWN = 5, // despawns instantly after death
59  TEMPSUMMON_CORPSE_TIMED_DESPAWN = 6, // despawns after a specified time after death
60  TEMPSUMMON_DEAD_DESPAWN = 7, // despawns when the creature disappears
61  TEMPSUMMON_MANUAL_DESPAWN = 8 // despawns when UnSummon() is called
62 };
63 
65 {
66  PHASEMASK_NORMAL = 0x00000001,
67  PHASEMASK_ANYWHERE = 0xFFFFFFFF
68 };
69 
71 {
72  NOTIFY_NONE = 0x00,
75  NOTIFY_ALL = 0xFF
76 };
77 
78 class Corpse;
79 class Creature;
80 class CreatureAI;
81 class DynamicObject;
82 class GameObject;
83 class InstanceScript;
84 class Player;
85 class TempSummon;
86 class Transport;
87 class Unit;
88 class UpdateData;
89 class WorldObject;
90 class WorldPacket;
91 class ZoneScript;
92 
93 typedef std::unordered_map<Player*, UpdateData> UpdateDataMapType;
94 
96 {
97  public:
98  virtual ~Object();
99 
100  bool IsInWorld() const { return m_inWorld; }
101 
102  virtual void AddToWorld();
103  virtual void RemoveFromWorld();
104 
105  ObjectGuid const& GetGUID() const { return GetGuidValue(OBJECT_FIELD_GUID); }
106  PackedGuid const& GetPackGUID() const { return m_PackGUID; }
107  uint32 GetEntry() const { return GetUInt32Value(OBJECT_FIELD_ENTRY); }
108  void SetEntry(uint32 entry) { SetUInt32Value(OBJECT_FIELD_ENTRY, entry); }
109 
110  float GetObjectScale() const { return GetFloatValue(OBJECT_FIELD_SCALE_X); }
111  virtual void SetObjectScale(float scale) { SetFloatValue(OBJECT_FIELD_SCALE_X, scale); }
112 
113  TypeID GetTypeId() const { return m_objectTypeId; }
114  bool isType(uint16 mask) const { return (mask & m_objectType) != 0; }
115 
116  virtual void BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) const;
117  void SendUpdateToPlayer(Player* player);
118 
119  void BuildValuesUpdateBlockForPlayer(UpdateData* data, Player* target) const;
120  void BuildOutOfRangeUpdateBlock(UpdateData* data) const;
121 
122  virtual void DestroyForPlayer(Player* target) const;
123 
124  int32 GetInt32Value(uint16 index) const;
125  uint32 GetUInt32Value(uint16 index) const;
126  uint64 GetUInt64Value(uint16 index) const;
127  float GetFloatValue(uint16 index) const;
128  uint8 GetByteValue(uint16 index, uint8 offset) const;
129  uint16 GetUInt16Value(uint16 index, uint8 offset) const;
130  ObjectGuid const& GetGuidValue(uint16 index) const;
131 
132  void SetInt32Value(uint16 index, int32 value);
133  void SetUInt32Value(uint16 index, uint32 value);
134  void UpdateUInt32Value(uint16 index, uint32 value);
135  void SetUInt64Value(uint16 index, uint64 value);
136  void SetFloatValue(uint16 index, float value);
137  void SetByteValue(uint16 index, uint8 offset, uint8 value);
138  void SetUInt16Value(uint16 index, uint8 offset, uint16 value);
139  void SetGuidValue(uint16 index, ObjectGuid const& value);
140  void SetStatFloatValue(uint16 index, float value);
141  void SetStatInt32Value(uint16 index, int32 value);
142 
143  bool AddGuidValue(uint16 index, ObjectGuid const& value);
144  bool RemoveGuidValue(uint16 index, ObjectGuid const& value);
145 
146  void ApplyModUInt32Value(uint16 index, int32 val, bool apply);
147  void ApplyModInt32Value(uint16 index, int32 val, bool apply);
148  void ApplyModUInt16Value(uint16 index, uint8 offset, int16 val, bool apply);
149  void ApplyModPositiveFloatValue(uint16 index, float val, bool apply);
150  void ApplyModSignedFloatValue(uint16 index, float val, bool apply);
151  void ApplyPercentModFloatValue(uint16 index, float val, bool apply);
152 
153  void SetFlag(uint16 index, uint32 newFlag);
154  void RemoveFlag(uint16 index, uint32 oldFlag);
155  void ToggleFlag(uint16 index, uint32 flag);
156  bool HasFlag(uint16 index, uint32 flag) const;
157  void ApplyModFlag(uint16 index, uint32 flag, bool apply);
158 
159  void SetByteFlag(uint16 index, uint8 offset, uint8 newFlag);
160  void RemoveByteFlag(uint16 index, uint8 offset, uint8 newFlag);
161  void ToggleByteFlag(uint16 index, uint8 offset, uint8 flag);
162  bool HasByteFlag(uint16 index, uint8 offset, uint8 flag) const;
163 
164  void SetFlag64(uint16 index, uint64 newFlag);
165  void RemoveFlag64(uint16 index, uint64 oldFlag);
166  void ToggleFlag64(uint16 index, uint64 flag);
167  bool HasFlag64(uint16 index, uint64 flag) const;
168  void ApplyModFlag64(uint16 index, uint64 flag, bool apply);
169 
170  std::vector<uint32> const& GetDynamicValues(uint16 index) const;
171  void AddDynamicValue(uint16 index, uint32 value);
172  void RemoveDynamicValue(uint16 index, uint32 value);
173  void ClearDynamicValue(uint16 index);
174  void SetDynamicValue(uint16 index, uint8 offset, uint32 value);
175 
176  void ClearUpdateMask(bool remove);
177 
178  uint16 GetValuesCount() const { return m_valuesCount; }
179 
180  virtual bool hasQuest(uint32 /* quest_id */) const { return false; }
181  virtual bool hasInvolvedQuest(uint32 /* quest_id */) const { return false; }
182  virtual void BuildUpdate(UpdateDataMapType&) { }
183  void BuildFieldsUpdate(Player*, UpdateDataMapType &) const;
184 
185  void SetFieldNotifyFlag(uint16 flag) { _fieldNotifyFlags |= flag; }
186  void RemoveFieldNotifyFlag(uint16 flag) { _fieldNotifyFlags &= uint16(~flag); }
187 
188  // FG: some hacky helpers
189  void ForceValuesUpdateAtIndex(uint32);
190 
191  Player* ToPlayer() { if (GetTypeId() == TYPEID_PLAYER) return reinterpret_cast<Player*>(this); else return NULL; }
192  Player const* ToPlayer() const { if (GetTypeId() == TYPEID_PLAYER) return reinterpret_cast<Player const*>(this); else return NULL; }
193 
194  Creature* ToCreature() { if (GetTypeId() == TYPEID_UNIT) return reinterpret_cast<Creature*>(this); else return NULL; }
195  Creature const* ToCreature() const { if (GetTypeId() == TYPEID_UNIT) return reinterpret_cast<Creature const*>(this); else return NULL; }
196 
197  Unit* ToUnit() { if (isType(TYPEMASK_UNIT)) return reinterpret_cast<Unit*>(this); else return NULL; }
198  Unit const* ToUnit() const { if (isType(TYPEMASK_UNIT)) return reinterpret_cast<Unit const*>(this); else return NULL; }
199 
200  GameObject* ToGameObject() { if (GetTypeId() == TYPEID_GAMEOBJECT) return reinterpret_cast<GameObject*>(this); else return NULL; }
201  GameObject const* ToGameObject() const { if (GetTypeId() == TYPEID_GAMEOBJECT) return reinterpret_cast<GameObject const*>(this); else return NULL; }
202 
203  Corpse* ToCorpse() { if (GetTypeId() == TYPEID_CORPSE) return reinterpret_cast<Corpse*>(this); else return NULL; }
204  Corpse const* ToCorpse() const { if (GetTypeId() == TYPEID_CORPSE) return reinterpret_cast<Corpse const*>(this); else return NULL; }
205 
206  DynamicObject* ToDynObject() { if (GetTypeId() == TYPEID_DYNAMICOBJECT) return reinterpret_cast<DynamicObject*>(this); else return NULL; }
207  DynamicObject const* ToDynObject() const { if (GetTypeId() == TYPEID_DYNAMICOBJECT) return reinterpret_cast<DynamicObject const*>(this); else return NULL; }
208 
209  AreaTrigger* ToAreaTrigger() { if (GetTypeId() == TYPEID_AREATRIGGER) return reinterpret_cast<AreaTrigger*>(this); else return NULL; }
210  AreaTrigger const* ToAreaTrigger() const { if (GetTypeId() == TYPEID_AREATRIGGER) return reinterpret_cast<AreaTrigger const*>(this); else return NULL; }
211 
212  protected:
213  Object();
214 
215  void _InitValues();
216  void _Create(ObjectGuid const& guid);
217  std::string _ConcatFields(uint16 startIndex, uint16 size) const;
218  void _LoadIntoDataField(std::string const& data, uint32 startOffset, uint32 count);
219 
220  uint32 GetUpdateFieldData(Player const* target, uint32*& flags) const;
221  uint32 GetDynamicUpdateFieldData(Player const* target, uint32*& flags) const;
222 
223  void BuildMovementUpdate(ByteBuffer* data, uint32 flags) const;
224  virtual void BuildValuesUpdate(uint8 updatetype, ByteBuffer* data, Player* target) const;
225  virtual void BuildDynamicValuesUpdate(uint8 updatetype, ByteBuffer* data, Player* target) const;
226 
228 
231 
232  union
233  {
237  };
238 
239  std::vector<uint32>* _dynamicValues;
240 
244 
247 
249 
250  virtual void AddToObjectUpdate() = 0;
251  virtual void RemoveFromObjectUpdate() = 0;
252  void AddToObjectUpdateIfNeeded();
253 
255 
256  private:
257  bool m_inWorld;
258 
260 
261  // for output helpfull error messages from asserts
262  bool PrintIndexError(uint32 index, bool set) const;
263  Object(Object const& right) = delete;
264  Object& operator=(Object const& right) = delete;
265 };
266 
268 {
269  // common
275 
276  // transport
278  {
279  void Reset()
280  {
281  guid.Clear();
282  pos.Relocate(0.0f, 0.0f, 0.0f, 0.0f);
283  seat = -1;
284  time = 0;
285  prevTime = 0;
286  vehicleId = 0;
287  }
288 
295  } transport;
296 
297  // swimming/flying
298  float pitch;
299 
300  // jumping
301  struct JumpInfo
302  {
303  void Reset()
304  {
305  fallTime = 0;
306  zspeed = sinAngle = cosAngle = xyspeed = 0.0f;
307  }
308 
310 
312 
313  } jump;
314 
315  // spline
317 
319  flags(0), flags2(0), time(0), pitch(0.0f), splineElevation(0.0f)
320  {
321  pos.Relocate(0.0f, 0.0f, 0.0f, 0.0f);
322  transport.Reset();
323  jump.Reset();
324  }
325 
326  uint32 GetMovementFlags() const { return flags; }
327  void SetMovementFlags(uint32 flag) { flags = flag; }
328  void AddMovementFlag(uint32 flag) { flags |= flag; }
329  void RemoveMovementFlag(uint32 flag) { flags &= ~flag; }
330  bool HasMovementFlag(uint32 flag) const { return (flags & flag) != 0; }
331 
332  uint16 GetExtraMovementFlags() const { return flags2; }
333  void SetExtraMovementFlags(uint16 flag) { flags2 = flag; }
334  void AddExtraMovementFlag(uint16 flag) { flags2 |= flag; }
335  void RemoveExtraMovementFlag(uint16 flag) { flags2 &= ~flag; }
336  bool HasExtraMovementFlag(uint16 flag) const { return (flags2 & flag) != 0; }
337 
338  uint32 GetFallTime() const { return jump.fallTime; }
339  void SetFallTime(uint32 fallTime) { jump.fallTime = fallTime; }
340 
342  {
343  transport.Reset();
344  }
345 
346  void ResetJump()
347  {
348  jump.Reset();
349  }
350 
351  void OutDebug();
352 };
353 
354 template<class T>
356 {
357  public:
358  virtual ~GridObject() { }
359 
360  bool IsInGrid() const { return _gridRef.isValid(); }
361  void AddToGrid(GridRefManager<T>& m) { ASSERT(!IsInGrid()); _gridRef.link(&m, (T*)this); }
363  private:
365 };
366 
367 template <class T_VALUES, class T_FLAGS, class FLAG_TYPE, uint8 ARRAY_SIZE>
369 {
370  public:
372  {
373  memset(&m_values, 0x00, sizeof(T_VALUES) * ARRAY_SIZE);
374  m_flags = 0;
375  }
376 
377  T_FLAGS GetFlags() const { return m_flags; }
378  bool HasFlag(FLAG_TYPE flag) const { return m_flags & (1 << flag); }
379  void AddFlag(FLAG_TYPE flag) { m_flags |= (1 << flag); }
380  void DelFlag(FLAG_TYPE flag) { m_flags &= ~(1 << flag); }
381 
382  T_VALUES GetValue(FLAG_TYPE flag) const { return m_values[flag]; }
383  void SetValue(FLAG_TYPE flag, T_VALUES value) { m_values[flag] = value; }
384  void AddValue(FLAG_TYPE flag, T_VALUES value) { m_values[flag] += value; }
385 
386  private:
387  T_VALUES m_values[ARRAY_SIZE];
388  T_FLAGS m_flags;
389 };
390 
392 {
393  MAP_OBJECT_CELL_MOVE_NONE, //not in move list
395  MAP_OBJECT_CELL_MOVE_INACTIVE, //in move list but should not move
396 };
397 
399 {
400  friend class Map; //map for moving creatures
401  friend class ObjectGridLoader; //grid loader for loading creatures
402 
403  protected:
405  {
406  _newPosition.Relocate(0.0f, 0.0f, 0.0f, 0.0f);
407  }
408 
409  private:
411  Cell const& GetCurrentCell() const { return _currentCell; }
412  void SetCurrentCell(Cell const& cell) { _currentCell = cell; }
413 
416  void SetNewCellPosition(float x, float y, float z, float o)
417  {
418  _moveState = MAP_OBJECT_CELL_MOVE_ACTIVE;
419  _newPosition.Relocate(x, y, z, o);
420  }
421 };
422 
424 {
425  protected:
426  explicit WorldObject(bool isWorldObject); //note: here it means if it is in grid object list or world object list
427  public:
428  virtual ~WorldObject();
429 
430  virtual void Update (uint32 /*time_diff*/) { }
431 
432  virtual void RemoveFromWorld() override;
433 
434  void GetNearPoint2D(float &x, float &y, float distance, float absAngle) const;
435  void GetNearPoint(WorldObject const* searcher, float &x, float &y, float &z, float searcher_size, float distance2d, float absAngle) const;
436  void GetClosePoint(float &x, float &y, float &z, float size, float distance2d = 0, float angle = 0) const;
437  void MovePosition(Position &pos, float dist, float angle);
438  Position GetNearPosition(float dist, float angle);
439  void MovePositionToFirstCollision(Position &pos, float dist, float angle);
440  Position GetFirstCollisionPosition(float dist, float angle);
441  Position GetRandomNearPosition(float radius);
442  void GetContactPoint(WorldObject const* obj, float &x, float &y, float &z, float distance2d = CONTACT_DISTANCE) const;
443 
444  float GetObjectSize() const;
445  void UpdateGroundPositionZ(float x, float y, float &z) const;
446  void UpdateAllowedPositionZ(float x, float y, float &z) const;
447 
448  void GetRandomPoint(Position const &srcPos, float distance, float &rand_x, float &rand_y, float &rand_z) const;
449  Position GetRandomPoint(Position const &srcPos, float distance) const;
450 
451  uint32 GetInstanceId() const { return m_InstanceId; }
452 
453  virtual void SetPhaseMask(uint32 newPhaseMask, bool update);
454  virtual bool SetInPhase(uint32 id, bool update, bool apply);
455  void CopyPhaseFrom(WorldObject* obj, bool update = false);
456  void UpdateAreaPhase();
457  void ClearPhases(bool update = false);
458  void RebuildTerrainSwaps();
459  void RebuildWorldMapAreaSwaps();
460  bool HasInPhaseList(uint32 phase);
461  uint32 GetPhaseMask() const { return m_phaseMask; }
462  bool IsInPhase(uint32 phase) const { return _phases.find(phase) != _phases.end(); }
463  bool IsInPhase(WorldObject const* obj) const;
464  bool IsInTerrainSwap(uint32 terrainSwap) const { return _terrainSwaps.find(terrainSwap) != _terrainSwaps.end(); }
465  std::set<uint32> const& GetPhases() const { return _phases; }
466  std::set<uint32> const& GetTerrainSwaps() const { return _terrainSwaps; }
467  std::set<uint32> const& GetWorldMapAreaSwaps() const { return _worldMapAreaSwaps; }
468  int32 GetDBPhase() const { return _dbPhase; }
469 
470  // if negative it is used as PhaseGroupId
471  void SetDBPhase(int32 p) { _dbPhase = p; }
472 
473  uint32 GetZoneId() const;
474  uint32 GetAreaId() const;
475  void GetZoneAndAreaId(uint32& zoneid, uint32& areaid) const;
476 
477  InstanceScript* GetInstanceScript();
478 
479  std::string const& GetName() const { return m_name; }
480  void SetName(std::string const& newname) { m_name=newname; }
481 
482  virtual std::string const& GetNameForLocaleIdx(LocaleConstant /*locale_idx*/) const { return m_name; }
483 
484  float GetDistance(WorldObject const* obj) const;
485  float GetDistance(Position const &pos) const;
486  float GetDistance(float x, float y, float z) const;
487  float GetDistance2d(WorldObject const* obj) const;
488  float GetDistance2d(float x, float y) const;
489  float GetDistanceZ(WorldObject const* obj) const;
490 
491  bool IsSelfOrInSameMap(WorldObject const* obj) const;
492  bool IsInMap(WorldObject const* obj) const;
493  bool IsWithinDist3d(float x, float y, float z, float dist) const;
494  bool IsWithinDist3d(Position const* pos, float dist) const;
495  bool IsWithinDist2d(float x, float y, float dist) const;
496  bool IsWithinDist2d(Position const* pos, float dist) const;
497  // use only if you will sure about placing both object at same map
498  bool IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D = true) const;
499  bool IsWithinDistInMap(WorldObject const* obj, float dist2compare, bool is3D = true) const;
500  bool IsWithinLOS(float x, float y, float z) const;
501  bool IsWithinLOSInMap(WorldObject const* obj) const;
502  bool GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2, bool is3D = true) const;
503  bool IsInRange(WorldObject const* obj, float minRange, float maxRange, bool is3D = true) const;
504  bool IsInRange2d(float x, float y, float minRange, float maxRange) const;
505  bool IsInRange3d(float x, float y, float z, float minRange, float maxRange) const;
506  bool isInFront(WorldObject const* target, float arc = float(M_PI)) const;
507  bool isInBack(WorldObject const* target, float arc = float(M_PI)) const;
508 
509  bool IsInBetween(WorldObject const* obj1, WorldObject const* obj2, float size = 0) const;
510 
511  virtual void CleanupsBeforeDelete(bool finalCleanup = true); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units
512 
513  virtual void SendMessageToSet(WorldPacket const* data, bool self);
514  virtual void SendMessageToSetInRange(WorldPacket const* data, float dist, bool self);
515  virtual void SendMessageToSet(WorldPacket const* data, Player const* skipped_rcvr);
516 
517  virtual uint8 getLevelForTarget(WorldObject const* /*target*/) const { return 1; }
518 
519  void PlayDistanceSound(uint32 sound_id, Player* target = NULL);
520  void PlayDirectSound(uint32 sound_id, Player* target = NULL);
521 
522  void SendObjectDeSpawnAnim(ObjectGuid guid);
523 
524  virtual void SaveRespawnTime() { }
525  void AddObjectToRemoveList();
526 
527  float GetGridActivationRange() const;
528  float GetVisibilityRange() const;
529  float GetSightRange(WorldObject const* target = NULL) const;
530  bool CanSeeOrDetect(WorldObject const* obj, bool ignoreStealth = false, bool distanceCheck = false, bool checkAlert = false) const;
531 
534 
537 
540 
541  virtual void SetMap(Map* map);
542  virtual void ResetMap();
543  Map* GetMap() const { ASSERT(m_currMap); return m_currMap; }
544  Map* FindMap() const { return m_currMap; }
545  //used to check all object's GetMap() calls when object is not in world!
546 
547  //this function should be removed in nearest time...
548  Map const* GetBaseMap() const;
549 
550  void SetZoneScript();
551  ZoneScript* GetZoneScript() const { return m_zoneScript; }
552 
553  TempSummon* SummonCreature(uint32 id, Position const &pos, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, uint32 vehId = 0) const;
554  TempSummon* SummonCreature(uint32 id, float x, float y, float z, float ang = 0, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0) const;
555  GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime /* s */);
556  Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL);
557  void SummonCreatureGroup(uint8 group, std::list<TempSummon*>* list = NULL);
558 
559  Creature* FindNearestCreature(uint32 entry, float range, bool alive = true) const;
560  GameObject* FindNearestGameObject(uint32 entry, float range) const;
561  GameObject* FindNearestGameObjectOfType(GameobjectTypes type, float range) const;
562 
563  void GetGameObjectListWithEntryInGrid(std::list<GameObject*>& lList, uint32 uiEntry, float fMaxSearchRange) const;
564  void GetCreatureListWithEntryInGrid(std::list<Creature*>& lList, uint32 uiEntry, float fMaxSearchRange) const;
565  void GetPlayerListInGrid(std::list<Player*>& lList, float fMaxSearchRange) const;
566 
567  void DestroyForNearbyPlayers();
568  virtual void UpdateObjectVisibility(bool forced = true);
569  void BuildUpdate(UpdateDataMapType&) override;
570  void AddToObjectUpdate() override;
571  void RemoveFromObjectUpdate() override;
572 
573  //relocation and visibility system functions
574  void AddToNotify(uint16 f) { m_notifyflags |= f;}
575  bool isNeedNotify(uint16 f) const { return (m_notifyflags & f) != 0; }
576  uint16 GetNotifyFlags() const { return m_notifyflags; }
577  bool NotifyExecuted(uint16 f) const { return (m_executed_notifies & f) != 0; }
578  void SetNotified(uint16 f) { m_executed_notifies |= f;}
579  void ResetAllNotifies() { m_notifyflags = 0; m_executed_notifies = 0; }
580 
581  bool isActiveObject() const { return m_isActive; }
582  void setActive(bool isActiveObject);
583  void SetWorldObject(bool apply);
584  bool IsPermanentWorldObject() const { return m_isWorldObject; }
585  bool IsWorldObject() const;
586 
587  template<class NOTIFIER> void VisitNearbyObject(float const& radius, NOTIFIER& notifier) const { if (IsInWorld()) GetMap()->VisitAll(GetPositionX(), GetPositionY(), radius, notifier); }
588  template<class NOTIFIER> void VisitNearbyGridObject(float const& radius, NOTIFIER& notifier) const { if (IsInWorld()) GetMap()->VisitGrid(GetPositionX(), GetPositionY(), radius, notifier); }
589  template<class NOTIFIER> void VisitNearbyWorldObject(float const& radius, NOTIFIER& notifier) const { if (IsInWorld()) GetMap()->VisitWorld(GetPositionX(), GetPositionY(), radius, notifier); }
590 
591 #ifdef MAP_BASED_RAND_GEN
592  int32 irand(int32 min, int32 max) const { return int32 (GetMap()->mtRand.randInt(max - min)) + min; }
593  uint32 urand(uint32 min, uint32 max) const { return GetMap()->mtRand.randInt(max - min) + min;}
594  int32 rand32() const { return GetMap()->mtRand.randInt();}
595  double rand_norm() const { return GetMap()->mtRand.randExc();}
596  double rand_chance() const { return GetMap()->mtRand.randExc(100.0);}
597 #endif
598 
600 
601  // Transports
602  Transport* GetTransport() const { return m_transport; }
603  float GetTransOffsetX() const { return m_movementInfo.transport.pos.GetPositionX(); }
604  float GetTransOffsetY() const { return m_movementInfo.transport.pos.GetPositionY(); }
605  float GetTransOffsetZ() const { return m_movementInfo.transport.pos.GetPositionZ(); }
606  float GetTransOffsetO() const { return m_movementInfo.transport.pos.GetOrientation(); }
607  uint32 GetTransTime() const { return m_movementInfo.transport.time; }
608  int8 GetTransSeat() const { return m_movementInfo.transport.seat; }
609  virtual ObjectGuid GetTransGUID() const;
610  void SetTransport(Transport* t) { m_transport = t; }
611 
613 
614  virtual float GetStationaryX() const { return GetPositionX(); }
615  virtual float GetStationaryY() const { return GetPositionY(); }
616  virtual float GetStationaryZ() const { return GetPositionZ(); }
617  virtual float GetStationaryO() const { return GetOrientation(); }
618 
619  virtual uint16 GetAIAnimKitId() const { return 0; }
620  virtual uint16 GetMovementAnimKitId() const { return 0; }
621  virtual uint16 GetMeleeAnimKitId() const { return 0; }
622 
623  protected:
624  std::string m_name;
626  const bool m_isWorldObject;
628 
629  // transports
631 
632  //these functions are used mostly for Relocate() and Corpse/Player specific stuff...
633  //use them ONLY in LoadFromDB()/Create() funcs and nowhere else!
634  //mapId/instanceId should be set in SetMap() function!
635  void SetLocationMapId(uint32 _mapId) { m_mapId = _mapId; }
636  void SetLocationInstanceId(uint32 _instanceId) { m_InstanceId = _instanceId; }
637 
638  virtual bool IsNeverVisible() const { return !IsInWorld(); }
639  virtual bool IsAlwaysVisibleFor(WorldObject const* /*seer*/) const { return false; }
640  virtual bool IsInvisibleDueToDespawn() const { return false; }
641  //difference from IsAlwaysVisibleFor: 1. after distance check; 2. use owner or charmer as seer
642  virtual bool IsAlwaysDetectableFor(WorldObject const* /*seer*/) const { return false; }
643  private:
644  Map* m_currMap; //current object's Map location
645 
646  //uint32 m_mapId; // object at map with map_id
647  uint32 m_InstanceId; // in map copy with instance id
648  uint32 m_phaseMask; // in area phase state
649  std::set<uint32> _phases;
650  std::set<uint32> _terrainSwaps;
651  std::set<uint32> _worldMapAreaSwaps;
653 
656  virtual bool _IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D) const;
657 
658  bool CanNeverSee(WorldObject const* obj) const;
659  virtual bool CanAlwaysSee(WorldObject const* /*obj*/) const { return false; }
660  bool CanDetect(WorldObject const* obj, bool ignoreStealth, bool checkAlert = false) const;
661  bool CanDetectInvisibilityOf(WorldObject const* obj) const;
662  bool CanDetectStealthOf(WorldObject const* obj, bool checkAlert = false) const;
663 };
664 
665 namespace Trinity
666 {
667  // Binary predicate to sort WorldObjects based on the distance to a reference WorldObject
669  {
670  public:
671  ObjectDistanceOrderPred(WorldObject const* refObj, bool ascending = true) : _refObj(refObj), _ascending(ascending) { }
672 
673  bool operator()(WorldObject const* left, WorldObject const* right) const
674  {
675  return _refObj->GetDistanceOrder(left, right) == _ascending;
676  }
677 
678  private:
681  };
682 }
683 
684 #endif
Definition: Object.h:95
Definition: Object.h:74
std::set< uint32 > _worldMapAreaSwaps
Definition: Object.h:651
FlaggedValuesArray32()
Definition: Object.h:371
bool HasMovementFlag(uint32 flag) const
Definition: Object.h:330
Definition: Corpse.h:49
Position _newPosition
Definition: Object.h:415
const bool m_isWorldObject
Definition: Object.h:626
float GetTransOffsetZ() const
Definition: Object.h:605
void RemoveFromGrid()
Definition: Object.h:362
T_FLAGS GetFlags() const
Definition: Object.h:377
bool m_objectUpdated
Definition: Object.h:254
void ResetAllNotifies()
Definition: Object.h:579
virtual bool IsNeverVisible() const
Definition: Object.h:638
Definition: UpdateMask.h:26
Definition: Position.h:228
Map * m_currMap
Definition: Object.h:644
Definition: Object.h:61
Definition: ByteBuffer.h:70
int8_t int8
Definition: Define.h:148
Definition: TemporarySummon.h:40
UpdateMask _changesMask
Definition: Object.h:241
bool m_inWorld
Definition: Object.h:257
uint32 fallTime
Definition: Object.h:309
bool GetDistanceOrder(WorldObject const *obj1, WorldObject const *obj2, bool is3D=true) const
Definition: Object.cpp:1680
uint32 * m_uint32Values
Definition: Object.h:235
virtual float GetStationaryX() const
Definition: Object.h:614
int32 * m_int32Values
Definition: Object.h:234
Definition: Object.h:368
Map * GetMap() const
Definition: Object.h:543
void unlink()
Definition: Reference.h:61
Definition: ObjectGuid.h:36
#define M_PI
Definition: Common.h:163
virtual void BuildUpdate(UpdateDataMapType &)
Definition: Object.h:182
void RemoveMovementFlag(uint32 flag)
Definition: Object.h:329
void AddToNotify(uint16 f)
Definition: Object.h:574
MovementInfo m_movementInfo
Definition: Object.h:612
void RemoveFieldNotifyFlag(uint16 flag)
Definition: Object.h:186
uint16 _dynamicValuesCount
Definition: Object.h:246
Position const MovePosition
Definition: zone_dustwallow_marsh.cpp:201
std::set< uint32 > _phases
Definition: Object.h:649
std::string m_name
Definition: Object.h:624
void VisitNearbyWorldObject(float const &radius, NOTIFIER &notifier) const
Definition: Object.h:589
float cosAngle
Definition: Object.h:311
bool isType(uint16 mask) const
Definition: Object.h:114
std::string const & GetName() const
Definition: Object.h:479
FlaggedValuesArray32< int32, uint32, ServerSideVisibilityType, TOTAL_SERVERSIDE_VISIBILITY_TYPES > m_serverSideVisibility
Definition: Object.h:538
Definition: Object.h:355
virtual void Update(uint32)
Definition: Object.h:430
void SetDBPhase(int32 p)
Definition: Object.h:471
void SetValue(FLAG_TYPE flag, T_VALUES value)
Definition: Object.h:383
std::set< uint32 > const & GetTerrainSwaps() const
Definition: Object.h:466
Definition: ObjectGuid.h:32
struct MovementInfo::JumpInfo jump
arena_t NULL
Definition: jemalloc_internal.h:624
Creature const * ToCreature() const
Definition: Object.h:195
TC_GAME_API void GetCreatureListWithEntryInGrid(std::list< Creature * > &list, WorldObject *source, uint32 entry, float maxSearchRange)
Definition: ScriptedCreature.cpp:621
Definition: Object.h:668
Definition: Transport.h:28
uint16 GetNotifyFlags() const
Definition: Object.h:576
void SetTransport(Transport *t)
Definition: Object.h:610
FlaggedValuesArray32< int32, uint32, InvisibilityType, TOTAL_INVISIBILITY_TYPES > m_invisibilityDetect
Definition: Object.h:536
float GetTransOffsetY() const
Definition: Object.h:604
bool isNeedNotify(uint16 f) const
Definition: Object.h:575
Definition: Object.h:58
Definition: Object.h:423
Definition: Creature.h:467
void SetLocationMapId(uint32 _mapId)
Definition: Object.h:635
void SetFallTime(uint32 fallTime)
Definition: Object.h:339
Definition: Object.h:67
Definition: Object.h:301
Position pos
Definition: Object.h:273
FlaggedValuesArray32< int32, uint32, StealthType, TOTAL_STEALTH_TYPES > m_stealthDetect
Definition: Object.h:533
Definition: Object.h:393
UpdateMask _dynamicChangesMask
Definition: Object.h:242
MovementInfo()
Definition: Object.h:318
void SetEntry(uint32 entry)
Definition: Object.h:108
DynamicObject * ToDynObject()
Definition: Object.h:206
Definition: Object.h:60
Cell const & GetCurrentCell() const
Definition: Object.h:411
GridReference< T > _gridRef
Definition: Object.h:364
uint32 prevTime
Definition: Object.h:293
virtual float GetStationaryZ() const
Definition: Object.h:616
void SetName(std::string const &newname)
Definition: Object.h:480
TC_GAME_API void GetPlayerListInGrid(std::list< Player * > &list, WorldObject *source, float maxSearchRange)
Definition: ScriptedCreature.cpp:631
TempSummonType
Definition: Object.h:52
void apply(T *val)
Definition: ByteConverter.h:41
uint16 m_objectType
Definition: Object.h:227
uint16_t uint16
Definition: g3dmath.h:166
GameObject * ToGameObject()
Definition: Object.h:200
bool IsInGrid() const
Definition: Object.h:360
Definition: UpdateData.h:59
double distance(double x, double y)
Definition: g3dmath.h:731
struct MovementInfo::TransportInfo transport
GameobjectTypes
Definition: SharedDefines.h:2063
double rand_chance()
Definition: Random.cpp:74
T max(const T &x, const T &y)
Definition: g3dmath.h:320
void VisitNearbyGridObject(float const &radius, NOTIFIER &notifier) const
Definition: Object.h:588
uint32 m_InstanceId
Definition: Object.h:647
Definition: ObjectGridLoader.h:30
void VisitNearbyObject(float const &radius, NOTIFIER &notifier) const
Definition: Object.h:587
Player * ToPlayer()
Definition: Object.h:191
uint32 GetTransTime() const
Definition: Object.h:607
Definition: UpdateFields.h:31
uint32 time
Definition: Object.h:274
uint16 m_notifyflags
Definition: Object.h:654
void SetExtraMovementFlags(uint16 flag)
Definition: Object.h:333
MapObjectCellMoveState _moveState
Definition: Object.h:414
Definition: ObjectGuid.h:49
virtual uint8 getLevelForTarget(WorldObject const *) const
Definition: Object.h:517
virtual bool IsInvisibleDueToDespawn() const
Definition: Object.h:640
int32 irand(int32 min, int32 max)
Definition: Random.cpp:39
int32 _dbPhase
Definition: Object.h:652
Definition: DynamicObject.h:35
Cell _currentCell
Definition: Object.h:410
virtual void RemoveFromObjectUpdate()=0
TypeID GetTypeId() const
Definition: Object.h:113
Definition: Object.h:277
Definition: Object.h:267
Definition: UpdateFields.h:29
float zspeed
Definition: Object.h:311
T min(const T &x, const T &y)
Definition: g3dmath.h:305
virtual void SaveRespawnTime()
Definition: Object.h:524
float GetOrientation() const
Definition: Position.h:107
std::unordered_map< Player *, UpdateData > UpdateDataMapType
Definition: Object.h:91
void Relocate(float x, float y)
Definition: Position.h:67
virtual bool IsAlwaysVisibleFor(WorldObject const *) const
Definition: Object.h:639
TypeID m_objectTypeId
Definition: Object.h:229
void SetCurrentCell(Cell const &cell)
Definition: Object.h:412
PackedGuid m_PackGUID
Definition: Object.h:259
Definition: ZoneScript.h:26
std::set< uint32 > _terrainSwaps
Definition: Object.h:650
Definition: ObjectGuid.h:37
float GetTransOffsetX() const
Definition: Object.h:603
MapObjectCellMoveState
Definition: Object.h:391
void SetMovementFlags(uint32 flag)
Definition: Object.h:327
virtual uint16 GetAIAnimKitId() const
Definition: Object.h:619
ZoneScript * m_zoneScript
Definition: Object.h:627
uint32 GetPhaseMask() const
Definition: Object.h:461
Corpse const * ToCorpse() const
Definition: Object.h:204
LocaleConstant
Definition: Common.h:115
Map * FindMap() const
Definition: Object.h:544
UpdateMask * _dynamicChangesArrayMask
Definition: Object.h:243
bool IsInTerrainSwap(uint32 terrainSwap) const
Definition: Object.h:464
float GetPositionY() const
Definition: Position.h:105
Definition: Object.h:66
Definition: Object.h:56
G3D::int16 z
Definition: Vector3int16.h:46
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
PhaseMasks
Definition: Object.h:64
Corpse * ToCorpse()
Definition: Object.h:203
uint32 vehicleId
Definition: Object.h:294
virtual float GetStationaryY() const
Definition: Object.h:615
Definition: Object.h:398
std::set< uint32 > const & GetWorldMapAreaSwaps() const
Definition: Object.h:467
bool m_isActive
Definition: Object.h:625
MapObject()
Definition: Object.h:404
FlaggedValuesArray32< int32, uint32, ServerSideVisibilityType, TOTAL_SERVERSIDE_VISIBILITY_TYPES > m_serverSideVisibilityDetect
Definition: Object.h:539
Player const * ToPlayer() const
Definition: Object.h:192
int8 seat
Definition: Object.h:291
Definition: ObjectGuid.h:34
uint32 GetInstanceId() const
Definition: Object.h:451
uint32 flags
Definition: Object.h:271
Vector2int16 & operator=(const Any &a)
float GetPositionZ() const
Definition: Position.h:106
int32_t int32
Definition: Define.h:146
bool isActiveObject() const
Definition: Object.h:581
Definition: CreatureAI.h:68
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
Transport * m_transport
Definition: Object.h:630
float pitch
Definition: Object.h:298
G3D::int16 y
Definition: Vector2int16.h:38
uint16 flags2
Definition: Object.h:272
uint16_t uint16
Definition: Define.h:151
PackedGuid const & GetPackGUID() const
Definition: Object.h:106
virtual bool CanAlwaysSee(WorldObject const *) const
Definition: Object.h:659
Definition: GameObject.h:880
void SetFieldNotifyFlag(uint16 flag)
Definition: Object.h:185
Definition: Object.h:75
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
bool IsInPhase(uint32 phase) const
Definition: Object.h:462
void AddValue(FLAG_TYPE flag, T_VALUES value)
Definition: Object.h:384
virtual void RemoveFromWorld()
Definition: Object.cpp:156
void ResetJump()
Definition: Object.h:346
void ResetTransport()
Definition: Object.h:341
Definition: Map.h:259
float splineElevation
Definition: Object.h:316
float sinAngle
Definition: Object.h:311
Definition: Object.h:55
bool operator()(WorldObject const *left, WorldObject const *right) const
Definition: Object.h:673
Definition: Object.h:394
void link(TO *toObj, FROM *fromObj)
Definition: Reference.h:46
TypeID
Definition: ObjectGuid.h:27
void AddFlag(FLAG_TYPE flag)
Definition: Object.h:379
void Reset()
Definition: Object.h:279
void RemoveExtraMovementFlag(uint16 flag)
Definition: Object.h:335
void Clear()
Definition: ObjectGuid.h:215
ObjectGuid guid
Definition: Object.h:270
Definition: Cell.h:49
Position pos
Definition: Object.h:290
int8 GetTransSeat() const
Definition: Object.h:608
void DelFlag(FLAG_TYPE flag)
Definition: Object.h:380
void SetLocationInstanceId(uint32 _instanceId)
Definition: Object.h:636
ObjectGuid const & GetGUID() const
Definition: Object.h:105
std::set< uint32 > const & GetPhases() const
Definition: Object.h:465
uint16 GetValuesCount() const
Definition: Object.h:178
ObjectDistanceOrderPred(WorldObject const *refObj, bool ascending=true)
Definition: Object.h:671
Transport * GetTransport() const
Definition: Object.h:602
int32 GetDBPhase() const
Definition: Object.h:468
GameObject const * ToGameObject() const
Definition: Object.h:201
std::vector< uint32 > * _dynamicValues
Definition: Object.h:239
Definition: ObjectGuid.h:33
bool _ascending
Definition: Object.h:680
void AddExtraMovementFlag(uint16 flag)
Definition: Object.h:334
void AddToGrid(GridRefManager< T > &m)
Definition: Object.h:361
bool NotifyExecuted(uint16 f) const
Definition: Object.h:577
double rand_norm()
Definition: Random.cpp:69
void OutDebug()
Definition: Object.cpp:1410
void SetNewCellPosition(float x, float y, float z, float o)
Definition: Object.h:416
Definition: Object.h:395
Creature * ToCreature()
Definition: Object.h:194
virtual void SetObjectScale(float scale)
Definition: Object.h:111
ZoneScript * GetZoneScript() const
Definition: Object.h:551
float GetTransOffsetO() const
Definition: Object.h:606
#define TC_GAME_API
Definition: Define.h:134
float * m_floatValues
Definition: Object.h:236
Definition: Object.h:73
Definition: Object.h:59
void AddMovementFlag(uint32 flag)
Definition: Object.h:328
virtual std::string const & GetNameForLocaleIdx(LocaleConstant) const
Definition: Object.h:482
int32_t int32
Definition: g3dmath.h:167
uint32 m_phaseMask
Definition: Object.h:648
uint16 m_valuesCount
Definition: Object.h:245
uint32 rand32()
Definition: Random.cpp:64
uint32 GetFallTime() const
Definition: Object.h:338
Definition: InstanceScript.h:141
WorldObject const * _refObj
Definition: Object.h:679
FlaggedValuesArray32< int32, uint32, StealthType, TOTAL_STEALTH_TYPES > m_stealth
Definition: Object.h:532
uint8_t uint8
Definition: Define.h:152
bool HasExtraMovementFlag(uint16 flag) const
Definition: Object.h:336
Definition: Position.h:27
#define ASSERT
Definition: Errors.h:55
Definition: UpdateFields.h:26
FlaggedValuesArray32< int32, uint32, InvisibilityType, TOTAL_INVISIBILITY_TYPES > m_invisibility
Definition: Object.h:535
ObjectGuid guid
Definition: Object.h:289
void Reset()
Definition: Object.h:303
T_VALUES GetValue(FLAG_TYPE flag) const
Definition: Object.h:382
bool isValid() const
Definition: Reference.h:78
const FieldDescriptor value
Definition: descriptor.h:1522
uint32 GetEntry() const
Definition: Object.h:107
virtual float GetStationaryO() const
Definition: Object.h:617
int16_t int16
Definition: Define.h:147
Definition: ObjectGuid.h:189
uint16 GetExtraMovementFlags() const
Definition: Object.h:332
uint8 flags
Definition: DisableMgr.cpp:44
Definition: Common.h:172
uint32 time
Definition: Object.h:292
virtual uint16 GetMovementAnimKitId() const
Definition: Object.h:620
#define const
Definition: zconf.h:217
#define CONTACT_DISTANCE
Definition: Object.h:33
G3D::int16 x
Definition: Vector2int16.h:37
bool IsInWorld() const
Definition: Object.h:100
Definition: Object.h:72
uint32 GetMovementFlags() const
Definition: Object.h:326
Definition: ObjectGuid.h:35
virtual uint16 GetMeleeAnimKitId() const
Definition: Object.h:621
virtual bool IsAlwaysDetectableFor(WorldObject const *) const
Definition: Object.h:642
float GetPositionX() const
Definition: Position.h:104
Unit const * ToUnit() const
Definition: Object.h:198
virtual void AddToObjectUpdate()=0
Definition: ObjectGuid.h:341
T_VALUES m_values[ARRAY_SIZE]
Definition: Object.h:387
virtual bool hasQuest(uint32) const
Definition: Object.h:180
T_FLAGS m_flags
Definition: Object.h:388
Definition: Unit.h:1305
AreaTrigger * ToAreaTrigger()
Definition: Object.h:209
virtual ~GridObject()
Definition: Object.h:358
TC_GAME_API void GetGameObjectListWithEntryInGrid(std::list< GameObject * > &list, WorldObject *source, uint32 entry, float maxSearchRange)
Definition: ScriptedCreature.cpp:626
AreaTrigger const * ToAreaTrigger() const
Definition: Object.h:210
uint16 m_executed_notifies
Definition: Object.h:655
Definition: WorldPacket.h:26
void SetNotified(uint16 f)
Definition: Object.h:578
DynamicObject const * ToDynObject() const
Definition: Object.h:207
virtual bool hasInvolvedQuest(uint32) const
Definition: Object.h:181
Unit * ToUnit()
Definition: Object.h:197
float GetObjectScale() const
Definition: Object.h:110
bool HasFlag(FLAG_TYPE flag) const
Definition: Object.h:378
float xyspeed
Definition: Object.h:311
bool IsPermanentWorldObject() const
Definition: Object.h:584
uint32 LastUsedScriptID
Definition: Object.h:599
Definition: AreaTrigger.h:26
uint32 m_updateFlag
Definition: Object.h:230
NotifyFlags
Definition: Object.h:70
uint16 _fieldNotifyFlags
Definition: Object.h:248
Definition: Object.h:54