Files
TCPlayerbotCore/src/game/WaypointManager.cpp
T

152 lines
4.1 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
* Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* 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
2008-12-09 23:02:17 -06:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* 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, write to the Free Software
2008-12-09 23:02:17 -06:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
#include "Database/DatabaseEnv.h"
#include "GridDefines.h"
#include "WaypointManager.h"
#include "ProgressBar.h"
#include "MapManager.h"
WaypointPathMap WaypointPathHolder;
2008-12-09 23:02:17 -06:00
WaypointStore WaypointMgr;
2008-10-02 16:23:55 -05:00
2008-12-09 23:02:17 -06:00
void WaypointStore::Free()
2008-10-02 16:23:55 -05:00
{
WaypointPathHolder.clear();
2008-10-02 16:23:55 -05:00
}
2008-12-09 23:02:17 -06:00
void WaypointStore::Load()
2008-10-02 16:23:55 -05:00
{
2008-12-24 12:06:25 +02:00
QueryResult *result = WorldDatabase.PQuery("SELECT MAX(`id`) FROM `waypoint_data`");
2008-12-09 23:02:17 -06:00
if(!result)
2008-10-02 16:23:55 -05:00
{
sLog.outError("an error occured while loading the table `waypoint_data` (maybe it doesn't exist ?)");
2008-12-09 23:02:17 -06:00
exit(1); // Stop server at loading non exited table or not accessable table
2008-10-02 16:23:55 -05:00
}
2009-02-09 08:16:34 -05:00
records = (*result)[0].GetUInt32();
2008-12-09 23:02:17 -06:00
delete result;
2008-10-02 16:23:55 -05:00
2009-02-09 08:16:34 -05:00
result = WorldDatabase.PQuery("SELECT `id`,`point`,`position_x`,`position_y`,`position_z`,`move_flag`,`delay`,`action`,`action_chance` FROM `waypoint_data` ORDER BY `id`, `point`");
2008-12-09 23:02:17 -06:00
if(!result)
2008-10-02 16:23:55 -05:00
{
sLog.outErrorDb("The table `waypoint_data` is empty or corrupted");
2008-12-09 23:02:17 -06:00
return;
2008-10-02 16:23:55 -05:00
}
2008-12-09 23:02:17 -06:00
WaypointPath* path_data;
uint32 total_records = result->GetRowCount();
2008-10-02 16:23:55 -05:00
2009-02-09 08:16:34 -05:00
barGoLink bar( total_records);
2008-12-09 23:02:17 -06:00
Field *fields;
uint32 last_id = 0;
2009-02-09 08:16:34 -05:00
do
2008-10-02 16:23:55 -05:00
{
2008-12-09 23:02:17 -06:00
fields = result->Fetch();
uint32 id = fields[0].GetUInt32();
bar.step();
WaypointData *wp = new WaypointData;
2009-02-09 08:16:34 -05:00
if(last_id != id)
path_data = new WaypointPath;
2009-02-09 08:16:34 -05:00
float x,y,z;
2008-12-09 23:02:17 -06:00
x = fields[2].GetFloat();
y = fields[3].GetFloat();
z = fields[4].GetFloat();
Trinity::NormalizeMapCoord(x);
Trinity::NormalizeMapCoord(y);
wp->id = fields[1].GetUInt32();
wp->x = x;
wp->y = y;
wp->z = z;
wp->run = fields[5].GetBool();
wp->delay = fields[6].GetUInt32();
wp->event_id = fields[7].GetUInt32();
wp->event_chance = fields[8].GetUInt8();
2009-02-09 08:16:34 -05:00
path_data->push_back(wp);
if(id != last_id)
WaypointPathHolder[id] = path_data;
2009-02-09 08:16:34 -05:00
last_id = id;
2008-12-09 23:02:17 -06:00
2009-02-09 08:16:34 -05:00
} while(result->NextRow()) ;
2008-12-09 23:02:17 -06:00
delete result;
2008-10-02 16:23:55 -05:00
}
2008-11-22 09:51:35 -06:00
2008-12-09 23:02:17 -06:00
void WaypointStore::UpdatePath(uint32 id)
2008-11-22 09:51:35 -06:00
{
// TODO: this will cause memory leak
if(WaypointPathHolder.find(id) != WaypointPathHolder.end())
WaypointPathHolder[id]->clear();
2009-02-09 08:16:34 -05:00
QueryResult *result;
2008-12-09 23:02:17 -06:00
result = WorldDatabase.PQuery("SELECT `id`,`point`,`position_x`,`position_y`,`position_z`,`move_flag`,`delay`,`action`,`action_chance` FROM `waypoint_data` WHERE id = %u ORDER BY `point`", id);
2009-02-09 08:16:34 -05:00
if(!result)
return;
2009-02-09 08:16:34 -05:00
WaypointPath* path_data;
2009-02-09 08:16:34 -05:00
path_data = new WaypointPath;
2009-02-09 08:16:34 -05:00
Field *fields;
2009-02-09 08:16:34 -05:00
do
2008-11-22 09:51:35 -06:00
{
2009-02-09 08:16:34 -05:00
fields = result->Fetch();
2008-12-09 23:02:17 -06:00
uint32 id = fields[0].GetUInt32();
2008-12-09 23:02:17 -06:00
WaypointData *wp = new WaypointData;
2009-02-09 08:16:34 -05:00
float x,y,z;
2008-12-09 23:02:17 -06:00
x = fields[2].GetFloat();
y = fields[3].GetFloat();
z = fields[4].GetFloat();
2009-02-09 08:16:34 -05:00
Trinity::NormalizeMapCoord(x);
2008-12-09 23:02:17 -06:00
Trinity::NormalizeMapCoord(y);
wp->id = fields[1].GetUInt32();
wp->x = x;
wp->y = y;
wp->z = z;
wp->run = fields[5].GetBool();
wp->delay = fields[6].GetUInt32();
wp->event_id = fields[7].GetUInt32();
wp->event_chance = fields[8].GetUInt8();
2009-02-09 08:16:34 -05:00
path_data->push_back(wp);
2008-12-09 23:02:17 -06:00
2009-02-09 08:16:34 -05:00
}while (result->NextRow());
WaypointPathHolder[id] = path_data;
2008-12-09 23:02:17 -06:00
2009-02-09 08:16:34 -05:00
delete result;
2008-11-22 09:51:35 -06:00
}
2009-02-17 20:07:49 -06:00