diff options
| author | ccrs <ccrs@users.noreply.github.com> | 2018-06-03 10:06:57 -0700 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2021-09-28 00:15:13 +0200 |
| commit | 426f9f2f92b26fbb68e7cda9290ccbd586c6af4e (patch) | |
| tree | ede70b7865c2edb58964c7aa668eb1250a5816ab /src/server/game/AI/SmartScripts | |
| parent | 3e0af19b7767d6e71a7467874fdad566cea5ee87 (diff) | |
Core/Movement: MotionMaster reimplementation (#21888)
Internal structure and handling changes, nothing behavioural (or thats the intention at least).
(cherry picked from commit 982643cd96790ffc54e7a3e507469649f3b074d2)
Diffstat (limited to 'src/server/game/AI/SmartScripts')
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 31 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.cpp | 10 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScriptMgr.cpp | 4 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScriptMgr.h | 8 |
4 files changed, 34 insertions, 19 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 950b1d10fa3..f4a775bee69 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -113,7 +113,7 @@ void SmartAI::PausePath(uint32 delay, bool forced) { if (!HasEscortState(SMART_ESCORT_ESCORTING)) { - me->PauseMovement(delay, MOTION_SLOT_IDLE, forced); + me->PauseMovement(delay, MOTION_SLOT_DEFAULT, forced); if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE) { std::pair<uint32, uint32> waypointInfo = me->GetCurrentWaypointInfo(); @@ -546,8 +546,11 @@ void SmartAI::JustReachedHome() CreatureGroup* formation = me->GetFormation(); if (!formation || formation->GetLeader() == me || !formation->IsFormed()) { - if (me->GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_IDLE) != WAYPOINT_MOTION_TYPE && me->GetWaypointPath()) - me->GetMotionMaster()->MovePath(me->GetWaypointPath(), true); + if (me->GetMotionMaster()->GetCurrentMovementGeneratorType(MOTION_SLOT_DEFAULT) != WAYPOINT_MOTION_TYPE) + { + if (me->GetWaypointPath()) + me->GetMotionMaster()->MovePath(me->GetWaypointPath(), true); + } else me->ResumeMovement(); } @@ -593,7 +596,8 @@ void SmartAI::AttackStart(Unit* who) if (who && me->Attack(who, mCanAutoAttack)) { - me->GetMotionMaster()->Clear(MOTION_SLOT_ACTIVE); + me->GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL); + me->PauseMovement(); if (mCanCombatMove) { @@ -772,13 +776,22 @@ void SmartAI::SetCombatMove(bool on) if (me->IsEngaged()) { - if (on && !me->HasReactState(REACT_PASSIVE) && me->GetVictim() && me->GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_ACTIVE) == MAX_MOTION_TYPE) + if (on) { - SetRun(mRun); - me->GetMotionMaster()->MoveChase(me->GetVictim()); + if (!me->HasReactState(REACT_PASSIVE) && me->GetVictim() && !me->GetMotionMaster()->HasMovementGenerator([](MovementGenerator const* movement) -> bool + { + return movement->Mode == MOTION_MODE_DEFAULT && movement->Priority == MOTION_PRIORITY_NORMAL; + })) + { + SetRun(mRun); + me->GetMotionMaster()->MoveChase(me->GetVictim()); + } } - else if (!on && me->GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_ACTIVE) == CHASE_MOTION_TYPE) - me->GetMotionMaster()->Clear(MOTION_SLOT_ACTIVE); + else if (MovementGenerator* movement = me->GetMotionMaster()->GetMovementGenerator([](MovementGenerator const* a) -> bool + { + return a->GetMovementGeneratorType() == CHASE_MOTION_TYPE && a->Mode == MOTION_MODE_DEFAULT && a->Priority == MOTION_PRIORITY_NORMAL; + })) + me->GetMotionMaster()->Remove(movement); } } diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index e0516b76abf..2d191d2082b 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -1642,10 +1642,12 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u float attackAngle = float(e.action.setRangedMovement.angle) / 180.0f * float(M_PI); for (WorldObject* target : targets) + { if (Creature* creature = target->ToCreature()) if (IsSmart(creature) && creature->GetVictim()) if (ENSURE_AI(SmartAI, creature->AI())->CanCombatMove()) creature->GetMotionMaster()->MoveChase(creature->GetVictim(), attackDistance, attackAngle); + } break; } @@ -2323,16 +2325,16 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u target->ToUnit()->RemoveAllGameObjects(); break; } - case SMART_ACTION_STOP_MOTION: + case SMART_ACTION_REMOVE_MOVEMENT: { for (WorldObject* const target : targets) { if (IsUnit(target)) { - if (e.action.stopMotion.stopMovement) + if (e.action.removeMovement.movementType && e.action.removeMovement.movementType < MAX_MOTION_TYPE) + target->ToUnit()->GetMotionMaster()->Remove(MovementGeneratorType(e.action.removeMovement.movementType)); + if (e.action.removeMovement.forced) target->ToUnit()->StopMoving(); - if (e.action.stopMotion.movementExpired) - target->ToUnit()->GetMotionMaster()->MovementExpired(); } } break; diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp index 34ac2eea2ac..42353663540 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp @@ -25,7 +25,7 @@ #include "GameEventMgr.h" #include "InstanceScript.h" #include "Log.h" -#include "MotionMaster.h" +#include "MovementDefines.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" #include "SpellInfo.h" @@ -1757,7 +1757,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e) case SMART_ACTION_REMOVE_ALL_GAMEOBJECTS: case SMART_ACTION_SPAWN_SPAWNGROUP: case SMART_ACTION_DESPAWN_SPAWNGROUP: - case SMART_ACTION_STOP_MOTION: + case SMART_ACTION_REMOVE_MOVEMENT: break; default: TC_LOG_ERROR("sql.sql", "SmartAIMgr: Not handled action_type(%u), event_type(%u), Entry " SI64FMTD " SourceType %u Event %u, skipped.", e.GetActionType(), e.GetEventType(), e.entryOrGuid, e.GetScriptType(), e.event_id); diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h index dd29f0e3185..0e1fe59b06e 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h @@ -590,7 +590,7 @@ enum SMART_ACTION SMART_ACTION_LOAD_EQUIPMENT = 124, // id SMART_ACTION_TRIGGER_RANDOM_TIMED_EVENT = 125, // id min range, id max range SMART_ACTION_REMOVE_ALL_GAMEOBJECTS = 126, - SMART_ACTION_STOP_MOTION = 127, // stopMoving, movementExpired + SMART_ACTION_REMOVE_MOVEMENT = 127, // movementType, forced SMART_ACTION_PLAY_ANIMKIT = 128, // id, type (0 = oneShot, 1 = aiAnim, 2 = meleeAnim, 3 = movementAnim) SMART_ACTION_SCENE_PLAY = 129, // sceneId SMART_ACTION_SCENE_CANCEL = 130, // sceneId @@ -1162,9 +1162,9 @@ struct SmartAction struct { - uint32 stopMovement; - uint32 movementExpired; - } stopMotion; + uint32 movementType; + uint32 forced; + } removeMovement; struct { |
