Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
liyunfan1223 committed Aug 4, 2024
1 parent fe94083 commit de37cfd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
14 changes: 10 additions & 4 deletions src/strategy/actions/CheckMountStateAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,27 @@ bool CheckMountStateAction::Execute(Event event)
bool enemy = AI_VALUE(Unit*, "enemy player target");
// ignore grind target in BG or bots will dismount near any creature (eg: the rams in AV)
bool dps = AI_VALUE(Unit*, "dps target");
bool fartarget = (enemy && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), 40.0f)) ||
bool fartarget =
(enemy && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "enemy player target"), 40.0f)) ||
(dps && sServerFacade->IsDistanceGreaterThan(AI_VALUE2(float, "distance", "dps target"), 50.0f));
bool attackdistance = false;
// bool chasedistance = false;
float attack_distance = 35.0f;
if (PlayerbotAI::IsMelee(bot)) {
if (PlayerbotAI::IsMelee(bot))
{
attack_distance = 5.0f;
} else {
}
else
{
attack_distance = 30.0f;
}

if (dps || enemy)
{
Unit* currentTarget = AI_VALUE(Unit*, "current target");
attackdistance = (enemy || dps) && currentTarget && sServerFacade->IsDistanceLessThan(AI_VALUE2(float, "distance", "current target"), attack_distance);
attackdistance =
(enemy || dps) && currentTarget &&
sServerFacade->IsDistanceLessThan(AI_VALUE2(float, "distance", "current target"), attack_distance);
}

if (bot->IsMounted() && attackdistance)
Expand Down
12 changes: 7 additions & 5 deletions src/strategy/actions/MovementActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,26 +789,28 @@ bool MovementAction::ReachCombatTo(Unit* target, float distance)

float dx = cos(angle) * needToGo + bx;
float dy = sin(angle) * needToGo + by;
float dz; // = std::max(bz, tz); // calc accurate z position to avoid stuck
float dz; // = std::max(bz, tz); // calc accurate z position to avoid stuck

if (target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD)) // target is moving forward, predict the position
if (target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD)) // target is moving forward, predict the position
{
float timeToGo = MoveDelay(abs(needToGo));
float targetMoveDist = timeToGo * target->GetSpeed(MOVE_RUN);
targetMoveDist = std::min(5.0f, targetMoveDist);
dx += targetMoveDist * cos(target->GetOrientation());
dy += targetMoveDist * sin(target->GetOrientation());
}

if (distanceToTarget > CONTACT_DISTANCE) {

if (distanceToTarget > CONTACT_DISTANCE)
{
dz = bz + (tz - bz) * (needToGo / distanceToTarget);
}
else
{
dz = tz;
}

if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), dx, dy, dz))
if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(),
bot->GetPositionZ(), dx, dy, dz))
return false;

return MoveTo(target->GetMapId(), dx, dy, dz);
Expand Down
3 changes: 2 additions & 1 deletion src/strategy/values/Arrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ WorldLocation ArrowFormation::GetLocationInternal()
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))
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
// master->UpdateGroundPositionZ(x, y, z);
return WorldLocation(master->GetMapId(), x, y, z);
Expand Down
44 changes: 26 additions & 18 deletions src/strategy/values/Formations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ class NearFormation : public MoveAheadFormation
if (!master)
return WorldLocation();

float range = sPlayerbotAIConfig->followDistance;
float angle = GetFollowAngle();
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))
return Formation::NullLocation;
return WorldLocation(master->GetMapId(), x, y, z);
float range = sPlayerbotAIConfig->followDistance;
float angle = GetFollowAngle();
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))
return Formation::NullLocation;
return WorldLocation(master->GetMapId(), x, y, z);
}

float GetMaxDistance() override { return sPlayerbotAIConfig->followDistance; }
Expand Down Expand Up @@ -119,30 +120,33 @@ class ChaosFormation : public MoveAheadFormation
return WorldLocation();

float range = sPlayerbotAIConfig->followDistance;
float angle = GetFollowAngle();
float angle = GetFollowAngle();

time_t now = time(nullptr);
if (!lastChangeTime || now - lastChangeTime >= 3)
{
lastChangeTime = now;
dx = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance;
dy = (urand(0, 10) / 10.0 - 0.5) * sPlayerbotAIConfig->tooCloseDistance;
dr = sqrt(dx*dx + dy*dy);
dr = sqrt(dx * dx + dy * dy);
}

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))
if (!master->GetMap()->CheckCollisionAndGetValidCoords(
master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
// bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ(), x, y, z);
// bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(),
// bot->GetPositionZ(), x, y, z);
return WorldLocation(master->GetMapId(), x, y, z);
}

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))
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
return WorldLocation(master->GetMapId(), x, y, z);
}
Expand Down Expand Up @@ -195,7 +199,8 @@ class CircleFormation : public MoveFormation
float x = target->GetPositionX() + cos(angle) * range;
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))
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z))
return Formation::NullLocation;

return WorldLocation(bot->GetMapId(), x, y, z);
Expand Down Expand Up @@ -357,15 +362,17 @@ class FarFormation : public FollowFormation

if (minDist)
{
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z))
if (!master->GetMap()->CheckCollisionAndGetValidCoords(
master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
return WorldLocation(bot->GetMapId(), minX, minY, z);
}

return Formation::NullLocation;
}

if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), x, y, z))
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(),
master->GetPositionZ(), x, y, z))
return Formation::NullLocation;
return WorldLocation(bot->GetMapId(), x, y, z);
}
Expand Down Expand Up @@ -627,7 +634,8 @@ WorldLocation MoveFormation::MoveSingleLine(std::vector<Player*> line, float dif
float lz = cz;

Player* master = botAI->GetMaster();
if (!master->GetMap()->CheckCollisionAndGetValidCoords(master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz))
if (!master->GetMap()->CheckCollisionAndGetValidCoords(
master, master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(), lx, ly, lz))
return Formation::NullLocation;

return WorldLocation(bot->GetMapId(), lx, ly, lz);
Expand Down

0 comments on commit de37cfd

Please sign in to comment.