AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
mmaps_commandscript Class Reference
Inheritance diagram for mmaps_commandscript:
CommandScript ScriptObject

Public Member Functions

 mmaps_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleMmapPathCommand (ChatHandler *handler, Optional< std::string > param)
 
static bool HandleMmapLocCommand (ChatHandler *handler)
 
static bool HandleMmapLoadedTilesCommand (ChatHandler *handler)
 
static bool HandleMmapStatsCommand (ChatHandler *handler)
 
static bool HandleMmapTestArea (ChatHandler *handler)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ mmaps_commandscript()

mmaps_commandscript::mmaps_commandscript ( )
inline
42: CommandScript("mmaps_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable mmaps_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

45 {
46 static ChatCommandTable mmapCommandTable =
47 {
48 { "loadedtiles", HandleMmapLoadedTilesCommand, SEC_ADMINISTRATOR, Console::No },
49 { "loc", HandleMmapLocCommand, SEC_ADMINISTRATOR, Console::No },
50 { "path", HandleMmapPathCommand, SEC_ADMINISTRATOR, Console::No },
51 { "stats", HandleMmapStatsCommand, SEC_ADMINISTRATOR, Console::No },
52 { "testarea", HandleMmapTestArea, SEC_ADMINISTRATOR, Console::No }
53 };
54
55 static ChatCommandTable commandTable =
56 {
57 { "mmap", mmapCommandTable }
58 };
59 return commandTable;
60 }
@ SEC_ADMINISTRATOR
Definition: Common.h:60
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleMmapPathCommand(ChatHandler *handler, Optional< std::string > param)
Definition: cs_mmaps.cpp:62
static bool HandleMmapLoadedTilesCommand(ChatHandler *handler)
Definition: cs_mmaps.cpp:192
static bool HandleMmapStatsCommand(ChatHandler *handler)
Definition: cs_mmaps.cpp:217
static bool HandleMmapLocCommand(ChatHandler *handler)
Definition: cs_mmaps.cpp:129
static bool HandleMmapTestArea(ChatHandler *handler)
Definition: cs_mmaps.cpp:264

References HandleMmapLoadedTilesCommand(), HandleMmapLocCommand(), HandleMmapPathCommand(), HandleMmapStatsCommand(), HandleMmapTestArea(), and SEC_ADMINISTRATOR.

◆ HandleMmapLoadedTilesCommand()

static bool mmaps_commandscript::HandleMmapLoadedTilesCommand ( ChatHandler handler)
inlinestatic
193 {
194 uint32 mapid = handler->GetSession()->GetPlayer()->GetMapId();
195 dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(mapid);
196 dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMeshQuery(mapid, handler->GetSession()->GetPlayer()->GetInstanceId());
197 if (!navmesh || !navmeshquery)
198 {
199 handler->PSendSysMessage("NavMesh not loaded for current map.");
200 return true;
201 }
202
203 handler->PSendSysMessage("mmap loadedtiles:");
204
205 for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
206 {
207 dtMeshTile const* tile = navmesh->getTile(i);
208 if (!tile || !tile->header)
209 continue;
210
211 handler->PSendSysMessage("[{}, {}]", tile->header->x, tile->header->y);
212 }
213
214 return true;
215 }
std::int32_t int32
Definition: Define.h:103
std::uint32_t uint32
Definition: Define.h:107
static MMapMgr * createOrGetMMapMgr()
Definition: MMapFactory.cpp:27
dtNavMesh const * GetNavMesh(uint32 mapId)
Definition: MMapMgr.cpp:306
dtNavMeshQuery const * GetNavMeshQuery(uint32 mapId, uint32 instanceId)
Definition: MMapMgr.cpp:317
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
WorldSession * GetSession()
Definition: Chat.h:242
uint32 GetInstanceId() const
Definition: Object.h:443
uint32 GetMapId() const
Definition: Position.h:275
Player * GetPlayer() const
Definition: WorldSession.h:362

References MMAP::MMapFactory::createOrGetMMapMgr(), WorldObject::GetInstanceId(), WorldLocation::GetMapId(), MMAP::MMapMgr::GetNavMesh(), MMAP::MMapMgr::GetNavMeshQuery(), WorldSession::GetPlayer(), ChatHandler::GetSession(), and ChatHandler::PSendSysMessage().

Referenced by GetCommands().

◆ HandleMmapLocCommand()

static bool mmaps_commandscript::HandleMmapLocCommand ( ChatHandler handler)
inlinestatic
130 {
131 handler->PSendSysMessage("mmap tileloc:");
132
133 // grid tile location
134 Player* player = handler->GetSession()->GetPlayer();
135
136 int32 gx = 32 - player->GetPositionX() / SIZE_OF_GRIDS;
137 int32 gy = 32 - player->GetPositionY() / SIZE_OF_GRIDS;
138
139 handler->PSendSysMessage("{}{}{}.mmtile", player->GetMapId(), gx, gy);
140 handler->PSendSysMessage("gridloc [{}, {}]", gy, gx);
141
142 // calculate navmesh tile location
143 dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId());
144 dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMeshQuery(handler->GetSession()->GetPlayer()->GetMapId(), player->GetInstanceId());
145 if (!navmesh || !navmeshquery)
146 {
147 handler->PSendSysMessage("NavMesh not loaded for current map.");
148 return true;
149 }
150
151 float const* min = navmesh->getParams()->orig;
152 float x, y, z;
153 player->GetPosition(x, y, z);
154 float location[VERTEX_SIZE] = {y, z, x};
155 float extents[VERTEX_SIZE] = {3.0f, 5.0f, 3.0f};
156
157 int32 tilex = int32((y - min[0]) / SIZE_OF_GRIDS);
158 int32 tiley = int32((x - min[2]) / SIZE_OF_GRIDS);
159
160 handler->PSendSysMessage("Calc [{}, {}]", tilex, tiley);
161
162 // navmesh poly -> navmesh tile location
164 dtPolyRef polyRef = INVALID_POLYREF;
165 if (dtStatusFailed(navmeshquery->findNearestPoly(location, extents, &filter, &polyRef, nullptr)))
166 {
167 handler->PSendSysMessage("Dt [??,??] (invalid poly, probably no tile loaded)");
168 return true;
169 }
170
171 if (polyRef == INVALID_POLYREF)
172 handler->PSendSysMessage("Dt [??, ??] (invalid poly, probably no tile loaded)");
173 else
174 {
175 dtMeshTile const* tile;
176 dtPoly const* poly;
177 if (dtStatusSucceed(navmesh->getTileAndPolyByRef(polyRef, &tile, &poly)))
178 {
179 if (tile)
180 {
181 handler->PSendSysMessage("Dt [{},{}]", tile->header->x, tile->header->y);
182 return false;
183 }
184 }
185
186 handler->PSendSysMessage("Dt [??,??] (no tile loaded)");
187 }
188
189 return true;
190 }
#define SIZE_OF_GRIDS
Definition: MapDefines.h:25
#define VERTEX_SIZE
Definition: PathGenerator.h:41
#define INVALID_POLYREF
Definition: PathGenerator.h:42
Definition: DetourExtended.h:11
float GetPositionX() const
Definition: Position.h:116
void GetPosition(float &x, float &y) const
Definition: Position.h:121
float GetPositionY() const
Definition: Position.h:117
Definition: Player.h:1064

References MMAP::MMapFactory::createOrGetMMapMgr(), WorldObject::GetInstanceId(), WorldLocation::GetMapId(), MMAP::MMapMgr::GetNavMesh(), MMAP::MMapMgr::GetNavMeshQuery(), WorldSession::GetPlayer(), Position::GetPosition(), Position::GetPositionX(), Position::GetPositionY(), ChatHandler::GetSession(), INVALID_POLYREF, ChatHandler::PSendSysMessage(), SIZE_OF_GRIDS, and VERTEX_SIZE.

Referenced by GetCommands().

◆ HandleMmapPathCommand()

static bool mmaps_commandscript::HandleMmapPathCommand ( ChatHandler handler,
Optional< std::string >  param 
)
inlinestatic
63 {
64 if (!MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId()))
65 {
66 handler->PSendSysMessage("NavMesh not loaded for current map.");
67 return true;
68 }
69
70 handler->PSendSysMessage("mmap path:");
71
72 // units
73 Player* player = handler->GetSession()->GetPlayer();
74 Unit* target = handler->getSelectedUnit();
75 if (!player || !target)
76 {
77 handler->PSendSysMessage("Invalid target/source selection.");
78 return true;
79 }
80
81 bool useStraightPath = false;
82 bool useRaycast = false;
83 if (param)
84 {
85 auto paramValue = param.value();
86 if (paramValue.starts_with("true"))
87 {
88 useStraightPath = true;
89 }
90
91 if (paramValue.starts_with("line") || paramValue.starts_with("ray") || paramValue.starts_with("raycast"))
92 {
93 useRaycast = true;
94 }
95 }
96
97 // unit locations
98 float x, y, z;
99 player->GetPosition(x, y, z);
100
101 // path
102 PathGenerator path(target);
103 path.SetUseStraightPath(useStraightPath);
104 path.SetUseRaycast(useRaycast);
105 bool result = path.CalculatePath(x, y, z, false);
106
107 Movement::PointsArray const& pointPath = path.GetPath();
108 handler->PSendSysMessage("{}'s path to {}:", target->GetName(), player->GetName());
109 handler->PSendSysMessage("Building: {}", useStraightPath ? "StraightPath" : useRaycast ? "Raycast" : "SmoothPath");
110 handler->PSendSysMessage("Result: {} - Length: {} - Type: {}", (result ? "true" : "false"), pointPath.size(), path.GetPathType());
111
112 G3D::Vector3 const& start = path.GetStartPosition();
113 G3D::Vector3 const& end = path.GetEndPosition();
114 G3D::Vector3 const& actualEnd = path.GetActualEndPosition();
115
116 handler->PSendSysMessage("StartPosition ({}, {}, {})", start.x, start.y, start.z);
117 handler->PSendSysMessage("EndPosition ({}, {}, {})", end.x, end.y, end.z);
118 handler->PSendSysMessage("ActualEndPosition ({}, {}, {})", actualEnd.x, actualEnd.y, actualEnd.z);
119
120 if (!player->IsGameMaster())
121 handler->PSendSysMessage("Enable GM mode to see the path points.");
122
123 for (auto i : pointPath)
124 player->SummonCreature(VISUAL_WAYPOINT, i.x, i.y, i.z, 0, TEMPSUMMON_TIMED_DESPAWN, 9000);
125
126 return true;
127 }
@ TEMPSUMMON_TIMED_DESPAWN
Definition: Object.h:47
#define VISUAL_WAYPOINT
Definition: MotionMaster.h:34
std::vector< Vector3 > PointsArray
Definition: MoveSplineInitArgs.h:28
Unit * getSelectedUnit() const
Definition: Chat.cpp:385
TempSummon * SummonCreature(uint32 id, const Position &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0, SummonPropertiesEntry const *properties=nullptr, bool visibleBySummonerOnly=false) const
Definition: Object.cpp:2355
std::string const & GetName() const
Definition: Object.h:458
bool IsGameMaster() const
Definition: Player.h:1158
Definition: Unit.h:630
Definition: PathGenerator.h:59

References PathGenerator::CalculatePath(), MMAP::MMapFactory::createOrGetMMapMgr(), PathGenerator::GetActualEndPosition(), PathGenerator::GetEndPosition(), WorldLocation::GetMapId(), WorldObject::GetName(), PathGenerator::GetPath(), PathGenerator::GetPathType(), WorldSession::GetPlayer(), Position::GetPosition(), ChatHandler::getSelectedUnit(), ChatHandler::GetSession(), PathGenerator::GetStartPosition(), Player::IsGameMaster(), ChatHandler::PSendSysMessage(), PathGenerator::SetUseRaycast(), PathGenerator::SetUseStraightPath(), WorldObject::SummonCreature(), TEMPSUMMON_TIMED_DESPAWN, and VISUAL_WAYPOINT.

Referenced by GetCommands().

◆ HandleMmapStatsCommand()

static bool mmaps_commandscript::HandleMmapStatsCommand ( ChatHandler handler)
inlinestatic
218 {
219 handler->PSendSysMessage("mmap stats:");
220 //handler->PSendSysMessage(" global mmap pathfinding is %sabled", DisableMgr::IsPathfindingEnabled(mapId) ? "en" : "dis");
221
223 handler->PSendSysMessage(" {} maps loaded with {} tiles overall", manager->getLoadedMapsCount(), manager->getLoadedTilesCount());
224
225 dtNavMesh const* navmesh = manager->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId());
226 if (!navmesh)
227 {
228 handler->PSendSysMessage("NavMesh not loaded for current map.");
229 return true;
230 }
231
232 uint32 tileCount = 0;
233 uint32 nodeCount = 0;
234 uint32 polyCount = 0;
235 uint32 vertCount = 0;
236 uint32 triCount = 0;
237 uint32 triVertCount = 0;
238 uint32 dataSize = 0;
239 for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
240 {
241 dtMeshTile const* tile = navmesh->getTile(i);
242 if (!tile || !tile->header)
243 continue;
244
245 tileCount++;
246 nodeCount += tile->header->bvNodeCount;
247 polyCount += tile->header->polyCount;
248 vertCount += tile->header->vertCount;
249 triCount += tile->header->detailTriCount;
250 triVertCount += tile->header->detailVertCount;
251 dataSize += tile->dataSize;
252 }
253
254 handler->PSendSysMessage("Navmesh stats:");
255 handler->PSendSysMessage(" {} tiles loaded", tileCount);
256 handler->PSendSysMessage(" {} BVTree nodes", nodeCount);
257 handler->PSendSysMessage(" {} polygons ({} vertices)", polyCount, vertCount);
258 handler->PSendSysMessage(" {} triangles ({} vertices)", triCount, triVertCount);
259 handler->PSendSysMessage(" {} MB of data (not including pointers)", ((float)dataSize / sizeof(unsigned char)) / 1048576);
260
261 return true;
262 }
Definition: MMapMgr.h:74
uint32 getLoadedTilesCount() const
Definition: MMapMgr.h:89
uint32 getLoadedMapsCount() const
Definition: MMapMgr.h:90

References MMAP::MMapFactory::createOrGetMMapMgr(), MMAP::MMapMgr::getLoadedMapsCount(), MMAP::MMapMgr::getLoadedTilesCount(), WorldLocation::GetMapId(), MMAP::MMapMgr::GetNavMesh(), WorldSession::GetPlayer(), ChatHandler::GetSession(), and ChatHandler::PSendSysMessage().

Referenced by GetCommands().

◆ HandleMmapTestArea()

static bool mmaps_commandscript::HandleMmapTestArea ( ChatHandler handler)
inlinestatic
265 {
266 float radius = 40.0f;
267 WorldObject* object = handler->GetSession()->GetPlayer();
268
269 // Get Creatures
270 std::list<Creature*> creatureList;
271 Acore::AnyUnitInObjectRangeCheck go_check(object, radius);
272 Acore::CreatureListSearcher<Acore::AnyUnitInObjectRangeCheck> go_search(object, creatureList, go_check);
273 Cell::VisitGridObjects(object, go_search, radius);
274
275 if (!creatureList.empty())
276 {
277 handler->PSendSysMessage("Found {} Creatures.", creatureList.size());
278
279 uint32 paths = 0;
280 uint32 uStartTime = getMSTime();
281
282 float gx, gy, gz;
283 object->GetPosition(gx, gy, gz);
284 for (std::list<Creature*>::iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr)
285 {
286 PathGenerator path(*itr);
287 path.CalculatePath(gx, gy, gz);
288 ++paths;
289 }
290
291 uint32 uPathLoadTime = getMSTimeDiff(uStartTime, getMSTime());
292 handler->PSendSysMessage("Generated {} paths in {} ms", paths, uPathLoadTime);
293 }
294 else
295 handler->PSendSysMessage("No creatures in {} yard range.", radius);
296
297 return true;
298 }
uint32 getMSTime()
Definition: Timer.h:103
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition: Timer.h:110
Definition: Object.h:405
static void VisitGridObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:178
Definition: GridNotifiers.h:473
Definition: GridNotifiers.h:1036

References PathGenerator::CalculatePath(), getMSTime(), getMSTimeDiff(), WorldSession::GetPlayer(), ChatHandler::GetSession(), ChatHandler::PSendSysMessage(), and Cell::VisitGridObjects().

Referenced by GetCommands().