summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorFate <fate-tmw@googlemail.com>2009-05-13 22:10:41 +0000
committerFate <fate-tmw@googlemail.com>2009-05-13 22:10:41 +0000
commit92c1c98824efb789709d70ee8d6d5ed6e49b47a3 (patch)
tree896e34592995fc594d162981b9069295841eac7d /src/map/script.c
parenta60768f84c1e4fcf321208b39443fe01254f376c (diff)
downloadtmwa-92c1c98824efb789709d70ee8d6d5ed6e49b47a3.tar.gz
tmwa-92c1c98824efb789709d70ee8d6d5ed6e49b47a3.tar.bz2
tmwa-92c1c98824efb789709d70ee8d6d5ed6e49b47a3.tar.xz
tmwa-92c1c98824efb789709d70ee8d6d5ed6e49b47a3.zip
menu command: skip all options after (and including) the first option with a blank line
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/map/script.c b/src/map/script.c
index d731b3f..9378e33 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -1625,21 +1625,34 @@ int buildin_close2(struct script_state *st)
int buildin_menu(struct script_state *st)
{
char *buf;
- int len,i;
+ int i, len = 0; // [fate] len is the total # of bytes we need to transmit the string choices
+ int menu_choices = 0;
+ int finished_menu_items = 0; // [fate] set to 1 after we hit the first empty string
+
struct map_session_data *sd;
sd=script_rid2sd(st);
+ // We don't need to do this iteration if the player cancels, strictly speaking.
+ for (i = st->start+2; i < st->end; i += 2) {
+ int choice_len;
+ conv_str(st,& (st->stack->stack_data[i]));
+ choice_len = strlen(st->stack->stack_data[i].u.str);
+ len += choice_len + 1; // count # of bytes we'll need for packet. Only used if menu_or_input = 0.
+
+ if (choice_len && !finished_menu_items)
+ ++menu_choices;
+ else
+ finished_menu_items = 1;
+ }
+
if(sd->state.menu_or_input==0){
st->state=RERUNLINE;
sd->state.menu_or_input=1;
- for(i=st->start+2,len=16;i<st->end;i+=2){
- conv_str(st,& (st->stack->stack_data[i]));
- len+=strlen(st->stack->stack_data[i].u.str)+1;
- }
+
buf=(char *)aCalloc(len,sizeof(char));
buf[0]=0;
- for(i=st->start+2,len=0;i<st->end;i+=2){
+ for(i=st->start+2; menu_choices > 0; i+=2, --menu_choices){
strcat(buf,st->stack->stack_data[i].u.str);
strcat(buf,":");
}
@@ -1653,10 +1666,9 @@ int buildin_menu(struct script_state *st)
pc_setreg(sd,add_str("l15"),sd->npc_menu);
pc_setreg(sd,add_str("@menu"),sd->npc_menu);
sd->state.menu_or_input=0;
- if(sd->npc_menu>0 && sd->npc_menu<(st->end-st->start)/2){
+ if(sd->npc_menu > 0 && sd->npc_menu <= menu_choices){
int pos;
if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
- printf("script: menu: not label !\n");
st->state=END;
return 0;
}