diff options
author | Treeston <treeston.mmoc@gmail.com> | 2017-11-30 20:45:44 +0100 |
---|---|---|
committer | Treeston <treeston.mmoc@gmail.com> | 2017-11-30 20:55:53 +0100 |
commit | 76a4c7d9748fdbfa925e81a3257acdee53d4f86e (patch) | |
tree | 24646e144b8dcc10b844ff21003dfaff08072851 | |
parent | 032194099e84bf0d47b121d82170c39fe73e0c87 (diff) |
Some misc streamlining/cleanup:
- std::chrono overloads for SummonCreature
- Removed misleading const qualifier from SummonCreature (it wasn't being honored)
- Rename parameters of SummonCreature to follow convention
- EventProcessor has a new method (AddEventAtOffset) that adds an event...at an offset. Genius.
PS: Hi there Keader.
-rw-r--r-- | src/common/Utilities/EventProcessor.cpp | 21 | ||||
-rw-r--r-- | src/common/Utilities/EventProcessor.h | 8 | ||||
-rw-r--r-- | src/server/game/Entities/GameObject/GameObject.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 18 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.h | 6 |
5 files changed, 25 insertions, 30 deletions
diff --git a/src/common/Utilities/EventProcessor.cpp b/src/common/Utilities/EventProcessor.cpp index 0149f222da8..eda5c5ed5ac 100644 --- a/src/common/Utilities/EventProcessor.cpp +++ b/src/common/Utilities/EventProcessor.cpp @@ -111,29 +111,24 @@ void EventProcessor::KillAllEvents(bool force) m_events.clear(); } -void EventProcessor::AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime) +void EventProcessor::AddEvent(BasicEvent* event, uint64 e_time, bool set_addtime) { if (set_addtime) - Event->m_addTime = m_time; - Event->m_execTime = e_time; - m_events.insert(std::pair<uint64, BasicEvent*>(e_time, Event)); + event->m_addTime = m_time; + event->m_execTime = e_time; + m_events.insert(std::pair<uint64, BasicEvent*>(e_time, event)); } -void EventProcessor::ModifyEventTime(BasicEvent* Event, uint64 newTime) +void EventProcessor::ModifyEventTime(BasicEvent* event, uint64 newTime) { for (auto itr = m_events.begin(); itr != m_events.end(); ++itr) { - if (itr->second != Event) + if (itr->second != event) continue; - Event->m_execTime = newTime; + event->m_execTime = newTime; m_events.erase(itr); - m_events.insert(std::pair<uint64, BasicEvent*>(newTime, Event)); + m_events.insert(std::pair<uint64, BasicEvent*>(newTime, event)); break; } } - -uint64 EventProcessor::CalculateTime(uint64 t_offset) const -{ - return(m_time + t_offset); -} diff --git a/src/common/Utilities/EventProcessor.h b/src/common/Utilities/EventProcessor.h index 9a356b0e3f5..488d4a98649 100644 --- a/src/common/Utilities/EventProcessor.h +++ b/src/common/Utilities/EventProcessor.h @@ -20,6 +20,7 @@ #define __EVENTPROCESSOR_H #include "Define.h" +#include "Duration.h" #include <map> class EventProcessor; @@ -76,9 +77,10 @@ class TC_COMMON_API EventProcessor void Update(uint32 p_time); void KillAllEvents(bool force); - void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true); - void ModifyEventTime(BasicEvent* Event, uint64 newTime); - uint64 CalculateTime(uint64 t_offset) const; + void AddEvent(BasicEvent* event, uint64 e_time, bool set_addtime = true); + void AddEventAtOffset(BasicEvent* event, Milliseconds const& offset) { AddEvent(event, CalculateTime(offset.count())); } + void ModifyEventTime(BasicEvent* event, uint64 newTime); + uint64 CalculateTime(uint64 t_offset) const { return m_time + t_offset; } protected: uint64 m_time; diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index ce9658ef37e..f7e3bc965d8 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -2513,7 +2513,7 @@ public: virtual G3D::Vector3 GetPosition() const override { return G3D::Vector3(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); } virtual float GetOrientation() const override { return _owner->GetOrientation(); } virtual float GetScale() const override { return _owner->GetObjectScale(); } - virtual void DebugVisualizeCorner(G3D::Vector3 const& corner) const override { _owner->SummonCreature(1, corner.x, corner.y, corner.z, 0, TEMPSUMMON_MANUAL_DESPAWN); } + virtual void DebugVisualizeCorner(G3D::Vector3 const& corner) const override { const_cast<GameObject*>(_owner)->SummonCreature(1, corner.x, corner.y, corner.z, 0, TEMPSUMMON_MANUAL_DESPAWN); } private: GameObject const* _owner; diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 9e2546f2df7..1a94b420b4c 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -1969,13 +1969,13 @@ void WorldObject::ClearZoneScript() m_zoneScript = nullptr; } -TempSummon* WorldObject::SummonCreature(uint32 entry, Position const& pos, TempSummonType spwtype /*= TEMPSUMMON_MANUAL_DESPAWN*/, uint32 duration /*= 0*/, uint32 /*vehId = 0*/) const +TempSummon* WorldObject::SummonCreature(uint32 entry, Position const& pos, TempSummonType despawnType /*= TEMPSUMMON_MANUAL_DESPAWN*/, uint32 despawnTime /*= 0*/, uint32 /*vehId = 0*/) { if (Map* map = FindMap()) { - if (TempSummon* summon = map->SummonCreature(entry, pos, nullptr, duration, isType(TYPEMASK_UNIT) ? (Unit*)this : nullptr)) + if (TempSummon* summon = map->SummonCreature(entry, pos, nullptr, despawnTime, ToUnit())) { - summon->SetTempSummonType(spwtype); + summon->SetTempSummonType(despawnType); return summon; } } @@ -1983,17 +1983,13 @@ TempSummon* WorldObject::SummonCreature(uint32 entry, Position const& pos, TempS return nullptr; } -TempSummon* WorldObject::SummonCreature(uint32 id, float x, float y, float z, float ang /*= 0*/, TempSummonType spwtype /*= TEMPSUMMON_MANUAL_DESPAWN*/, uint32 despwtime /*= 0*/) const +TempSummon* WorldObject::SummonCreature(uint32 id, float x, float y, float z, float o /*= 0*/, TempSummonType despawnType /*= TEMPSUMMON_MANUAL_DESPAWN*/, uint32 despawnTime /*= 0*/) { if (!x && !y && !z) - { GetClosePoint(x, y, z, GetCombatReach()); - ang = GetOrientation(); - } - - Position pos; - pos.Relocate(x, y, z, ang); - return SummonCreature(id, pos, spwtype, despwtime, 0); + if (!o) + o = GetOrientation(); + return SummonCreature(id, { x,y,z,o }, despawnType, despawnTime); } GameObject* WorldObject::SummonGameObject(uint32 entry, Position const& pos, QuaternionData const& rot, uint32 respawnTime) diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index b6cee547126..b3e2c445963 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -20,6 +20,7 @@ #define _OBJECT_H #include "Common.h" +#include "Duration.h" #include "GridReference.h" #include "GridRefManager.h" #include "ModelIgnoreFlags.h" @@ -372,8 +373,9 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation void ClearZoneScript(); ZoneScript* GetZoneScript() const { return m_zoneScript; } - TempSummon* SummonCreature(uint32 id, Position const& pos, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, uint32 vehId = 0) const; - TempSummon* SummonCreature(uint32 id, float x, float y, float z, float ang = 0, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0) const; + TempSummon* SummonCreature(uint32 entry, Position const& pos, TempSummonType despawnType = TEMPSUMMON_MANUAL_DESPAWN, uint32 despawnTime = 0, uint32 vehId = 0); + TempSummon* SummonCreature(uint32 entry, Position const& pos, TempSummonType despawnType, Milliseconds const& despawnTime, uint32 vehId = 0) { SummonCreature(entry, pos, despawnType, uint32(despawnTime.count()), vehId); } + TempSummon* SummonCreature(uint32 entry, float x, float y, float z, float o = 0, TempSummonType despawnType = TEMPSUMMON_MANUAL_DESPAWN, uint32 despawnTime = 0); GameObject* SummonGameObject(uint32 entry, Position const& pos, QuaternionData const& rot, uint32 respawnTime /* s */); GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, QuaternionData const& rot, uint32 respawnTime /* s */); Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = nullptr); |