diff --git a/include/core.h b/include/core.h index 7a23d40..981bcbb 100644 --- a/include/core.h +++ b/include/core.h @@ -399,7 +399,7 @@ enum PickupType // reload state enum ReloadState { - RELOAD_NONE = 0, // no reload state currrently + RELOAD_NONE = 0, // no reload state currently RELOAD_PRIMARY = 1, // primary weapon reload state RELOAD_SECONDARY = 2 // secondary weapon reload state }; @@ -975,6 +975,7 @@ private: void CheckRadioCommands (void); void CheckReload (void); void AvoidGrenades (void); + void CheckGrenadeThrow (void); void CheckBurstMode (float distance); void CheckSilencer (void); @@ -998,7 +999,7 @@ private: edict_t *FindNearestButton (const char *className); edict_t *FindBreakable (void); int FindCoverWaypoint (float maxDistance); - int FindDefendWaypoint (Vector origin); + int FindDefendWaypoint (const Vector &origin); int FindGoal (void); void FilterGoals (const Array &goals, int *result); void FindItem (void); @@ -1012,7 +1013,7 @@ private: bool HeadTowardWaypoint (void); int InFieldOfView (const Vector &dest); - bool IsBombDefusing (Vector bombOrigin); + bool IsBombDefusing (const Vector &bombOrigin); bool IsBlockedLeft (void); bool IsBlockedRight (void); bool IsPointOccupied (int index); @@ -1034,7 +1035,7 @@ private: bool ReactOnEnemy (void); void ResetCollideState (void); void SetConditions (void); - void SetStrafeSpeed (Vector moveDir, float strafeSpeed); + void SetStrafeSpeed (const Vector &moveDir, float strafeSpeed); void StartGame (void); void TaskComplete (void); bool GetBestNextWaypoint (void); @@ -1045,15 +1046,16 @@ private: byte ThrottledMsec (void); void GetValidWaypoint (void); void ChangeWptIndex (int waypointIndex); - bool IsDeadlyDrop (Vector targetOriginPos); + bool IsDeadlyDrop (const Vector &to); bool OutOfBombTimer (void); void SelectLeaderEachTeam (int team); Vector CheckToss (const Vector &start, Vector end); Vector CheckThrow (const Vector &start, Vector end); - Vector GetAimPosition (void); Vector CheckBombAudible (void); + const Vector &GetAimPosition (void); + float GetZOffset (float distance); int CheckGrenades (void); @@ -1069,13 +1071,14 @@ private: void SelectBestWeapon (void); void SelectPistol (void); bool IsFriendInLineOfFire (float distance); - bool IsGroupOfEnemies (Vector location, int numEnemies = 1, int radius = 256); + bool IsGroupOfEnemies (const Vector &location, int numEnemies = 1, int radius = 256); bool IsShootableThruObstacle (const Vector &dest); bool IsShootableThruObstacleEx (const Vector &dest); - int GetNearbyEnemiesNearPosition (Vector origin, int radius); - int GetNearbyFriendsNearPosition (Vector origin, int radius); + int GetNearbyEnemiesNearPosition (const Vector &origin, int radius); + int GetNearbyFriendsNearPosition (const Vector &origin, int radius); + void SelectWeaponByName (const char *name); void SelectWeaponbyNumber (int num); int GetHighestWeapon (void); @@ -1087,7 +1090,8 @@ private: float GetEstimatedReachTime (void); int GetAimingWaypoint (void); - int GetAimingWaypoint (Vector targetOriginPos); + int GetAimingWaypoint (const Vector &to); + void FindShortestPath (int srcIndex, int destIndex); void FindPath (int srcIndex, int destIndex, unsigned char pathType = 0); void DebugMsg (const char *format, ...); @@ -1248,7 +1252,7 @@ public: void Kill (void); void Kick (void); void ResetDoubleJumpState (void); - void MoveToVector (Vector to); + void MoveToVector (const Vector &to); int FindPlantedBomb(void); bool HasHostage (void); @@ -1282,6 +1286,9 @@ private: bool m_economicsGood[2]; // is team able to buy anything bool m_deathMsgSent; // for fakeping + // holds currently active grenades in the map + Array m_activeGrenades; + protected: int CreateBot (String name, int difficulty, int personality, int team, int member); @@ -1328,9 +1335,24 @@ public: void CheckTeamEconomics (int team); static void CallGameEntity (entvars_t *vars); + inline void SetDeathMsgState (bool sent) + { + m_deathMsgSent = sent; + } - inline void SetDeathMsgState (bool sent) { m_deathMsgSent = sent; } - inline bool GetDeathMsgState (void) { return m_deathMsgSent; } + inline bool GetDeathMsgState (void) + { + return m_deathMsgSent; + } + + // grenades + void UpdateActiveGrenades (void); + const Array &GetActiveGrenades (void); + + inline bool HasActiveGrenades (void) + { + return !m_activeGrenades.IsEmpty (); + } public: void CalculatePingOffsets (void); @@ -1432,10 +1454,10 @@ public: void AddPath (short int addIndex, short int pathIndex, float distance); int GetFacingIndex (void); - int FindFarest (Vector origin, float maxDistance = 32.0); - int FindNearest (Vector origin, float minDistance = 9999.0, int flags = -1); - void FindInRadius (Vector origin, float radius, int *holdTab, int *count); - void FindInRadius (Array &queueID, float radius, Vector origin); + int FindFarest (const Vector &origin, float maxDistance = 32.0); + int FindNearest (const Vector &origin, float minDistance = 9999.0, int flags = -1); + void FindInRadius (const Vector &origin, float radius, int *holdTab, int *count); + void FindInRadius (Array &queueID, float radius, const Vector &origin); void Add (int flags, const Vector &waypointOrigin = nullvec); void Delete (void); @@ -1448,7 +1470,7 @@ public: void DeletePath (void); void CacheWaypoint (void); - float GetTravelTime (float maxSpeed, Vector src, Vector origin); + float GetTravelTime (float maxSpeed, const Vector &src, const Vector &origin); bool IsVisible (int srcIndex, int destIndex); bool IsStandVisible (int srcIndex, int destIndex); bool IsDuckVisible (int srcIndex, int destIndex); @@ -1458,7 +1480,7 @@ public: void Save (void); bool Reachable (Bot *bot, int index); - bool IsNodeReachable (Vector src, Vector destination); + bool IsNodeReachable (const Vector &src, const Vector &destination); void Think (void); bool NodesValid (void); void SaveExperienceTab (void); @@ -1483,7 +1505,11 @@ public: bool IsGoalVisited (int index); void SetGoalVisited (int index); - inline Vector GetBombPosition (void) { return m_foundBombOrigin; } + inline const Vector &GetBombPosition (void) + { + return m_foundBombOrigin; + } + void SetBombPosition (bool shouldReset = false); String CheckSubfolderFile (void); }; @@ -1637,7 +1663,6 @@ extern void DetectCSVersion (void); extern void PlaySound (edict_t *ent, const char *soundName); extern void ServerPrint (const char *format, ...); extern void ChartPrint (const char *format, ...); -extern void ServerPrintNoTag (const char *format, ...); extern void CenterPrint (const char *format, ...); extern void ClientPrint (edict_t *ent, int dest, const char *format, ...); extern void HudMessage (edict_t *ent, bool toCenter, Vector rgb, char *format, ...); diff --git a/include/engine/eiface.h b/include/engine/eiface.h index 23c8831..b548ee1 100644 --- a/include/engine/eiface.h +++ b/include/engine/eiface.h @@ -100,6 +100,8 @@ typedef struct int iHitgroup; // 0 == generic, non zero is specific body part } TraceResult; +typedef edict_t *entity_t; + typedef uint32 CRC32_t; // Engine hands this to DLLs for functionality callbacks diff --git a/include/resource.h b/include/resource.h index 37d956e..f728139 100644 --- a/include/resource.h +++ b/include/resource.h @@ -10,10 +10,10 @@ #pragma once // general product information -#define PRODUCT_NAME "YaPB" +#define PRODUCT_NAME "Yet Another POD-Bot" #define PRODUCT_VERSION "2.7" #define PRODUCT_AUTHOR "YaPB Dev Team" -#define PRODUCT_URL "http://yapb.jeefo.net/" +#define PRODUCT_URL "http://yapb.ru/" #define PRODUCT_EMAIL "dmitry@jeefo.net" #define PRODUCT_LOGTAG "YAPB" #define PRODUCT_DESCRIPTION PRODUCT_NAME " v" PRODUCT_VERSION " - The Counter-Strike Bot" diff --git a/source/basecode.cpp b/source/basecode.cpp index c4fc211..dc5564e 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -238,32 +238,168 @@ bool Bot::EntityIsVisible (const Vector &dest, bool fromBody) return tr.flFraction >= 1.0; } +void Bot::CheckGrenadeThrow (void) +{ + // check if throwing a grenade is a good thing to do... + if (m_lastEnemy == NULL || yb_ignore_enemies.GetBool () || yb_jasonmode.GetBool () && m_grenadeCheckTime > GetWorldTime () || m_isUsingGrenade || GetTaskId () == TASK_PLANTBOMB || GetTaskId () == TASK_DEFUSEBOMB || m_isReloading || !IsAlive (m_lastEnemy)) + { + m_states &= ~(STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG); + return; + } + + // check again in some seconds + m_grenadeCheckTime = GetWorldTime () + yb_timergrenade.GetFloat (); + + // check if we have grenades to throw + int grenadeToThrow = CheckGrenades (); + + // if we don't have grenades no need to check it this round again + if (grenadeToThrow == -1) + { + m_grenadeCheckTime = GetWorldTime () + 15.0; // changed since, conzero can drop grens from dead players + m_states &= ~(STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG); + + return; + } + // care about different types of grenades + if ((grenadeToThrow == WEAPON_EXPLOSIVE || grenadeToThrow == WEAPON_SMOKE) && Random.Long (0, 100) < 45 && !(m_states & (STATE_SEEING_ENEMY | STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG))) + { + float distance = (m_lastEnemy->v.origin - pev->origin).GetLength (); + + // is enemy to high to throw + if ((m_lastEnemy->v.origin.z > (pev->origin.z + 650.0)) || !(m_lastEnemy->v.flags & (FL_ONGROUND | FL_DUCKING))) + distance = FLT_MAX; // just some crazy value + + // enemy is within a good throwing distance ? + if (distance > (grenadeToThrow == WEAPON_SMOKE ? 400 : 600) && distance <= 1000) + { + // care about different types of grenades + if (grenadeToThrow == WEAPON_EXPLOSIVE) + { + bool allowThrowing = true; + + // check for teammates + if (GetNearbyFriendsNearPosition (m_lastEnemy->v.origin, 256) > 0) + allowThrowing = false; + + if (allowThrowing && m_seeEnemyTime + 2.0 < GetWorldTime ()) + { + const Vector &enemyPredict = ((m_lastEnemy->v.velocity * 0.5).SkipZ () + m_lastEnemy->v.origin); + int searchTab[4], count = 4; + + float searchRadius = m_lastEnemy->v.velocity.GetLength2D (); + + // check the search radius + if (searchRadius < 128.0) + searchRadius = 128.0; + + // search waypoints + g_waypoint->FindInRadius (enemyPredict, searchRadius, searchTab, &count); + + while (count > 0) + { + allowThrowing = true; + + // check the throwing + m_throw = g_waypoint->GetPath (searchTab[count--])->origin; + Vector src = CheckThrow (EyePosition (), m_throw); + + if (src.GetLengthSquared () < 100.0) + src = CheckToss (EyePosition (), m_throw); + + if (src == nullvec) + allowThrowing = false; + else + break; + } + } + + // start explosive grenade throwing? + if (allowThrowing) + m_states |= STATE_THROW_HE; + else + m_states &= ~STATE_THROW_HE; + } + else if (grenadeToThrow == WEAPON_SMOKE) + { + // start smoke grenade throwing? + if ((m_states & STATE_SEEING_ENEMY) && GetShootingConeDeviation (m_enemy, &pev->origin) >= 0.70 && m_seeEnemyTime + 2.0 < GetWorldTime ()) + m_states &= ~STATE_THROW_SG; + else + m_states |= STATE_THROW_SG; + } + } + } + else if (IsAlive (m_lastEnemy) && grenadeToThrow == WEAPON_FLASHBANG && (m_lastEnemy->v.origin - pev->origin).GetLength () < 800 && !(m_aimFlags & AIM_ENEMY) && Random.Long (0, 100) < 50) + { + bool allowThrowing = true; + Array inRadius; + + g_waypoint->FindInRadius (inRadius, 256, m_lastEnemy->v.origin + (m_lastEnemy->v.velocity * 0.5).SkipZ ()); + + IterateArray (inRadius, i) + { + Path *path = g_waypoint->GetPath (i); + + if (GetNearbyFriendsNearPosition (path->origin, 256) != 0 || !(m_difficulty == 4 && GetNearbyFriendsNearPosition (path->origin, 256) != 0)) + continue; + + m_throw = path->origin; + Vector src = CheckThrow (EyePosition (), m_throw); + + if (src.GetLengthSquared () < 100) + src = CheckToss (EyePosition (), m_throw); + + if (src == nullvec) + continue; + + allowThrowing = true; + break; + } + + // start concussion grenade throwing? + if (allowThrowing && m_seeEnemyTime + 2.0 < GetWorldTime ()) + m_states |= STATE_THROW_FB; + else + m_states &= ~STATE_THROW_FB; + } + + if (m_states & STATE_THROW_HE) + StartTask (TASK_THROWHEGRENADE, TASKPRI_THROWGRENADE, -1, GetWorldTime () + 3.0, false); + else if (m_states & STATE_THROW_FB) + StartTask (TASK_THROWFLASHBANG, TASKPRI_THROWGRENADE, -1, GetWorldTime () + 3.0, false); + else if (m_states & STATE_THROW_SG) + StartTask (TASK_THROWSMOKE, TASKPRI_THROWGRENADE, -1, GetWorldTime () + 3.0, false); + + // delay next grenade throw + if (m_states & (STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG)) + m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; +} void Bot::AvoidGrenades (void) { // checks if bot 'sees' a grenade, and avoid it - edict_t *ent = m_avoidGrenade; + if (!g_botManager->HasActiveGrenades ()) + return; // check if old pointers to grenade is invalid - if (IsEntityNull (ent)) + if (IsEntityNull (m_avoidGrenade)) { m_avoidGrenade = NULL; m_needAvoidGrenade = 0; } - else if ((ent->v.flags & FL_ONGROUND) || (ent->v.effects & EF_NODRAW)) + else if ((m_avoidGrenade->v.flags & FL_ONGROUND) || (m_avoidGrenade->v.effects & EF_NODRAW)) { m_avoidGrenade = NULL; m_needAvoidGrenade = 0; } - ent = NULL; + Array activeGrenades = g_botManager->GetActiveGrenades (); // find all grenades on the map - while (!IsEntityNull (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) + IterateArray (activeGrenades, it) { - // if grenade is invisible don't care for it - if (ent->v.effects & EF_NODRAW) - continue; + edict_t *ent = activeGrenades[it]; // check if visible to the bot if (!EntityIsVisible (ent->v.origin) && InFieldOfView (ent->v.origin - EyePosition ()) > pev->fov / 2) @@ -272,12 +408,12 @@ void Bot::AvoidGrenades (void) // TODO: should be done once for grenade, instead of checking several times if (m_difficulty == 4 && strcmp (STRING (ent->v.model) + 9, "flashbang.mdl") == 0) { - Vector position = (GetEntityOrigin (ent) - EyePosition ()).ToAngles (); + const Vector &position = (GetEntityOrigin (ent) - EyePosition ()).ToAngles (); - // don't look at flashbang + // don't look at flash bang if (!(m_states & STATE_SEEING_ENEMY)) { - pev->v_angle.y = AngleNormalize (position.y + 180.0); + pev->v_angle.y = AngleNormalize (position.y + 180.0f); m_canChooseAimDirection = false; } } @@ -298,8 +434,8 @@ void Bot::AvoidGrenades (void) { MakeVectors (pev->v_angle); - Vector dirToPoint = (pev->origin - ent->v.origin).Normalize2D (); - Vector rightSide = g_pGlobals->v_right.Normalize2D (); + const Vector &dirToPoint = (pev->origin - ent->v.origin).Normalize2D (); + const Vector &rightSide = g_pGlobals->v_right.Normalize2D (); if ((dirToPoint | rightSide) > 0) m_needAvoidGrenade = -1; @@ -315,21 +451,28 @@ void Bot::AvoidGrenades (void) bool Bot::IsBehindSmokeClouds (edict_t *ent) { - edict_t *pentGrenade = NULL; - Vector betweenUs = (ent->v.origin - pev->origin).Normalize (); + if (!g_botManager->HasActiveGrenades ()) + return false; - while (!IsEntityNull (pentGrenade = FIND_ENTITY_BY_CLASSNAME (pentGrenade, "grenade"))) + const Vector &betweenUs = (ent->v.origin - pev->origin).Normalize (); + Array activeGrenades = g_botManager->GetActiveGrenades (); + + // find all grenades on the map + IterateArray (activeGrenades, it) { + edict_t *pentGrenade = activeGrenades[it]; + // if grenade is invisible don't care for it - if ((pentGrenade->v.effects & EF_NODRAW) || !(pentGrenade->v.flags & (FL_ONGROUND | FL_PARTIALGROUND)) || strcmp (STRING (pentGrenade->v.model) + 9, "smokegrenade.mdl")) + if (!(pentGrenade->v.flags & (FL_ONGROUND | FL_PARTIALGROUND)) || strcmp (STRING (pentGrenade->v.model) + 9, "smokegrenade.mdl")) continue; // check if visible to the bot if (!EntityIsVisible (ent->v.origin) && InFieldOfView (ent->v.origin - EyePosition ()) > pev->fov / 3) continue; - Vector betweenNade = (GetEntityOrigin (pentGrenade) - pev->origin).Normalize (); - Vector betweenResult = ((Vector (betweenNade.y, betweenNade.x, 0) * 150.0 + GetEntityOrigin (pentGrenade)) - pev->origin).Normalize (); + const Vector &entityOrigin = GetEntityOrigin (pentGrenade); + const Vector &betweenNade = (entityOrigin - pev->origin).Normalize (); + const Vector &betweenResult = ((Vector (betweenNade.y, betweenNade.x, 0) * 150.0 + entityOrigin) - pev->origin).Normalize (); if ((betweenNade | betweenUs) > (betweenNade | betweenResult)) return true; @@ -527,26 +670,29 @@ void Bot::FindItem (void) bool allowPickup = false; float distance, minDistance = 341.0; + const float searchRadius = 340.0f; if (!IsEntityNull (m_pickupItem)) { bool itemExists = false; pickupItem = m_pickupItem; - while (!IsEntityNull (ent = FIND_ENTITY_IN_SPHERE (ent, pev->origin, 340.0))) + while (!IsEntityNull (ent = FIND_ENTITY_IN_SPHERE (ent, pev->origin, searchRadius))) { if ((ent->v.effects & EF_NODRAW) || IsValidPlayer (ent->v.owner)) - continue; // someone owns this weapon or it hasn't respawned yet + continue; // someone owns this weapon or it hasn't re spawned yet if (ent == pickupItem) { if (ItemIsVisible (GetEntityOrigin (ent), const_cast (STRING (ent->v.classname)))) itemExists = true; + break; } } if (itemExists) return; + else { m_pickupItem = NULL; @@ -565,7 +711,7 @@ void Bot::FindItem (void) m_pickupItem = NULL; m_pickupType = PICKUP_NONE; - while (!IsEntityNull (ent = FIND_ENTITY_IN_SPHERE (ent, pev->origin, 340.0))) + while (!IsEntityNull (ent = FIND_ENTITY_IN_SPHERE (ent, pev->origin, searchRadius))) { allowPickup = false; // assume can't use it until known otherwise @@ -659,7 +805,7 @@ void Bot::FindItem (void) if (pickupType == PICKUP_DROPPED_C4) { allowPickup = true; - m_destOrigin = entityOrigin; // ensure we reached droped bomb + m_destOrigin = entityOrigin; // ensure we reached dropped bomb ChatterMessage (Chatter_FoundC4); // play info about that DeleteSearchNodes (); @@ -849,7 +995,7 @@ void Bot::GetCampDirection (Vector *dest) // mostly used for getting a good camping direction vector if not camping on a camp waypoint TraceResult tr; - Vector src = EyePosition (); + const Vector &src = EyePosition (); TraceLine (src, *dest, true, GetEntity (), &tr); @@ -1850,141 +1996,7 @@ void Bot::SetConditions (void) m_aimFlags |= AIM_LAST_ENEMY; } } - - // check if throwing a grenade is a good thing to do... - if (m_lastEnemy != NULL && !yb_ignore_enemies.GetBool() && !yb_jasonmode.GetBool() && m_grenadeCheckTime < GetWorldTime() && !m_isUsingGrenade && GetTaskId() != TASK_PLANTBOMB && GetTaskId() != TASK_DEFUSEBOMB && !m_isReloading && IsAlive(m_lastEnemy)) - { - // check again in some seconds - m_grenadeCheckTime = GetWorldTime () + yb_timergrenade.GetFloat (); - - // check if we have grenades to throw - int grenadeToThrow = CheckGrenades (); - - // if we don't have grenades no need to check it this round again - if (grenadeToThrow == -1) - { - m_grenadeCheckTime = GetWorldTime () + 15.0; // changed since, conzero can drop grens from dead players - m_states &= ~(STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG); - } - else - { - // care about different types of grenades - if ((grenadeToThrow == WEAPON_EXPLOSIVE || grenadeToThrow == WEAPON_SMOKE) && Random.Long (0, 100) < 45 && !(m_states & (STATE_SEEING_ENEMY | STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG))) - { - float distance = (m_lastEnemy->v.origin - pev->origin).GetLength (); - - // is enemy to high to throw - if ((m_lastEnemy->v.origin.z > (pev->origin.z + 650.0)) || !(m_lastEnemy->v.flags & (FL_ONGROUND | FL_DUCKING))) - distance = FLT_MAX; // just some crazy value - - // enemy is within a good throwing distance ? - if (distance > (grenadeToThrow == WEAPON_SMOKE ? 400 : 600) && distance <= 1000) - { - // care about different types of grenades - if (grenadeToThrow == WEAPON_EXPLOSIVE) - { - bool allowThrowing = true; - - // check for teammates - if (GetNearbyFriendsNearPosition (m_lastEnemy->v.origin, 256) > 0) - allowThrowing = false; - - if (allowThrowing && m_seeEnemyTime + 2.0 < GetWorldTime ()) - { - Vector enemyPredict = ((m_lastEnemy->v.velocity * 0.5).SkipZ () + m_lastEnemy->v.origin); - int searchTab[4], count = 4; - - float searchRadius = m_lastEnemy->v.velocity.GetLength2D (); - - // check the search radius - if (searchRadius < 128.0) - searchRadius = 128.0; - - // search waypoints - g_waypoint->FindInRadius (enemyPredict, searchRadius, searchTab, &count); - - while (count > 0) - { - allowThrowing = true; - - // check the throwing - m_throw = g_waypoint->GetPath (searchTab[count--])->origin; - Vector src = CheckThrow (EyePosition (), m_throw); - - if (src.GetLengthSquared () < 100.0) - src = CheckToss (EyePosition (), m_throw); - - if (src == nullvec) - allowThrowing = false; - else - break; - } - } - - // start explosive grenade throwing? - if (allowThrowing) - m_states |= STATE_THROW_HE; - else - m_states &= ~STATE_THROW_HE; - } - else if (grenadeToThrow == WEAPON_SMOKE) - { - // start smoke grenade throwing? - if ((m_states & STATE_SEEING_ENEMY) && GetShootingConeDeviation (m_enemy, &pev->origin) >= 0.70 && m_seeEnemyTime + 2.0 < GetWorldTime ()) - m_states &= ~STATE_THROW_SG; - else - m_states |= STATE_THROW_SG; - } - } - } - else if (IsAlive (m_lastEnemy) && grenadeToThrow == WEAPON_FLASHBANG && (m_lastEnemy->v.origin - pev->origin).GetLength () < 800 && !(m_aimFlags & AIM_ENEMY) && Random.Long (0, 100) < 50) - { - bool allowThrowing = true; - Array inRadius; - - g_waypoint->FindInRadius (inRadius, 256, m_lastEnemy->v.origin + (m_lastEnemy->v.velocity * 0.5).SkipZ ()); - - IterateArray (inRadius, i) - { - Path *path = g_waypoint->GetPath (i); - - if (GetNearbyFriendsNearPosition (path->origin, 256) != 0 || !(m_difficulty == 4 && GetNearbyFriendsNearPosition (path->origin, 256) != 0)) - continue; - - m_throw = path->origin; - Vector src = CheckThrow (EyePosition (), m_throw); - - if (src.GetLengthSquared () < 100) - src = CheckToss (EyePosition (), m_throw); - - if (src == nullvec) - continue; - - allowThrowing = true; - break; - } - - // start concussion grenade throwing? - if (allowThrowing && m_seeEnemyTime + 2.0 < GetWorldTime ()) - m_states |= STATE_THROW_FB; - else - m_states &= ~STATE_THROW_FB; - } - - if (m_states & STATE_THROW_HE) - StartTask (TASK_THROWHEGRENADE, TASKPRI_THROWGRENADE, -1, GetWorldTime () + 3.0, false); - else if (m_states & STATE_THROW_FB) - StartTask (TASK_THROWFLASHBANG, TASKPRI_THROWGRENADE, -1, GetWorldTime () + 3.0, false); - else if (m_states & STATE_THROW_SG) - StartTask (TASK_THROWSMOKE, TASKPRI_THROWGRENADE, -1, GetWorldTime () + 3.0, false); - - // delay next grenade throw - if (m_states & (STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG)) - m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; - } - } - else - m_states &= ~(STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG); + CheckGrenadeThrow (); // check if there are items needing to be used/collected if (m_itemCheckTime < GetWorldTime () || !IsEntityNull (m_pickupItem)) @@ -2078,7 +2090,7 @@ void Bot::SetConditions (void) // if half of the round is over, allow hunting // FIXME: it probably should be also team/map dependant - if (IsEntityNull (m_enemy) && (g_timeRoundMid < GetWorldTime ()) && !m_isUsingGrenade && m_currentWaypointIndex != g_waypoint->FindNearest (m_lastEnemyOrigin) && m_personality != PERSONALITY_CAREFUL) + if (IsEntityNull (m_enemy) && g_timeRoundMid < GetWorldTime () && !m_isUsingGrenade && m_currentWaypointIndex != g_waypoint->FindNearest (m_lastEnemyOrigin) && m_personality != PERSONALITY_CAREFUL) { desireLevel = 4096.0 - ((1.0 - tempAgression) * distance); desireLevel = (100 * desireLevel) / 4096.0; @@ -2098,7 +2110,7 @@ void Bot::SetConditions (void) g_taskFilters[TASK_HUNTENEMY].desire = 0; } - // blinded behaviour + // blinded behavior if (m_blindTime > GetWorldTime ()) g_taskFilters[TASK_BLINDED].desire = TASKPRI_BLINDED; else @@ -2135,7 +2147,7 @@ void Bot::SetConditions (void) if (!m_tasks.IsEmpty ()) { final = MaxDesire (final, GetTask ()); - StartTask (final->id, final->desire, final->data, final->time, final->resume); // push the final behaviour in our task stack to carry out + StartTask (final->id, final->desire, final->data, final->time, final->resume); // push the final behavior in our task stack to carry out } } @@ -3001,7 +3013,7 @@ void Bot::ChooseAimDirection (void) { if ((g_experienceData + (index * g_numWaypoints) + index)->team0DangerIndex != -1) { - Vector dest = g_waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team0DangerIndex)->origin; + const Vector &dest = g_waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team0DangerIndex)->origin; TraceLine (pev->origin, dest, true, GetEntity (), &tr); if (tr.flFraction > 0.8 || tr.pHit != g_worldEdict) @@ -3012,7 +3024,7 @@ void Bot::ChooseAimDirection (void) { if ((g_experienceData + (index * g_numWaypoints) + index)->team1DangerIndex != -1) { - Vector dest = g_waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team1DangerIndex)->origin; + const Vector &dest = g_waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team1DangerIndex)->origin; TraceLine (pev->origin, dest, true, GetEntity (), &tr); if (tr.flFraction > 0.8 || tr.pHit != g_worldEdict) @@ -3728,7 +3740,7 @@ void Bot::RunTask (void) int foundPoints[3]; int distanceTab[3]; - Vector dotA = (destination - pev->origin).Normalize2D (); + const Vector &dotA = (destination - pev->origin).Normalize2D (); for (i = 0; i < g_numWaypoints; i++) { @@ -3736,7 +3748,7 @@ void Bot::RunTask (void) if (!g_waypoint->IsVisible (m_currentWaypointIndex, i) || (i == m_currentWaypointIndex)) continue; - Vector dotB = (g_waypoint->GetPath (i)->origin - pev->origin).Normalize2D (); + const Vector &dotB = (g_waypoint->GetPath (i)->origin - pev->origin).Normalize2D (); if ((dotA | dotB) > 0.9) { @@ -4254,9 +4266,13 @@ void Bot::RunTask (void) else { edict_t *ent = NULL; + Array activeGrenades = g_botManager->GetActiveGrenades (); - while (!IsEntityNull (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) + // find all grenades on the map + IterateArray (activeGrenades, it) { + ent = activeGrenades[it]; + if (ent->v.owner == GetEntity () && strcmp (STRING (ent->v.model) + 9, "hegrenade.mdl") == 0) { // set the correct velocity for the grenade @@ -4320,8 +4336,13 @@ void Bot::RunTask (void) else { edict_t *ent = NULL; - while (!IsEntityNull (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) + Array activeGrenades = g_botManager->GetActiveGrenades (); + + // find all grenades on the map + IterateArray (activeGrenades, it) { + ent = activeGrenades[it]; + if (ent->v.owner == GetEntity () && strcmp (STRING (ent->v.model) + 9, "flashbang.mdl") == 0) { // set the correct velocity for the grenade @@ -4907,10 +4928,10 @@ void Bot::BotAI (void) SetIdealReactionTimes (); // calculate 2 direction vectors, 1 without the up/down component - Vector directionOld = m_destOrigin - (pev->origin + pev->velocity * m_frameInterval); + const Vector &directionOld = m_destOrigin - (pev->origin + pev->velocity * m_frameInterval); Vector directionNormal = directionOld.Normalize (); - Vector direction = directionNormal; + const Vector &direction = directionNormal; directionNormal.z = 0.0; m_moveAngles = directionOld.ToAngles (); @@ -5245,13 +5266,13 @@ void Bot::BotAI (void) while (node != NULL) { - Vector srcPath = g_waypoint->GetPath (node->index)->origin; + const Vector &srcPath = g_waypoint->GetPath (node->index)->origin; node = node->next; if (node != NULL) { - Vector dest = g_waypoint->GetPath (node->index)->origin; - DrawArrow (g_hostEntity, srcPath, dest, 15, 0, 255, 100, 55, 200, 5, 1); + const Vector &dstPath = g_waypoint->GetPath (node->index)->origin; + DrawArrow (g_hostEntity, srcPath, dstPath, 15, 0, 255, 100, 55, 200, 5, 1); } } } @@ -5634,7 +5655,7 @@ void Bot::DebugMsg (const char *format, ...) vsprintf (buffer, format, ap); va_end (ap); - ServerPrintNoTag ("%s: %s", STRING (pev->netname), buffer); + ServerPrint ("%s: %s", STRING (pev->netname), buffer); if (yb_debug.GetInt () >= 3) AddLogEntry (false, LL_DEFAULT, "%s: %s", STRING (pev->netname), buffer); @@ -5744,7 +5765,7 @@ Vector Bot::CheckBombAudible (void) if (m_difficulty >= 3) return g_waypoint->GetBombPosition(); - Vector bombOrigin = g_waypoint->GetBombPosition (); + const Vector &bombOrigin = g_waypoint->GetBombPosition (); float timeElapsed = ((GetWorldTime () - g_timeBombPlanted) / mp_c4timer.GetFloat ()) * 100; float desiredRadius = 768.0; @@ -5766,7 +5787,7 @@ Vector Bot::CheckBombAudible (void) return nullvec; } -void Bot::MoveToVector (Vector to) +void Bot::MoveToVector (const Vector &to) { if (to == nullvec) return; @@ -5919,7 +5940,7 @@ bool Bot::OutOfBombTimer (void) if (timeLeft > 16) return false; - Vector bombOrigin = g_waypoint->GetBombPosition (); + const Vector &bombOrigin = g_waypoint->GetBombPosition (); // for terrorist, if timer is lower than eleven seconds, return true if (static_cast (timeLeft) < 16 && m_team == TEAM_TF && (bombOrigin - pev->origin).GetLength () < 1000) @@ -6109,7 +6130,7 @@ void Bot::EquipInBuyzone (int buyCount) } } -bool Bot::IsBombDefusing (Vector bombOrigin) +bool Bot::IsBombDefusing (const Vector &bombOrigin) { // this function finds if somebody currently defusing the bomb. diff --git a/source/combat.cpp b/source/combat.cpp index bfe14b1..64cc786 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -15,7 +15,7 @@ ConVar yb_csdm_mode ("yb_csdm_mode", "0", VT_NOSERVER); ConVar mp_friendlyfire ("mp_friendlyfire", NULL, VT_NOREGISTER); -int Bot::GetNearbyFriendsNearPosition (Vector origin, int radius) +int Bot::GetNearbyFriendsNearPosition (const Vector &origin, int radius) { int count = 0; @@ -30,7 +30,7 @@ int Bot::GetNearbyFriendsNearPosition (Vector origin, int radius) return count; } -int Bot::GetNearbyEnemiesNearPosition (Vector origin, int radius) +int Bot::GetNearbyEnemiesNearPosition (const Vector &origin, int radius) { int count = 0; @@ -271,7 +271,7 @@ bool Bot::LookupEnemy (void) return false; } -Vector Bot::GetAimPosition (void) +const Vector &Bot::GetAimPosition (void) { // the purpose of this function, is to make bot aiming not so ideal. it's mutate m_enemyOrigin enemy vector // returned from visibility check function. @@ -1406,7 +1406,7 @@ void Bot::CommandTeam (void) m_timeTeamOrder = GetWorldTime () + Random.Float (5.0, 30.0); } -bool Bot::IsGroupOfEnemies (Vector location, int numEnemies, int radius) +bool Bot::IsGroupOfEnemies (const Vector &location, int numEnemies, int radius) { int numPlayers = 0; diff --git a/source/interface.cpp b/source/interface.cpp index b68c17e..e5d06fc 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -165,7 +165,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c "------------------------------------------------\n" "Name: %s\n" "Version: %s (Build: %u)\n" - "Compiled: %s, %s +300 (GMT)\n" + "Compiled: %s, %s tz: +3\n" "------------------------------------------------"; ClientPrint (ent, print_console, versionData, PRODUCT_NAME, PRODUCT_VERSION, GenerateBuildNumber (), __DATE__, __TIME__); @@ -201,27 +201,27 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c if (!IsDedicatedServer ()) { - ServerPrintNoTag ("yapb autowp - toggle autowppointing."); - ServerPrintNoTag ("yapb wp - toggle waypoint showing."); - ServerPrintNoTag ("yapb wp on noclip - enable noclip cheat"); - ServerPrintNoTag ("yapb wp save nocheck - save waypoints without checking."); - ServerPrintNoTag ("yapb wp add - open menu for waypoint creation."); - ServerPrintNoTag ("yapb wp menu - open main waypoint menu."); - ServerPrintNoTag ("yapb wp addbasic - creates basic waypoints on map."); - ServerPrintNoTag ("yapb wp find - show direction to specified waypoint."); - ServerPrintNoTag ("yapb wp load - wload the waypoint file from hard disk."); - ServerPrintNoTag ("yapb wp check - checks if all waypoints connections are valid."); - ServerPrintNoTag ("yapb wp cache - cache nearest waypoint."); - ServerPrintNoTag ("yapb wp teleport - teleport hostile to specified waypoint."); - ServerPrintNoTag ("yapb wp setradius - manually sets the wayzone radius for this waypoint."); - ServerPrintNoTag ("yapb path autodistance - opens menu for setting autopath maximum distance."); - ServerPrintNoTag ("yapb path cache - remember the nearest to player waypoint."); - ServerPrintNoTag ("yapb path create - opens menu for path creation."); - ServerPrintNoTag ("yapb path delete - delete path from cached to nearest waypoint."); - ServerPrintNoTag ("yapb path create_in - creating incoming path connection."); - ServerPrintNoTag ("yapb path create_out - creating outgoing path connection."); - ServerPrintNoTag ("yapb path create_both - creating both-ways path connection."); - ServerPrintNoTag ("yapb exp save - save the experience data."); + ServerPrint ("yapb autowp - toggle autowppointing."); + ServerPrint ("yapb wp - toggle waypoint showing."); + ServerPrint ("yapb wp on noclip - enable noclip cheat"); + ServerPrint ("yapb wp save nocheck - save waypoints without checking."); + ServerPrint ("yapb wp add - open menu for waypoint creation."); + ServerPrint ("yapb wp menu - open main waypoint menu."); + ServerPrint ("yapb wp addbasic - creates basic waypoints on map."); + ServerPrint ("yapb wp find - show direction to specified waypoint."); + ServerPrint ("yapb wp load - wload the waypoint file from hard disk."); + ServerPrint ("yapb wp check - checks if all waypoints connections are valid."); + ServerPrint ("yapb wp cache - cache nearest waypoint."); + ServerPrint ("yapb wp teleport - teleport hostile to specified waypoint."); + ServerPrint ("yapb wp setradius - manually sets the wayzone radius for this waypoint."); + ServerPrint ("yapb path autodistance - opens menu for setting autopath maximum distance."); + ServerPrint ("yapb path cache - remember the nearest to player waypoint."); + ServerPrint ("yapb path create - opens menu for path creation."); + ServerPrint ("yapb path delete - delete path from cached to nearest waypoint."); + ServerPrint ("yapb path create_in - creating incoming path connection."); + ServerPrint ("yapb path create_out - creating outgoing path connection."); + ServerPrint ("yapb path create_both - creating both-ways path connection."); + ServerPrint ("yapb exp save - save the experience data."); } } } @@ -249,7 +249,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c if (stricmp (arg0, "randgen") == 0) { for (int i = 0; i < 500; i++) - ServerPrintNoTag ("Result Range[0 - 100]: %d", Random.Long (0, 100)); + ServerPrint ("Result Range[0 - 100]: %d", Random.Long (0, 100)); } #if defined (MMGR_H) // dump memory information @@ -997,12 +997,12 @@ void Touch (edict_t *pentTouched, edict_t *pentOther) // the two entities both have velocities, for example two players colliding, this function // is called twice, once for each entity moving. - if (!IsEntityNull (pentTouched) && (pentTouched->v.flags & FL_FAKECLIENT)) + if (!IsEntityNull (pentOther) && (pentOther->v.flags & FL_FAKECLIENT)) { - Bot *touched = g_botManager->GetBot (pentTouched); + Bot *bot = g_botManager->GetBot (pentOther); - if (touched != NULL) - touched->VerifyBreakable (pentOther); + if (bot != NULL) + bot->VerifyBreakable (pentTouched); } if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -1440,7 +1440,7 @@ void ClientCommand (edict_t *ent) if (path->flags & FLAG_NOHOSTAGE) noHostagePoints++; } - ServerPrintNoTag ("Waypoints: %d - T Points: %d\n" + ServerPrint ("Waypoints: %d - T Points: %d\n" "CT Points: %d - Goal Points: %d\n" "Rescue Points: %d - Camp Points: %d\n" "Block Hostage Points: %d - Sniper Points: %d\n", g_numWaypoints, terrPoints, ctPoints, goalPoints, rescuePoints, campPoints, noHostagePoints, sniperPoints); @@ -2216,7 +2216,7 @@ void StartFrame (void) } g_botManager->SetDeathMsgState (false); - if (g_timePerSecondUpdate <= GetWorldTime ()) + if (g_timePerSecondUpdate < GetWorldTime ()) { g_botManager->CalculatePingOffsets (); @@ -2246,20 +2246,28 @@ void StartFrame (void) } } } - - if (g_isMetamod) - { - cvar_t *csdm_active = CVAR_GET_POINTER ("csdm_active"); - cvar_t *mp_freeforall = CVAR_GET_POINTER ("mp_freeforall"); - - if (csdm_active != NULL && csdm_active->value > 0) - yb_csdm_mode.SetInt (mp_freeforall != NULL && mp_freeforall->value > 0 ? 2 : 1); - } - g_timePerSecondUpdate = GetWorldTime () + 1.0f; } if (g_bombPlanted) g_waypoint->SetBombPosition (); + + if (g_isMetamod) + { + static cvar_t *csdm_active; + static cvar_t *mp_freeforall; + + if (csdm_active == NULL) + csdm_active = CVAR_GET_POINTER ("csdm_active"); + + if (mp_freeforall == NULL) + mp_freeforall = CVAR_GET_POINTER ("mp_freeforall"); + + if (csdm_active != NULL && csdm_active->value > 0) + yb_csdm_mode.SetInt (mp_freeforall != NULL && mp_freeforall->value > 0 ? 2 : 1); + } + g_timePerSecondUpdate = GetWorldTime () + 1.0f; } + else if (g_timePerSecondUpdate * 0.5f < GetWorldTime ()) + g_botManager->UpdateActiveGrenades (); // keep bot number up to date g_botManager->MaintainBotQuota (); diff --git a/source/manager.cpp b/source/manager.cpp index 5a6c958..a140d4b 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -244,7 +244,7 @@ void BotManager::Think (void) // error occurred. kick off all bots and then print a warning message RemoveAll (); - ServerPrintNoTag ("**** INTERNAL BOT ERROR! PLEASE SHUTDOWN AND RESTART YOUR SERVER! ****"); + ServerPrint ("**** INTERNAL BOT ERROR! PLEASE SHUTDOWN AND RESTART YOUR SERVER! ****"); } #else m_bots[i]->Think (); @@ -612,7 +612,7 @@ void BotManager::ListBots (void) { // this function list's bots currently playing on the server - ServerPrintNoTag ("%-3.5s %-9.13s %-17.18s %-3.4s %-3.4s %-3.4s", "index", "name", "personality", "team", "difficulty", "frags"); + ServerPrint ("%-3.5s %-9.13s %-17.18s %-3.4s %-3.4s %-3.4s", "index", "name", "personality", "team", "difficulty", "frags"); for (int i = 0; i < GetMaxClients (); i++) { @@ -624,7 +624,7 @@ void BotManager::ListBots (void) Bot *bot = GetBot (player); if (bot != NULL) - ServerPrintNoTag ("[%-3.1d] %-9.13s %-17.18s %-3.4s %-3.1d %-3.1d", i, STRING (player->v.netname), bot->m_personality == PERSONALITY_RUSHER ? "rusher" : bot->m_personality == PERSONALITY_NORMAL ? "normal" : "careful", GetTeam (player) != 0 ? "CT" : "T", bot->m_difficulty, static_cast (player->v.frags)); + ServerPrint ("[%-3.1d] %-9.13s %-17.18s %-3.4s %-3.1d %-3.1d", i, STRING (player->v.netname), bot->m_personality == PERSONALITY_RUSHER ? "rusher" : bot->m_personality == PERSONALITY_NORMAL ? "normal" : "careful", GetTeam (player) != 0 ? "CT" : "T", bot->m_difficulty, static_cast (player->v.frags)); } } } @@ -1347,4 +1347,26 @@ void BotManager::SendDeathMsgFix (void) for (int i = 0; i < GetMaxClients (); i++) SendPingDataOffsets (g_clients[i].ent); } +} + +void BotManager::UpdateActiveGrenades (void) +{ + edict_t *grenade = NULL; + + // clear previously stored grenades + m_activeGrenades.RemoveAll (); + + // search the map for any type of grenade + while (!IsEntityNull (grenade = FIND_ENTITY_BY_CLASSNAME (grenade, "grenade"))) + { + if (grenade->v.effects & EF_NODRAW) + continue; + + m_activeGrenades.Push (grenade); + } +} + +const Array &BotManager::GetActiveGrenades (void) +{ + return m_activeGrenades; } \ No newline at end of file diff --git a/source/navigate.cpp b/source/navigate.cpp index b843434..09bebd2 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -1715,7 +1715,7 @@ void Bot::DeleteSearchNodes (void) m_chosenGoalIndex = -1; } -int Bot::GetAimingWaypoint (Vector targetOriginPos) +int Bot::GetAimingWaypoint (const Vector &to) { // return the most distant waypoint which is seen from the Bot to the Target and is within count @@ -1723,7 +1723,7 @@ int Bot::GetAimingWaypoint (Vector targetOriginPos) ChangeWptIndex (g_waypoint->FindNearest (pev->origin)); int srcIndex = m_currentWaypointIndex; - int destIndex = g_waypoint->FindNearest (targetOriginPos); + int destIndex = g_waypoint->FindNearest (to); int bestIndex = srcIndex; PathNode *node = new PathNode; @@ -2022,7 +2022,7 @@ int Bot::ChooseBombWaypoint (void) return goal; } -int Bot::FindDefendWaypoint (Vector origin) +int Bot::FindDefendWaypoint (const Vector &origin) { // this function tries to find a good position which has a line of sight to a position, // provides enough cover point, and is far away from the defending position @@ -2280,7 +2280,7 @@ int Bot::FindCoverWaypoint (float maxDistance) bool Bot::GetBestNextWaypoint (void) { - // this function does a realtime postprocessing of waypoints return from the + // this function does a realtime post processing of waypoints return from the // pathfinder, to vary paths and find the best waypoint on our way InternalAssert (m_navNode != NULL); @@ -2300,7 +2300,9 @@ bool Bot::GetBestNextWaypoint (void) if (!IsPointOccupied (id)) { + DebugMsg ("postprocess %d -> %d", m_navNode->index, id); m_navNode->index = id; + return true; } } @@ -2323,7 +2325,6 @@ bool Bot::HeadTowardWaypoint (void) m_navNode = m_navNode->next; // advance in list m_currentTravelFlags = 0; // reset travel flags (jumping etc) - // we're not at the end of the list? // we're not at the end of the list? if (m_navNode != NULL) { @@ -2334,7 +2335,7 @@ bool Bot::HeadTowardWaypoint (void) m_minSpeed = pev->maxspeed; // only if we in normal task and bomb is not planted - if (GetTaskId () == TASK_NORMAL && m_timeCamping + 30.0f < GetWorldTime () && !g_bombPlanted && m_personality != PERSONALITY_RUSHER && !m_hasC4 && !m_isVIP && m_loosedBombWptIndex == -1 && !HasHostage ()) + if (GetTaskId () == TASK_NORMAL && g_timeRoundMid + 10.0f < GetWorldTime () && m_timeCamping + 30.0f < GetWorldTime () && !g_bombPlanted && m_personality != PERSONALITY_RUSHER && !m_hasC4 && !m_isVIP && m_loosedBombWptIndex == -1 && !HasHostage ()) { m_campButtons = 0; @@ -2347,7 +2348,7 @@ bool Bot::HeadTowardWaypoint (void) kills = (g_experienceData + (waypoint * g_numWaypoints) + waypoint)->team1Damage / g_highestDamageCT; // if damage done higher than one - if (kills > 0.15f && g_timeRoundMid > GetWorldTime ()) + if (kills > 0.15f && g_timeRoundMid + 15.0f < GetWorldTime ()) { switch (m_personality) { @@ -2887,17 +2888,17 @@ bool Bot::CheckWallOnRight (void) return false; } -bool Bot::IsDeadlyDrop (Vector targetOriginPos) +bool Bot::IsDeadlyDrop (const Vector &to) { // this function eturns if given location would hurt Bot with falling damage Vector botPos = pev->origin; TraceResult tr; - Vector move ((targetOriginPos - botPos).ToYaw (), 0, 0); + Vector move ((to - botPos).ToYaw (), 0, 0); MakeVectors (move); - Vector direction = (targetOriginPos - botPos).Normalize (); // 1 unit long + Vector direction = (to - botPos).Normalize (); // 1 unit long Vector check = botPos; Vector down = botPos; @@ -2911,7 +2912,7 @@ bool Bot::IsDeadlyDrop (Vector targetOriginPos) float height; float lastHeight = tr.flFraction * 1000.0; // height from ground - float distance = (targetOriginPos - check).GetLength (); // distance from goal + float distance = (to - check).GetLength (); // distance from goal while (distance > 16.0) { @@ -2931,7 +2932,7 @@ bool Bot::IsDeadlyDrop (Vector targetOriginPos) return true; lastHeight = height; - distance = (targetOriginPos - check).GetLength (); // distance from goal + distance = (to - check).GetLength (); // distance from goal } return false; } @@ -3236,11 +3237,11 @@ void Bot::FacePosition (void) pev->angles.z = pev->v_angle.z = 0.0; // ignore Z component } -void Bot::SetStrafeSpeed (Vector moveDir, float strafeSpeed) +void Bot::SetStrafeSpeed (const Vector &moveDir, float strafeSpeed) { MakeVectors (pev->angles); - Vector los = (moveDir - pev->origin).Normalize2D (); + const Vector &los = (moveDir - pev->origin).Normalize2D (); float dot = los | g_pGlobals->v_forward.SkipZ (); if (dot > 0 && !CheckWallOnRight ()) @@ -3290,7 +3291,7 @@ bool Bot::IsPointOccupied (int index) // check if this waypoint is already used if (IsAlive (bot->GetEntity ())) { - if ((GetShootingConeDeviation (bot->GetEntity (), &pev->origin) >= 0.7 ? bot->m_prevWptIndex[0] : m_currentWaypointIndex) == index || bot->GetTask ()->data == index || (g_waypoint->GetPath (index)->origin - bot->pev->origin).GetLength2D () < 96.0) + if ((GetShootingConeDeviation (bot->GetEntity (), &pev->origin) >= 0.7 ? bot->m_prevWptIndex[0] : m_currentWaypointIndex) == index || bot->GetTask ()->data == index) return true; } } diff --git a/source/support.cpp b/source/support.cpp index e1ac758..abd2d64 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -145,7 +145,7 @@ Vector GetEntityOrigin (edict_t *ent) return nullvec; if (ent->v.origin == nullvec) - return ent->v.absmin + (ent->v.size * 0.5); + return ent->v.absmin + ent->v.size * 0.5; return ent->v.origin; } @@ -769,7 +769,7 @@ void RoundInit (void) // calculate the round mid/end in world time g_timeRoundStart = GetWorldTime () + mp_freezetime.GetFloat (); - g_timeRoundMid = g_timeRoundStart + mp_roundtime.GetFloat () * 60 / 2; + g_timeRoundMid = g_timeRoundStart + mp_roundtime.GetFloat () * 60 * 0.5f; g_timeRoundEnd = g_timeRoundStart + mp_roundtime.GetFloat () * 60; } @@ -881,19 +881,8 @@ void ServerPrint (const char *format, ...) vsprintf (string, g_localizer->TranslateInput (format), ap); va_end (ap); - SERVER_PRINT (FormatBuffer ("%s\n", string)); -} - -void ServerPrintNoTag (const char *format, ...) -{ - va_list ap; - char string[3072]; - - va_start (ap, format); - vsprintf (string, g_localizer->TranslateInput (format), ap); - va_end (ap); - - SERVER_PRINT (FormatBuffer ("%s\n", string)); + SERVER_PRINT (string); + SERVER_PRINT ("\n"); } void CenterPrint (const char *format, ...) @@ -954,7 +943,7 @@ void ClientPrint (edict_t *ent, int dest, const char *format, ...) if (dest & 0x3ff) ServerPrint (string); else - ServerPrintNoTag (string); + ServerPrint (string); return; } @@ -1206,7 +1195,7 @@ void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...) } if (outputToConsole) - ServerPrintNoTag ("%s%s", levelString, buffer); + ServerPrint ("%s%s", levelString, buffer); // now check if logging disabled if (!(logLevel & LL_IGNORE)) diff --git a/source/waypoint.cpp b/source/waypoint.cpp index 62aee3e..9ec34a2 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -83,7 +83,7 @@ void Waypoint::AddPath (short int addIndex, short int pathIndex, float distance) } } -int Waypoint::FindFarest (Vector origin, float maxDistance) +int Waypoint::FindFarest (const Vector &origin, float maxDistance) { // find the farest waypoint to that Origin, and return the index to this waypoint @@ -102,7 +102,7 @@ int Waypoint::FindFarest (Vector origin, float maxDistance) return index; } -int Waypoint::FindNearest (Vector origin, float minDistance, int flags) +int Waypoint::FindNearest (const Vector &origin, float minDistance, int flags) { // find the nearest waypoint to that origin and return the index @@ -124,7 +124,7 @@ int Waypoint::FindNearest (Vector origin, float minDistance, int flags) return index; } -void Waypoint::FindInRadius (Vector origin, float radius, int *holdTab, int *count) +void Waypoint::FindInRadius (const Vector &origin, float radius, int *holdTab, int *count) { // returns all waypoints within radius from position @@ -145,7 +145,7 @@ void Waypoint::FindInRadius (Vector origin, float radius, int *holdTab, int *cou *count -= 1; } -void Waypoint::FindInRadius (Array &queueID, float radius, Vector origin) +void Waypoint::FindInRadius (Array &queueID, float radius, const Vector &origin) { for (int i = 0; i < g_numWaypoints; i++) { @@ -1234,7 +1234,7 @@ String Waypoint::CheckSubfolderFile (void) return FormatBuffer ("%s%s.pwf", GetWaypointDir (), GetMapName ()); } -float Waypoint::GetTravelTime (float maxSpeed, Vector src, Vector origin) +float Waypoint::GetTravelTime (float maxSpeed, const Vector &src, const Vector &origin) { // this function returns 2D traveltime to a position @@ -1277,7 +1277,7 @@ bool Waypoint::Reachable (Bot *bot, int index) return false; } -bool Waypoint::IsNodeReachable (Vector src, Vector destination) +bool Waypoint::IsNodeReachable (const Vector &src, const Vector &destination) { TraceResult tr;