diff --git a/include/core.h b/include/core.h
index ee2e41f..7d89e39 100644
--- a/include/core.h
+++ b/include/core.h
@@ -472,6 +472,14 @@ enum PathFlag
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
enum PathConnection
{
@@ -779,7 +787,7 @@ private:
PathNode *m_navNodeStart; // pointer to start of path finding nodes
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
int m_currentWaypointIndex; // current waypoint index
@@ -1045,7 +1053,7 @@ private:
int GetAimingWaypoint (const Vector &to);
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 PeriodicThink (void);
diff --git a/project/yapb.vcxproj b/project/yapb.vcxproj
index 1b089e6..5d6b43f 100644
--- a/project/yapb.vcxproj
+++ b/project/yapb.vcxproj
@@ -49,6 +49,7 @@
{C232645A-3B99-48F4-A1F3-F20CF0A9568B}
yapb
8.1
+ 8.1
@@ -80,7 +81,7 @@
true
true
false
- AllRules.ruleset
+ NativeRecommendedRules.ruleset
.\release\
diff --git a/source/basecode.cpp b/source/basecode.cpp
index 0dd2fe9..d0bc8c5 100644
--- a/source/basecode.cpp
+++ b/source/basecode.cpp
@@ -1118,7 +1118,7 @@ void Bot::CheckMessageQueue (void)
{
m_isVIP = true;
m_buyState = BUYSTATE_FINISHED;
- m_pathType = 0;
+ m_pathType = SEARCH_PATH_FASTEST;
}
// 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
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
{
@@ -3391,7 +3391,7 @@ void Bot::RunTask_SeekCover (void)
TaskComplete ();
m_prevGoalIndex = -1;
- m_pathType = 0;
+ m_pathType = SEARCH_PATH_FASTEST;
// start hide task
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;
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 ();
// tell teammates to move over here...
- if (GetNearbyFriendsNearPosition (pev->origin, 1200) != 0)
+ if (GetNearbyFriendsNearPosition (pev->origin, 1200.0f) != 0)
RadioMessage (Radio_NeedBackup);
DeleteSearchNodes ();
@@ -5751,7 +5751,7 @@ void Bot::MoveToVector (const Vector &to)
if (to.IsZero ())
return;
- FindPath (m_currentWaypointIndex, waypoints.FindNearest (to), 0);
+ FindPath (m_currentWaypointIndex, waypoints.FindNearest (to), SEARCH_PATH_FASTEST);
}
byte Bot::ThrottledMsec (void)
diff --git a/source/manager.cpp b/source/manager.cpp
index 9d48041..1679461 100644
--- a/source/manager.cpp
+++ b/source/manager.cpp
@@ -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 ());
return 2;
}
-
int index = IndexOfEntity (bot) - 1;
InternalAssert (index >= 0 && index <= 32); // check index
@@ -1079,15 +1078,15 @@ void Bot::NewRound (void)
switch (m_personality)
{
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;
case PERSONALITY_RUSHER:
- m_pathType = 0;
+ m_pathType = SEARCH_PATH_FASTEST;
break;
case PERSONALITY_CAREFUL:
- m_pathType = 2;
+ m_pathType = SEARCH_PATH_SAFEST;
break;
}
diff --git a/source/navigate.cpp b/source/navigate.cpp
index 679f38d..b2b3da0 100644
--- a/source/navigate.cpp
+++ b/source/navigate.cpp
@@ -1610,7 +1610,7 @@ float hfunctionNumberNodes (int index, int startIndex, int goalIndex)
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
@@ -1656,7 +1656,7 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
switch (pathType)
{
- case 0:
+ case SEARCH_PATH_FASTEST:
if ((g_mapType & MAP_CS) && HasHostage ())
{
gcalc = gfunctionPathDistWithHostage;
@@ -1669,7 +1669,7 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
}
break;
- case 1:
+ case SEARCH_PATH_SAFEST_FASTER:
if (m_team == TERRORIST)
{
gcalc = gfunctionKillsDistT;
@@ -1687,7 +1687,7 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
}
break;
- case 2:
+ case SEARCH_PATH_SAFEST:
default:
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
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?
if (currentIndex == destIndex)
{
diff --git a/source/support.cpp b/source/support.cpp
index dc5de6a..988dde0 100644
--- a/source/support.cpp
+++ b/source/support.cpp
@@ -1220,7 +1220,7 @@ char *Localizer::TranslateInput (const char *input)
{
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)
strncat (string, ptr, 1024 - 1 - strlen (string));
diff --git a/source/waypoint.cpp b/source/waypoint.cpp
index 00f075c..f930aa2 100644
--- a/source/waypoint.cpp
+++ b/source/waypoint.cpp
@@ -448,7 +448,7 @@ void Waypoint::Delete (void)
int index = FindNearest (g_hostEntity->v.origin, 50.0f);
- if (index == -1)
+ if (index < 0)
return;
Path *path = NULL;
@@ -1271,7 +1271,7 @@ bool Waypoint::Reachable (Bot *bot, int index)
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)
return false;
@@ -2570,7 +2570,7 @@ WaypointDownloadError WaypointDownloader::DoDownload (void)
finished = true;
// 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);
return WDE_NOTFOUND_ERROR;