enhanced interactive role selection (trunk only)

[See cvs log for src/role.c for a much longer description.]

     When picking role, race, and so forth, new menu entries allow you to
pick any of the other items before the one currently being handled.  After
picking all four of race, role, gender, and alignment (or if you answered
'y' to "shall I pick for you?"), there is a followup prompt to confirm the
choices.  It's a menu which also provides a chance to rename the character.

     This has only been implemented in win/tty's player_selection(), with
some support code in the core that might be useful to other interfaces.
And so far, the chance to rename is only presented as a menu choice if
you've given an answer to "who are you?" prompt earlier during startup.
Also, ports that use pcmain.c aren't able to perform hero renaming yet.
This commit is contained in:
nethack.rankin
2009-03-22 00:23:57 +00:00
parent c35d7f42be
commit 44cc716fe4
13 changed files with 693 additions and 373 deletions

View File

@@ -192,10 +192,7 @@ char *argv[];
/* wizard mode access is deferred until here */
set_playmode(); /* sets plname to "wizard" for wizard mode */
if(!*plname || !strncmp(plname, "player", 4)
|| !strncmp(plname, "games", 4)) {
askname();
} else if (exact_username) {
if (exact_username) {
/* guard against user names with hyphens in them */
int len = strlen(plname);
/* append the current role, if any, so that last dash is ours */
@@ -203,27 +200,33 @@ char *argv[];
(void)strncat(strcat(plname, "-"),
pl_character, sizeof plname - len - 1);
}
plnamesuffix(); /* strip suffix from name; calls askname() */
/* again if suffix was whole name */
/* accepts any suffix */
/* strip role,race,&c suffix; calls askname() if plname[] is empty
or holds a generic user name like "player" or "games" */
plnamesuffix();
#ifdef WIZARD
if(!wizard) {
if (wizard) {
/* use character name rather than lock letter for file names */
locknum = 0;
} else
#endif
/*
* check for multiple games under the same name
* (if !locknum) or check max nr of players (otherwise)
*/
{
/* suppress interrupts while processing lock file */
(void) signal(SIGQUIT,SIG_IGN);
(void) signal(SIGINT,SIG_IGN);
if(!locknum)
Sprintf(lock, "%d%s", (int)getuid(), plname);
getlock();
#ifdef WIZARD
} else {
Sprintf(lock, "%d%s", (int)getuid(), plname);
getlock();
}
#endif /* WIZARD */
/*
* getlock() complains and quits if there is already a game
* in progress for current character name (when locknum == 0)
* or if there are too many active games (when locknum > 0).
* When proceeding, it creates an empty <lockname>.0 file to
* designate the current game.
* getlock() constructs <lockname> based on the character
* name (for !locknum) or on first available of alock, block,
* clock, &c not currently in use in the playground directory
* (for locknum > 0).
*/
getlock();
program_state.preserve_locks = 0; /* after getlock() */
dlb_init(); /* must be before newgame() */
@@ -247,6 +250,11 @@ char *argv[];
display_gamewindows();
/*
* First, try to find and restore a save file for specified character.
* We'll return here if new game player_selection() renames the hero.
*/
attempt_restore:
if ((fd = restore_saved_game()) >= 0) {
const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1);
@@ -275,7 +283,24 @@ char *argv[];
}
if (!resuming) {
player_selection();
/* new game: start by choosing role, race, etc;
player might change the hero's name while doing that,
in which case we try to restore under the new name
and skip selection this time if that didn't succeed */
if (!iflags.renameinprogress) {
player_selection();
if (iflags.renameinprogress) {
/* player has renamed the hero while selecting role;
if locking alphabetically, the existing lock file
can still be used; otherwise, discard current one
and create another for the new character name */
if (!locknum) {
delete_levelfile(0); /* remove empty lock file */
getlock();
}
goto attempt_restore;
}
}
newgame();
wd_message();
}

View File

@@ -112,6 +112,12 @@ getlock()
error("%s", "");
}
/* default value of lock[] is "1lock" where '1' gets changed to
'a','b',&c below; override the default and use <uid><charname>
if we aren't restricting the number of simultaneous games */
if (!locknum)
Sprintf(lock, "%u%s", (unsigned)getuid(), plname);
regularize(lock);
set_levelfile_name(lock, 0);