From 15d38649fa915c427a703be6546bbc1f87c3bfb0 Mon Sep 17 00:00:00 2001 From: Fyre <58180427+i-am-fyre@users.noreply.github.com> Date: Tue, 7 Jun 2022 00:45:19 +0100 Subject: [PATCH] Documentation added to WaypointManager. (#54) * Documentation added to WaypointManager. --- src/game/WorldHandlers/WaypointManager.cpp | 120 ++++++++++++++++++++- 1 file changed, 117 insertions(+), 3 deletions(-) diff --git a/src/game/WorldHandlers/WaypointManager.cpp b/src/game/WorldHandlers/WaypointManager.cpp index c00b1b43..b3e4dc44 100644 --- a/src/game/WorldHandlers/WaypointManager.cpp +++ b/src/game/WorldHandlers/WaypointManager.cpp @@ -33,6 +33,12 @@ INSTANTIATE_SINGLETON_1(WaypointManager); +/** + * If the emote, spell, model1, or model2 variables are not 0, then the function returns false. + * Otherwise, if any of the textid variables are not 0, then the function returns false. Otherwise, the + * function returns true + * @return a boolean value. + */ bool WaypointBehavior::isEmpty() { if (emote || spell || model1 || model2) @@ -49,6 +55,10 @@ bool WaypointBehavior::isEmpty() return true; } +/** + * This function is a copy constructor for the WaypointBehavior class. + * @param b The waypoint behavior to copy. + */ WaypointBehavior::WaypointBehavior(const WaypointBehavior& b) { emote = b.emote; @@ -61,12 +71,17 @@ WaypointBehavior::WaypointBehavior(const WaypointBehavior& b) } } +/** + * It loads the waypoints from the database + * @return a pointer to a WaypointPath object. + */ void WaypointManager::Load() { uint32 total_paths = 0; uint32 total_nodes = 0; uint32 total_behaviors = 0; + /* Getting the script chain map for the DBS_ON_CREATURE_MOVEMENT event. */ ScriptChainMap const* scm = sScriptMgr.GetScriptChainMap(DBS_ON_CREATURE_MOVEMENT); if (!scm) { @@ -75,6 +90,7 @@ void WaypointManager::Load() std::set movementScriptSet; + /* Iterating through the map and printing out the key and value. */ for (ScriptChainMap::const_iterator itr = scm->begin(); itr != scm->end(); ++itr) { movementScriptSet.insert(itr->first); @@ -408,6 +424,9 @@ void WaypointManager::Load() } } +/** + * It clears all the waypoints from the path map, path template map, and external path template map + */ void WaypointManager::Unload() { for (WaypointPathMap::iterator itr = m_pathMap.begin(); itr != m_pathMap.end(); ++itr) @@ -430,6 +449,10 @@ void WaypointManager::Unload() } +/** + * It deletes all the waypoints in a path + * @param path The path to clear. + */ void WaypointManager::_clearPath(WaypointPath& path) { for (WaypointPath::const_iterator itr = path.begin(); itr != path.end(); ++itr) @@ -439,7 +462,19 @@ void WaypointManager::_clearPath(WaypointPath& path) path.clear(); } -/// Insert a node into the storage for external access +/** + * It adds a waypoint to the external waypoint map + * @param entry The entry of the NPC you want to add the waypoint to. + * @param pathId This is the path ID. It's a number between 0 and 255. + * @param pointId The point ID of the waypoint. + * @param x The X coordinate of the waypoint. + * @param y The Y coordinate of the waypoint. + * @param z The Z coordinate of the waypoint. + * @param o The orientation + * @param waittime The time in milliseconds that the NPC will wait at this node before moving to the + * next node. + * @return a boolean value. + */ bool WaypointManager::AddExternalNode(uint32 entry, int32 pathId, uint32 pointId, float x, float y, float z, float o, uint32 waittime) { if (pathId < 0 || pathId >= 0xFF) @@ -458,7 +493,17 @@ bool WaypointManager::AddExternalNode(uint32 entry, int32 pathId, uint32 pointId return true; } -/// - Insert at a certain point, if pointId == 0 insert last. In this case pointId will be changed to the id to which the node was added +/** + * It adds a new waypoint to the waypoint path + * @param entry The entry of the creature. + * @param dbGuid The GUID of the creature in the database. + * @param pointId The waypoint ID. + * @param wpDest + * @param x The X coordinate of the waypoint. + * @param y The Y coordinate of the waypoint. + * @param z The Z coordinate of the waypoint. + * @return A pointer to the WaypointNode object that was just created. + */ WaypointNode const* WaypointManager::AddNode(uint32 entry, uint32 dbGuid, uint32& pointId, WaypointPathOrigin wpDest, float x, float y, float z) { // Support only normal movement tables @@ -516,6 +561,15 @@ WaypointNode const* WaypointManager::AddNode(uint32 entry, uint32 dbGuid, uint32 return &path[pointId]; } +/** + * It deletes a waypoint from the database + * @param entry The entry of the creature. + * @param dbGuid The GUID of the creature in the database. + * @param point The point number to delete. + * @param pathId The path ID of the waypoint path you want to delete a node from. + * @param wpOrigin This is the type of waypoint path you want to delete. + * @return a pointer to a WaypointPath object. + */ void WaypointManager::DeleteNode(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin) { // Support only normal movement tables @@ -538,6 +592,10 @@ void WaypointManager::DeleteNode(uint32 entry, uint32 dbGuid, uint32 point, int3 path->erase(point); } +/** + * It deletes a path from the database, but not from the map + * @param id The ID of the path you want to delete. + */ void WaypointManager::DeletePath(uint32 id) { WorldDatabase.PExecuteLog("DELETE FROM `creature_movement` WHERE `id`=%u", id); @@ -552,6 +610,19 @@ void WaypointManager::DeletePath(uint32 id) // only meant to be called by GM commands } +/** + * It updates the position of a waypoint in the database + * @param entry The entry of the creature. + * @param dbGuid The GUID of the creature in the database. + * @param point The point number in the path. + * @param pathId The path ID of the waypoint. + * @param wpOrigin This is the type of waypoint path. It can be PATH_FROM_GUID, PATH_FROM_ENTRY, or + * PATH_FROM_EXTERNAL. + * @param x The X coordinate of the waypoint. + * @param y The Y coordinate of the waypoint. + * @param z The Z coordinate of the waypoint. + * @return a pointer to a WaypointPath object. + */ void WaypointManager::SetNodePosition(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, float x, float y, float z) { // Support only normal movement tables @@ -580,6 +651,17 @@ void WaypointManager::SetNodePosition(uint32 entry, uint32 dbGuid, uint32 point, } } +/** + * It updates the waittime of a waypoint in the database + * @param entry The entry of the creature. + * @param dbGuid The GUID of the creature in the database. + * @param point The point number in the path. + * @param pathId The path ID of the waypoint path you want to modify. + * @param wpOrigin This is the type of waypoint path you want to modify. + * @param waittime The time in milliseconds that the NPC will wait at the waypoint before moving to the + * next one. + * @return a pointer to a WaypointPath object. + */ void WaypointManager::SetNodeWaittime(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, uint32 waittime) { // Support only normal movement tables @@ -606,6 +688,16 @@ void WaypointManager::SetNodeWaittime(uint32 entry, uint32 dbGuid, uint32 point, } } +/** + * It updates the orientation of a waypoint in the database + * @param entry The entry of the creature. + * @param dbGuid The GUID of the creature in the database. + * @param point The point number in the path. + * @param pathId The path ID of the waypoint path you want to modify. + * @param wpOrigin This is the type of waypoint path you want to modify. + * @param orientation The new orientation of the waypoint. + * @return a pointer to a WaypointPath object. + */ void WaypointManager::SetNodeOrientation(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, float orientation) { // Support only normal movement tables @@ -632,7 +724,17 @@ void WaypointManager::SetNodeOrientation(uint32 entry, uint32 dbGuid, uint32 poi } } -/// return true if a valid scriptId is provided +/** + * It updates the script_id field of the creature_movement table for the given entry, dbGuid, point, + * pathId, and wpOrigin + * @param entry The entry of the creature. + * @param dbGuid The GUID of the creature in the database. + * @param point The waypoint number. + * @param pathId The path ID of the waypoint path you want to modify. + * @param wpOrigin This is the type of waypoint path you want to modify. + * @param scriptId The scriptId of the script you want to run. + * @return The script_id of the waypoint. + */ bool WaypointManager::SetNodeScriptId(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, uint32 scriptId) { // Support only normal movement tables @@ -667,6 +769,14 @@ bool WaypointManager::SetNodeScriptId(uint32 entry, uint32 dbGuid, uint32 point, return scm->find(scriptId) != scm->end(); } +/** + * It checks if the textid is valid and if it is, it removes it from the set of textids. + * @param isTemplate Whether the waypoint is for a creature template or a creature. + * @param entryOrGuid The entry or guid of the creature. + * @param point The point ID of the waypoint. + * @param be WaypointBehavior* + * @param ids A set of all the text IDs used in the database. + */ inline void CheckWPText(bool isTemplate, uint32 entryOrGuid, uint32 point, WaypointBehavior* be, std::set& ids) { int zeroCount = 0; // Counting leading zeros for futher textid shift @@ -697,6 +807,10 @@ inline void CheckWPText(bool isTemplate, uint32 entryOrGuid, uint32 point, Waypo } } +/** + * It checks if the waypoint text exists in the database + * @param ids The set of ids that are being checked for existence. + */ void WaypointManager::CheckTextsExistance(std::set& ids) { for (WaypointPathMap::const_iterator pmItr = m_pathMap.begin(); pmItr != m_pathMap.end(); ++pmItr)