TrinityCore
Loading...
Searching...
No Matches
WaypointManager.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "WaypointManager.h"
19#include "DatabaseEnv.h"
20#include "GridDefines.h"
21#include "MapManager.h"
22#include "Log.h"
23
25{
26 uint32 oldMSTime = getMSTime();
27
28 // 0 1 2 3 4 5 6 7 8 9
29 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");
30
31 if (!result)
32 {
33 TC_LOG_INFO("server.loading", ">> Loaded 0 waypoints. DB table `waypoint_data` is empty!");
34 return;
35 }
36
37 uint32 count = 0;
38
39 do
40 {
41 Field* fields = result->Fetch();
42 uint32 pathId = fields[0].GetUInt32();
43 float x = fields[2].GetFloat();
44 float y = fields[3].GetFloat();
45 float z = fields[4].GetFloat();
47 if (!fields[5].IsNull())
48 o = fields[5].GetFloat();
49
52
53 WaypointNode waypoint;
54 waypoint.id = fields[1].GetUInt32();
55 waypoint.x = x;
56 waypoint.y = y;
57 waypoint.z = z;
58 waypoint.orientation = o;
59 waypoint.moveType = fields[6].GetUInt32();
60
61 if (waypoint.moveType >= WAYPOINT_MOVE_TYPE_MAX)
62 {
63 TC_LOG_ERROR("sql.sql", "Waypoint {} in waypoint_data has invalid move_type, ignoring", waypoint.id);
64 continue;
65 }
66
67 waypoint.delay = fields[7].GetUInt32();
68 waypoint.eventId = fields[8].GetUInt32();
69 waypoint.eventChance = fields[9].GetInt16();
70
71 WaypointPath& path = _waypointStore[pathId];
72 path.id = pathId;
73 path.nodes.push_back(std::move(waypoint));
74 ++count;
75 }
76 while (result->NextRow());
77
78 TC_LOG_INFO("server.loading", ">> Loaded {} waypoints in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
79}
80
86
88{
90
91 stmt->setUInt32(0, id);
92
93 PreparedQueryResult result = WorldDatabase.Query(stmt);
94
95 if (!result)
96 return;
97
98 std::vector<WaypointNode> values;
99 do
100 {
101 Field* fields = result->Fetch();
102 float x = fields[1].GetFloat();
103 float y = fields[2].GetFloat();
104 float z = fields[3].GetFloat();
106 if (!fields[4].IsNull())
107 o = fields[4].GetFloat();
108
111
112 WaypointNode waypoint;
113 waypoint.id = fields[0].GetUInt32();
114 waypoint.x = x;
115 waypoint.y = y;
116 waypoint.z = z;
117 waypoint.orientation = o;
118 waypoint.moveType = fields[5].GetUInt32();
119
120 if (waypoint.moveType >= WAYPOINT_MOVE_TYPE_MAX)
121 {
122 TC_LOG_ERROR("sql.sql", "Waypoint {} in waypoint_data has invalid move_type, ignoring", waypoint.id);
123 continue;
124 }
125
126 waypoint.delay = fields[6].GetUInt32();
127 waypoint.eventId = fields[7].GetUInt32();
128 waypoint.eventChance = fields[8].GetUInt8();
129
130 values.push_back(std::move(waypoint));
131 }
132 while (result->NextRow());
133
134 WaypointPath& path = _waypointStore[id];
135 path.id = id;
136 path.nodes = std::move(values);
137}
138
140{
141 auto itr = _waypointStore.find(id);
142 if (itr != _waypointStore.end())
143 return &itr->second;
144
145 return nullptr;
146}
std::shared_ptr< ResultSet > QueryResult
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
uint32_t uint32
Definition Define.h:133
#define TC_LOG_ERROR(filterType__,...)
Definition Log.h:165
#define TC_LOG_INFO(filterType__,...)
Definition Log.h:159
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:57
uint32 getMSTime()
Definition Timer.h:33
@ WAYPOINT_MOVE_TYPE_MAX
@ WORLD_SEL_WAYPOINT_DATA_BY_ID
Class used to access individual fields of database query result.
Definition Field.h:92
uint8 GetUInt8() const
Definition Field.cpp:29
int16 GetInt16() const
Definition Field.cpp:53
float GetFloat() const
Definition Field.cpp:93
uint32 GetUInt32() const
Definition Field.cpp:61
void setUInt32(uint8 index, uint32 value)
std::unordered_map< uint32, WaypointPath > _waypointStore
WaypointPath const * GetPath(uint32 id) const
static WaypointMgr * instance()
void ReloadPath(uint32 id)
void NormalizeMapCoord(float &c)
Optional< float > orientation
std::vector< WaypointNode > nodes