/* * 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(); } }
/* * Hack -- save a screen dump to a file in html format */ static void do_cmd_save_screen_html(int mode) { size_t i; ang_file *fff; char file_name[1024]; char tmp_val[256]; typedef void (*dump_func)(ang_file *); dump_func dump_visuals [] = { dump_monsters, dump_features, dump_objects, dump_flavors, dump_colors }; if (mode == 0) my_strcpy(tmp_val, "dump.html", sizeof(tmp_val)); else my_strcpy(tmp_val, "dump.txt", sizeof(tmp_val)); /* Ask for a file */ if (!get_string("File: ", tmp_val, sizeof(tmp_val))) return; /* Save current preferences */ path_build(file_name, 1024, ANGBAND_DIR_USER, "dump.prf"); fff = file_open(file_name, MODE_WRITE, (mode == 0 ? FTYPE_HTML : FTYPE_TEXT)); /* Check for failure */ if (!fff) { msg("Screen dump failed."); message_flush(); return; } /* Dump all the visuals */ for (i = 0; i < N_ELEMENTS(dump_visuals); i++) dump_visuals[i](fff); file_close(fff); /* Dump the screen with raw character attributes */ reset_visuals(FALSE); do_cmd_redraw(); html_screenshot(tmp_val, mode); /* Recover current graphics settings */ reset_visuals(TRUE); process_pref_file(file_name, TRUE, FALSE); file_delete(file_name); do_cmd_redraw(); msg("HTML screen dump saved."); message_flush(); }
/* * 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? ")); }
/* * Get a string from the user * * The "prompt" should take the form "Prompt: " * * Note that the initial contents of the string is used as * the default response, so be sure to "clear" it if needed. * * We clear the input, and return FALSE, on "ESCAPE". */ bool get_string(char *buf, int len, cptr str, ...) { bool res; va_list vp; char prompt[1024]; /* Begin the Varargs Stuff */ va_start(vp, str); /* Format the args, save the length */ (void)vstrnfmt(prompt, 1024, str, &vp); /* End the Varargs Stuff */ va_end(vp); /* Paranoia XXX XXX XXX */ message_flush(); /* Display prompt */ prtf(0, 0, prompt); /* Ask the user for a string */ res = askfor_aux(buf, len); /* Clear prompt */ clear_msg(); /* Result */ return (res); }
static void print_error(const char *name, struct parser *p) { struct parser_state s; parser_getstate(p, &s); msg("Parse error in %s line %d column %d: %s: %s", name, s.line, s.col, s.msg, parser_error_str[s.error]); message_flush(); }
/* * Menu command: dump character dump to file. */ static void death_file(const char *title, int row) { char buf[1024]; char ftmp[80]; strnfmt(ftmp, sizeof(ftmp), "%s.txt", op_ptr->base_name); if (get_file(ftmp, buf, sizeof buf)) { errr err; /* Dump a character file */ screen_save(); err = file_character(buf, FALSE); screen_load(); /* Check result */ if (err) msg("Character dump failed!"); else msg("Character dump successful."); /* Flush messages */ message_flush(); } }
/* * Inscribe an object with a comment */ void do_cmd_inscribe(void) { int item; object_type *o_ptr; char o_name[80]; char tmp[80]; cptr q, s; /* Get an item */ q = "Inscribe which item? "; s = "You have nothing to inscribe."; if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return; /* Get the item (in the pack) */ if (item >= 0) { o_ptr = &inventory[item]; } /* Get the item (on the floor) */ else { o_ptr = &o_list[0 - item]; } /* Describe the activity */ object_desc(o_name, o_ptr, TRUE, 3); /* Message */ msg_format("Inscribing %s.", o_name); message_flush(); /* Start with nothing */ strcpy(tmp, ""); /* Use old inscription */ if (o_ptr->note) { /* Start with the old inscription */ strnfmt(tmp, 80, "%s", quark_str(o_ptr->note)); } /* Get a new inscription (possibly empty) */ if (get_string("Inscription: ", tmp, 80)) { /* Save the inscription */ o_ptr->note = quark_add(tmp); /* Combine the pack */ p_ptr->notice |= (PN_COMBINE); /* Window stuff */ p_ptr->window |= (PW_INVEN | PW_EQUIP); } }
/** * Verify use of "debug" mode */ static bool verify_debug_mode(void) { static int verify = 1; /* Ask first time, unless the savefile is already in debug mode. */ if (verify && (!(p_ptr->noscore & 0x0008))) { /* Mention effects */ msg ("You are about to use the dangerous, unsupported, debug commands!"); msg ("Your machine may crash, and your savefile may become corrupted!"); msg("Using the debug commands will also mark your savefile."); message_flush(); /* Verify request */ if (!get_check("Are you sure you want to use the debug commands? ")) { return (FALSE); } } /* Verified */ verify = 0; /* Mark savefile */ p_ptr->noscore |= 0x0008; /* Okay */ return (TRUE); }
/* * Gets a name for the character, reacting to name changes. * * If sf is TRUE, we change the savefile name depending on the character name. * * What a horrible name for a global function. XXX XXX XXX */ bool get_name(char *buf, size_t buflen) { bool res; /* Paranoia XXX XXX XXX */ message_flush(); /* Display prompt */ prt("Enter a name for your character (* for a random name): ", 0, 0); /* Save the player name */ my_strcpy(buf, op_ptr->full_name, buflen); /* Ask the user for a string */ res = askfor_aux(buf, buflen, get_name_keypress); /* Clear prompt */ prt("", 0, 0); /* Revert to the old name if the player doesn't pick a new one. */ if (!res) { my_strcpy(buf, op_ptr->full_name, buflen); } return res; }
/* More angband-specific bits of the parser * These require hooks into other parts of the code, and are a candidate for * moving elsewhere. */ static void print_error(struct file_parser *fp, struct parser *p) { struct parser_state s; parser_getstate(p, &s); msg("Parse error in %s line %d column %d: %s: %s", fp->name, s.line, s.col, s.msg, parser_error_str[s.error]); message_flush(); quit_fmt("Parse error in %s line %d column %d.", fp->name, s.line, s.col); }
/** * Handle character death */ void death_screen(void) { const region area = { 51, 2, 0, N_ELEMENTS(death_actions) }; /* Dump bones file */ make_bones(); /* Handle retirement */ if (p_ptr->total_winner) kingly(); /* Save dead player */ if (!old_save()) { msg_print("death save failed!"); message_flush(); } /* Get time of death */ #ifdef _WIN32_WCE { unsigned long fake_time(unsigned long *fake_time_t); fake_time(&death_time); } #else (void) time(&death_time); #endif /* You are dead */ print_tomb(); /* Hack - Know everything upon death */ death_knowledge(); /* Enter player in high score list */ enter_score(&death_time); /* Flush all input keys */ flush(); /* Flush messages */ msg_print(NULL); 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? ")); }
static void visuals_reset(const char *title, int row) { /* Reset */ reset_visuals(true); /* Message */ prt("", 0, 0); msg("Visual attr/char tables reset."); message_flush(); }
/* * Save the screen, and increase the "icky" depth. * * This function must match exactly one call to "screen_load()". */ void screen_save(void) { /* Hack -- Flush messages */ message_flush(); /* Save the screen (if legal) */ Term_save(); /* Increase "icky" depth */ character_icky++; }
/* * Load the screen, and decrease the "icky" depth. * * This function must match exactly one call to "screen_save()". */ void screen_load(void) { /* Hack -- Flush messages */ message_flush(); /* Load the screen */ Term_load(); /* Decrease "icky" depth */ character_icky--; }
static void keymap_browse_hook(int oid, void *db, const region *loc) { char tmp[1024]; message_flush(); clear_from(13); /* Show current action */ prt("Current action (if any) shown below:", 13, 0); keypress_to_text(tmp, sizeof(tmp), keymap_buffer, false); prt(tmp, 14, 0); }
static void spoiler_menu_act(const char *title, int row) { if (row == 0) spoil_obj_desc("obj-desc.spo"); else if (row == 1) spoil_artifact("artifact.spo"); else if (row == 2) spoil_mon_desc("mon-desc.spo"); else if (row == 3) spoil_mon_info("mon-info.spo"); 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) { /* Handle stuff */ handle_stuff(p_ptr); /* Flush the messages */ message_flush(); /* Flush the input */ flush(); /* No suspending now */ signals_ignore_tstp(); /* Hack -- Increase "icky" depth */ character_icky++; /* Handle death */ if (p_ptr->is_dead) { death_screen(); } /* Still alive */ 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 */ character_icky--; /* Allow suspending now */ signals_handle_tstp(); }
/* * Ask the user to respond with a character. Options is a constant string, * e.g. "yns"; len is the length of the constant string, and fallback should * be the default answer if the user hits escape or an invalid key. * * Example: get_char("Study? ", "yns", 3, 'n') * This prompts "Study? [yns]" and defaults to 'n'. * */ char get_char(const char *prompt, const char *options, size_t len, char fallback) { size_t i; struct keypress key; char button[4], buf[80]; bool repeat = FALSE; /* Paranoia XXX XXX XXX */ message_flush(); /* Hack -- Build a "useful" prompt */ strnfmt(buf, 78, "%.70s[%s] ", prompt, options); /* Hack - kill the repeat button */ if (button_kill('n')) repeat = TRUE; /* Make some buttons */ for (i = 0; i < len; i++) { strnfmt(button, 4, "[%c]", options[i]); button_add(button, options[i]); } redraw_stuff(p_ptr); /* Prompt for it */ prt(buf, 0, 0); /* Get an acceptable answer */ key = inkey(); /* Lowercase answer if necessary */ if (key.code >= 'A' && key.code <= 'Z') key.code += 32; /* See if key is in our options string */ if (!strchr(options, (char)key.code)) key.code = fallback; /* Kill the buttons */ for (i = 0; i < len; i++) button_kill(options[i]); /* Hack - restore the repeat button */ if (repeat) button_add("[Rpt]", 'n'); redraw_stuff(p_ptr); /* Erase the prompt */ prt("", 0, 0); /* Success */ return key.code; }
/* * Load the screen, and decrease the "icky" depth. * * This function must match exactly one call to "screen_save()". */ void screen_load(void) { /* Hack -- Flush messages */ message_flush(); /* Load the screen (if legal) */ Term_load(); /* Decrease "icky" depth */ character_icky--; /* Mega hack -redraw big graphics - sorry NRM */ if (character_icky == 0 && (tile_width > 1 || tile_height > 1)) Term_redraw(); }
/* * Display a parser error message. */ static void display_parse_error(cptr filename, errr err, cptr buf) { cptr oops; /* Error string */ oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown"); /* Oops */ msg_format("Error at line %d of '%s.txt'.", error_line, filename); msg_format("Record %d contains a '%s' error.", error_idx, oops); msg_format("Parsing '%s'.", buf); message_flush(); /* Quit */ quit_fmt("Error in '%s.txt' file.", filename); }
/* * Verify something with the user * * The "prompt" should take the form "Query? " * * Note that "[y/n]" is appended to the prompt. */ bool get_check(const char *prompt) { //struct keypress ke; ui_event ke; char buf[80]; bool repeat = FALSE; /* Paranoia XXX XXX XXX */ message_flush(); /* Hack -- Build a "useful" prompt */ strnfmt(buf, 78, "%.70s[y/n] ", prompt); /* Hack - kill the repeat button */ if (button_kill('n')) repeat = TRUE; /* Make some buttons */ button_add("[y]", 'y'); button_add("[n]", 'n'); redraw_stuff(p_ptr); /* Prompt for it */ prt(buf, 0, 0); ke = inkey_m(); /* Kill the buttons */ button_kill('y'); button_kill('n'); /* Hack - restore the repeat button */ if (repeat) button_add("[Rpt]", 'n'); redraw_stuff(p_ptr); /* Erase the prompt */ prt("", 0, 0); /* Normal negation */ if (ke.type == EVT_MOUSE) { if ((ke.mouse.button != 1) && (ke.mouse.y != 0)) return (FALSE); } else if ((ke.key.code != 'Y') && (ke.key.code != 'y')) return (FALSE); /* Success */ return (TRUE); }
/* * Hack -- describe the given monster race at the top of the screen */ void screen_roff(int r_idx) { /* Flush messages */ message_flush(); /* Begin recall */ Term_erase(0, 1, 255); /* Output to the screen */ text_out_hook = text_out_to_screen; /* Recall monster */ describe_monster(r_idx, FALSE); /* Describe monster */ roff_top(r_idx); }
/* * Save the game */ void save_game(void) { /* Disturb the player */ disturb(1, 0); /* Clear messages */ message_flush(); /* Handle stuff */ handle_stuff(); /* 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 (old_save()) { prt("Saving game... done.", 0, 0); } /* Save failed (oops) */ 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)); }
/* * Hack -- describe the given monster race at the top of the screen */ void screen_roff(const int r_idx, const monster_lore *l_ptr) { monster_race *r_ptr = &r_info[r_idx]; /* Flush messages */ message_flush(); /* Begin recall */ Term_erase(0, 1, 255); /* Output to the screen */ text_out_hook = text_out_to_screen; /* Recall monster */ describe_monster_race(r_ptr, l_ptr, FALSE); /* Describe monster */ roff_top(r_idx, 0); }
/* * Prompt for a string from the user. * * The "prompt" should take the form "Prompt: ". * * See "askfor_aux" for some notes about "buf" and "len", and about * the return value of this function. */ bool get_string(const char *prompt, char *buf, size_t len) { bool res; /* Paranoia XXX XXX XXX */ message_flush(); /* Display prompt */ prt(prompt, 0, 0); /* Ask the user for a string */ res = askfor_aux(buf, len, NULL); /* Clear prompt */ prt("", 0, 0); /* Result */ return (res); }
/* * Verify something with the user * * The "prompt" should take the form "Query? " * * Note that "[y/n]" is appended to the prompt. */ static bool get_check_base(bool def, bool esc, cptr prompt) { int i; /* Do not skip */ p_ptr->state.skip_more = FALSE; /* Paranoia XXX XXX XXX */ message_flush(); /* Prompt for it */ prtf(0, 0, "%.70s[y/n] ", prompt); /* Get an acceptable answer */ while (TRUE) { i = inkey(); if (quick_messages) break; if (i == ESCAPE) break; if (strchr("YyNn\n\r", i)) break; bell("Illegal response to a 'yes/no' question!"); } /* Erase the prompt */ clear_msg(); /* Success? */ switch (i) { case 'y': case 'Y': return (TRUE); case ESCAPE: return (esc); case '\n': case '\r': return (def); default: return (FALSE); } }
/* * Prompts for a keypress * * The "prompt" should take the form "Command: " * * Returns TRUE unless the character is "Escape" */ bool get_com(cptr prompt, char *command) { /* Paranoia XXX XXX XXX */ message_flush(); /* Display a prompt */ prtf(0, 0, prompt); /* Get a key */ *command = inkey(); /* Clear the prompt */ clear_msg(); /* Handle "cancel" */ if (*command == ESCAPE) return (FALSE); /* Success */ return (TRUE); }
/* * Verify use of "debug" mode */ void do_cmd_try_debug(void) { /* Ask first time */ if (!(p_ptr->noscore & NOSCORE_DEBUG)) { /* Mention effects */ msg("You are about to use the dangerous, unsupported, debug commands!"); msg("Your machine may crash, and your savefile may become corrupted!"); message_flush(); /* Verify request */ if (!get_check("Are you sure you want to use the debug commands? ")) return; /* Mark savefile */ p_ptr->noscore |= NOSCORE_DEBUG; } /* Okay */ do_cmd_debug(); }
void textui_obj_inscribe(object_type *o_ptr, int item) { char o_name[80]; char tmp[80] = ""; object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_FULL); msg_format("Inscribing %s.", o_name); message_flush(); /* Use old inscription */ if (o_ptr->note) strnfmt(tmp, sizeof(tmp), "%s", quark_str(o_ptr->note)); /* Get a new inscription (possibly empty) */ if (get_string("Inscription: ", tmp, sizeof(tmp))) { cmd_insert(CMD_INSCRIBE); cmd_set_arg_item(cmd_get_top(), 0, item); cmd_set_arg_string(cmd_get_top(), 1, tmp); } }
/* * Prompt for a string from the user. * * The "prompt" should take the form "Prompt: ". * * See "askfor_aux" for some notes about "buf" and "len", and about * the return value of this function. */ bool get_string(const char *prompt, char *buf, size_t len) { bool res; /* Paranoia XXX XXX XXX */ message_flush(); /* Display prompt */ prt(prompt, 0, 0); /* Ask the user for a string */ res = askfor_aux(buf, len, NULL); /* Translate it to 8-bit (Latin-1) */ xstr_trans(buf, LATIN1); /* Clear prompt */ prt("", 0, 0); /* Result */ return (res); }