PHP Code:
bool WaypointNodesValid()
{
int iTPoints = 0;
int iCTPoints = 0;
int iGoalPoints = 0;
int iRescuePoints = 0;
int iConnections;
int i, j;
for (i = 0; i < g_iNumWaypoints; i++)
{
iConnections = 0;
for (int n = 0; n < MAX_PATH_INDEX; n++)
{
if (paths[i]->index[n] != -1)
{
if (paths[i]->index[n] > g_iNumWaypoints)
{
SERVER_PRINT(UTIL_VarArgs("Node %d connected with invalid Waypoint Nr. %d!\n", i, paths[i]->index[n]));
return FALSE;
}
iConnections++;
break;
}
}
if (iConnections == 0)
{
if (!WaypointIsConnected(i))
{
SERVER_PRINT(UTIL_VarArgs("Node %d isn't connected with any other Waypoint!\n", i));
return FALSE;
}
}
if (paths[i]->iPathNumber != i)
{
SERVER_PRINT(UTIL_VarArgs("Node %d pathnumber differs from index!\n", i));
return FALSE;
}
if (paths[i]->flags & W_FL_CAMP)
{
if (paths[i]->fcampendx == 0.0 && paths[i]->fcampendy == 0.0)
{
SERVER_PRINT(UTIL_VarArgs("Node %d Camp-Endposition not set!\n", i));
return FALSE;
}
}
else if (paths[i]->flags & W_FL_TERRORIST)
iTPoints++;
else if (paths[i]->flags & W_FL_COUNTER)
iCTPoints++;
else if (paths[i]->flags & W_FL_GOAL)
iGoalPoints++;
else if (paths[i]->flags & W_FL_RESCUE)
iRescuePoints++;
int x = 0;
while (x < MAX_PATH_INDEX)
{
if (paths[i]->index[x] != -1)
{
if (paths[i]->index[x] >= g_iNumWaypoints || paths[i]->index[x] < -1)
{
SERVER_PRINT(UTIL_VarArgs("Node %d - Pathindex %d out of Range!\n", i, x));
g_engfuncs.pfnSetOrigin(pHostEdict, paths[i]->origin);
g_bWaypointOn = TRUE;
bEditNoclip = TRUE;
return FALSE;
}
else if (paths[i]->index[x] == i)
{
SERVER_PRINT(UTIL_VarArgs("Node %d - Pathindex %d points to itself!\n", i, x));
g_engfuncs.pfnSetOrigin(pHostEdict, paths[i]->origin);
g_bWaypointOn = TRUE;
bEditNoclip = TRUE;
return FALSE;
}
}
x++;
}
}
if (g_iMapType & MAP_CS)
{
if (iRescuePoints == 0)
{
SERVER_PRINT("You didn't set a Rescue Point!\n");
return FALSE;
}
}
if (iTPoints == 0)
{
SERVER_PRINT("You didn't set any Terrorist Important Point!\n");
return FALSE;
}
else if (iCTPoints == 0)
{
SERVER_PRINT("You didn't set any CT Important Point!\n");
return FALSE;
}
else if (iGoalPoints == 0)
{
SERVER_PRINT("You didn't set any Goal Point!\n");
return FALSE;
}
bool rgbVisited[MAX_WAYPOINTS];
PATHNODE *stack = NULL;
// first check incoming connectivity
// initialize the "visited" table
for (i = 0; i < g_iNumWaypoints; i++)
rgbVisited[i] = FALSE;
// check from Waypoint nr. 0
stack = (PATHNODE *)malloc(sizeof(PATHNODE));
stack->NextNode = NULL;
stack->iIndex = 0;
while (stack)
{
// pop a node from the stack
PATHNODE *current = stack;
stack = stack->NextNode;
rgbVisited[current->iIndex] = TRUE;
for (j = 0; j < MAX_PATH_INDEX; j++)
{
int iIndex = paths[current->iIndex]->index[j];
if (rgbVisited[iIndex])
continue; // skip this waypoint as it's already visited
if (iIndex >= 0 && iIndex < g_iNumWaypoints)
{
PATHNODE *newnode = (PATHNODE *)malloc(sizeof(PATHNODE));
newnode->NextNode = stack;
newnode->iIndex = iIndex;
stack = newnode;
}
}
free(current);
}
for (i = 0; i < g_iNumWaypoints; i++)
{
if (!rgbVisited[i])
{
SERVER_PRINT(UTIL_VarArgs("Path broken from Waypoint Nr. 0 to Waypoint Nr. %d!\n", i));
g_engfuncs.pfnSetOrigin(pHostEdict, paths[i]->origin);
g_bWaypointOn = TRUE;
bEditNoclip = TRUE;
return FALSE;
}
}
// then check outgoing connectivity
std::vector<int> in_paths[MAX_WAYPOINTS]; // store incoming paths for speedup
for (i = 0; i < g_iNumWaypoints; i++)
for (j = 0; j < MAX_PATH_INDEX; j++)
if (paths[i]->index[j] >= 0 && paths[i]->index[j] < g_iNumWaypoints)
in_paths[paths[i]->index[j]].push_back(i);
// initialize the "visited" table
for (i = 0; i < g_iNumWaypoints; i++)
rgbVisited[i] = FALSE;
// check from Waypoint nr. 0
stack = (PATHNODE *)malloc(sizeof(PATHNODE));
stack->NextNode = NULL;
stack->iIndex = 0;
while (stack)
{
// pop a node from the stack
PATHNODE *current = stack;
stack = stack->NextNode;
rgbVisited[current->iIndex] = TRUE;
for (j = 0; j < (int)in_paths[current->iIndex].size(); j++)
{
if (rgbVisited[in_paths[current->iIndex][j]])
continue; // skip this waypoint as it's already visited
PATHNODE *newnode = (PATHNODE *)malloc(sizeof(PATHNODE));
newnode->NextNode = stack;
newnode->iIndex = in_paths[current->iIndex][j];
stack = newnode;
}
free(current);
}
for (i = 0; i < g_iNumWaypoints; i++)
{
if (!rgbVisited[i])
{
SERVER_PRINT(UTIL_VarArgs("Path broken from Waypoint Nr. %d to Waypoint Nr. 0!\n", i));
g_engfuncs.pfnSetOrigin(pHostEdict, paths[i]->origin);
g_bWaypointOn = TRUE;
bEditNoclip = TRUE;
return FALSE;
}
}
return TRUE;
}