Merge pull request #466 from liyunfan1223/fix-transport

Fix transport movement
This commit is contained in:
Yunfan Li
2024-08-12 14:13:51 +08:00
committed by GitHub
3 changed files with 74 additions and 25 deletions

View File

@@ -827,15 +827,21 @@ bool MovementAction::ReachCombatTo(Unit* target, float distance)
ty = target->GetPositionY(); ty = target->GetPositionY();
tz = target->GetPositionZ(); tz = target->GetPositionZ();
} }
} // Prediction may cause this, which makes ShortenPathUntilDist fail
if (bot->GetExactDist(tx, ty, tz) <= distance) if (bot->GetExactDist(tx, ty, tz) <= distance)
{ {
return false; tx = target->GetPositionX();
ty = target->GetPositionY();
tz = target->GetPositionZ();
} }
}
if (bot->GetExactDist(tx, ty, tz) <= distance)
return false;
PathGenerator path(bot); PathGenerator path(bot);
path.CalculatePath(tx, ty, tz, false); path.CalculatePath(tx, ty, tz, false);
PathType type = path.GetPathType(); PathType type = path.GetPathType();
if (type != PATHFIND_NORMAL && type != PATHFIND_INCOMPLETE) int typeOk = PATHFIND_NORMAL | PATHFIND_INCOMPLETE;
if (!(type & typeOk))
return false; return false;
path.ShortenPathUntilDist(G3D::Vector3(tx, ty, tz), distance); path.ShortenPathUntilDist(G3D::Vector3(tx, ty, tz), distance);
G3D::Vector3 endPos = path.GetPath().back(); 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) bool MovementAction::IsMovingAllowed(uint32 mapId, float x, float y, float z)
{ {
// removed sqrt as means distance limit was effectively 22500 (ReactDistance<63>) // removed sqrt as means distance limit was effectively 22500 (ReactDistance<63>)
// leaving it commented incase we find ReactDistance limit causes problems // leaving it commented incase we find ReactDistance limit causes problems
// float distance = sqrt(bot->GetDistance(x, y, z)); // float distance = sqrt(bot->GetDistance(x, y, z));
float distance = bot->GetDistance(x, y, z); float distance = bot->GetDistance(x, y, z);
@@ -2351,10 +2357,15 @@ bool MoveRandomAction::Execute(Event event)
float angle = (float)rand_norm() * static_cast<float>(M_PI); float angle = (float)rand_norm() * static_cast<float>(M_PI);
x += urand(0, distance) * cos(angle); x += urand(0, distance) * cos(angle);
y += urand(0, distance) * sin(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(), if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(),
bot->GetPositionZ(), x, y, z)) bot->GetPositionZ(), x, y, z))
{ {
continue; x = ox;
y = oy;
z = oz;
} }
if (map->IsInWater(bot->GetPhaseMask(), x, y, z, bot->GetCollisionHeight())) if (map->IsInWater(bot->GetPhaseMask(), x, y, z, bot->GetCollisionHeight()))
continue; continue;

View File

@@ -47,11 +47,14 @@ WorldLocation ArrowFormation::GetLocationInternal()
float x = master->GetPositionX() - masterUnit->GetX() + botUnit->GetX(); float x = master->GetPositionX() - masterUnit->GetX() + botUnit->GetX();
float y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY(); float y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY();
float z = master->GetPositionZ(); float z = master->GetPositionZ();
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z)) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; {
// master->UpdateGroundPositionZ(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); return WorldLocation(master->GetMapId(), x, y, z);
} }

View File

@@ -7,6 +7,7 @@
#include "Arrow.h" #include "Arrow.h"
#include "Event.h" #include "Event.h"
#include "Map.h"
#include "Playerbots.h" #include "Playerbots.h"
#include "ServerFacade.h" #include "ServerFacade.h"
@@ -88,10 +89,14 @@ public:
float x = master->GetPositionX() + cos(angle) * range; float x = master->GetPositionX() + cos(angle) * range;
float y = master->GetPositionY() + sin(angle) * range; float y = master->GetPositionY() + sin(angle) * range;
float z = master->GetPositionZ(); float z = master->GetPositionZ();
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z)) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; {
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); return WorldLocation(master->GetMapId(), x, y, z);
} }
@@ -134,9 +139,15 @@ public:
float x = master->GetPositionX() + cos(angle) * range + dx; float x = master->GetPositionX() + cos(angle) * range + dx;
float y = master->GetPositionY() + sin(angle) * range + dy; float y = master->GetPositionY() + sin(angle) * range + dy;
float z = master->GetPositionZ(); float z = master->GetPositionZ();
if (!master->GetMap()->CheckCollisionAndGetValidCoords( z = bot->GetMapHeight(x, y, z + 5.0f);
master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z)) if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
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);
}
// bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), // bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(),
// bot->GetPositionZ(), x, y, z); // bot->GetPositionZ(), x, y, z);
return WorldLocation(master->GetMapId(), x, y, z); return WorldLocation(master->GetMapId(), x, y, z);
@@ -145,9 +156,15 @@ public:
float x = master->GetPositionX() + cos(angle) * range + dx; float x = master->GetPositionX() + cos(angle) * range + dx;
float y = master->GetPositionY() + sin(angle) * range + dy; float y = master->GetPositionY() + sin(angle) * range + dy;
float z = master->GetPositionZ(); float z = master->GetPositionZ();
z = bot->GetMapHeight(x, y, z + 5.0f);
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z)) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; {
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); return WorldLocation(master->GetMapId(), x, y, z);
} }
@@ -201,8 +218,12 @@ public:
float z = target->GetPositionZ(); float z = target->GetPositionZ();
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z)) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; {
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); return WorldLocation(bot->GetMapId(), x, y, z);
} }
}; };
@@ -362,9 +383,14 @@ public:
if (minDist) if (minDist)
{ {
if (!master->GetMap()->CheckCollisionAndGetValidCoords( if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z)) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; {
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); return WorldLocation(bot->GetMapId(), minX, minY, z);
} }
@@ -373,7 +399,12 @@ public:
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z)) master->GetPositionZ(), x, y, z))
return Formation::NullLocation; {
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); return WorldLocation(bot->GetMapId(), x, y, z);
} }
}; };
@@ -636,7 +667,11 @@ WorldLocation MoveFormation::MoveSingleLine(std::vector<Player*> line, float dif
Player* master = botAI->GetMaster(); Player* master = botAI->GetMaster();
if (!master->GetMap()->CheckCollisionAndGetValidCoords( if (!master->GetMap()->CheckCollisionAndGetValidCoords(
master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz)) master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz))
return Formation::NullLocation; {
lx = x + cos(angle) * radius;
ly = y + sin(angle) * radius;
lz = cz;
}
return WorldLocation(bot->GetMapId(), lx, ly, lz); return WorldLocation(bot->GetMapId(), lx, ly, lz);
} }