///////////////////////////////////////////////////////// Brings up the Create A New Pilot Dialog
| 1258 | ////////////////////////////////////////////////////////////// |
| 1259 | // Brings up the Create A New Pilot Dialog |
| 1260 | bool PilotCreate(pilot *Pilot, bool forceselection) { |
| 1261 | bool done = false; |
| 1262 | bool ret; |
| 1263 | bool to_ret = false; |
| 1264 | char pname[PILOT_STRING_SIZE]; |
| 1265 | |
| 1266 | while (!done) { |
| 1267 | pname[0] = 0; |
| 1268 | ret = DoEditDialog(TXT_PLTENTERNAME1, pname, PILOT_STRING_SIZE - 1); |
| 1269 | |
| 1270 | if (!ret) { |
| 1271 | if (!forceselection) { |
| 1272 | done = true; |
| 1273 | to_ret = false; |
| 1274 | } |
| 1275 | } else { |
| 1276 | mprintf(0, "Creating Pilot!"); |
| 1277 | |
| 1278 | // call this to initialize pilot data for player. |
| 1279 | PilotInitData(Pilot); |
| 1280 | char pfilename[_MAX_FNAME]; |
| 1281 | |
| 1282 | // strip whitespace |
| 1283 | char *ptr = pname + strlen(pname) - 1; |
| 1284 | while ((ptr > pname) && (*ptr == ' ' || *ptr == '\t')) { |
| 1285 | *ptr = '\0'; |
| 1286 | ptr--; |
| 1287 | } |
| 1288 | |
| 1289 | ptr = pname; |
| 1290 | while (*ptr && (*ptr == ' ' || *ptr == '\t')) |
| 1291 | ptr++; |
| 1292 | |
| 1293 | if (strlen(ptr) == 0) { |
| 1294 | DoMessageBox(TXT_PLTERROR, TXT_PLTERRORNAME, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); |
| 1295 | goto retry; |
| 1296 | } |
| 1297 | |
| 1298 | Pilot->set_name(ptr); |
| 1299 | strcpy(pfilename, ptr); |
| 1300 | PltMakeFNValid(pfilename); |
| 1301 | strcat(pfilename, PLTEXTENSION); |
| 1302 | |
| 1303 | Pilot->set_filename(pfilename); |
| 1304 | |
| 1305 | RestoreDefaultControls(); |
| 1306 | |
| 1307 | for (int id = 0; id < NUM_CONTROLLER_FUNCTIONS; id++) { |
| 1308 | ct_type type[2]; |
| 1309 | ct_config_data value; |
| 1310 | uint8_t flags[2]; |
| 1311 | Controller->get_controller_function(Controller_needs[id].id, type, &value, flags); |
| 1312 | Pilot->controls[id].id = Controller_needs[id].id; |
| 1313 | Pilot->controls[id].type[0] = type[0]; |
| 1314 | Pilot->controls[id].type[1] = type[1]; |
| 1315 | Pilot->controls[id].value = value; |
| 1316 | Pilot->controls[id].flags[0] = flags[0]; |
| 1317 | Pilot->controls[id].flags[1] = flags[1]; |
no test coverage detected