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)

(cherry picked from commit 7fff83d675)
This commit is contained in:
ccrs
2017-08-12 01:40:25 +02:00
committed by Shauren
parent a86870622d
commit 97585597f0
87 changed files with 1264 additions and 1413 deletions
@@ -29,6 +29,7 @@
#include "SpellMgr.h"
#include "Timer.h"
#include "UnitDefines.h"
#include "WaypointDefines.h"
#include <algorithm>
SmartWaypointMgr* SmartWaypointMgr::instance()
@@ -41,15 +42,7 @@ void SmartWaypointMgr::LoadFromDB()
{
uint32 oldMSTime = getMSTime();
for (std::unordered_map<uint32, WPPath*>::iterator itr = waypoint_map.begin(); itr != waypoint_map.end(); ++itr)
{
for (WPPath::iterator pathItr = itr->second->begin(); pathItr != itr->second->end(); ++pathItr)
delete pathItr->second;
delete itr->second;
}
waypoint_map.clear();
_waypointStore.clear();
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_SMARTAI_WP);
PreparedQueryResult result = WorldDatabase.Query(stmt);
@@ -63,49 +56,47 @@ void SmartWaypointMgr::LoadFromDB()
uint32 count = 0;
uint32 total = 0;
uint32 last_entry = 0;
uint32 last_id = 1;
uint32 lastEntry = 0;
uint32 lastId = 1;
do
{
Field* fields = result->Fetch();
uint32 entry = fields[0].GetUInt32();
uint32 id = fields[1].GetUInt32();
float x, y, z;
x = fields[2].GetFloat();
y = fields[3].GetFloat();
z = fields[4].GetFloat();
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
float z = fields[4].GetFloat();
if (last_entry != entry)
if (lastEntry != entry)
{
waypoint_map[entry] = new WPPath();
last_id = 1;
count++;
lastId = 1;
++count;
}
if (last_id != id)
TC_LOG_ERROR("sql.sql", "SmartWaypointMgr::LoadFromDB: Path entry %u, unexpected point id %u, expected %u.", entry, id, last_id);
if (lastId != id)
TC_LOG_ERROR("sql.sql", "SmartWaypointMgr::LoadFromDB: Path entry %u, unexpected point id %u, expected %u.", entry, id, lastId);
last_id++;
(*waypoint_map[entry])[id] = new WayPoint(id, x, y, z);
++lastId;
last_entry = entry;
total++;
WaypointPath& path = _waypointStore[entry];
path.id = entry;
path.nodes.emplace_back(id, x, y, z);
lastEntry = entry;
++total;
}
while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded %u SmartAI waypoint paths (total %u waypoints) in %u ms", count, total, GetMSTimeDiffToNow(oldMSTime));
}
SmartWaypointMgr::~SmartWaypointMgr()
WaypointPath const* SmartWaypointMgr::GetPath(uint32 id)
{
for (std::unordered_map<uint32, WPPath*>::iterator itr = waypoint_map.begin(); itr != waypoint_map.end(); ++itr)
{
for (WPPath::iterator pathItr = itr->second->begin(); pathItr != itr->second->end(); ++pathItr)
delete pathItr->second;
delete itr->second;
}
auto itr = _waypointStore.find(id);
if (itr != _waypointStore.end())
return &itr->second;
return nullptr;
}
SmartAIMgr* SmartAIMgr::instance()
@@ -1363,21 +1354,22 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
return false;
break;
case SMART_ACTION_WP_START:
{
WaypointPath const* path = sSmartWaypointMgr->GetPath(e.action.wpStart.pathID);
if (!path || path->nodes.empty())
{
if (!sSmartWaypointMgr->GetPath(e.action.wpStart.pathID))
{
TC_LOG_ERROR("sql.sql", "SmartAIMgr: Creature " SI64FMTD " Event %u Action %u uses non-existent WaypointPath id %u, skipped.", e.entryOrGuid, e.event_id, e.GetActionType(), e.action.wpStart.pathID);
return false;
}
if (e.action.wpStart.quest && !IsQuestValid(e, e.action.wpStart.quest))
return false;
if (e.action.wpStart.reactState > REACT_AGGRESSIVE)
{
TC_LOG_ERROR("sql.sql", "SmartAIMgr: Creature " SI64FMTD " Event %u Action %u uses invalid React State %u, skipped.", e.entryOrGuid, e.event_id, e.GetActionType(), e.action.wpStart.reactState);
return false;
}
break;
TC_LOG_ERROR("sql.sql", "SmartAIMgr: Creature " SI64FMTD " Event %u Action %u uses non-existent WaypointPath id %u, skipped.", e.entryOrGuid, e.event_id, e.GetActionType(), e.action.wpStart.pathID);
return false;
}
if (e.action.wpStart.quest && !IsQuestValid(e, e.action.wpStart.quest))
return false;
if (e.action.wpStart.reactState > REACT_AGGRESSIVE)
{
TC_LOG_ERROR("sql.sql", "SmartAIMgr: Creature " SI64FMTD " Event %u Action %u uses invalid React State %u, skipped.", e.entryOrGuid, e.event_id, e.GetActionType(), e.action.wpStart.reactState);
return false;
}
break;
}
case SMART_ACTION_CREATE_TIMED_EVENT:
{
if (!IsMinMaxValid(e, e.action.timeEvent.min, e.action.timeEvent.max))