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
 

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)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ mmaps_commandscript()

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

Member Function Documentation

◆ GetCommands()

ChatCommandTable mmaps_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

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

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

◆ HandleMmapLoadedTilesCommand()

static bool mmaps_commandscript::HandleMmapLoadedTilesCommand ( ChatHandler handler)
inlinestatic
195 {
196 uint32 mapid = handler->GetSession()->GetPlayer()->GetMapId();
197 dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMesh(mapid);
198 dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapMgr()->GetNavMeshQuery(mapid, handler->GetSession()->GetPlayer()->GetInstanceId());
199 if (!navmesh || !navmeshquery)
200 {
201 handler->PSendSysMessage("NavMesh not loaded for current map.");
202 return true;
203 }
204
205 handler->PSendSysMessage("mmap loadedtiles:");
206
207 for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
208 {
209 dtMeshTile const* tile = navmesh->getTile(i);
210 if (!tile || !tile->header)
211 continue;
212
213 handler->PSendSysMessage("[%02i, %02i]", tile->header->x, tile->header->y);
214 }
215
216 return true;
217 }
std::int32_t int32
Definition: Define.h:104
std::uint32_t uint32
Definition: Define.h:108
static MMapMgr * createOrGetMMapMgr()
Definition: MMapFactory.cpp:29
dtNavMesh const * GetNavMesh(uint32 mapId)
Definition: MMapMgr.cpp:306
dtNavMeshQuery const * GetNavMeshQuery(uint32 mapId, uint32 instanceId)
Definition: MMapMgr.cpp:317
WorldSession * GetSession()
Definition: Chat.h:139
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60
uint32 GetInstanceId() const
Definition: Object.h:431
uint32 GetMapId() const
Definition: Position.h:276
Player * GetPlayer() const
Definition: WorldSession.h:364

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

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

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(), Acore::StringFormatFmt(), WorldObject::SummonCreature(), TEMPSUMMON_TIMED_DESPAWN, and VISUAL_WAYPOINT.

Referenced by GetCommands().

◆ HandleMmapStatsCommand()

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

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

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

Referenced by GetCommands().