void wr_messages(void) { s16b i; u16b num; num = messages_num(); if (num > 80) num = 80; wr_u16b(num); /* Dump the messages (oldest first!) */ for (i = num - 1; i >= 0; i--) { wr_string(message_str(i)); wr_u16b(message_type(i)); } }
/** * Write a character dump */ void write_character_dump(ang_file *fff) { int i, x, y; int a; wchar_t c; struct store *home = &stores[STORE_HOME]; struct object **home_list = mem_zalloc(sizeof(struct object *) * z_info->store_inven_max); char o_name[80]; char buf[1024]; char *p; /* Begin dump */ file_putf(fff, " [%s Character Dump]\n\n", buildid); /* Display player */ display_player(0); /* Dump part of the screen */ for (y = 1; y < 23; y++) { p = buf; /* Dump each row */ for (x = 0; x < 79; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ file_putf(fff, "%s\n", buf); } /* Skip a line */ file_putf(fff, "\n"); /* Display player */ display_player(1); /* Dump part of the screen */ for (y = 11; y < 20; y++) { p = buf; /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ file_putf(fff, "%s\n", buf); } /* Skip a line */ file_putf(fff, "\n"); /* Dump part of the screen */ for (y = 11; y < 20; y++) { p = buf; /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x + 40, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ file_putf(fff, "%s\n", buf); } /* Skip some lines */ file_putf(fff, "\n\n"); /* If dead, dump last messages -- Prfnoff */ if (player->is_dead) { i = messages_num(); if (i > 15) i = 15; file_putf(fff, " [Last Messages]\n\n"); while (i-- > 0) { file_putf(fff, "> %s\n", message_str((s16b)i)); } file_putf(fff, "\nKilled by %s.\n\n", player->died_from); } /* Dump the equipment */ file_putf(fff, " [Character Equipment]\n\n"); for (i = 0; i < player->body.count; i++) { struct object *obj = slot_object(player, i); if (!obj) continue; object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL); file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name); object_info_chardump(fff, obj, 5, 72); } file_putf(fff, "\n\n"); /* Dump the inventory */ file_putf(fff, "\n\n [Character Inventory]\n\n"); for (i = 0; i < z_info->pack_size; i++) { struct object *obj = player->upkeep->inven[i]; if (!obj) break; object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL); file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name); object_info_chardump(fff, obj, 5, 72); } file_putf(fff, "\n\n"); /* Dump the quiver */ file_putf(fff, "\n\n [Character Quiver]\n\n"); for (i = 0; i < z_info->quiver_size; i++) { struct object *obj = player->upkeep->quiver[i]; if (!obj) continue; object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL); file_putf(fff, "%c) %s\n", gear_to_label(obj), o_name); object_info_chardump(fff, obj, 5, 72); } file_putf(fff, "\n\n"); /* Dump the Home -- if anything there */ store_stock_list(home, home_list, z_info->store_inven_max); if (home->stock_num) { /* Header */ file_putf(fff, " [Home Inventory]\n\n"); /* Dump all available items */ for (i = 0; i < z_info->store_inven_max; i++) { struct object *obj = home_list[i]; if (!obj) break; object_desc(o_name, sizeof(o_name), obj, ODESC_PREFIX | ODESC_FULL); file_putf(fff, "%c) %s\n", I2A(i), o_name); object_info_chardump(fff, obj, 5, 72); } /* Add an empty line */ file_putf(fff, "\n\n"); } /* Dump character history */ dump_history(fff); file_putf(fff, "\n\n"); /* Dump options */ file_putf(fff, " [Options]\n\n"); /* Dump options */ for (i = 0; i < OP_MAX; i++) { int opt; const char *title = ""; switch (i) { case OP_INTERFACE: title = "User interface"; break; case OP_BIRTH: title = "Birth"; break; default: continue; } file_putf(fff, " [%s]\n\n", title); for (opt = 0; opt < OPT_MAX; opt++) { if (option_type(opt) != i) continue; file_putf(fff, "%-45s: %s (%s)\n", option_desc(opt), player->opts.opt[opt] ? "yes" : "no ", option_name(opt)); } /* Skip some lines */ file_putf(fff, "\n"); } mem_free(home_list); }
/* * Show previous messages to the user * * The screen format uses line 0 and 23 for headers and prompts, * skips line 1 and 22, and uses line 2 thru 21 for old messages. * * This command shows you which commands you are viewing, and allows * you to "search" for strings in the recall. * * Note that messages may be longer than 80 characters, but they are * displayed using "infinite" length, with a special sub-command to * "slide" the virtual display to the left or right. * * Attempt to only highlight the matching portions of the string. */ void do_cmd_messages(void) { ui_event ke; bool more = TRUE; int i, j, n, q; int wid, hgt; char shower[80] = ""; /* Total messages */ n = messages_num(); /* Start on first message */ i = 0; /* Start at leftmost edge */ q = 0; /* Get size */ Term_get_size(&wid, &hgt); /* Save screen */ screen_save(); /* Process requests until done */ while (more) { /* Clear screen */ Term_clear(); /* Dump messages */ for (j = 0; (j < hgt - 4) && (i + j < n); j++) { const char *msg; const char *str = message_str(i + j); byte attr = message_color(i + j); u16b count = message_count(i + j); if (count == 1) msg = str; else msg = format("%s <%dx>", str, count); /* Apply horizontal scroll */ msg = ((int)strlen(msg) >= q) ? (msg + q) : ""; /* Dump the messages, bottom to top */ Term_putstr(0, hgt - 3 - j, -1, attr, msg); /* Highlight "shower" */ if (shower[0]) { str = msg; /* Display matches */ while ((str = my_stristr(str, shower)) != NULL) { int len = strlen(shower); /* Display the match */ Term_putstr(str-msg, hgt - 3 - j, len, TERM_YELLOW, str); /* Advance */ str += len; } } } /* Display header */ prt(format("Message recall (%d-%d of %d), offset %d", i, i + j - 1, n, q), 0, 0); /* Display prompt (not very informative) */ if (shower[0]) prt("[Movement keys to navigate, '-' for next, '=' to find]", hgt - 1, 0); else prt("[Movement keys to navigate, '=' to find, or ESCAPE to exit]", hgt - 1, 0); /* Get a command */ ke = inkey_ex(); /* Scroll forwards or backwards using mouse clicks */ if (ke.type == EVT_MOUSE) { if (ke.mouse.y <= hgt / 2) { /* Go older if legal */ if (i + 20 < n) i += 20; } else { /* Go newer */ i = (i >= 20) ? (i - 20) : 0; } } else if (ke.type == EVT_KBRD) { switch (ke.key.code) { case ESCAPE: { more = FALSE; break; } case '=': { /* Get the string to find */ prt("Find: ", hgt - 1, 0); if (!askfor_aux(shower, sizeof shower, NULL)) continue; /* Set to find */ ke.key.code = '-'; break; } case ARROW_LEFT: case '4': q = (q >= wid / 2) ? (q - wid / 2) : 0; break; case ARROW_RIGHT: case '6': q = q + wid / 2; break; case ARROW_UP: case '8': if (i + 1 < n) i += 1; break; case ARROW_DOWN: case '2': case '\r': case '\n': i = (i >= 1) ? (i - 1) : 0; break; case KC_PGUP: case 'p': case ' ': if (i + 20 < n) i += 20; break; case KC_PGDOWN: case 'n': i = (i >= 20) ? (i - 20) : 0; break; } } /* Find the next item */ if (ke.key.code == '-' && shower[0]) { s16b z; /* Scan messages */ for (z = i + 1; z < n; z++) { /* Search for it */ if (my_stristr(message_str(z), shower)) { /* New location */ i = z; /* Done */ break; } } } } /* Load screen */ screen_load(); }
/* * Hack -- Dump a character description file * * XXX XXX XXX Allow the "full" flag to dump additional info, * and trigger its usage from various places in the code. */ errr file_character(const char *path, bool full) { int i, x, y; int a; wchar_t c; ang_file *fp; struct store *st_ptr = &stores[STORE_HOME]; char o_name[80]; char buf[1024]; char *p; /* Unused parameter */ (void)full; /* Open the file for writing */ fp = file_open(path, MODE_WRITE, FTYPE_TEXT); if (!fp) return (-1); /* Begin dump */ file_putf(fp, " [%s Character Dump]\n\n", buildid); /* Display player */ display_player(0); /* Dump part of the screen */ for (y = 1; y < 23; y++) { p = buf; /* Dump each row */ for (x = 0; x < 79; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ x_file_putf(fp, "%s\n", buf); } /* Skip a line */ file_putf(fp, "\n"); /* Display player */ display_player(1); /* Dump part of the screen */ for (y = 11; y < 20; y++) { p = buf; /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ x_file_putf(fp, "%s\n", buf); } /* Skip a line */ file_putf(fp, "\n"); /* Dump part of the screen */ for (y = 11; y < 20; y++) { p = buf; /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x + 40, y, &a, &c)); /* Dump it */ p += wctomb(p, c); } /* Back up over spaces */ while ((p > buf) && (p[-1] == ' ')) --p; /* Terminate */ *p = '\0'; /* End the row */ x_file_putf(fp, "%s\n", buf); } /* Skip some lines */ file_putf(fp, "\n\n"); /* If dead, dump last messages -- Prfnoff */ if (p_ptr->is_dead) { i = messages_num(); if (i > 15) i = 15; file_putf(fp, " [Last Messages]\n\n"); while (i-- > 0) { x_file_putf(fp, "> %s\n", message_str((s16b)i)); } x_file_putf(fp, "\nKilled by %s.\n\n", p_ptr->died_from); } /* Dump the equipment */ file_putf(fp, " [Character Equipment]\n\n"); for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++) { if (i == INVEN_TOTAL) { file_putf(fp, "\n\n [Character Quiver]\n\n"); continue; } object_desc(o_name, sizeof(o_name), &p_ptr->inventory[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, "%c) %s\n", index_to_label(i), o_name); if (p_ptr->inventory[i].kind) object_info_chardump(fp, &p_ptr->inventory[i], 5, 72); } /* Dump the inventory */ file_putf(fp, "\n\n [Character Inventory]\n\n"); for (i = 0; i < INVEN_PACK; i++) { if (!p_ptr->inventory[i].kind) break; object_desc(o_name, sizeof(o_name), &p_ptr->inventory[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, "%c) %s\n", index_to_label(i), o_name); object_info_chardump(fp, &p_ptr->inventory[i], 5, 72); } file_putf(fp, "\n\n"); /* Dump the Home -- if anything there */ if (st_ptr->stock_num) { /* Header */ file_putf(fp, " [Home Inventory]\n\n"); /* Dump all available items */ for (i = 0; i < st_ptr->stock_num; i++) { object_desc(o_name, sizeof(o_name), &st_ptr->stock[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, "%c) %s\n", I2A(i), o_name); object_info_chardump(fp, &st_ptr->stock[i], 5, 72); } /* Add an empty line */ file_putf(fp, "\n\n"); } /* Dump character history */ dump_history(fp); file_putf(fp, "\n\n"); /* Dump options */ file_putf(fp, " [Options]\n\n"); /* Dump options */ for (i = 0; i < OPT_PAGE_MAX - 1; i++) { int j; const char *title = ""; switch (i) { case 0: title = "Interface"; break; case 1: title = "Warning"; break; case 2: title = "Birth"; break; } file_putf(fp, " [%s]\n\n", title); for (j = 0; j < OPT_PAGE_PER; j++) { int opt = option_page[i][j]; if (!option_name(opt)) continue; file_putf(fp, "%-45s: %s (%s)\n", option_desc(opt), op_ptr->opt[opt] ? "yes" : "no ", option_name(opt)); } /* Skip some lines */ file_putf(fp, "\n"); } file_close(fp); /* Success */ return (0); }
/* * Hack -- Dump a character description file * * XXX XXX XXX Allow the "full" flag to dump additional info, * and trigger its usage from various places in the code. */ errr file_character(const char *path, bool full) { int i, x, y; byte a; char c; ang_file *fp; struct store *st_ptr = &stores[STORE_HOME]; char o_name[80]; byte (*old_xchar_hook)(byte c) = Term.xchar_hook; char buf[1024]; /* We use either ascii or system-specific encoding */ int encoding = OPT(xchars_to_file) ? SYSTEM_SPECIFIC : ASCII; /* Unused parameter */ (void)full; /* Open the file for writing */ fp = file_open(path, MODE_WRITE, FTYPE_TEXT); if (!fp) return (-1); /* Display the requested encoding -- ASCII or system-specific */ if (!OPT(xchars_to_file)) Term.xchar_hook = null; /* Begin dump */ file_putf(fp, " [%s Character Dump]\n\n", buildid); /* Display player */ display_player(0); /* Dump part of the screen */ for (y = 1; y < 23; y++) { /* Dump each row */ for (x = 0; x < 79; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ buf[x] = c; } /* Back up over spaces */ while ((x > 0) && (buf[x-1] == ' ')) --x; /* Terminate */ buf[x] = '\0'; /* End the row */ x_file_putf(fp, encoding, "%s\n", buf); } /* Skip a line */ file_putf(fp, "\n"); /* Display player */ display_player(1); /* Dump part of the screen */ for (y = 11; y < 20; y++) { /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Dump it */ buf[x] = c; } /* Back up over spaces */ while ((x > 0) && (buf[x-1] == ' ')) --x; /* Terminate */ buf[x] = '\0'; /* End the row */ x_file_putf(fp, encoding, "%s\n", buf); } /* Skip a line */ file_putf(fp, "\n"); /* Dump part of the screen */ for (y = 11; y < 20; y++) { /* Dump each row */ for (x = 0; x < 39; x++) { /* Get the attr/char */ (void)(Term_what(x + 40, y, &a, &c)); /* Dump it */ buf[x] = c; } /* Back up over spaces */ while ((x > 0) && (buf[x-1] == ' ')) --x; /* Terminate */ buf[x] = '\0'; /* End the row */ x_file_putf(fp, encoding, "%s\n", buf); } /* Skip some lines */ file_putf(fp, "\n\n"); /* If dead, dump last messages -- Prfnoff */ if (p_ptr.is_dead) { i = messages_num(); if (i > 15) i = 15; file_putf(fp, " [Last Messages]\n\n"); while (i-- > 0) { x_file_putf(fp, encoding, "> %s\n", message_str((s16b)i)); } x_file_putf(fp, encoding, "\nKilled by %s.\n\n", p_ptr.died_from); } /* Dump the equipment */ file_putf(fp, " [Character Equipment]\n\n"); for (i = INVEN_WIELD; i < ALL_INVEN_TOTAL; i++) { if (i == INVEN_TOTAL) { file_putf(fp, "\n\n [Character Quiver]\n\n"); continue; } object_desc(o_name, sizeof(o_name), &p_ptr.inventory[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, encoding, "%c) %s\n", index_to_label(i), o_name); if (p_ptr.inventory[i].kind) object_info_chardump(fp, &p_ptr.inventory[i], 5, 72); } /* Dump the inventory */ file_putf(fp, "\n\n [Character Inventory]\n\n"); for (i = 0; i < INVEN_PACK; i++) { if (!p_ptr.inventory[i].kind) break; object_desc(o_name, sizeof(o_name), &p_ptr.inventory[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, encoding, "%c) %s\n", index_to_label(i), o_name); object_info_chardump(fp, &p_ptr.inventory[i], 5, 72); } file_putf(fp, "\n\n"); /* Dump the Home -- if anything there */ if (st_ptr.stock_num) { /* Header */ file_putf(fp, " [Home Inventory]\n\n"); /* Dump all available items */ for (i = 0; i < st_ptr.stock_num; i++) { object_desc(o_name, sizeof(o_name), &st_ptr.stock[i], ODESC_PREFIX | ODESC_FULL); x_file_putf(fp, encoding, "%c) %s\n", I2A(i), o_name); object_info_chardump(fp, &st_ptr.stock[i], 5, 72); } /* Add an empty line */ file_putf(fp, "\n\n"); } /* Dump character history */ dump_history(fp); file_putf(fp, "\n\n"); /* Dump options */ file_putf(fp, " [Options]\n\n"); /* Dump options */ for (i = OPT_BIRTH; i < OPT_BIRTH + N_OPTS_BIRTH; i++) { if (option_name(i)) { file_putf(fp, "%-45s: %s (%s)\n", option_desc(i), op_ptr.opt[i] ? "yes" : "no ", option_name(i)); } } /* Skip some lines */ file_putf(fp, "\n\n"); /* Return to standard display */ Term.xchar_hook = old_xchar_hook; file_close(fp); /* Success */ return (0); }
/** * Show previous messages to the user * * The screen format uses line 0 and 23 for headers and prompts, * skips line 1 and 22, and uses line 2 thru 21 for old messages. * * This command shows you which commands you are viewing, and allows * you to "search" for strings in the recall. * * Note that messages may be longer than 80 characters, but they are * displayed using "infinite" length, with a special sub-command to * "slide" the virtual display to the left or right. * * Attempt to only hilight the matching portions of the string. */ void do_cmd_messages(void) { ui_event ke; int i, j, n, q; int wid, hgt; char shower[80]; char finder[80]; char p[80]; /* Wipe finder */ my_strcpy(finder, "", sizeof(shower)); /* Wipe shower */ my_strcpy(shower, "", sizeof(finder)); /* Total messages */ n = messages_num(); /* Start on first message */ i = 0; /* Start at leftmost edge */ q = 0; /* Get size */ Term_get_size(&wid, &hgt); /* Prompt */ strncpy(p, "[Press 'p' for older, 'n' for newer, ..., or ESCAPE]", 80); /* Save screen */ screen_save(); /* Adjust the buttons */ button_backup_all(); button_kill_all(); button_add("ESC", ESCAPE); button_add("-", '-'); button_add("=", '='); button_add("/", '/'); button_add("p", 'p'); button_add("n", 'n'); button_add("+", '+'); button_add("->", '6'); button_add("<-", '4'); p_ptr->redraw |= (PR_BUTTONS); /* Process requests until done */ while (1) { /* Clear screen */ Term_clear(); /* Dump messages */ for (j = 0; (j < hgt - 4) && (i + j < n); j++) { const char *msg = message_str((s16b)(i+j)); byte attr = message_color((s16b)(i+j)); /* Apply horizontal scroll */ msg = ((int)strlen(msg) >= q) ? (msg + q) : ""; /* Dump the messages, bottom to top */ Term_putstr(0, hgt - 3 - j, -1, attr, msg); /* Hilight "shower" */ if (shower[0]) { const char *str = msg; /* Display matches */ while ((str = strstr(str, shower)) != NULL) { int len = strlen(shower); /* Display the match */ Term_putstr(str-msg, hgt - 3 - j, len, TERM_YELLOW, shower); /* Advance */ str += len; } } } /* Display header XXX XXX XXX */ prt(format("Message Recall (%d-%d of %d), Offset %d", i, i + j - 1, n, q), 0, 0); /* Display prompt (not very informative) */ prt(p, hgt - 1, 0); redraw_stuff(p_ptr); /* Get a command */ ke = inkey_ex(); /* Exit on Escape */ if (ke.key.code == ESCAPE) break; /* Hack -- Save the old index */ j = i; /* Horizontal scroll */ if (ke.key.code == '4') { /* Scroll left */ q = (q >= wid / 2) ? (q - wid / 2) : 0; /* Success */ continue; } /* Horizontal scroll */ if (ke.key.code == '6') { /* Scroll right */ q = q + wid / 2; /* Success */ continue; } /* Hack -- handle show */ if (ke.key.code == '=') { /* Prompt */ prt("Show: ", hgt - 1, 0); /* Get a "shower" string, or continue */ if (!askfor_aux(shower, sizeof shower, NULL)) continue; /* Okay */ continue; } /* Hack -- handle find */ if (ke.key.code == '/') { s16b z; /* Prompt */ prt("Find: ", hgt - 1, 0); /* Get a "finder" string, or continue */ if (!askfor_aux(finder, sizeof finder, NULL)) continue; /* Show it */ my_strcpy(shower, finder, sizeof(shower)); /* Scan messages */ for (z = i + 1; z < n; z++) { const char *msg = message_str(z); /* Search for it */ if (strstr(msg, finder)) { /* New location */ i = z; /* Done */ break; } } } /* Recall 20 older messages */ if ((ke.key.code == 'p') || (ke.key.code == KTRL('P')) || (ke.key.code == ' ')) { /* Go older if legal */ if (i + 20 < n) i += 20; } /* Recall 10 older messages */ if (ke.key.code == '+') { /* Go older if legal */ if (i + 10 < n) i += 10; } /* Recall 1 older message */ if ((ke.key.code == '8') || (ke.key.code == '\n') || (ke.key.code == '\r')) { /* Go older if legal */ if (i + 1 < n) i += 1; } /* Recall 20 newer messages */ if ((ke.key.code == 'n') || (ke.key.code == KTRL('N'))) { /* Go newer (if able) */ i = (i >= 20) ? (i - 20) : 0; } /* Recall 10 newer messages */ if (ke.key.code == '-') { /* Go newer (if able) */ i = (i >= 10) ? (i - 10) : 0; } /* Recall 1 newer messages */ if (ke.key.code == '2') { /* Go newer (if able) */ i = (i >= 1) ? (i - 1) : 0; } /* Scroll forwards or backwards using mouse clicks */ if (ke.mouse.button) { if (ke.mouse.y <= hgt / 2) { /* Go older if legal */ if (i + 20 < n) i += 20; } else { /* Go newer (if able) */ i = (i >= 20) ? (i - 20) : 0; } } /* Hack -- Error of some kind */ if (i == j) bell(NULL); } /* Adjust the buttons */ button_restore(); /* Load screen */ screen_load(); }