AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
SmartWaypointMgr Class Reference

#include "SmartScriptMgr.h"

Public Member Functions

 ~SmartWaypointMgr ()
 
void LoadFromDB ()
 
WaypointPathGetPath (uint32 id)
 

Static Public Member Functions

static SmartWaypointMgrinstance ()
 

Private Member Functions

 SmartWaypointMgr ()
 

Private Attributes

std::unordered_map< uint32, WaypointPath * > waypoint_map
 

Detailed Description

Constructor & Destructor Documentation

◆ SmartWaypointMgr()

SmartWaypointMgr::SmartWaypointMgr ( )
inlineprivate
2035{}

◆ ~SmartWaypointMgr()

SmartWaypointMgr::~SmartWaypointMgr ( )
116{
117 for (auto itr : waypoint_map)
118 {
119 delete itr.second;
120 }
121}
std::unordered_map< uint32, WaypointPath * > waypoint_map
Definition SmartScriptMgr.h:2051

References waypoint_map.

Member Function Documentation

◆ GetPath()

WaypointPath * SmartWaypointMgr::GetPath ( uint32  id)
inline
2044 {
2045 if (waypoint_map.find(id) != waypoint_map.end())
2046 return waypoint_map[id];
2047 else return 0;
2048 }

References waypoint_map.

◆ instance()

SmartWaypointMgr * SmartWaypointMgr::instance ( )
static
42{
44 return &instance;
45}
Definition SmartScriptMgr.h:2034
static SmartWaypointMgr * instance()
Definition SmartScriptMgr.cpp:41

References instance().

Referenced by instance().

◆ LoadFromDB()

void SmartWaypointMgr::LoadFromDB ( )
48{
49 uint32 oldMSTime = getMSTime();
50
51 for (auto itr : waypoint_map)
52 {
53 delete itr.second;
54 }
55
56 waypoint_map.clear();
57
59 PreparedQueryResult result = WorldDatabase.Query(stmt);
60
61 if (!result)
62 {
63 LOG_WARN("server.loading", ">> Loaded 0 SmartAI Waypoint Paths. DB table `waypoints` is empty.");
64 LOG_INFO("server.loading", " ");
65 return;
66 }
67
68 uint32 count = 0;
69 uint32 total = 0;
70 uint32 last_entry = 0;
71 uint32 last_id = 1;
72
73 do
74 {
75 Field* fields = result->Fetch();
76 uint32 entry = fields[0].Get<uint32>();
77 uint32 id = fields[1].Get<uint32>();
78 float x = fields[2].Get<float>();
79 float y = fields[3].Get<float>();
80 float z = fields[4].Get<float>();
82 if (!fields[5].IsNull())
83 o = fields[5].Get<float>();
84 uint32 delay = fields[6].Get<uint32>();
85
86 if (last_entry != entry)
87 {
88 waypoint_map[entry] = new WaypointPath();
89 last_id = 1;
90 count++;
91 }
92
93 if (last_id != id)
94 LOG_ERROR("sql.sql", "SmartWaypointMgr::LoadFromDB: Path entry {}, unexpected point id {}, expected {}.", entry, id, last_id);
95
96 last_id++;
97 WaypointData data;
98 data.id = id;
99 data.x = x;
100 data.y = y;
101 data.z = z;
102 data.orientation = o;
103 data.delay = delay;
105 (*waypoint_map[entry]).emplace(id, data);
106
107 last_entry = entry;
108 total++;
109 } while (result->NextRow());
110
111 LOG_INFO("server.loading", ">> Loaded {} SmartAI waypoint paths (total {} waypoints) in {} ms", count, total, GetMSTimeDiffToNow(oldMSTime));
112 LOG_INFO("server.loading", " ");
113}
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition DatabaseEnv.cpp:20
std::uint32_t uint32
Definition Define.h:107
#define LOG_INFO(filterType__,...)
Definition Log.h:166
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define LOG_WARN(filterType__,...)
Definition Log.h:162
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:131
uint32 getMSTime()
Definition Timer.h:103
@ WAYPOINT_MOVE_TYPE_MAX
Definition WaypointMgr.h:34
std::map< uint32, WaypointData > WaypointPath
Definition WaypointMgr.h:48
@ WORLD_SEL_SMARTAI_WP
Definition WorldDatabase.h:36
Class used to access individual fields of database query result.
Definition Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112
Definition PreparedStatement.h:157
Definition WaypointMgr.h:38
float z
Definition WaypointMgr.h:40
float x
Definition WaypointMgr.h:40
float y
Definition WaypointMgr.h:40
std::optional< float > orientation
Definition WaypointMgr.h:41
uint32 delay
Definition WaypointMgr.h:42
uint32 id
Definition WaypointMgr.h:39
uint32 move_type
Definition WaypointMgr.h:44

References WaypointData::delay, Field::Get(), getMSTime(), GetMSTimeDiffToNow(), WaypointData::id, LOG_ERROR, LOG_INFO, LOG_WARN, WaypointData::move_type, WaypointData::orientation, waypoint_map, WAYPOINT_MOVE_TYPE_MAX, WORLD_SEL_SMARTAI_WP, WorldDatabase, WaypointData::x, WaypointData::y, and WaypointData::z.

Member Data Documentation

◆ waypoint_map

std::unordered_map<uint32, WaypointPath*> SmartWaypointMgr::waypoint_map
private

The documentation for this class was generated from the following files: