OregonCore  revision fb2a440-git
Your Favourite TBC server
WaypointManager.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 "Database/DatabaseEnv.h"
19 #include "GridDefines.h"
20 #include "WaypointManager.h"
21 #include "MapManager.h"
22 
24 
26 {
27  for (WaypointPathContainer::iterator itr = _waypointStore.begin(); itr != _waypointStore.end(); ++itr)
28  {
29  for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
30  delete *it;
31 
32  itr->second.clear();
33  }
34 
35  _waypointStore.clear();
36 }
37 
39 {
40  QueryResult_AutoPtr result = WorldDatabase.Query("SELECT COUNT(id) FROM waypoint_data");
41  if (!result)
42  sLog.outFatal("an error occured while loading the table waypoint_data (maybe it doesn't exist ?)");
43 
44  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");
45  if (!result)
46  {
47  sLog.outErrorDb("The table waypoint_data is empty or corrupted");
48  return;
49  }
50 
51  uint32 count = 0;
52 
53  do
54  {
55  Field* fields = result->Fetch();
56  WaypointData* wp = new WaypointData();
57 
58  uint32 pathId = fields[0].GetUInt32();
59  WaypointPath& path = _waypointStore[pathId];
60 
61  float x = fields[2].GetFloat();
62  float y = fields[3].GetFloat();
63  float z = fields[4].GetFloat();
64  float o = fields[5].GetFloat();
65 
68 
69  wp->id = fields[1].GetUInt32();
70  wp->x = x;
71  wp->y = y;
72  wp->z = z;
73  wp->orientation = o;
74  wp->run = fields[6].GetBool();
75  wp->delay = fields[7].GetUInt32();
76  wp->event_id = fields[8].GetUInt32();
77  wp->event_chance = fields[9].GetInt16();
78 
79  path.push_back(wp);
80  ++count;
81  }
82  while (result->NextRow());
83 
84  sLog.outString(">> Loaded %u waypoints", count);
85 }
86 
88 {
89  WaypointPathContainer::iterator itr = _waypointStore.find(id);
90  if (itr != _waypointStore.end())
91  {
92  for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
93  delete *it;
94 
95  _waypointStore.erase(itr);
96  }
97 
98  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT point, position_x, position_y, position_z, orientation, move_type, delay, action, action_chance FROM waypoint_data WHERE id = %u ORDER BY point", id);
99  if (!result)
100  return;
101 
102  WaypointPath& path = _waypointStore[id];
103 
104  do
105  {
106  Field* fields = result->Fetch();
107  WaypointData *wp = new WaypointData();
108 
109  float x = fields[1].GetFloat();
110  float y = fields[2].GetFloat();
111  float z = fields[3].GetFloat();
112  float o = fields[4].GetFloat();
113 
116 
117  wp->id = fields[0].GetUInt32();
118  wp->x = x;
119  wp->y = y;
120  wp->z = z;
121  wp->orientation = o;
122  wp->run = fields[5].GetBool();
123  wp->delay = fields[6].GetUInt32();
124  wp->event_id = fields[7].GetUInt32();
125  wp->event_chance = fields[8].GetUInt8();
126 
127  path.push_back(wp);
128 
129  }
130  while (result->NextRow());
131 }
DatabaseType WorldDatabase
Accessor to the world database.
Definition: Main.cpp:53
QueryResult_AutoPtr PQuery(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:400
Definition: Field.h:24
#define sLog
Log class singleton.
Definition: Log.h:187
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
std::vector< WaypointData * > WaypointPath
void ReloadPath(uint32 id)
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
ACE_UINT32 uint32
Definition: Define.h:71
WaypointPathContainer _waypointStore
void NormalizeMapCoord(float &c)
Definition: GridDefines.h:184