refactor: reformat the code

This commit is contained in:
jeefo 2024-05-05 01:06:56 +03:00
commit 009bdf2f3e
No known key found for this signature in database
GPG key ID: D696786B81B667C8
15 changed files with 852 additions and 850 deletions

View file

@ -302,7 +302,7 @@ int Bot::findGoalPost (int tactic, IntArray *defensive, IntArray *offensive) {
postprocessGoals (graph.m_goalPoints, goalChoices);
}
}
else if (tactic == GoalTactic::RescueHostage && !graph.m_rescuePoints.empty ()) {
else if (tactic == GoalTactic::RescueHostage && !graph.m_rescuePoints.empty ()) {
// force ct with hostage(s) to select closest rescue goal
float nearestDistanceSq = kInfiniteDistance;
int count = 0;
@ -893,7 +893,7 @@ void Bot::moveToGoal () {
src.z += 12.0f;
dst.z += 18.0f + 28.0f;
game.testLine (src, dst, TraceIgnore::Everything, ent (), &tr);
if (tr.flFraction >= 0.95f) {
@ -1037,7 +1037,7 @@ bool Bot::updateNavigation () {
selectBestWeapon ();
}
}
if (m_pathFlags & NodeFlag::Ladder) {
const float ladderDistance = pev->origin.distance (m_pathOrigin);
@ -1074,10 +1074,10 @@ bool Bot::updateNavigation () {
// special detection if someone is using the ladder (to prevent to have bots-towers on ladders)
for (const auto &client : util.getClients ()) {
if (!(client.flags & ClientFlags::Used)
|| !(client.flags & ClientFlags::Alive)
|| (client.ent->v.movetype != MOVETYPE_FLY)
|| client.team != m_team
|| client.ent == ent ()) {
|| !(client.flags & ClientFlags::Alive)
|| (client.ent->v.movetype != MOVETYPE_FLY)
|| client.team != m_team
|| client.ent == ent ()) {
continue;
}
@ -1091,8 +1091,8 @@ bool Bot::updateNavigation () {
// someone is above or below us and is using the ladder already
if (tr.pHit == client.ent
&& cr::abs (pev->origin.z - client.ent->v.origin.z) > 15.0f
&& (client.ent->v.movetype == MOVETYPE_FLY)) {
&& cr::abs (pev->origin.z - client.ent->v.origin.z) > 15.0f
&& (client.ent->v.movetype == MOVETYPE_FLY)) {
const auto numPreviousNode = rg (0, 2);
@ -1246,8 +1246,8 @@ bool Bot::updateNavigation () {
// needs precise placement - check if we get past the point
if (desiredDistanceSq < cr::sqrf (22.0f)
&& nodeDistanceSq < cr::sqrf (30.0f)
&& m_pathOrigin.distanceSq (pev->origin + pev->velocity * m_frameInterval) >= nodeDistanceSq) {
&& nodeDistanceSq < cr::sqrf (30.0f)
&& m_pathOrigin.distanceSq (pev->origin + pev->velocity * m_frameInterval) >= nodeDistanceSq) {
desiredDistanceSq = nodeDistanceSq + 1.0f;
}
@ -1287,10 +1287,10 @@ bool Bot::updateNavigation () {
const int taskTarget = getTask ()->data;
if (game.mapIs (MapFlags::Demolition)
&& bots.isBombPlanted ()
&& m_team == Team::CT
&& getCurrentTaskId () != Task::EscapeFromBomb
&& taskTarget != kInvalidNodeIndex) {
&& bots.isBombPlanted ()
&& m_team == Team::CT
&& getCurrentTaskId () != Task::EscapeFromBomb
&& taskTarget != kInvalidNodeIndex) {
const Vector &bombOrigin = isBombAudible ();
@ -1350,9 +1350,9 @@ bool Bot::updateLiftHandling () {
game.testLine (pev->origin, m_pathOrigin, TraceIgnore::Everything, ent (), &tr);
if (tr.flFraction < 1.0f
&& util.isDoorEntity (tr.pHit)
&& (m_liftState == LiftState::None || m_liftState == LiftState::WaitingFor || m_liftState == LiftState::LookingButtonOutside)
&& pev->groundentity != tr.pHit) {
&& util.isDoorEntity (tr.pHit)
&& (m_liftState == LiftState::None || m_liftState == LiftState::WaitingFor || m_liftState == LiftState::LookingButtonOutside)
&& pev->groundentity != tr.pHit) {
if (m_liftState == LiftState::None) {
m_liftState = LiftState::LookingButtonOutside;
@ -1372,8 +1372,8 @@ bool Bot::updateLiftHandling () {
// if trace result shows us that it is a lift
if (!game.isNullEntity (tr.pHit) && !m_pathWalk.empty () && isFunc (tr.pHit->v.classname.str ()) && !liftClosedDoorExists) {
if ((m_liftState == LiftState::None
|| m_liftState == LiftState::WaitingFor
|| m_liftState == LiftState::LookingButtonOutside) && cr::fzero (tr.pHit->v.velocity.z)) {
|| m_liftState == LiftState::WaitingFor
|| m_liftState == LiftState::LookingButtonOutside) && cr::fzero (tr.pHit->v.velocity.z)) {
if (cr::abs (pev->origin.z - tr.vecEndPos.z) < 70.0f) {
m_liftEntity = tr.pHit;
@ -1449,10 +1449,10 @@ bool Bot::updateLiftHandling () {
for (const auto &bot : bots) {
if (!bot->m_isAlive
|| bot->m_team != m_team
|| bot->m_targetEntity != ent ()
|| bot->getCurrentTaskId () != Task::FollowUser
|| bot->m_liftEntity != m_liftEntity) {
|| bot->m_team != m_team
|| bot->m_targetEntity != ent ()
|| bot->getCurrentTaskId () != Task::FollowUser
|| bot->m_liftEntity != m_liftEntity) {
continue;
}
@ -1484,10 +1484,10 @@ bool Bot::updateLiftHandling () {
// got a valid button entity ?
if (!game.isNullEntity (button)
&& pev->groundentity == m_liftEntity
&& m_buttonPushTime + 1.0f < game.time ()
&& cr::fzero (m_liftEntity->v.velocity.z)
&& isOnFloor ()) {
&& pev->groundentity == m_liftEntity
&& m_buttonPushTime + 1.0f < game.time ()
&& cr::fzero (m_liftEntity->v.velocity.z)
&& isOnFloor ()) {
auto buttonWithLineOfSight = lookupButton (m_liftEntity->v.targetname.str (), false);
@ -1508,14 +1508,14 @@ bool Bot::updateLiftHandling () {
// is lift activated and bot is standing on it and lift is moving ?
if (m_liftState == LiftState::LookingButtonInside
|| m_liftState == LiftState::EnteringIn
|| m_liftState == LiftState::WaitingForTeammates
|| m_liftState == LiftState::WaitingFor) {
|| m_liftState == LiftState::EnteringIn
|| m_liftState == LiftState::WaitingForTeammates
|| m_liftState == LiftState::WaitingFor) {
if (pev->groundentity == m_liftEntity
&& !cr::fzero (m_liftEntity->v.velocity.z)
&& isOnFloor ()
&& ((graph[m_previousNodes[0]].flags & NodeFlag::Lift) || !game.isNullEntity (m_targetEntity))) {
&& !cr::fzero (m_liftEntity->v.velocity.z)
&& isOnFloor ()
&& ((graph[m_previousNodes[0]].flags & NodeFlag::Lift) || !game.isNullEntity (m_targetEntity))) {
m_liftState = LiftState::TravelingBy;
m_liftUsageTime = game.time () + 14.0f;
@ -1555,10 +1555,10 @@ bool Bot::updateLiftHandling () {
// iterate though clients, and find if lift already used
for (const auto &client : util.getClients ()) {
if (!(client.flags & ClientFlags::Used)
|| !(client.flags & ClientFlags::Alive)
|| client.team != m_team
|| client.ent == ent ()
|| game.isNullEntity (client.ent->v.groundentity)) {
|| !(client.flags & ClientFlags::Alive)
|| client.team != m_team
|| client.ent == ent ()
|| game.isNullEntity (client.ent->v.groundentity)) {
continue;
}
@ -1613,8 +1613,8 @@ bool Bot::updateLiftHandling () {
// bot fall down somewhere inside the lift's groove :)
if (pev->groundentity != m_liftEntity && graph.exists (m_previousNodes[0])) {
if ((graph[m_previousNodes[0]].flags & NodeFlag::Lift)
&& (m_path->origin.z - pev->origin.z) > 50.0f
&& (graph[m_previousNodes[0]].origin.z - pev->origin.z) > 50.0f) {
&& (m_path->origin.z - pev->origin.z) > 50.0f
&& (graph[m_previousNodes[0]].origin.z - pev->origin.z) > 50.0f) {
m_liftState = LiftState::None;
m_liftEntity = nullptr;
@ -2129,8 +2129,8 @@ int Bot::findDefendNode (const Vector &origin) {
for (const auto &path : graph) {
if (origin.distanceSq (path.origin) < cr::sqrf (kMaxDistance)
&& vistab.visible (path.number, posIndex)
&& !isOccupiedNode (path.number)) {
&& vistab.visible (path.number, posIndex)
&& !isOccupiedNode (path.number)) {
found.push (path.number);
}
@ -2379,13 +2379,13 @@ bool Bot::advanceMovement () {
// only if we in normal task and bomb is not planted
if (tid == Task::Normal
&& bots.getRoundMidTime () + 5.0f < game.time ()
&& m_timeCamping + 5.0f < game.time ()
&& !bots.isBombPlanted ()
&& m_personality != Personality::Rusher
&& !m_hasC4 && !m_isVIP
&& m_loosedBombNodeIndex == kInvalidNodeIndex
&& !m_hasHostage && !m_isCreature) {
&& bots.getRoundMidTime () + 5.0f < game.time ()
&& m_timeCamping + 5.0f < game.time ()
&& !bots.isBombPlanted ()
&& m_personality != Personality::Rusher
&& !m_hasC4 && !m_isVIP
&& m_loosedBombNodeIndex == kInvalidNodeIndex
&& !m_hasHostage && !m_isCreature) {
m_campButtons = 0;
@ -2497,10 +2497,10 @@ bool Bot::advanceMovement () {
// is there a jump node right ahead and do we need to draw out the light weapon ?
if (willJump && !usesKnife ()
&& m_currentWeapon != Weapon::Scout
&& !m_isReloading && !usesPistol ()
&& (jumpDistanceSq > cr::sqrf (145.0f) || (dst.z - 32.0f > src.z && jumpDistanceSq > cr::sqrf (125.0f)))
&& !(m_states & Sense::SeeingEnemy)) {
&& m_currentWeapon != Weapon::Scout
&& !m_isReloading && !usesPistol ()
&& (jumpDistanceSq > cr::sqrf (145.0f) || (dst.z - 32.0f > src.z && jumpDistanceSq > cr::sqrf (125.0f)))
&& !(m_states & Sense::SeeingEnemy)) {
selectWeaponById (Weapon::Knife); // draw out the knife if we needed
}
@ -3351,7 +3351,7 @@ void Bot::syncFindPath (int srcIndex, int destIndex, FindPath pathType) {
m_planner->setG (Heuristic::gfunctionPathDist);
}
}
m_chosenGoalIndex = srcIndex;
m_goalValue = 0.0f;