MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / PPic_QueryPilot

Function PPic_QueryPilot

Descent3/PilotPicsAPI.cpp:213–259  ·  view source on GitHub ↗

--------------------------------------------------------- PPic_QueryPilot Purpose: Given a pilot callsign it will search the database and return the number of pilots that match the name ---------------------------------------------------------

Source from the content-addressed store, hash-verified

211// and return the number of pilots that match the name
212// ---------------------------------------------------------
213uint16_t PPic_QueryPilot(char *pilot_name) {
214 if (!PilotPic_init)
215 return 0;
216
217 int letter_offset = PPic_JumpToPilot(pilot_name);
218 if (letter_offset == -1)
219 return 0;
220
221 int count = 0;
222 bool done = false;
223 char name_buffer[PILOT_STRING_SIZE];
224 CFILE *file = PilotPic_database_index_handle;
225
226 // now read through the pilots until we don't get a match anymore
227 while (!done) {
228 // first read in the pilot name
229 uint8_t name_size;
230 name_size = cf_ReadByte(file);
231
232 if (cfeof(file)) {
233 done = true;
234 continue;
235 }
236 cf_ReadBytes((uint8_t *)name_buffer, name_size, file);
237 name_buffer[name_size] = '\0';
238
239 // next read in pilot_id
240 uint16_t pilot_id;
241 pilot_id = (uint16_t)cf_ReadShort(file);
242
243 // next read past the bitmap name
244 uint8_t bmp_size;
245 bmp_size = cf_ReadByte(file);
246 cfseek(file, bmp_size, SEEK_CUR);
247
248 if (stricmp(name_buffer, pilot_name)) {
249 // we're done
250 done = true;
251 } else
252 count++;
253
254 if (cfeof(file))
255 done = true;
256 }
257
258 return count;
259}
260
261// ---------------------------------------------------------
262// PPic_FindFirst

Callers 2

PilotSelectFunction · 0.85
ShowPilotPicDialogFunction · 0.85

Calls 6

PPic_JumpToPilotFunction · 0.85
cf_ReadByteFunction · 0.85
cfeofFunction · 0.85
cf_ReadBytesFunction · 0.85
cf_ReadShortFunction · 0.85
cfseekFunction · 0.85

Tested by

no test coverage detected