2010-10-07 15:35:36 +02:00
/*
2012-01-01 00:32:13 +01:00
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:35:36 +02:00
* 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
2010-06-08 17:01:03 -06:00
#include "DatabaseEnv.h"
2008-10-02 16:23:55 -05:00
#include "GridDefines.h"
#include "WaypointManager.h"
#include "MapManager.h"
2011-08-01 13:46:00 +02:00
#include "Log.h"
2009-10-17 15:51:44 -07:00
2011-05-24 23:13:47 +02:00
WaypointMgr :: WaypointMgr ()
2008-10-02 16:23:55 -05:00
{
2011-05-24 23:13:47 +02:00
}
WaypointMgr ::~ WaypointMgr ()
{
for ( WaypointPathContainer :: iterator itr = _waypointStore . begin (); itr != _waypointStore . end (); ++ itr )
2010-05-13 00:42:37 +02:00
{
2011-05-24 23:13:47 +02:00
for ( WaypointPath :: const_iterator it = itr -> second . begin (); it != itr -> second . end (); ++ it )
2010-05-13 00:42:37 +02:00
delete * it ;
2011-05-24 23:13:47 +02:00
itr -> second . clear ();
2010-05-13 00:42:37 +02:00
}
2011-05-24 23:13:47 +02:00
_waypointStore . clear ();
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2011-05-24 23:13:47 +02:00
void WaypointMgr :: Load ()
2008-10-02 16:23:55 -05:00
{
2010-12-19 17:06:33 +01:00
uint32 oldMSTime = getMSTime ();
2009-10-17 15:51:44 -07:00
2012-03-27 21:36:16 +01:00
// 0 1 2 3 4 5 6 7 8 9
2011-10-15 18:38:27 +02:00
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
{
2012-08-03 14:20:18 +02: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
2010-01-01 14:19:29 -06: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
{
2011-05-24 23:13:47 +02:00
Field * fields = result -> Fetch ();
WaypointData * wp = new WaypointData ();
2009-10-17 15:51:44 -07:00
2011-05-24 23:13:47 +02:00
uint32 pathId = fields [ 0 ]. GetUInt32 ();
WaypointPath & path = _waypointStore [ pathId ];
2009-10-17 15:51:44 -07:00
2011-05-24 23:13:47 +02:00
float x = fields [ 2 ]. GetFloat ();
float y = fields [ 3 ]. GetFloat ();
float z = fields [ 4 ]. GetFloat ();
2011-10-15 18:38:27 +02:00
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 ;
2011-10-15 18:38:27 +02:00
wp -> orientation = o ;
wp -> run = fields [ 6 ]. GetBool ();
wp -> delay = fields [ 7 ]. GetUInt32 ();
wp -> event_id = fields [ 8 ]. GetUInt32 ();
2012-03-28 00:38:04 +01:00
wp -> event_chance = fields [ 9 ]. GetInt16 ();
2009-10-17 15:51:44 -07:00
2011-05-24 23:13:47 +02:00
path . push_back ( wp );
++ count ;
2010-12-19 17:06:33 +01:00
}
2011-05-24 23:13:47 +02:00
while ( result -> NextRow ());
2009-10-17 15:51:44 -07:00
2012-08-03 14:20:18 +02: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
2011-05-24 23:13:47 +02:00
void WaypointMgr :: ReloadPath ( uint32 id )
2008-11-22 09:51:35 -06:00
{
2011-05-24 23:13:47 +02: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
2011-05-24 23:13:47 +02:00
_waypointStore . erase ( itr );
}
2009-10-17 15:51:44 -07:00
2012-03-24 01:25:08 +01: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
2011-05-24 23:13:47 +02: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
{
2011-05-24 23:13:47 +02:00
Field * fields = result -> Fetch ();
2011-09-15 14:08:17 +02:00
WaypointData * wp = new WaypointData ();
2009-10-17 15:51:44 -07:00
2011-05-24 23:13:47 +02:00
float x = fields [ 1 ]. GetFloat ();
float y = fields [ 2 ]. GetFloat ();
float z = fields [ 3 ]. GetFloat ();
2011-10-15 18:38:27 +02:00
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 ;
2011-10-15 18:38:27 +02:00
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
2011-05-24 23:13:47 +02:00
path . push_back ( wp );
2009-10-17 15:51:44 -07:00
2009-08-22 16:54:14 +02:00
}
while ( result -> NextRow ());
2008-11-22 09:51:35 -06:00
}