static void game_ended(int status, fnchar *filename) { fnchar fncopy[1024], logname[1024], savedir[BUFSZ], *bp, *fname; if (status != GAME_OVER) return; show_topten(player.plname, settings.end_top, settings.end_around, settings.end_own); /* * The game ended terminally. Now it would be nice to move the saved game * out of the save/ dir and into the log/ dir, since it's only use now is as * a tropy. */ #if !defined(WIN32) /* dirname and basename may modify the input string, depending on the system */ strncpy(fncopy, filename, sizeof(fncopy)); bp = dirname(fncopy); get_gamedir(SAVE_DIR, savedir); savedir[strlen(savedir)-1] = '\0'; /* remove the trailing '/' */ if (strcmp(bp, savedir) != 0) return; /* file was not in savedir, so don't touch it */ get_gamedir(LOG_DIR, logname); strncpy(fncopy, filename, sizeof(fncopy)); fname = basename(fncopy); strncat(logname, fname, sizeof(logname)-1); /* don't care about errors: rename is nice to have, not essential */ rename(filename, logname); #else bp = wcsrchr(filename, L'\\'); get_gamedir(SAVE_DIR, savedir); if (!bp || wcsncmp(filename, savedir, wcslen(savedir))) return; get_gamedir(LOG_DIR, logname); wcsncat(logname, bp+1, 1024); /* don't care about errors: rename is nice to have, not essential */ _wrename(filename, logname); #endif }
static void mainmenu(void) { int menuresult[1]; int n = 1, logoheight, i; const char *const *copybanner = nh_get_copyright_banner(); const char **nhlogo; char verstr[32]; nh_bool first = TRUE; snprintf(verstr, ARRAY_SIZE(verstr), "Version %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL); #if defined(NETCLIENT) if (ui_flags.connection_only) { netgame(); return; } #endif load_keymap(); /* netgame() assumes the keymap isn't loaded */ while (n >= 0) { if (COLS >= 100) { nhlogo = nhlogo_large; logoheight = sizeof (nhlogo_large) / sizeof (nhlogo_large[0]); } else { nhlogo = nhlogo_small; logoheight = sizeof (nhlogo_small) / sizeof (nhlogo_small[0]); } wclear(basewin); wattron(basewin, A_BOLD | COLOR_PAIR(4)); for (i = 0; i < logoheight; i++) { wmove(basewin, i, (COLS - strlen(nhlogo[0])) / 2); if (nhlogo[i]) waddstr(basewin, nhlogo[i]); } wattroff(basewin, A_BOLD | COLOR_PAIR(4)); mvwaddstr(basewin, LINES - 3, 0, copybanner[0]); mvwaddstr(basewin, LINES - 2, 0, copybanner[1]); mvwaddstr(basewin, LINES - 1, 0, copybanner[2]); mvwaddstr(basewin, LINES - 4, COLS - strlen(verstr), verstr); wnoutrefresh(basewin); if (first) { network_motd(); first = FALSE; } menuresult[0] = EXITGAME; /* default action */ if (!override_hackdir) curses_display_menu_core( STATIC_MENULIST(mainmenu_items), NULL, PICK_ONE, menuresult, curses_menu_callback, 0, logoheight - 1, COLS, LINES - 3, FALSE, NULL, FALSE); else curses_display_menu_core( STATIC_MENULIST(mainmenu_items_noclient), NULL, PICK_ONE, menuresult, curses_menu_callback, 0, logoheight - 1, COLS, LINES - 3, FALSE, NULL, FALSE); if (*menuresult == CURSES_MENU_CANCELLED && !ui_flags.done_hup) continue; switch (menuresult[0]) { case NEWGAME: rungame(FALSE); break; case LOAD: loadgame(); break; case REPLAY: replay(); break; case OPTIONS: display_options(TRUE); break; #if defined(NETCLIENT) case NETWORK: free_keymap(); /* don't use the local keymap for server play */ netgame(); load_keymap(); break; #endif case TOPTEN: show_topten(NULL, -1, FALSE, FALSE); break; case EXITGAME: case CURSES_MENU_CANCELLED: /* in case of hangup */ n = -1; /* simulate menu cancel */ break; } } free_keymap(); }