fixed infinite loop on bad waypoints. now bots will crash down, instead of eating all the ram.

more magic-numbers replacements.
This commit is contained in:
jeefo 2016-02-29 23:50:16 +03:00
commit cd48b98180
7 changed files with 35 additions and 21 deletions

View file

@ -472,6 +472,14 @@ enum PathFlag
PATHFLAG_JUMP = (1 << 0), // must jump for this connection PATHFLAG_JUMP = (1 << 0), // must jump for this connection
}; };
// enum pathfind search type
enum SearchPathType
{
SEARCH_PATH_FASTEST = 0,
SEARCH_PATH_SAFEST_FASTER,
SEARCH_PATH_SAFEST
};
// defines waypoint connection types // defines waypoint connection types
enum PathConnection enum PathConnection
{ {
@ -779,7 +787,7 @@ private:
PathNode *m_navNodeStart; // pointer to start of path finding nodes PathNode *m_navNodeStart; // pointer to start of path finding nodes
Path *m_currentPath; // pointer to the current path waypoint Path *m_currentPath; // pointer to the current path waypoint
unsigned char m_pathType; // which pathfinder to use SearchPathType m_pathType; // which pathfinder to use
unsigned char m_visibility; // visibility flags unsigned char m_visibility; // visibility flags
int m_currentWaypointIndex; // current waypoint index int m_currentWaypointIndex; // current waypoint index
@ -1045,7 +1053,7 @@ private:
int GetAimingWaypoint (const Vector &to); int GetAimingWaypoint (const Vector &to);
void FindShortestPath (int srcIndex, int destIndex); void FindShortestPath (int srcIndex, int destIndex);
void FindPath (int srcIndex, int destIndex, unsigned char pathType = 0); void FindPath (int srcIndex, int destIndex, SearchPathType pathType = SEARCH_PATH_FASTEST);
void DebugMsg (const char *format, ...); void DebugMsg (const char *format, ...);
void PeriodicThink (void); void PeriodicThink (void);

View file

@ -49,6 +49,7 @@
<ProjectGuid>{C232645A-3B99-48F4-A1F3-F20CF0A9568B}</ProjectGuid> <ProjectGuid>{C232645A-3B99-48F4-A1F3-F20CF0A9568B}</ProjectGuid>
<RootNamespace>yapb</RootNamespace> <RootNamespace>yapb</RootNamespace>
<TargetPlatformVersion>8.1</TargetPlatformVersion> <TargetPlatformVersion>8.1</TargetPlatformVersion>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@ -80,7 +81,7 @@
<IgnoreImportLibrary>true</IgnoreImportLibrary> <IgnoreImportLibrary>true</IgnoreImportLibrary>
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<EmbedManifest>false</EmbedManifest> <EmbedManifest>false</EmbedManifest>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>NativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>.\release\</OutDir> <OutDir>.\release\</OutDir>

View file

@ -1118,7 +1118,7 @@ void Bot::CheckMessageQueue (void)
{ {
m_isVIP = true; m_isVIP = true;
m_buyState = BUYSTATE_FINISHED; m_buyState = BUYSTATE_FINISHED;
m_pathType = 0; m_pathType = SEARCH_PATH_FASTEST;
} }
// prevent terrorists from buying on es maps // prevent terrorists from buying on es maps
@ -3246,7 +3246,7 @@ void Bot::RunTask_Normal (void)
// do pathfinding if it's not the current waypoint // do pathfinding if it's not the current waypoint
if (destIndex != m_currentWaypointIndex) if (destIndex != m_currentWaypointIndex)
FindPath (m_currentWaypointIndex, destIndex, ((g_bombPlanted && m_team == CT) || yb_debug_goal.GetInt () != -1) ? 0 : m_pathType); FindPath (m_currentWaypointIndex, destIndex, ((g_bombPlanted && m_team == CT) || yb_debug_goal.GetInt () != -1) ? SEARCH_PATH_FASTEST : m_pathType);
} }
else else
{ {
@ -3391,7 +3391,7 @@ void Bot::RunTask_SeekCover (void)
TaskComplete (); TaskComplete ();
m_prevGoalIndex = -1; m_prevGoalIndex = -1;
m_pathType = 0; m_pathType = SEARCH_PATH_FASTEST;
// start hide task // start hide task
PushTask (TASK_HIDE, TASKPRI_HIDE, -1, GetWorldTime () + Random.Float (5.0f, 15.0f), false); PushTask (TASK_HIDE, TASKPRI_HIDE, -1, GetWorldTime () + Random.Float (5.0f, 15.0f), false);
@ -3459,7 +3459,7 @@ void Bot::RunTask_SeekCover (void)
GetTask ()->data = destIndex; GetTask ()->data = destIndex;
if (destIndex != m_currentWaypointIndex) if (destIndex != m_currentWaypointIndex)
FindPath (m_currentWaypointIndex, destIndex, 0); FindPath (m_currentWaypointIndex, destIndex, SEARCH_PATH_FASTEST);
} }
} }
@ -3786,7 +3786,7 @@ void Bot::RunTask_PlantBomb (void)
TaskComplete (); TaskComplete ();
// tell teammates to move over here... // tell teammates to move over here...
if (GetNearbyFriendsNearPosition (pev->origin, 1200) != 0) if (GetNearbyFriendsNearPosition (pev->origin, 1200.0f) != 0)
RadioMessage (Radio_NeedBackup); RadioMessage (Radio_NeedBackup);
DeleteSearchNodes (); DeleteSearchNodes ();
@ -5751,7 +5751,7 @@ void Bot::MoveToVector (const Vector &to)
if (to.IsZero ()) if (to.IsZero ())
return; return;
FindPath (m_currentWaypointIndex, waypoints.FindNearest (to), 0); FindPath (m_currentWaypointIndex, waypoints.FindNearest (to), SEARCH_PATH_FASTEST);
} }
byte Bot::ThrottledMsec (void) byte Bot::ThrottledMsec (void)

View file

@ -199,7 +199,6 @@ int BotManager::CreateBot (const String &name, int difficulty, int personality,
CenterPrint ("Maximum players reached (%d/%d). Unable to create Bot.", GetMaxClients (), GetMaxClients ()); CenterPrint ("Maximum players reached (%d/%d). Unable to create Bot.", GetMaxClients (), GetMaxClients ());
return 2; return 2;
} }
int index = IndexOfEntity (bot) - 1; int index = IndexOfEntity (bot) - 1;
InternalAssert (index >= 0 && index <= 32); // check index InternalAssert (index >= 0 && index <= 32); // check index
@ -1079,15 +1078,15 @@ void Bot::NewRound (void)
switch (m_personality) switch (m_personality)
{ {
case PERSONALITY_NORMAL: case PERSONALITY_NORMAL:
m_pathType = Random.Long (0, 100) > 50 ? 1 : 2; m_pathType = Random.Long (0, 100) > 50 ? SEARCH_PATH_SAFEST_FASTER : SEARCH_PATH_SAFEST;
break; break;
case PERSONALITY_RUSHER: case PERSONALITY_RUSHER:
m_pathType = 0; m_pathType = SEARCH_PATH_FASTEST;
break; break;
case PERSONALITY_CAREFUL: case PERSONALITY_CAREFUL:
m_pathType = 2; m_pathType = SEARCH_PATH_SAFEST;
break; break;
} }

View file

@ -1610,7 +1610,7 @@ float hfunctionNumberNodes (int index, int startIndex, int goalIndex)
return hfunctionSquareDist (index, startIndex, goalIndex) / 128.0f * g_highestKills; return hfunctionSquareDist (index, startIndex, goalIndex) / 128.0f * g_highestKills;
} }
void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType) void Bot::FindPath(int srcIndex, int destIndex, SearchPathType pathType /*= SEARCH_PATH_FASTEST */)
{ {
// this function finds a path from srcIndex to destIndex // this function finds a path from srcIndex to destIndex
@ -1656,7 +1656,7 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
switch (pathType) switch (pathType)
{ {
case 0: case SEARCH_PATH_FASTEST:
if ((g_mapType & MAP_CS) && HasHostage ()) if ((g_mapType & MAP_CS) && HasHostage ())
{ {
gcalc = gfunctionPathDistWithHostage; gcalc = gfunctionPathDistWithHostage;
@ -1669,7 +1669,7 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
} }
break; break;
case 1: case SEARCH_PATH_SAFEST_FASTER:
if (m_team == TERRORIST) if (m_team == TERRORIST)
{ {
gcalc = gfunctionKillsDistT; gcalc = gfunctionKillsDistT;
@ -1687,7 +1687,7 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
} }
break; break;
case 2: case SEARCH_PATH_SAFEST:
default: default:
if (m_team == TERRORIST) if (m_team == TERRORIST)
{ {
@ -1719,6 +1719,12 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
// remove the first node from the open list // remove the first node from the open list
int currentIndex = openList.Pop (); int currentIndex = openList.Pop ();
if (currentIndex < 0 || currentIndex > g_numWaypoints)
{
AddLogEntry (false, LL_FATAL, "openList.Pop () = %d. It's not possible to continue execution. Please obtain better waypoint.");
return;
}
// is the current node the goal node? // is the current node the goal node?
if (currentIndex == destIndex) if (currentIndex == destIndex)
{ {

View file

@ -1220,7 +1220,7 @@ char *Localizer::TranslateInput (const char *input)
{ {
if (strcmp (string, m_langTab[i].original) == 0) if (strcmp (string, m_langTab[i].original) == 0)
{ {
strncpy (string, m_langTab[i].translated, 1023); strncpy (string, m_langTab[i].translated, SIZEOF_CHAR (string));
if (ptr != input) if (ptr != input)
strncat (string, ptr, 1024 - 1 - strlen (string)); strncat (string, ptr, 1024 - 1 - strlen (string));

View file

@ -448,7 +448,7 @@ void Waypoint::Delete (void)
int index = FindNearest (g_hostEntity->v.origin, 50.0f); int index = FindNearest (g_hostEntity->v.origin, 50.0f);
if (index == -1) if (index < 0)
return; return;
Path *path = NULL; Path *path = NULL;
@ -1271,7 +1271,7 @@ bool Waypoint::Reachable (Bot *bot, int index)
float distance = (dest - src).GetLength (); float distance = (dest - src).GetLength ();
// check is destination is close to us enoguh // check is destination is close to us enough
if (distance >= 150.0f) if (distance >= 150.0f)
return false; return false;
@ -2570,7 +2570,7 @@ WaypointDownloadError WaypointDownloader::DoDownload (void)
finished = true; finished = true;
// ugly, but whatever // ugly, but whatever
if (buffer[recvPosition - 2] == '4' && buffer[recvPosition - 1] == '0' && buffer[recvPosition] == '4') if (recvPosition > 2 && buffer[recvPosition - 2] == '4' && buffer[recvPosition - 1] == '0' && buffer[recvPosition] == '4')
{ {
FreeSocket (socketHandle); FreeSocket (socketHandle);
return WDE_NOTFOUND_ERROR; return WDE_NOTFOUND_ERROR;