Skip to content

Instantly share code, notes, and snippets.

@tung
Created April 12, 2011 03:11
Show Gist options
  • Save tung/914849 to your computer and use it in GitHub Desktop.
Save tung/914849 to your computer and use it in GitHub Desktop.
Unix/TTY-specific NetHack patch to allow choosing a name after picking a role. Made because Michael Lehotay's patch (http://bilious.homelinux.org/?68) was unavailable, until yesterday.
diff -r -U 3 -x '*.o' -x nethack -x nhdat -x date.h vanilla/include/extern.h nethack-3.4.3/include/extern.h
--- vanilla/include/extern.h 2011-04-09 00:08:56.000000000 +1000
+++ nethack-3.4.3/include/extern.h 2011-04-12 03:28:47.000000000 +1000
@@ -638,6 +638,7 @@
E int NDECL(open_savefile);
E int NDECL(delete_savefile);
E int NDECL(restore_saved_game);
+E int NDECL(saved_game_exists);
E void FDECL(compress, (const char *));
E void FDECL(uncompress, (const char *));
E boolean FDECL(lock_file, (const char *,int,int));
@@ -1729,6 +1730,7 @@
E int FDECL(pick_align, (int, int, int, int));
E void NDECL(role_init);
E void NDECL(rigid_role_checks);
+E void NDECL(plnamejustsuffix);
E void NDECL(plnamesuffix);
E const char *FDECL(Hello, (struct monst *));
E const char *NDECL(Goodbye);
diff -r -U 3 -x '*.o' -x nethack -x nhdat -x date.h vanilla/src/files.c nethack-3.4.3/src/files.c
--- vanilla/src/files.c 2011-04-09 00:08:56.000000000 +1000
+++ nethack-3.4.3/src/files.c 2011-04-12 03:28:47.000000000 +1000
@@ -938,6 +938,32 @@
return fd;
}
+
+/* check if a saved file exists */
+int
+saved_game_exists()
+{
+ char fq_save[80];
+ int fd;
+
+ set_savefile_name();
+#ifdef MFLOPPY
+ if (!saveDiskPrompt(1))
+ return -1;
+#endif /* MFLOPPY */
+ Strcpy(fq_save, fqname(SAVEF, SAVEPREFIX, 0));
+
+#ifdef COMPRESS_EXTENSION
+ Strcat(fq_save, COMPRESS_EXTENSION);
+#endif /* COMPRESS_EXTENSION */
+ if ((fd = open(fq_save, O_RDONLY | O_BINARY, 0)) != -1) {
+ close(fd);
+ return -1;
+ }
+ return 0;
+}
+
+
#if defined(UNIX) && defined(QT_GRAPHICS)
/*ARGSUSED*/
static char*
diff -r -U 3 -x '*.o' -x nethack -x nhdat -x date.h vanilla/src/role.c nethack-3.4.3/src/role.c
--- vanilla/src/role.c 2011-04-09 00:08:56.000000000 +1000
+++ nethack-3.4.3/src/role.c 2011-04-12 03:28:47.000000000 +1000
@@ -1289,7 +1289,7 @@
#undef NUM_BP
void
-plnamesuffix()
+plnamejustsuffix()
{
char *sptr, *eptr;
int i;
@@ -1313,6 +1313,14 @@
else if ((i = str2align(sptr)) != ROLE_NONE)
flags.initalign = i;
}
+}
+
+void
+plnamesuffix()
+{
+ char *sptr;
+
+ plnamejustsuffix();
if(!plname[0]) {
askname();
plnamesuffix();
diff -r -U 3 -x '*.o' -x nethack -x nhdat -x date.h vanilla/sys/unix/unixmain.c nethack-3.4.3/sys/unix/unixmain.c
--- vanilla/sys/unix/unixmain.c 2011-04-09 00:08:56.000000000 +1000
+++ nethack-3.4.3/sys/unix/unixmain.c 2011-04-12 03:33:21.000000000 +1000
@@ -193,27 +193,28 @@
(void)strncat(strcat(plname, "-"),
pl_character, sizeof plname - len - 1);
}
- plnamesuffix(); /* strip suffix from name; calls askname() */
- /* again if suffix was whole name */
+ plnamejustsuffix(); /* strip suffix from name; */
/* accepts any suffix */
+ if(plname[0] && saved_game_exists()) {
#ifdef WIZARD
- if(!wizard) {
+ if(!wizard) {
#endif
- /*
- * check for multiple games under the same name
- * (if !locknum) or check max nr of players (otherwise)
- */
- (void) signal(SIGQUIT,SIG_IGN);
- (void) signal(SIGINT,SIG_IGN);
- if(!locknum)
- Sprintf(lock, "%d%s", (int)getuid(), plname);
- getlock();
+ /*
+ * check for multiple games under the same name
+ * (if !locknum) or check max nr of players (otherwise)
+ */
+ (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();
- }
+ } else {
+ Sprintf(lock, "%d%s", (int)getuid(), plname);
+ getlock();
+ }
#endif /* WIZARD */
+ }
dlb_init(); /* must be before newgame() */
@@ -236,6 +237,9 @@
display_gamewindows();
+ if(!plname[0] || !saved_game_exists())
+ goto not_recovered;
+
if ((fd = restore_saved_game()) >= 0) {
#ifdef WIZARD
/* Since wizard is actually flags.debug, restoring might
@@ -275,6 +279,37 @@
} else {
not_recovered:
player_selection();
+ pline("You are a %s %s %s %s",
+ aligns[flags.initalign].adj,
+ genders[flags.initgend].adj,
+ races[flags.initrace].adj,
+ flags.initgend && roles[flags.initrole].name.f ?
+ roles[flags.initrole].name.f :
+ roles[flags.initrole].name.m);
+
+ while(!plname[0] || saved_game_exists()) {
+ plname[0] = 0;
+ plnamesuffix();
+ }
+#ifdef WIZARD
+ if(!wizard) {
+#endif
+ /*
+ * check for multiple games under the same name
+ * (if !locknum) or check max nr of players (otherwise)
+ */
+ (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 */
+
newgame();
wd_message();
diff -r -U 3 -x '*.o' -x nethack -x nhdat -x date.h vanilla/win/tty/wintty.c nethack-3.4.3/win/tty/wintty.c
--- vanilla/win/tty/wintty.c 2011-04-09 00:08:56.000000000 +1000
+++ nethack-3.4.3/win/tty/wintty.c 2011-04-12 03:28:47.000000000 +1000
@@ -727,7 +727,7 @@
}
}
plname[ct] = 0;
- } while (ct == 0);
+ } while (0);
/* move to next line to simulate echo of user's <return> */
tty_curs(BASE_WINDOW, 1, wins[BASE_WINDOW]->cury + 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment