| 1051 | } |
| 1052 | |
| 1053 | node_s *CWaypointClass::GetNearestWaypoint(vec v_src, float flRange) |
| 1054 | { |
| 1055 | TLinkedList<node_s *>::node_s *pNode; |
| 1056 | node_s *pNearest = NULL; |
| 1057 | short i, j, MinI, MaxI, MinJ, MaxJ, Offset = (short)ceil(flRange / MAX_MAP_GRIDS); |
| 1058 | float flNearestDist = 9999.99f, flDist; |
| 1059 | |
| 1060 | GetNodeIndexes(v_src, &i, &j); |
| 1061 | MinI = i - Offset; |
| 1062 | MaxI = i + Offset; |
| 1063 | MinJ = j - Offset; |
| 1064 | MaxJ = j + Offset; |
| 1065 | |
| 1066 | if (MinI < 0) |
| 1067 | MinI = 0; |
| 1068 | if (MaxI > MAX_MAP_GRIDS - 1) |
| 1069 | MaxI = MAX_MAP_GRIDS - 1; |
| 1070 | if (MinJ < 0) |
| 1071 | MinJ = 0; |
| 1072 | if (MaxJ > MAX_MAP_GRIDS - 1) |
| 1073 | MaxJ = MAX_MAP_GRIDS - 1; |
| 1074 | |
| 1075 | for (int x=MinI;x<=MaxI;x++) |
| 1076 | { |
| 1077 | for(int y=MinJ;y<=MaxJ;y++) |
| 1078 | { |
| 1079 | pNode = m_Waypoints[x][y].GetFirst(); |
| 1080 | |
| 1081 | while(pNode) |
| 1082 | { |
| 1083 | flDist = GetDistance(v_src, pNode->Entry->v_origin); |
| 1084 | if ((flDist < flNearestDist) && (flDist <= flRange)) |
| 1085 | { |
| 1086 | if (IsVisible(v_src, pNode->Entry->v_origin, NULL)) |
| 1087 | { |
| 1088 | pNearest = pNode->Entry; |
| 1089 | flNearestDist = flDist; |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | pNode = pNode->next; |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | return pNearest; |
| 1098 | } |
| 1099 | |
| 1100 | node_s *CWaypointClass::GetNearestTriggerWaypoint(vec v_src, float flRange) |
| 1101 | { |
no test coverage detected