Track chosen pilot name outside Players[]
Players need not be defined outside a game, but the pilot's name needs to be available outside a game. Therefore, track it outside Players[].
This commit is contained in:
parent
bfeca84bb8
commit
0c7de10512
|
@ -25,9 +25,11 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "dxxsconf.h"
|
||||
#include "fwd-event.h"
|
||||
#include "dsx-ns.h"
|
||||
#include "ntstring.h"
|
||||
#include "player-callsign.h"
|
||||
|
||||
namespace dcx {
|
||||
|
||||
|
@ -64,6 +66,16 @@ struct d_fname : ntstring<FILENAME_LEN - 1>
|
|||
}
|
||||
};
|
||||
|
||||
struct d_interface_unique_state
|
||||
{
|
||||
callsign_t PilotName;
|
||||
#if DXX_HAVE_POISON
|
||||
d_interface_unique_state();
|
||||
#endif
|
||||
};
|
||||
|
||||
extern d_interface_unique_state InterfaceUniqueState;
|
||||
|
||||
}
|
||||
|
||||
#ifdef dsx
|
||||
|
|
|
@ -271,7 +271,7 @@ int WriteConfigFile()
|
|||
PHYSFSX_printf(infile, "%s=%s\n", CMMiscMusic3Str, CGameCfg.CMMiscMusic[SONG_ENDGAME].data());
|
||||
PHYSFSX_printf(infile, "%s=%s\n", CMMiscMusic4Str, CGameCfg.CMMiscMusic[SONG_CREDITS].data());
|
||||
PHYSFSX_printf(infile, "%s=%d\n", GammaLevelStr, GameCfg.GammaLevel);
|
||||
PHYSFSX_printf(infile, "%s=%s\n", LastPlayerStr, static_cast<const char *>(get_local_player().callsign));
|
||||
PHYSFSX_printf(infile, "%s=%s\n", LastPlayerStr, static_cast<const char *>(InterfaceUniqueState.PilotName));
|
||||
PHYSFSX_printf(infile, "%s=%s\n", LastMissionStr, static_cast<const char *>(CGameCfg.LastMission));
|
||||
PHYSFSX_printf(infile, "%s=%i\n", ResolutionXStr, SM_W(Game_screen_mode));
|
||||
PHYSFSX_printf(infile, "%s=%i\n", ResolutionYStr, SM_H(Game_screen_mode));
|
||||
|
|
|
@ -240,7 +240,7 @@ static void show_netplayerinfo()
|
|||
const auto color = get_player_or_team_color(i);
|
||||
auto &prgb = player_rgb[color];
|
||||
gr_set_fontcolor(canvas, BM_XRGB(prgb.r, prgb.g, prgb.b), -1);
|
||||
gr_printf(canvas, game_font, x, y, "%s\n", static_cast<const char *>(plr.callsign));
|
||||
gr_string(canvas, game_font, x, y, plr.callsign);
|
||||
{
|
||||
auto &plrobj = *vcobjptr(plr.objnum);
|
||||
auto &player_info = plrobj.ctype.player_info;
|
||||
|
|
|
@ -398,6 +398,13 @@ window_event_result standard_handler(const d_event &event)
|
|||
return window_event_result::ignored;
|
||||
}
|
||||
|
||||
#if DXX_HAVE_POISON
|
||||
d_interface_unique_state::d_interface_unique_state()
|
||||
{
|
||||
DXX_MAKE_VAR_UNDEFINED(PilotName);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
namespace dsx {
|
||||
|
@ -617,20 +624,11 @@ static int main(int argc, char *argv[])
|
|||
con_puts(CON_DEBUG, "Running game...");
|
||||
init_game();
|
||||
|
||||
get_local_player().callsign = {};
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
key_flush();
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
// If built with editor, option to auto-load a level and quit game
|
||||
// to write certain data.
|
||||
#ifdef EDITOR
|
||||
if (!GameArg.EdiAutoLoad.empty()) {
|
||||
Players[0u].callsign = "dummy";
|
||||
} else
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
InterfaceUniqueState.PilotName.fill(0);
|
||||
if (!CGameArg.SysPilot.empty())
|
||||
{
|
||||
char filename[sizeof(PLAYER_DIRECTORY_TEXT) + CALLSIGN_LEN + 4];
|
||||
|
@ -658,7 +656,7 @@ static int main(int argc, char *argv[])
|
|||
}
|
||||
if(PHYSFSX_exists(filename,0))
|
||||
{
|
||||
get_local_player().callsign.copy(b, std::distance(b, &filename[j - 4]));
|
||||
InterfaceUniqueState.PilotName.copy(b, std::distance(b, &filename[j - 4]));
|
||||
read_player_file();
|
||||
WriteConfigFile();
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ static int MakeNewPlayerFile(int allow_abort)
|
|||
{
|
||||
int x;
|
||||
char filename[PATH_MAX];
|
||||
callsign_t text = get_local_player().callsign;
|
||||
auto text = InterfaceUniqueState.PilotName;
|
||||
|
||||
try_again:
|
||||
{
|
||||
|
@ -272,8 +272,7 @@ try_again:
|
|||
if ( !new_player_config() )
|
||||
goto try_again; // They hit Esc during New player config
|
||||
|
||||
get_local_player().callsign = text;
|
||||
|
||||
InterfaceUniqueState.PilotName = text;
|
||||
write_player_file();
|
||||
|
||||
return 1;
|
||||
|
@ -352,10 +351,9 @@ static window_event_result player_menu_handler( listbox *lb,const d_event &event
|
|||
}
|
||||
else
|
||||
{
|
||||
get_local_player().callsign.copy_lower(items[citem], strlen(items[citem]));
|
||||
InterfaceUniqueState.PilotName.copy_lower(items[citem], strlen(items[citem]));
|
||||
}
|
||||
return window_event_result::close;
|
||||
break;
|
||||
}
|
||||
|
||||
case EVENT_WINDOW_CLOSE:
|
||||
|
@ -383,18 +381,18 @@ static void RegisterPlayer()
|
|||
int citem = 0;
|
||||
int allow_abort_flag = 1;
|
||||
|
||||
auto &plr = get_local_player();
|
||||
if (!*static_cast<const char *>(plr.callsign))
|
||||
auto &callsign = InterfaceUniqueState.PilotName;
|
||||
if (!callsign[0])
|
||||
{
|
||||
if (!*static_cast<const char *>(GameCfg.LastPlayer))
|
||||
{
|
||||
plr.callsign = "player";
|
||||
callsign = "player";
|
||||
allow_abort_flag = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read the last player's name from config file, not lastplr.txt
|
||||
plr.callsign = GameCfg.LastPlayer;
|
||||
callsign = GameCfg.LastPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,7 +442,7 @@ static void RegisterPlayer()
|
|||
qsort(&m[1], NumItems - 1, sizeof(char *), string_array_sort_func);
|
||||
|
||||
for ( i=0; i<NumItems; i++ )
|
||||
if (!d_stricmp(static_cast<const char *>(get_local_player().callsign), m[i]) )
|
||||
if (!d_stricmp(static_cast<const char *>(callsign), m[i]))
|
||||
citem = i;
|
||||
|
||||
newmenu_listbox1(TXT_SELECT_PILOT, NumItems, m.release(), allow_abort_flag, citem, player_menu_handler, list.release());
|
||||
|
|
|
@ -50,6 +50,7 @@ static void reconstruct_global_variable(T &t)
|
|||
new(&t) T();
|
||||
}
|
||||
|
||||
d_interface_unique_state InterfaceUniqueState;
|
||||
d_game_unique_state GameUniqueState;
|
||||
d_level_shared_boss_state LevelSharedBossState;
|
||||
d_level_shared_vertex_state LevelSharedVertexState;
|
||||
|
|
|
@ -845,7 +845,7 @@ int read_player_file()
|
|||
Assert(Player_num < MAX_PLAYERS);
|
||||
|
||||
memset(filename, '\0', PATH_MAX);
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plr"), static_cast<const char *>(get_local_player().callsign));
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plr"), static_cast<const char *>(InterfaceUniqueState.PilotName));
|
||||
if (!PHYSFSX_exists(filename,0))
|
||||
return ENOENT;
|
||||
auto file = PHYSFSX_openReadBuffered(filename);
|
||||
|
@ -1324,10 +1324,9 @@ void write_player_file()
|
|||
|
||||
errno_ret = WriteConfigFile();
|
||||
|
||||
auto &plr = get_local_player();
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plx"), static_cast<const char *>(plr.callsign));
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plx"), static_cast<const char *>(InterfaceUniqueState.PilotName));
|
||||
write_player_dxx(filename);
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plr"), static_cast<const char *>(plr.callsign));
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plr"), static_cast<const char *>(InterfaceUniqueState.PilotName));
|
||||
auto file = PHYSFSX_openWriteBuffered(filename);
|
||||
if (!file)
|
||||
return;
|
||||
|
@ -1525,7 +1524,7 @@ void read_netgame_profile(netgame_info *ng)
|
|||
ng->TrackerNATWarned = TrackerNATHolePunchWarn::Unset;
|
||||
#endif
|
||||
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.ngp"), static_cast<const char *>(get_local_player().callsign));
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.ngp"), static_cast<const char *>(InterfaceUniqueState.PilotName));
|
||||
auto file = PHYSFSX_openReadBuffered(filename);
|
||||
if (!file)
|
||||
return;
|
||||
|
@ -1619,7 +1618,7 @@ void read_netgame_profile(netgame_info *ng)
|
|||
void write_netgame_profile(netgame_info *ng)
|
||||
{
|
||||
char filename[PATH_MAX];
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.ngp"), static_cast<const char *>(get_local_player().callsign));
|
||||
snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.ngp"), static_cast<const char *>(InterfaceUniqueState.PilotName));
|
||||
auto file = PHYSFSX_openWriteBuffered(filename);
|
||||
if (!file)
|
||||
return;
|
||||
|
|
|
@ -720,7 +720,7 @@ static int state_get_savegame_filename(char * fname, char * dsc, const char * ca
|
|||
nsaves=0;
|
||||
nm_set_item_text(m[0], "\n\n\n\n");
|
||||
for (i=0;i<NUM_SAVES; i++ ) {
|
||||
snprintf(filename[i], sizeof(filename[i]), PLAYER_DIRECTORY_STRING("%.8s.%cg%x"), static_cast<const char *>(get_local_player().callsign), (Game_mode & GM_MULTI_COOP)?'m':'s', i );
|
||||
snprintf(filename[i], sizeof(filename[i]), PLAYER_DIRECTORY_STRING("%.8s.%cg%x"), static_cast<const char *>(InterfaceUniqueState.PilotName), (Game_mode & GM_MULTI_COOP)?'m':'s', i );
|
||||
valid = 0;
|
||||
if (auto fp = PHYSFSX_openReadBuffered(filename[i]))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue