int test_newgame(void *state) { /* Try making a new game */ cmdq_push(CMD_BIRTH_INIT); cmdq_push(CMD_BIRTH_RESET); cmdq_push(CMD_CHOOSE_RACE); cmd_set_arg_choice(cmdq_peek(), "choice", 0); cmdq_push(CMD_CHOOSE_CLASS); cmd_set_arg_choice(cmdq_peek(), "choice", 0); cmdq_push(CMD_ROLL_STATS); cmdq_push(CMD_NAME_CHOICE); cmd_set_arg_string(cmdq_peek(), "name", "Tester"); cmdq_push(CMD_ACCEPT_CHARACTER); cmdq_execute(CMD_BIRTH); eq(player->is_dead, FALSE); cave_generate(&cave, player); on_new_level(); noteq(cave, NULL); eq(player->chp, player->mhp); eq(player->food, PY_FOOD_FULL - 1); /* Should be all set up to save properly now */ eq(savefile_save("Test1"), TRUE); /* Make sure it saved properly */ eq(file_exists("Test1"), TRUE); ok; }
/* * Handle abrupt death of the visual system * * This routine is called only in very rare situations, and only * by certain visual systems, when they experience fatal errors. * * XXX XXX Hack -- clear the death flag when creating a HANGUP * save file so that player can see tombstone when restart. */ void exit_game_panic(void) { /* If nothing important has happened, just quit */ if (!character_generated || character_saved) quit("panic"); /* Mega-Hack -- see "msg_print()" */ msg_flag = FALSE; /* Clear the top line */ prt("", 0, 0); /* Hack -- turn off some things */ disturb(1, 0); /* Hack -- Delay death XXX XXX XXX */ if (p_ptr->chp < 0) p_ptr->is_dead = FALSE; /* Hardcode panic save */ p_ptr->panic_save = 1; /* Forbid suspend */ signals_ignore_tstp(); /* Indicate panic save */ my_strcpy(p_ptr->died_from, "(panic save)", sizeof(p_ptr->died_from)); /* Panic save, or get worried */ if (!savefile_save(savefile)) quit("panic save failed!"); /* Successful panic save */ quit("panic save succeeded!"); }
/* * Handle character death */ void death_screen(void) { bool done = FALSE; const region area = { 51, 2, 0, N_ELEMENTS(death_actions) }; /* Retire in the town in a good state */ if (p_ptr->total_winner) { p_ptr->depth = 0; my_strcpy(p_ptr->died_from, "Ripe Old Age", sizeof(p_ptr->died_from)); p_ptr->exp = p_ptr->max_exp; p_ptr->lev = p_ptr->max_lev; p_ptr->au += 10000000L; display_winner(); } /* Get time of death */ (void)time(&death_time); print_tomb(); death_knowledge(); enter_score(&death_time); /* Flush all input and output */ flush(); message_flush(); /* Display and use the death menu */ if (!death_menu) { death_menu = menu_new_action(death_actions, N_ELEMENTS(death_actions)); death_menu->flags = MN_CASELESS_TAGS; } menu_layout(death_menu, &area); while (!done) { ui_event e = menu_select(death_menu, EVT_KBRD); if (e.type == EVT_KBRD) { if (e.key.code == KTRL('X')) break; } else if (e.type == EVT_SELECT) { done = get_check("Do you want to quit? "); } } /* Save dead player */ if (!savefile_save(savefile)) { msg("death save failed!"); message_flush(); } }
/** * Close up the current game (player may or may not be dead) * * Note that the savefile is not saved until the tombstone is * actually displayed and the player has a chance to examine * the inventory and such. This allows cheating if the game * is equipped with a "quit without save" method. XXX XXX XXX */ void close_game(void) { /* Tell the UI we're done with the game state */ event_signal(EVENT_LEAVE_GAME); /* Handle stuff */ handle_stuff(player->upkeep); /* Flush the messages */ event_signal(EVENT_MESSAGE_FLUSH); /* Flush the input */ event_signal(EVENT_INPUT_FLUSH); /* No suspending now */ signals_ignore_tstp(); /* Hack -- Increase "icky" depth */ screen_save_depth++; /* Save monster memory to user directory */ if (!lore_save("lore.txt")) { msg("lore save failed!"); event_signal(EVENT_MESSAGE_FLUSH); } /* Handle death or life */ if (player->is_dead) { death_knowledge(); death_screen(); /* Save dead player */ if (!savefile_save(savefile)) { msg("death save failed!"); event_signal(EVENT_MESSAGE_FLUSH); } } else { /* Save the game */ save_game(); if (Term->mapped_flag) { struct keypress ch; prt("Press Return (or Escape).", 0, 40); ch = inkey(); if (ch.code != ESCAPE) predict_score(); } } /* Hack -- Decrease "icky" depth */ screen_save_depth--; /* Allow suspending now */ signals_handle_tstp(); }
/** * Save the game */ void save_game(void) { char name[80]; char path[1024]; /* Disturb the player */ disturb(player, 1); /* Clear messages */ event_signal(EVENT_MESSAGE_FLUSH); /* Handle stuff */ handle_stuff(player); /* Message */ prt("Saving game...", 0, 0); /* Refresh */ Term_fresh(); /* The player is not dead */ my_strcpy(player->died_from, "(saved)", sizeof(player->died_from)); /* Forbid suspend */ signals_ignore_tstp(); /* Save the player */ if (savefile_save(savefile)) prt("Saving game... done.", 0, 0); else prt("Saving game... failed!", 0, 0); /* Refresh */ Term_fresh(); /* Save the window prefs */ strnfmt(name, sizeof(name), "%s.prf", player_safe_name(player, TRUE)); path_build(path, sizeof(path), ANGBAND_DIR_USER, name); if (!prefs_save(path, option_dump, "Dump window settings")) prt("Failed to save subwindow preferences", 0, 0); /* Allow suspend again */ signals_handle_tstp(); /* Refresh */ Term_fresh(); /* Note that the player is not dead */ my_strcpy(player->died_from, "(alive and well)", sizeof(player->died_from)); }
/* * Handle character death */ void death_screen(void) { const region area = { 51, 2, 0, N_ELEMENTS(death_actions) }; /* Retire in the town in a good state */ if (p_ptr->total_winner) { p_ptr->depth = 0; my_strcpy(p_ptr->died_from, "Ripe Old Age", sizeof(p_ptr->died_from)); p_ptr->exp = p_ptr->max_exp; p_ptr->lev = p_ptr->max_lev; p_ptr->au += 10000000L; display_winner(); } /* Save dead player */ if (!savefile_save(savefile)) { msg("death save failed!"); message_flush(); } /* Get time of death */ (void)time(&death_time); print_tomb(); death_knowledge(); enter_score(&death_time); /* Flush all input and output */ flush(); message_flush(); if (!death_menu) { death_menu = menu_new_action(death_actions, N_ELEMENTS(death_actions)); death_menu->flags = MN_CASELESS_TAGS; } menu_layout(death_menu, &area); do { menu_select(death_menu, 0); } while (!get_check("Do you want to quit? ")); }
/* * Handle signal -- abort, kill, etc */ static void handle_signal_abort(int sig) { /* Disable handler */ (void)(*signal_aux)(sig, SIG_IGN); /* Nothing to save, just quit */ if (!character_generated || character_saved) quit(NULL); /* Clear the bottom line */ Term_erase(0, 23, 255); /* Give a warning */ Term_putstr(0, 23, -1, TERM_RED, "A gruesome software bug LEAPS out at you!"); /* Message */ Term_putstr(45, 23, -1, TERM_RED, "Panic save..."); /* Flush output */ Term_fresh(); /* Panic Save */ p_ptr->panic_save = 1; /* Panic save */ my_strcpy(p_ptr->died_from, "(panic save)", sizeof(p_ptr->died_from)); /* Forbid suspend */ signals_ignore_tstp(); /* Attempt to save */ if (savefile_save(savefile)) Term_putstr(45, 23, -1, TERM_RED, "Panic save succeeded!"); else Term_putstr(45, 23, -1, TERM_RED, "Panic save failed!"); /* Flush output */ Term_fresh(); /* Quit */ quit("software bug"); }
/* * Save the game */ void save_game(void) { /* Disturb the player */ disturb(p_ptr, 1, 0); /* Clear messages */ message_flush(); /* Handle stuff */ handle_stuff(p_ptr); /* Message */ prt("Saving game...", 0, 0); /* Refresh */ Term_fresh(); /* The player is not dead */ my_strcpy(p_ptr->died_from, "(saved)", sizeof(p_ptr->died_from)); /* Forbid suspend */ signals_ignore_tstp(); /* Save the player */ if (savefile_save(savefile)) prt("Saving game... done.", 0, 0); else prt("Saving game... failed!", 0, 0); /* Allow suspend again */ signals_handle_tstp(); /* Refresh */ Term_fresh(); /* Note that the player is not dead */ my_strcpy(p_ptr->died_from, "(alive and well)", sizeof(p_ptr->died_from)); }