summaryrefslogtreecommitdiff
path: root/npc/functions/dynamic_menu.txt
diff options
context:
space:
mode:
Diffstat (limited to 'npc/functions/dynamic_menu.txt')
-rw-r--r--npc/functions/dynamic_menu.txt289
1 files changed, 289 insertions, 0 deletions
diff --git a/npc/functions/dynamic_menu.txt b/npc/functions/dynamic_menu.txt
new file mode 100644
index 00000000..29902bac
--- /dev/null
+++ b/npc/functions/dynamic_menu.txt
@@ -0,0 +1,289 @@
+
+function script DynamicItemMenu {
+set @items_nr, getarraysize(@items);
+if(@items_nr != getarraysize(@item_names$)) goto L_ArrayLengthMismatch;
+if(@default_choice$ == "") set @default_choice$, "Never mind.";
+goto L_pick_one_of_many_items;
+
+L_pick_one_of_many_items:
+ @c = 0;
+ @i = 0;
+
+ setarray @choice_n$, "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "";
+ goto L_pick_choice_loop;
+
+L_pick_choice_loop:
+ if (@i >= @items_nr)
+ goto L_choice_init_done;
+ @current = @items[@i];
+ @current_name$ = @item_names$[@i];
+ @current_index = @i;
+ @i = @i + 1;
+
+ if (countitem(@current) == 0)
+ goto L_pick_choice_loop;
+ @choice_v[@c] = @current;
+ @choice_n$[@c] = @current_name$;
+ @choice_i[@c] = @current_index;
+ @c = @c + 1;
+ goto L_pick_choice_loop;
+
+L_choice_init_done:
+ @choice_v[@c] = 0;
+ @choice_n$[@c] = @default_choice$;
+ @c = @c + 1;
+
+ if (@c < 10)
+ menu
+ @choice_n$[0], L_MenuItems,
+ @choice_n$[1], L_MenuItems,
+ @choice_n$[2], L_MenuItems,
+ @choice_n$[3], L_MenuItems,
+ @choice_n$[4], L_MenuItems,
+ @choice_n$[5], L_MenuItems,
+ @choice_n$[6], L_MenuItems,
+ @choice_n$[7], L_MenuItems,
+ @choice_n$[8], L_MenuItems,
+ @choice_n$[9], L_MenuItems;
+ goto L_MenuItems;
+
+L_MenuItems:
+ if (@c < 10)
+ goto L_choice_join;
+
+ if (@c < 20)
+ menu
+ @choice_n$[0], L_MenuItems1,
+ @choice_n$[1], L_MenuItems1,
+ @choice_n$[2], L_MenuItems1,
+ @choice_n$[3], L_MenuItems1,
+ @choice_n$[4], L_MenuItems1,
+ @choice_n$[5], L_MenuItems1,
+ @choice_n$[6], L_MenuItems1,
+ @choice_n$[7], L_MenuItems1,
+ @choice_n$[8], L_MenuItems1,
+ @choice_n$[9], L_MenuItems1,
+ @choice_n$[10], L_MenuItems1,
+ @choice_n$[11], L_MenuItems1,
+ @choice_n$[12], L_MenuItems1,
+ @choice_n$[13], L_MenuItems1,
+ @choice_n$[14], L_MenuItems1,
+ @choice_n$[15], L_MenuItems1,
+ @choice_n$[16], L_MenuItems1,
+ @choice_n$[17], L_MenuItems1,
+ @choice_n$[18], L_MenuItems1,
+ @choice_n$[19], L_MenuItems1;
+ goto L_MenuItems1;
+
+L_MenuItems1:
+ if (@c < 20)
+ goto L_choice_join;
+
+ menu
+ @choice_n$[0], L_choice_join,
+ @choice_n$[1], L_choice_join,
+ @choice_n$[2], L_choice_join,
+ @choice_n$[3], L_choice_join,
+ @choice_n$[4], L_choice_join,
+ @choice_n$[5], L_choice_join,
+ @choice_n$[6], L_choice_join,
+ @choice_n$[7], L_choice_join,
+ @choice_n$[8], L_choice_join,
+ @choice_n$[9], L_choice_join,
+ @choice_n$[10], L_choice_join,
+ @choice_n$[11], L_choice_join,
+ @choice_n$[12], L_choice_join,
+ @choice_n$[13], L_choice_join,
+ @choice_n$[14], L_choice_join,
+ @choice_n$[15], L_choice_join,
+ @choice_n$[16], L_choice_join,
+ @choice_n$[17], L_choice_join,
+ @choice_n$[18], L_choice_join,
+ @choice_n$[19], L_choice_join,
+ @choice_n$[20], L_choice_join,
+ @choice_n$[21], L_choice_join,
+ @choice_n$[22], L_choice_join,
+ @choice_n$[23], L_choice_join,
+ @choice_n$[24], L_choice_join,
+ @choice_n$[25], L_choice_join,
+ @choice_n$[26], L_choice_join,
+ @choice_n$[27], L_choice_join,
+ @choice_n$[28], L_choice_join,
+ @choice_n$[29], L_choice_join,
+ @choice_n$[30], L_choice_join,
+ @choice_n$[31], L_choice_join;
+
+L_choice_join:
+ @menu = @menu - 1;
+ @item = @choice_v[@menu];
+ @index = @choice_i[@menu];
+ if (@menu >= @c)
+ @item = 0;
+ goto L_Clean;
+
+L_Clean:
+ @menu = 0;
+ @items_nr = 0;
+ @c = 0;
+ @i = 0;
+ @current = 0;
+ @current_name$ = "";
+ cleararray @choice_v, 0, getarraysize(@choice_v);
+ cleararray @choice_n$, "", getarraysize(@choice_n$);
+ cleararray @choice_i, 0, getarraysize(@choice_i);
+ return;
+
+L_ArrayLengthMismatch:
+ debugmes "@items and @item_names$ array length mismatch";
+ mapexit;
+}
+
+
+
+
+
+function script DynamicItemMenu$ {
+set @items_nr, getarraysize(@items$);
+if(@items_nr != getarraysize(@item_names$)) goto L_ArrayLengthMismatch;
+if(@default_choice$ == "") set @default_choice$, "Never mind.";
+goto L_pick_one_of_many_items;
+
+L_pick_one_of_many_items:
+ @c = 0;
+ @i = 0;
+
+ setarray @choice_n$, "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "";
+ goto L_pick_choice_loop;
+
+L_pick_choice_loop:
+ if (@i >= @items_nr)
+ goto L_choice_init_done;
+ @current$ = @items$[@i];
+ @current_name$ = @item_names$[@i];
+ @current_index = @i;
+ @i = @i + 1;
+
+ if (countitem(@current$) == 0)
+ goto L_pick_choice_loop;
+ @choice_v$[@c] = @current$;
+ @choice_n$[@c] = @current_name$;
+ @choice_i[@c] = @current_index;
+ @c = @c + 1;
+ goto L_pick_choice_loop;
+
+L_choice_init_done:
+ @choice_v$[@c] = "";
+ @choice_n$[@c] = @default_choice$;
+ @c = @c + 1;
+
+ if (@c < 10)
+ menu
+ @choice_n$[0], L_MenuItems,
+ @choice_n$[1], L_MenuItems,
+ @choice_n$[2], L_MenuItems,
+ @choice_n$[3], L_MenuItems,
+ @choice_n$[4], L_MenuItems,
+ @choice_n$[5], L_MenuItems,
+ @choice_n$[6], L_MenuItems,
+ @choice_n$[7], L_MenuItems,
+ @choice_n$[8], L_MenuItems,
+ @choice_n$[9], L_MenuItems;
+ goto L_MenuItems;
+
+L_MenuItems:
+ if (@c < 10)
+ goto L_choice_join;
+
+ if (@c < 20)
+ menu
+ @choice_n$[0], L_MenuItems1,
+ @choice_n$[1], L_MenuItems1,
+ @choice_n$[2], L_MenuItems1,
+ @choice_n$[3], L_MenuItems1,
+ @choice_n$[4], L_MenuItems1,
+ @choice_n$[5], L_MenuItems1,
+ @choice_n$[6], L_MenuItems1,
+ @choice_n$[7], L_MenuItems1,
+ @choice_n$[8], L_MenuItems1,
+ @choice_n$[9], L_MenuItems1,
+ @choice_n$[10], L_MenuItems1,
+ @choice_n$[11], L_MenuItems1,
+ @choice_n$[12], L_MenuItems1,
+ @choice_n$[13], L_MenuItems1,
+ @choice_n$[14], L_MenuItems1,
+ @choice_n$[15], L_MenuItems1,
+ @choice_n$[16], L_MenuItems1,
+ @choice_n$[17], L_MenuItems1,
+ @choice_n$[18], L_MenuItems1,
+ @choice_n$[19], L_MenuItems1;
+ goto L_MenuItems1;
+
+L_MenuItems1:
+ if (@c < 20)
+ goto L_choice_join;
+
+ menu
+ @choice_n$[0], L_choice_join,
+ @choice_n$[1], L_choice_join,
+ @choice_n$[2], L_choice_join,
+ @choice_n$[3], L_choice_join,
+ @choice_n$[4], L_choice_join,
+ @choice_n$[5], L_choice_join,
+ @choice_n$[6], L_choice_join,
+ @choice_n$[7], L_choice_join,
+ @choice_n$[8], L_choice_join,
+ @choice_n$[9], L_choice_join,
+ @choice_n$[10], L_choice_join,
+ @choice_n$[11], L_choice_join,
+ @choice_n$[12], L_choice_join,
+ @choice_n$[13], L_choice_join,
+ @choice_n$[14], L_choice_join,
+ @choice_n$[15], L_choice_join,
+ @choice_n$[16], L_choice_join,
+ @choice_n$[17], L_choice_join,
+ @choice_n$[18], L_choice_join,
+ @choice_n$[19], L_choice_join,
+ @choice_n$[20], L_choice_join,
+ @choice_n$[21], L_choice_join,
+ @choice_n$[22], L_choice_join,
+ @choice_n$[23], L_choice_join,
+ @choice_n$[24], L_choice_join,
+ @choice_n$[25], L_choice_join,
+ @choice_n$[26], L_choice_join,
+ @choice_n$[27], L_choice_join,
+ @choice_n$[28], L_choice_join,
+ @choice_n$[29], L_choice_join,
+ @choice_n$[30], L_choice_join,
+ @choice_n$[31], L_choice_join;
+
+L_choice_join:
+ @menu = @menu - 1;
+ @item$ = @choice_v$[@menu];
+ @index = @choice_i[@menu];
+ if (@menu >= @c)
+ @item$ = "";
+ goto L_Clean;
+
+L_Clean:
+ @menu = 0;
+ @items_nr = 0;
+ @c = 0;
+ @current_index = 0;
+ @i = 0;
+ @current$ = 0;
+ @current_name$ = "";
+ cleararray @choice_v$, "", getarraysize(@choice_v$);
+ cleararray @choice_n$, "", getarraysize(@choice_n$);
+ cleararray @choice_i, 0, getarraysize(@choice_i);
+ return;
+
+L_ArrayLengthMismatch:
+ debugmes "@items$ and @item_names$ array length mismatch";
+ mapexit;
+}