TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mmaps_commandscript Class Reference

Public Member Functions

 mmaps_commandscript ()
 
std::vector< ChatCommandGetCommands () const override
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

Static Public Member Functions

static bool HandleMmapPathCommand (ChatHandler *handler, char const *args)
 
static bool HandleMmapLocCommand (ChatHandler *handler, char const *)
 
static bool HandleMmapLoadedTilesCommand (ChatHandler *handler, char const *)
 
static bool HandleMmapStatsCommand (ChatHandler *handler, char const *)
 
static bool HandleMmapTestArea (ChatHandler *handler, char const *)
 

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 ()
 

Constructor & Destructor Documentation

mmaps_commandscript::mmaps_commandscript ( )
inline
43 : CommandScript("mmaps_commandscript") { }
CommandScript(const char *name)
Definition: ScriptMgr.cpp:1616

Member Function Documentation

std::vector<ChatCommand> mmaps_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

46  {
47  static std::vector<ChatCommand> mmapCommandTable =
48  {
53  { "testarea", rbac::RBAC_PERM_COMMAND_MMAP_TESTAREA, false, &HandleMmapTestArea, "" },
54  };
55 
56  static std::vector<ChatCommand> commandTable =
57  {
58  { "mmap", rbac::RBAC_PERM_COMMAND_MMAP, true, NULL, "", mmapCommandTable },
59  };
60  return commandTable;
61  }
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: RBAC.h:443
static bool HandleMmapLoadedTilesCommand(ChatHandler *handler, char const *)
Definition: cs_mmaps.cpp:186
static bool HandleMmapLocCommand(ChatHandler *handler, char const *)
Definition: cs_mmaps.cpp:123
Definition: RBAC.h:445
static bool HandleMmapStatsCommand(ChatHandler *handler, char const *)
Definition: cs_mmaps.cpp:211
static bool HandleMmapTestArea(ChatHandler *handler, char const *)
Definition: cs_mmaps.cpp:259
Definition: RBAC.h:446
static bool HandleMmapPathCommand(ChatHandler *handler, char const *args)
Definition: cs_mmaps.cpp:63

+ Here is the call graph for this function:

static bool mmaps_commandscript::HandleMmapLoadedTilesCommand ( ChatHandler handler,
char const  
)
inlinestatic
187  {
188  uint32 mapid = handler->GetSession()->GetPlayer()->GetMapId();
189  dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(mapid, handler->GetSession()->GetPlayer()->GetTerrainSwaps());
190  dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMeshQuery(mapid, handler->GetSession()->GetPlayer()->GetInstanceId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps());
191  if (!navmesh || !navmeshquery)
192  {
193  handler->PSendSysMessage("NavMesh not loaded for current map.");
194  return true;
195  }
196 
197  handler->PSendSysMessage("mmap loadedtiles:");
198 
199  for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
200  {
201  dtMeshTile const* tile = navmesh->getTile(i);
202  if (!tile || !tile->header)
203  continue;
204 
205  handler->PSendSysMessage("[%02i, %02i]", tile->header->x, tile->header->y);
206  }
207 
208  return true;
209  }
dtMeshHeader * header
The tile header.
Definition: DetourNavMesh.h:284
Player * GetPlayer() const
Definition: WorldSession.h:927
dtNavMesh const * GetNavMesh(uint32 mapId, TerrainSet swaps)
Definition: MMapManager.cpp:399
Definition: DetourNavMesh.h:323
dtNavMeshQuery const * GetNavMeshQuery(uint32 mapId, uint32 instanceId, TerrainSet swaps)
Definition: MMapManager.cpp:408
int x
The x-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:251
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
const dtMeshTile * getTile(int i) const
Definition: DetourNavMesh.cpp:1102
WorldSession * GetSession()
Definition: Chat.h:59
static MMapManager * createOrGetMMapManager()
Definition: MMapFactory.cpp:28
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: DetourNavMesh.h:279
int y
The y-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:252
Definition: DetourNavMeshQuery.h:153
int getMaxTiles() const
Definition: DetourNavMesh.cpp:1092

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool mmaps_commandscript::HandleMmapLocCommand ( ChatHandler handler,
char const  
)
inlinestatic
124  {
125  handler->PSendSysMessage("mmap tileloc:");
126 
127  // grid tile location
128  Player* player = handler->GetSession()->GetPlayer();
129 
130  int32 gx = 32 - player->GetPositionX() / SIZE_OF_GRIDS;
131  int32 gy = 32 - player->GetPositionY() / SIZE_OF_GRIDS;
132 
133  handler->PSendSysMessage("%03u%02i%02i.mmtile", player->GetMapId(), gx, gy);
134  handler->PSendSysMessage("gridloc [%i, %i]", gy, gx);
135 
136  // calculate navmesh tile location
137  dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps());
138  dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMeshQuery(handler->GetSession()->GetPlayer()->GetMapId(), player->GetInstanceId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps());
139  if (!navmesh || !navmeshquery)
140  {
141  handler->PSendSysMessage("NavMesh not loaded for current map.");
142  return true;
143  }
144 
145  float const* min = navmesh->getParams()->orig;
146  float x, y, z;
147  player->GetPosition(x, y, z);
148  float location[VERTEX_SIZE] = { y, z, x };
149  float extents[VERTEX_SIZE] = { 3.0f, 5.0f, 3.0f };
150 
151  int32 tilex = int32((y - min[0]) / SIZE_OF_GRIDS);
152  int32 tiley = int32((x - min[2]) / SIZE_OF_GRIDS);
153 
154  handler->PSendSysMessage("Calc [%02i, %02i]", tilex, tiley);
155 
156  // navmesh poly -> navmesh tile location
157  dtQueryFilter filter = dtQueryFilter();
158  dtPolyRef polyRef = INVALID_POLYREF;
159  if (dtStatusFailed(navmeshquery->findNearestPoly(location, extents, &filter, &polyRef, NULL)))
160  {
161  handler->PSendSysMessage("Dt [??,??] (invalid poly, probably no tile loaded)");
162  return true;
163  }
164 
165  if (polyRef == INVALID_POLYREF)
166  handler->PSendSysMessage("Dt [??, ??] (invalid poly, probably no tile loaded)");
167  else
168  {
169  dtMeshTile const* tile;
170  dtPoly const* poly;
171  if (dtStatusSucceed(navmesh->getTileAndPolyByRef(polyRef, &tile, &poly)))
172  {
173  if (tile)
174  {
175  handler->PSendSysMessage("Dt [%02i,%02i]", tile->header->x, tile->header->y);
176  return false;
177  }
178  }
179 
180  handler->PSendSysMessage("Dt [??,??] (no tile loaded)");
181  }
182 
183  return true;
184  }
uint64_d dtPolyRef
Definition: DetourNavMesh.h:49
dtMeshHeader * header
The tile header.
Definition: DetourNavMesh.h:284
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
float orig[3]
The world space origin of the navigation mesh's tile space. [(x, y, z)].
Definition: DetourNavMesh.h:314
const dtNavMeshParams * getParams() const
The navigation mesh initialization params.
Definition: DetourNavMesh.cpp:286
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
Definition: DetourNavMeshQuery.h:35
dtNavMesh const * GetNavMesh(uint32 mapId, TerrainSet swaps)
Definition: MMapManager.cpp:399
Definition: DetourNavMesh.h:323
dtNavMeshQuery const * GetNavMeshQuery(uint32 mapId, uint32 instanceId, TerrainSet swaps)
Definition: MMapManager.cpp:408
T min(const T &x, const T &y)
Definition: g3dmath.h:305
#define INVALID_POLYREF
Definition: PathGenerator.h:39
Definition: DetourNavMesh.h:153
int x
The x-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:251
bool dtStatusSucceed(dtStatus status)
Definition: DetourStatus.h:41
G3D::int16 z
Definition: Vector3int16.h:46
int32_t int32
Definition: Define.h:146
dtStatus getTileAndPolyByRef(const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const
Definition: DetourNavMesh.cpp:1113
G3D::int16 y
Definition: Vector2int16.h:38
bool dtStatusFailed(dtStatus status)
Definition: DetourStatus.h:47
dtStatus findNearestPoly(const float *center, const float *extents, const dtQueryFilter *filter, dtPolyRef *nearestRef, float *nearestPt) const
Definition: DetourNavMeshQuery.cpp:710
int32_t int32
Definition: g3dmath.h:167
WorldSession * GetSession()
Definition: Chat.h:59
static MMapManager * createOrGetMMapManager()
Definition: MMapFactory.cpp:28
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
#define VERTEX_SIZE
Definition: PathGenerator.h:38
G3D::int16 x
Definition: Vector2int16.h:37
Definition: DetourNavMesh.h:279
int y
The y-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:252
Definition: DetourNavMeshQuery.h:153

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool mmaps_commandscript::HandleMmapPathCommand ( ChatHandler handler,
char const args 
)
inlinestatic
64  {
65  if (!MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps()))
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  char* para = strtok((char*)args, " ");
83 
84  bool useStraightPath = false;
85  if (para && strcmp(para, "true") == 0)
86  useStraightPath = true;
87 
88  bool useStraightLine = false;
89  if (para && strcmp(para, "line") == 0)
90  useStraightLine = true;
91 
92  // unit locations
93  float x, y, z;
94  player->GetPosition(x, y, z);
95 
96  // path
97  PathGenerator path(target);
98  path.SetUseStraightPath(useStraightPath);
99  bool result = path.CalculatePath(x, y, z, false, useStraightLine);
100 
101  Movement::PointsArray const& pointPath = path.GetPath();
102  handler->PSendSysMessage("%s's path to %s:", target->GetName().c_str(), player->GetName().c_str());
103  handler->PSendSysMessage("Building: %s", useStraightPath ? "StraightPath" : useStraightLine ? "Raycast" : "SmoothPath");
104  handler->PSendSysMessage("Result: %s - Length: %zu - Type: %u", (result ? "true" : "false"), pointPath.size(), path.GetPathType());
105 
106  G3D::Vector3 const &start = path.GetStartPosition();
107  G3D::Vector3 const &end = path.GetEndPosition();
108  G3D::Vector3 const &actualEnd = path.GetActualEndPosition();
109 
110  handler->PSendSysMessage("StartPosition (%.3f, %.3f, %.3f)", start.x, start.y, start.z);
111  handler->PSendSysMessage("EndPosition (%.3f, %.3f, %.3f)", end.x, end.y, end.z);
112  handler->PSendSysMessage("ActualEndPosition (%.3f, %.3f, %.3f)", actualEnd.x, actualEnd.y, actualEnd.z);
113 
114  if (!player->IsGameMaster())
115  handler->PSendSysMessage("Enable GM mode to see the path points.");
116 
117  for (uint32 i = 0; i < pointPath.size(); ++i)
118  player->SummonCreature(VISUAL_WAYPOINT, pointPath[i].x, pointPath[i].y, pointPath[i].z, 0, TEMPSUMMON_TIMED_DESPAWN, 9000);
119 
120  return true;
121  }
float x
Definition: Vector3.h:62
Unit * getSelectedUnit()
Definition: Chat.cpp:591
std::string const & GetName() const
Definition: Object.h:479
Player * GetPlayer() const
Definition: WorldSession.h:927
float y
Definition: Vector3.h:62
Definition: Vector3.h:58
Definition: Object.h:56
G3D::int16 z
Definition: Vector3int16.h:46
std::vector< Vector3 > PointsArray
Definition: MoveSplineInitArgs.h:30
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
Definition: PathGenerator.h:52
float z
Definition: Vector3.h:62
WorldSession * GetSession()
Definition: Chat.h:59
static MMapManager * createOrGetMMapManager()
Definition: MMapFactory.cpp:28
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
G3D::int16 x
Definition: Vector2int16.h:37
#define VISUAL_WAYPOINT
Definition: MotionMaster.h:32
Definition: Unit.h:1305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool mmaps_commandscript::HandleMmapStatsCommand ( ChatHandler handler,
char const  
)
inlinestatic
212  {
213  uint32 mapId = handler->GetSession()->GetPlayer()->GetMapId();
214  handler->PSendSysMessage("mmap stats:");
215  handler->PSendSysMessage(" global mmap pathfinding is %sabled", DisableMgr::IsPathfindingEnabled(mapId) ? "en" : "dis");
216 
218  handler->PSendSysMessage(" %u maps loaded with %u tiles overall", manager->getLoadedMapsCount(), manager->getLoadedTilesCount());
219 
220  dtNavMesh const* navmesh = manager->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps());
221  if (!navmesh)
222  {
223  handler->PSendSysMessage("NavMesh not loaded for current map.");
224  return true;
225  }
226 
227  uint32 tileCount = 0;
228  uint32 nodeCount = 0;
229  uint32 polyCount = 0;
230  uint32 vertCount = 0;
231  uint32 triCount = 0;
232  uint32 triVertCount = 0;
233  uint32 dataSize = 0;
234  for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
235  {
236  dtMeshTile const* tile = navmesh->getTile(i);
237  if (!tile || !tile->header)
238  continue;
239 
240  tileCount++;
241  nodeCount += tile->header->bvNodeCount;
242  polyCount += tile->header->polyCount;
243  vertCount += tile->header->vertCount;
244  triCount += tile->header->detailTriCount;
245  triVertCount += tile->header->detailVertCount;
246  dataSize += tile->dataSize;
247  }
248 
249  handler->PSendSysMessage("Navmesh stats:");
250  handler->PSendSysMessage(" %u tiles loaded", tileCount);
251  handler->PSendSysMessage(" %u BVTree nodes", nodeCount);
252  handler->PSendSysMessage(" %u polygons (%u vertices)", polyCount, vertCount);
253  handler->PSendSysMessage(" %u triangles (%u vertices)", triCount, triVertCount);
254  handler->PSendSysMessage(" %.2f MB of data (not including pointers)", ((float)dataSize / sizeof(unsigned char)) / 1048576);
255 
256  return true;
257  }
dtMeshHeader * header
The tile header.
Definition: DetourNavMesh.h:284
bool IsPathfindingEnabled(uint32 mapId)
Definition: DisableMgr.cpp:380
Player * GetPlayer() const
Definition: WorldSession.h:927
uint32 getLoadedMapsCount() const
Definition: MMapManager.h:110
dtNavMesh const * GetNavMesh(uint32 mapId, TerrainSet swaps)
Definition: MMapManager.cpp:399
Definition: DetourNavMesh.h:323
int polyCount
The number of polygons in the tile.
Definition: DetourNavMesh.h:255
int bvNodeCount
The number of bounding volume nodes. (Zero if bounding volumes are disabled.)
Definition: DetourNavMesh.h:264
int detailVertCount
The number of unique vertices in the detail mesh. (In addition to the polygon vertices.)
Definition: DetourNavMesh.h:261
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
int dataSize
Size of the tile data.
Definition: DetourNavMesh.h:303
uint32 getLoadedTilesCount() const
Definition: MMapManager.h:109
Definition: MMapManager.h:93
const dtMeshTile * getTile(int i) const
Definition: DetourNavMesh.cpp:1102
int detailTriCount
The number of triangles in the detail mesh.
Definition: DetourNavMesh.h:263
WorldSession * GetSession()
Definition: Chat.h:59
static MMapManager * createOrGetMMapManager()
Definition: MMapFactory.cpp:28
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: DetourNavMesh.h:279
int vertCount
The number of vertices in the tile.
Definition: DetourNavMesh.h:256
int getMaxTiles() const
Definition: DetourNavMesh.cpp:1092

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool mmaps_commandscript::HandleMmapTestArea ( ChatHandler handler,
char const  
)
inlinestatic
260  {
261  float radius = 40.0f;
262  WorldObject* object = handler->GetSession()->GetPlayer();
263 
264  CellCoord pair(Trinity::ComputeCellCoord(object->GetPositionX(), object->GetPositionY()));
265  Cell cell(pair);
266  cell.SetNoCreate();
267 
268  std::list<Creature*> creatureList;
269 
270  Trinity::AnyUnitInObjectRangeCheck go_check(object, radius);
271  Trinity::CreatureListSearcher<Trinity::AnyUnitInObjectRangeCheck> go_search(object, creatureList, go_check);
273 
274  // Get Creatures
275  cell.Visit(pair, go_visit, *(object->GetMap()), *object, radius);
276 
277  if (!creatureList.empty())
278  {
279  handler->PSendSysMessage("Found %zu Creatures.", creatureList.size());
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  }
Definition: TypeContainerVisitor.h:32
Map * GetMap() const
Definition: Object.h:543
Definition: GridNotifiers.h:885
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition: Timer.h:33
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:193
uint32 getMSTime()
Definition: Timer.h:24
Definition: Object.h:423
Player * GetPlayer() const
Definition: WorldSession.h:927
Definition: TypeContainer.h:86
Definition: GridNotifiers.h:459
uint32_t uint32
Definition: Define.h:150
Definition: PathGenerator.h:52
Definition: Cell.h:49
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
float GetPositionX() const
Definition: Position.h:104

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


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