From 02823791c071d0fada0b42ea1ab23d795c4dabc9 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 Jun 2015 00:18:49 +0300 Subject: [PATCH] save point for tomorrow, good night --- include/core.h | 21 +++++++++++++++++++-- source/basecode.cpp | 10 ++++++++-- source/interface.cpp | 30 +++++++++++++++++++----------- source/manager.cpp | 22 ++++++++++++++++++++++ source/navigate.cpp | 3 +-- 5 files changed, 69 insertions(+), 17 deletions(-) diff --git a/include/core.h b/include/core.h index a1a2d49..fef85fb 100644 --- a/include/core.h +++ b/include/core.h @@ -1284,6 +1284,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); @@ -1330,9 +1333,23 @@ 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); diff --git a/source/basecode.cpp b/source/basecode.cpp index 4b48395..d03bc50 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -243,6 +243,9 @@ void Bot::AvoidGrenades (void) { // checks if bot 'sees' a grenade, and avoid it + if (!g_botManager->HasActiveGrenades ()) + return; + edict_t *ent = m_avoidGrenade; // check if old pointers to grenade is invalid @@ -272,12 +275,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 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; } } @@ -315,6 +318,9 @@ void Bot::AvoidGrenades (void) bool Bot::IsBehindSmokeClouds (edict_t *ent) { + if (!g_botManager->HasActiveGrenades ()) + return false; + edict_t *pentGrenade = NULL; Vector betweenUs = (ent->v.origin - pev->origin).Normalize (); diff --git a/source/interface.cpp b/source/interface.cpp index 4de6233..d7e2372 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -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..eddcc6c 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -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 ea4f571..c2ca41c 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -2323,7 +2323,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) { @@ -2347,7 +2346,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) {