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
 
- 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
43: CommandScript("mmaps_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable mmaps_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

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

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

◆ HandleMmapLoadedTilesCommand()

static bool mmaps_commandscript::HandleMmapLoadedTilesCommand ( ChatHandler handler)
inlinestatic
227 {
228 uint32 mapid = handler->GetSession()->GetPlayer()->GetMapId();
229 dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(mapid);
230 dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMeshQuery(mapid, handler->GetSession()->GetPlayer()->GetInstanceId());
231 if (!navmesh || !navmeshquery)
232 {
233 handler->PSendSysMessage("NavMesh not loaded for current map.");
234 return true;
235 }
236
237 handler->PSendSysMessage("mmap loadedtiles:");
238
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 handler->PSendSysMessage("[{}, {}]", tile->header->x, tile->header->y);
246 }
247
248 return true;
249 }
std::int32_t int32
Definition Define.h:103
std::uint32_t uint32
Definition Define.h:107
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:211
WorldSession * GetSession()
Definition Chat.h:242
static MMapMgr * createOrGetMMapMgr()
Definition MMapFactory.cpp:27
dtNavMesh const * GetNavMesh(uint32 mapId)
Definition MMapMgr.cpp:303
dtNavMeshQuery const * GetNavMeshQuery(uint32 mapId, uint32 instanceId)
Definition MMapMgr.cpp:314
uint32 GetMapId() const
Definition Position.h:281
uint32 GetInstanceId() const
Definition Object.h:510
Player * GetPlayer() const
Definition WorldSession.h:424

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
131 {
132 handler->PSendSysMessage("mmap tileloc:");
133
134 // grid tile location
135 Player* player = handler->GetSession()->GetPlayer();
136
137 GridCoord const gridCoord = Acore::ComputeGridCoord(player->GetPositionX(), player->GetPositionY());
138
139 handler->PSendSysMessage("{}{}{}.mmtile", player->GetMapId(), gridCoord.x_coord, gridCoord.y_coord);
140
141 std::string fileName = Acore::StringFormat(MMAP::TILE_FILE_NAME_FORMAT, sConfigMgr->GetOption<std::string>("DataDir", "."), player->GetMapId(), gridCoord.x_coord, gridCoord.y_coord);
142 FILE* file = fopen(fileName.c_str(), "rb");
143 if (!file)
144 {
145 LOG_DEBUG("maps", "MMAP:loadMap: Could not open mmtile file '{}'", fileName);
146 return false;
147 }
148
149 // read header
150 MmapTileHeader fileHeader;
151 if (fread(&fileHeader, sizeof(MmapTileHeader), 1, file) != 1 || fileHeader.mmapMagic != MMAP_MAGIC)
152 {
153 LOG_ERROR("maps", "MMAP:loadMap: Bad header in mmap {:03}{:02}{:02}.mmtile", player->GetMapId(), gridCoord.x_coord, gridCoord.y_coord);
154 fclose(file);
155 return false;
156 }
157 fclose(file);
158 handler->PSendSysMessage("Recast config used:");
159 handler->PSendSysMessage("- walkableSlopeAngle: {}", fileHeader.recastConfig.walkableSlopeAngle);
160
161 const float cellHeight = fileHeader.recastConfig.cellSizeVertical;
162 handler->PSendSysMessage("- walkableHeight: {} ({} units)", fileHeader.recastConfig.walkableHeight * cellHeight, fileHeader.recastConfig.walkableHeight);
163 handler->PSendSysMessage("- walkableClimb: {} ({} units)", fileHeader.recastConfig.walkableClimb * cellHeight, fileHeader.recastConfig.walkableClimb);
164 handler->PSendSysMessage("- walkableRadius: {} ({} units)", fileHeader.recastConfig.walkableRadius * cellHeight, fileHeader.recastConfig.walkableRadius);
165
166 handler->PSendSysMessage("- maxSimplificationError: {}", fileHeader.recastConfig.maxSimplificationError);
167 handler->PSendSysMessage("- vertexPerMapEdge: {}", fileHeader.recastConfig.vertexPerMapEdge);
168 handler->PSendSysMessage("- vertexPerTileEdge: {}", fileHeader.recastConfig.vertexPerTileEdge);
169 handler->PSendSysMessage("- tilesPerMapEdge: {}", fileHeader.recastConfig.tilesPerMapEdge);
170 handler->PSendSysMessage("- baseUnitDim: {}", fileHeader.recastConfig.baseUnitDim);
171 handler->PSendSysMessage("- cellSizeHorizontal: {}", fileHeader.recastConfig.cellSizeHorizontal);
172 handler->PSendSysMessage("- cellSizeVertical: {}", fileHeader.recastConfig.cellSizeVertical);
173
174 handler->PSendSysMessage("gridloc [{}, {}]", gridCoord.x_coord, gridCoord.y_coord);
175
176 // calculate navmesh tile location
177 dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId());
178 dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMeshQuery(handler->GetSession()->GetPlayer()->GetMapId(), player->GetInstanceId());
179 if (!navmesh || !navmeshquery)
180 {
181 handler->PSendSysMessage("NavMesh not loaded for current map.");
182 return true;
183 }
184
185 float const* min = navmesh->getParams()->orig;
186 float x, y, z;
187 player->GetPosition(x, y, z);
188 float location[VERTEX_SIZE] = {y, z, x};
189 float extents[VERTEX_SIZE] = {3.0f, 5.0f, 3.0f};
190
191 int32 tilex = int32((y - min[0]) / SIZE_OF_GRIDS);
192 int32 tiley = int32((x - min[2]) / SIZE_OF_GRIDS);
193
194 handler->PSendSysMessage("Calc [{}, {}]", tilex, tiley);
195
196 // navmesh poly -> navmesh tile location
198 dtPolyRef polyRef = INVALID_POLYREF;
199 if (dtStatusFailed(navmeshquery->findNearestPoly(location, extents, &filter, &polyRef, nullptr)))
200 {
201 handler->PSendSysMessage("Dt [??,??] (invalid poly, probably no tile loaded)");
202 return true;
203 }
204
205 if (polyRef == INVALID_POLYREF)
206 handler->PSendSysMessage("Dt [??, ??] (invalid poly, probably no tile loaded)");
207 else
208 {
209 dtMeshTile const* tile;
210 dtPoly const* poly;
211 if (dtStatusSucceed(navmesh->getTileAndPolyByRef(polyRef, &tile, &poly)))
212 {
213 if (tile)
214 {
215 handler->PSendSysMessage("Dt [{},{}]", tile->header->x, tile->header->y);
216 return false;
217 }
218 }
219
220 handler->PSendSysMessage("Dt [??,??] (no tile loaded)");
221 }
222
223 return true;
224 }
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
#define SIZE_OF_GRIDS
Definition MapDefines.h:26
#define MMAP_MAGIC
Definition MapDefines.h:28
#define VERTEX_SIZE
Definition PathGenerator.h:41
#define INVALID_POLYREF
Definition PathGenerator.h:42
Definition Player.h:1071
Definition DetourExtended.h:11
#define sConfigMgr
Definition Config.h:74
GridCoord ComputeGridCoord(float x, float y)
Definition GridDefines.h:185
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition StringFormat.h:34
static char const *const TILE_FILE_NAME_FORMAT
Definition MMapMgr.h:43
Definition GridDefines.h:88
uint32 x_coord
Definition GridDefines.h:155
uint32 y_coord
Definition GridDefines.h:156
Definition MapDefines.h:65
MmapTileRecastConfig recastConfig
Definition MapDefines.h:73
uint32 mmapMagic
Definition MapDefines.h:66
uint8 walkableRadius
Definition MapDefines.h:35
float cellSizeHorizontal
Definition MapDefines.h:44
float baseUnitDim
Definition MapDefines.h:43
uint32 tilesPerMapEdge
Definition MapDefines.h:42
uint32 vertexPerMapEdge
Definition MapDefines.h:40
uint8 walkableClimb
Definition MapDefines.h:37
uint32 vertexPerTileEdge
Definition MapDefines.h:41
float cellSizeVertical
Definition MapDefines.h:45
uint8 walkableHeight
Definition MapDefines.h:36
float walkableSlopeAngle
Definition MapDefines.h:33
float maxSimplificationError
Definition MapDefines.h:46
float GetPositionX() const
Definition Position.h:121
void GetPosition(float &x, float &y) const
Definition Position.h:126
float GetPositionY() const
Definition Position.h:122

References MmapTileRecastConfig::baseUnitDim, MmapTileRecastConfig::cellSizeHorizontal, MmapTileRecastConfig::cellSizeVertical, Acore::ComputeGridCoord(), 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, LOG_DEBUG, LOG_ERROR, MmapTileRecastConfig::maxSimplificationError, MMAP_MAGIC, MmapTileHeader::mmapMagic, ChatHandler::PSendSysMessage(), MmapTileHeader::recastConfig, sConfigMgr, SIZE_OF_GRIDS, Acore::StringFormat(), MMAP::TILE_FILE_NAME_FORMAT, MmapTileRecastConfig::tilesPerMapEdge, VERTEX_SIZE, MmapTileRecastConfig::vertexPerMapEdge, MmapTileRecastConfig::vertexPerTileEdge, MmapTileRecastConfig::walkableClimb, MmapTileRecastConfig::walkableHeight, MmapTileRecastConfig::walkableRadius, MmapTileRecastConfig::walkableSlopeAngle, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

Referenced by GetCommands().

◆ HandleMmapPathCommand()

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

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
252 {
253 handler->PSendSysMessage("mmap stats:");
254 //handler->PSendSysMessage(" global mmap pathfinding is {}abled", sDisableMgr->IsPathfindingEnabled(mapId) ? "en" : "dis");
256 handler->PSendSysMessage(" {} maps loaded with {} tiles overall", manager->getLoadedMapsCount(), manager->getLoadedTilesCount());
257
258 dtNavMesh const* navmesh = manager->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId());
259 if (!navmesh)
260 {
261 handler->PSendSysMessage("NavMesh not loaded for current map.");
262 return true;
263 }
264
265 uint32 tileCount = 0;
266 uint32 nodeCount = 0;
267 uint32 polyCount = 0;
268 uint32 vertCount = 0;
269 uint32 triCount = 0;
270 uint32 triVertCount = 0;
271 uint32 dataSize = 0;
272 for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
273 {
274 dtMeshTile const* tile = navmesh->getTile(i);
275 if (!tile || !tile->header)
276 continue;
277
278 tileCount++;
279 nodeCount += tile->header->bvNodeCount;
280 polyCount += tile->header->polyCount;
281 vertCount += tile->header->vertCount;
282 triCount += tile->header->detailTriCount;
283 triVertCount += tile->header->detailVertCount;
284 dataSize += tile->dataSize;
285 }
286
287 handler->PSendSysMessage("Navmesh stats:");
288 handler->PSendSysMessage(" {} tiles loaded", tileCount);
289 handler->PSendSysMessage(" {} BVTree nodes", nodeCount);
290 handler->PSendSysMessage(" {} polygons ({} vertices)", polyCount, vertCount);
291 handler->PSendSysMessage(" {} triangles ({} vertices)", triCount, triVertCount);
292 handler->PSendSysMessage(" {} MB of data (not including pointers)", ((float)dataSize / sizeof(unsigned char)) / 1048576);
293
294 return true;
295 }
Definition MMapMgr.h:77
uint32 getLoadedTilesCount() const
Definition MMapMgr.h:92
uint32 getLoadedMapsCount() const
Definition MMapMgr.h:93

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
298 {
299 float radius = 40.0f;
300 WorldObject* object = handler->GetSession()->GetPlayer();
301
302 // Get Creatures
303 std::list<Creature*> creatureList;
304 Acore::AnyUnitInObjectRangeCheck go_check(object, radius);
305 Acore::CreatureListSearcher<Acore::AnyUnitInObjectRangeCheck> go_search(object, creatureList, go_check);
306 Cell::VisitObjects(object, go_search, radius);
307
308 if (!creatureList.empty())
309 {
310 handler->PSendSysMessage("Found {} Creatures.", creatureList.size());
311
312 uint32 paths = 0;
313 uint32 uStartTime = getMSTime();
314
315 float gx, gy, gz;
316 object->GetPosition(gx, gy, gz);
317 for (std::list<Creature*>::iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr)
318 {
319 PathGenerator path(*itr);
320 path.CalculatePath(gx, gy, gz);
321 ++paths;
322 }
323
324 uint32 uPathLoadTime = getMSTimeDiff(uStartTime, getMSTime());
325 handler->PSendSysMessage("Generated {} paths in {} ms", paths, uPathLoadTime);
326 }
327 else
328 handler->PSendSysMessage("No creatures in {} yard range.", radius);
329
330 return true;
331 }
uint32 getMSTime()
Definition Timer.h:103
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition Timer.h:110
Definition GridNotifiers.h:1027
Definition Object.h:472
Definition GridNotifiers.h:464
static void VisitObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:165

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

Referenced by GetCommands().


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