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

Method LoadWaypoints

source/src/bot/bot_waypoint.cpp:83–279  ·  view source on GitHub ↗

returns true if waypoints succesfull loaded

Source from the content-addressed store, hash-verified

81
82// returns true if waypoints succesfull loaded
83bool 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

Callers 2

wploadFunction · 0.80
BeginMapMethod · 0.80

Calls 7

openfileFunction · 0.85
MakeBotFileNameMethod · 0.80
ResetMethod · 0.80
AddNodeMethod · 0.80
conoutfFunction · 0.50
readMethod · 0.45
AddWaypointMethod · 0.45

Tested by

no test coverage detected