returns true if waypoints succesfull loaded
| 81 | |
| 82 | // returns true if waypoints succesfull loaded |
| 83 | bool CWaypointClass::LoadWaypoints() |
| 84 | { |
| 85 | stream *bfp; |
| 86 | char szWPFileName[64]; |
| 87 | char filename[256]; |
| 88 | waypoint_header_s header; |
| 89 | short num, triggernr, yaw; |
| 90 | int i, j, flags; |
| 91 | vec from, to; |
| 92 | |
| 93 | strcpy(szWPFileName, m_szMapName); |
| 94 | strcat(szWPFileName, ".wpt"); |
| 95 | |
| 96 | BotManager.MakeBotFileName(szWPFileName, "waypoints", NULL, filename); |
| 97 | |
| 98 | bfp = openfile(filename, "rb"); |
| 99 | |
| 100 | BotManager.m_sCurrentTriggerNr = -1; |
| 101 | |
| 102 | // if file exists, read the waypoint structure from it |
| 103 | if (bfp != NULL) |
| 104 | { |
| 105 | bfp->read(&header, sizeof(header)); |
| 106 | |
| 107 | header.szFileType[sizeof(header.szFileType)-1] = 0; |
| 108 | if (strcmp(header.szFileType, "cube_bot") == 0) |
| 109 | { |
| 110 | header.szMapName[sizeof(header.szMapName)-1] = 0; |
| 111 | |
| 112 | if (strcmp(header.szMapName, m_szMapName) == 0) |
| 113 | { |
| 114 | Init(); // remove any existing waypoints |
| 115 | |
| 116 | // Check which waypoint file version this is, handle each of them different |
| 117 | if (header.iFileVersion == 1) |
| 118 | { |
| 119 | // First version, works with an big array and has a limit |
| 120 | |
| 121 | waypoint_version_1_s WPs[1024]; |
| 122 | int path_index; |
| 123 | |
| 124 | m_iWaypointCount = header.iWPCount; |
| 125 | for (i=0; i < header.iWPCount; i++) |
| 126 | { |
| 127 | bfp->read(&WPs[i], sizeof(WPs[0])); |
| 128 | WPs[i].ConnectedWPs.Reset(); // We get garbage when we read this from |
| 129 | // a file, so just clear it |
| 130 | |
| 131 | // Convert to new waypoint structure |
| 132 | node_s *pNode = new node_s(WPs[i].v_origin, WPs[i].iFlags, 0); |
| 133 | |
| 134 | short x, y; |
| 135 | GetNodeIndexes(pNode->v_origin, &x, &y); |
| 136 | |
| 137 | m_Waypoints[x][y].AddNode(pNode); |
| 138 | BotManager.AddWaypoint(pNode); |
| 139 | } |
| 140 |
no test coverage detected