From aeb712c2b3d291acd6e07c92524dbbc6df87dcd2 Mon Sep 17 00:00:00 2001 From: jeefo Date: Thu, 7 Jan 2016 18:49:55 +0300 Subject: [PATCH] fixed race-condition in bomb location detection fixed visited goals are not cleared on round-start --- include/core.h | 1 + source/basecode.cpp | 5 +++-- source/navigate.cpp | 4 ++-- source/netmsg.cpp | 3 ++- source/support.cpp | 33 +++++++++++++++++++++++++++++++-- source/waypoint.cpp | 24 ++++++------------------ 6 files changed, 45 insertions(+), 25 deletions(-) diff --git a/include/core.h b/include/core.h index d352464..f712265 100644 --- a/include/core.h +++ b/include/core.h @@ -1584,6 +1584,7 @@ public: bool IsGoalVisited (int index); void SetGoalVisited (int index); + void ClearVisitedGoals (void); inline const Vector &GetBombPosition (void) { diff --git a/source/basecode.cpp b/source/basecode.cpp index 0c05df9..3782a21 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -587,6 +587,7 @@ void Bot::FindItem (void) break; } } + if (itemExists) return; @@ -787,7 +788,7 @@ void Bot::FindItem (void) } else if (pickupType == PICKUP_PLANTED_C4 && !OutOfBombTimer ()) { - if (m_states & (STATE_SEEING_ENEMY | STATE_SUSPECT_ENEMY)) + if (IsValidPlayer (m_enemy)) { allowPickup = false; return; @@ -5667,7 +5668,7 @@ Vector Bot::CheckBombAudible (void) { // this function checks if bomb is can be heard by the bot, calculations done by manual testing. - if (!g_bombPlanted || (GetTaskId () == TASK_ESCAPEFROMBOMB)) + if (!g_bombPlanted || GetTaskId () == TASK_ESCAPEFROMBOMB) return Vector::GetZero (); // reliability check if (m_difficulty >= 3) diff --git a/source/navigate.cpp b/source/navigate.cpp index 595cebb..3644e36 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -1220,7 +1220,7 @@ bool Bot::DoWaypointNav (void) if ((g_mapType & MAP_DE) && g_bombPlanted && m_team == TEAM_CF && GetTaskId () != TASK_ESCAPEFROMBOMB && GetTask ()->data != -1) { - Vector bombOrigin = CheckBombAudible (); + const Vector &bombOrigin = CheckBombAudible (); // bot within 'hearable' bomb tick noises? if (!bombOrigin.IsZero ()) @@ -2039,7 +2039,7 @@ int Bot::ChooseBombWaypoint (void) bombOrigin = pev->origin; int goal = 0, count = 0; - float lastDistance = 99999.0f; + float lastDistance = 999999.0f; // find nearest goal waypoint either to bomb (if "heard" or player) FOR_EACH_AE (goals, i) diff --git a/source/netmsg.cpp b/source/netmsg.cpp index 22ad597..a0878d8 100644 --- a/source/netmsg.cpp +++ b/source/netmsg.cpp @@ -426,6 +426,8 @@ void NetworkMsg::Execute (void *p) } else if (!g_bombPlanted && FStrEq (PTR_TO_STR (p), "#Bomb_Planted")) { + waypoints.SetBombPosition (); + g_bombPlanted = g_bombSayString = true; g_timeBombPlanted = GetWorldTime (); @@ -442,7 +444,6 @@ void NetworkMsg::Execute (void *p) bot->ChatterMessage (Chatter_WhereIsTheBomb); } } - waypoints.SetBombPosition (); } else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_BurstFire")) m_bot->m_weaponBurstMode = BM_ON; diff --git a/source/support.cpp b/source/support.cpp index e4dc891..5f56e23 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -747,6 +747,7 @@ void RoundInit (void) g_radioSelect[i] = 0; } waypoints.SetBombPosition (true); + waypoints.ClearVisitedGoals (); g_bombSayString = false; g_timeBombPlanted = 0.0f; @@ -1176,7 +1177,6 @@ void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...) printf ("%s", buffer); #endif - #if defined (PLATFORM_WIN32) _exit (1); #else @@ -1535,4 +1535,33 @@ int GetWeaponReturn (bool needString, const char *weaponAlias, int weaponIndex) return weaponTab[i].weaponIndex; } return -1; // no weapon was found return -1 -} \ No newline at end of file +} + +class ISkyBotIf +{ +public: + virtual int GetVersion () = 0; +}; + +class IEntity : public ISkyBotIf +{ +public: +}; + +class IPlayer : public IEntity +{ +public: +}; + +class IWeapon : public ISkyBotIf +{ +public: + virtual IPlayer *GetOwner () = 0; +}; + +class IGame : public ISkyBotIf +{ +public: + virtual bool IsBombPlanted () = 0; + virtual const Vector &GetBombPlantedOrigin () = 0; +}; diff --git a/source/waypoint.cpp b/source/waypoint.cpp index b7895db..1e13e1d 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -2182,25 +2182,13 @@ void Waypoint::SetGoalVisited (int index) if (index < 0 || index >= g_numWaypoints) return; - if (!IsGoalVisited (index) || !(m_paths[index]->flags & FLAG_GOAL)) - { -#if 0 - int bombPoint = FindNearest (GetBombPosition ()); - - Array markAsVisited; - FindInRadius (markAsVisited, 356.0f, GetPath (index)->origin); - - IterateArray (markAsVisited, i) - { - // skip still valid bomb point - if (markAsVisited[i] == bombPoint) - continue; - - m_visitedGoals.Push (markAsVisited[i]); - } -#endif + if (!IsGoalVisited (index) && (m_paths[index]->flags & FLAG_GOAL)) m_visitedGoals.Push (index); - } +} + +void Waypoint::ClearVisitedGoals (void) +{ + m_visitedGoals.RemoveAll (); } bool Waypoint::IsGoalVisited (int index)