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

Function PPic_FindFirst

Descent3/PilotPicsAPI.cpp:269–310  ·  view source on GitHub ↗

--------------------------------------------------------- PPic_FindFirst Purpose: Given a pilot callsign it will return the first pilot that matches the search. Returns true on success, false if it couldn't find any pilots matching. It returns the pilot id. ----------------------------------------------------------

Source from the content-addressed store, hash-verified

267// the pilot id.
268// ----------------------------------------------------------
269bool PPic_FindFirst(char *pilot_name, uint16_t *pilot_id) {
270 if (!PilotPic_init)
271 return false;
272
273 *pilot_id = 65535;
274
275 int letter_offset = PPic_JumpToPilot(pilot_name);
276 if (letter_offset == -1)
277 return false;
278
279 strcpy(PilotPic_find_name, pilot_name);
280
281 char name_buffer[PILOT_STRING_SIZE];
282 CFILE *file = PilotPic_database_index_handle;
283
284 // first read in the pilot name
285 uint8_t name_size;
286 name_size = cf_ReadByte(file);
287 if (cfeof(file)) {
288 return false;
289 }
290 cf_ReadBytes((uint8_t *)name_buffer, name_size, file);
291 name_buffer[name_size] = '\0';
292
293 // next read in pilot_id
294 uint16_t pid;
295 pid = (uint16_t)cf_ReadShort(file);
296
297 // next read past the bitmap name
298 uint8_t bmp_size;
299 bmp_size = cf_ReadByte(file);
300 cfseek(file, bmp_size, SEEK_CUR);
301
302 if (stricmp(name_buffer, pilot_name)) {
303 return false; // weird
304 }
305
306 *pilot_id = pid;
307 PilotPic_find_offset = cftell(file);
308
309 return true;
310}
311
312// ----------------------------------------------------------
313// PPic_FindNext

Callers 1

ShowPilotPicDialogFunction · 0.85

Calls 7

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

Tested by

no test coverage detected