mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-23 13:46:24 +00:00
First Commit
For Azeroth!
This commit is contained in:
158
src/server/game/Movement/Waypoints/WaypointManager.cpp
Normal file
158
src/server/game/Movement/Waypoints/WaypointManager.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "DatabaseEnv.h"
|
||||
#include "GridDefines.h"
|
||||
#include "WaypointManager.h"
|
||||
#include "MapManager.h"
|
||||
#include "Log.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();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
sLog->outErrorDb(">> Loaded 0 waypoints. DB table `waypoint_data` is empty!");
|
||||
sLog->outString();
|
||||
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();
|
||||
|
||||
Trinity::NormalizeMapCoord(x);
|
||||
Trinity::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());
|
||||
|
||||
sLog->outString(">> Loaded %u waypoints in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
PreparedStatement* 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();
|
||||
|
||||
Trinity::NormalizeMapCoord(x);
|
||||
Trinity::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());
|
||||
}
|
||||
80
src/server/game/Movement/Waypoints/WaypointManager.h
Normal file
80
src/server/game/Movement/Waypoints/WaypointManager.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_WAYPOINTMANAGER_H
|
||||
#define TRINITY_WAYPOINTMANAGER_H
|
||||
|
||||
#include <ace/Singleton.h>
|
||||
#include <ace/Null_Mutex.h>
|
||||
#include <vector>
|
||||
|
||||
enum WaypointMoveType
|
||||
{
|
||||
WAYPOINT_MOVE_TYPE_WALK,
|
||||
WAYPOINT_MOVE_TYPE_RUN,
|
||||
WAYPOINT_MOVE_TYPE_LAND,
|
||||
WAYPOINT_MOVE_TYPE_TAKEOFF,
|
||||
|
||||
WAYPOINT_MOVE_TYPE_MAX
|
||||
};
|
||||
|
||||
struct WaypointData
|
||||
{
|
||||
uint32 id;
|
||||
float x, y, z, orientation;
|
||||
uint32 delay;
|
||||
uint32 event_id;
|
||||
uint32 move_type;
|
||||
uint8 event_chance;
|
||||
};
|
||||
|
||||
typedef std::vector<WaypointData*> WaypointPath;
|
||||
typedef UNORDERED_MAP<uint32, WaypointPath> WaypointPathContainer;
|
||||
|
||||
class WaypointMgr
|
||||
{
|
||||
friend class ACE_Singleton<WaypointMgr, ACE_Null_Mutex>;
|
||||
|
||||
public:
|
||||
// Attempts to reload a single path from database
|
||||
void ReloadPath(uint32 id);
|
||||
|
||||
// Loads all paths from database, should only run on startup
|
||||
void Load();
|
||||
|
||||
// Returns the path from a given id
|
||||
WaypointPath const* GetPath(uint32 id) const
|
||||
{
|
||||
WaypointPathContainer::const_iterator itr = _waypointStore.find(id);
|
||||
if (itr != _waypointStore.end())
|
||||
return &itr->second;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
// Only allow instantiation from ACE_Singleton
|
||||
WaypointMgr();
|
||||
~WaypointMgr();
|
||||
|
||||
WaypointPathContainer _waypointStore;
|
||||
};
|
||||
|
||||
#define sWaypointMgr ACE_Singleton<WaypointMgr, ACE_Null_Mutex>::instance()
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user