Files
azerothcore-wotlk/src/server/game/Movement/Waypoints/WaypointMgr.cpp
Kitzunu 2f449326e0 refactor(Core): Rename ...Manager to ...Mgr (#6910)
* Rename MapManager.h to MapMgr.h

* Rename BanManager.h to BanMgr.h

* Rename MapManager.cpp to MapMgr.cpp

* Rename BanManager.cpp to BanMgr.cpp

* Rename MapRefManager.h to MapRefMgr.h

* Rename ThreatManager.h to ThreatMgr.h

* Rename GridRefManager.h to GridRefMgr.h

* Rename ThreatManager.cpp to ThreatMgr.cpp

* Rename GroupRefManager.h to GroupRefMgr.h

* Rename HostileRefManager.h to HostileRefMgr.h

* Rename HostileRefManager.cpp to HostileRefMgr.cpp

* Rename MMapManager.h to MMapMgr.h

* Rename FollowerRefManager.h to FollowerRefMgr.h

* Rename VMapManager2.h to VMapMgr2.h

* Rename IVMapManager.h to IVMapMgr.h

* Rename MMapManager.cpp to MMapMgr.cpp

* Rename VMapManager2.cpp to VMapMgr2.cpp

* Rename RefManager.h to RefMgr.h

* Rename WaypointManager.h to WaypointMgr.h

* Rename WaypointManager.cpp to WaypointMgr.cpp

* Rename MPQManager.h to MPQMgr.h

* Rename MPQManager.cpp to MPQMgr.cpp

* Rename IMMAPManager.h to IMMAPMgr.h

* fix build

* Update Main.cpp

* chore(Core/Misc): Remove toxic language

* Revert "chore(Core/Misc): Remove toxic language"

* fix build

* build
2021-09-15 17:50:28 +02:00

149 lines
4.2 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/
#include "DatabaseEnv.h"
#include "GridDefines.h"
#include "Log.h"
#include "WaypointMgr.h"
WaypointMgr::WaypointMgr()
{
}
WaypointMgr::~WaypointMgr()
{
for (WaypointPathContainer::iterator itr = _waypointStore.begin(); itr != _waypointStore.end(); ++itr)
{
for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
delete *it;
itr->second.clear();
}
_waypointStore.clear();
}
WaypointMgr* WaypointMgr::instance()
{
static WaypointMgr instance;
return &instance;
}
void WaypointMgr::Load()
{
uint32 oldMSTime = getMSTime();
// 0 1 2 3 4 5 6 7 8 9
QueryResult result = WorldDatabase.Query("SELECT id, point, position_x, position_y, position_z, orientation, move_type, delay, action, action_chance FROM waypoint_data ORDER BY id, point");
if (!result)
{
LOG_ERROR("sql.sql", ">> Loaded 0 waypoints. DB table `waypoint_data` is empty!");
LOG_INFO("server.loading", " ");
return;
}
uint32 count = 0;
do
{
Field* fields = result->Fetch();
WaypointData* wp = new WaypointData();
uint32 pathId = fields[0].GetUInt32();
WaypointPath& path = _waypointStore[pathId];
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
float z = fields[4].GetFloat();
float o = fields[5].GetFloat();
Acore::NormalizeMapCoord(x);
Acore::NormalizeMapCoord(y);
wp->id = fields[1].GetUInt32();
wp->x = x;
wp->y = y;
wp->z = z;
wp->orientation = o;
wp->move_type = fields[6].GetUInt32();
if (wp->move_type >= WAYPOINT_MOVE_TYPE_MAX)
{
//TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp->id);
delete wp;
continue;
}
wp->delay = fields[7].GetUInt32();
wp->event_id = fields[8].GetUInt32();
wp->event_chance = fields[9].GetInt16();
path.push_back(wp);
++count;
} while (result->NextRow());
LOG_INFO("server.loading", ">> Loaded %u waypoints in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
void WaypointMgr::ReloadPath(uint32 id)
{
WaypointPathContainer::iterator itr = _waypointStore.find(id);
if (itr != _waypointStore.end())
{
for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
delete *it;
_waypointStore.erase(itr);
}
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_ID);
stmt->setUInt32(0, id);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (!result)
return;
WaypointPath& path = _waypointStore[id];
do
{
Field* fields = result->Fetch();
WaypointData* wp = new WaypointData();
float x = fields[1].GetFloat();
float y = fields[2].GetFloat();
float z = fields[3].GetFloat();
float o = fields[4].GetFloat();
Acore::NormalizeMapCoord(x);
Acore::NormalizeMapCoord(y);
wp->id = fields[0].GetUInt32();
wp->x = x;
wp->y = y;
wp->z = z;
wp->orientation = o;
wp->move_type = fields[5].GetUInt32();
if (wp->move_type >= WAYPOINT_MOVE_TYPE_MAX)
{
//TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp->id);
delete wp;
continue;
}
wp->delay = fields[6].GetUInt32();
wp->event_id = fields[7].GetUInt32();
wp->event_chance = fields[8].GetUInt8();
path.push_back(wp);
} while (result->NextRow());
}