void player_select_process_input(int k) { char buf[CALLSIGN_LEN + 1]; int idx,z; // if the player is in the process of typing in a new pilot name... switch (k) { // cancel create pilot case KEY_ESC: player_select_cancel_create(); break; // accept a new pilot name case KEY_ENTER: Player_select_input_box.get_text(buf); drop_white_space(buf); z = 0; if (!isalpha(*buf)) { z = 1; } else { for (idx=1; buf[idx]; idx++) { if (!isalpha(buf[idx]) && !isdigit(buf[idx]) && !strchr(VALID_PILOT_CHARS, buf[idx])) { z = 1; break; } } } for (idx=1; idx<Player_select_num_pilots; idx++) { if (!stricmp(buf, Pilots[idx])) { // verify if it is ok to overwrite the file if (pilot_verify_overwrite() == 1) { // delete the pilot and select the beginning of the list Player_select_pilot = idx; player_select_delete_pilot(); Player_select_pilot = 0; idx = Player_select_num_pilots; z = 0; } else z = 1; break; } } if (!*buf || (idx < Player_select_num_pilots)) { z = 1; } if (z) { gamesnd_play_iface(SND_GENERAL_FAIL); break; } // Create the new pilot, and write out his file strcpy(Pilots[0], buf); // if this is the first guy, we should set the Player struct if (Player == NULL) { Player = &Players[0]; Player->reset(); Player->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE; } strcpy_s(Player->callsign, buf); init_new_pilot(Player, !Player_select_clone_flag); // set him as being a multiplayer pilot if we're in the correct mode if (Player_select_mode == PLAYER_SELECT_MODE_MULTI) { Player->flags |= PLAYER_FLAGS_IS_MULTI; Player->stats.flags |= STATS_FLAG_MULTIPLAYER; } // create his pilot file Pilot.save_player(Player); // unset the player Player->reset(); Player = NULL; // make this guy the selected pilot and put him first on the list Player_select_pilot = 0; // unset the input mode player_select_set_input_mode(0); // clear any pending bottom text player_select_set_bottom_text(""); // clear any pending middle text player_select_set_middle_text(""); // ungray all the controls player_select_set_controls(0); // evaluate whether or not this is the very first pilot player_select_eval_very_first_pilot(); break; case 0: break; // always kill middle text when a char is pressed in input mode default: player_select_set_middle_text(""); break; } }
// process pilot callsign void barracks_accept_new_pilot_callsign() { char buf[CALLSIGN_LEN + 1]; char name[MAX_FILENAME_LEN]; int i; int z = 0; Inputbox.get_text(buf); drop_white_space(buf); if (!isalpha(*buf)) { z = 1; } else { for (i=1; buf[i]; i++) { if (!isalpha(buf[i]) && !isdigit(buf[i]) && !strchr(VALID_PILOT_CHARS, buf[i])) { z = 1; return; } } } for (i=1; i<Num_pilots; i++) { if (!stricmp(buf, Pilots[i])) { z = 1; if (pilot_verify_overwrite() == 1) { strcpy_s(name, Pilots[Selected_line]); for (z=i; z<Num_pilots-1; z++) { strcpy(Pilots[z], Pilots[z + 1]); Pilot_ranks[z] = Pilot_ranks[z + 1]; } Num_pilots--; delete_pilot_file(name); z = 0; } return; } } if (!*buf || (i < Num_pilots)) { // duplicate name, alert user z = 1; } if (z) { gamesnd_play_iface(SND_GENERAL_FAIL); return; } strcpy(Pilots[0], buf); strcpy_s(Cur_pilot->callsign, buf); init_new_pilot(Cur_pilot, !Clone_flag); // again, make sure we set his flags correctly to ensure that he gets saved to the proper directory and gets // displayed correctly if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) { Cur_pilot->flags &= ~(PLAYER_FLAGS_IS_MULTI); } else { Cur_pilot->flags |= PLAYER_FLAGS_IS_MULTI; Cur_pilot->stats.flags |= STATS_FLAG_MULTIPLAYER; } if ( !(Game_mode & GM_STANDALONE_SERVER) ) { Pilot.save_player(Cur_pilot); } Selected_line = 0; barracks_new_pilot_selected(); barracks_set_callsign_enter_mode(false); }
// this will make a TC pilot based on his info from the database void pilot_manage_make_tc_pilot(Idline id, char *name) { // play sound for pilot creation gamesnd_play_iface(SND_SCROLL); // only write pilot file if there is an active pilot if (strlen(Player->callsign)) { write_pilot_file(); } int z = 0; for (int i=0; i<Num_pilots; i++) { if (!stricmp(name, Pilots[i])) { z = 1; if (pilot_verify_overwrite() == 1) { for (z=i; z<Num_pilots-1; z++) { strcpy(Pilots[z], Pilots[z + 1]); Pilot_ranks[z] = Pilot_ranks[z + 1]; } Num_pilots--; delete_pilot_file(name, 0); z = 0; } else return; } } if (!*name || (i < Num_pilots)) { // duplicate name, alert user z = 1; } if (z) { gamesnd_play_iface(SND_GENERAL_FAIL); return; } // move other pilot names and ranks down to make room for the new one int idx = Num_pilots; Assert(Num_pilots >= 0); while (idx--) { strcpy(Pilots[idx + 1], Pilots[idx]); Pilot_ranks[idx + 1] = Pilot_ranks[idx]; } Selected_line = 0; Num_pilots++; Pilots[Selected_line][0] = 0; Pilot_ranks[Selected_line] = 0; List_scroll_offset = 0; strcpy(Pilots[0], name); // make sure his rank pip matches his actual rank Pilot_ranks[0] = get_rank(id.rank); strcpy(Cur_pilot->callsign, name); init_new_pilot(Cur_pilot, !Clone_flag); Cur_pilot->flags |= PLAYER_FLAGS_IS_MULTI; Cur_pilot->stats.flags |= STATS_FLAG_MULTIPLAYER; Cur_pilot->stats.rank = get_rank(id.rank); Cur_pilot->stats.fchg = get_fchg(id.fchg); make_medals(&Cur_pilot->stats, id.medals); write_pilot_file(Cur_pilot); pilot_manage_new_pilot_selected(); }