fixed race-condition in bomb location detection

fixed visited goals are not cleared on round-start
This commit is contained in:
jeefo 2016-01-07 18:49:55 +03:00
commit aeb712c2b3
6 changed files with 45 additions and 25 deletions

View file

@ -1584,6 +1584,7 @@ public:
bool IsGoalVisited (int index); bool IsGoalVisited (int index);
void SetGoalVisited (int index); void SetGoalVisited (int index);
void ClearVisitedGoals (void);
inline const Vector &GetBombPosition (void) inline const Vector &GetBombPosition (void)
{ {

View file

@ -587,6 +587,7 @@ void Bot::FindItem (void)
break; break;
} }
} }
if (itemExists) if (itemExists)
return; return;
@ -787,7 +788,7 @@ void Bot::FindItem (void)
} }
else if (pickupType == PICKUP_PLANTED_C4 && !OutOfBombTimer ()) else if (pickupType == PICKUP_PLANTED_C4 && !OutOfBombTimer ())
{ {
if (m_states & (STATE_SEEING_ENEMY | STATE_SUSPECT_ENEMY)) if (IsValidPlayer (m_enemy))
{ {
allowPickup = false; allowPickup = false;
return; 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. // 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 return Vector::GetZero (); // reliability check
if (m_difficulty >= 3) if (m_difficulty >= 3)

View file

@ -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) 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? // bot within 'hearable' bomb tick noises?
if (!bombOrigin.IsZero ()) if (!bombOrigin.IsZero ())
@ -2039,7 +2039,7 @@ int Bot::ChooseBombWaypoint (void)
bombOrigin = pev->origin; bombOrigin = pev->origin;
int goal = 0, count = 0; int goal = 0, count = 0;
float lastDistance = 99999.0f; float lastDistance = 999999.0f;
// find nearest goal waypoint either to bomb (if "heard" or player) // find nearest goal waypoint either to bomb (if "heard" or player)
FOR_EACH_AE (goals, i) FOR_EACH_AE (goals, i)

View file

@ -426,6 +426,8 @@ void NetworkMsg::Execute (void *p)
} }
else if (!g_bombPlanted && FStrEq (PTR_TO_STR (p), "#Bomb_Planted")) else if (!g_bombPlanted && FStrEq (PTR_TO_STR (p), "#Bomb_Planted"))
{ {
waypoints.SetBombPosition ();
g_bombPlanted = g_bombSayString = true; g_bombPlanted = g_bombSayString = true;
g_timeBombPlanted = GetWorldTime (); g_timeBombPlanted = GetWorldTime ();
@ -442,7 +444,6 @@ void NetworkMsg::Execute (void *p)
bot->ChatterMessage (Chatter_WhereIsTheBomb); bot->ChatterMessage (Chatter_WhereIsTheBomb);
} }
} }
waypoints.SetBombPosition ();
} }
else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_BurstFire")) else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_BurstFire"))
m_bot->m_weaponBurstMode = BM_ON; m_bot->m_weaponBurstMode = BM_ON;

View file

@ -747,6 +747,7 @@ void RoundInit (void)
g_radioSelect[i] = 0; g_radioSelect[i] = 0;
} }
waypoints.SetBombPosition (true); waypoints.SetBombPosition (true);
waypoints.ClearVisitedGoals ();
g_bombSayString = false; g_bombSayString = false;
g_timeBombPlanted = 0.0f; g_timeBombPlanted = 0.0f;
@ -1176,7 +1177,6 @@ void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...)
printf ("%s", buffer); printf ("%s", buffer);
#endif #endif
#if defined (PLATFORM_WIN32) #if defined (PLATFORM_WIN32)
_exit (1); _exit (1);
#else #else
@ -1535,4 +1535,33 @@ int GetWeaponReturn (bool needString, const char *weaponAlias, int weaponIndex)
return weaponTab[i].weaponIndex; return weaponTab[i].weaponIndex;
} }
return -1; // no weapon was found return -1 return -1; // no weapon was found return -1
} }
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;
};

View file

@ -2182,25 +2182,13 @@ void Waypoint::SetGoalVisited (int index)
if (index < 0 || index >= g_numWaypoints) if (index < 0 || index >= g_numWaypoints)
return; return;
if (!IsGoalVisited (index) || !(m_paths[index]->flags & FLAG_GOAL)) if (!IsGoalVisited (index) && (m_paths[index]->flags & FLAG_GOAL))
{
#if 0
int bombPoint = FindNearest (GetBombPosition ());
Array <int> 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
m_visitedGoals.Push (index); m_visitedGoals.Push (index);
} }
void Waypoint::ClearVisitedGoals (void)
{
m_visitedGoals.RemoveAll ();
} }
bool Waypoint::IsGoalVisited (int index) bool Waypoint::IsGoalVisited (int index)