diff options
-rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp | 77 | ||||
-rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedEscortAI.h | 11 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptSystem.h | 17 |
3 files changed, 92 insertions, 13 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index 2ba37f83dd9..cdea190dfbc 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -383,12 +383,12 @@ void npc_escortAI::AddWaypoint(uint32 id, float x, float y, float z, uint32 wait void npc_escortAI::FillPointMovementListForCreature() { - std::vector<ScriptPointMove> const& movePoints = sScriptSystemMgr->GetPointMoveList(me->GetEntry()); + ScriptPointVector const& movePoints = sScriptSystemMgr->GetPointMoveList(me->GetEntry()); if (movePoints.empty()) return; - std::vector<ScriptPointMove>::const_iterator itrEnd = movePoints.end();; - for (std::vector<ScriptPointMove>::const_iterator itr = movePoints.begin(); itr != itrEnd; ++itr) + ScriptPointVector::const_iterator itrEnd = movePoints.end();; + for (ScriptPointVector::const_iterator itr = movePoints.begin(); itr != itrEnd; ++itr) { Escort_Waypoint point(itr->uiPointId, itr->fX, itr->fY, itr->fZ, itr->uiWaitTime); WaypointList.push_back(point); @@ -416,7 +416,7 @@ void npc_escortAI::SetRun(bool on) } //TODO: get rid of this many variables passed in function. -void npc_escortAI::Start(bool isActiveAttacker, bool run, uint64 playerGUID, Quest const* quest, bool instantRespawn, bool canLoopPath) +void npc_escortAI::Start(bool isActiveAttacker /* = true*/, bool run /* = false */, uint64 playerGUID /* = 0 */, Quest const* quest /* = NULL */, bool instantRespawn /* = false */, bool canLoopPath /* = false */, bool resetWaypoints /* = true */) { if (me->getVictim()) { @@ -430,7 +430,7 @@ void npc_escortAI::Start(bool isActiveAttacker, bool run, uint64 playerGUID, Que return; } - if (!ScriptWP) // sd2 never adds wp in script, but tc does + if (!ScriptWP && resetWaypoints) // sd2 never adds wp in script, but tc does { if (!WaypointList.empty()) WaypointList.clear(); @@ -490,3 +490,70 @@ void npc_escortAI::SetEscortPaused(bool on) else RemoveEscortState(STATE_ESCORT_PAUSED); } + +bool npc_escortAI::SetNextWaypoint(uint32 pointId, float x, float y, float z, float orientation) +{ + me->SetPosition(x, y, z, orientation); + return SetNextWaypoint(pointId, false, true); +} + +bool npc_escortAI::SetNextWaypoint(uint32 pointId, bool setPosition, bool resetWaypointsOnFail) +{ + if (!WaypointList.empty()) + WaypointList.clear(); + + FillPointMovementListForCreature(); + + if (WaypointList.empty()) + return false; + + size_t const size = WaypointList.size(); + Escort_Waypoint waypoint(0, 0, 0, 0, 0); + do + { + waypoint = WaypointList.front(); + WaypointList.pop_front(); + if (waypoint.id == pointId) + { + if (setPosition) + me->SetPosition(waypoint.x, waypoint.y, waypoint.z, me->GetOrientation()); + + CurrentWP = WaypointList.begin(); + return true; + } + } + while (!WaypointList.empty()); + + // we failed. + // we reset the waypoints in the start; if we pulled any, reset it again + if (resetWaypointsOnFail && size != WaypointList.size()) + { + if (!WaypointList.empty()) + WaypointList.clear(); + + FillPointMovementListForCreature(); + } + + return false; +} + +bool npc_escortAI::GetWaypointPosition(uint32 pointId, float& x, float& y, float& z) +{ + ScriptPointVector const& waypoints = sScriptSystemMgr->GetPointMoveList(me->GetEntry()); + if (waypoints.empty()) + return false; + + ScriptPointVector::const_iterator itrEnd = waypoints.end(); + for (ScriptPointVector::const_iterator itr = waypoints.begin(); itr != waypoints.end(); ++itr) + { + if (itr->uiPointId == pointId) + { + x = itr->fX; + y = itr->fY; + z = itr->fZ; + return true; + } + } + + return false; +} diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h index c7ce81ed7a4..24d15f9079b 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h @@ -62,10 +62,19 @@ struct npc_escortAI : public ScriptedAI // EscortAI functions void AddWaypoint(uint32 id, float x, float y, float z, uint32 waitTime = 0); // waitTime is in ms + //this will set the current position to x/y/z/o, and the current WP to pointId. + bool SetNextWaypoint(uint32 pointId, float x, float y, float z, float orientation); + + //this will set the current position to WP start position (if setPosition == true), + //and the current WP to pointId + bool SetNextWaypoint(uint32 pointId, bool setPosition = true, bool resetWaypointsOnFail = true); + + bool GetWaypointPosition(uint32 pointId, float& x, float& y, float& z); + virtual void WaypointReached(uint32 pointId) = 0; virtual void WaypointStart(uint32 /*pointId*/) {} - void Start(bool isActiveAttacker = true, bool run = false, uint64 playerGUID = 0, Quest const* quest = NULL, bool instantRespawn = false, bool canLoopPath = false); + void Start(bool isActiveAttacker = true, bool run = false, uint64 playerGUID = 0, Quest const* quest = NULL, bool instantRespawn = false, bool canLoopPath = false, bool resetWaypoints = true); void SetRun(bool on = true); void SetEscortPaused(bool on); diff --git a/src/server/game/Scripting/ScriptSystem.h b/src/server/game/Scripting/ScriptSystem.h index c353bcb7120..1fb84977e5d 100644 --- a/src/server/game/Scripting/ScriptSystem.h +++ b/src/server/game/Scripting/ScriptSystem.h @@ -42,6 +42,8 @@ struct ScriptPointMove uint32 uiWaitTime; }; +typedef std::vector<ScriptPointMove> ScriptPointVector; + struct StringTextData { uint32 uiSoundId; @@ -55,10 +57,11 @@ class SystemMgr friend class ACE_Singleton<SystemMgr, ACE_Null_Mutex>; SystemMgr() {} ~SystemMgr() {} + public: //Maps and lists typedef UNORDERED_MAP<int32, StringTextData> TextDataMap; - typedef UNORDERED_MAP<uint32, std::vector<ScriptPointMove> > PointMoveMap; + typedef UNORDERED_MAP<uint32, ScriptPointVector> PointMoveMap; //Database void LoadVersion(); @@ -67,9 +70,9 @@ class SystemMgr void LoadScriptWaypoints(); //Retrive from storage - StringTextData const* GetTextData(int32 uiTextId) const + StringTextData const* GetTextData(int32 textId) const { - TextDataMap::const_iterator itr = m_mTextDataMap.find(uiTextId); + TextDataMap::const_iterator itr = m_mTextDataMap.find(textId); if (itr == m_mTextDataMap.end()) return NULL; @@ -77,14 +80,14 @@ class SystemMgr return &itr->second; } - std::vector<ScriptPointMove> const &GetPointMoveList(uint32 uiCreatureEntry) const + ScriptPointVector const& GetPointMoveList(uint32 creatureEntry) const { - static std::vector<ScriptPointMove> vEmpty; + static ScriptPointVector empty; - PointMoveMap::const_iterator itr = m_mPointMoveMap.find(uiCreatureEntry); + PointMoveMap::const_iterator itr = m_mPointMoveMap.find(creatureEntry); if (itr == m_mPointMoveMap.end()) - return vEmpty; + return empty; return itr->second; } |