diff options
| author | ccrs <ccrs@users.noreply.github.com> | 2017-08-12 01:40:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-12 01:40:25 +0200 |
| commit | 7fff83d67526efff63867d41b9e036a19a9287b3 (patch) | |
| tree | 0462cb16ac0099318ab9ce07dc6cc099e141375e /src/server/game/Scripting | |
| parent | 00329fe9a505c437af0b7591d8321bf3b77ad7fb (diff) | |
Core/Movement: waypoint movement (#20121)
Following the work done in #19361 this is the cleanup and improvement of the related logic of waypoint management.
Ref 28050f3 #18020
(taking the good parts and ignoring the incomplete work)
Diffstat (limited to 'src/server/game/Scripting')
| -rw-r--r-- | src/server/game/Scripting/ScriptSystem.cpp | 56 | ||||
| -rw-r--r-- | src/server/game/Scripting/ScriptSystem.h | 46 |
2 files changed, 45 insertions, 57 deletions
diff --git a/src/server/game/Scripting/ScriptSystem.cpp b/src/server/game/Scripting/ScriptSystem.cpp index 1b4ad6b98d5..b814229151a 100644 --- a/src/server/game/Scripting/ScriptSystem.cpp +++ b/src/server/game/Scripting/ScriptSystem.cpp @@ -37,17 +37,17 @@ void SystemMgr::LoadScriptWaypoints() { uint32 oldMSTime = getMSTime(); - // Drop Existing Waypoint list - m_mPointMoveMap.clear(); + // drop Existing Waypoint list + _waypointStore.clear(); - uint64 uiCreatureCount = 0; + uint64 entryCount = 0; - // Load Waypoints + // load Waypoints QueryResult result = WorldDatabase.Query("SELECT COUNT(entry) FROM script_waypoint GROUP BY entry"); if (result) - uiCreatureCount = result->GetRowCount(); + entryCount = result->GetRowCount(); - TC_LOG_INFO("server.loading", "Loading Script Waypoints for " UI64FMTD " creature(s)...", uiCreatureCount); + TC_LOG_INFO("server.loading", "Loading Script Waypoints for " UI64FMTD " creature(s)...", entryCount); // 0 1 2 3 4 5 result = WorldDatabase.Query("SELECT entry, pointid, location_x, location_y, location_z, waittime FROM script_waypoint ORDER BY pointid"); @@ -61,29 +61,28 @@ void SystemMgr::LoadScriptWaypoints() do { - Field* pFields = result->Fetch(); - ScriptPointMove temp; - - temp.uiCreatureEntry = pFields[0].GetUInt32(); - uint32 uiEntry = temp.uiCreatureEntry; - temp.uiPointId = pFields[1].GetUInt32(); - temp.fX = pFields[2].GetFloat(); - temp.fY = pFields[3].GetFloat(); - temp.fZ = pFields[4].GetFloat(); - temp.uiWaitTime = pFields[5].GetUInt32(); - - CreatureTemplate const* pCInfo = sObjectMgr->GetCreatureTemplate(temp.uiCreatureEntry); - - if (!pCInfo) + Field* fields = result->Fetch(); + uint32 entry = fields[0].GetUInt32(); + uint32 id = fields[1].GetUInt32(); + float x = fields[2].GetFloat(); + float y = fields[3].GetFloat(); + float z = fields[4].GetFloat(); + uint32 waitTime = fields[5].GetUInt32(); + + CreatureTemplate const* info = sObjectMgr->GetCreatureTemplate(entry); + if (!info) { - TC_LOG_ERROR("sql.sql", "TSCR: DB table script_waypoint has waypoint for non-existant creature entry %u", temp.uiCreatureEntry); + TC_LOG_ERROR("sql.sql", "SystemMgr: DB table script_waypoint has waypoint for non-existant creature entry %u", entry); continue; } - if (!pCInfo->ScriptID) - TC_LOG_ERROR("sql.sql", "TSCR: DB table script_waypoint has waypoint for creature entry %u, but creature does not have ScriptName defined and then useless.", temp.uiCreatureEntry); + if (!info->ScriptID) + TC_LOG_ERROR("sql.sql", "SystemMgr: DB table script_waypoint has waypoint for creature entry %u, but creature does not have ScriptName defined and then useless.", entry); + + WaypointPath& path = _waypointStore[entry]; + path.id = entry; + path.nodes.emplace_back(id, x, y, z, 0.f, waitTime); - m_mPointMoveMap[uiEntry].push_back(temp); ++count; } while (result->NextRow()); @@ -163,6 +162,15 @@ void SystemMgr::LoadScriptSplineChains() } } +WaypointPath const* SystemMgr::GetPath(uint32 creatureEntry) const +{ + auto itr = _waypointStore.find(creatureEntry); + if (itr == _waypointStore.end()) + return nullptr; + + return &itr->second; +} + std::vector<SplineChainLink> const* SystemMgr::GetSplineChain(uint32 entry, uint16 chainId) const { auto it = m_mSplineChainsMap.find({ entry, chainId }); diff --git a/src/server/game/Scripting/ScriptSystem.h b/src/server/game/Scripting/ScriptSystem.h index 7828c24d680..7370a6262eb 100644 --- a/src/server/game/Scripting/ScriptSystem.h +++ b/src/server/game/Scripting/ScriptSystem.h @@ -21,59 +21,39 @@ #include "Define.h" #include "Hash.h" +#include "WaypointDefines.h" #include <unordered_map> #include <vector> class Creature; struct SplineChainLink; -#define TEXT_SOURCE_RANGE -1000000 //the amount of entries each text source has available - -struct ScriptPointMove -{ - uint32 uiCreatureEntry; - uint32 uiPointId; - float fX; - float fY; - float fZ; - uint32 uiWaitTime; -}; - -typedef std::vector<ScriptPointMove> ScriptPointVector; +#define TEXT_SOURCE_RANGE -1000000 // the amount of entries each text source has available class TC_GAME_API SystemMgr { - private: - SystemMgr(); - ~SystemMgr(); - SystemMgr(SystemMgr const&) = delete; - SystemMgr& operator=(SystemMgr const&) = delete; - public: static SystemMgr* instance(); - typedef std::unordered_map<uint32, ScriptPointVector> PointMoveMap; - - //Database + // database void LoadScriptWaypoints(); void LoadScriptSplineChains(); - ScriptPointVector const* GetPointMoveList(uint32 creatureEntry) const - { - PointMoveMap::const_iterator itr = m_mPointMoveMap.find(creatureEntry); - - if (itr == m_mPointMoveMap.end()) - return nullptr; - - return &itr->second; - } + WaypointPath const* GetPath(uint32 creatureEntry) const; std::vector<SplineChainLink> const* GetSplineChain(uint32 entry, uint16 chainId) const; std::vector<SplineChainLink> const* GetSplineChain(Creature const* who, uint16 id) const; - protected: - PointMoveMap m_mPointMoveMap; //coordinates for waypoints + private: typedef std::pair<uint32, uint16> ChainKeyType; // creature entry + chain ID + + SystemMgr(); + ~SystemMgr(); + + SystemMgr(SystemMgr const&) = delete; + SystemMgr& operator=(SystemMgr const&) = delete; + + std::unordered_map<uint32, WaypointPath> _waypointStore; std::unordered_map<ChainKeyType, std::vector<SplineChainLink>> m_mSplineChainsMap; // spline chains }; |
