From 65579abb47713fa39328a86aa18fd5c15ac000c0 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 12 Aug 2024 02:27:36 +0800 Subject: [PATCH 1/3] Fix transport movement --- src/strategy/actions/MoveToRpgTargetAction.cpp | 2 +- src/strategy/actions/MovementActions.cpp | 18 ++++++++++++------ src/strategy/values/Arrow.cpp | 2 +- src/strategy/values/Formations.cpp | 14 +++++++------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/strategy/actions/MoveToRpgTargetAction.cpp b/src/strategy/actions/MoveToRpgTargetAction.cpp index 9640fc5c..c2bf3446 100644 --- a/src/strategy/actions/MoveToRpgTargetAction.cpp +++ b/src/strategy/actions/MoveToRpgTargetAction.cpp @@ -95,7 +95,7 @@ bool MoveToRpgTargetAction::Execute(Event event) x += cos(angle) * INTERACTION_DISTANCE * distance; y += sin(angle) * INTERACTION_DISTANCE * distance; if (!wo->GetMap()->CheckCollisionAndGetValidCoords(wo, wo->GetPositionX(), wo->GetPositionY(), wo->GetPositionZ(), - x, y, z)) + x, y, z, false)) { x = wo->GetPositionX(); y = wo->GetPositionY(); diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index 149773a7..bc933202 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -820,22 +820,28 @@ bool MovementAction::ReachCombatTo(Unit* target, float distance) tx += targetMoveDist * cos(target->GetOrientation()); ty += targetMoveDist * sin(target->GetOrientation()); if (!target->GetMap()->CheckCollisionAndGetValidCoords(target, target->GetPositionX(), target->GetPositionY(), - target->GetPositionZ(), tx, ty, tz)) + target->GetPositionZ(), tx, ty, tz, false)) { // disable prediction if position is invalid tx = target->GetPositionX(); ty = target->GetPositionY(); tz = target->GetPositionZ(); } + // Prediction may cause this, which makes ShortenPathUntilDist fail + if (bot->GetExactDist(tx, ty, tz) <= distance) + { + tx = target->GetPositionX(); + ty = target->GetPositionY(); + tz = target->GetPositionZ(); + } } if (bot->GetExactDist(tx, ty, tz) <= distance) - { return false; - } PathGenerator path(bot); path.CalculatePath(tx, ty, tz, false); PathType type = path.GetPathType(); - if (type != PATHFIND_NORMAL && type != PATHFIND_INCOMPLETE) + int typeOk = PATHFIND_NORMAL | PATHFIND_INCOMPLETE; + if (!(type & typeOk)) return false; path.ShortenPathUntilDist(G3D::Vector3(tx, ty, tz), distance); G3D::Vector3 endPos = path.GetPath().back(); @@ -881,7 +887,7 @@ bool MovementAction::IsMovingAllowed(Unit* target) bool MovementAction::IsMovingAllowed(uint32 mapId, float x, float y, float z) { - // removed sqrt as means distance limit was effectively 22500 (ReactDistance²) + // removed sqrt as means distance limit was effectively 22500 (ReactDistance�) // leaving it commented incase we find ReactDistance limit causes problems // float distance = sqrt(bot->GetDistance(x, y, z)); float distance = bot->GetDistance(x, y, z); @@ -2352,7 +2358,7 @@ bool MoveRandomAction::Execute(Event event) x += urand(0, distance) * cos(angle); y += urand(0, distance) * sin(angle); if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), - bot->GetPositionZ(), x, y, z)) + bot->GetPositionZ(), x, y, z, false)) { continue; } diff --git a/src/strategy/values/Arrow.cpp b/src/strategy/values/Arrow.cpp index a981eade..12926225 100644 --- a/src/strategy/values/Arrow.cpp +++ b/src/strategy/values/Arrow.cpp @@ -49,7 +49,7 @@ WorldLocation ArrowFormation::GetLocationInternal() float z = master->GetPositionZ(); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + master->GetPositionZ(), x, y, z, false)) return Formation::NullLocation; // master->UpdateGroundPositionZ(x, y, z); return WorldLocation(master->GetMapId(), x, y, z); diff --git a/src/strategy/values/Formations.cpp b/src/strategy/values/Formations.cpp index 9418b441..8464141a 100644 --- a/src/strategy/values/Formations.cpp +++ b/src/strategy/values/Formations.cpp @@ -90,7 +90,7 @@ public: float z = master->GetPositionZ(); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + master->GetPositionZ(), x, y, z, false)) return Formation::NullLocation; return WorldLocation(master->GetMapId(), x, y, z); } @@ -135,7 +135,7 @@ public: float y = master->GetPositionY() + sin(angle) * range + dy; float z = master->GetPositionZ(); if (!master->GetMap()->CheckCollisionAndGetValidCoords( - master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z)) + master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z, false)) return Formation::NullLocation; // bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), // bot->GetPositionZ(), x, y, z); @@ -146,7 +146,7 @@ public: float y = master->GetPositionY() + sin(angle) * range + dy; float z = master->GetPositionZ(); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + master->GetPositionZ(), x, y, z, false)) return Formation::NullLocation; return WorldLocation(master->GetMapId(), x, y, z); } @@ -200,7 +200,7 @@ public: float y = target->GetPositionY() + sin(angle) * range; float z = target->GetPositionZ(); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + master->GetPositionZ(), x, y, z, false)) return Formation::NullLocation; return WorldLocation(bot->GetMapId(), x, y, z); @@ -363,7 +363,7 @@ public: if (minDist) { if (!master->GetMap()->CheckCollisionAndGetValidCoords( - master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z)) + master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z, false)) return Formation::NullLocation; return WorldLocation(bot->GetMapId(), minX, minY, z); } @@ -372,7 +372,7 @@ public: } if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z)) + master->GetPositionZ(), x, y, z, false)) return Formation::NullLocation; return WorldLocation(bot->GetMapId(), x, y, z); } @@ -635,7 +635,7 @@ WorldLocation MoveFormation::MoveSingleLine(std::vector line, float dif Player* master = botAI->GetMaster(); if (!master->GetMap()->CheckCollisionAndGetValidCoords( - master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz)) + master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz, false)) return Formation::NullLocation; return WorldLocation(bot->GetMapId(), lx, ly, lz); From d3b10417199c7d05cbf5255c1fa26c1fd029a52d Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 12 Aug 2024 11:07:14 +0800 Subject: [PATCH 2/3] Fix movement on transport --- src/strategy/values/Arrow.cpp | 11 +++-- src/strategy/values/Formations.cpp | 71 ++++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/src/strategy/values/Arrow.cpp b/src/strategy/values/Arrow.cpp index 12926225..f52dc670 100644 --- a/src/strategy/values/Arrow.cpp +++ b/src/strategy/values/Arrow.cpp @@ -47,11 +47,14 @@ WorldLocation ArrowFormation::GetLocationInternal() float x = master->GetPositionX() - masterUnit->GetX() + botUnit->GetX(); float y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY(); float z = master->GetPositionZ(); - if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z, false)) - return Formation::NullLocation; - // master->UpdateGroundPositionZ(x, y, z); + master->GetPositionZ(), x, y, z)) + { + x = master->GetPositionX() - masterUnit->GetX() + botUnit->GetX(); + y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY(); + z = master->GetPositionZ() + master->GetHoverHeight(); + z = master->GetMapHeight(x, y, z); + } return WorldLocation(master->GetMapId(), x, y, z); } diff --git a/src/strategy/values/Formations.cpp b/src/strategy/values/Formations.cpp index 8464141a..61ec1b3d 100644 --- a/src/strategy/values/Formations.cpp +++ b/src/strategy/values/Formations.cpp @@ -7,6 +7,7 @@ #include "Arrow.h" #include "Event.h" +#include "Map.h" #include "Playerbots.h" #include "ServerFacade.h" @@ -88,10 +89,14 @@ public: float x = master->GetPositionX() + cos(angle) * range; float y = master->GetPositionY() + sin(angle) * range; float z = master->GetPositionZ(); - if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z, false)) - return Formation::NullLocation; + master->GetPositionZ(), x, y, z)) + { + x = master->GetPositionX() + cos(angle) * range; + y = master->GetPositionY() + sin(angle) * range; + z = master->GetPositionZ() + master->GetHoverHeight(); + master->UpdateAllowedPositionZ(x, y, z); + } return WorldLocation(master->GetMapId(), x, y, z); } @@ -134,9 +139,15 @@ public: float x = master->GetPositionX() + cos(angle) * range + dx; float y = master->GetPositionY() + sin(angle) * range + dy; float z = master->GetPositionZ(); - if (!master->GetMap()->CheckCollisionAndGetValidCoords( - master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z, false)) - return Formation::NullLocation; + z = bot->GetMapHeight(x, y, z + 5.0f); + if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), + master->GetPositionZ(), x, y, z)) + { + x = master->GetPositionX() + cos(angle) * range + dx; + y = master->GetPositionY() + sin(angle) * range + dy; + z = master->GetPositionZ() + master->GetHoverHeight(); + z = master->GetMapHeight(x, y, z); + } // bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), // bot->GetPositionZ(), x, y, z); return WorldLocation(master->GetMapId(), x, y, z); @@ -145,9 +156,15 @@ public: float x = master->GetPositionX() + cos(angle) * range + dx; float y = master->GetPositionY() + sin(angle) * range + dy; float z = master->GetPositionZ(); + z = bot->GetMapHeight(x, y, z + 5.0f); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z, false)) - return Formation::NullLocation; + master->GetPositionZ(), x, y, z)) + { + x = master->GetPositionX() + cos(angle) * range + dx; + y = master->GetPositionY() + sin(angle) * range + dy; + z = master->GetPositionZ() + master->GetHoverHeight(); + z = master->GetMapHeight(x, y, z); + } return WorldLocation(master->GetMapId(), x, y, z); } @@ -200,9 +217,13 @@ public: float y = target->GetPositionY() + sin(angle) * range; float z = target->GetPositionZ(); if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z, false)) - return Formation::NullLocation; - + master->GetPositionZ(), x, y, z)) + { + x = target->GetPositionX() + cos(angle) * range; + y = target->GetPositionY() + sin(angle) * range; + z = target->GetPositionZ() + target->GetHoverHeight(); + z = master->GetMapHeight(x, y, z); + } return WorldLocation(bot->GetMapId(), x, y, z); } }; @@ -362,9 +383,14 @@ public: if (minDist) { - if (!master->GetMap()->CheckCollisionAndGetValidCoords( - master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z, false)) - return Formation::NullLocation; + if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), + master->GetPositionZ(), x, y, z)) + { + x = master->GetPositionX() + cos(angle) * range + cos(followAngle) * followRange; + y = master->GetPositionY() + sin(angle) * range + sin(followAngle) * followRange; + z = master->GetPositionZ() + master->GetHoverHeight(); + z = master->GetMapHeight(x, y, z); + } return WorldLocation(bot->GetMapId(), minX, minY, z); } @@ -372,8 +398,13 @@ public: } if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), - master->GetPositionZ(), x, y, z, false)) - return Formation::NullLocation; + master->GetPositionZ(), x, y, z)) + { + x = master->GetPositionX() + cos(angle) * range + cos(followAngle) * followRange; + y = master->GetPositionY() + sin(angle) * range + sin(followAngle) * followRange; + z = master->GetPositionZ() + master->GetHoverHeight(); + z = master->GetMapHeight(x, y, z); + } return WorldLocation(bot->GetMapId(), x, y, z); } }; @@ -635,8 +666,12 @@ WorldLocation MoveFormation::MoveSingleLine(std::vector line, float dif Player* master = botAI->GetMaster(); if (!master->GetMap()->CheckCollisionAndGetValidCoords( - master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz, false)) - return Formation::NullLocation; + master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz)) + { + lx = x + cos(angle) * radius; + ly = y + sin(angle) * radius; + lz = cz; + } return WorldLocation(bot->GetMapId(), lx, ly, lz); } From 2b35aeb0495952bc76f4354e7597e027eb4626ef Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 12 Aug 2024 11:52:33 +0800 Subject: [PATCH 3/3] Collision check in movement --- src/strategy/actions/MoveToRpgTargetAction.cpp | 2 +- src/strategy/actions/MovementActions.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/strategy/actions/MoveToRpgTargetAction.cpp b/src/strategy/actions/MoveToRpgTargetAction.cpp index c2bf3446..9640fc5c 100644 --- a/src/strategy/actions/MoveToRpgTargetAction.cpp +++ b/src/strategy/actions/MoveToRpgTargetAction.cpp @@ -95,7 +95,7 @@ bool MoveToRpgTargetAction::Execute(Event event) x += cos(angle) * INTERACTION_DISTANCE * distance; y += sin(angle) * INTERACTION_DISTANCE * distance; if (!wo->GetMap()->CheckCollisionAndGetValidCoords(wo, wo->GetPositionX(), wo->GetPositionY(), wo->GetPositionZ(), - x, y, z, false)) + x, y, z)) { x = wo->GetPositionX(); y = wo->GetPositionY(); diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index bc933202..ea460bc1 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -820,7 +820,7 @@ bool MovementAction::ReachCombatTo(Unit* target, float distance) tx += targetMoveDist * cos(target->GetOrientation()); ty += targetMoveDist * sin(target->GetOrientation()); if (!target->GetMap()->CheckCollisionAndGetValidCoords(target, target->GetPositionX(), target->GetPositionY(), - target->GetPositionZ(), tx, ty, tz, false)) + target->GetPositionZ(), tx, ty, tz)) { // disable prediction if position is invalid tx = target->GetPositionX(); @@ -2357,10 +2357,15 @@ bool MoveRandomAction::Execute(Event event) float angle = (float)rand_norm() * static_cast(M_PI); x += urand(0, distance) * cos(angle); y += urand(0, distance) * sin(angle); + float ox = x; + float oy = y; + float oz = z; if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), - bot->GetPositionZ(), x, y, z, false)) + bot->GetPositionZ(), x, y, z)) { - continue; + x = ox; + y = oy; + z = oz; } if (map->IsInWater(bot->GetPhaseMask(), x, y, z, bot->GetCollisionHeight())) continue;