Skip to content

Commit 9f32003

Browse files
committed
EAI/Scripts/EscortAI: Enable specifying waypoint_path entry
1 parent 0d801e7 commit 9f32003

File tree

8 files changed

+68
-18
lines changed

8 files changed

+68
-18
lines changed

doc/EventAI.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ For all ACTION_T_RANDOM Actions, When a Particular Param is selected for the Eve
161161
45 ACTION_T_THROW_AI_EVENT EventType, Radius, Target Throws an AIEvent of type (Param1) to nearby friendly Npcs in range of (Param2), Invoker of event is Target
162162
46 ACTION_T_SET_THROW_MASK EventTypeMask Marks for which AIEvents the npc will throw AIEvents on its own.
163163
47 ACTION_T_SET_STAND_STATE StandState Set the unit stand state (Param1) of the current creature.
164-
48 ACTION_T_CHANGE_MOVEMENT MovementType, WanderDistance Change the unit movement type (Param1). If the movement type is Random Movement (1), the WanderDistance (Param2) must be provided. If the movement type is Waypoint Movement (2), Param2 is PathId. Param3 is asDefault.
164+
48 ACTION_T_CHANGE_MOVEMENT MovementType, WanderDistance Change the unit movement type (Param1). If the movement type is Random Movement (1), the WanderDistance (Param2) must be provided. If the movement type is Waypoint Movement (2), Param2 is PathId. Param3 0x1 is asDefault, 0x2 forces waypoint, path or linear path movement to use waypoint_path table PathId
165165
49 ACTION_T_REUSE
166166
50 ACTION_T_SET_REACT_STATE ReactState Change react state of the creature
167167
51 ACTION_T_PAUSE_WAYPOINTS DoPause Pause waypoints of creature

doc/script_commands.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ Defining a buddy could be done in several way:
260260
* datalog = movie id
261261

262262
20 SCRIPT_COMMAND_MOVEMENT resultingSource = Creature
263-
* datalong = MovementType (0:idle, 1:random, 2:waypoint, 3:path)
263+
* datalong = MovementType (0:idle, 1:random, 2:waypoint, 3:path, 4:linear)
264264
* datalong2 = wanderDistance (for random movement), pathId (for waypoint movement)
265-
* datalong3 = timer for timed random movement or pass target to waypoint and path movegen (by default, source targets self)
265+
* datalong3 = 0x1 - timer for timed random movement or pass target to waypoint and path movegen (by default, source targets self)
266+
* 0x2 - for waypoint, path and linear path - uses pathId from waypoint_path table
266267
* data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL: RandomMovement around current position
267268
* dataint = enum ForcedMovement
268269

src/game/AI/EventAI/CreatureEventAI.cpp

+22-3
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ bool CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
11891189
}
11901190
case ACTION_T_CHANGE_MOVEMENT:
11911191
{
1192-
if (action.changeMovement.asDefault)
1192+
if (action.changeMovement.flags & CHANGE_MOVEMENT_FLAG_AS_DEFAULT)
11931193
m_defaultMovement = MovementGeneratorType(action.changeMovement.movementType);
11941194
switch (action.changeMovement.movementType)
11951195
{
@@ -1200,15 +1200,34 @@ bool CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
12001200
m_creature->GetMotionMaster()->MoveRandomAroundPoint(m_creature->GetPositionX(), m_creature->GetPositionY(), m_creature->GetPositionZ(), float(action.changeMovement.wanderORpathID));
12011201
break;
12021202
case WAYPOINT_MOTION_TYPE:
1203+
{
12031204
m_creature->StopMoving();
12041205
m_creature->GetMotionMaster()->Clear(false, true);
1205-
m_creature->GetMotionMaster()->MoveWaypoint(action.changeMovement.wanderORpathID);
1206+
WaypointPathOrigin origin = PATH_NO_PATH;
1207+
if (action.changeMovement.flags & CHANGE_MOVEMENT_FLAG_WAYPOINT_PATH)
1208+
origin = PATH_FROM_WAYPOINT_PATH;
1209+
m_creature->GetMotionMaster()->MoveWaypoint(action.changeMovement.wanderORpathID, origin);
1210+
break;
1211+
}
1212+
case PATH_MOTION_TYPE:
1213+
{
1214+
m_creature->StopMoving();
1215+
WaypointPathOrigin origin = PATH_NO_PATH;
1216+
if (action.changeMovement.flags & CHANGE_MOVEMENT_FLAG_WAYPOINT_PATH)
1217+
origin = PATH_FROM_WAYPOINT_PATH;
1218+
m_creature->GetMotionMaster()->MovePath(action.changeMovement.wanderORpathID, origin);
12061219
break;
1220+
}
12071221
case LINEAR_WP_MOTION_TYPE:
1222+
{
12081223
m_creature->StopMoving();
12091224
m_creature->GetMotionMaster()->Clear(false, true);
1210-
m_creature->GetMotionMaster()->MoveLinearWP(action.changeMovement.wanderORpathID);
1225+
WaypointPathOrigin origin = PATH_NO_PATH;
1226+
if (action.changeMovement.flags & CHANGE_MOVEMENT_FLAG_WAYPOINT_PATH)
1227+
origin = PATH_FROM_WAYPOINT_PATH;
1228+
m_creature->GetMotionMaster()->MoveLinearWP(action.changeMovement.wanderORpathID, origin);
12111229
break;
1230+
}
12121231
}
12131232
break;
12141233
}

src/game/AI/EventAI/CreatureEventAI.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ enum DespawnAggregation : uint32
229229
AGGREGATION_DEATH = 0x4,
230230
};
231231

232+
enum ChangeMovementFlags : uint32
233+
{
234+
CHANGE_MOVEMENT_FLAG_AS_DEFAULT = 0x1,
235+
CHANGE_MOVEMENT_FLAG_WAYPOINT_PATH = 0x2,
236+
CHANGE_MOVEMENT_MAX = 0x3,
237+
};
238+
232239
struct CreatureEventAI_Action
233240
{
234241
EventAI_ActionType type: 16;
@@ -480,7 +487,7 @@ struct CreatureEventAI_Action
480487
{
481488
uint32 movementType;
482489
uint32 wanderORpathID;
483-
uint32 asDefault;
490+
uint32 flags;
484491
} changeMovement;
485492
// ACTION_T_REUSE = 49
486493
struct

src/game/AI/EventAI/CreatureEventAIMgr.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,10 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
903903
{
904904
sLog.outErrorEventAI("Event %u Action %u uses invalid movement type %u (must be smaller than %u)", eventId, j + 1, action.changeMovement.movementType, MAX_DB_MOTION_TYPE);
905905
}
906-
if (action.changeMovement.asDefault > 1)
906+
if (action.changeMovement.flags > CHANGE_MOVEMENT_MAX)
907907
{
908-
sLog.outErrorEventAI("Event %u Action %u uses invalid default movement setting %u. Setting to 0.", eventId, j + 1, action.changeMovement.asDefault);
909-
action.changeMovement.asDefault = 0;
908+
sLog.outErrorEventAI("Event %u Action %u uses invalid flags setting %u. Setting to 0.", eventId, j + 1, action.changeMovement.flags);
909+
action.changeMovement.flags = 0;
910910
}
911911
break;
912912
case ACTION_T_SET_REACT_STATE:

src/game/AI/ScriptDevAI/base/escort_ai.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void npc_escortAI::SetRun(bool run)
232232
}
233233

234234
// TODO: get rid of this many variables passed in function.
235-
void npc_escortAI::Start(bool run, const Player* player, const Quest* quest, bool instantRespawn, bool canLoopPath)
235+
void npc_escortAI::Start(bool run, const Player* player, const Quest* quest, bool instantRespawn, bool canLoopPath, uint32 waypointPath)
236236
{
237237
if (m_creature->GetVictim())
238238
{
@@ -246,7 +246,15 @@ void npc_escortAI::Start(bool run, const Player* player, const Quest* quest, boo
246246
return;
247247
}
248248

249-
if (!sWaypointMgr.GetPathFromOrigin(m_creature->GetEntry(), m_creature->GetGUIDLow(), m_waypointPathID, PATH_FROM_EXTERNAL))
249+
uint32 pathId = m_waypointPathID;
250+
WaypointPathOrigin origin = PATH_FROM_EXTERNAL;
251+
if (waypointPath)
252+
{
253+
pathId = waypointPath;
254+
origin = PATH_FROM_WAYPOINT_PATH;
255+
}
256+
257+
if (!sWaypointMgr.GetPathFromOrigin(m_creature->GetEntry(), m_creature->GetGUIDLow(), pathId, origin))
250258
{
251259
script_error_log("EscortAI attempt to start escorting for %s, but has no waypoints loaded.", m_creature->GetScriptName().data());
252260
return;
@@ -276,7 +284,7 @@ void npc_escortAI::Start(bool run, const Player* player, const Quest* quest, boo
276284

277285
// Start moving along the path with 2500ms delay
278286
m_creature->GetMotionMaster()->Clear(false, true);
279-
m_creature->GetMotionMaster()->MoveWaypoint(m_waypointPathID, PATH_FROM_EXTERNAL, 2500);
287+
m_creature->GetMotionMaster()->MoveWaypoint(pathId, origin, 2500);
280288

281289
JustStartedEscort();
282290
}

src/game/AI/ScriptDevAI/base/escort_ai.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct npc_escortAI : public ScriptedAI
3939
virtual void WaypointReached(uint32 pointId) = 0;
4040
virtual void WaypointStart(uint32 /*pointId*/) {}
4141

42-
void Start(bool run = false, const Player* player = nullptr, const Quest* quest = nullptr, bool instantRespawn = false, bool canLoopPath = false);
42+
void Start(bool run = false, const Player* player = nullptr, const Quest* quest = nullptr, bool instantRespawn = false, bool canLoopPath = false, uint32 waypointPath = 0);
4343

4444
void SetRun(bool run = true);
4545
void SetEscortPaused(bool paused);

src/game/DBScripts/ScriptMgr.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ bool ScriptAction::ExecuteDbscriptCommand(WorldObject* pSource, WorldObject* pTa
20472047

20482048
if (m_script->movement.movementType == WAYPOINT_MOTION_TYPE || m_script->movement.movementType == PATH_MOTION_TYPE)
20492049
{
2050-
if (m_script->movement.timerOrPassTarget && !pTarget)
2050+
if ((m_script->movement.timerOrPassTarget & 0x1) && !pTarget)
20512051
{
20522052
DETAIL_FILTER_LOG(LOG_FILTER_DB_SCRIPT, " DB-SCRIPTS: Process table `%s` id %u, SCRIPT_COMMAND_MOVEMENT called for movement change to %u with source guid %s, pass target true and target nullptr: skipping.", m_table, m_script->id, m_script->movement.movementType, pSource->GetGuidStr().c_str());
20532053
break;
@@ -2073,28 +2073,43 @@ bool ScriptAction::ExecuteDbscriptCommand(WorldObject* pSource, WorldObject* pTa
20732073
}
20742074
break;
20752075
case WAYPOINT_MOTION_TYPE:
2076+
{
20762077
source->StopMoving();
20772078
source->GetMotionMaster()->Clear(false, true);
2078-
if (!m_script->movement.timerOrPassTarget)
2079+
WaypointPathOrigin origin = PATH_NO_PATH;
2080+
if (m_script->movement.timerOrPassTarget & 0x2)
2081+
origin = PATH_FROM_WAYPOINT_PATH;
2082+
if (!m_script->movement.timerOrPassTarget & 0x1)
20792083
source->GetMotionMaster()->MoveWaypoint(m_script->movement.wanderORpathId);
20802084
else
20812085
source->GetMotionMaster()->MoveWaypoint(m_script->movement.wanderORpathId, 0, 0, 0, ForcedMovement(m_script->textId[0]), pTarget->GetObjectGuid());
20822086
break;
2087+
}
20832088
case PATH_MOTION_TYPE:
2089+
{
20842090
source->StopMoving();
2085-
if (!m_script->movement.timerOrPassTarget)
2091+
WaypointPathOrigin origin = PATH_NO_PATH;
2092+
if (m_script->movement.timerOrPassTarget & 0x2)
2093+
origin = PATH_FROM_WAYPOINT_PATH;
2094+
if (!m_script->movement.timerOrPassTarget & 0x1)
20862095
source->GetMotionMaster()->MovePath(m_script->movement.wanderORpathId);
20872096
else
20882097
source->GetMotionMaster()->MovePath(m_script->movement.wanderORpathId, PATH_NO_PATH, ForcedMovement(m_script->textId[0]), false, 0.f, false, pTarget->GetObjectGuid());
20892098
break;
2099+
}
20902100
case LINEAR_WP_MOTION_TYPE:
2101+
{
20912102
source->StopMoving();
20922103
source->GetMotionMaster()->Clear(false, true);
2093-
if (!m_script->movement.timerOrPassTarget)
2104+
WaypointPathOrigin origin = PATH_NO_PATH;
2105+
if (m_script->movement.timerOrPassTarget & 0x2)
2106+
origin = PATH_FROM_WAYPOINT_PATH;
2107+
if (!m_script->movement.timerOrPassTarget & 0x1)
20942108
source->GetMotionMaster()->MoveLinearWP(m_script->movement.wanderORpathId);
20952109
else
20962110
source->GetMotionMaster()->MoveLinearWP(m_script->movement.wanderORpathId, 0, 0, 0, ForcedMovement(m_script->textId[0]), pTarget->GetObjectGuid());
20972111
break;
2112+
}
20982113
}
20992114

21002115
break;

0 commit comments

Comments
 (0)