Core/Movement: merged smooth waypoint movement. Followup commits will be merged soon (tm)

This commit is contained in:
Ovahlord committed 2018-08-02 15:38:35 +02:00
1 parent d59a20701e
commit c808b981f7
88 files changed
+1301 -1396

No files matched your search

@@ -30,6 +30,7 @@
#include "SpellMgr.h"
#include "Timer.h"
#include "UnitDefines.h"
#include "WaypointDefines.h"
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();
PreparedStatement* 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()
@@ -1375,7 +1366,8 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
break;
case SMART_ACTION_WP_START:
{
if (!sSmartWaypointMgr->GetPath(e.action.wpStart.pathID))
WaypointPath const* path = sSmartWaypointMgr->GetPath(e.action.wpStart.pathID);
if (!path || path->nodes.empty())
{
TC_LOG_ERROR("sql.sql", "SmartAIMgr: Creature %d Event %u Action %u uses non-existent WaypointPath id %u, skipped.", e.entryOrGuid, e.event_id, e.GetActionType(), e.action.wpStart.pathID);
return false;