Skip to content

Commit

Permalink
Scripts: Implement passing target to MovePoint, MovePath and MoveWayp…
Browse files Browse the repository at this point in the history
…oint and implement Relay script on MovePoint
  • Loading branch information
killerwife committed Nov 8, 2021
1 parent 8351505 commit ef15dd2
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 26 deletions.
7 changes: 5 additions & 2 deletions doc/script_commands.txt
Expand Up @@ -177,7 +177,9 @@ Defining a buddy could be done in several way:
3 SCRIPT_COMMAND_MOVE_TO resultingSource = Creature
If position is very near to current position, or x=y=z=0, then only orientation is changed
If x=y=0 and z !=0, then only Z position is changed (new value will be added to current 'z' position)
* datalong = dbscripts_on_relay id - executed for source and target same as this script
* datalong2 = travel_speed*100 (use 0 for creature default movement)
* datalong3 = enum ForcedMovement
* data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL: teleport unit to position
* x/y/z/o

Expand Down Expand Up @@ -256,10 +258,11 @@ Defining a buddy could be done in several way:
* datalog = movie id

20 SCRIPT_COMMAND_MOVEMENT resultingSource = Creature
* datalong = MovementType (0:idle, 1:random or 2:waypoint)
* datalong = MovementType (0:idle, 1:random, 2:waypoint, 3:path)
* datalong2 = wanderDistance (for random movement), pathId (for waypoint movement)
* datalong3 = timer for timed random movement
* datalong3 = timer for timed random movement or pass target to waypoint and path movegen (by default, source targets self)
* data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL: RandomMovement around current position
* dataint = enum ForcedMovement

21 SCRIPT_COMMAND_SET_ACTIVEOBJECT resultingSource = Creature
* datalong=bool 0=off, 1=on
Expand Down
27 changes: 23 additions & 4 deletions src/game/DBScripts/ScriptMgr.cpp
Expand Up @@ -1543,7 +1543,7 @@ bool ScriptAction::ExecuteDbscriptCommand(WorldObject* pSource, WorldObject* pTa
else
{
((Unit*)pSource)->GetMotionMaster()->Clear();
((Unit*)pSource)->GetMotionMaster()->MovePoint(0, m_script->x, m_script->y, m_script->z);
((Unit*)pSource)->GetMotionMaster()->MovePoint(0, Position(m_script->x, m_script->y, m_script->z, m_script->o), ForcedMovement(m_script->moveTo.forcedMovement), 0.f, true, pTarget ? pTarget->GetObjectGuid() : ObjectGuid(), m_script->moveTo.relayId);
}
break;
}
Expand Down Expand Up @@ -1923,6 +1923,15 @@ bool ScriptAction::ExecuteDbscriptCommand(WorldObject* pSource, WorldObject* pTa
break;
}

if (m_script->movement.movementType == WAYPOINT_MOTION_TYPE || m_script->movement.movementType == PATH_MOTION_TYPE)
{
if (m_script->movement.timerOrPassTarget && !pTarget)
{
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());
break;
}
}

switch (m_script->movement.movementType)
{
case IDLE_MOTION_TYPE:
Expand All @@ -1932,19 +1941,29 @@ bool ScriptAction::ExecuteDbscriptCommand(WorldObject* pSource, WorldObject* pTa
break;
case RANDOM_MOTION_TYPE:
if (m_script->data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL)
source->GetMotionMaster()->MoveRandomAroundPoint(pSource->GetPositionX(), pSource->GetPositionY(), pSource->GetPositionZ(), float(m_script->movement.wanderORpathId), 0.f, m_script->movement.timer);
source->GetMotionMaster()->MoveRandomAroundPoint(pSource->GetPositionX(), pSource->GetPositionY(), pSource->GetPositionZ(), float(m_script->movement.wanderORpathId), 0.f, m_script->movement.timerOrPassTarget);
else
{
float respX, respY, respZ, respO, wander_distance;
source->GetRespawnCoord(respX, respY, respZ, &respO, &wander_distance);
wander_distance = m_script->movement.wanderORpathId ? m_script->movement.wanderORpathId : wander_distance;
source->GetMotionMaster()->MoveRandomAroundPoint(respX, respY, respZ, wander_distance, 0.f, m_script->movement.timer);
source->GetMotionMaster()->MoveRandomAroundPoint(respX, respY, respZ, wander_distance, 0.f, m_script->movement.timerOrPassTarget);
}
break;
case WAYPOINT_MOTION_TYPE:
source->StopMoving();
source->GetMotionMaster()->Clear(false, true);
source->GetMotionMaster()->MoveWaypoint(m_script->movement.wanderORpathId);
if (!m_script->movement.timerOrPassTarget)
source->GetMotionMaster()->MoveWaypoint(m_script->movement.wanderORpathId);
else
source->GetMotionMaster()->MoveWaypoint(m_script->movement.wanderORpathId, 0, 0, 0, ForcedMovement(m_script->textId[0]), pTarget->GetObjectGuid());
break;
case PATH_MOTION_TYPE:
source->StopMoving();
if (!m_script->movement.timerOrPassTarget)
source->GetMotionMaster()->MovePath(m_script->movement.wanderORpathId);
else
source->GetMotionMaster()->MovePath(m_script->movement.wanderORpathId, PATH_NO_PATH, ForcedMovement(m_script->textId[0]), false, 0.f, false, pTarget->GetObjectGuid());
break;
}

Expand Down
9 changes: 5 additions & 4 deletions src/game/DBScripts/ScriptMgr.h
Expand Up @@ -39,7 +39,7 @@ enum ScriptCommand // resSource, resTar
SCRIPT_COMMAND_EMOTE = 1, // resSource = Unit, resTarget = Unit/none
// datalong1 = emote_id, dataint1-4 optional for random selected emotes
SCRIPT_COMMAND_FIELD_SET = 2, // source = any, datalong = field_id, datalong2 = value
SCRIPT_COMMAND_MOVE_TO = 3, // resSource = Creature, datalong2 = travel_speed*100, x/y/z
SCRIPT_COMMAND_MOVE_TO = 3, // resSource = Creature, datalong1 = relayId, datalong2 = travel_speed*100, datalong3 = forcedMovement, x/y/z/o
// data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL: teleport unit to position
SCRIPT_COMMAND_FLAG_SET = 4, // source = any, datalong = field_id, datalong2 = bitmask
SCRIPT_COMMAND_FLAG_REMOVE = 5, // source = any, datalong = field_id, datalong2 = bitmask
Expand All @@ -62,7 +62,7 @@ enum ScriptCommand // resSource, resTar
SCRIPT_COMMAND_CREATE_ITEM = 17, // source or target must be player, datalong = item entry, datalong2 = amount
SCRIPT_COMMAND_DESPAWN_SELF = 18, // resSource = Creature, datalong = despawn delay
SCRIPT_COMMAND_PLAY_MOVIE = 19, // target can only be a player, datalog = movie id
SCRIPT_COMMAND_MOVEMENT = 20, // resSource = Creature. datalong = MovementType (0:idle, 1:random or 2:waypoint), datalong2 = wander-distance/pathId, datalong3 = timer
SCRIPT_COMMAND_MOVEMENT = 20, // resSource = Creature. datalong = MovementType (0:idle, 1:random or 2:waypoint), datalong2 = wander-distance/pathId, datalong3 = timer/passTarget, dataint1 = forcedMovement
// data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL = Random-movement around current position
SCRIPT_COMMAND_SET_ACTIVEOBJECT = 21, // resSource = Creature
// datalong=bool 0=off, 1=on
Expand Down Expand Up @@ -180,8 +180,9 @@ struct ScriptInfo

struct // SCRIPT_COMMAND_MOVE_TO (3)
{
uint32 unused1; // datalong
uint32 relayId; // datalong
uint32 travelSpeed; // datalong2
uint32 forcedMovement; // datalong3
} moveTo;

struct // SCRIPT_COMMAND_FLAG_SET (4)
Expand Down Expand Up @@ -282,7 +283,7 @@ struct ScriptInfo
{
uint32 movementType; // datalong
uint32 wanderORpathId; // datalong2
uint32 timer; // datalong3
uint32 timerOrPassTarget; // datalong3
} movement;

struct // SCRIPT_COMMAND_SET_ACTIVEOBJECT (21)
Expand Down
9 changes: 5 additions & 4 deletions src/game/MotionGenerators/MotionMaster.cpp
Expand Up @@ -373,7 +373,7 @@ void MotionMaster::MoveStay(float x, float y, float z, float o, bool asMain)
Mutate(new StayMovementGenerator(x, y, z, o));
}

void MotionMaster::MovePoint(uint32 id, Position const& position, ForcedMovement forcedMovement/* = FORCED_MOVEMENT_NONE*/, float speed/* = 0.f*/, bool generatePath/* = true*/)
void MotionMaster::MovePoint(uint32 id, Position const& position, ForcedMovement forcedMovement/* = FORCED_MOVEMENT_NONE*/, float speed/* = 0.f*/, bool generatePath/* = true*/, ObjectGuid guid/* = ObjectGuid()*/, uint32 relayId/* = 0*/)
{
Mutate(new PointMovementGenerator(id, position.x, position.y, position.z, position.o, generatePath, forcedMovement, speed));
}
Expand Down Expand Up @@ -410,10 +410,10 @@ void MotionMaster::MovePath(std::vector<G3D::Vector3>& path, float o, ForcedMove
Mutate(new FixedPathMovementGenerator(path, o, forcedMovement, flying));
}

void MotionMaster::MovePath(int32 pathId, WaypointPathOrigin wpOrigin /*= PATH_NO_PATH*/, ForcedMovement forcedMovement, bool flying, float speed, bool cyclic)
void MotionMaster::MovePath(int32 pathId, WaypointPathOrigin wpOrigin /*= PATH_NO_PATH*/, ForcedMovement forcedMovement, bool flying, float speed, bool cyclic, ObjectGuid guid/* = ObjectGuid()*/)
{
m_currentPathId = pathId;
Mutate(new FixedPathMovementGenerator(*m_owner, pathId, wpOrigin, forcedMovement, flying, speed, 0, cyclic));
Mutate(new FixedPathMovementGenerator(*m_owner, pathId, wpOrigin, forcedMovement, flying, speed, 0, cyclic, guid));
}

void MotionMaster::MoveRetreat(float x, float y, float z, float o, uint32 delay)
Expand All @@ -435,7 +435,7 @@ void MotionMaster::MoveFleeing(Unit* source, uint32 time)
Mutate(new FleeingMovementGenerator(*source));
}

void MotionMaster::MoveWaypoint(uint32 pathId /*=0*/, uint32 source /*=0==PATH_NO_PATH*/, uint32 initialDelay /*=0*/, uint32 overwriteEntry /*=0*/, ForcedMovement forcedMovement)
void MotionMaster::MoveWaypoint(uint32 pathId /*=0*/, uint32 source /*=0==PATH_NO_PATH*/, uint32 initialDelay /*=0*/, uint32 overwriteEntry /*=0*/, ForcedMovement forcedMovement /*=FORCED_MOVEMENT_NONE*/, ObjectGuid guid/* = ObjectGuid()*/)
{
if (m_owner->GetTypeId() == TYPEID_UNIT)
{
Expand All @@ -451,6 +451,7 @@ void MotionMaster::MoveWaypoint(uint32 pathId /*=0*/, uint32 source /*=0==PATH_N
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s start MoveWaypoint()", m_owner->GetGuidStr().c_str());
WaypointMovementGenerator<Creature>* newWPMMgen = new WaypointMovementGenerator<Creature>(*creature);
newWPMMgen->SetForcedMovement(forcedMovement);
newWPMMgen->SetGuid(guid);
Mutate(newWPMMgen);
newWPMMgen->InitializeWaypointPath(*creature, pathId, (WaypointPathOrigin)source, initialDelay, overwriteEntry);
}
Expand Down
6 changes: 3 additions & 3 deletions src/game/MotionGenerators/MotionMaster.h
Expand Up @@ -138,15 +138,15 @@ class MotionMaster : private std::stack<MovementGenerator*>
void DistanceYourself(float dist);
void MoveConfused();
void MoveFleeing(Unit* enemy, uint32 time = 0);
void MovePoint(uint32 id, Position const& position, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE, float speed = 0.f, bool generatePath = true);
void MovePoint(uint32 id, Position const& position, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE, float speed = 0.f, bool generatePath = true, ObjectGuid guid = ObjectGuid(), uint32 relayId = 0);
void MovePoint(uint32 id, float x, float y, float z, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE, bool generatePath = true);
void MovePointTOL(uint32 id, float x, float y, float z, bool takeOff, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE);
void MovePath(std::vector<G3D::Vector3>& path, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE, bool flying = false);
void MovePath(std::vector<G3D::Vector3>& path, float o, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE, bool flying = false);
// MovePath can not change speed or flying mid path due to how it works - if you wish to do that, split it into two paths
void MovePath(int32 pathId = 0, WaypointPathOrigin wpOrigin = PATH_NO_PATH, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE, bool flying = false, float speed = 0.f, bool cyclic = false);
void MovePath(int32 pathId = 0, WaypointPathOrigin wpOrigin = PATH_NO_PATH, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE, bool flying = false, float speed = 0.f, bool cyclic = false, ObjectGuid guid = ObjectGuid());
void MoveRetreat(float x, float y, float z, float o, uint32 delay);
void MoveWaypoint(uint32 pathId = 0, uint32 source = 0, uint32 initialDelay = 0, uint32 overwriteEntry = 0, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE);
void MoveWaypoint(uint32 pathId = 0, uint32 source = 0, uint32 initialDelay = 0, uint32 overwriteEntry = 0, ForcedMovement forcedMovement = FORCED_MOVEMENT_NONE, ObjectGuid guid = ObjectGuid());
void MoveTaxi();
void MoveDistract(uint32 timer);
void MoveCharge(float x, float y, float z, float speed, uint32 id = EVENT_CHARGE);
Expand Down
8 changes: 4 additions & 4 deletions src/game/MotionGenerators/PathMovementGenerator.cpp
Expand Up @@ -36,8 +36,8 @@ AbstractPathMovementGenerator::AbstractPathMovementGenerator(const Movement::Poi
m_spline.reserve(m_path.size());
}

AbstractPathMovementGenerator::AbstractPathMovementGenerator(const WaypointPath* path, int32 offset/* = 0*/, bool cyclic/* = false*/) :
m_pathIndex(offset), m_orientation(0), m_speedChanged(false), m_cyclic(cyclic), m_firstCycle(false), m_startPoint(0)
AbstractPathMovementGenerator::AbstractPathMovementGenerator(const WaypointPath* path, int32 offset/* = 0*/, bool cyclic/* = false*/, ObjectGuid guid /*= ObjectGuid()*/) :
m_pathIndex(offset), m_orientation(0), m_speedChanged(false), m_cyclic(cyclic), m_firstCycle(false), m_startPoint(0), m_guid(guid)
{
if (!path)
return;
Expand Down Expand Up @@ -225,9 +225,9 @@ void AbstractPathMovementGenerator::MovementInform(Unit& unit)
}
}

FixedPathMovementGenerator::FixedPathMovementGenerator(Unit& creature, int32 pathId, WaypointPathOrigin wpOrigin, ForcedMovement forcedMovement, bool flying, float speed, int32 offset, bool cyclic) :
FixedPathMovementGenerator::FixedPathMovementGenerator(Unit& creature, int32 pathId, WaypointPathOrigin wpOrigin, ForcedMovement forcedMovement, bool flying, float speed, int32 offset, bool cyclic, ObjectGuid guid) :
AbstractPathMovementGenerator((pathId || wpOrigin != PATH_NO_PATH ? sWaypointMgr.GetPathFromOrigin(creature.GetEntry(), creature.GetDbGuid(), pathId, (wpOrigin == PATH_NO_PATH && pathId ? PATH_FROM_ENTRY : wpOrigin))
: sWaypointMgr.GetDefaultPath(creature.GetEntry(), creature.GetDbGuid())), offset, cyclic), m_flying(flying), m_speed(speed), m_forcedMovement(forcedMovement)
: sWaypointMgr.GetDefaultPath(creature.GetEntry(), creature.GetDbGuid())), offset, cyclic, guid), m_flying(flying), m_speed(speed), m_forcedMovement(forcedMovement)
{
}

Expand Down
5 changes: 3 additions & 2 deletions src/game/MotionGenerators/PathMovementGenerator.h
Expand Up @@ -30,7 +30,7 @@ class AbstractPathMovementGenerator : public MovementGenerator
{
public:
explicit AbstractPathMovementGenerator(const Movement::PointsArray& path, float orientation = 0, int32 offset = 0);
explicit AbstractPathMovementGenerator(const WaypointPath* path, int32 offset = 0, bool cyclic = false);
explicit AbstractPathMovementGenerator(const WaypointPath* path, int32 offset = 0, bool cyclic = false, ObjectGuid guid = ObjectGuid());

void Initialize(Unit& owner) override;
void Finalize(Unit& owner) override;
Expand All @@ -52,6 +52,7 @@ class AbstractPathMovementGenerator : public MovementGenerator
bool m_cyclic;
bool m_firstCycle;
uint32 m_startPoint;
ObjectGuid m_guid;

private:
bool m_speedChanged;
Expand All @@ -64,7 +65,7 @@ class FixedPathMovementGenerator : public AbstractPathMovementGenerator
AbstractPathMovementGenerator(path, orientation, offset), m_flying(flying), m_speed(speed), m_forcedMovement(forcedMovement) {}
FixedPathMovementGenerator(const Movement::PointsArray& path, uint32 forcedMovement, bool flying = false, float speed = 0, int32 offset = 0) :
FixedPathMovementGenerator(path, 0, forcedMovement, flying, speed, offset) {}
FixedPathMovementGenerator(Unit& unit, int32 pathId, WaypointPathOrigin wpOrigin, ForcedMovement forcedMovement, bool flying = false, float speed = 0, int32 offset = 0, bool cyclic = false);
FixedPathMovementGenerator(Unit& unit, int32 pathId, WaypointPathOrigin wpOrigin, ForcedMovement forcedMovement, bool flying = false, float speed = 0, int32 offset = 0, bool cyclic = false, ObjectGuid guid = ObjectGuid());
FixedPathMovementGenerator(Creature& creature);

void Initialize(Unit& unit) override;
Expand Down
3 changes: 3 additions & 0 deletions src/game/MotionGenerators/PointMovementGenerator.cpp
Expand Up @@ -122,6 +122,9 @@ void PointMovementGenerator::MovementInform(Unit& unit)
ai->SummonedMovementInform(static_cast<Creature*>(&unit), type, m_id);
}
}

if (m_relayId)
unit.GetMap()->ScriptsStart(sRelayScripts, m_relayId, &unit, m_guid ? unit.GetMap()->GetWorldObject(m_guid) : nullptr);
}

void RetreatMovementGenerator::Initialize(Unit& unit)
Expand Down
7 changes: 5 additions & 2 deletions src/game/MotionGenerators/PointMovementGenerator.h
Expand Up @@ -24,8 +24,9 @@
class PointMovementGenerator : public MovementGenerator
{
public:
PointMovementGenerator(uint32 id, float x, float y, float z, float o, bool generatePath, uint32 forcedMovement, float speed = 0.f) :
m_x(x), m_y(y), m_z(z), m_o(o), m_speed(speed), m_generatePath(generatePath), m_forcedMovement(forcedMovement), m_id(id), m_speedChanged(false) {}
PointMovementGenerator(uint32 id, float x, float y, float z, float o, bool generatePath, uint32 forcedMovement, float speed = 0.f, ObjectGuid guid = ObjectGuid(), uint32 relayId = 0) :
m_x(x), m_y(y), m_z(z), m_o(o), m_speed(speed), m_generatePath(generatePath), m_forcedMovement(forcedMovement), m_id(id), m_speedChanged(false),
m_guid(guid), m_relayId(relayId) {}
PointMovementGenerator(uint32 id, float x, float y, float z, bool generatePath, uint32 forcedMovement, float speed = 0.f) :
PointMovementGenerator(id, x, y, z, 0, generatePath, forcedMovement, speed) {}

Expand All @@ -51,6 +52,8 @@ class PointMovementGenerator : public MovementGenerator
private:
uint32 m_id;
bool m_speedChanged;
ObjectGuid m_guid;
uint32 m_relayId;
};

class RetreatMovementGenerator : public PointMovementGenerator
Expand Down
2 changes: 1 addition & 1 deletion src/game/MotionGenerators/WaypointMovementGenerator.cpp
Expand Up @@ -171,7 +171,7 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
if (node.script_id)
{
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature movement start script %u at point %u for %s.", node.script_id, i_currentNode, creature.GetGuidStr().c_str());
creature.GetMap()->ScriptsStart(sCreatureMovementScripts, node.script_id, &creature, &creature);
creature.GetMap()->ScriptsStart(sCreatureMovementScripts, node.script_id, &creature, m_guid ? creature.GetMap()->GetWorldObject(m_guid) : &creature);
}

// Inform script
Expand Down

0 comments on commit ef15dd2

Please sign in to comment.