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

Function PPic_GetPilot

Descent3/PilotPicsAPI.cpp:378–410  ·  view source on GitHub ↗

---------------------------------------------------------- PPic_GetPilot Purpose: Given a pilot id, it will return the pilot name of the pilot name. Returns false if it's an invalid pilot id. ----------------------------------------------------------

Source from the content-addressed store, hash-verified

376// the pilot name. Returns false if it's an invalid pilot id.
377// ----------------------------------------------------------
378bool PPic_GetPilot(uint16_t pilot_id, char *pilot_name, int buffersize) {
379 if (!PilotPic_init)
380 return false;
381
382 int oldoffset = cftell(PilotPic_database_index_handle);
383
384 int offset = PPic_GetOffsetByID(pilot_id);
385 if (offset == -1)
386 return false;
387
388 // jump to the offset
389 // ------------------
390 cfseek(PilotPic_database_index_handle, offset, SEEK_SET);
391 if (cfeof(PilotPic_database_index_handle)) {
392 cfseek(PilotPic_database_index_handle, oldoffset, SEEK_SET);
393 return false;
394 }
395
396 // read in the pilot name
397 // ----------------------
398 uint8_t name_size;
399 name_size = cf_ReadByte(PilotPic_database_index_handle);
400 if (cfeof(PilotPic_database_index_handle)) {
401 cfseek(PilotPic_database_index_handle, oldoffset, SEEK_SET);
402 return false;
403 }
404 int toread = std::min<int>(name_size, buffersize - 1);
405 cf_ReadBytes((uint8_t *)pilot_name, toread, PilotPic_database_index_handle);
406 pilot_name[toread] = '\0';
407
408 cfseek(PilotPic_database_index_handle, oldoffset, SEEK_SET);
409 return true;
410}
411
412// ----------------------------------------------------------
413// PPic_GetBitmapHandle

Callers

nothing calls this directly

Calls 6

cftellFunction · 0.85
PPic_GetOffsetByIDFunction · 0.85
cfseekFunction · 0.85
cfeofFunction · 0.85
cf_ReadByteFunction · 0.85
cf_ReadBytesFunction · 0.85

Tested by

no test coverage detected