Merge branch 'liyunfan1223:master' into oil_fix

This commit is contained in:
Atidote
2024-08-11 10:00:13 +02:00
committed by GitHub
5 changed files with 56 additions and 59 deletions

View File

@@ -2566,7 +2566,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, float x, float y, float z, uint8
if (!itemTarget) if (!itemTarget)
{ {
if (sqrt(bot->GetDistance(x, y, z)) > sPlayerbotAIConfig->sightDistance) if (bot->GetDistance(x, y, z) > sPlayerbotAIConfig->sightDistance)
return false; return false;
} }
@@ -3096,21 +3096,9 @@ bool PlayerbotAI::CastVehicleSpell(uint32 spellId, Unit* target)
targets.SetDst(dest); targets.SetDst(dest);
targets.SetSpeed(30.0f); targets.SetSpeed(30.0f);
float distanceToDest = sqrt(vehicleBase->GetPosition().GetExactDist(dest)); float dist = vehicleBase->GetPosition().GetExactDist(dest);
float elev = 0.01f; // very much an approximation of the real projectile arc
if (distanceToDest < 25.0f) float elev = dist >= 110.0f ? 1.0f : pow(((dist + 10.0f) / 120.0f), 2.0f);
elev = 0.04f;
else if (distanceToDest < 55.0f)
elev = 0.22f;
else if (distanceToDest < 85.0f)
elev = 0.42f;
else if (distanceToDest < 95.0f)
elev = 0.70f;
else if (distanceToDest < 110.0f)
elev = 0.88f;
else
elev = 1.0f;
targets.SetElevation(elev); targets.SetElevation(elev);
} }

View File

@@ -34,7 +34,7 @@ bool ReachAreaTriggerAction::Execute(Event event)
return true; return true;
} }
if (bot->GetMapId() != at->map || sqrt(bot->GetDistance(at->x, at->y, at->z)) > sPlayerbotAIConfig->sightDistance) if (bot->GetMapId() != at->map)
{ {
botAI->TellError("I won't follow: too far away"); botAI->TellError("I won't follow: too far away");
return true; return true;
@@ -42,7 +42,7 @@ bool ReachAreaTriggerAction::Execute(Event event)
bot->GetMotionMaster()->MovePoint(at->map, at->x, at->y, at->z); bot->GetMotionMaster()->MovePoint(at->map, at->x, at->y, at->z);
float distance = sqrt(bot->GetDistance(at->x, at->y, at->z)); float distance = bot->GetDistance(at->x, at->y, at->z);
float delay = 1000.0f * distance / bot->GetSpeed(MOVE_RUN) + sPlayerbotAIConfig->reactDelay; float delay = 1000.0f * distance / bot->GetSpeed(MOVE_RUN) + sPlayerbotAIConfig->reactDelay;
botAI->TellError("Wait for me"); botAI->TellError("Wait for me");
botAI->SetNextCheckDelay(delay); botAI->SetNextCheckDelay(delay);

View File

@@ -2617,8 +2617,8 @@ bool BGTactics::selectObjective(bool reset)
{ {
if (GameObject* pGO = bg->GetBGObject(AV_HordeAttackObjectives[0].second)) if (GameObject* pGO = bg->GetBGObject(AV_HordeAttackObjectives[0].second))
{ {
float const distance = sqrt(bot->GetDistance(pGO)); float const distance = bot->GetDistance(pGO);
if (distance < 20.0f) if (distance < 400.0f)
BgObjective = pGO; BgObjective = pGO;
} }
} }
@@ -2638,7 +2638,7 @@ bool BGTactics::selectObjective(bool reset)
{ {
if (GameObject* pGO = bg->GetBGObject(objective.second)) if (GameObject* pGO = bg->GetBGObject(objective.second))
{ {
float const distance = sqrt(bot->GetDistance(pGO)); float const distance = bot->GetDistance(pGO);
if (attackObjectiveDistance > distance) if (attackObjectiveDistance > distance)
{ {
BgObjective = pGO; BgObjective = pGO;
@@ -2808,8 +2808,8 @@ bool BGTactics::selectObjective(bool reset)
{ {
if (GameObject* pGO = bg->GetBGObject(AV_AllianceAttackObjectives[0].second)) if (GameObject* pGO = bg->GetBGObject(AV_AllianceAttackObjectives[0].second))
{ {
float const distance = sqrt(bot->GetDistance(pGO)); float const distance = bot->GetDistance(pGO);
if (distance < 20.0f) if (distance < 400.0f)
BgObjective = pGO; BgObjective = pGO;
} }
} }
@@ -2829,7 +2829,7 @@ bool BGTactics::selectObjective(bool reset)
{ {
if (GameObject* pGO = bg->GetBGObject(objective.second)) if (GameObject* pGO = bg->GetBGObject(objective.second))
{ {
float const distance = sqrt(bot->GetDistance(pGO)); float const distance = bot->GetDistance(pGO);
if (attackObjectiveDistance > distance) if (attackObjectiveDistance > distance)
{ {
BgObjective = pGO; BgObjective = pGO;
@@ -3022,7 +3022,7 @@ bool BGTactics::selectObjective(bool reset)
{ {
if (GameObject* pGO = bg->GetBGObject(objective * BG_AB_OBJECTS_PER_NODE)) if (GameObject* pGO = bg->GetBGObject(objective * BG_AB_OBJECTS_PER_NODE))
{ {
float const distance = sqrt(bot->GetDistance(pGO)); float const distance = bot->GetDistance(pGO);
if (attackObjectiveDistance > distance) if (attackObjectiveDistance > distance)
{ {
// do not pick if already in list // do not pick if already in list
@@ -3071,7 +3071,7 @@ bool BGTactics::selectObjective(bool reset)
{ {
if (GameObject* pGO = bg->GetBGObject(objective * BG_AB_OBJECTS_PER_NODE)) if (GameObject* pGO = bg->GetBGObject(objective * BG_AB_OBJECTS_PER_NODE))
{ {
float const distance = sqrt(bot->GetDistance(pGO)); float const distance = bot->GetDistance(pGO);
if (attackObjectiveDistance > distance) if (attackObjectiveDistance > distance)
{ {
// do not pick if already in list // do not pick if already in list
@@ -3133,14 +3133,15 @@ bool BGTactics::selectObjective(bool reset)
uint8 ownership = pointOwner == bot->GetTeamId() ? 2 : pointOwner == TEAM_NEUTRAL ? 1 : 0; uint8 ownership = pointOwner == bot->GetTeamId() ? 2 : pointOwner == TEAM_NEUTRAL ? 1 : 0;
if (closestObjectiveOwnership > ownership) if (closestObjectiveOwnership > ownership)
continue; continue;
float dist = sqrt(bot->GetDistance(go)); float dist = bot->GetDistance(go);
// select objective when ownership is better
// or distance difference is significantly better
// or distance difference is insignificantly better and coinflip
// the reason it doesn't just check if distance is better is to avoid bot going to same point every time
if (closestObjectiveOwnership < ownership || if (closestObjectiveOwnership < ownership ||
(closestObjectiveDist > dist && closestObjectiveDist - 30 > dist ||
(closestObjectiveDist - dist > 1 || (closestObjectiveDist > dist && urand(0, 1)))
urand(
0,
1)))) // if distance difference is minor (as it will be when they first pick flag up
// from middle) add some randomness so its not going to same point every time
{ {
closestObjectiveOwnership = ownership; closestObjectiveOwnership = ownership;
closestObjectiveDist = dist; closestObjectiveDist = dist;
@@ -3397,10 +3398,9 @@ bool BGTactics::selectObjective(bool reset)
} }
else // target gate directly at range if other vehicle else // target gate directly at range if other vehicle
{ {
// take a siege position // just make bot stay where it is if already close
if (sqrt(bot->GetDistance(IC_GATE_ATTACK_POS_HORDE)) < // (stops them shifting around between the random spots)
5.0f) // just make bot stay where it is (stops them shifting around to the random if (bot->GetDistance(IC_GATE_ATTACK_POS_HORDE) < 8.0f)
// spots)
pos.Set(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), bot->GetMapId()); pos.Set(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), bot->GetMapId());
else else
pos.Set(IC_GATE_ATTACK_POS_HORDE.GetPositionX() + frand(-5.0f, +5.0f), pos.Set(IC_GATE_ATTACK_POS_HORDE.GetPositionX() + frand(-5.0f, +5.0f),
@@ -3486,10 +3486,10 @@ bool BGTactics::selectObjective(bool reset)
} }
} }
if (!BgObjective) // guard vehicles as they seige if (!BgObjective) // guard vehicles as they seige
{ {
if (sqrt(bot->GetDistance(IC_GATE_ATTACK_POS_HORDE)) < // just make bot stay where it is if already close
5.0f) // just make bot stay where it is (stops them shifting around to the random spots) // (stops them shifting around between the random spots)
if (bot->GetDistance(IC_GATE_ATTACK_POS_HORDE) < 8.0f)
pos.Set(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), bot->GetMapId()); pos.Set(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), bot->GetMapId());
else else
pos.Set(IC_GATE_ATTACK_POS_HORDE.GetPositionX() + frand(-5.0f, +5.0f), pos.Set(IC_GATE_ATTACK_POS_HORDE.GetPositionX() + frand(-5.0f, +5.0f),
@@ -3550,10 +3550,9 @@ bool BGTactics::selectObjective(bool reset)
} }
else // target gate directly at range if other vehicle else // target gate directly at range if other vehicle
{ {
// take a siege position // just make bot stay where it is if already close
if (sqrt(bot->GetDistance(IC_GATE_ATTACK_POS_ALLIANCE)) < // (stops them shifting around between the random spots)
5.0f) // just make bot stay where it is (stops them shifting around to the random if (bot->GetDistance(IC_GATE_ATTACK_POS_ALLIANCE) < 8.0f)
// spots)
pos.Set(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), bot->GetMapId()); pos.Set(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), bot->GetMapId());
else else
pos.Set(IC_GATE_ATTACK_POS_ALLIANCE.GetPositionX() + frand(-5.0f, +5.0f), pos.Set(IC_GATE_ATTACK_POS_ALLIANCE.GetPositionX() + frand(-5.0f, +5.0f),
@@ -3640,8 +3639,9 @@ bool BGTactics::selectObjective(bool reset)
} }
if (!BgObjective) // guard vehicles as they seige if (!BgObjective) // guard vehicles as they seige
{ {
if (sqrt(bot->GetDistance(IC_GATE_ATTACK_POS_ALLIANCE)) < // just make bot stay where it is if already close
5.0f) // just make bot stay where it is (stops them shifting around to the random spots) // (stops them shifting around between the random spots)
if (bot->GetDistance(IC_GATE_ATTACK_POS_ALLIANCE) < 8.0f)
pos.Set(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), bot->GetMapId()); pos.Set(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), bot->GetMapId());
else else
pos.Set(IC_GATE_ATTACK_POS_ALLIANCE.GetPositionX() + frand(-5.0f, +5.0f), pos.Set(IC_GATE_ATTACK_POS_ALLIANCE.GetPositionX() + frand(-5.0f, +5.0f),
@@ -3700,7 +3700,7 @@ bool BGTactics::moveToObjective()
} }
// don't try to move if already close // don't try to move if already close
if (sqrt(bot->GetDistance(pos.x, pos.y, pos.z)) < 2.0f) if (bot->GetDistance(pos.x, pos.y, pos.z) < 4.0f)
{ {
resetObjective(); resetObjective();
@@ -3714,9 +3714,8 @@ bool BGTactics::moveToObjective()
if (bgType == BATTLEGROUND_WS) if (bgType == BATTLEGROUND_WS)
return MoveTo(bot->GetMapId(), pos.x, pos.y, pos.z); return MoveTo(bot->GetMapId(), pos.x, pos.y, pos.z);
else else
return MoveNear(bot->GetMapId(), pos.x, pos.y, pos.z, // dont increase from 1.5 will cause bugs with horde capping AV towers
1.5f); // note - don't make distance too large or horde bots may struggle to get flags in return MoveNear(bot->GetMapId(), pos.x, pos.y, pos.z, 1.5f);
// alliance AV towers (because they'll be targetting a spot in midair)
} }
return false; return false;
} }
@@ -3745,7 +3744,7 @@ bool BGTactics::selectObjectiveWp(std::vector<BattleBotPath*> const& vPaths)
// get bots out of cave when they respawn there (otherwise path selection happens while they're deep within cave // get bots out of cave when they respawn there (otherwise path selection happens while they're deep within cave
// and the results arent good) // and the results arent good)
Position const caveSpawn = bot->GetTeamId() == TEAM_ALLIANCE ? AV_CAVE_SPAWN_ALLIANCE : AV_CAVE_SPAWN_HORDE; Position const caveSpawn = bot->GetTeamId() == TEAM_ALLIANCE ? AV_CAVE_SPAWN_ALLIANCE : AV_CAVE_SPAWN_HORDE;
if (sqrt(bot->GetDistance(caveSpawn)) < 4.0f) if (bot->GetDistance(caveSpawn) < 16.0f)
{ {
return moveToStart(true); return moveToStart(true);
} }
@@ -3793,6 +3792,12 @@ bool BGTactics::selectObjectiveWp(std::vector<BattleBotPath*> const& vPaths)
std::find(vPaths_HordeMine.begin(), vPaths_HordeMine.end(), path) != vPaths_HordeMine.end()) std::find(vPaths_HordeMine.begin(), vPaths_HordeMine.end(), path) != vPaths_HordeMine.end())
continue; continue;
// TODO need to remove sqrt from these two and distToBot but it totally throws path scoring out of
// whack if you do that without changing how its implemented (I'm amazed it works as well as it does
// using sqrt'ed distances)
// In a reworked version maybe compare the differences of path distances to point (ie: against best path)
// or maybe ratio's (where if a path end is twice the difference in distance from destination we basically
// use that to multiply the total score?
BattleBotWaypoint& startPoint = ((*path)[0]); BattleBotWaypoint& startPoint = ((*path)[0]);
float const startPointDistToDestination = float const startPointDistToDestination =
sqrt(Position(pos.x, pos.y, pos.z, 0.f).GetExactDist(startPoint.x, startPoint.y, startPoint.z)); sqrt(Position(pos.x, pos.y, pos.z, 0.f).GetExactDist(startPoint.x, startPoint.y, startPoint.z));
@@ -3958,6 +3963,7 @@ bool BGTactics::startNewPathBegin(std::vector<BattleBotPath*> const& vPaths)
std::find(vPaths_HordeMine.begin(), vPaths_HordeMine.end(), pPath) != vPaths_HordeMine.end()) std::find(vPaths_HordeMine.begin(), vPaths_HordeMine.end(), pPath) != vPaths_HordeMine.end())
continue; continue;
// TODO remove sqrt
BattleBotWaypoint* pStart = &((*pPath)[0]); BattleBotWaypoint* pStart = &((*pPath)[0]);
if (sqrt(bot->GetDistance(pStart->x, pStart->y, pStart->z)) < INTERACTION_DISTANCE) if (sqrt(bot->GetDistance(pStart->x, pStart->y, pStart->z)) < INTERACTION_DISTANCE)
availablePaths.emplace_back(AvailablePath(pPath, false)); availablePaths.emplace_back(AvailablePath(pPath, false));
@@ -3967,6 +3973,7 @@ bool BGTactics::startNewPathBegin(std::vector<BattleBotPath*> const& vPaths)
vPaths_NoReverseAllowed.end()) vPaths_NoReverseAllowed.end())
continue; continue;
// TODO remove sqrt
BattleBotWaypoint* pEnd = &((*pPath)[(*pPath).size() - 1]); BattleBotWaypoint* pEnd = &((*pPath)[(*pPath).size() - 1]);
if (sqrt(bot->GetDistance(pEnd->x, pEnd->y, pEnd->z)) < INTERACTION_DISTANCE) if (sqrt(bot->GetDistance(pEnd->x, pEnd->y, pEnd->z)) < INTERACTION_DISTANCE)
availablePaths.emplace_back(AvailablePath(pPath, true)); availablePaths.emplace_back(AvailablePath(pPath, true));
@@ -4016,6 +4023,7 @@ bool BGTactics::startNewPathFree(std::vector<BattleBotPath*> const& vPaths)
for (uint32 i = 0; i < pPath->size(); i++) for (uint32 i = 0; i < pPath->size(); i++)
{ {
BattleBotWaypoint& waypoint = ((*pPath)[i]); BattleBotWaypoint& waypoint = ((*pPath)[i]);
// TODO remove sqrt
float const distanceToPoint = sqrt(bot->GetDistance(waypoint.x, waypoint.y, waypoint.z)); float const distanceToPoint = sqrt(bot->GetDistance(waypoint.x, waypoint.y, waypoint.z));
if (distanceToPoint < closestDistance) if (distanceToPoint < closestDistance)
{ {
@@ -4048,7 +4056,7 @@ bool BGTactics::atFlag(std::vector<BattleBotPath*> const& vPaths, std::vector<ui
GuidVector closeObjects; GuidVector closeObjects;
GuidVector closePlayers; GuidVector closePlayers;
float flagRange; float flagRange = 0.0f;
switch (bgType) switch (bgType)
{ {
@@ -4110,7 +4118,7 @@ bool BGTactics::atFlag(std::vector<BattleBotPath*> const& vPaths, std::vector<ui
if (!bot->CanUseBattlegroundObject(go) && bgType != BATTLEGROUND_WS) if (!bot->CanUseBattlegroundObject(go) && bgType != BATTLEGROUND_WS)
continue; continue;
float const dist = sqrt(bot->GetDistance(go)); float const dist = bot->GetDistance(go);
if (flagRange && dist > flagRange) if (flagRange && dist > flagRange)
continue; continue;
@@ -4422,7 +4430,7 @@ bool BGTactics::IsLockedInsideKeep()
// ALLIANCE // ALLIANCE
if (bot->GetTeamId() == TEAM_ALLIANCE) if (bot->GetTeamId() == TEAM_ALLIANCE)
{ {
if (GameObject* go = bg->GetBGObject(BG_IC_GO_DOODAD_PORTCULLISACTIVE01)) if (GameObject* go = bg->GetBGObject(BG_IC_GO_DOODAD_PORTCULLISACTIVE02))
{ {
if (go->isSpawned()) if (go->isSpawned())
{ {

View File

@@ -294,7 +294,7 @@ bool ChooseRpgTargetAction::isFollowValid(Player* bot, WorldPosition pos)
if (!botAI->HasStrategy("follow", BOT_STATE_NON_COMBAT)) if (!botAI->HasStrategy("follow", BOT_STATE_NON_COMBAT))
return true; return true;
if (sqrt(bot->GetDistance(master)) > sPlayerbotAIConfig->rpgDistance * 2) if (bot->GetDistance(master) > sPlayerbotAIConfig->rpgDistance * 2)
return false; return false;
Formation* formation = AI_VALUE(Formation*, "formation"); Formation* formation = AI_VALUE(Formation*, "formation");

View File

@@ -66,7 +66,6 @@ void MovementAction::JumpTo(uint32 mapId, float x, float y, float z)
float botZ = bot->GetPositionZ(); float botZ = bot->GetPositionZ();
float speed = bot->GetSpeed(MOVE_RUN); float speed = bot->GetSpeed(MOVE_RUN);
MotionMaster& mm = *bot->GetMotionMaster(); MotionMaster& mm = *bot->GetMotionMaster();
botAI->SetNextCheckDelay(1000);
mm.Clear(); mm.Clear();
mm.MoveJump(x, y, z, speed, speed, 1); mm.MoveJump(x, y, z, speed, speed, 1);
AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation(), 1000); AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation(), 1000);
@@ -141,7 +140,7 @@ bool MovementAction::MoveToLOS(WorldObject* target, bool ranged)
if (botAI->HasStrategy("debug move", BOT_STATE_NON_COMBAT)) if (botAI->HasStrategy("debug move", BOT_STATE_NON_COMBAT))
CreateWp(bot, point.x, point.y, point.z, 0.0, 2334); CreateWp(bot, point.x, point.y, point.z, 0.0, 2334);
float distPoint = sqrt(target->GetDistance(point.x, point.y, point.z)); float distPoint = target->GetDistance(point.x, point.y, point.z);
if (distPoint < dist && target->IsWithinLOS(point.x, point.y, point.z + bot->GetCollisionHeight())) if (distPoint < dist && target->IsWithinLOS(point.x, point.y, point.z + bot->GetCollisionHeight()))
{ {
dist = distPoint; dist = distPoint;
@@ -208,7 +207,6 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
delay = std::max(.0f, delay); delay = std::max(.0f, delay);
delay = std::min((float)sPlayerbotAIConfig->maxWaitForMove, delay); delay = std::min((float)sPlayerbotAIConfig->maxWaitForMove, delay);
AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation(), delay); AI_VALUE(LastMovement&, "last movement").Set(mapId, x, y, z, bot->GetOrientation(), delay);
// TODO: is botAI->SetNextCheckDelay() meant to go here or is setting "last movement" value enough? (same question goes for below)
return true; return true;
} }
} }
@@ -883,7 +881,10 @@ 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)
{ {
float distance = sqrt(bot->GetDistance(x, y, z)); // removed sqrt as means distance limit was effectively 22500 (ReactDistance<63>)
// 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);
if (!bot->InBattleground() && distance > sPlayerbotAIConfig->reactDistance) if (!bot->InBattleground() && distance > sPlayerbotAIConfig->reactDistance)
return false; return false;