diff --git a/LICENSE.txt b/LICENSE.txt index ef0b11a..9546c39 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2014, YaPB Dev Team +Copyright (c) 2003-2016, YaPB Dev Team Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/include/core.h b/include/core.h index f759b74..d352464 100644 --- a/include/core.h +++ b/include/core.h @@ -626,7 +626,6 @@ const float TASKPRI_SHOOTBREAKABLE = 100.0f; const float TASKPRI_ESCAPEFROMBOMB = 100.0f; const float MAX_GRENADE_TIMER = 2.34f; -const float TRACE_FRACTION_EQ = 0.999999f; const int MAX_HOSTAGES = 8; const int MAX_PATH_INDEX = 8; @@ -1539,7 +1538,7 @@ public: int GetFacingIndex (void); int FindFarest (const Vector &origin, float maxDistance = 32.0); - int FindNearest (const Vector &origin, float minDistance = 99999999.0f, int flags = -1); + int FindNearest (const Vector &origin, float minDistance = 9999.0f, int flags = -1); void FindInRadius (Array &radiusHolder, float radius, const Vector &origin, int maxCount = -1); void Add (int flags, const Vector &waypointOrigin = Vector::GetZero ()); diff --git a/include/resource.h b/include/resource.h index cda0274..a7a3bb6 100644 --- a/include/resource.h +++ b/include/resource.h @@ -13,11 +13,11 @@ #define PRODUCT_NAME "Yet Another POD-Bot" #define PRODUCT_VERSION "2.7.1" #define PRODUCT_AUTHOR "YaPB Dev Team" -#define PRODUCT_URL "http://yapb.jeefo.net" +#define PRODUCT_URL "https://yapb.jeefo.net" #define PRODUCT_EMAIL "dmitry@jeefo.net" #define PRODUCT_LOGTAG "YAPB" #define PRODUCT_DESCRIPTION PRODUCT_NAME " v" PRODUCT_VERSION " - The Counter-Strike Bot" -#define PRODUCT_COPYRIGHT "Copyright © 2003-2015, by " PRODUCT_AUTHOR +#define PRODUCT_COPYRIGHT "Copyright © 2003-2016, by " PRODUCT_AUTHOR #define PRODUCT_LEGAL "Half-Life, Counter-Strike, Counter-Strike: Condition Zero, Steam, Valve is a trademark of Valve Corporation" #define PRODUCT_ORIGINAL_NAME "yapb.dll" #define PRODUCT_INTERNAL_NAME "skybot" diff --git a/source/basecode.cpp b/source/basecode.cpp index 4a39f7b..eef8e8a 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -105,7 +105,7 @@ bool Bot::ItemIsVisible (const Vector &destination, char *itemName) TraceLine (EyePosition (), destination, true, GetEntity (), &tr); // check if line of sight to object is not blocked (i.e. visible) - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) { // check for standard items if (strcmp (STRING (tr.pHit->v.classname), itemName) == 0) @@ -127,7 +127,7 @@ bool Bot::EntityIsVisible (const Vector &dest, bool fromBody) TraceLine (fromBody ? pev->origin - Vector (0.0f, 0.0f, 1.0f) : EyePosition (), dest, true, true, GetEntity (), &tr); // check if line of sight to object is not blocked (i.e. visible) - return tr.flFraction > TRACE_FRACTION_EQ; + return tr.flFraction >= 1.0f; } void Bot::CheckGrenadeThrow (void) @@ -481,7 +481,7 @@ edict_t *Bot::FindBreakable (void) TraceResult tr; TraceLine (pev->origin, pev->origin + (m_destOrigin - pev->origin).Normalize () * 64.0f, false, false, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) { edict_t *ent = tr.pHit; @@ -494,7 +494,7 @@ edict_t *Bot::FindBreakable (void) } TraceLine (EyePosition (), EyePosition () + (m_destOrigin - EyePosition ()).Normalize () * 64.0f, false, false, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) { edict_t *ent = tr.pHit; @@ -898,7 +898,7 @@ void Bot::GetCampDirection (Vector *dest) TraceLine (src, *dest, true, GetEntity (), &tr); // check if the trace hit something... - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) { float length = (tr.vecEndPos - src).GetLengthSquared (); @@ -942,7 +942,7 @@ void Bot::GetCampDirection (Vector *dest) if (path->index[i] == -1) continue; - float distance = waypoints.GetPathDistance (path->index[i], enemyIndex); + float distance = static_cast (waypoints.GetPathDistance (path->index[i], enemyIndex)); if (distance < minDistance) { @@ -2219,7 +2219,7 @@ bool Bot::ReactOnEnemy (void) int enemyIndex = waypoints.FindNearest (m_enemy->v.origin); float lineDist = (m_enemy->v.origin - pev->origin).GetLength (); - float pathDist = waypoints.GetPathDistance (i, enemyIndex); + float pathDist = static_cast (waypoints.GetPathDistance (i, enemyIndex)); if (pathDist - lineDist > 112.0f) m_isEnemyReachable = false; @@ -3233,8 +3233,8 @@ void Bot::RunTask_Spray (void) TraceLine (EyePosition (), sprayOrigin, true, GetEntity (), &tr); // no wall in front? - if (tr.flFraction > TRACE_FRACTION_EQ) - sprayOrigin.z -= 128.0; + if (tr.flFraction >= 1.0f) + sprayOrigin.z -= 128.0f; m_entity = sprayOrigin; @@ -3743,12 +3743,12 @@ void Bot::RunTask_PlantBomb (void) DeleteSearchNodes (); int index = FindDefendWaypoint (pev->origin); - float bombTimer = mp_c4timer.GetFloat (); + float guardTime = mp_c4timer.GetFloat () * 0.5f + mp_c4timer.GetFloat () * 0.25f; // push camp task on to stack - PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + (bombTimer * 0.5f + bombTimer * 0.25f), true); + PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + guardTime, true); // push move command - PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + (bombTimer * 0.5f + bombTimer * 0.25f), true); + PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + guardTime, true); if (waypoints.GetPath (index)->vis.crouch <= waypoints.GetPath (index)->vis.stand) m_campButtons |= IN_DUCK; @@ -4242,7 +4242,7 @@ void Bot::RunTask_DoubleJump (void) TraceResult tr; TraceLine (EyePosition (), dest, false, true, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ && tr.pHit == m_doubleJumpEntity) + if (tr.flFraction < 1.0f && tr.pHit == m_doubleJumpEntity) { if (m_doubleJumpEntity->v.button & IN_JUMP) { @@ -4313,15 +4313,15 @@ void Bot::RunTask_EscapeFromBomb (void) { DeleteSearchNodes (); - int lastSelectedGoal = -1; - float safeRadius = Random.Float (1248.0f, 2048.0f), minPathDistance = 99999.0f; + int lastSelectedGoal = -1, minPathDistance = 99999; + float safeRadius = Random.Float (1248.0f, 2048.0f); for (int i = 0; i < g_numWaypoints; i++) { if ((waypoints.GetPath (i)->origin - waypoints.GetBombPosition ()).GetLength () < safeRadius || IsPointOccupied (i)) continue; - float pathDistance = waypoints.GetPathDistance (m_currentWaypointIndex, i); + int pathDistance = waypoints.GetPathDistance (m_currentWaypointIndex, i); if (minPathDistance > pathDistance) { @@ -5586,7 +5586,7 @@ Vector Bot::CheckToss(const Vector &start, const Vector &stop) Vector midPoint = start + (end - start) * 0.5f; TraceHull (midPoint, midPoint + Vector (0.0f, 0.0f, 500.0f), true, head_hull, ENT (pev), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) { midPoint = tr.vecEndPos; midPoint.z = tr.pHit->v.absmin.z - 1.0f; @@ -5609,12 +5609,12 @@ Vector Bot::CheckToss(const Vector &start, const Vector &stop) TraceHull (start, apex, false, head_hull, ENT (pev), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ || tr.fAllSolid) + if (tr.flFraction < 1.0f || tr.fAllSolid) return Vector::GetZero (); TraceHull (end, apex, true, head_hull, ENT (pev), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) { float dot = -(tr.vecPlaneNormal | (apex - end).Normalize ()); @@ -5648,12 +5648,12 @@ Vector Bot::CheckThrow(const Vector &start, const Vector &stop) TraceHull (start, apex, false, head_hull, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) return Vector::GetZero (); TraceHull (stop, apex, true, head_hull, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ || tr.fAllSolid) + if (tr.flFraction != 1.0 || tr.fAllSolid) { float dot = -(tr.vecPlaneNormal | (apex - stop).Normalize ()); diff --git a/source/combat.cpp b/source/combat.cpp index a2d14ab..fd0a6a2 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -109,7 +109,7 @@ bool Bot::CheckVisibility (edict_t *target, Vector *origin, byte *bodyPart) // check for the body TraceLine (botHead, target->v.origin, true, true, GetEntity (), &tr); - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction >= 1.0f) { *bodyPart |= VISIBLE_BODY; *origin = target->v.origin; @@ -121,7 +121,7 @@ bool Bot::CheckVisibility (edict_t *target, Vector *origin, byte *bodyPart) // check for the head TraceLine (botHead, target->v.origin + target->v.view_ofs, true, true, GetEntity (), &tr); - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction >= 1.0f) { *bodyPart |= VISIBLE_HEAD; *origin = target->v.origin + target->v.view_ofs; @@ -184,7 +184,7 @@ bool Bot::CheckVisibility (edict_t *target, Vector *origin, byte *bodyPart) TraceLine (botHead, pos, true, true, GetEntity (), &tr); // check if we hit something - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction >= 1.0f) { *origin = tr.vecEndPos; *bodyPart |= VISIBLE_OTHER; @@ -631,7 +631,7 @@ bool Bot::IsShootableThruObstacle (const Vector &dest) const Vector &source = tr.vecEndPos; TraceLine (dest, source, true, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) { if ((tr.vecEndPos - dest).GetLengthSquared () > GET_SQUARE (800.0f)) return false; @@ -677,7 +677,7 @@ bool Bot::IsShootableThruObstacleEx (const Vector &dest) TraceResult tr; TraceLine (source, dest, true, true, GetEntity (), &tr); - while (tr.flFraction <= TRACE_FRACTION_EQ && numHits < 3) + while (tr.flFraction != 1.0f && numHits < 3) { numHits++; thikness++; diff --git a/source/interface.cpp b/source/interface.cpp index 9bbe490..6eaf7e8 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -2215,6 +2215,7 @@ void StartFrame (void) } } } + if (g_bombPlanted) waypoints.SetBombPosition (); diff --git a/source/navigate.cpp b/source/navigate.cpp index fef677d..93e518c 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -117,8 +117,8 @@ int Bot::FindGoal (void) } else if ((g_mapType & MAP_DE) && m_team == TEAM_TF && g_timeRoundStart + 10.0f < GetWorldTime ()) { - // send some terrorists to guard planter bomb - if (g_bombPlanted && GetTaskId () != TASK_ESCAPEFROMBOMB && GetBombTimeleft () >= 15.0) + // send some terrorists to guard planted bomb + if (!m_defendedBomb && g_bombPlanted && GetTaskId () != TASK_ESCAPEFROMBOMB && GetBombTimeleft () >= 15.0) return m_chosenGoalIndex = FindDefendWaypoint (waypoints.GetBombPosition ()); } @@ -469,7 +469,7 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal) TraceHull (src, dst, true, head_hull, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) blockedRight = true; src = pev->origin - g_pGlobals->v_right * 32.0f; @@ -477,7 +477,7 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal) TraceHull (src, dst, true, head_hull, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) blockedLeft = true; if (dirLeft) @@ -519,14 +519,14 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal) TraceLine (src, m_destOrigin, true, true, GetEntity (), &tr); - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction >= 1.0f) { src = EyePosition (); src = src - g_pGlobals->v_right * 15.0f; TraceLine (src, m_destOrigin, true, true, GetEntity (), &tr); - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction >= 1.0f) state[i] += 5; } } @@ -538,7 +538,7 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal) dst = src + dirNormal * 30.0f; TraceLine (src, dst, true, true, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) state[i] += 10; } else @@ -719,7 +719,7 @@ bool Bot::DoWaypointNav (void) // trace line to door TraceLine (pev->origin, m_currentPath->origin, true, true, GetEntity (), &tr2); - if (tr2.flFraction <= TRACE_FRACTION_EQ && strcmp (STRING (tr2.pHit->v.classname), "func_door") == 0 && (m_liftState == LIFT_NO_NEARBY || m_liftState == LIFT_WAITING_FOR || m_liftState == LIFT_LOOKING_BUTTON_OUTSIDE) && pev->groundentity != tr2.pHit) + if (tr2.flFraction < 1.0f && strcmp (STRING (tr2.pHit->v.classname), "func_door") == 0 && (m_liftState == LIFT_NO_NEARBY || m_liftState == LIFT_WAITING_FOR || m_liftState == LIFT_LOOKING_BUTTON_OUTSIDE) && pev->groundentity != tr2.pHit) { if (m_liftState == LIFT_NO_NEARBY) { @@ -1416,7 +1416,7 @@ float gfunctionKillsDistT (int currentIndex, int parentIndex) if (current->flags & FLAG_CROUCH) cost *= 1.5f; - return waypoints.GetPathDistance (parentIndex, currentIndex) + cost; + return static_cast (waypoints.GetPathDistance (parentIndex, currentIndex)) + cost; } @@ -1442,7 +1442,7 @@ float gfunctionKillsDistCT (int currentIndex, int parentIndex) if (current->flags & FLAG_CROUCH) cost *= 1.5f; - return waypoints.GetPathDistance (parentIndex, currentIndex) + cost; + return static_cast (waypoints.GetPathDistance (parentIndex, currentIndex)) + cost; } float gfunctionKillsDistCTWithHostage (int currentIndex, int parentIndex) @@ -2094,26 +2094,24 @@ int Bot::FindDefendWaypoint (const Vector &origin) continue; // use the 'real' pathfinding distances - int distances = waypoints.GetPathDistance (srcIndex, i); + int distance = waypoints.GetPathDistance (srcIndex, i); - // skip wayponts with distance more than 1536 units - if (distances > 1536.0f) + // skip wayponts with distance more than 512 units + if (distance > 512) continue; TraceLine (waypoints.GetPath (i)->origin, waypoints.GetPath (posIndex)->origin, true, true, GetEntity (), &tr); // check if line not hit anything - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) continue; for (int j = 0; j < MAX_PATH_INDEX; j++) { - if (distances > minDistance[j]) + if (distance > minDistance[j]) { waypointIndex[j] = i; - minDistance[j] = distances; - - break; + minDistance[j] = distance; } } } @@ -2161,13 +2159,15 @@ int Bot::FindDefendWaypoint (const Vector &origin) } } while (isOrderChanged); + + if (waypointIndex[0] == -1) { Array found; for (int i = 0; i < g_numWaypoints; i++) { - if ((waypoints.GetPath (i)->origin - origin).GetLength () <= 1248.0f && !IsPointOccupied (i)) + if ((waypoints.GetPath (i)->origin - origin).GetLength () <= 1248.0f && !waypoints.IsVisible (i, posIndex) && !IsPointOccupied (i)) found.Push (i); } @@ -2314,7 +2314,7 @@ int Bot::FindCoverWaypoint (float maxDistance) { TraceLine (m_lastEnemyOrigin + Vector (0.0f, 0.0f, 36.0f), waypoints.GetPath (waypointIndex[i])->origin, true, true, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return waypointIndex[i]; } } @@ -2507,7 +2507,7 @@ bool Bot::HeadTowardWaypoint (void) { TraceLine (Vector (pev->origin.x, pev->origin.y, pev->absmin.z), m_waypointOrigin, true, true, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) m_waypointOrigin = m_waypointOrigin + (pev->origin - m_waypointOrigin) * 0.5f + Vector (0.0f, 0.0f, 32.0f); } m_navTimeset = GetWorldTime (); @@ -2531,7 +2531,7 @@ bool Bot::CantMoveForward (const Vector &normal, TraceResult *tr) TraceLine (src, forward, true, GetEntity (), tr); // check if the trace hit something... - if (tr->flFraction <= TRACE_FRACTION_EQ) + if (tr->flFraction < 1.0f) { if (strncmp ("func_door", STRING (tr->pHit->v.classname), 9) == 0) return false; @@ -2547,7 +2547,7 @@ bool Bot::CantMoveForward (const Vector &normal, TraceResult *tr) TraceLine (src, forward, true, GetEntity (), tr); // check if the trace hit something... - if (tr->flFraction <= TRACE_FRACTION_EQ && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) + if (tr->flFraction < 1.0f && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) return true; // bot's body will hit something // bot's head is clear, check at shoulder level... @@ -2558,7 +2558,7 @@ bool Bot::CantMoveForward (const Vector &normal, TraceResult *tr) TraceLine (src, forward, true, GetEntity (), tr); // check if the trace hit something... - if (tr->flFraction <= TRACE_FRACTION_EQ && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) + if (tr->flFraction < 1.0f && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) return true; // bot's body will hit something // now check below waist @@ -2570,7 +2570,7 @@ bool Bot::CantMoveForward (const Vector &normal, TraceResult *tr) TraceLine (src, forward, true, GetEntity (), tr); // check if the trace hit something... - if (tr->flFraction <= TRACE_FRACTION_EQ && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) + if (tr->flFraction < 1.0f && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) return true; // bot's body will hit something src = pev->origin; @@ -2579,7 +2579,7 @@ bool Bot::CantMoveForward (const Vector &normal, TraceResult *tr) TraceLine (src, forward, true, GetEntity (), tr); // check if the trace hit something... - if (tr->flFraction <= TRACE_FRACTION_EQ && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) + if (tr->flFraction < 1.0f && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) return true; // bot's body will hit something } else @@ -2592,7 +2592,7 @@ bool Bot::CantMoveForward (const Vector &normal, TraceResult *tr) TraceLine (src, forward, true, GetEntity (), tr); // check if the trace hit something... - if (tr->flFraction <= TRACE_FRACTION_EQ && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) + if (tr->flFraction < 1.0f && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) return true; // bot's body will hit something // trace from the left waist to the right forward waist pos @@ -2602,7 +2602,7 @@ bool Bot::CantMoveForward (const Vector &normal, TraceResult *tr) TraceLine (src, forward, true, GetEntity (), tr); // check if the trace hit something... - if (tr->flFraction <= TRACE_FRACTION_EQ && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) + if (tr->flFraction < 1.0f && strncmp ("func_door", STRING (tr->pHit->v.classname), 9) != 0) return true; // bot's body will hit something } return false; // bot can move forward, return false @@ -2689,7 +2689,7 @@ bool Bot::CanJumpUp (const Vector &normal) // trace a line forward at maximum jump height... TraceLine (src, dest, true, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) goto CheckDuckJump; else { @@ -2699,7 +2699,7 @@ bool Bot::CanJumpUp (const Vector &normal) TraceLine (src, dest, true, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; } @@ -2711,7 +2711,7 @@ bool Bot::CanJumpUp (const Vector &normal) TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) goto CheckDuckJump; // now trace from jump height upward to check for obstructions... @@ -2721,7 +2721,7 @@ bool Bot::CanJumpUp (const Vector &normal) TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; // now check same height on the other side of the bot... @@ -2732,7 +2732,7 @@ bool Bot::CanJumpUp (const Vector &normal) TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) goto CheckDuckJump; // now trace from jump height upward to check for obstructions... @@ -2742,7 +2742,7 @@ bool Bot::CanJumpUp (const Vector &normal) TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - return tr.flFraction > TRACE_FRACTION_EQ; + return tr.flFraction > 1.0f; // here we check if a duck jump would work... CheckDuckJump: @@ -2754,7 +2754,7 @@ CheckDuckJump: // trace a line forward at maximum jump height... TraceLine (src, dest, true, GetEntity (), &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; else { @@ -2765,7 +2765,7 @@ CheckDuckJump: TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, check duckjump - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; } @@ -2777,7 +2777,7 @@ CheckDuckJump: TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; // now trace from jump height upward to check for obstructions... @@ -2787,7 +2787,7 @@ CheckDuckJump: TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; // now check same height on the other side of the bot... @@ -2798,7 +2798,7 @@ CheckDuckJump: TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; // now trace from jump height upward to check for obstructions... @@ -2808,7 +2808,7 @@ CheckDuckJump: TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - return tr.flFraction > TRACE_FRACTION_EQ; + return tr.flFraction > 1.0f; } bool Bot::CanDuckUnder (const Vector &normal) @@ -2834,7 +2834,7 @@ bool Bot::CanDuckUnder (const Vector &normal) TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; // now check same height to one side of the bot... @@ -2845,7 +2845,7 @@ bool Bot::CanDuckUnder (const Vector &normal) TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; // now check same height on the other side of the bot... @@ -2856,7 +2856,7 @@ bool Bot::CanDuckUnder (const Vector &normal) TraceLine (src, dest, true, GetEntity (), &tr); // if trace hit something, return false - return tr.flFraction > TRACE_FRACTION_EQ; + return tr.flFraction > 1.0f; } #ifdef DEAD_CODE @@ -2875,7 +2875,7 @@ bool Bot::IsBlockedLeft (void) TraceLine (pev->origin, g_pGlobals->v_forward * direction - g_pGlobals->v_right * 48.0f, true, GetEntity (), &tr); // check if the trace hit something... - if (tr.flFraction <= TRACE_FRACTION_EQ && strncmp ("func_door", STRING (tr.pHit->v.classname), 9) != 0) + if (tr.flFraction < 1.0f && strncmp ("func_door", STRING (tr.pHit->v.classname), 9) != 0) return true; // bot's body will hit something return false; @@ -2895,7 +2895,7 @@ bool Bot::IsBlockedRight (void) TraceLine (pev->origin, pev->origin + g_pGlobals->v_forward * direction + g_pGlobals->v_right * 48.0f, true, GetEntity (), &tr); // check if the trace hit something... - if (tr.flFraction <= TRACE_FRACTION_EQ && (strncmp ("func_door", STRING (tr.pHit->v.classname), 9) != 0)) + if (tr.flFraction < 1.0f && (strncmp ("func_door", STRING (tr.pHit->v.classname), 9) != 0)) return true; // bot's body will hit something return false; @@ -2911,7 +2911,7 @@ bool Bot::CheckWallOnLeft (void) TraceLine (pev->origin, pev->origin - g_pGlobals->v_right * 40.0f, true, GetEntity (), &tr); // check if the trace hit something... - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return true; return false; @@ -2926,7 +2926,7 @@ bool Bot::CheckWallOnRight (void) TraceLine (pev->origin, pev->origin + g_pGlobals->v_right * 40.0f, true, GetEntity (), &tr); // check if the trace hit something... - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return true; return false; @@ -3320,6 +3320,8 @@ bool Bot::IsPointOccupied (int index) continue; // check if this waypoint is already used + // TODO: take in account real players + if (bot->m_notKilled) { int occupyId = GetShootingConeDeviation (bot->GetEntity (), &pev->origin) >= 0.7f ? bot->m_prevWptIndex[0] : m_currentWaypointIndex; @@ -3327,7 +3329,7 @@ bool Bot::IsPointOccupied (int index) // length check float length = (waypoints.GetPath (occupyId)->origin - waypoints.GetPath (index)->origin).GetLengthSquared (); - if (occupyId == index || bot->GetTask ()->data == index || length < GET_SQUARE (75.0f)) + if (occupyId == index || bot->GetTask ()->data == index || length < GET_SQUARE (64.0f)) return true; } } diff --git a/source/support.cpp b/source/support.cpp index 6468272..e4dc891 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -135,7 +135,7 @@ bool IsVisible (const Vector &origin, edict_t *ent) TraceResult tr; TraceLine (ent->v.origin + ent->v.view_ofs, origin, true, true, ent, &tr); - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction != 1.0f) return true; return false; @@ -229,7 +229,7 @@ void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex) if (decalIndex < 0) decalIndex = (*g_engfuncs.pfnDecalIndex) ("{lambda06"); - if (trace->flFraction > TRACE_FRACTION_EQ) + if (trace->flFraction == 1.0f) return; if (!IsEntityNull (trace->pHit)) @@ -1013,7 +1013,7 @@ void CheckWelcomeMessage (void) { ServerCommand ("speak \"%s\"", const_cast (sentences.GetRandomElement ().GetBuffer ())); - ChartPrint ("----- YaPB v%s (Build: %u), {%s}, (c) 2015, by %s -----", PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_DATE, PRODUCT_AUTHOR); + ChartPrint ("----- %s v%s (Build: %u), {%s}, (c) 2016, by %s (%s)-----", PRODUCT_NAME, PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_DATE, PRODUCT_AUTHOR, PRODUCT_URL); MESSAGE_BEGIN (MSG_ONE, SVC_TEMPENTITY, NULL, g_hostEntity); WRITE_BYTE (TE_TEXTMESSAGE); diff --git a/source/waypoint.cpp b/source/waypoint.cpp index 7ce4851..2abe5ea 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -116,9 +116,9 @@ int Waypoint::FindNearest (const Vector &origin, float minDistance, int flags) if (flags != -1 && !(m_paths[i]->flags & flags)) continue; // if flag not -1 and waypoint has no this flag, skip waypoint - float distance = (m_paths[i]->origin - origin).GetLengthSquared (); + float distance = (m_paths[i]->origin - origin).GetLength (); - if (distance < GET_SQUARE (minDistance)) + if (distance < minDistance) { index = i; minDistance = distance; @@ -136,10 +136,11 @@ void Waypoint::FindInRadius (Array &radiusHolder, float radius, const Vect if (maxCount != -1 && radiusHolder.GetElementNumber () > maxCount) break; - if ((m_paths[i]->origin - origin).GetLengthSquared () < GET_SQUARE (radius)) + if ((m_paths[i]->origin - origin).GetLength () < radius) radiusHolder.Push (i); } } + void Waypoint::Add (int flags, const Vector &waypointOrigin) { if (IsEntityNull (g_hostEntity)) @@ -367,7 +368,7 @@ void Waypoint::Add (int flags, const Vector &waypointOrigin) // check if the waypoint is reachable from the new one TraceLine (newOrigin, m_paths[i]->origin, true, g_hostEntity, &tr); - if (tr.flFraction > TRACE_FRACTION_EQ && fabs (newOrigin.x - m_paths[i]->origin.x) < 64.0f && fabs (newOrigin.y - m_paths[i]->origin.y) < 64.0f && fabs (newOrigin.z - m_paths[i]->origin.z) < g_autoPathDistance) + if (tr.flFraction == 1.0f && fabs (newOrigin.x - m_paths[i]->origin.x) < 64.0f && fabs (newOrigin.y - m_paths[i]->origin.y) < 64.0f && fabs (newOrigin.z - m_paths[i]->origin.z) < g_autoPathDistance) { distance = (m_paths[i]->origin - newOrigin).GetLength (); @@ -756,7 +757,7 @@ void Waypoint::CalculateWayzone (int index) TraceHull (radiusStart, radiusEnd, true, head_hull, NULL, &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) { TraceLine (radiusStart, radiusEnd, true, NULL, &tr); @@ -779,7 +780,7 @@ void Waypoint::CalculateWayzone (int index) TraceHull (dropStart, dropEnd, true, head_hull, NULL, &tr); - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction >= 1.0f) { wayBlocked = true; path->radius -= 16.0f; @@ -791,7 +792,7 @@ void Waypoint::CalculateWayzone (int index) TraceHull (dropStart, dropEnd, true, head_hull, NULL, &tr); - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction >= 1.0f) { wayBlocked = true; path->radius -= 16.0f; @@ -801,7 +802,7 @@ void Waypoint::CalculateWayzone (int index) radiusEnd.z += 34.0f; TraceHull (radiusStart, radiusEnd, true, head_hull, NULL, &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) { wayBlocked = true; path->radius -= 16.0f; @@ -1278,7 +1279,7 @@ bool Waypoint::Reachable (Bot *bot, int index) TraceLine (src, dest, true, bot->GetEntity (), &tr); // if waypoint is visible from current position (even behind head)... - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction >= 1.0f) { if (bot->pev->waterlevel == 2 || bot->pev->waterlevel == 3) return true; @@ -1314,14 +1315,14 @@ bool Waypoint::IsNodeReachable (const Vector &src, const Vector &destination) TraceLine (src, destination, ignore_monsters, g_hostEntity, &tr); // if waypoint is visible from current position (even behind head)... - if (tr.flFraction > TRACE_FRACTION_EQ || strncmp ("func_door", STRING (tr.pHit->v.classname), 9) == 0) + if (tr.flFraction >= 1.0f || strncmp ("func_door", STRING (tr.pHit->v.classname), 9) == 0) { // if it's a door check if nothing blocks behind if (strncmp ("func_door", STRING (tr.pHit->v.classname), 9) == 0) { TraceLine (tr.vecEndPos, destination, ignore_monsters, tr.pHit, &tr); - if (tr.flFraction <= TRACE_FRACTION_EQ) + if (tr.flFraction < 1.0f) return false; } @@ -1339,7 +1340,7 @@ bool Waypoint::IsNodeReachable (const Vector &src, const Vector &destination) TraceLine (sourceNew, destinationNew, ignore_monsters, g_hostEntity, &tr); // check if we didn't hit anything, if not then it's in mid-air - if (tr.flFraction > TRACE_FRACTION_EQ) + if (tr.flFraction >= 1.0) return false; // can't reach this one } @@ -1380,7 +1381,7 @@ bool Waypoint::IsNodeReachable (const Vector &src, const Vector &destination) void Waypoint::InitializeVisibility (void) { - if (m_redoneVisibility == false) + if (!m_redoneVisibility) return; TraceResult tr; @@ -1411,7 +1412,7 @@ void Waypoint::InitializeVisibility (void) TraceLine (sourceDuck, dest, true, NULL, &tr); // check if line of sight to object is not blocked (i.e. visible) - if (tr.flFraction <= TRACE_FRACTION_EQ || tr.fStartSolid) + if (tr.flFraction != 1.0f || tr.fStartSolid) res = 1; else res = 0; @@ -1421,7 +1422,7 @@ void Waypoint::InitializeVisibility (void) TraceLine (sourceStand, dest, true, NULL, &tr); // check if line of sight to object is not blocked (i.e. visible) - if (tr.flFraction <= TRACE_FRACTION_EQ || tr.fStartSolid) + if (tr.flFraction != 1.0f || tr.fStartSolid) res |= 1; shift = (i % 4) << 1; @@ -2239,7 +2240,7 @@ void Waypoint::CreateBasic (void) TraceHull (down, up, true, point_hull, NULL, &tr); - if (POINT_CONTENTS (up) == CONTENTS_SOLID || tr.flFraction <= TRACE_FRACTION_EQ) + if (POINT_CONTENTS (up) == CONTENTS_SOLID || tr.flFraction != 1.0f) { up = down = back; down.z = ent->v.absmax.z;