Add a history menu for wizwish

Use the 'm' Prefix to make wizwish show the history menu.
Also entries wished via WIZKIT are added to the history.

While debugging, I often need to wish the same thing multiple
times, and typing or pasting it with mouse is annoying...
This commit is contained in:
Pasi Kallinen
2026-03-25 13:46:03 +02:00
parent 41b2087436
commit f8bd79354c
7 changed files with 93 additions and 3 deletions

View File

@@ -1996,7 +1996,7 @@ struct ext_func_tab extcmdlist[] = {
{ '\0', "wizwhere", "show locations of special levels",
wiz_where, IFBURIED | AUTOCOMPLETE | WIZMODECMD, NULL },
{ C('w'), "wizwish", "wish for something",
wiz_wish, IFBURIED | WIZMODECMD, NULL },
wiz_wish, IFBURIED | CMD_M_PREFIX | WIZMODECMD, NULL },
{ '\0', "wmode", "show wall modes",
wiz_show_wmodes, IFBURIED | AUTOCOMPLETE | WIZMODECMD, NULL },
{ 'z', "zap", "zap a wand",

View File

@@ -2546,8 +2546,10 @@ proc_wizkit_line(char *buf)
otmp = readobjnam(buf, (struct obj *) 0);
if (otmp) {
if (otmp != &hands_obj)
if (otmp != &hands_obj) {
wish_history_add(buf);
wizkit_addinv(otmp);
}
} else {
/* .60 limits output line width to 79 chars */
config_error_add("Bad wizkit item: \"%.60s\"", buf);

View File

@@ -40,6 +40,7 @@ staticfn int maybe_destroy_item(struct monst *, struct obj *, int) NONNULLPTRS;
staticfn boolean destroyable(struct obj *, int);
staticfn void wishcmdassist(int);
staticfn void wish_history_menu(char *);
#define ZT_MAGIC_MISSILE (AD_MAGM - 1)
#define ZT_FIRE (AD_FIRE - 1)
@@ -6210,6 +6211,81 @@ wishcmdassist(int triesleft)
destroy_nhwindow(win);
}
#define MAX_WISH_HISTORY 20
static char *wish_history[MAX_WISH_HISTORY] = { NULL };
static int wish_history_idx = 0;
/* add string to wish history list */
void
wish_history_add(char *buf)
{
#ifdef DEBUG
int i;
if (!wizard)
return;
for (i = 0; i < MAX_WISH_HISTORY; i++) {
int idx = (wish_history_idx + i) % MAX_WISH_HISTORY;
if (!wish_history[idx])
continue;
if (!strncmpi(wish_history[idx], buf, strlen(wish_history[idx])))
break;
}
if (i == MAX_WISH_HISTORY) {
int idx = (wish_history_idx + i) % MAX_WISH_HISTORY;
if (wish_history[idx])
free(wish_history[idx]);
wish_history[idx] = (char *)alloc(strlen(buf) + 1);
strcpy(wish_history[idx], buf);
wish_history_idx = (wish_history_idx + 1) % MAX_WISH_HISTORY;
}
#endif /* DEBUG */
}
/* shows menu of previous wishes, copies selected into buf, max BUFSZ len.
buf is not modified, if nothing was selected. */
staticfn void
wish_history_menu(char *buf)
{
#ifdef DEBUG
winid win;
anything any;
int i = 0, npick;
menu_item *picks = (menu_item *) 0;
int idx;
win = create_nhwindow(NHW_MENU);
start_menu(win, MENU_BEHAVE_STANDARD);
any = cg.zeroany;
for (i = MAX_WISH_HISTORY-1; i >= 0; i--) {
idx = (wish_history_idx + i) % MAX_WISH_HISTORY;
if (wish_history[idx]) {
any.a_int = (i + 1);
add_menu(win, &nul_glyphinfo, &any, '\0', 0, ATR_NONE, NO_COLOR,
wish_history[idx], MENU_ITEMFLAGS_NONE);
}
}
end_menu(win, "Wish what?");
npick = select_menu(win, PICK_ONE, &picks);
destroy_nhwindow(win);
if (npick > 0) {
i = picks->item.a_int;
i--;
idx = (wish_history_idx + i) % MAX_WISH_HISTORY;
if (wish_history[idx])
strcpy(buf, wish_history[idx]);
}
#endif /* DEBUG */
}
RESTORE_WARNING_FORMAT_NONLITERAL
void
@@ -6232,7 +6308,11 @@ makewish(void)
if (iflags.cmdassist && tries > 0)
Strcat(promptbuf, " (enter 'help' for assistance)");
Strcat(promptbuf, "?");
getlin(promptbuf, buf);
if (iflags.menu_requested && wish_history[0] && (tries == 0))
wish_history_menu(buf);
else
getlin(promptbuf, buf);
if (iflags.term_gone) {
if (!iflags.debug_fuzzer)
@@ -6270,9 +6350,11 @@ makewish(void)
livelog_printf(LL_WISH, "declined to make a wish");
return;
} else if (otmp == &hands_obj) {
wish_history_add(bufcpy);
/* wizard mode terrain wish: skip livelogging, etc */
return;
}
wish_history_add(bufcpy);
if (otmp->oartifact) {
/* update artifact bookkeeping; doesn't produce a livelog event */