From e3df7d8ebda36542c477beba281dfc3f9c737af4 Mon Sep 17 00:00:00 2001 From: gumi Date: Wed, 10 Oct 2018 16:23:19 -0400 Subject: bake buildin_prompt into buildin_select and clarify the difference between the two --- src/map/script.c | 98 +++++++------------------------------------------------- src/map/script.h | 2 ++ 2 files changed, 13 insertions(+), 87 deletions(-) (limited to 'src/map') diff --git a/src/map/script.c b/src/map/script.c index 5eed58977..9682fea40 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -6216,103 +6216,27 @@ static BUILDIN(select) ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu); script->reportsrc(st); } - } else if( sd->npc_menu == 0xff ) {// Cancel was pressed + } else if(sd->npc_menu == 0xff) { // Cancel was pressed sd->state.menu_or_input = 0; - st->state = END; - } else {// return selected option - int menu = 0; - - sd->state.menu_or_input = 0; - for( i = 2; i <= script_lastdata(st); ++i ) { - text = script_getstr(st, i); - sd->npc_menu -= script->menu_countoptions(text, sd->npc_menu, &menu); - if( sd->npc_menu <= 0 ) - break;// entry found - } - pc->setreg(sd, script->add_variable("@menu"), menu); - script_pushint(st, menu); - st->state = RUN; - } - return true; -} -/// Displays a menu with options and returns the selected option. -/// Behaves like 'menu' without the target labels, except when cancel is -/// pressed. -/// When cancel is pressed, the script continues and 255 is returned. -/// -/// prompt({,,...}) -> -/// -/// @see menu -static BUILDIN(prompt) -{ - int i; - const char *text; - struct map_session_data *sd = script->rid2sd(st); - if (sd == NULL) - return true; - -#ifdef SECURE_NPCTIMEOUT - sd->npc_idle_type = NPCT_MENU; -#endif - - if( sd->state.menu_or_input == 0 ) - { - struct StringBuf buf; - - StrBuf->Init(&buf); - sd->npc_menu = 0; - for( i = 2; i <= script_lastdata(st); ++i ) - { - text = script_getstr(st, i); - if( sd->npc_menu > 0 ) - StrBuf->AppendStr(&buf, ":"); - StrBuf->AppendStr(&buf, text); - sd->npc_menu += script->menu_countoptions(text, 0, NULL); - } - - st->state = RERUNLINE; - sd->state.menu_or_input = 1; - - /* menus beyond this length crash the client (see bugreport:6402) */ - if( StrBuf->Length(&buf) >= 2047 ) { - struct npc_data * nd = map->id2nd(st->oid); - char* menu; - CREATE(menu, char, 2048); - safestrncpy(menu, StrBuf->Value(&buf), 2047); - ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StrBuf->Length(&buf)); - clif->scriptmenu(sd, st->oid, menu); - aFree(menu); - } else - clif->scriptmenu(sd, st->oid, StrBuf->Value(&buf)); - StrBuf->Destroy(&buf); - - if( sd->npc_menu >= 0xff ) - { - ShowWarning("buildin_prompt: Too many options specified (current=%d, max=254).\n", sd->npc_menu); - script->reportsrc(st); + if (strncmp(get_buildin_name(st), "prompt", 6) == 0) { + pc->setreg(sd, script->add_variable("@menu"), 0xff); + script_pushint(st, 0xff); + st->state = RUN; + } else { + st->state = END; } - } - else if( sd->npc_menu == 0xff ) - {// Cancel was pressed - sd->state.menu_or_input = 0; - pc->setreg(sd, script->add_variable("@menu"), 0xff); - script_pushint(st, 0xff); - st->state = RUN; - } - else - {// return selected option + } else {// return selected option int menu = 0; sd->state.menu_or_input = 0; - for( i = 2; i <= script_lastdata(st); ++i ) - { + for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); sd->npc_menu -= script->menu_countoptions(text, sd->npc_menu, &menu); if( sd->npc_menu <= 0 ) break;// entry found } - pc->setreg(sd, script->add_variable("@menu"), menu); + pc->setreg(sd, script->add_variable("@menu"), menu); // TODO: throw a deprecation warning for scripts using @menu script_pushint(st, menu); st->state = RUN; } @@ -24978,7 +24902,7 @@ static void script_parse_builtin(void) BUILDIN_DEF(close2,""), BUILDIN_DEF(menu,"sl*"), BUILDIN_DEF(select,"s*"), //for future jA script compatibility - BUILDIN_DEF(prompt,"s*"), + BUILDIN_DEF2(select, "prompt", "s*"), // BUILDIN_DEF(goto,"l"), BUILDIN_DEF(callsub,"l*"), diff --git a/src/map/script.h b/src/map/script.h index 9c72b793c..f05eb802c 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -177,6 +177,8 @@ struct item_data; #define BUILDIN(x) bool buildin_ ## x (struct script_state* st) +#define get_buildin_name(st) ( script->get_str((int)(script_getdata((st), 0)->u.num)) ) + #define script_fetch(st, n, t) do { \ if( script_hasdata((st),(n)) ) \ (t)=script_getnum((st),(n)); \ -- cgit v1.2.3-60-g2f50 From 5c59f230d982a2e0201956a6f9f853253b9f3c5f Mon Sep 17 00:00:00 2001 From: gumi Date: Thu, 11 Oct 2018 18:24:20 -0400 Subject: add constants for max menu length and options --- doc/script_commands.txt | 6 ++++-- src/map/clif.c | 2 +- src/map/script.c | 30 ++++++++++++++++-------------- src/map/script.h | 3 +++ 4 files changed, 24 insertions(+), 17 deletions(-) (limited to 'src/map') diff --git a/doc/script_commands.txt b/doc/script_commands.txt index aa7141951..98bc7b0e5 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -714,6 +714,8 @@ MAX_BANK_ZENY - Maximum Zeny in the bank MAX_BG_MEMBERS - Maximum BattleGround members MAX_CHAT_USERS - Maximum Chat users MAX_REFINE - Maximum Refine level +MAX_MENU_OPTIONS - Maximum NPC menu options +MAX_MENU_LENGTH - Maximum NPC menu string length Send targets and status options are also hard-coded and can be found in 'doc/constants.md'. @@ -1616,8 +1618,8 @@ and empty options. *prompt("