diff options
| author | ModoX <moardox@gmail.com> | 2023-04-08 01:33:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-08 01:33:05 +0200 |
| commit | 356c98579babd1aef12e2b5ef28baba2403368d0 (patch) | |
| tree | e4824b312ecbcf462418d1d149614b71effd5d02 /src/server/game | |
| parent | 7d5d3cf655b3e701d8a570b03499a388476cbdf9 (diff) | |
Core/SAI: Drop waypoints table and move existing rows to waypoint_data table (#28834)
Diffstat (limited to 'src/server/game')
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 47 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.h | 5 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.cpp | 8 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScriptMgr.cpp | 74 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScriptMgr.h | 20 | ||||
| -rw-r--r-- | src/server/game/World/World.cpp | 3 |
6 files changed, 26 insertions, 131 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 1e0e0b9dec0..36917a73ea3 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -30,6 +30,7 @@ #include "Player.h" #include "ScriptMgr.h" #include "Vehicle.h" +#include "WaypointManager.h" SmartAI::SmartAI(Creature* creature, uint32 scriptId) : CreatureAI(creature, scriptId), _charmed(false), _followCreditType(0), _followArrivedTimer(0), _followCredit(0), _followArrivedEntry(0), _followDistance(0.f), _followAngle(0.f), _escortState(SMART_ESCORT_NONE), _escortNPCFlags(0), _escortInvokerCheckTimer(1000), _currentWaypointNode(0), _waypointReached(false), _waypointPauseTimer(0), _waypointPauseForced(false), _repeatWaypointPath(false), @@ -44,20 +45,16 @@ bool SmartAI::IsAIControlled() const return !_charmed; } -void SmartAI::StartPath(bool run/* = false*/, uint32 pathId/* = 0*/, bool repeat/* = false*/, Unit* invoker/* = nullptr*/, uint32 nodeId/* = 1*/) +void SmartAI::StartPath(uint32 pathId/* = 0*/, bool repeat/* = false*/, Unit* invoker/* = nullptr*/, uint32 nodeId/* = 1*/) { if (HasEscortState(SMART_ESCORT_ESCORTING)) StopPath(); - SetRun(run); - - if (pathId) - { - if (!LoadPath(pathId)) - return; - } + if (!pathId) + return; - if (_path.nodes.empty()) + WaypointPath const* path = LoadPath(pathId); + if (!path) return; _currentWaypointNode = nodeId; @@ -74,32 +71,23 @@ void SmartAI::StartPath(bool run/* = false*/, uint32 pathId/* = 0*/, bool repeat me->ReplaceAllNpcFlags(UNIT_NPC_FLAG_NONE); } - me->GetMotionMaster()->MovePath(_path, _repeatWaypointPath); + me->GetMotionMaster()->MovePath(*path, _repeatWaypointPath); } -bool SmartAI::LoadPath(uint32 entry) +WaypointPath const* SmartAI::LoadPath(uint32 entry) { if (HasEscortState(SMART_ESCORT_ESCORTING)) - return false; + return nullptr; - WaypointPath const* path = sSmartWaypointMgr->GetPath(entry); + WaypointPath const* path = sWaypointMgr->GetPath(entry); if (!path || path->nodes.empty()) { GetScript()->SetPathId(0); - return false; - } - - _path.id = path->id; - _path.nodes = path->nodes; - for (WaypointNode& waypoint : _path.nodes) - { - Trinity::NormalizeMapCoord(waypoint.x); - Trinity::NormalizeMapCoord(waypoint.y); - waypoint.moveType = _run ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK; + return nullptr; } GetScript()->SetPathId(entry); - return true; + return path; } void SmartAI::PausePath(uint32 delay, bool forced) @@ -190,7 +178,7 @@ void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail) void SmartAI::EndPath(bool fail) { RemoveEscortState(SMART_ESCORT_ESCORTING | SMART_ESCORT_PAUSED | SMART_ESCORT_RETURNING); - _path.nodes.clear(); + _waypointPauseTimer = 0; if (_escortNPCFlags) @@ -252,7 +240,7 @@ void SmartAI::EndPath(bool fail) if (_repeatWaypointPath) { if (IsAIControlled()) - StartPath(_run, GetScript()->GetPathId(), _repeatWaypointPath); + StartPath(GetScript()->GetPathId(), _repeatWaypointPath); } else if (pathid == GetScript()->GetPathId()) // if it's not the same pathid, our script wants to start another path; don't override it GetScript()->SetPathId(0); @@ -373,7 +361,8 @@ void SmartAI::WaypointReached(uint32 nodeId, uint32 pathId) } else if (HasEscortState(SMART_ESCORT_ESCORTING) && me->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE) { - if (_currentWaypointNode == _path.nodes.size()) + WaypointPath const* path = sWaypointMgr->GetPath(pathId); + if (path && _currentWaypointNode == path->nodes.size()) _waypointPathEnded = true; else SetRun(_run); @@ -703,7 +692,7 @@ void SmartAI::OnCharmed(bool isNew) if (!charmed && !me->IsInEvadeMode()) { if (_repeatWaypointPath) - StartPath(_run, GetScript()->GetPathId(), true); + StartPath(GetScript()->GetPathId(), true); else me->SetWalk(!_run); @@ -751,8 +740,6 @@ void SmartAI::SetRun(bool run) { me->SetWalk(!run); _run = run; - for (auto& node : _path.nodes) - node.moveType = run ? WAYPOINT_MOVE_TYPE_RUN : WAYPOINT_MOVE_TYPE_WALK; } void SmartAI::SetDisableGravity(bool fly) diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h index 82e2a53be3c..a83e5175066 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.h +++ b/src/server/game/AI/SmartScripts/SmartAI.h @@ -49,8 +49,8 @@ class TC_GAME_API SmartAI : public CreatureAI bool IsAIControlled() const; // Start moving to the desired MovePoint - void StartPath(bool run = false, uint32 pathId = 0, bool repeat = false, Unit* invoker = nullptr, uint32 nodeId = 1); - bool LoadPath(uint32 entry); + void StartPath(uint32 pathId = 0, bool repeat = false, Unit* invoker = nullptr, uint32 nodeId = 1); + WaypointPath const* LoadPath(uint32 entry); void PausePath(uint32 delay, bool forced = false); bool CanResumePath(); void StopPath(uint32 DespawnTime = 0, uint32 quest = 0, bool fail = false); @@ -253,7 +253,6 @@ class TC_GAME_API SmartAI : public CreatureAI uint32 _escortState; uint32 _escortNPCFlags; uint32 _escortInvokerCheckTimer; - WaypointPath _path; uint32 _currentWaypointNode; bool _waypointReached; uint32 _waypointPauseTimer; diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index aae2db1fab3..fb42e3105aa 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -43,6 +43,7 @@ #include "TemporarySummon.h" #include "Vehicle.h" #include "WaypointDefines.h" +#include "WaypointManager.h" SmartScript::SmartScript() { @@ -1381,7 +1382,6 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (!IsSmart()) break; - bool run = e.action.wpStart.run != 0; uint32 entry = e.action.wpStart.pathID; bool repeat = e.action.wpStart.repeat != 0; @@ -1394,7 +1394,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u } } - ENSURE_AI(SmartAI, me->AI())->StartPath(run, entry, repeat, unit); + ENSURE_AI(SmartAI, me->AI())->StartPath(entry, repeat, unit); uint32 quest = e.action.wpStart.quest; uint32 DespawnTime = e.action.wpStart.despawnTime; @@ -2062,7 +2062,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u { for (uint32 pathId : waypoints) { - WaypointPath const* path = sSmartWaypointMgr->GetPath(pathId); + WaypointPath const* path = sWaypointMgr->GetPath(pathId); if (!path || path->nodes.empty()) continue; @@ -2079,7 +2079,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u } if (closest.first != 0) - ENSURE_AI(SmartAI, creature->AI())->StartPath(false, closest.first, true, nullptr, closest.second); + ENSURE_AI(SmartAI, creature->AI())->StartPath(closest.first, true, nullptr, closest.second); } } } diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp index e28adee32db..7ac71ca5625 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp @@ -34,6 +34,7 @@ #include "UnitDefines.h" #include "Util.h" #include "WaypointDefines.h" +#include "WaypointManager.h" #include <algorithm> #define TC_SAI_IS_BOOLEAN_VALID(e, value) \ @@ -46,77 +47,6 @@ } \ } -SmartWaypointMgr* SmartWaypointMgr::instance() -{ - static SmartWaypointMgr instance; - return &instance; -} - -void SmartWaypointMgr::LoadFromDB() -{ - uint32 oldMSTime = getMSTime(); - - _waypointStore.clear(); - - WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_SMARTAI_WP); - PreparedQueryResult result = WorldDatabase.Query(stmt); - - if (!result) - { - TC_LOG_INFO("server.loading", ">> Loaded 0 SmartAI Waypoint Paths. DB table `waypoints` is empty."); - - return; - } - - uint32 count = 0; - uint32 total = 0; - uint32 lastEntry = 0; - uint32 lastId = 1; - - do - { - Field* fields = result->Fetch(); - uint32 entry = fields[0].GetUInt32(); - uint32 id = fields[1].GetUInt32(); - float x = fields[2].GetFloat(); - float y = fields[3].GetFloat(); - float z = fields[4].GetFloat(); - Optional<float> o; - if (!fields[5].IsNull()) - o = fields[5].GetFloat(); - uint32 delay = fields[6].GetUInt32(); - - if (lastEntry != entry) - { - lastId = 1; - ++count; - } - - if (lastId != id) - TC_LOG_ERROR("sql.sql", "SmartWaypointMgr::LoadFromDB: Path entry {}, unexpected point id {}, expected {}.", entry, id, lastId); - - ++lastId; - - WaypointPath& path = _waypointStore[entry]; - path.id = entry; - path.nodes.emplace_back(id, x, y, z, o, delay); - - lastEntry = entry; - ++total; - } - while (result->NextRow()); - - TC_LOG_INFO("server.loading", ">> Loaded {} SmartAI waypoint paths (total {} waypoints) in {} ms", count, total, GetMSTimeDiffToNow(oldMSTime)); -} - -WaypointPath const* SmartWaypointMgr::GetPath(uint32 id) -{ - auto itr = _waypointStore.find(id); - if (itr != _waypointStore.end()) - return &itr->second; - return nullptr; -} - SmartAIMgr* SmartAIMgr::instance() { static SmartAIMgr instance; @@ -1901,7 +1831,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e) break; case SMART_ACTION_WP_START: { - WaypointPath const* path = sSmartWaypointMgr->GetPath(e.action.wpStart.pathID); + WaypointPath const* path = sWaypointMgr->GetPath(e.action.wpStart.pathID); if (!path || path->nodes.empty()) { TC_LOG_ERROR("sql.sql", "SmartAIMgr: Creature {} Event {} Action {} uses non-existent WaypointPath id {}, skipped.", e.entryOrGuid, e.event_id, e.GetActionType(), e.action.wpStart.pathID); diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h index 475b4ad4ad5..31bb3c82161 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h @@ -865,7 +865,7 @@ struct SmartAction struct { - SAIBool run; + SAIBool run; // unused / overridden by waypoint_data uint32 pathID; SAIBool repeat; uint32 quest; @@ -1687,24 +1687,6 @@ class ObjectGuidVector }; typedef std::unordered_map<uint32, ObjectGuidVector> ObjectVectorMap; -class TC_GAME_API SmartWaypointMgr -{ - public: - static SmartWaypointMgr* instance(); - - void LoadFromDB(); - - WaypointPath const* GetPath(uint32 id); - - private: - SmartWaypointMgr() { } - ~SmartWaypointMgr() { } - - std::unordered_map<uint32, WaypointPath> _waypointStore; -}; - -#define sSmartWaypointMgr SmartWaypointMgr::instance() - // all events for a single entry typedef std::vector<SmartScriptHolder> SmartAIEventList; typedef std::vector<SmartScriptHolder> SmartAIEventStoredList; diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index fa79a585ad8..1edcb7bc3bb 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -2271,9 +2271,6 @@ void World::SetInitialWorldSettings() TC_LOG_INFO("server.loading", "Loading Waypoints..."); sWaypointMgr->Load(); - TC_LOG_INFO("server.loading", "Loading SmartAI Waypoints..."); - sSmartWaypointMgr->LoadFromDB(); - TC_LOG_INFO("server.loading", "Loading Creature Formations..."); sFormationMgr->LoadCreatureFormations(); |
