Skip to content

Commit 5f697e8

Browse files
authored
Rerwite is moving allowed logic + fix root flag heartbeat spam (mod-playerbots#1908)
Okay, what have been done: 1. Fix heartbeat spam for root flag: check against `MOVEMENTFLAG_ROOT` flag (`IsRooted`) instead of `HasRootAura`. 2. Rewrite `IsMovingAllowed` - place checks from most common to the rarest. 3. Remove unnecessary checks: `HasRootAura`, `HasConfuseAura`, `HasStunAura` - handled by AuraEffects and set unit state flags `UNIT_STATE_ROOT`, `UNIT_STATE_CONFUSED`, `UNIT_STATE_STUNNED` - `UNIT_STATE_LOST_CONTROL` already handles confused and stunned (rooted checked with `IsRooted` method). 4. Combine traveling state checks for taxi flights: `UNIT_STATE_IN_FLIGHT` + MM flag `FLIGHT_MOTION_TYPE`. 5. Simplify check against being in vehicle: use `MOVEMENTFLAG_ONTRANSPORT` as an indicator that the unit is in the vehicle. Also, update `UpdateMovementState` method with simplified checks and the updated logic (common > rare). This should fix issues: mod-playerbots#1903 and mod-playerbots#1902 NOTE: The `PlayerbotAI` class has a method `CanMove` with the same checks, but this method is only used once in the code. We should decide how to properly check if the bot can move or not: 1. Place all logic into `IsMovingAllowed` and drop `CanMove`. 2. Place all logic into `CanMove` and use it inside `IsMovingAllowed`. 3. Use them for different approaches: - `CanMove`: simple checks (unit flags, CC state, death state, travel state, vehicle state); - `IsMovingAllowed`: everything from `CanMove` + MM flags checks (not sure about rooted since it still checks for movement flags...).
1 parent 934e73a commit 5f697e8

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

src/strategy/actions/MovementActions.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -946,38 +946,48 @@ bool MovementAction::IsWaitingForLastMove(MovementPriority priority)
946946

947947
bool MovementAction::IsMovingAllowed()
948948
{
949-
// do not allow if not vehicle driver
950-
if (botAI->IsInVehicle() && !botAI->IsInVehicle(true))
949+
// Most common checks: confused, stunned, fleeing, jumping, charging. All these
950+
// states are set when handling certain aura effects. We don't check against
951+
// UNIT_STATE_ROOT here, because this state is used by vehicles.
952+
if (bot->HasUnitState(UNIT_STATE_LOST_CONTROL))
951953
return false;
952954

953-
if (bot->isFrozen() || bot->IsPolymorphed() || (bot->isDead() && !bot->HasPlayerFlag(PLAYER_FLAGS_GHOST)) ||
954-
bot->IsBeingTeleported() || bot->HasRootAura() || bot->HasSpiritOfRedemptionAura() || bot->HasConfuseAura() ||
955-
bot->IsCharmed() || bot->HasStunAura() || bot->IsInFlight() || bot->HasUnitState(UNIT_STATE_LOST_CONTROL))
955+
// Death state (w/o spirit release) and Spirit of Redemption aura (priest)
956+
if ((bot->isDead() && !bot->HasPlayerFlag(PLAYER_FLAGS_GHOST)) || bot->HasSpiritOfRedemptionAura())
957+
return false;
958+
959+
// Common CC effects, ordered by frequency: rooted > frozen > polymorphed
960+
if (bot->IsRooted() || bot->isFrozen() || bot->IsPolymorphed())
956961
return false;
957962

963+
// Check for the MM controlled slot types: feared, confused, fleeing, etc.
958964
if (bot->GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_CONTROLLED) != NULL_MOTION_TYPE)
959-
{
960965
return false;
961-
}
962966

963-
// if (bot->HasUnitMovementFlag(MOVEMENTFLAG_FALLING))
964-
// {
965-
// return false;
966-
// }
967-
return bot->GetMotionMaster()->GetCurrentMovementGeneratorType() != FLIGHT_MOTION_TYPE;
967+
// Traveling state: taxi flight and being teleported (relatively rare)
968+
if (bot->IsInFlight() || bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE ||
969+
bot->IsBeingTeleported())
970+
return false;
971+
972+
// Vehicle state: is in the vehicle and can control it (rare, content-specific).
973+
// We need to check charmed state AFTER vehicle one, cuz that's how it works:
974+
// passengers are set to charmed by vehicle with CHARM_TYPE_VEHICLE.
975+
if ((bot->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && !botAI->IsInVehicle(true)) ||
976+
bot->IsCharmed())
977+
return false;
978+
979+
return true;
968980
}
969981

970982
bool MovementAction::Follow(Unit* target, float distance) { return Follow(target, distance, GetFollowAngle()); }
971983

972984
void MovementAction::UpdateMovementState()
973985
{
974986
const bool isCurrentlyRestricted = // see if the bot is currently slowed, rooted, or otherwise unable to move
987+
bot->HasUnitState(UNIT_STATE_LOST_CONTROL) ||
988+
bot->IsRooted() ||
975989
bot->isFrozen() ||
976-
bot->IsPolymorphed() ||
977-
bot->HasRootAura() ||
978-
bot->HasStunAura() ||
979-
bot->HasConfuseAura() ||
980-
bot->HasUnitState(UNIT_STATE_LOST_CONTROL);
990+
bot->IsPolymorphed();
981991

982992
// no update movement flags while movement is current restricted.
983993
if (!isCurrentlyRestricted && bot->IsAlive())

0 commit comments

Comments
 (0)