int new_player_config() { int i=0; for (i=0;i<N_SAVE_SLOTS;i++) saved_games[i].name[0] = 0; InitWeaponOrdering (); //setup default weapon priorities PlayerCfg.ControlType=0; // Assume keyboard memcpy(PlayerCfg.KeySettings, DefaultKeySettings, sizeof(DefaultKeySettings)); memcpy(PlayerCfg.KeySettingsD1X, DefaultKeySettingsD1X, sizeof(DefaultKeySettingsD1X)); kc_set_controls(); PlayerCfg.DefaultDifficulty = 1; PlayerCfg.AutoLeveling = 1; PlayerCfg.NHighestLevels = 1; PlayerCfg.HighestLevels[0].Shortname[0] = 0; //no name for mission 0 PlayerCfg.HighestLevels[0].LevelNum = 1; //was highest level in old struct PlayerCfg.JoystickSens[0] = PlayerCfg.JoystickSens[1] = PlayerCfg.JoystickSens[2] = PlayerCfg.JoystickSens[3] = PlayerCfg.JoystickSens[4] = PlayerCfg.JoystickSens[5] = 8; PlayerCfg.JoystickDead[0] = PlayerCfg.JoystickDead[1] = PlayerCfg.JoystickDead[2] = PlayerCfg.JoystickDead[3] = PlayerCfg.JoystickDead[4] = PlayerCfg.JoystickDead[5] = 0; PlayerCfg.MouseFlightSim = 0; PlayerCfg.MouseSens[0] = PlayerCfg.MouseSens[1] = PlayerCfg.MouseSens[2] = PlayerCfg.MouseSens[3] = PlayerCfg.MouseSens[4] = PlayerCfg.MouseSens[5] = 8; PlayerCfg.MouseFSDead = 0; PlayerCfg.MouseFSIndicator = 1; PlayerCfg.CockpitMode[0] = PlayerCfg.CockpitMode[1] = CM_FULL_COCKPIT; PlayerCfg.ReticleType = RET_TYPE_CLASSIC; PlayerCfg.ReticleRGBA[0] = RET_COLOR_DEFAULT_R; PlayerCfg.ReticleRGBA[1] = RET_COLOR_DEFAULT_G; PlayerCfg.ReticleRGBA[2] = RET_COLOR_DEFAULT_B; PlayerCfg.ReticleRGBA[3] = RET_COLOR_DEFAULT_A; PlayerCfg.ReticleSize = 0; PlayerCfg.HudMode = 0; PlayerCfg.PersistentDebris = 0; PlayerCfg.PRShot = 0; PlayerCfg.NoRedundancy = 0; PlayerCfg.MultiMessages = 0; PlayerCfg.BombGauge = 1; PlayerCfg.AutomapFreeFlight = 0; PlayerCfg.NoFireAutoselect = 0; PlayerCfg.AlphaEffects = 0; PlayerCfg.DynLightColor = 0; // Default taunt macros #ifdef NETWORK strcpy(PlayerCfg.NetworkMessageMacro[0], TXT_DEF_MACRO_1); strcpy(PlayerCfg.NetworkMessageMacro[1], TXT_DEF_MACRO_2); strcpy(PlayerCfg.NetworkMessageMacro[2], TXT_DEF_MACRO_3); strcpy(PlayerCfg.NetworkMessageMacro[3], TXT_DEF_MACRO_4); PlayerCfg.NetlifeKills=0; PlayerCfg.NetlifeKilled=0; #endif return 1; }
void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem ) { int oc_joy = Config_control_joystick.intval; int oc_mouse = Config_control_mouse.intval; cvar_setint(&Config_control_joystick, items[0].value); cvar_setint(&Config_control_mouse, items[1].value); if (!oc_joy && Config_control_joystick.intval) joydefs_calibrate_flag = 1; if (oc_joy != Config_control_joystick.intval || oc_mouse != Config_control_mouse.intval) kc_set_controls(); }
//Inputs the player's name, without putting up the background screen RegisterPlayer() { int i,j; char filename[14]; int allow_abort_flag = 1; if ( Players[Player_num].callsign[0] == 0 ) { //--------------------------------------------------------------------- // Set default config options in case there is no config file // kc_keyboard, kc_joystick, kc_mouse are statically defined. Config_joystick_sensitivity = 8; Config_control_type =CONTROL_NONE; for (i=0; i<CONTROL_MAX_TYPES; i++ ) for (j=0; j<MAX_CONTROLS; j++ ) kconfig_settings[i][j] = default_kconfig_settings[i][j]; kc_set_controls(); //---------------------------------------------------------------- // Read the last player's name from config file, not lastplr.txt strncpy( Players[Player_num].callsign, config_last_player, CALLSIGN_LEN ); if (config_last_player[0]==0) allow_abort_flag = 0; } do_menu_again: ; if (!newmenu_get_filename( TXT_SELECT_PILOT, "*.plr", filename, allow_abort_flag )) { return 0; // They hit Esc in file selector } if ( filename[0] == '<' ) { // They selected 'create new pilot' if (!MakeNewPlayerFile(allow_abort_flag)) //return 0; // They hit Esc during enter name stage goto do_menu_again; } else { strncpy(Players[Player_num].callsign,filename, CALLSIGN_LEN); } read_player_file(); Auto_leveling_on = Default_leveling_on; WriteConfigFile(); // Update lastplr return 1; }
void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem ) { int i; int oc_type = Config_control_type; nitems = nitems; last_key = last_key; citem = citem; for (i=0; i<3; i++ ) if (items[i].value) Config_control_type = i; //added on 10/17/98 by Hans de Goede for joystick/mouse # fix // remap mouse, since "Flightstick Pro", "Thrustmaster FCS" // and "Gravis Gamepad" where removed from the options if (Config_control_type == 2) Config_control_type = CONTROL_MOUSE; //end this section addition - Hans if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) ) { nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS ); } if (oc_type != Config_control_type) { switch (Config_control_type) { // case CONTROL_NONE: case CONTROL_JOYSTICK: case CONTROL_FLIGHTSTICK_PRO: case CONTROL_THRUSTMASTER_FCS: case CONTROL_GRAVIS_GAMEPAD: // case CONTROL_MOUSE: // case CONTROL_CYBERMAN: joydefs_calibrate_flag = 1; } kc_set_controls(); } }
//read in the player's saved games. returns errno (0 == no error) int read_player_file() { char filename[PATH_MAX]; PHYSFS_file *file; int player_file_size, shareware_file = -1, id = 0; short saved_game_version, player_struct_version; Assert(Player_num>=0 && Player_num<MAX_PLAYERS); memset(filename, '\0', PATH_MAX); snprintf(filename, PATH_MAX, GameArg.SysUsePlayersDir? "Players/%.8s.plr" : "%.8s.plr", Players[Player_num].callsign); if (!PHYSFSX_exists(filename,0)) return ENOENT; file = PHYSFSX_openReadBuffered(filename); if (!file) goto read_player_file_failed; new_player_config(); // Set defaults! // Unfortunatly d1x has been writing both shareware and registered // player files with a saved_game_version of 7 and 8, whereas the // original decent used 4 for shareware games and 7 for registered // games. Because of this the player files didn't get properly read // when reading d1x shareware player files in d1x registered or // vica versa. The problem is that the sizeof of the taunt macros // differ between the share and registered versions, causing the // reading of the player file to go wrong. Thus we now determine the // sizeof the player file to determine what kinda player file we are // dealing with so that we can do the right thing PHYSFS_seek(file, 0); player_file_size = PHYSFS_fileLength(file); PHYSFS_readSLE32(file, &id); saved_game_version = PHYSFSX_readShort(file); player_struct_version = PHYSFSX_readShort(file); PlayerCfg.NHighestLevels = PHYSFSX_readInt(file); PlayerCfg.DefaultDifficulty = PHYSFSX_readInt(file); PlayerCfg.AutoLeveling = PHYSFSX_readInt(file); if (id!=SAVE_FILE_ID) { nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid player file"); PHYSFS_close(file); return -1; } if (saved_game_version<COMPATIBLE_SAVED_GAME_VERSION || player_struct_version<COMPATIBLE_PLAYER_STRUCT_VERSION) { nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_ERROR_PLR_VERSION); PHYSFS_close(file); return -1; } /* determine if we're dealing with a shareware or registered playerfile */ switch (saved_game_version) { case 4: shareware_file = 1; break; case 5: case 6: shareware_file = 0; break; case 7: /* version 7 doesn't have the saved games array */ if ((player_file_size - (sizeof(hli)*PlayerCfg.NHighestLevels)) == (2212 - sizeof(saved_games))) shareware_file = 1; if ((player_file_size - (sizeof(hli)*PlayerCfg.NHighestLevels)) == (2252 - sizeof(saved_games))) shareware_file = 0; break; case 8: if ((player_file_size - (sizeof(hli)*PlayerCfg.NHighestLevels)) == 2212) shareware_file = 1; if ((player_file_size - (sizeof(hli)*PlayerCfg.NHighestLevels)) == 2252) shareware_file = 0; /* d1x-rebirth v0.31 to v0.42 broke things by adding stuff to the player struct without thinking (sigh) */ if ((player_file_size - (sizeof(hli)*PlayerCfg.NHighestLevels)) == (2212 + 2*sizeof(int))) { shareware_file = 1; /* skip the cruft added to the player_info struct */ PHYSFS_seek(file, PHYSFS_tell(file)+2*sizeof(int)); } if ((player_file_size - (sizeof(hli)*PlayerCfg.NHighestLevels)) == (2252 + 2*sizeof(int))) { shareware_file = 0; /* skip the cruft added to the player_info struct */ PHYSFS_seek(file, PHYSFS_tell(file)+2*sizeof(int)); } } if (shareware_file == -1) { nm_messagebox(TXT_ERROR, 1, TXT_OK, "Error invalid or unknown\nplayerfile-size"); PHYSFS_close(file); return -1; } if (saved_game_version <= 5) { //deal with old-style highest level info PlayerCfg.HighestLevels[0].Shortname[0] = 0; //no name for mission 0 PlayerCfg.HighestLevels[0].LevelNum = PlayerCfg.NHighestLevels; //was highest level in old struct //This hack allows the player to start on level 8 if he's made it to //level 7 on the shareware. We do this because the shareware didn't //save the information that the player finished level 7, so the most //we know is that he made it to level 7. if (PlayerCfg.NHighestLevels==7) PlayerCfg.HighestLevels[0].LevelNum = 8; } else { //read new highest level info if (PHYSFS_read(file,PlayerCfg.HighestLevels,sizeof(hli),PlayerCfg.NHighestLevels) != PlayerCfg.NHighestLevels) goto read_player_file_failed; } if ( saved_game_version != 7 ) { // Read old & SW saved games. if (PHYSFS_read(file,saved_games,sizeof(saved_games),1) != 1) goto read_player_file_failed; } //read taunt macros { int i; int len = shareware_file? 25:35; #ifdef NETWORK for (i = 0; i < 4; i++) if (PHYSFS_read(file, PlayerCfg.NetworkMessageMacro[i], len, 1) != 1) goto read_player_file_failed; #else i = 0; PHYSFS_seek( file, PHYSFS_tell(file)+4*len ); #endif } //read kconfig data { ubyte dummy_joy_sens; if (PHYSFS_read(file, &PlayerCfg.KeySettings[0], sizeof(PlayerCfg.KeySettings[0]),1)!=1) goto read_player_file_failed; if (PHYSFS_read(file, &PlayerCfg.KeySettings[1], sizeof(PlayerCfg.KeySettings[1]),1)!=1) goto read_player_file_failed; PHYSFS_seek( file, PHYSFS_tell(file)+(sizeof(ubyte)*MAX_CONTROLS*3) ); // Skip obsolete Flightstick/Thrustmaster/Gravis map fields if (PHYSFS_read(file, &PlayerCfg.KeySettings[2], sizeof(PlayerCfg.KeySettings[2]),1)!=1) goto read_player_file_failed; PHYSFS_seek( file, PHYSFS_tell(file)+(sizeof(ubyte)*MAX_CONTROLS) ); // Skip obsolete Cyberman map field if (PHYSFS_read(file, &PlayerCfg.ControlType, sizeof(ubyte), 1 )!=1) goto read_player_file_failed; else if (PHYSFS_read(file, &dummy_joy_sens, sizeof(ubyte), 1 )!=1) goto read_player_file_failed; } if ( saved_game_version != 7 ) { int i, found=0; Assert( N_SAVE_SLOTS == 10 ); for (i=0; i<N_SAVE_SLOTS; i++ ) { if ( saved_games[i].name[0] ) { state_save_old_game(i, saved_games[i].name, &saved_games[i].sg_player, saved_games[i].difficulty_level, saved_games[i].primary_weapon, saved_games[i].secondary_weapon, saved_games[i].next_level_num ); // make sure we do not do this again, which would possibly overwrite // a new newstyle savegame saved_games[i].name[0] = 0; found++; } } if (found) write_player_file(); } if (!PHYSFS_close(file)) goto read_player_file_failed; filename[strlen(filename) - 4] = 0; strcat(filename, ".plx"); read_player_d1x(filename); kc_set_controls(); return EZERO; read_player_file_failed: nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s", "Error reading PLR file", PHYSFS_getLastError()); if (file) PHYSFS_close(file); return -1; }