Files
TCPlayerbotCore/src/server/game/Movement/Waypoints/WaypointManager.cpp
T

143 lines
4.0 KiB
C++
Raw Normal View History

/*
2012-01-01 00:32:13 +01:00
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
#include "DatabaseEnv.h"
2008-10-02 16:23:55 -05:00
#include "GridDefines.h"
#include "WaypointManager.h"
#include "MapManager.h"
#include "Log.h"
2009-10-17 15:51:44 -07:00
WaypointMgr::WaypointMgr()
2008-10-02 16:23:55 -05:00
{
}
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();
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
void WaypointMgr::Load()
2008-10-02 16:23:55 -05:00
{
uint32 oldMSTime = getMSTime();
2009-10-17 15:51:44 -07:00
// 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_flag, delay, action, action_chance FROM waypoint_data ORDER BY id, point");
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!result)
2008-10-02 16:23:55 -05:00
{
sLog->outError(LOG_FILTER_SQL, ">> Loaded 0 waypoints. DB table `waypoint_data` is empty!");
2012-08-03 15:54:54 +02:00
2008-12-09 23:02:17 -06:00
return;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
uint32 count = 0;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
do
2008-10-02 16:23:55 -05:00
{
Field* fields = result->Fetch();
WaypointData* wp = new WaypointData();
2009-10-17 15:51:44 -07:00
uint32 pathId = fields[0].GetUInt32();
WaypointPath& path = _waypointStore[pathId];
2009-10-17 15:51:44 -07:00
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
float z = fields[4].GetFloat();
float o = fields[5].GetFloat();
2009-10-17 15:51:44 -07:00
2008-12-09 23:02:17 -06:00
Trinity::NormalizeMapCoord(x);
Trinity::NormalizeMapCoord(y);
2009-10-17 15:51:44 -07:00
2008-12-09 23:02:17 -06:00
wp->id = fields[1].GetUInt32();
wp->x = x;
wp->y = y;
wp->z = z;
wp->orientation = o;
wp->run = fields[6].GetBool();
wp->delay = fields[7].GetUInt32();
wp->event_id = fields[8].GetUInt32();
wp->event_chance = fields[9].GetInt16();
2009-10-17 15:51:44 -07:00
path.push_back(wp);
++count;
}
while (result->NextRow());
2009-10-17 15:51:44 -07:00
sLog->outInfo(LOG_FILTER_GENERAL, ">> Loaded %u waypoints in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
2012-08-03 15:54:54 +02:00
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
void WaypointMgr::ReloadPath(uint32 id)
2008-11-22 09:51:35 -06:00
{
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;
2009-10-17 15:51:44 -07:00
_waypointStore.erase(itr);
}
2009-10-17 15:51:44 -07:00
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_ID);
stmt->setUInt32(0, id);
PreparedQueryResult result = WorldDatabase.Query(stmt);
2010-04-07 19:14:10 +02:00
if (!result)
2009-02-09 08:16:34 -05:00
return;
2009-10-17 15:51:44 -07:00
WaypointPath& path = _waypointStore[id];
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
do
2008-11-22 09:51:35 -06:00
{
Field* fields = result->Fetch();
WaypointData* wp = new WaypointData();
2009-10-17 15:51:44 -07:00
float x = fields[1].GetFloat();
float y = fields[2].GetFloat();
float z = fields[3].GetFloat();
float o = fields[4].GetFloat();
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
Trinity::NormalizeMapCoord(x);
2008-12-09 23:02:17 -06:00
Trinity::NormalizeMapCoord(y);
2009-10-17 15:51:44 -07:00
2010-04-19 17:08:08 +02:00
wp->id = fields[0].GetUInt32();
2008-12-09 23:02:17 -06:00
wp->x = x;
wp->y = y;
wp->z = z;
wp->orientation = o;
wp->run = fields[5].GetBool();
wp->delay = fields[6].GetUInt32();
wp->event_id = fields[7].GetUInt32();
wp->event_chance = fields[8].GetUInt8();
2009-10-17 15:51:44 -07:00
path.push_back(wp);
2009-10-17 15:51:44 -07:00
}
while (result->NextRow());
2008-11-22 09:51:35 -06:00
}