Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
cs_mmaps.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
13
14#include "CellImpl.h"
15#include "Chat.h"
16#include "GridNotifiers.h"
17#include "GridNotifiersImpl.h"
18#include "Map.h"
19#include "MMapFactory.h"
20#include "ObjectMgr.h"
21#include "PathGenerator.h"
22#include "Player.h"
24#include "ScriptMgr.h"
26
28{
29public:
30 mmaps_commandscript() : CommandScript("mmaps_commandscript") { }
31
32 std::vector<ChatCommand> GetCommands() const OVERRIDE
33 {
34 static std::vector<ChatCommand> mmapCommandTable =
35 {
41 };
42
43 static std::vector<ChatCommand> commandTable =
44 {
45 { "mmap", rbac::RBAC_PERM_COMMAND_MMAP, true, NULL, "", mmapCommandTable },
46 };
47 return commandTable;
48 }
49
50 static bool HandleMmapPathCommand(ChatHandler* handler, char const* args)
51 {
53 {
54 handler->PSendSysMessage("NavMesh not loaded for current map.");
55 return true;
56 }
57
58 handler->PSendSysMessage("mmap path:");
59
60 // units
61 Player* player = handler->GetSession()->GetPlayer();
62 Unit* target = handler->getSelectedUnit();
63 if (!player || !target)
64 {
65 handler->PSendSysMessage("Invalid target/source selection.");
66 return true;
67 }
68
69 char* para = strtok((char*)args, " ");
70
71 bool useStraightPath = false;
72 if (para && strcmp(para, "true") == 0)
73 useStraightPath = true;
74
75 // unit locations
76 float x, y, z;
77 player->GetPosition(x, y, z);
78
79 // path
80 PathGenerator path(target);
81 path.SetUseStraightPath(useStraightPath);
82 bool result = path.CalculatePath(x, y, z);
83
84 Movement::PointsArray const& pointPath = path.GetPath();
85 handler->PSendSysMessage("%s's path to %s:", target->GetName().c_str(), player->GetName().c_str());
86 handler->PSendSysMessage("Building: %s", useStraightPath ? "StraightPath" : "SmoothPath");
87 handler->PSendSysMessage("Result: %s - Length: " SIZEFMTD " - Type: %u", (result ? "true" : "false"), pointPath.size(), path.GetPathType());
88
89 G3D::Vector3 const& start = path.GetStartPosition();
90 G3D::Vector3 const& end = path.GetEndPosition();
91 G3D::Vector3 const& actualEnd = path.GetActualEndPosition();
92
93 handler->PSendSysMessage("StartPosition (%.3f, %.3f, %.3f)", start.x, start.y, start.z);
94 handler->PSendSysMessage("EndPosition (%.3f, %.3f, %.3f)", end.x, end.y, end.z);
95 handler->PSendSysMessage("ActualEndPosition (%.3f, %.3f, %.3f)", actualEnd.x, actualEnd.y, actualEnd.z);
96
97 if (!player->IsGameMaster())
98 handler->PSendSysMessage("Enable GM mode to see the path points.");
99
100 for (uint32 i = 0; i < pointPath.size(); ++i)
101 player->SummonCreature(VISUAL_WAYPOINT, pointPath[i].x, pointPath[i].y, pointPath[i].z, 0, TempSummonType::TEMPSUMMON_TIMED_DESPAWN, 9000);
102
103 return true;
104 }
105
106 static bool HandleMmapLocCommand(ChatHandler* handler, char const* /*args*/)
107 {
108 handler->PSendSysMessage("mmap tileloc:");
109
110 // grid tile location
111 Player* player = handler->GetSession()->GetPlayer();
112
113 int32 gx = 32 - player->GetPositionX() / SIZE_OF_GRIDS;
114 int32 gy = 32 - player->GetPositionY() / SIZE_OF_GRIDS;
115
116 handler->PSendSysMessage("%04u_%02i_%02i.mmtile", player->GetMapId(), gy, gx);
117 handler->PSendSysMessage("gridloc [%i, %i]", gx, gy);
118
119 // calculate navmesh tile location
120 dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps());
121 dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMeshQuery(handler->GetSession()->GetPlayer()->GetMapId(), player->GetInstanceId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps());
122 if (!navmesh || !navmeshquery)
123 {
124 handler->PSendSysMessage("NavMesh not loaded for current map.");
125 return true;
126 }
127
128 float const* min = navmesh->getParams()->orig;
129 float x, y, z;
130 player->GetPosition(x, y, z);
131 float location[VERTEX_SIZE] = { y, z, x };
132 float extents[VERTEX_SIZE] = { 3.0f, 5.0f, 3.0f };
133
134 int32 tilex = int32((y - min[0]) / SIZE_OF_GRIDS);
135 int32 tiley = int32((x - min[2]) / SIZE_OF_GRIDS);
136
137 handler->PSendSysMessage("Calc [%02i, %02i]", tilex, tiley);
138
139 // navmesh poly -> navmesh tile location
140 dtQueryFilter filter = dtQueryFilter();
141 dtPolyRef polyRef = INVALID_POLYREF;
142 if (dtStatusFailed(navmeshquery->findNearestPoly(location, extents, &filter, &polyRef, NULL)))
143 {
144 handler->PSendSysMessage("Dt [??,??] (invalid poly, probably no tile loaded)");
145 return true;
146 }
147
148 if (polyRef == INVALID_POLYREF)
149 handler->PSendSysMessage("Dt [??, ??] (invalid poly, probably no tile loaded)");
150 else
151 {
152 dtMeshTile const* tile;
153 dtPoly const* poly;
154 if (dtStatusSucceed(navmesh->getTileAndPolyByRef(polyRef, &tile, &poly)))
155 {
156 if (tile)
157 {
158 handler->PSendSysMessage("Dt [%02i,%02i]", tile->header->x, tile->header->y);
159 return false;
160 }
161 }
162
163 handler->PSendSysMessage("Dt [??,??] (no tile loaded)");
164 }
165
166 return true;
167 }
168
169 static bool HandleMmapLoadedTilesCommand(ChatHandler* handler, char const* /*args*/)
170 {
171 uint32 mapid = handler->GetSession()->GetPlayer()->GetMapId();
172 dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(mapid, handler->GetSession()->GetPlayer()->GetTerrainSwaps());
173 dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMeshQuery(mapid, handler->GetSession()->GetPlayer()->GetInstanceId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps());
174 if (!navmesh || !navmeshquery)
175 {
176 handler->PSendSysMessage("NavMesh not loaded for current map.");
177 return true;
178 }
179
180 handler->PSendSysMessage("mmap loadedtiles:");
181
182 for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
183 {
184 dtMeshTile const* tile = navmesh->getTile(i);
185 if (!tile || !tile->header)
186 continue;
187
188 handler->PSendSysMessage("[%02i, %02i]", tile->header->x, tile->header->y);
189 }
190
191 return true;
192 }
193
194 static bool HandleMmapStatsCommand(ChatHandler* handler, char const* /*args*/)
195 {
196 uint32 mapId = handler->GetSession()->GetPlayer()->GetMapId();
197 handler->PSendSysMessage("mmap stats:");
198 handler->PSendSysMessage(" global mmap pathfinding is %sabled", MMAP::MMapFactory::IsPathfindingEnabled(mapId) ? "en" : "dis");
199
201 handler->PSendSysMessage(" %u maps loaded with %u tiles overall", manager->getLoadedMapsCount(), manager->getLoadedTilesCount());
202
203 dtNavMesh const* navmesh = manager->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId(), handler->GetSession()->GetPlayer()->GetTerrainSwaps());
204 if (!navmesh)
205 {
206 handler->PSendSysMessage("NavMesh not loaded for current map.");
207 return true;
208 }
209
210 uint32 tileCount = 0;
211 uint32 nodeCount = 0;
212 uint32 polyCount = 0;
213 uint32 vertCount = 0;
214 uint32 triCount = 0;
215 uint32 triVertCount = 0;
216 uint32 dataSize = 0;
217 for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
218 {
219 dtMeshTile const* tile = navmesh->getTile(i);
220 if (!tile || !tile->header)
221 continue;
222
223 tileCount++;
224 nodeCount += tile->header->bvNodeCount;
225 polyCount += tile->header->polyCount;
226 vertCount += tile->header->vertCount;
227 triCount += tile->header->detailTriCount;
228 triVertCount += tile->header->detailVertCount;
229 dataSize += tile->dataSize;
230 }
231
232 handler->PSendSysMessage("Navmesh stats:");
233 handler->PSendSysMessage(" %u tiles loaded", tileCount);
234 handler->PSendSysMessage(" %u BVTree nodes", nodeCount);
235 handler->PSendSysMessage(" %u polygons (%u vertices)", polyCount, vertCount);
236 handler->PSendSysMessage(" %u triangles (%u vertices)", triCount, triVertCount);
237 handler->PSendSysMessage(" %.2f MB of data (not including pointers)", ((float)dataSize / sizeof(unsigned char)) / 1048576);
238
239 return true;
240 }
241
242 static bool HandleMmapTestArea(ChatHandler* handler, char const* /*args*/)
243 {
244 float radius = 40.0f;
245 WorldObject* object = handler->GetSession()->GetPlayer();
246
248 Cell cell(pair);
249 cell.SetNoCreate();
250
251 std::list<Creature*> creatureList;
252
253 Skyfire::AnyUnitInObjectRangeCheck go_check(object, radius);
254 Skyfire::CreatureListSearcher<Skyfire::AnyUnitInObjectRangeCheck> go_search(object, creatureList, go_check);
256
257 // Get Creatures
258 cell.Visit(pair, go_visit, *(object->GetMap()), *object, radius);
259
260 if (!creatureList.empty())
261 {
262 handler->PSendSysMessage("Found " SIZEFMTD " Creatures.", creatureList.size());
263
264 uint32 paths = 0;
265 uint32 uStartTime = getMSTime();
266
267 float gx, gy, gz;
268 object->GetPosition(gx, gy, gz);
269 for (std::list<Creature*>::iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr)
270 {
271 PathGenerator path(*itr);
272 path.CalculatePath(gx, gy, gz);
273 ++paths;
274 }
275
276 uint32 uPathLoadTime = getMSTimeDiff(uStartTime, getMSTime());
277 handler->PSendSysMessage("Generated %i paths in %i ms", paths, uPathLoadTime);
278 }
279 else
280 handler->PSendSysMessage("No creatures in %f yard range.", radius);
281
282 return true;
283 }
284};
285
std::int32_t int32
Definition Define.h:73
std::uint32_t uint32
Definition Define.h:77
#define SIZEFMTD
Definition Define.h:70
#define OVERRIDE
Definition Define.h:60
#define SIZE_OF_GRIDS
Definition GridDefines.h:26
TypeMapContainer< AllGridObjectTypes > GridTypeMapContainer
Definition GridDefines.h:71
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
#define VISUAL_WAYPOINT
@ TEMPSUMMON_TIMED_DESPAWN
Definition Object.h:70
#define VERTEX_SIZE
#define INVALID_POLYREF
uint32 getMSTime()
Definition Timer.h:12
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition Timer.h:17
Unit * getSelectedUnit()
Definition Chat.cpp:841
WorldSession * GetSession()
Definition Chat.h:43
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition Chat.cpp:221
CommandScript(const char *name)
static MMapManager * createOrGetMMapManager()
static bool IsPathfindingEnabled(uint32 mapId)
uint32 getLoadedMapsCount() const
Definition MMapManager.h:96
dtNavMeshQuery const * GetNavMeshQuery(uint32 mapId, uint32 instanceId, TerrainSet swaps)
dtNavMesh const * GetNavMesh(uint32 mapId, TerrainSet swaps)
uint32 getLoadedTilesCount() const
Definition MMapManager.h:95
Movement::PointsArray const & GetPath() const
G3D::Vector3 const & GetStartPosition() const
PathType GetPathType() const
G3D::Vector3 const & GetEndPosition() const
bool CalculatePath(float destX, float destY, float destZ, bool forceDest=false)
void SetUseStraightPath(bool useStraightPath)
G3D::Vector3 const & GetActualEndPosition() const
bool IsGameMaster() const
Definition Player.h:1369
Definition Unit.h:1367
uint32 GetMapId() const
Definition Object.h:546
Map * GetMap() const
Definition Object.h:740
std::set< uint32 > const & GetTerrainSwaps() const
Definition Object.h:649
uint32 GetInstanceId() const
Definition Object.h:638
std::string const & GetName() const
Definition Object.h:664
TempSummon * SummonCreature(uint32 id, Position const &pos, TempSummonType spwtype=TempSummonType::TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0) const
Definition Object.cpp:2703
Player * GetPlayer() const
static bool HandleMmapTestArea(ChatHandler *handler, char const *)
Definition cs_mmaps.cpp:242
static bool HandleMmapLocCommand(ChatHandler *handler, char const *)
Definition cs_mmaps.cpp:106
std::vector< ChatCommand > GetCommands() const OVERRIDE
Definition cs_mmaps.cpp:32
static bool HandleMmapPathCommand(ChatHandler *handler, char const *args)
Definition cs_mmaps.cpp:50
static bool HandleMmapStatsCommand(ChatHandler *handler, char const *)
Definition cs_mmaps.cpp:194
static bool HandleMmapLoadedTilesCommand(ChatHandler *handler, char const *)
Definition cs_mmaps.cpp:169
void AddSC_mmaps_commandscript()
Definition cs_mmaps.cpp:286
std::vector< Vector3 > PointsArray
CellCoord ComputeCellCoord(float x, float y)
@ RBAC_PERM_COMMAND_MMAP_LOC
Definition RBAC.h:426
@ RBAC_PERM_COMMAND_MMAP
Definition RBAC.h:424
@ RBAC_PERM_COMMAND_MMAP_TESTAREA
Definition RBAC.h:429
@ RBAC_PERM_COMMAND_MMAP_STATS
Definition RBAC.h:428
@ RBAC_PERM_COMMAND_MMAP_LOADEDTILES
Definition RBAC.h:425
@ RBAC_PERM_COMMAND_MMAP_PATH
Definition RBAC.h:427
Definition Cell.h:37
void SetNoCreate()
Definition Cell.h:66
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &, float) const
Definition CellImpl.h:109
float GetPositionX() const
Definition Object.h:328
void GetPosition(float &x, float &y) const
Definition Object.h:333
float GetPositionY() const
Definition Object.h:329