Skip to content

Instantly share code, notes, and snippets.

@tung
Created April 12, 2011 03:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tung/914854 to your computer and use it in GitHub Desktop.
Save tung/914854 to your computer and use it in GitHub Desktop.
Gist mirror of Michael Lehotay's TTY-only Defer Name v1.0 NetHack patch (see http://bilious.homelinux.org/?68).
diff -r -u nethack-3.4.3/src/allmain.c defername/src/allmain.c
--- nethack-3.4.3/src/allmain.c 2003-12-07 18:39:14.000000000 +0000
+++ defername/src/allmain.c 2003-12-14 18:58:28.000000000 +0000
@@ -450,6 +450,9 @@
void
display_gamewindows()
{
+ if(WIN_MESSAGE != WIN_ERR)
+ return;
+
WIN_MESSAGE = create_nhwindow(NHW_MESSAGE);
WIN_STATUS = create_nhwindow(NHW_STATUS);
WIN_MAP = create_nhwindow(NHW_MAP);
diff -r -u nethack-3.4.3/win/tty/wintty.c defername/win/tty/wintty.c
--- nethack-3.4.3/win/tty/wintty.c 2003-12-07 18:39:14.000000000 +0000
+++ defername/win/tty/wintty.c 2003-12-14 19:06:18.000000000 +0000
@@ -145,6 +145,8 @@
boolean HE_resets_AS; /* see termcap.c */
#endif
+static boolean player_selected = FALSE;
+
#if defined(MICRO) || defined(WIN32CON)
static const char to_continue[] = "to continue";
#define getret() getreturn(to_continue)
@@ -324,6 +326,9 @@
anything any;
menu_item *selected = 0;
+ if(player_selected)
+ return;
+
/* prevent an unnecessary prompt */
rigid_role_checks();
@@ -647,7 +652,9 @@
flags.initalign = k;
}
}
+
/* Success! */
+ player_selected = TRUE;
tty_display_nhwindow(BASE_WINDOW, FALSE);
}
@@ -663,14 +670,14 @@
static char who_are_you[] = "Who are you? ";
register int c, ct, tryct = 0;
- tty_putstr(BASE_WINDOW, 0, "");
+ tty_putstr(BASE_WINDOW, 0, player_selected ? "" :
+ "Press <Enter> to answer this question later.");
+
do {
if (++tryct > 1) {
if (tryct > 10) bail("Giving up after 10 tries.\n");
- tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury - 1);
+ tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury - 1), cl_end();
tty_putstr(BASE_WINDOW, 0, "Enter a name for your character...");
- /* erase previous prompt (in case of ESC after partial response) */
- tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury), cl_end();
}
tty_putstr(BASE_WINDOW, 0, who_are_you);
tty_curs(BASE_WINDOW, (int)(sizeof who_are_you),
@@ -678,7 +685,13 @@
ct = 0;
while((c = tty_nhgetch()) != '\n') {
if(c == EOF) error("End of input\n");
- if (c == '\033') { ct = 0; break; } /* continue outer loop */
+ if (c == '\033') {
+ ct = 0;
+ /* clear partial input */
+ tty_curs(BASE_WINDOW, (int)(sizeof who_are_you),
+ wins[BASE_WINDOW]->cury), cl_end();
+ break; /* continue outer loop */
+ }
#if defined(WIN32CON)
if (c == '\003') bail("^C abort.\n");
#endif
@@ -727,10 +740,46 @@
}
}
plname[ct] = 0;
- } while (ct == 0);
+ } while (ct == 0 && player_selected);
/* move to next line to simulate echo of user's <return> */
tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury + 1);
+
+ if(ct == 0) { /* user wants to select player first */
+ char pbuf[QBUFSZ], plbuf[QBUFSZ];
+ int name_selected = FALSE;
+
+ display_gamewindows();
+ tty_player_selection();
+
+ /* let user know about their character (in case it was random) */
+ tty_clear_nhwindow(BASE_WINDOW);
+ root_plselection_prompt(plbuf, QBUFSZ - 1,
+ flags.initrole, flags.initrace, flags.initgend, flags.initalign);
+ Sprintf(pbuf, "You are a%s %s.", index(vowels, *plbuf) ? "n" : "", plbuf);
+ tty_putstr(BASE_WINDOW, 0, pbuf);
+ tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury + 1);
+
+ /* ask user for name again */
+ do {
+ int fd;
+
+ tty_askname();
+ if((fd=restore_saved_game()) < 0)
+ name_selected = TRUE;
+ else {
+ close(fd);
+ tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury - 2);
+ tty_putstr(BASE_WINDOW, 0,
+ "There is already a saved game using that name. "
+ "Please choose another one.");
+
+ /* clear bad name from screen */
+ tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury), cl_end();
+ tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury - 1);
+ }
+ } while(!name_selected);
+ }
}
void
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment