From 2ebeb244ec44a416431fcc2073585cbb1c9d0993 Mon Sep 17 00:00:00 2001 From: SaW Date: Sat, 25 Jan 2025 16:30:47 +0100 Subject: [PATCH] Fix bot swimming behavior at the surface and in shallow waters (#908) - Fix for Bots don't swim properly near the surface #903 - Prevents bots teleporting/warping to the surface when in (shallow) waters. --- src/strategy/actions/MovementActions.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index 6b519011..de32bfcb 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -978,11 +978,13 @@ bool MovementAction::Follow(Unit* target, float distance) { return Follow(target void MovementAction::UpdateMovementState() { - if (bot->Unit::IsUnderWater()) + int8 botInLiquidState = bot->GetLiquidData().Status; + + if (botInLiquidState == LIQUID_MAP_IN_WATER || botInLiquidState == LIQUID_MAP_UNDER_WATER) { bot->SetSwim(true); } - else if (!bot->Unit::IsInWater()) + else { bot->SetSwim(false); } @@ -990,18 +992,21 @@ void MovementAction::UpdateMovementState() bool onGround = bot->GetPositionZ() < bot->GetMapWaterOrGroundLevel(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ()) + 1.0f; + // Keep bot->SendMovementFlagUpdate() withing the if statements to not intefere with bot behavior on ground/(shallow) waters if (!bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) && bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) && !onGround) { bot->AddUnitMovementFlag(MOVEMENTFLAG_FLYING); + bot->SendMovementFlagUpdate(); } - if (bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) && + + else if (bot->HasUnitMovementFlag(MOVEMENTFLAG_FLYING) && (!bot->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) || onGround)) { bot->RemoveUnitMovementFlag(MOVEMENTFLAG_FLYING); + bot->SendMovementFlagUpdate(); } - bot->SendMovementFlagUpdate(); // Temporary speed increase in group // if (botAI->HasRealPlayerMaster()) { // bot->SetSpeedRate(MOVE_RUN, 1.1f);