MCPcopy Create free account
hub / github.com/assaultcube/AC / GetNearestTriggerWaypoint

Method GetNearestTriggerWaypoint

source/src/bot/bot_waypoint.cpp:1100–1151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1098}
1099
1100node_s *CWaypointClass::GetNearestTriggerWaypoint(vec v_src, float flRange)
1101{
1102 TLinkedList<node_s *>::node_s *pNode;
1103 node_s *pNearest = NULL;
1104 short i, j, MinI, MaxI, MinJ, MaxJ, Offset = (short)ceil(flRange / MAX_MAP_GRIDS);
1105 float flNearestDist = 9999.99f, flDist;
1106
1107 GetNodeIndexes(v_src, &i, &j);
1108 MinI = i - Offset;
1109 MaxI = i + Offset;
1110 MinJ = j - Offset;
1111 MaxJ = j + Offset;
1112
1113 if (MinI < 0)
1114 MinI = 0;
1115 if (MaxI > MAX_MAP_GRIDS - 1)
1116 MaxI = MAX_MAP_GRIDS - 1;
1117 if (MinJ < 0)
1118 MinJ = 0;
1119 if (MaxJ > MAX_MAP_GRIDS - 1)
1120 MaxJ = MAX_MAP_GRIDS - 1;
1121
1122 for (int x=MinI;x<=MaxI;x++)
1123 {
1124 for(int y=MinJ;y<=MaxJ;y++)
1125 {
1126 pNode = m_Waypoints[x][y].GetFirst();
1127
1128 while(pNode)
1129 {
1130 if ((pNode->Entry->iFlags & W_FL_FLOOD) || !(pNode->Entry->iFlags & W_FL_TRIGGER))
1131 {
1132 pNode = pNode->next;
1133 continue;
1134 }
1135
1136 flDist = GetDistance(v_src, pNode->Entry->v_origin);
1137 if ((flDist < flNearestDist) && (flDist <= flRange))
1138 {
1139 if (IsVisible(v_src, pNode->Entry->v_origin, NULL))
1140 {
1141 pNearest = pNode->Entry;
1142 flNearestDist = flDist;
1143 }
1144 }
1145
1146 pNode = pNode->next;
1147 }
1148 }
1149 }
1150 return pNearest;
1151}
1152
1153node_s *CWaypointClass::GetWaypointFromVec(const vec &v_src)
1154{

Callers 1

loopvFunction · 0.80

Calls 4

GetDistanceFunction · 0.85
IsVisibleFunction · 0.85
GetNodeIndexesMethod · 0.80
GetFirstMethod · 0.45

Tested by

no test coverage detected