diff options
author | j-tkay <joseph.tk.ea@gmail.com> | 2013-06-19 11:59:28 +0800 |
---|---|---|
committer | j-tkay <joseph.tk.ea@gmail.com> | 2013-06-19 11:59:28 +0800 |
commit | de7919f0f59f47473e6de709b5d5287a4a55e18d (patch) | |
tree | 5967ef231271682ebf9db27185e7e86bbdbc57d4 /src/map/script.c | |
parent | 98fe7e4770376ca66590b5a1e75ce3a848d032a9 (diff) | |
parent | bd95eccf047bda9d72abcea0724ad34b31131ab0 (diff) | |
download | hercules-de7919f0f59f47473e6de709b5d5287a4a55e18d.tar.gz hercules-de7919f0f59f47473e6de709b5d5287a4a55e18d.tar.bz2 hercules-de7919f0f59f47473e6de709b5d5287a4a55e18d.tar.xz hercules-de7919f0f59f47473e6de709b5d5287a4a55e18d.zip |
Merge branch 'master' of https://github.com/HerculesWS/Hercules
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 2667 |
1 files changed, 1494 insertions, 1173 deletions
diff --git a/src/map/script.c b/src/map/script.c index 9a123705b..682faa42b 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -89,26 +89,6 @@ static inline void SETVALUE(unsigned char* buf, int i, int n) buf[i+2] = GetByte(n, 2); } -// String buffer structures. -// str_data stores string information -static struct str_data_struct { - enum c_op type; - int str; - int backpatch; - int label; - bool (*func)(struct script_state *st); - int val; - int next; -} *str_data = NULL; -static int str_data_size = 0; // size of the data -static int str_num = LABEL_START; // next id to be assigned - -// str_buf holds the strings themselves -static char *str_buf; -static int str_size = 0; // size of the buffer -static int str_pos = 0; // next position to be assigned - - // Using a prime number for SCRIPT_HASH_SIZE should give better distributions #define SCRIPT_HASH_SIZE 1021 int str_hash[SCRIPT_HASH_SIZE]; @@ -201,8 +181,6 @@ int potion_target=0; c_op get_com(unsigned char *script,int *pos); int get_num(unsigned char *script,int *pos); -static struct linkdb_node* sleep_db;// int oid -> struct script_state* - /*========================================== * (Only those needed) local declaration prototype *------------------------------------------*/ @@ -338,7 +316,7 @@ static void script_dump_stack(struct script_state* st) break; case C_NAME: - ShowMessage(" \"%s\" (id=%d ref=%p subtype=%s)\n", reference_getname(data), data->u.num, data->ref, script_op2name(str_data[data->u.num].type)); + ShowMessage(" \"%s\" (id=%d ref=%p subtype=%s)\n", reference_getname(data), data->u.num, data->ref, script_op2name(script->str_data[data->u.num].type)); break; case C_RETINFO: @@ -363,7 +341,7 @@ static void script_reportsrc(struct script_state *st) if( st->oid == 0 ) return; //Can't report source. - bl = map_id2bl(st->oid); + bl = iMap->id2bl(st->oid); if( bl == NULL ) return; @@ -416,7 +394,7 @@ static void script_reportdata(struct script_data* data) ShowDebug("Data: param name='%s' type=%d\n", reference_getname(data), reference_getparamtype(data)); } else {// ??? ShowDebug("Data: reference name='%s' type=%s\n", reference_getname(data), script_op2name(data->type)); - ShowDebug("Please report this!!! - str_data.type=%s\n", script_op2name(str_data[reference_getid(data)].type)); + ShowDebug("Please report this!!! - script->str_data.type=%s\n", script_op2name(script->str_data[reference_getid(data)].type)); } break; case C_POS:// label @@ -442,7 +420,7 @@ static void script_reportfunc(struct script_state* st) data = script_getdata(st,0); - if( !data_isreference(data) || str_data[reference_getid(data)].type != C_FUNC ) + if( !data_isreference(data) || script->str_data[reference_getid(data)].type != C_FUNC ) {// script currently not executing a built-in function or corrupt stack return; } @@ -526,14 +504,14 @@ static unsigned int calc_hash(const char* p) /*========================================== - * str_data manipulation functions + * script->str_data manipulation functions *------------------------------------------*/ /// Looks up string using the provided id. const char* get_str(int id) { - Assert( id >= LABEL_START && id < str_size ); - return str_buf+str_data[id].str; + Assert( id >= LABEL_START && id < script->str_size ); + return script->str_buf+script->str_data[id].str; } /// Returns the uid of the string, or -1. @@ -541,7 +519,7 @@ static int search_str(const char* p) { int i; - for( i = str_hash[calc_hash(p)]; i != 0; i = str_data[i].next ) + for( i = str_hash[calc_hash(p)]; i != 0; i = script->str_data[i].next ) if( strcasecmp(get_str(i),p) == 0 ) return i; @@ -557,52 +535,46 @@ int add_str(const char* p) h = calc_hash(p); - if( str_hash[h] == 0 ) - {// empty bucket, add new node here - str_hash[h] = str_num; - } - else - {// scan for end of list, or occurence of identical string - for( i = str_hash[h]; ; i = str_data[i].next ) - { + if( str_hash[h] == 0 ) {// empty bucket, add new node here + str_hash[h] = script->str_num; + } else {// scan for end of list, or occurence of identical string + for( i = str_hash[h]; ; i = script->str_data[i].next ) { if( strcasecmp(get_str(i),p) == 0 ) return i; // string already in list - if( str_data[i].next == 0 ) + if( script->str_data[i].next == 0 ) break; // reached the end } // append node to end of list - str_data[i].next = str_num; + script->str_data[i].next = script->str_num; } // grow list if neccessary - if( str_num >= str_data_size ) - { - str_data_size += 128; - RECREATE(str_data,struct str_data_struct,str_data_size); - memset(str_data + (str_data_size - 128), '\0', 128); + if( script->str_num >= script->str_data_size ) { + script->str_data_size += 1280; + RECREATE(script->str_data,struct str_data_struct,script->str_data_size); + memset(script->str_data + (script->str_data_size - 1280), '\0', 1280); } len=(int)strlen(p); // grow string buffer if neccessary - while( str_pos+len+1 >= str_size ) - { - str_size += 256; - RECREATE(str_buf,char,str_size); - memset(str_buf + (str_size - 256), '\0', 256); + while( script->str_pos+len+1 >= script->str_size ) { + script->str_size += 10240; + RECREATE(script->str_buf,char,script->str_size); + memset(script->str_buf + (script->str_size - 10240), '\0', 10240); } - safestrncpy(str_buf+str_pos, p, len+1); - str_data[str_num].type = C_NOP; - str_data[str_num].str = str_pos; - str_data[str_num].next = 0; - str_data[str_num].func = NULL; - str_data[str_num].backpatch = -1; - str_data[str_num].label = -1; - str_pos += len+1; + safestrncpy(script->str_buf+script->str_pos, p, len+1); + script->str_data[script->str_num].type = C_NOP; + script->str_data[script->str_num].str = script->str_pos; + script->str_data[script->str_num].next = 0; + script->str_data[script->str_num].func = NULL; + script->str_data[script->str_num].backpatch = -1; + script->str_data[script->str_num].label = -1; + script->str_pos += len+1; - return str_num++; + return script->str_num++; } @@ -646,35 +618,35 @@ static void add_scripti(int a) add_scriptb(a|0x80); } -/// Appends a str_data object (label/function/variable/integer) to the script buffer. +/// Appends a script->str_data object (label/function/variable/integer) to the script buffer. /// -/// @param l The id of the str_data entry +/// @param l The id of the script->str_data entry // Maximum up to 16M static void add_scriptl(int l) { - int backpatch = str_data[l].backpatch; + int backpatch = script->str_data[l].backpatch; - switch(str_data[l].type){ + switch(script->str_data[l].type){ case C_POS: case C_USERFUNC_POS: add_scriptc(C_POS); - add_scriptb(str_data[l].label); - add_scriptb(str_data[l].label>>8); - add_scriptb(str_data[l].label>>16); + add_scriptb(script->str_data[l].label); + add_scriptb(script->str_data[l].label>>8); + add_scriptb(script->str_data[l].label>>16); break; case C_NOP: case C_USERFUNC: // Embedded data backpatch there is a possibility of label add_scriptc(C_NAME); - str_data[l].backpatch = script_pos; + script->str_data[l].backpatch = script_pos; add_scriptb(backpatch); add_scriptb(backpatch>>8); add_scriptb(backpatch>>16); break; case C_INT: - add_scripti(abs(str_data[l].val)); - if( str_data[l].val < 0 ) //Notice that this is negative, from jA (Rayce) + add_scripti(abs(script->str_data[l].val)); + if( script->str_data[l].val < 0 ) //Notice that this is negative, from jA (Rayce) add_scriptc(C_NEG); break; default: // assume C_NAME @@ -693,20 +665,20 @@ void set_label(int l,int pos, const char* script_pos) { int i,next; - if(str_data[l].type==C_INT || str_data[l].type==C_PARAM || str_data[l].type==C_FUNC) + if(script->str_data[l].type==C_INT || script->str_data[l].type==C_PARAM || script->str_data[l].type==C_FUNC) { //Prevent overwriting constants values, parameters and built-in functions [Skotlex] disp_error_message("set_label: invalid label name",script_pos); return; } - if(str_data[l].label!=-1){ + if(script->str_data[l].label!=-1){ disp_error_message("set_label: dup label ",script_pos); return; } - str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS); - str_data[l].label=pos; - for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){ + script->str_data[l].type=(script->str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS); + script->str_data[l].label=pos; + for(i=script->str_data[l].backpatch;i>=0 && i!=0x00ffffff;){ next=GETVALUE(script_buf,i); - script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS); + script_buf[i-1]=(script->str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS); SETVALUE(script_buf,i,pos); i=next; } @@ -748,24 +720,21 @@ const char* skip_space(const char* p) } /// Skips a word. -/// A word consists of undercores and/or alfanumeric characters, +/// A word consists of undercores and/or alphanumeric characters, /// and valid variable prefixes/postfixes. -static -const char* skip_word(const char* p) -{ +static const char* skip_word(const char* p) { // prefix - switch( *p ) - { - case '@':// temporary char variable - ++p; break; - case '#':// account variable - p += ( p[1] == '#' ? 2 : 1 ); break; - case '\'':// instance variable - ++p; break; - case '.':// npc variable - p += ( p[1] == '@' ? 2 : 1 ); break; - case '$':// global variable - p += ( p[1] == '@' ? 2 : 1 ); break; + switch( *p ) { + case '@':// temporary char variable + ++p; break; + case '#':// account variable + p += ( p[1] == '#' ? 2 : 1 ); break; + case '\'':// instance variable + ++p; break; + case '.':// npc variable + p += ( p[1] == '@' ? 2 : 1 ); break; + case '$':// global variable + p += ( p[1] == '@' ? 2 : 1 ); break; } while( ISALNUM(*p) || *p == '_' ) @@ -777,30 +746,28 @@ const char* skip_word(const char* p) return p; } - -/// Adds a word to str_data. +/// Adds a word to script->str_data. /// @see skip_word /// @see add_str -static -int add_word(const char* p) -{ - char* word; +static int add_word(const char* p) { int len; int i; // Check for a word len = skip_word(p) - p; if( len == 0 ) - disp_error_message("script:add_word: invalid word. A word consists of undercores and/or alfanumeric characters, and valid variable prefixes/postfixes.", p); + disp_error_message("script:add_word: invalid word. A word consists of undercores and/or alphanumeric characters, and valid variable prefixes/postfixes.", p); // Duplicate the word - word = (char*)aMalloc(len+1); - memcpy(word, p, len); - word[len] = 0; + if( len+1 > script->word_size ) + RECREATE(script->word_buf, char, (script->word_size = (len+1))); + + memcpy(script->word_buf, p, len); + script->word_buf[len] = 0; // add the word - i = add_str(word); - aFree(word); + i = add_str(script->word_buf); + return i; } @@ -815,19 +782,21 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom) int func; func = add_word(p); - if( str_data[func].type == C_FUNC ){ + if( script->str_data[func].type == C_FUNC ){ + char argT = 0; // buildin function add_scriptl(func); add_scriptc(C_ARG); - arg = script->buildin[str_data[func].val]; - } else if( str_data[func].type == C_USERFUNC || str_data[func].type == C_USERFUNC_POS ){ + arg = script->buildin[script->str_data[func].val]; + if( !arg ) arg = &argT; + } else if( script->str_data[func].type == C_USERFUNC || script->str_data[func].type == C_USERFUNC_POS ){ // script defined function add_scriptl(buildin_callsub_ref); add_scriptc(C_ARG); add_scriptl(func); - arg = script->buildin[str_data[buildin_callsub_ref].val]; + arg = script->buildin[script->str_data[buildin_callsub_ref].val]; if( *arg == 0 ) - disp_error_message("parse_callfunc: callsub has no arguments, please review it's definition",p); + disp_error_message("parse_callfunc: callsub has no arguments, please review its definition",p); if( *arg != '*' ) ++arg; // count func as argument } else { @@ -843,7 +812,7 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom) add_scriptc(C_STR); while( *name ) add_scriptb(*name ++); add_scriptb(0); - arg = script->buildin[str_data[buildin_callfunc_ref].val]; + arg = script->buildin[script->str_data[buildin_callfunc_ref].val]; if( *arg != '*' ) ++ arg; } #endif @@ -916,9 +885,9 @@ static void parse_nextline(bool first, const char* p) } // initialize data for new '-' label fix up scheduling - str_data[LABEL_NEXTLINE].type = C_NOP; - str_data[LABEL_NEXTLINE].backpatch = -1; - str_data[LABEL_NEXTLINE].label = -1; + script->str_data[LABEL_NEXTLINE].type = C_NOP; + script->str_data[LABEL_NEXTLINE].backpatch = -1; + script->str_data[LABEL_NEXTLINE].label = -1; } /// Parse a variable assignment using the direct equals operator @@ -1005,7 +974,7 @@ const char* parse_variable(const char* p) { // parse the variable currently being modified word = add_word(var); - if( str_data[word].type == C_FUNC || str_data[word].type == C_USERFUNC || str_data[word].type == C_USERFUNC_POS ) + if( script->str_data[word].type == C_FUNC || script->str_data[word].type == C_USERFUNC || script->str_data[word].type == C_USERFUNC_POS ) {// cannot assign a variable which exists as a function or label disp_error_message("Cannot modify a variable which has the same name as a function or label.", p); } @@ -1067,7 +1036,7 @@ const char* parse_simpleexpr(const char *p) p=skip_space(p); if(*p==';' || *p==',') - disp_error_message("parse_simpleexpr: unexpected expr end",p); + disp_error_message("parse_simpleexpr: unexpected end of expression",p); if(*p=='('){ if( (i=syntax.curly_count-1) >= 0 && syntax.curly[i].type == TYPE_ARGLIST ) ++syntax.curly[i].count; @@ -1083,7 +1052,7 @@ const char* parse_simpleexpr(const char *p) syntax.curly[i].flag = ARGLIST_NO_PAREN; } if( *p != ')' ) - disp_error_message("parse_simpleexpr: unmatch ')'",p); + disp_error_message("parse_simpleexpr: unmatched ')'",p); ++p; } else if(ISDIGIT(*p) || ((*p=='-' || *p=='+') && ISDIGIT(p[1]))){ char *np; @@ -1109,7 +1078,7 @@ const char* parse_simpleexpr(const char *p) add_scriptb(*p++); } if(!*p) - disp_error_message("parse_simpleexpr: unexpected eof @ string",p); + disp_error_message("parse_simpleexpr: unexpected end of file @ string",p); add_scriptb(0); p++; //'"' } else { @@ -1121,7 +1090,7 @@ const char* parse_simpleexpr(const char *p) disp_error_message("parse_simpleexpr: unexpected character",p); l=add_word(p); - if( str_data[l].type == C_FUNC || str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS) + if( script->str_data[l].type == C_FUNC || script->str_data[l].type == C_USERFUNC || script->str_data[l].type == C_USERFUNC_POS) return parse_callfunc(p,1,0); #ifdef SCRIPT_CALLFUNC_CHECK else { @@ -1147,7 +1116,7 @@ const char* parse_simpleexpr(const char *p) p=parse_subexpr(p+1,-1); p=skip_space(p); if( *p != ']' ) - disp_error_message("parse_simpleexpr: unmatch ']'",p); + disp_error_message("parse_simpleexpr: unmatched ']'",p); ++p; add_scriptc(C_FUNC); }else @@ -1348,8 +1317,8 @@ const char* parse_curly_close(const char* p) } // Syntax-related processing -// break, case, continue, default, do, for, function, -// if, switch, while ? will handle this internally. +// break, case, continue, default, do, for, function, +// if, switch, while ? will handle this internally. const char* parse_syntax(const char* p) { const char *p2 = skip_word(p); @@ -1429,14 +1398,14 @@ const char* parse_syntax(const char* p) memcpy(label,p,v); label[v]='\0'; if( !script_get_constant(label, &v) ) - disp_error_message("parse_syntax: 'case' label not integer",p); + disp_error_message("parse_syntax: 'case' label is not an integer",p); p = skip_word(p); } else { //Numeric value if((*p == '-' || *p == '+') && ISDIGIT(p[1])) // pre-skip because '-' can not skip_word p++; p = skip_word(p); if(np != p) - disp_error_message("parse_syntax: 'case' label not integer",np); + disp_error_message("parse_syntax: 'case' label is not an integer",np); } p = skip_space(p); if(*p != ':') @@ -1644,9 +1613,9 @@ const char* parse_syntax(const char* p) // function declaration - just register the name int l; l = add_word(func_name); - if( str_data[l].type == C_NOP )// register only, if the name was not used by something else - str_data[l].type = C_USERFUNC; - else if( str_data[l].type == C_USERFUNC ) + if( script->str_data[l].type == C_NOP )// register only, if the name was not used by something else + script->str_data[l].type = C_USERFUNC; + else if( script->str_data[l].type == C_USERFUNC ) ; // already registered else disp_error_message("parse_syntax:function: function name is invalid", func_name); @@ -1675,9 +1644,9 @@ const char* parse_syntax(const char* p) // Set the position of the function (label) l=add_word(func_name); - if( str_data[l].type == C_NOP || str_data[l].type == C_USERFUNC )// register only, if the name was not used by something else + if( script->str_data[l].type == C_NOP || script->str_data[l].type == C_USERFUNC )// register only, if the name was not used by something else { - str_data[l].type = C_USERFUNC; + script->str_data[l].type = C_USERFUNC; set_label(l, script_pos, p); if( parse_options&SCRIPT_USE_LABEL_DB ) strdb_iput(scriptlabel_db, get_str(l), script_pos); @@ -1972,11 +1941,11 @@ bool script_get_constant(const char* name, int* value) { int n = search_str(name); - if( n == -1 || str_data[n].type != C_INT ) + if( n == -1 || script->str_data[n].type != C_INT ) {// not found or not a constant return false; } - value[0] = str_data[n].val; + value[0] = script->str_data[n].val; return true; } @@ -1986,18 +1955,18 @@ void script_set_constant(const char* name, int value, bool isparameter) { int n = add_str(name); - if( str_data[n].type == C_NOP ) + if( script->str_data[n].type == C_NOP ) {// new - str_data[n].type = isparameter ? C_PARAM : C_INT; - str_data[n].val = value; + script->str_data[n].type = isparameter ? C_PARAM : C_INT; + script->str_data[n].val = value; } - else if( str_data[n].type == C_PARAM || str_data[n].type == C_INT ) + else if( script->str_data[n].type == C_PARAM || script->str_data[n].type == C_INT ) {// existing parameter or constant - ShowError("script_set_constant: Attempted to overwrite existing %s '%s' (old value=%d, new value=%d).\n", ( str_data[n].type == C_PARAM ) ? "parameter" : "constant", name, str_data[n].val, value); + ShowError("script_set_constant: Attempted to overwrite existing %s '%s' (old value=%d, new value=%d).\n", ( script->str_data[n].type == C_PARAM ) ? "parameter" : "constant", name, script->str_data[n].val, value); } else {// existing name - ShowError("script_set_constant: Invalid name for %s '%s' (already defined as %s).\n", isparameter ? "parameter" : "constant", name, script_op2name(str_data[n].type)); + ShowError("script_set_constant: Invalid name for %s '%s' (already defined as %s).\n", isparameter ? "parameter" : "constant", name, script_op2name(script->str_data[n].type)); } } @@ -2011,7 +1980,7 @@ static void read_constdb(void) char line[1024],name[1024],val[1024]; int type; - sprintf(line, "%s/const.txt", db_path); + sprintf(line, "%s/const.txt", iMap->db_path); fp=fopen(line, "r"); if(fp==NULL){ ShowError("can't read %s\n", line); @@ -2074,7 +2043,11 @@ void script_error(const char* src, const char* file, int start_line, const char* StrBuf->Init(&buf); StrBuf->AppendStr(&buf, "\a\n"); - StrBuf->Printf(&buf, "script error on %s line %d\n", file, line); + if( line >= 0 ) + StrBuf->Printf(&buf, "script error on %s line %d\n", file, line); + else + StrBuf->Printf(&buf, "script error on %s item ID %d\n", file, -line); + StrBuf->Printf(&buf, " %s\n", error_msg); for(j = 0; j < 5; j++ ) { script_print_line(&buf, linestart[j], NULL, line + j - 5); @@ -2124,8 +2097,8 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o script_pos = 0; script_size = 0; script_buf = NULL; - for(i=LABEL_START;i<str_num;i++) - if(str_data[i].type == C_NOP) str_data[i].type = C_NAME; + for(i=LABEL_START;i<script->str_num;i++) + if(script->str_data[i].type == C_NOP) script->str_data[i].type = C_NAME; for(i=0; i<size; i++) linkdb_final(&syntax.curly[i].case_label); return NULL; @@ -2163,14 +2136,14 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o } // clear references of labels, variables and internal functions - for(i=LABEL_START;i<str_num;i++){ + for(i=LABEL_START;i<script->str_num;i++){ if( - str_data[i].type==C_POS || str_data[i].type==C_NAME || - str_data[i].type==C_USERFUNC || str_data[i].type == C_USERFUNC_POS + script->str_data[i].type==C_POS || script->str_data[i].type==C_NAME || + script->str_data[i].type==C_USERFUNC || script->str_data[i].type == C_USERFUNC_POS ){ - str_data[i].type=C_NOP; - str_data[i].backpatch=-1; - str_data[i].label=-1; + script->str_data[i].type=C_NOP; + script->str_data[i].backpatch=-1; + script->str_data[i].label=-1; } } @@ -2204,20 +2177,20 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o RECREATE(script_buf,unsigned char,script_pos); // default unknown references to variables - for(i=LABEL_START;i<str_num;i++){ - if(str_data[i].type==C_NOP){ + for(i=LABEL_START;i<script->str_num;i++){ + if(script->str_data[i].type==C_NOP){ int j,next; - str_data[i].type=C_NAME; - str_data[i].label=i; - for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){ + script->str_data[i].type=C_NAME; + script->str_data[i].label=i; + for(j=script->str_data[i].backpatch;j>=0 && j!=0x00ffffff;){ next=GETVALUE(script_buf,j); SETVALUE(script_buf,j,i); j=next; } } - else if( str_data[i].type == C_USERFUNC ) + else if( script->str_data[i].type == C_USERFUNC ) {// 'function name;' without follow-up code - ShowError("parse_script: function '%s' declared but not defined.\n", str_buf+str_data[i].str); + ShowError("parse_script: function '%s' declared but not defined.\n", script->str_buf+script->str_data[i].str); unresolved_names = true; } } @@ -2270,16 +2243,15 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o CREATE(code,struct script_code,1); code->script_buf = script_buf; code->script_size = script_size; - code->script_vars = idb_alloc(DB_OPT_RELEASE_DATA); + code->script_vars = NULL; return code; } /// Returns the player attached to this script, identified by the rid. /// If there is no player attached, the script is terminated. -TBL_PC *script_rid2sd(struct script_state *st) -{ - TBL_PC *sd=map_id2sd(st->rid); - if(!sd){ +TBL_PC *script_rid2sd(struct script_state *st) { + TBL_PC *sd; + if( !( sd = iMap->id2sd(st->rid) ) ){ ShowError("script_rid2sd: fatal error ! player not attached!\n"); script_reportfunc(st); script_reportsrc(st); @@ -2307,20 +2279,15 @@ void get_val(struct script_state* st, struct script_data* data) postfix = name[strlen(name) - 1]; //##TODO use reference_tovariable(data) when it's confirmed that it works [FlavioJS] - if( !reference_toconstant(data) && not_server_variable(prefix) ) - { + if( !reference_toconstant(data) && not_server_variable(prefix) ) { sd = script_rid2sd(st); - if( sd == NULL ) - {// needs player attached - if( postfix == '$' ) - {// string variable - ShowWarning("script:get_val: cannot access player variable '%s', defaulting to \"\"\n", name); + if( sd == NULL ) {// needs player attached + if( postfix == '$' ) {// string variable + ShowWarning("script:script->get_val: cannot access player variable '%s', defaulting to \"\"\n", name); data->type = C_CONSTSTR; data->u.str = ""; - } - else - {// integer variable - ShowWarning("script:get_val: cannot access player variable '%s', defaulting to 0\n", name); + } else {// integer variable + ShowWarning("script:script->get_val: cannot access player variable '%s', defaulting to 0\n", name); data->type = C_INT; data->u.num = 0; } @@ -2328,128 +2295,113 @@ void get_val(struct script_state* st, struct script_data* data) } } - if( postfix == '$' ) - {// string variable + if( postfix == '$' ) {// string variable - switch( prefix ) - { - case '@': - data->u.str = pc_readregstr(sd, data->u.num); - break; - case '$': - data->u.str = mapreg_readregstr(data->u.num); - break; - case '#': - if( name[1] == '#' ) - data->u.str = pc_readaccountreg2str(sd, name);// global - else - data->u.str = pc_readaccountregstr(sd, name);// local - break; - case '.': - { - struct DBMap* n = - data->ref ? *data->ref: - name[1] == '@' ? st->stack->var_function:// instance/scope variable - st->script->script_vars;// npc variable - if( n ) - data->u.str = (char*)idb_get(n,reference_getuid(data)); + switch( prefix ) { + case '@': + data->u.str = pc->readregstr(sd, data->u.num); + break; + case '$': + data->u.str = mapreg_readregstr(data->u.num); + break; + case '#': + if( name[1] == '#' ) + data->u.str = pc_readaccountreg2str(sd, name);// global else - data->u.str = NULL; - } - break; - case '\'': - if (st->instance_id) { - data->u.str = (char*)idb_get(instance[st->instance_id].vars,reference_getuid(data)); - } else { - ShowWarning("script:get_val: cannot access instance variable '%s', defaulting to \"\"\n", name); - data->u.str = NULL; + data->u.str = pc_readaccountregstr(sd, name);// local + break; + case '.': + { + struct DBMap* n = + data->ref ? *data->ref: + name[1] == '@' ? st->stack->var_function:// instance/scope variable + st->script->script_vars;// npc variable + if( n ) + data->u.str = (char*)idb_get(n,reference_getuid(data)); + else + data->u.str = NULL; } - break; - default: - data->u.str = pc_readglobalreg_str(sd, name); - break; + break; + case '\'': + if ( st->instance_id >= 0 ) { + data->u.str = (char*)idb_get(instances[st->instance_id].vars,reference_getuid(data)); + } else { + ShowWarning("script:script->get_val: cannot access instance variable '%s', defaulting to \"\"\n", name); + data->u.str = NULL; + } + break; + default: + data->u.str = pc_readglobalreg_str(sd, name); + break; } - if( data->u.str == NULL || data->u.str[0] == '\0' ) - {// empty string + if( data->u.str == NULL || data->u.str[0] == '\0' ) {// empty string data->type = C_CONSTSTR; data->u.str = ""; - } - else - {// duplicate string + } else {// duplicate string data->type = C_STR; data->u.str = aStrdup(data->u.str); } - } - else - {// integer variable + } else {// integer variable data->type = C_INT; - if( reference_toconstant(data) ) - { + if( reference_toconstant(data) ) { data->u.num = reference_getconstant(data); - } - else if( reference_toparam(data) ) - { - data->u.num = pc_readparam(sd, reference_getparamtype(data)); - } - else - switch( prefix ) - { - case '@': - data->u.num = pc_readreg(sd, data->u.num); - break; - case '$': - data->u.num = mapreg_readreg(data->u.num); - break; - case '#': - if( name[1] == '#' ) - data->u.num = pc_readaccountreg2(sd, name);// global - else - data->u.num = pc_readaccountreg(sd, name);// local - break; - case '.': - { - struct DBMap* n = - data->ref ? *data->ref: - name[1] == '@' ? st->stack->var_function:// instance/scope variable - st->script->script_vars;// npc variable - if( n ) - data->u.num = (int)idb_iget(n,reference_getuid(data)); - else - data->u.num = 0; + } else if( reference_toparam(data) ) { + data->u.num = pc->readparam(sd, reference_getparamtype(data)); + } else + switch( prefix ) { + case '@': + data->u.num = pc->readreg(sd, data->u.num); + break; + case '$': + data->u.num = mapreg_readreg(data->u.num); + break; + case '#': + if( name[1] == '#' ) + data->u.num = pc_readaccountreg2(sd, name);// global + else + data->u.num = pc_readaccountreg(sd, name);// local + break; + case '.': + { + struct DBMap* n = + data->ref ? *data->ref: + name[1] == '@' ? st->stack->var_function:// instance/scope variable + st->script->script_vars;// npc variable + if( n ) + data->u.num = (int)idb_iget(n,reference_getuid(data)); + else + data->u.num = 0; + } + break; + case '\'': + if( st->instance_id >= 0 ) + data->u.num = (int)idb_iget(instances[st->instance_id].vars,reference_getuid(data)); + else { + ShowWarning("script:script->get_val: cannot access instance variable '%s', defaulting to 0\n", name); + data->u.num = 0; + } + break; + default: + data->u.num = pc_readglobalreg(sd, name); + break; } - break; - case '\'': - if( st->instance_id ) - data->u.num = (int)idb_iget(instance[st->instance_id].vars,reference_getuid(data)); - else { - ShowWarning("script:get_val: cannot access instance variable '%s', defaulting to 0\n", name); - data->u.num = 0; - } - break; - default: - data->u.num = pc_readglobalreg(sd, name); - break; - } } return; } -struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct DBMap** ref); - /// Retrieves the value of a reference identified by uid (variable, constant, param) /// The value is left in the top of the stack and needs to be removed manually. -void* get_val2(struct script_state* st, int uid, struct DBMap** ref) -{ +void* get_val2(struct script_state* st, int uid, struct DBMap** ref) { struct script_data* data; - push_val2(st->stack, C_NAME, uid, ref); + script->push_val(st->stack, C_NAME, uid, ref); data = script_getdatatop(st, -1); - get_val(st, data); + script->get_val(st, data); return (data->type == C_INT ? (void*)__64BPTRSIZE(data->u.num) : (void*)__64BPTRSIZE(data->u.str)); } @@ -2466,7 +2418,7 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam const char* str = (const char*)value; switch (prefix) { case '@': - return pc_setregstr(sd, num, str); + return pc->setregstr(sd, num, str); case '$': return mapreg_setregstr(num, str); case '#': @@ -2484,9 +2436,9 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam } return 1; case '\'': - if( st->instance_id ) { - idb_remove(instance[st->instance_id].vars, num); - if( str[0] ) idb_put(instance[st->instance_id].vars, num, aStrdup(str)); + if( st->instance_id >= 0 ) { + idb_remove(instances[st->instance_id].vars, num); + if( str[0] ) idb_put(instances[st->instance_id].vars, num, aStrdup(str)); } return 1; default: @@ -2496,9 +2448,9 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam else {// integer variable int val = (int)__64BPTRSIZE(value); - if(str_data[num&0x00ffffff].type == C_PARAM) + if(script->str_data[num&0x00ffffff].type == C_PARAM) { - if( pc_setparam(sd, str_data[num&0x00ffffff].val, val) == 0 ) + if( pc->setparam(sd, script->str_data[num&0x00ffffff].val, val) == 0 ) { if( st != NULL ) { @@ -2513,7 +2465,7 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam switch (prefix) { case '@': - return pc_setreg(sd, num, val); + return pc->setreg(sd, num, val); case '$': return mapreg_setreg(num, val); case '#': @@ -2532,10 +2484,10 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam } return 1; case '\'': - if( st->instance_id ) { - idb_remove(instance[st->instance_id].vars, num); + if( st->instance_id >= 0 ) { + idb_remove(instances[st->instance_id].vars, num); if( val != 0 ) - idb_iput(instance[st->instance_id].vars, num, val); + idb_iput(instances[st->instance_id].vars, num, val); } return 1; default: @@ -2559,7 +2511,7 @@ const char* conv_str(struct script_state* st, struct script_data* data) { char* p; - get_val(st, data); + script->get_val(st, data); if( data_isstring(data) ) {// nothing to convert } @@ -2573,7 +2525,7 @@ const char* conv_str(struct script_state* st, struct script_data* data) } else if( data_isreference(data) ) {// reference -> string - //##TODO when does this happen (check get_val) [FlavioJS] + //##TODO when does this happen (check script->get_val) [FlavioJS] data->type = C_CONSTSTR; data->u.str = reference_getname(data); } @@ -2593,7 +2545,7 @@ int conv_num(struct script_state* st, struct script_data* data) { char* p; long num; - get_val(st, data); + script->get_val(st, data); if( data_isint(data) ) {// nothing to convert } @@ -2648,8 +2600,7 @@ int conv_num(struct script_state* st, struct script_data* data) { // /// Increases the size of the stack -void stack_expand(struct script_stack* stack) -{ +void stack_expand(struct script_stack* stack) { stack->sp_max += 64; stack->stack_data = (struct script_data*)aRealloc(stack->stack_data, stack->sp_max * sizeof(stack->stack_data[0]) ); @@ -2657,12 +2608,8 @@ void stack_expand(struct script_stack* stack) 64 * sizeof(stack->stack_data[0]) ); } -/// Pushes a value into the stack -#define push_val(stack,type,val) push_val2(stack, type, val, NULL) - /// Pushes a value into the stack (with reference) -struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct DBMap** ref) -{ +struct script_data* push_val(struct script_stack* stack, enum c_op type, int val, struct DBMap** ref) { if( stack->sp >= stack->sp_max ) stack_expand(stack); stack->stack_data[stack->sp].type = type; @@ -2697,28 +2644,26 @@ struct script_data* push_retinfo(struct script_stack* stack, struct script_retin } /// Pushes a copy of the target position into the stack -struct script_data* push_copy(struct script_stack* stack, int pos) -{ - switch( stack->stack_data[pos].type ) - { - case C_CONSTSTR: - return push_str(stack, C_CONSTSTR, stack->stack_data[pos].u.str); - break; - case C_STR: - return push_str(stack, C_STR, aStrdup(stack->stack_data[pos].u.str)); - break; - case C_RETINFO: - ShowFatalError("script:push_copy: can't create copies of C_RETINFO. Exiting...\n"); - exit(1); - break; - default: - return push_val2( - stack,stack->stack_data[pos].type, - stack->stack_data[pos].u.num, - stack->stack_data[pos].ref - ); - break; - } +struct script_data* push_copy(struct script_stack* stack, int pos) { + switch( stack->stack_data[pos].type ) { + case C_CONSTSTR: + return script->push_str(stack, C_CONSTSTR, stack->stack_data[pos].u.str); + break; + case C_STR: + return script->push_str(stack, C_STR, aStrdup(stack->stack_data[pos].u.str)); + break; + case C_RETINFO: + ShowFatalError("script:push_copy: can't create copies of C_RETINFO. Exiting...\n"); + exit(1); + break; + default: + return script->push_val( + stack,stack->stack_data[pos].type, + stack->stack_data[pos].u.num, + stack->stack_data[pos].ref + ); + break; + } } /// Removes the values in indexes [start,end[ from the stack. @@ -2799,24 +2744,32 @@ void script_free_code(struct script_code* code) /// @param rid Who is running the script (attached player) /// @param oid Where the code is being run (npc 'object') /// @return Script state -struct script_state* script_alloc_state(struct script_code* script, int pos, int rid, int oid) -{ +struct script_state* script_alloc_state(struct script_code* rootscript, int pos, int rid, int oid) { struct script_state* st; - CREATE(st, struct script_state, 1); - st->stack = (struct script_stack*)aMalloc(sizeof(struct script_stack)); + + st = ers_alloc(script->st_ers, struct script_state); + st->stack = ers_alloc(script->stack_ers, struct script_stack); st->stack->sp = 0; st->stack->sp_max = 64; CREATE(st->stack->stack_data, struct script_data, st->stack->sp_max); st->stack->defsp = st->stack->sp; st->stack->var_function = idb_alloc(DB_OPT_RELEASE_DATA); st->state = RUN; - st->script = script; - //st->scriptroot = script; + st->script = rootscript; st->pos = pos; st->rid = rid; st->oid = oid; st->sleep.timer = INVALID_TIMER; st->npc_item_flag = battle_config.item_enabled_npc; + + if( !st->script->script_vars ) + st->script->script_vars = idb_alloc(DB_OPT_RELEASE_DATA); + + st->id = script->next_id++; + script->active_scripts++; + + idb_put(script->st_db, st->id, st); + return st; } @@ -2825,19 +2778,27 @@ struct script_state* script_alloc_state(struct script_code* script, int pos, int /// @param st Script state void script_free_state(struct script_state* st) { - if(st->bk_st) - {// backup was not restored + if(st->bk_st) {// backup was not restored ShowDebug("script_free_state: Previous script state lost (rid=%d, oid=%d, state=%d, bk_npcid=%d).\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid); } + if( st->sleep.timer != INVALID_TIMER ) - delete_timer(st->sleep.timer, run_script_timer); + iTimer->delete_timer(st->sleep.timer, run_script_timer); script_free_vars(st->stack->var_function); - pop_stack(st, 0, st->stack->sp); + script->pop_stack(st, 0, st->stack->sp); aFree(st->stack->stack_data); - aFree(st->stack); + ers_free(script->stack_ers, st->stack); + if( st->script && st->script->script_vars && !db_size(st->script->script_vars) ) { + script_free_vars(st->script->script_vars); + st->script->script_vars = NULL; + } st->stack = NULL; st->pos = -1; - aFree(st); + idb_remove(script->st_db, st->id); + ers_free(script->st_ers, st); + if( --script->active_scripts == 0 ) { + script->next_id = 0; + } } // @@ -2882,7 +2843,7 @@ int pop_val(struct script_state* st) if(st->stack->sp<=0) return 0; st->stack->sp--; - get_val(st,&(st->stack->stack_data[st->stack->sp])); + script->get_val(st,&(st->stack->stack_data[st->stack->sp])); if(st->stack->stack_data[st->stack->sp].type==C_INT) return st->stack->stack_data[st->stack->sp].u.num; return 0; @@ -2896,7 +2857,7 @@ void op_3(struct script_state* st, int op) int flag = 0; data = script_getdatatop(st, -3); - get_val(st, data); + script->get_val(st, data); if( data_isstring(data) ) flag = data->u.str[0];// "" -> false @@ -3040,8 +3001,8 @@ void op_2(struct script_state *st, int op) st->op2ref = 0; } - get_val(st, left); - get_val(st, right); + script->get_val(st, left); + script->get_val(st, right); // automatic conversions switch( op ) @@ -3102,7 +3063,7 @@ void op_1(struct script_state* st, int op) int i1; data = script_getdatatop(st, -1); - get_val(st, data); + script->get_val(st, data); if( !data_isint(data) ) {// not a number @@ -3140,7 +3101,7 @@ static void script_check_buildin_argtype(struct script_state* st, int func) { char type; int idx, invalid = 0; - char* sf = script->buildin[str_data[func].val]; + char* sf = script->buildin[script->str_data[func].val]; for( idx = 2; script_hasdata(st, idx); idx++ ) { struct script_data* data = script_getdata(st, idx); @@ -3236,7 +3197,7 @@ int run_func(struct script_state *st) st->end = end_sp; data = &st->stack->stack_data[st->start]; - if( data->type == C_NAME && str_data[data->u.num].type == C_FUNC ) + if( data->type == C_NAME && script->str_data[data->u.num].type == C_FUNC ) func = data->u.num; else { @@ -3252,11 +3213,11 @@ int run_func(struct script_state *st) script_check_buildin_argtype(st, func); } - if(str_data[func].func){ - if (!(str_data[func].func(st))) //Report error + if(script->str_data[func].func){ + if (!(script->str_data[func].func(st))) //Report error script_reportsrc(st); } else { - ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!\n", get_str(func), func, script_op2name(str_data[func].type)); + ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!\n", get_str(func), func, script_op2name(script->str_data[func].type)); script_reportsrc(st); st->state = END; } @@ -3265,14 +3226,14 @@ int run_func(struct script_state *st) if( st->state == RERUNLINE ) return 0; - pop_stack(st, st->start, st->end); + script->pop_stack(st, st->start, st->end); if( st->state == RETFUNC ) {// return from a user-defined function struct script_retinfo* ri; int olddefsp = st->stack->defsp; int nargs; - pop_stack(st, st->stack->defsp, st->start);// pop distractions from the stack + script->pop_stack(st, st->stack->defsp, st->start);// pop distractions from the stack if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp-1].type != C_RETINFO ) { ShowWarning("script:run_func: return without callfunc or callsub!\n"); @@ -3290,7 +3251,7 @@ int run_func(struct script_state *st) st->stack->defsp = ri->defsp; memset(ri, 0, sizeof(struct script_retinfo)); - pop_stack(st, olddefsp-nargs-1, olddefsp);// pop arguments and retinfo + script->pop_stack(st, olddefsp-nargs-1, olddefsp);// pop arguments and retinfo st->state = GOTO; } @@ -3301,74 +3262,50 @@ int run_func(struct script_state *st) /*========================================== * script execution *------------------------------------------*/ -void run_script(struct script_code *rootscript,int pos,int rid,int oid) -{ +void run_script(struct script_code *rootscript,int pos,int rid,int oid) { struct script_state *st; if( rootscript == NULL || pos < 0 ) return; - + // TODO In jAthena, this function can take over the pending script in the player. [FlavioJS] // It is unclear how that can be triggered, so it needs the be traced/checked in more detail. // NOTE At the time of this change, this function wasn't capable of taking over the script state because st->scriptroot was never set. st = script_alloc_state(rootscript, pos, rid, oid); + run_script_main(st); } -void script_stop_sleeptimers(int id) -{ +void script_stop_instances(int id) { + DBIterator *iter; struct script_state* st; - for(;;) - { - st = (struct script_state*)linkdb_erase(&sleep_db,(void*)__64BPTRSIZE(id)); - if( st == NULL ) - break; // no more sleep timers - script_free_state(st); + + if( !script->active_scripts ) + return;//dont even bother. + + iter = db_iterator(script->st_db); + + for( st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter) ) { + if( st->oid == id ) { + script_free_state(st); + } } -} - -/*========================================== - * Delete the specified node from sleep_db - *------------------------------------------*/ -struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n) -{ - struct linkdb_node *retnode; - - if( n == NULL) - return NULL; - if( n->prev == NULL ) - sleep_db = n->next; - else - n->prev->next = n->next; - if( n->next ) - n->next->prev = n->prev; - retnode = n->next; - aFree( n ); - return retnode; // The following; return retnode + + dbi_destroy(iter); } /*========================================== * Timer function for sleep *------------------------------------------*/ -int run_script_timer(int tid, unsigned int tick, int id, intptr_t data) -{ +int run_script_timer(int tid, unsigned int tick, int id, intptr_t data) { struct script_state *st = (struct script_state *)data; - struct linkdb_node *node = (struct linkdb_node *)sleep_db; - TBL_PC *sd = map_id2sd(st->rid); + TBL_PC *sd = iMap->id2sd(st->rid); - if((sd && sd->status.char_id != id) || (st->rid && !sd)) - { //Character mismatch. Cancel execution. + if((sd && sd->status.char_id != id) || (st->rid && !sd)) { //Character mismatch. Cancel execution. st->rid = 0; st->state = END; } - while( node && st->sleep.timer != INVALID_TIMER ) { - if( (int)__64BPTRSIZE(node->key) == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) { - script_erase_sleepdb(node); - st->sleep.timer = INVALID_TIMER; - break; - } - node = node->next; - } + st->sleep.timer = INVALID_TIMER; if(st->state != RERUNLINE) st->sleep.tick = 0; run_script_main(st); @@ -3383,9 +3320,10 @@ static void script_detach_state(struct script_state* st, bool dequeue_event) { struct map_session_data* sd; - if(st->rid && (sd = map_id2sd(st->rid))!=NULL) { + if(st->rid && (sd = iMap->id2sd(st->rid))!=NULL) { sd->st = st->bk_st; sd->npc_id = st->bk_npcid; + sd->state.dialog = 0; if(st->bk_st) { //Remove tag for removal. st->bk_st = NULL; @@ -3399,15 +3337,13 @@ static void script_detach_state(struct script_state* st, bool dequeue_event) * We're done with this NPC session, so we cancel the timer (if existent) and move on **/ if( sd->npc_idle_timer != INVALID_TIMER ) { - delete_timer(sd->npc_idle_timer,npc_rr_secure_timeout_timer); + iTimer->delete_timer(sd->npc_idle_timer,npc_rr_secure_timeout_timer); sd->npc_idle_timer = INVALID_TIMER; } #endif npc_event_dequeue(sd); } - } - else if(st->bk_st) - {// rid was set to 0, before detaching the script state + } else if(st->bk_st) { // rid was set to 0, before detaching the script state ShowError("script_detach_state: Found previous script state without attached player (rid=%d, oid=%d, state=%d, bk_npcid=%d)\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid); script_reportsrc(st->bk_st); @@ -3423,7 +3359,7 @@ static void script_attach_state(struct script_state* st) { struct map_session_data* sd; - if(st->rid && (sd = map_id2sd(st->rid))!=NULL) + if(st->rid && (sd = iMap->id2sd(st->rid))!=NULL) { if(st!=sd->st) { @@ -3442,8 +3378,8 @@ static void script_attach_state(struct script_state* st) **/ #ifdef SECURE_NPCTIMEOUT if( sd->npc_idle_timer == INVALID_TIMER ) - sd->npc_idle_timer = add_timer(gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc_rr_secure_timeout_timer,sd->bl.id,0); - sd->npc_idle_tick = gettick(); + sd->npc_idle_timer = iTimer->add_timer(iTimer->gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc_rr_secure_timeout_timer,sd->bl.id,0); + sd->npc_idle_tick = iTimer->gettick(); #endif } } @@ -3456,14 +3392,16 @@ void run_script_main(struct script_state *st) int cmdcount = script_config.check_cmdcount; int gotocount = script_config.check_gotocount; TBL_PC *sd; - struct script_stack *stack=st->stack; + struct script_stack *stack = st->stack; struct npc_data *nd; script_attach_state(st); - nd = map_id2nd(st->oid); - if( nd && map[nd->bl.m].instance_id > 0 ) + nd = iMap->id2nd(st->oid); + if( nd && nd->bl.m >= 0 ) st->instance_id = map[nd->bl.m].instance_id; + else + st->instance_id = -1; if(st->state == RERUNLINE) { run_func(st); @@ -3472,86 +3410,85 @@ void run_script_main(struct script_state *st) } else if(st->state != END) st->state = RUN; - while(st->state == RUN) - { + while( st->state == RUN ){ enum c_op c = get_com(st->script->script_buf,&st->pos); switch(c){ - case C_EOL: - if( stack->defsp > stack->sp ) - ShowError("script:run_script_main: unexpected stack position (defsp=%d sp=%d). please report this!!!\n", stack->defsp, stack->sp); - else - pop_stack(st, stack->defsp, stack->sp);// pop unused stack data. (unused return value) - break; - case C_INT: - push_val(stack,C_INT,get_num(st->script->script_buf,&st->pos)); - break; - case C_POS: - case C_NAME: - push_val(stack,c,GETVALUE(st->script->script_buf,st->pos)); - st->pos+=3; - break; - case C_ARG: - push_val(stack,c,0); - break; - case C_STR: - push_str(stack,C_CONSTSTR,(char*)(st->script->script_buf+st->pos)); - while(st->script->script_buf[st->pos++]); - break; - case C_FUNC: - run_func(st); - if(st->state==GOTO){ - st->state = RUN; - if( !st->freeloop && gotocount>0 && (--gotocount)<=0 ){ - ShowError("run_script: infinity loop !\n"); - script_reportsrc(st); - st->state=END; + case C_EOL: + if( stack->defsp > stack->sp ) + ShowError("script:run_script_main: unexpected stack position (defsp=%d sp=%d). please report this!!!\n", stack->defsp, stack->sp); + else + script->pop_stack(st, stack->defsp, stack->sp);// pop unused stack data. (unused return value) + break; + case C_INT: + script->push_val(stack,C_INT,get_num(st->script->script_buf,&st->pos),NULL); + break; + case C_POS: + case C_NAME: + script->push_val(stack,c,GETVALUE(st->script->script_buf,st->pos),NULL); + st->pos+=3; + break; + case C_ARG: + script->push_val(stack,c,0,NULL); + break; + case C_STR: + script->push_str(stack,C_CONSTSTR,(char*)(st->script->script_buf+st->pos)); + while(st->script->script_buf[st->pos++]); + break; + case C_FUNC: + run_func(st); + if(st->state==GOTO){ + st->state = RUN; + if( !st->freeloop && gotocount>0 && (--gotocount)<=0 ){ + ShowError("run_script: infinity loop !\n"); + script_reportsrc(st); + st->state=END; + } } - } - break; + break; - case C_REF: - st->op2ref = 1; - break; + case C_REF: + st->op2ref = 1; + break; - case C_NEG: - case C_NOT: - case C_LNOT: - op_1(st ,c); - break; + case C_NEG: + case C_NOT: + case C_LNOT: + op_1(st ,c); + break; - case C_ADD: - case C_SUB: - case C_MUL: - case C_DIV: - case C_MOD: - case C_EQ: - case C_NE: - case C_GT: - case C_GE: - case C_LT: - case C_LE: - case C_AND: - case C_OR: - case C_XOR: - case C_LAND: - case C_LOR: - case C_R_SHIFT: - case C_L_SHIFT: - op_2(st, c); - break; + case C_ADD: + case C_SUB: + case C_MUL: + case C_DIV: + case C_MOD: + case C_EQ: + case C_NE: + case C_GT: + case C_GE: + case C_LT: + case C_LE: + case C_AND: + case C_OR: + case C_XOR: + case C_LAND: + case C_LOR: + case C_R_SHIFT: + case C_L_SHIFT: + op_2(st, c); + break; - case C_OP3: - op_3(st, c); - break; + case C_OP3: + op_3(st, c); + break; - case C_NOP: - st->state=END; - break; + case C_NOP: + st->state=END; + break; - default: - ShowError("unknown command : %d @ %d\n",c,st->pos); - st->state=END; - break; + default: + ShowError("unknown command : %d @ %d\n",c,st->pos); + st->state=END; + break; } if( !st->freeloop && cmdcount>0 && (--cmdcount)<=0 ){ ShowError("run_script: infinity loop !\n"); @@ -3564,13 +3501,11 @@ void run_script_main(struct script_state *st) //Restore previous script script_detach_state(st, false); //Delay execution - sd = map_id2sd(st->rid); // Get sd since script might have attached someone while running. [Inkfish] + sd = iMap->id2sd(st->rid); // Get sd since script might have attached someone while running. [Inkfish] st->sleep.charid = sd?sd->status.char_id:0; - st->sleep.timer = add_timer(gettick()+st->sleep.tick, + st->sleep.timer = iTimer->add_timer(iTimer->gettick()+st->sleep.tick, run_script_timer, st->sleep.charid, (intptr_t)st); - linkdb_insert(&sleep_db, (void*)__64BPTRSIZE(st->oid), st); - } - else if(st->state != END && st->rid){ + } else if(st->state != END && st->rid){ //Resume later (st is already attached to player). if(st->bk_st) { ShowWarning("Unable to restore stack! Double continuation!\n"); @@ -3585,8 +3520,7 @@ void run_script_main(struct script_state *st) } } else { //Dispose of script. - if ((sd = map_id2sd(st->rid))!=NULL) - { //Restore previous stack and save char. + if ((sd = iMap->id2sd(st->rid))!=NULL) { //Restore previous stack and save char. if(sd->state.using_fake_npc){ clif->clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd); sd->state.using_fake_npc = 0; @@ -3705,14 +3639,14 @@ void script_cleararray_pc(struct map_session_data* sd, const char* varname, void { for( idx = 0; idx < SCRIPT_MAX_ARRAYSIZE; idx++ ) { - pc_setregstr(sd, reference_uid(key, idx), (const char*)value); + pc->setregstr(sd, reference_uid(key, idx), (const char*)value); } } else { for( idx = 0; idx < SCRIPT_MAX_ARRAYSIZE; idx++ ) { - pc_setreg(sd, reference_uid(key, idx), (int)__64BPTRSIZE(value)); + pc->setreg(sd, reference_uid(key, idx), (int)__64BPTRSIZE(value)); } } } @@ -3740,11 +3674,11 @@ void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 if( is_string_variable(varname) ) { - pc_setregstr(sd, reference_uid(key, idx), (const char*)value); + pc->setregstr(sd, reference_uid(key, idx), (const char*)value); } else { - pc_setreg(sd, reference_uid(key, idx), (int)__64BPTRSIZE(value)); + pc->setreg(sd, reference_uid(key, idx), (int)__64BPTRSIZE(value)); } if( refcache ) @@ -3757,6 +3691,9 @@ void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 *------------------------------------------*/ void do_final_script(void) { int i; + DBIterator *iter; + struct script_state *st; + #ifdef DEBUG_HASH if (battle_config.etc_log) { @@ -3773,7 +3710,7 @@ void do_final_script(void) { memset(count, 0, sizeof(count)); fprintf(fp,"num : hash : data_name\n"); fprintf(fp,"---------------------------------------------------------------\n"); - for(i=LABEL_START; i<str_num; i++) { + for(i=LABEL_START; i<script->str_num; i++) { unsigned int h = calc_hash(get_str(i)); fprintf(fp,"%04d : %4u : %s\n",i,h, get_str(i)); ++count[h]; @@ -3817,20 +3754,19 @@ void do_final_script(void) { db_destroy(scriptlabel_db); userfunc_db->destroy(userfunc_db, db_script_free_code_sub); autobonus_db->destroy(autobonus_db, db_script_free_code_sub); - if(sleep_db) { - struct linkdb_node *n = (struct linkdb_node *)sleep_db; - while(n) { - struct script_state *st = (struct script_state *)n->data; - script_free_state(st); - n = n->next; - } - linkdb_final(&sleep_db); - } - if (str_data) - aFree(str_data); - if (str_buf) - aFree(str_buf); + iter = db_iterator(script->st_db); + + for( st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter) ) { + script_free_state(st); + } + + dbi_destroy(iter); + + if (script->str_data) + aFree(script->str_data); + if (script->str_buf) + aFree(script->str_buf); for( i = 0; i < atcommand->binding_count; i++ ) { aFree(atcommand->binding[i]); @@ -3845,17 +3781,48 @@ void do_final_script(void) { script->buildin[i] = NULL; } } - - aFree(script->buildin); + aFree(script->buildin); + + if( script->hqs ) { + for( i = 0; i < script->hqs; i++ ) { + if( script->hq[i].item != NULL ) + aFree(script->hq[i].item); + } + } + if( script->hqis ) { + for( i = 0; i < script->hqis; i++ ) { + if( script->hqi[i].item != NULL ) + aFree(script->hqi[i].item); + } + } + if( script->hq != NULL ) + aFree(script->hq); + if( script->hqi != NULL ) + aFree(script->hqi); + if( script->word_buf != NULL ) + aFree(script->word_buf); + + ers_destroy(script->st_ers); + ers_destroy(script->stack_ers); + + db_destroy(script->st_db); } /*========================================== * Initialization *------------------------------------------*/ void do_init_script(void) { + script->st_db = idb_alloc(DB_OPT_BASE); userfunc_db = strdb_alloc(DB_OPT_DUP_KEY,0); scriptlabel_db = strdb_alloc(DB_OPT_DUP_KEY,50); autobonus_db = strdb_alloc(DB_OPT_DUP_KEY,0); + + script->st_ers = ers_new(sizeof(struct script_state), "script.c::st_ers", ERS_OPT_NONE); + script->stack_ers = ers_new(sizeof(struct script_stack), "script.c::script_stack", ERS_OPT_NONE); + + ers_chunk_size(script->st_ers, 10); + ers_chunk_size(script->stack_ers, 10); + script->parse_builtin(); read_constdb(); mapreg_init(); @@ -3863,6 +3830,8 @@ void do_init_script(void) { int script_reload() { int i; + DBIterator *iter; + struct script_state *st; userfunc_db->clear(userfunc_db, db_script_free_code_sub); db_clear(scriptlabel_db); @@ -3876,15 +3845,16 @@ int script_reload() { atcommand->binding_count = 0; - if(sleep_db) { - struct linkdb_node *n = (struct linkdb_node *)sleep_db; - while(n) { - struct script_state *st = (struct script_state *)n->data; - script_free_state(st); - n = n->next; - } - linkdb_final(&sleep_db); + iter = db_iterator(script->st_db); + + for( st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter) ) { + script_free_state(st); } + + dbi_destroy(iter); + + db_clear(script->st_db); + mapreg_reload(); return 0; } @@ -3904,22 +3874,17 @@ int script_reload() { /// If a dialog doesn't exist yet, one is created. /// /// mes "<message>"; -BUILDIN(mes) -{ +BUILDIN(mes) { TBL_PC* sd = script_rid2sd(st); if( sd == NULL ) return true; - if( !script_hasdata(st, 3) ) - {// only a single line detected in the script + if( !script_hasdata(st, 3) ) {// only a single line detected in the script clif->scriptmes(sd, st->oid, script_getstr(st, 2)); - } - else - {// parse multiple lines as they exist + } else {// parse multiple lines as they exist int i; - for( i = 2; script_hasdata(st, i); i++ ) - { + for( i = 2; script_hasdata(st, i); i++ ) { // send the message to the client clif->scriptmes(sd, st->oid, script_getstr(st, i)); } @@ -3951,15 +3916,14 @@ BUILDIN(next) /// The dialog is closed when the button is pressed. /// /// close; -BUILDIN(close) -{ +BUILDIN(close) { TBL_PC* sd; sd = script_rid2sd(st); if( sd == NULL ) return true; - st->state = CLOSE; + st->state = sd->state.dialog == 1 ? CLOSE : END; clif->scriptclose(sd, st->oid); return true; } @@ -3968,8 +3932,7 @@ BUILDIN(close) /// The dialog is closed and the script continues when the button is pressed. /// /// close2; -BUILDIN(close2) -{ +BUILDIN(close2) { TBL_PC* sd; sd = script_rid2sd(st); @@ -4093,7 +4056,7 @@ BUILDIN(menu) * menus beyond this length crash the client (see bugreport:6402) **/ if( StrBuf->Length(&buf) >= 2047 ) { - struct npc_data * nd = map_id2nd(st->oid); + struct npc_data * nd = iMap->id2nd(st->oid); char* menu; CREATE(menu, char, 2048); safestrncpy(menu, StrBuf->Value(&buf), 2047); @@ -4149,7 +4112,7 @@ BUILDIN(menu) st->state = END; return false; } - pc_setreg(sd, add_str("@menu"), menu); + pc->setreg(sd, add_str("@menu"), menu); st->pos = script_getnum(st, i + 1); st->state = GOTO; } @@ -4198,7 +4161,7 @@ BUILDIN(select) * menus beyond this length crash the client (see bugreport:6402) **/ if( StrBuf->Length(&buf) >= 2047 ) { - struct npc_data * nd = map_id2nd(st->oid); + struct npc_data * nd = iMap->id2nd(st->oid); char* menu; CREATE(menu, char, 2048); safestrncpy(menu, StrBuf->Value(&buf), 2047); @@ -4226,7 +4189,7 @@ BUILDIN(select) if( sd->npc_menu <= 0 ) break;// entry found } - pc_setreg(sd, add_str("@menu"), menu); + pc->setreg(sd, add_str("@menu"), menu); script_pushint(st, menu); st->state = RUN; } @@ -4277,7 +4240,7 @@ BUILDIN(prompt) * menus beyond this length crash the client (see bugreport:6402) **/ if( StrBuf->Length(&buf) >= 2047 ) { - struct npc_data * nd = map_id2nd(st->oid); + struct npc_data * nd = iMap->id2nd(st->oid); char* menu; CREATE(menu, char, 2048); safestrncpy(menu, StrBuf->Value(&buf), 2047); @@ -4297,7 +4260,7 @@ BUILDIN(prompt) else if( sd->npc_menu == 0xff ) {// Cancel was pressed sd->state.menu_or_input = 0; - pc_setreg(sd, add_str("@menu"), 0xff); + pc->setreg(sd, add_str("@menu"), 0xff); script_pushint(st, 0xff); st->state = RUN; } @@ -4313,7 +4276,7 @@ BUILDIN(prompt) if( sd->npc_menu <= 0 ) break;// entry found } - pc_setreg(sd, add_str("@menu"), menu); + pc->setreg(sd, add_str("@menu"), menu); script_pushint(st, menu); st->state = RUN; } @@ -4363,7 +4326,7 @@ BUILDIN(callfunc) for( i = st->start+3, j = 0; i < st->end; i++, j++ ) { - struct script_data* data = push_copy(st->stack,i); + struct script_data* data = script->push_copy(st->stack,i); if( data_isreference(data) && !data->ref ) { const char* name = reference_getname(data); @@ -4411,7 +4374,7 @@ BUILDIN(callsub) for( i = st->start+3, j = 0; i < st->end; i++, j++ ) { - struct script_data* data = push_copy(st->stack,i); + struct script_data* data = script->push_copy(st->stack,i); if( data_isreference(data) && !data->ref ) { const char* name = reference_getname(data); @@ -4461,7 +4424,7 @@ BUILDIN(getarg) idx = script_getnum(st,2); if( idx >= 0 && idx < ri->nargs ) - push_copy(st->stack, st->stack->defsp - 1 - ri->nargs + idx); + script->push_copy(st->stack, st->stack->defsp - 1 - ri->nargs + idx); else if( script_hasdata(st,3) ) script_pushcopy(st, 3); else @@ -4492,7 +4455,7 @@ BUILDIN(return) if( name[0] == '.' && name[1] == '@' ) {// scope variable if( !data->ref || data->ref == (DBMap**)&st->stack->var_function ) - get_val(st, data);// current scope, convert to value + script->get_val(st, data);// current scope, convert to value } else if( name[0] == '.' && !data->ref ) {// script variable, link to current script @@ -4559,11 +4522,11 @@ BUILDIN(warp) y = script_getnum(st,4); if(strcmp(str,"Random")==0) - ret = pc_randomwarp(sd,CLR_TELEPORT); + ret = pc->randomwarp(sd,CLR_TELEPORT); else if(strcmp(str,"SavePoint")==0 || strcmp(str,"Save")==0) - ret = pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); + ret = pc->setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); else - ret = pc_setpos(sd,mapindex_name2id(str),x,y,CLR_OUTSIGHT); + ret = pc->setpos(sd,mapindex_name2id(str),x,y,CLR_OUTSIGHT); if( ret ) { ShowError("buildin_warp: moving player '%s' to \"%s\",%d,%d failed.\n", sd->status.name, str, x, y); @@ -4587,7 +4550,7 @@ static int buildin_areawarp_sub(struct block_list *bl,va_list ap) y3 = va_arg(ap,int); if(index == 0) - pc_randomwarp((TBL_PC *)bl,CLR_TELEPORT); + pc->randomwarp((TBL_PC *)bl,CLR_TELEPORT); else if(x3 && y3) { int max, tx, ty, j = 0; @@ -4600,12 +4563,12 @@ static int buildin_areawarp_sub(struct block_list *bl,va_list ap) tx = rnd()%(x3-x2+1)+x2; ty = rnd()%(y3-y2+1)+y2; j++; - } while( map_getcell(index,tx,ty,CELL_CHKNOPASS) && j < max ); + } while( iMap->getcell(index,tx,ty,CELL_CHKNOPASS) && j < max ); - pc_setpos((TBL_PC *)bl,index,tx,ty,CLR_OUTSIGHT); + pc->setpos((TBL_PC *)bl,index,tx,ty,CLR_OUTSIGHT); } else - pc_setpos((TBL_PC *)bl,index,x2,y2,CLR_OUTSIGHT); + pc->setpos((TBL_PC *)bl,index,x2,y2,CLR_OUTSIGHT); return 0; } BUILDIN(areawarp) @@ -4635,7 +4598,7 @@ BUILDIN(areawarp) } } - if( (m = map_mapname2mapid(mapname)) < 0 ) + if( (m = iMap->mapname2mapid(mapname)) < 0 ) return true; if( strcmp(str,"Random") == 0 ) @@ -4643,7 +4606,7 @@ BUILDIN(areawarp) else if( !(index=mapindex_name2id(str)) ) return true; - map_foreachinarea(buildin_areawarp_sub, m,x0,y0,x1,y1, BL_PC, index,x2,y2,x3,y3); + iMap->foreachinarea(buildin_areawarp_sub, m,x0,y0,x1,y1, BL_PC, index,x2,y2,x3,y3); return true; } @@ -4655,7 +4618,7 @@ static int buildin_areapercentheal_sub(struct block_list *bl,va_list ap) int hp, sp; hp = va_arg(ap, int); sp = va_arg(ap, int); - pc_percentheal((TBL_PC *)bl,hp,sp); + pc->percentheal((TBL_PC *)bl,hp,sp); return 0; } BUILDIN(areapercentheal) @@ -4672,10 +4635,10 @@ BUILDIN(areapercentheal) hp=script_getnum(st,7); sp=script_getnum(st,8); - if( (m=map_mapname2mapid(mapname))< 0) + if( (m=iMap->mapname2mapid(mapname))< 0) return true; - map_foreachinarea(buildin_areapercentheal_sub,m,x0,y0,x1,y1,BL_PC,hp,sp); + iMap->foreachinarea(buildin_areapercentheal_sub,m,x0,y0,x1,y1,BL_PC,hp,sp); return true; } @@ -4696,17 +4659,17 @@ BUILDIN(warpchar) y=script_getnum(st,4); a=script_getnum(st,5); - sd = map_charid2sd(a); + sd = iMap->charid2sd(a); if( sd == NULL ) return true; if(strcmp(str, "Random") == 0) - pc_randomwarp(sd, CLR_TELEPORT); + pc->randomwarp(sd, CLR_TELEPORT); else if(strcmp(str, "SavePoint") == 0) - pc_setpos(sd, sd->status.save_point.map,sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT); + pc->setpos(sd, sd->status.save_point.map,sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT); else - pc_setpos(sd, mapindex_name2id(str), x, y, CLR_TELEPORT); + pc->setpos(sd, mapindex_name2id(str), x, y, CLR_TELEPORT); return true; } @@ -4732,7 +4695,7 @@ BUILDIN(warpparty) if ( script_hasdata(st,6) ) str2 = script_getstr(st,6); - p = party_search(p_id); + p = party->search(p_id); if(!p) return true; @@ -4780,20 +4743,20 @@ BUILDIN(warpparty) { case 0: // Random if(!map[pl_sd->bl.m].flag.nowarp) - pc_randomwarp(pl_sd,CLR_TELEPORT); + pc->randomwarp(pl_sd,CLR_TELEPORT); break; case 1: // SavePointAll if(!map[pl_sd->bl.m].flag.noreturn) - pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT); + pc->setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT); break; case 2: // SavePoint if(!map[pl_sd->bl.m].flag.noreturn) - pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); + pc->setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); break; case 3: // Leader case 4: // m,x,y if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp) - pc_setpos(pl_sd,mapindex,x,y,CLR_TELEPORT); + pc->setpos(pl_sd,mapindex,x,y,CLR_TELEPORT); break; } } @@ -4841,19 +4804,19 @@ BUILDIN(warpguild) { case 0: // Random if(!map[pl_sd->bl.m].flag.nowarp) - pc_randomwarp(pl_sd,CLR_TELEPORT); + pc->randomwarp(pl_sd,CLR_TELEPORT); break; case 1: // SavePointAll if(!map[pl_sd->bl.m].flag.noreturn) - pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT); + pc->setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT); break; case 2: // SavePoint if(!map[pl_sd->bl.m].flag.noreturn) - pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); + pc->setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); break; case 3: // m,x,y if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp) - pc_setpos(pl_sd,mapindex_name2id(str),x,y,CLR_TELEPORT); + pc->setpos(pl_sd,mapindex_name2id(str),x,y,CLR_TELEPORT); break; } } @@ -4896,7 +4859,7 @@ BUILDIN(itemheal) sd = script_rid2sd(st); if (!sd) return true; - pc_itemheal(sd,sd->itemid,hp,sp); + pc->itemheal(sd,sd->itemid,hp,sp); return true; } /*========================================== @@ -4923,7 +4886,7 @@ BUILDIN(percentheal) if( sd->sc.data[SC_EXTREMITYFIST2] ) sp = 0; #endif - pc_percentheal(sd,hp,sp); + pc->percentheal(sd,hp,sp); return true; } @@ -4946,7 +4909,7 @@ BUILDIN(jobchange) if( sd == NULL ) return true; - pc_jobchange(sd, job, upper); + pc->jobchange(sd, job, upper); } return true; @@ -4958,7 +4921,7 @@ BUILDIN(jobchange) BUILDIN(jobname) { int class_=script_getnum(st,2); - script_pushconststr(st, (char*)job_name(class_)); + script_pushconststr(st, (char*)pc->job_name(class_)); return true; } @@ -5087,7 +5050,7 @@ BUILDIN(set) } // push the maximum number of array values to the stack - push_val(st->stack, C_INT, SCRIPT_MAX_ARRAYSIZE); + script->push_val(st->stack, C_INT, SCRIPT_MAX_ARRAYSIZE,NULL); // call the copy array method directly return buildin_copyarray(st); @@ -5119,7 +5082,7 @@ static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isst { for( ; idx < SCRIPT_MAX_ARRAYSIZE; ++idx ) { - char* str = (char*)get_val2(st, reference_uid(id, idx), ref); + char* str = (char*)script->get_val2(st, reference_uid(id, idx), ref); if( str && *str ) ret = idx + 1; script_removetop(st, -1, 0); @@ -5129,7 +5092,7 @@ static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isst { for( ; idx < SCRIPT_MAX_ARRAYSIZE; ++idx ) { - int32 num = (int32)__64BPTRSIZE(get_val2(st, reference_uid(id, idx), ref)); + int32 num = (int32)__64BPTRSIZE(script->get_val2(st, reference_uid(id, idx), ref)); if( num ) ret = idx + 1; script_removetop(st, -1, 0); @@ -5322,7 +5285,7 @@ BUILDIN(copyarray) {// destination might be overlapping the source - copy in reverse order for( i = count - 1; i >= 0; --i ) { - v = get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); + v = script->get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1)); script_removetop(st, -1, 0); } @@ -5333,7 +5296,7 @@ BUILDIN(copyarray) { if( idx2 + i < SCRIPT_MAX_ARRAYSIZE ) { - v = get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); + v = script->get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1)); script_removetop(st, -1, 0); } @@ -5435,7 +5398,7 @@ BUILDIN(deletearray) // move rest of the elements backward for( ; start + count < end; ++start ) { - void* v = get_val2(st, reference_uid(id, start + count), reference_getref(data)); + void* v = script->get_val2(st, reference_uid(id, start + count), reference_getref(data)); set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data)); script_removetop(st, -1, 0); } @@ -5497,7 +5460,7 @@ BUILDIN(getelementofarray) return false;// out of range } - push_val2(st->stack, C_NAME, reference_uid(id, i), reference_getref(data)); + script->push_val(st->stack, C_NAME, reference_uid(id, i), reference_getref(data)); return true; } @@ -5520,7 +5483,7 @@ BUILDIN(setlook) if( sd == NULL ) return true; - pc_changelook(sd,type,val); + pc->changelook(sd,type,val); return true; } @@ -5597,7 +5560,7 @@ BUILDIN(countitem) } data = script_getdata(st,2); - get_val(st, data); // convert into value in case of a variable + script->get_val(st, data); // convert into value in case of a variable if( data_isstring(data) ) {// item name @@ -5644,7 +5607,7 @@ BUILDIN(countitem2) } data = script_getdata(st,2); - get_val(st, data); // convert into value in case of a variable + script->get_val(st, data); // convert into value in case of a variable if( data_isstring(data) ) {// item name @@ -5709,11 +5672,11 @@ BUILDIN(checkweight) script_pushint(st,0); return false; } - slots = pc_inventoryblank(sd); //nb of empty slot + slots = pc->inventoryblank(sd); //nb of empty slot for(i=2; i<nbargs; i=i+2){ data = script_getdata(st,i); - get_val(st, data); // convert into value in case of a variable + script->get_val(st, data); // convert into value in case of a variable if( data_isstring(data) ){// item name id = itemdb_searchname(script->conv_str(st, data)); } else {// item id @@ -5740,7 +5703,7 @@ BUILDIN(checkweight) return true; } - switch( pc_checkadditem(sd, nameid, amount) ) + switch( pc->checkadditem(sd, nameid, amount) ) { case ADDITEM_EXIST: // item is already in inventory, but there is still space for the requested amount @@ -5823,11 +5786,11 @@ BUILDIN(checkweight2) fail = 1; } - slots = pc_inventoryblank(sd); + slots = pc->inventoryblank(sd); for(i=0; i<nb_it; i++){ - nameid = (int32)__64BPTRSIZE(get_val2(st,reference_uid(id_it,idx_it+i),reference_getref(data_it))); + nameid = (int32)__64BPTRSIZE(script->get_val2(st,reference_uid(id_it,idx_it+i),reference_getref(data_it))); script_removetop(st, -1, 0); - amount = (int32)__64BPTRSIZE(get_val2(st,reference_uid(id_nb,idx_nb+i),reference_getref(data_nb))); + amount = (int32)__64BPTRSIZE(script->get_val2(st,reference_uid(id_nb,idx_nb+i),reference_getref(data_nb))); script_removetop(st, -1, 0); if(fail) continue; //cpntonie to depop rest @@ -5846,7 +5809,7 @@ BUILDIN(checkweight2) fail = 1; continue; } - switch( pc_checkadditem(sd, nameid, amount) ) { + switch( pc->checkadditem(sd, nameid, amount) ) { case ADDITEM_EXIST: // item is already in inventory, but there is still space for the requested amount break; @@ -5885,7 +5848,7 @@ BUILDIN(getitem) struct item_data *item_data; data=script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ) {// "<item name>" const char *name=script->conv_str(st,data); @@ -5922,7 +5885,7 @@ BUILDIN(getitem) it.identify=itemdb_isidentified2(item_data); if( script_hasdata(st,4) ) - sd=map_id2sd(script_getnum(st,4)); // <Account ID> + sd=iMap->id2sd(script_getnum(st,4)); // <Account ID> else sd=script_rid2sd(st); // Attached player @@ -5940,11 +5903,11 @@ BUILDIN(getitem) // if not pet egg if (!pet_create_egg(sd, nameid)) { - if ((flag = pc_additem(sd, &it, get_count, LOG_TYPE_SCRIPT))) + if ((flag = pc->additem(sd, &it, get_count, LOG_TYPE_SCRIPT))) { clif->additem(sd, 0, 0, flag); - if( pc_candrop(sd,&it) ) - map_addflooritem(&it,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + if( pc->candrop(sd,&it) ) + iMap->addflooritem(&it,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } @@ -5965,7 +5928,7 @@ BUILDIN(getitem2) struct script_data *data; if( script_hasdata(st,11) ) - sd=map_id2sd(script_getnum(st,11)); // <Account ID> + sd=iMap->id2sd(script_getnum(st,11)); // <Account ID> else sd=script_rid2sd(st); // Attached player @@ -5973,7 +5936,7 @@ BUILDIN(getitem2) return true; data=script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ){ const char *name=script->conv_str(st,data); struct item_data *item_data = itemdb_searchname(name); @@ -6038,11 +6001,11 @@ BUILDIN(getitem2) // if not pet egg if (!pet_create_egg(sd, nameid)) { - if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) + if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) { clif->additem(sd, 0, 0, flag); - if( pc_candrop(sd,&item_tmp) ) - map_addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + if( pc->candrop(sd,&item_tmp) ) + iMap->addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } @@ -6064,7 +6027,7 @@ BUILDIN(rentitem) int nameid = 0, flag; data = script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( (sd = script_rid2sd(st)) == NULL ) return true; @@ -6101,7 +6064,7 @@ BUILDIN(rentitem) it.identify = 1; it.expire_time = (unsigned int)(time(NULL) + seconds); - if( (flag = pc_additem(sd, &it, 1, LOG_TYPE_SCRIPT)) ) + if( (flag = pc->additem(sd, &it, 1, LOG_TYPE_SCRIPT)) ) { clif->additem(sd, 0, 0, flag); return false; @@ -6131,7 +6094,7 @@ BUILDIN(getnameditem) } data=script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ){ const char *name=script->conv_str(st,data); struct item_data *item_data = itemdb_searchname(name); @@ -6151,11 +6114,11 @@ BUILDIN(getnameditem) } data=script_getdata(st,3); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ) //Char Name - tsd=map_nick2sd(script->conv_str(st,data)); + tsd=iMap->nick2sd(script->conv_str(st,data)); else //Char Id was given - tsd=map_charid2sd(script->conv_num(st,data)); + tsd=iMap->charid2sd(script->conv_num(st,data)); if( tsd == NULL ) { //Failed @@ -6170,7 +6133,7 @@ BUILDIN(getnameditem) item_tmp.card[0]=CARD0_CREATE; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus] item_tmp.card[2]=tsd->status.char_id; item_tmp.card[3]=tsd->status.char_id >> 16; - if(pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT)) { + if(pc->additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT)) { script_pushint(st,0); return true; //Failed to add item, we will not drop if they don't fit } @@ -6205,7 +6168,7 @@ BUILDIN(makeitem) struct item_data *item_data; data=script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ){ const char *name=script->conv_str(st,data); if( (item_data = itemdb_searchname(name)) ) @@ -6231,7 +6194,7 @@ BUILDIN(makeitem) if (!sd) return true; //Failed... m=sd->bl.m; } else - m=map_mapname2mapid(mapname); + m=iMap->mapname2mapid(mapname); memset(&item_tmp,0,sizeof(item_tmp)); item_tmp.nameid=nameid; @@ -6240,7 +6203,7 @@ BUILDIN(makeitem) else item_tmp.identify=itemdb_isidentified2(item_data); - map_addflooritem(&item_tmp,amount,m,x,y,0,0,0,0); + iMap->addflooritem(&item_tmp,amount,m,x,y,0,0,0,0); return true; } @@ -6262,7 +6225,7 @@ static void buildin_delitem_delete(struct map_session_data* sd, int idx, int* am {// delete associated pet intif_delete_petdata(MakeDWord(inv->card[1], inv->card[2])); } - pc_delitem(sd, idx, delamount, 0, 0, LOG_TYPE_SCRIPT); + pc->delitem(sd, idx, delamount, 0, 0, LOG_TYPE_SCRIPT); } amount[0]-= delamount; @@ -6401,7 +6364,7 @@ BUILDIN(delitem) if( script_hasdata(st,4) ) { int account_id = script_getnum(st,4); - sd = map_id2sd(account_id); // <account id> + sd = iMap->id2sd(account_id); // <account id> if( sd == NULL ) { ShowError("script:delitem: player not found (AID=%d).\n", account_id); @@ -6417,7 +6380,7 @@ BUILDIN(delitem) } data = script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ) { const char* item_name = script->conv_str(st,data); @@ -6470,7 +6433,7 @@ BUILDIN(delitem2) if( script_hasdata(st,11) ) { int account_id = script_getnum(st,11); - sd = map_id2sd(account_id); // <account id> + sd = iMap->id2sd(account_id); // <account id> if( sd == NULL ) { ShowError("script:delitem2: player not found (AID=%d).\n", account_id); @@ -6486,7 +6449,7 @@ BUILDIN(delitem2) } data = script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ) { const char* item_name = script->conv_str(st,data); @@ -6556,7 +6519,7 @@ BUILDIN(disableitemuse) /*========================================== * return the basic stats of sd - * chk pc_readparam for available type + * chk pc->readparam for available type *------------------------------------------*/ BUILDIN(readparam) { @@ -6565,7 +6528,7 @@ BUILDIN(readparam) type=script_getnum(st,2); if( script_hasdata(st,3) ) - sd=map_nick2sd(script_getstr(st,3)); + sd=iMap->nick2sd(script_getstr(st,3)); else sd=script_rid2sd(st); @@ -6574,7 +6537,7 @@ BUILDIN(readparam) return true; } - script_pushint(st,pc_readparam(sd,type)); + script_pushint(st,pc->readparam(sd,type)); return true; } @@ -6595,7 +6558,7 @@ BUILDIN(getcharid) num = script_getnum(st,2); if( script_hasdata(st,3) ) - sd=map_nick2sd(script_getstr(st,3)); + sd=iMap->nick2sd(script_getstr(st,3)); else sd=script_rid2sd(st); @@ -6660,7 +6623,7 @@ BUILDIN(getpartyname) party_id = script_getnum(st,2); - if( ( p = party_search(party_id) ) != NULL ) + if( ( p = party->search(party_id) ) != NULL ) { script_pushstrcopy(st,p->party.name); } @@ -6684,7 +6647,7 @@ BUILDIN(getpartymember) struct party_data *p; int i,j=0,type=0; - p=party_search(script_getnum(st,2)); + p=party->search(script_getnum(st,2)); if( script_hasdata(st,3) ) type=script_getnum(st,3); @@ -6724,7 +6687,7 @@ BUILDIN(getpartyleader) if( script_hasdata(st,3) ) type=script_getnum(st,3); - p=party_search(party_id); + p=party->search(party_id); if (p) //Search leader for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++); @@ -6837,7 +6800,7 @@ BUILDIN(strcharinfo) script_pushstrcopy(st,sd->status.name); break; case 1: - if( ( p = party_search(sd->status.party_id) ) != NULL ) { + if( ( p = party->search(sd->status.party_id) ) != NULL ) { script_pushstrcopy(st,p->party.name); } else { script_pushconststr(st,""); @@ -6877,7 +6840,7 @@ BUILDIN(strnpcinfo) int num; char *buf,*name=NULL; - nd = map_id2nd(st->oid); + nd = iMap->id2nd(st->oid); if (!nd) { script_pushconststr(st, ""); return true; @@ -6941,7 +6904,7 @@ BUILDIN(getequipid) } // get inventory position of item - i = pc_checkequip(sd,equip[num]); + i = pc->checkequip(sd,equip[num]); if( i < 0 ) { script_pushint(st,-1); @@ -6979,7 +6942,7 @@ BUILDIN(getequipname) } // get inventory position of item - i = pc_checkequip(sd,equip[num]); + i = pc->checkequip(sd,equip[num]); if( i < 0 ) { script_pushconststr(st,""); @@ -7098,7 +7061,7 @@ BUILDIN(getequipisequiped) return true; if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if(i >= 0) script_pushint(st,1); @@ -7125,7 +7088,7 @@ BUILDIN(getequipisenableref) return true; if( num > 0 && num <= ARRAYLENGTH(equip) ) - i = pc_checkequip(sd,equip[num-1]); + i = pc->checkequip(sd,equip[num-1]); if( i >= 0 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine && !sd->status.inventory[i].expire_time ) script_pushint(st,1); else @@ -7151,7 +7114,7 @@ BUILDIN(getequipisidentify) return true; if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if(i >= 0) script_pushint(st,sd->status.inventory[i].identify); else @@ -7177,7 +7140,7 @@ BUILDIN(getequiprefinerycnt) return true; if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if(i >= 0) script_pushint(st,sd->status.inventory[i].refine); else @@ -7204,7 +7167,7 @@ BUILDIN(getequipweaponlv) return true; if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if(i >= 0 && sd->inventory_data[i]) script_pushint(st,sd->inventory_data[i]->wlv); else @@ -7230,7 +7193,7 @@ BUILDIN(getequippercentrefinery) return true; if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE) script_pushint(st,status_get_refine_chance(itemdb_wlv(sd->status.inventory[i].nameid), (int)sd->status.inventory[i].refine)); else @@ -7253,15 +7216,18 @@ BUILDIN(successrefitem) return true; if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if(i >= 0) { ep=sd->status.inventory[i].equip; //Logs items, got from (N)PC scripts [Lupus] logs->pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i],sd->inventory_data[i]); + if (sd->status.inventory[i].refine >= MAX_REFINE) + return true; + sd->status.inventory[i].refine++; - pc_unequipitem(sd,i,2); // status calc will happen in pc_equipitem() below + pc->unequipitem(sd,i,2); // status calc will happen in pc->equipitem() below clif->refine(sd->fd,0,i,sd->status.inventory[i].refine); clif->delitem(sd,i,1,3); @@ -7270,21 +7236,21 @@ BUILDIN(successrefitem) logs->pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[i],sd->inventory_data[i]); clif->additem(sd,i,1,0); - pc_equipitem(sd,i,ep); + pc->equipitem(sd,i,ep); clif->misceffect(&sd->bl,3); - if(sd->status.inventory[i].refine == MAX_REFINE && + if(sd->status.inventory[i].refine == 10 && sd->status.inventory[i].card[0] == CARD0_FORGE && sd->status.char_id == (int)MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3]) ){ // Fame point system [DracoRPG] switch (sd->inventory_data[i]->wlv){ case 1: - pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point + pc->addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point break; case 2: - pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point + pc->addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point break; case 3: - pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point + pc->addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point break; } } @@ -7307,13 +7273,13 @@ BUILDIN(failedrefitem) return true; if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if(i >= 0) { sd->status.inventory[i].refine = 0; - pc_unequipitem(sd,i,3); //recalculate bonus + pc->unequipitem(sd,i,3); //recalculate bonus clif->refine(sd->fd,1,i,sd->status.inventory[i].refine); //notify client of failure - pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); + pc->delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); clif->misceffect(&sd->bl,2); // display failure effect } @@ -7335,7 +7301,7 @@ BUILDIN(downrefitem) return true; if (num > 0 && num <= ARRAYLENGTH(equip)) - i = pc_checkequip(sd,equip[num-1]); + i = pc->checkequip(sd,equip[num-1]); if(i >= 0) { ep = sd->status.inventory[i].equip; @@ -7343,7 +7309,7 @@ BUILDIN(downrefitem) logs->pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i],sd->inventory_data[i]); sd->status.inventory[i].refine++; - pc_unequipitem(sd,i,2); // status calc will happen in pc_equipitem() below + pc->unequipitem(sd,i,2); // status calc will happen in pc->equipitem() below clif->refine(sd->fd,2,i,sd->status.inventory[i].refine = sd->status.inventory[i].refine - 2); clif->delitem(sd,i,1,3); @@ -7352,7 +7318,7 @@ BUILDIN(downrefitem) logs->pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[i],sd->inventory_data[i]); clif->additem(sd,i,1,0); - pc_equipitem(sd,i,ep); + pc->equipitem(sd,i,ep); clif->misceffect(&sd->bl,2); } @@ -7373,10 +7339,10 @@ BUILDIN(delequip) return true; if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if(i >= 0) { - pc_unequipitem(sd,i,3); //recalculate bonus - pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); + pc->unequipitem(sd,i,3); //recalculate bonus + pc->delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); } return true; @@ -7395,7 +7361,7 @@ BUILDIN(statusup) if( sd == NULL ) return true; - pc_statusup(sd,type); + pc->statusup(sd,type); return true; } @@ -7413,7 +7379,7 @@ BUILDIN(statusup2) if( sd == NULL ) return true; - pc_statusup2(sd,type,val); + pc->statusup2(sd,type,val); return true; } @@ -7467,16 +7433,16 @@ BUILDIN(bonus) switch( script_lastdata(st)-2 ) { case 1: - pc_bonus(sd, type, val1); + pc->bonus(sd, type, val1); break; case 2: val2 = script_getnum(st,4); - pc_bonus2(sd, type, val1, val2); + pc->bonus2(sd, type, val1, val2); break; case 3: val2 = script_getnum(st,4); val3 = script_getnum(st,5); - pc_bonus3(sd, type, val1, val2, val3); + pc->bonus3(sd, type, val1, val2, val3); break; case 4: if( type == SP_AUTOSPELL_ONSKILL && script_isstring(st,4) ) @@ -7486,7 +7452,7 @@ BUILDIN(bonus) val3 = script_getnum(st,5); val4 = script_getnum(st,6); - pc_bonus4(sd, type, val1, val2, val3, val4); + pc->bonus4(sd, type, val1, val2, val3, val4); break; case 5: if( type == SP_AUTOSPELL_ONSKILL && script_isstring(st,4) ) @@ -7497,7 +7463,7 @@ BUILDIN(bonus) val3 = script_getnum(st,5); val4 = script_getnum(st,6); val5 = script_getnum(st,7); - pc_bonus5(sd, type, val1, val2, val3, val4, val5); + pc->bonus5(sd, type, val1, val2, val3, val4, val5); break; default: ShowDebug("buildin_bonus: unexpected number of arguments (%d)\n", (script_lastdata(st) - 1)); @@ -7533,7 +7499,7 @@ BUILDIN(autobonus) if( script_hasdata(st,6) ) other_script = script_getstr(st,6); - if( pc_addautobonus(sd->autobonus,ARRAYLENGTH(sd->autobonus), + if( pc->addautobonus(sd->autobonus,ARRAYLENGTH(sd->autobonus), bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) ) { script_add_autobonus(bonus_script); @@ -7570,7 +7536,7 @@ BUILDIN(autobonus2) if( script_hasdata(st,6) ) other_script = script_getstr(st,6); - if( pc_addautobonus(sd->autobonus2,ARRAYLENGTH(sd->autobonus2), + if( pc->addautobonus(sd->autobonus2,ARRAYLENGTH(sd->autobonus2), bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) ) { script_add_autobonus(bonus_script); @@ -7605,7 +7571,7 @@ BUILDIN(autobonus3) if( script_hasdata(st,6) ) other_script = script_getstr(st,6); - if( pc_addautobonus(sd->autobonus3,ARRAYLENGTH(sd->autobonus3), + if( pc->addautobonus(sd->autobonus3,ARRAYLENGTH(sd->autobonus3), bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,true) ) { script_add_autobonus(bonus_script); @@ -7641,7 +7607,7 @@ BUILDIN(skill) level = script_getnum(st,3); if( script_hasdata(st,4) ) flag = script_getnum(st,4); - pc_skill(sd, id, level, flag); + pc->skill(sd, id, level, flag); return true; } @@ -7670,7 +7636,7 @@ BUILDIN(addtoskill) level = script_getnum(st,3); if( script_hasdata(st,4) ) flag = script_getnum(st,4); - pc_skill(sd, id, level, flag); + pc->skill(sd, id, level, flag); return true; } @@ -7712,7 +7678,7 @@ BUILDIN(getskilllv) return true;// no player attached, report source id = ( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); - script_pushint(st, pc_checkskill(sd,id)); + script_pushint(st, pc->checkskill(sd,id)); return true; } @@ -7760,7 +7726,7 @@ BUILDIN(getgmlevel) if( sd == NULL ) return true;// no player attached, report source - script_pushint(st, pc_get_group_level(sd)); + script_pushint(st, pc->get_group_level(sd)); return true; } @@ -7783,8 +7749,7 @@ BUILDIN(getgroupid) /// Terminates the execution of this script instance. /// /// end -BUILDIN(end) -{ +BUILDIN(end) { st->state = END; return true; } @@ -7882,9 +7847,9 @@ BUILDIN(setoption) if( flag ){// Add option if( option&OPTION_WEDDING && !battle_config.wedding_modifydisplay ) option &= ~OPTION_WEDDING;// Do not show the wedding sprites - pc_setoption(sd, sd->sc.option|option); + pc->setoption(sd, sd->sc.option|option); } else// Remove option - pc_setoption(sd, sd->sc.option&~option); + pc->setoption(sd, sd->sc.option&~option); return true; } @@ -7932,7 +7897,7 @@ BUILDIN(setcart) if( script_hasdata(st,2) ) type = script_getnum(st,2); - pc_setcart(sd, type); + pc->setcart(sd, type); return true; } @@ -7975,7 +7940,7 @@ BUILDIN(setfalcon) if( script_hasdata(st,2) ) flag = script_getnum(st,2); - pc_setfalcon(sd, flag); + pc->setfalcon(sd, flag); return true; } @@ -8017,7 +7982,7 @@ BUILDIN(setriding) if( script_hasdata(st,2) ) flag = script_getnum(st,2); - pc_setriding(sd, flag); + pc->setriding(sd, flag); return true; } @@ -8078,7 +8043,7 @@ BUILDIN(setmadogear) if( script_hasdata(st,2) ) flag = script_getnum(st,2); - pc_setmadogear(sd, flag); + pc->setmadogear(sd, flag); return true; } @@ -8104,7 +8069,7 @@ BUILDIN(savepoint) y = script_getnum(st,4); map = mapindex_name2id(str); if( map ) - pc_setsavepoint(sd, map, x, y); + pc->setsavepoint(sd, map, x, y); return true; } @@ -8135,7 +8100,7 @@ BUILDIN(gettimetick) /* Asgard Version */ case 0: default: //type 0:(System Ticks) - script_pushint(st,gettick()); + script_pushint(st,iTimer->gettick()); break; } return true; @@ -8351,7 +8316,7 @@ BUILDIN(getexp) base = (int) cap_value(base * bonus, 0, INT_MAX); job = (int) cap_value(job * bonus, 0, INT_MAX); - pc_gainexp(sd, NULL, base, job, true); + pc->gainexp(sd, NULL, base, job, true); return true; } @@ -8388,7 +8353,7 @@ BUILDIN(guildchangegm) guild_id = script_getnum(st,2); name = script_getstr(st,3); - sd=map_nick2sd(name); + sd=iMap->nick2sd(name); if (!sd) script_pushint(st,0); @@ -8454,17 +8419,14 @@ BUILDIN(monster) return false; } - sd = map_id2sd(st->rid); + sd = iMap->id2sd(st->rid); if (sd && strcmp(mapn, "this") == 0) m = sd->bl.m; - else - { - m = map_mapname2mapid(mapn); - if (map[m].flag.src4instance && st->instance_id) - { // Try to redirect to the instance map, not the src map - if ((m = instance_mapid2imapid(m, st->instance_id)) < 0) - { + else { + m = iMap->mapname2mapid(mapn); + if (map[m].flag.src4instance && st->instance_id >= 0) { // Try to redirect to the instance map, not the src map + if ((m = instance->mapid2imapid(m, st->instance_id)) < 0) { ShowError("buildin_monster: Trying to spawn monster (%d) on instance map (%s) without instance attached.\n", class_, mapn); return false; } @@ -8531,43 +8493,35 @@ BUILDIN(areamonster) struct map_session_data* sd; int16 m; - if (script_hasdata(st,10)) - { + if (script_hasdata(st,10)) { event = script_getstr(st, 10); check_event(st, event); } - if (script_hasdata(st, 11)) - { + if (script_hasdata(st, 11)) { size = script_getnum(st, 11); - if (size > 3) - { + if (size > 3) { ShowWarning("buildin_monster: Attempted to spawn non-existing size %d for monster class %d\n", size, class_); return false; } } - if (script_hasdata(st, 12)) - { + if (script_hasdata(st, 12)) { ai = script_getnum(st, 12); - if (ai > 4) - { + if (ai > 4) { ShowWarning("buildin_monster: Attempted to spawn non-existing ai %d for monster class %d\n", ai, class_); return false; } } - sd = map_id2sd(st->rid); + sd = iMap->id2sd(st->rid); if (sd && strcmp(mapn, "this") == 0) m = sd->bl.m; - else - { - m = map_mapname2mapid(mapn); - if (map[m].flag.src4instance && st->instance_id) - { // Try to redirect to the instance map, not the src map - if ((m = instance_mapid2imapid(m, st->instance_id)) < 0) - { + else { + m = iMap->mapname2mapid(mapn); + if (map[m].flag.src4instance && st->instance_id >= 0) { // Try to redirect to the instance map, not the src map + if ((m = instance->mapid2imapid(m, st->instance_id)) < 0) { ShowError("buildin_areamonster: Trying to spawn monster (%d) on instance map (%s) without instance attached.\n", class_, mapn); return false; } @@ -8626,22 +8580,22 @@ BUILDIN(killmonster) else check_event(st, event); - if( (m=map_mapname2mapid(mapname))<0 ) + if( (m=iMap->mapname2mapid(mapname))<0 ) return true; - if( map[m].flag.src4instance && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 ) + if( map[m].flag.src4instance && st->instance_id >= 0 && (m = instance->mapid2imapid(m, st->instance_id)) < 0 ) return true; if( script_hasdata(st,4) ) { if ( script_getnum(st,4) == 1 ) { - map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag); + iMap->foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag); return true; } } - map_freeblock_lock(); - map_foreachinmap(buildin_killmonster_sub_strip, m, BL_MOB, event ,allflag); - map_freeblock_unlock(); + iMap->freeblock_lock(); + iMap->foreachinmap(buildin_killmonster_sub_strip, m, BL_MOB, event ,allflag); + iMap->freeblock_unlock(); return true; } @@ -8667,20 +8621,20 @@ BUILDIN(killmonsterall) int16 m; mapname=script_getstr(st,2); - if( (m = map_mapname2mapid(mapname))<0 ) + if( (m = iMap->mapname2mapid(mapname))<0 ) return true; - if( map[m].flag.src4instance && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 ) + if( map[m].flag.src4instance && st->instance_id >= 0 && (m = instance->mapid2imapid(m, st->instance_id)) < 0 ) return true; if( script_hasdata(st,3) ) { if ( script_getnum(st,3) == 1 ) { - map_foreachinmap(buildin_killmonsterall_sub,m,BL_MOB); + iMap->foreachinmap(buildin_killmonsterall_sub,m,BL_MOB); return true; } } - map_foreachinmap(buildin_killmonsterall_sub_strip,m,BL_MOB); + iMap->foreachinmap(buildin_killmonsterall_sub_strip,m,BL_MOB); return true; } @@ -8715,13 +8669,13 @@ BUILDIN(clone) check_event(st, event); - m = map_mapname2mapid(map); + m = iMap->mapname2mapid(map); if (m < 0) return true; - sd = map_charid2sd(char_id); + sd = iMap->charid2sd(char_id); if (master_id) { - msd = map_charid2sd(master_id); + msd = iMap->charid2sd(master_id); if (msd) master_id = msd->bl.id; else @@ -8757,7 +8711,7 @@ BUILDIN(donpcevent) const char* event = script_getstr(st,2); check_event(st, event); if( !npc_event_do(event) ) { - struct npc_data * nd = map_id2nd(st->oid); + struct npc_data * nd = iMap->id2nd(st->oid); ShowDebug("NPCEvent '%s' not found! (source: %s)\n",event,nd?nd->name:"Unknown"); script_pushint(st, 0); } else @@ -8791,7 +8745,7 @@ BUILDIN(addtimer) if( sd == NULL ) return true; - pc_addeventtimer(sd,tick,event); + pc->addeventtimer(sd,tick,event); return true; } /*========================================== @@ -8807,7 +8761,7 @@ BUILDIN(deltimer) return true; check_event(st, event); - pc_deleventtimer(sd,event); + pc->deleventtimer(sd,event); return true; } /*========================================== @@ -8825,7 +8779,7 @@ BUILDIN(addtimercount) return true; check_event(st, event); - pc_addeventtimercount(sd,event,tick); + pc->addeventtimercount(sd,event,tick); return true; } @@ -8845,12 +8799,12 @@ BUILDIN(initnpctimer) { //Check if argument is numeric (flag) or string (npc name) struct script_data *data; data = script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ) //NPC name nd = npc_name2id(script->conv_str(st, data)); else if( data_isint(data) ) //Flag { - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); flag = script->conv_num(st,data); } else @@ -8860,7 +8814,7 @@ BUILDIN(initnpctimer) } } else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); if( !nd ) return true; @@ -8893,12 +8847,12 @@ BUILDIN(startnpctimer) { //Check if argument is numeric (flag) or string (npc name) struct script_data *data; data = script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ) //NPC name nd = npc_name2id(script->conv_str(st, data)); else if( data_isint(data) ) //Flag { - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); flag = script->conv_num(st,data); } else @@ -8908,7 +8862,7 @@ BUILDIN(startnpctimer) } } else - nd=(struct npc_data *)map_id2bl(st->oid); + nd=(struct npc_data *)iMap->id2bl(st->oid); if( !nd ) return true; @@ -8939,12 +8893,12 @@ BUILDIN(stopnpctimer) { //Check if argument is numeric (flag) or string (npc name) struct script_data *data; data = script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ) //NPC name nd = npc_name2id(script->conv_str(st, data)); else if( data_isint(data) ) //Flag { - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); flag = script->conv_num(st,data); } else @@ -8954,7 +8908,7 @@ BUILDIN(stopnpctimer) } } else - nd=(struct npc_data *)map_id2bl(st->oid); + nd=(struct npc_data *)iMap->id2bl(st->oid); if( !nd ) return true; @@ -8976,7 +8930,7 @@ BUILDIN(getnpctimer) if( script_hasdata(st,3) ) nd = npc_name2id(script_getstr(st,3)); else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); if( !nd || nd->bl.type != BL_NPC ) { @@ -8991,7 +8945,7 @@ BUILDIN(getnpctimer) case 1: if( nd->u.scr.rid ) { - sd = map_id2sd(nd->u.scr.rid); + sd = iMap->id2sd(nd->u.scr.rid); if( !sd ) { ShowError("buildin_getnpctimer: Attached player not found!\n"); @@ -9019,7 +8973,7 @@ BUILDIN(setnpctimer) if( script_hasdata(st,3) ) nd = npc_name2id(script_getstr(st,3)); else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); if( !nd || nd->bl.type != BL_NPC ) { @@ -9039,7 +8993,7 @@ BUILDIN(setnpctimer) BUILDIN(attachnpctimer) { TBL_PC *sd; - struct npc_data *nd = (struct npc_data *)map_id2bl(st->oid); + struct npc_data *nd = (struct npc_data *)iMap->id2bl(st->oid); if( !nd || nd->bl.type != BL_NPC ) { @@ -9049,7 +9003,7 @@ BUILDIN(attachnpctimer) } if( script_hasdata(st,2) ) - sd = map_nick2sd(script_getstr(st,2)); + sd = iMap->nick2sd(script_getstr(st,2)); else sd = script_rid2sd(st); @@ -9075,7 +9029,7 @@ BUILDIN(detachnpctimer) if( script_hasdata(st,2) ) nd = npc_name2id(script_getstr(st,2)); else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); if( !nd || nd->bl.type != BL_NPC ) { @@ -9096,7 +9050,7 @@ BUILDIN(detachnpctimer) *------------------------------------------*/ BUILDIN(playerattached) { - if(st->rid == 0 || map_id2sd(st->rid) == NULL) + if(st->rid == 0 || iMap->id2sd(st->rid) == NULL) script_pushint(st,0); else script_pushint(st,st->rid); @@ -9118,7 +9072,7 @@ BUILDIN(announce) if (flag&0x0f) // Broadcast source or broadcast region defined { send_target target; - struct block_list *bl = (flag&0x08) ? map_id2bl(st->oid) : (struct block_list *)script_rid2sd(st); // If bc_npc flag is set, use NPC as broadcast source + struct block_list *bl = (flag&0x08) ? iMap->id2bl(st->oid) : (struct block_list *)script_rid2sd(st); // If bc_npc flag is set, use NPC as broadcast source if (bl == NULL) return true; @@ -9169,10 +9123,10 @@ BUILDIN(itemeffect) { struct item_data *item_data; nullpo_retr( 1, ( sd = script_rid2sd( st ) ) ); - nullpo_retr( 1, ( nd = (TBL_NPC *)map_id2bl( sd->npc_id ) ) ); + nullpo_retr( 1, ( nd = (TBL_NPC *)iMap->id2bl( sd->npc_id ) ) ); data = script_getdata( st, 2 ); - get_val( st, data ); + script->get_val( st, data ); if( data_isstring( data ) ){ const char *name = script->conv_str( st, data ); @@ -9210,10 +9164,10 @@ BUILDIN(mapannounce) int fontY = script_hasdata(st,9) ? script_getnum(st,9) : 0; // default fontY int16 m; - if ((m = map_mapname2mapid(mapname)) < 0) + if ((m = iMap->mapname2mapid(mapname)) < 0) return true; - map_foreachinmap(buildin_announce_sub, m, BL_PC, + iMap->foreachinmap(buildin_announce_sub, m, BL_PC, mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY); return true; } @@ -9235,10 +9189,10 @@ BUILDIN(areaannounce) int fontY = script_hasdata(st,13) ? script_getnum(st,13) : 0; // default fontY int16 m; - if ((m = map_mapname2mapid(mapname)) < 0) + if ((m = iMap->mapname2mapid(mapname)) < 0) return true; - map_foreachinarea(buildin_announce_sub, m, x0, y0, x1, y1, BL_PC, + iMap->foreachinarea(buildin_announce_sub, m, x0, y0, x1, y1, BL_PC, mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY); return true; } @@ -9258,7 +9212,7 @@ BUILDIN(getusers) case 0: if(flag&0x8) {// npc - bl = map_id2bl(st->oid); + bl = iMap->id2bl(st->oid); } else if((sd = script_rid2sd(st))!=NULL) {// pc @@ -9271,7 +9225,7 @@ BUILDIN(getusers) } break; case 1: - val = map_getusers(); + val = iMap->getusers(); break; default: ShowWarning("buildin_getusers: Unknown type %d.\n", flag); @@ -9294,11 +9248,11 @@ BUILDIN(getusersname) sd = script_rid2sd(st); if (!sd) return true; - group_level = pc_get_group_level(sd); + group_level = pc->get_group_level(sd); iter = mapit_getallusers(); for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { - if (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > group_level) + if (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc->get_group_level(pl_sd) > group_level) continue; // skip hidden sessions /* Temporary fix for bugreport:1023. @@ -9323,7 +9277,7 @@ BUILDIN(getmapguildusers) struct guild *g = NULL; str=script_getstr(st,2); gid=script_getnum(st,3); - if ((m = map_mapname2mapid(str)) < 0) { // map id on this server (m == -1 if not in actual map-server) + if ((m = iMap->mapname2mapid(str)) < 0) { // map id on this server (m == -1 if not in actual map-server) script_pushint(st,-1); return true; } @@ -9347,7 +9301,7 @@ BUILDIN(getmapusers) const char *str; int16 m; str=script_getstr(st,2); - if( (m=map_mapname2mapid(str))< 0){ + if( (m=iMap->mapname2mapid(str))< 0){ script_pushint(st,-1); return true; } @@ -9371,11 +9325,11 @@ BUILDIN(getareausers) y0=script_getnum(st,4); x1=script_getnum(st,5); y1=script_getnum(st,6); - if( (m=map_mapname2mapid(str))< 0){ + if( (m=iMap->mapname2mapid(str))< 0){ script_pushint(st,-1); return true; } - map_foreachinarea(buildin_getareausers_sub, + iMap->foreachinarea(buildin_getareausers_sub, m,x0,y0,x1,y1,BL_PC,&users); script_pushint(st,users); return true; @@ -9408,7 +9362,7 @@ BUILDIN(getareadropitem) y1=script_getnum(st,6); data=script_getdata(st,7); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ){ const char *name=script->conv_str(st,data); struct item_data *item_data = itemdb_searchname(name); @@ -9418,11 +9372,11 @@ BUILDIN(getareadropitem) }else item=script->conv_num(st,data); - if( (m=map_mapname2mapid(str))< 0){ + if( (m=iMap->mapname2mapid(str))< 0){ script_pushint(st,-1); return true; } - map_foreachinarea(buildin_getareadropitem_sub, + iMap->foreachinarea(buildin_getareadropitem_sub, m,x0,y0,x1,y1,BL_ITEM,item,&amount); script_pushint(st,amount); return true; @@ -9480,9 +9434,9 @@ BUILDIN(sc_start) tick = script_getnum(st,3); val1 = script_getnum(st,4); if( script_hasdata(st,5) ) - bl = map_id2bl(script_getnum(st,5)); + bl = iMap->id2bl(script_getnum(st,5)); else - bl = map_id2bl(st->rid); + bl = iMap->id2bl(st->rid); if( tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0 ) {// When there isn't a duration specified, try to get it from the skill_db @@ -9491,7 +9445,7 @@ BUILDIN(sc_start) if( potion_flag == 1 && potion_target ) { //skill.c set the flags before running the script, this must be a potion-pitched effect. - bl = map_id2bl(potion_target); + bl = iMap->id2bl(potion_target); tick /= 2;// Thrown potions only last half. val4 = 1;// Mark that this was a thrown sc_effect } @@ -9519,9 +9473,9 @@ BUILDIN(sc_start2) val1 = script_getnum(st,4); rate = script_getnum(st,5); if( script_hasdata(st,6) ) - bl = map_id2bl(script_getnum(st,6)); + bl = iMap->id2bl(script_getnum(st,6)); else - bl = map_id2bl(st->rid); + bl = iMap->id2bl(st->rid); if( tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0 ) {// When there isn't a duration specified, try to get it from the skill_db @@ -9530,7 +9484,7 @@ BUILDIN(sc_start2) if( potion_flag == 1 && potion_target ) { //skill.c set the flags before running the script, this must be a potion-pitched effect. - bl = map_id2bl(potion_target); + bl = iMap->id2bl(potion_target); tick /= 2;// Thrown potions only last half. val4 = 1;// Mark that this was a thrown sc_effect } @@ -9561,9 +9515,9 @@ BUILDIN(sc_start4) val3 = script_getnum(st,6); val4 = script_getnum(st,7); if( script_hasdata(st,8) ) - bl = map_id2bl(script_getnum(st,8)); + bl = iMap->id2bl(script_getnum(st,8)); else - bl = map_id2bl(st->rid); + bl = iMap->id2bl(st->rid); if( tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0 ) {// When there isn't a duration specified, try to get it from the skill_db @@ -9572,7 +9526,7 @@ BUILDIN(sc_start4) if( potion_flag == 1 && potion_target ) { //skill.c set the flags before running the script, this must be a potion-pitched effect. - bl = map_id2bl(potion_target); + bl = iMap->id2bl(potion_target); tick /= 2;// Thrown potions only last half. } @@ -9592,12 +9546,12 @@ BUILDIN(sc_end) type = script_getnum(st, 2); if (script_hasdata(st, 3)) - bl = map_id2bl(script_getnum(st, 3)); + bl = iMap->id2bl(script_getnum(st, 3)); else - bl = map_id2bl(st->rid); + bl = iMap->id2bl(st->rid); if (potion_flag == 1 && potion_target) //##TODO how does this work [FlavioJS] - bl = map_id2bl(potion_target); + bl = iMap->id2bl(potion_target); if (!bl) return true; @@ -9613,8 +9567,8 @@ BUILDIN(sc_end) switch (type) { - case SC_WEIGHT50: - case SC_WEIGHT90: + case SC_WEIGHTOVER50: + case SC_WEIGHTOVER90: case SC_NOCHAT: case SC_PUSH_CART: return true; @@ -9644,9 +9598,9 @@ BUILDIN(getscrate) type=script_getnum(st,2); rate=script_getnum(st,3); if( script_hasdata(st,4) ) //get for the bl assigned - bl = map_id2bl(script_getnum(st,4)); + bl = iMap->id2bl(script_getnum(st,4)); else - bl = map_id2bl(st->rid); + bl = iMap->id2bl(st->rid); if (bl) rate = status_get_sc_def(bl, (sc_type)type, 10000, 10000, 0); @@ -9691,11 +9645,11 @@ BUILDIN(getstatus) case 4: script_pushint(st, sd->sc.data[id]->val4); break; case 5: { - struct TimerData* timer = (struct TimerData*)get_timer(sd->sc.data[id]->timer); + struct TimerData* timer = (struct TimerData*)iTimer->get_timer(sd->sc.data[id]->timer); if( timer ) {// return the amount of time remaining - script_pushint(st, timer->tick - gettick()); + script_pushint(st, timer->tick - iTimer->gettick()); } } break; @@ -9795,6 +9749,31 @@ BUILDIN(homunculus_shuffle) { return true; } +/*========================================== + * Check for homunculus state. + * Return: -1 = No homunculus + * 0 = Homunculus is active + * 1 = Homunculus is vaporized (rest) + * 2 = Homunculus is in morph state + *------------------------------------------*/ +BUILDIN(checkhomcall) +{ + TBL_PC *sd = script_rid2sd(st); + TBL_HOM *hd; + + if( sd == NULL ) + return false; + + hd = sd->hd; + + if( !hd ) + script_pushint(st, -1); + else + script_pushint(st, hd->homunculus.vaporize); + + return true; +} + //These two functions bring the eA MAPID_* class functionality to scripts. BUILDIN(eaclass) { @@ -9810,7 +9789,7 @@ BUILDIN(eaclass) } class_ = sd->status.class_; } - script_pushint(st,pc_jobid2mapid(class_)); + script_pushint(st,pc->jobid2mapid(class_)); return true; } @@ -9827,7 +9806,7 @@ BUILDIN(roclass) else sex = 1; //Just use male when not found. } - script_pushint(st,pc_mapid2jobid(class_, sex)); + script_pushint(st,pc->mapid2jobid(class_, sex)); return true; } @@ -9868,7 +9847,7 @@ BUILDIN(resetlvl) if( sd == NULL ) return true; - pc_resetlvl(sd,type); + pc->resetlvl(sd,type); return true; } /*========================================== @@ -9878,7 +9857,7 @@ BUILDIN(resetstatus) { TBL_PC *sd; sd=script_rid2sd(st); - pc_resetstate(sd); + pc->resetstate(sd); return true; } @@ -9889,7 +9868,7 @@ BUILDIN(resetskill) { TBL_PC *sd; sd=script_rid2sd(st); - pc_resetskill(sd,1); + pc->resetskill(sd,1); return true; } @@ -9900,7 +9879,7 @@ BUILDIN(skillpointcount) { TBL_PC *sd; sd=script_rid2sd(st); - script_pushint(st,sd->status.skill_point + pc_resetskill(sd,2)); + script_pushint(st,sd->status.skill_point + pc->resetskill(sd,2)); return true; } @@ -9913,7 +9892,7 @@ BUILDIN(changebase) int vclass; if( script_hasdata(st,3) ) - sd=map_id2sd(script_getnum(st,3)); + sd=iMap->id2sd(script_getnum(st,3)); else sd=script_rid2sd(st); @@ -9951,10 +9930,10 @@ BUILDIN(changesex) TBL_PC *sd = NULL; sd = script_rid2sd(st); - pc_resetskill(sd,4); + pc->resetskill(sd,4); // to avoid any problem with equipment and invalid sex, equipment is unequiped. for( i=0; i<EQI_MAX; i++ ) - if( sd->equip_index[i] >= 0 ) pc_unequipitem(sd, sd->equip_index[i], 3); + if( sd->equip_index[i] >= 0 ) pc->unequipitem(sd, sd->equip_index[i], 3); chrif_changesex(sd); return true; } @@ -9964,7 +9943,7 @@ BUILDIN(changesex) *------------------------------------------*/ BUILDIN(globalmes) { - struct block_list *bl = map_id2bl(st->oid); + struct block_list *bl = iMap->id2bl(st->oid); struct npc_data *nd = (struct npc_data *)bl; const char *name=NULL,*mes; @@ -10001,7 +9980,7 @@ BUILDIN(waitingroom) int minLvl = script_hasdata(st,7) ? script_getnum(st,7) : 1; int maxLvl = script_hasdata(st,8) ? script_getnum(st,8) : MAX_LEVEL; - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); if( nd != NULL ) chat_createnpcchat(nd, title, limit, pub, trigger, ev, zeny, minLvl, maxLvl); @@ -10018,7 +9997,7 @@ BUILDIN(delwaitingroom) if( script_hasdata(st,2) ) nd = npc_name2id(script_getstr(st, 2)); else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); if( nd != NULL ) chat_deletenpcchat(nd); return true; @@ -10036,9 +10015,9 @@ BUILDIN(waitingroomkickall) if( script_hasdata(st,2) ) nd = npc_name2id(script_getstr(st,2)); else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); - if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL ) + if( nd != NULL && (cd=(struct chat_data *)iMap->id2bl(nd->chat_id)) != NULL ) chat_npckickall(cd); return true; } @@ -10055,9 +10034,9 @@ BUILDIN(enablewaitingroomevent) if( script_hasdata(st,2) ) nd = npc_name2id(script_getstr(st, 2)); else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); - if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL ) + if( nd != NULL && (cd=(struct chat_data *)iMap->id2bl(nd->chat_id)) != NULL ) chat_enableevent(cd); return true; } @@ -10074,9 +10053,9 @@ BUILDIN(disablewaitingroomevent) if( script_hasdata(st,2) ) nd = npc_name2id(script_getstr(st, 2)); else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); - if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL ) + if( nd != NULL && (cd=(struct chat_data *)iMap->id2bl(nd->chat_id)) != NULL ) chat_disableevent(cd); return true; } @@ -10105,9 +10084,9 @@ BUILDIN(getwaitingroomstate) if( script_hasdata(st,3) ) nd = npc_name2id(script_getstr(st, 3)); else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); - if( nd == NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id)) == NULL ) + if( nd == NULL || (cd=(struct chat_data *)iMap->id2bl(nd->chat_id)) == NULL ) { script_pushint(st, -1); return true; @@ -10152,8 +10131,8 @@ BUILDIN(warpwaitingpc) struct chat_data* cd; TBL_PC* sd; - nd = (struct npc_data *)map_id2bl(st->oid); - if( nd == NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id)) == NULL ) + nd = (struct npc_data *)iMap->id2bl(st->oid); + if( nd == NULL || (cd=(struct chat_data *)iMap->id2bl(nd->chat_id)) == NULL ) return true; map_name = script_getstr(st,2); @@ -10179,17 +10158,17 @@ BUILDIN(warpwaitingpc) {// no zeny to cover set fee break; } - pc_payzeny(sd, cd->zeny, LOG_TYPE_NPC, NULL); + pc->payzeny(sd, cd->zeny, LOG_TYPE_NPC, NULL); } mapreg_setreg(reference_uid(add_str("$@warpwaitingpc"), i), sd->bl.id); if( strcmp(map_name,"Random") == 0 ) - pc_randomwarp(sd,CLR_TELEPORT); + pc->randomwarp(sd,CLR_TELEPORT); else if( strcmp(map_name,"SavePoint") == 0 ) - pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT); + pc->setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT); else - pc_setpos(sd, mapindex_name2id(map_name), x, y, CLR_OUTSIGHT); + pc->setpos(sd, mapindex_name2id(map_name), x, y, CLR_OUTSIGHT); } mapreg_setreg(add_str("$@warpwaitingpcnum"), i); return true; @@ -10202,10 +10181,8 @@ BUILDIN(warpwaitingpc) /// Detaches a character from a script. /// /// @param st Script state to detach the character from. -static void script_detach_rid(struct script_state* st) -{ - if(st->rid) - { +void script_detach_rid(struct script_state* st) { + if(st->rid) { script_detach_state(st, false); st->rid = 0; } @@ -10218,7 +10195,7 @@ BUILDIN(attachrid) { int rid = script_getnum(st,2); - if (map_id2sd(rid) != NULL) { + if (iMap->id2sd(rid) != NULL) { script_detach_rid(st); st->rid = rid; @@ -10241,11 +10218,11 @@ BUILDIN(detachrid) *------------------------------------------*/ BUILDIN(isloggedin) { - TBL_PC* sd = map_id2sd(script_getnum(st,2)); + TBL_PC* sd = iMap->id2sd(script_getnum(st,2)); if (script_hasdata(st,3) && sd && sd->status.char_id != script_getnum(st,3)) sd = NULL; - push_val(st->stack,C_INT,sd!=NULL); + script->push_val(st->stack,C_INT,sd!=NULL,NULL); return true; } @@ -10263,7 +10240,7 @@ BUILDIN(setmapflagnosave) str2=script_getstr(st,3); x=script_getnum(st,4); y=script_getnum(st,5); - m = map_mapname2mapid(str); + m = iMap->mapname2mapid(str); mapindex = mapindex_name2id(str2); if(m >= 0 && mapindex) { @@ -10284,7 +10261,7 @@ BUILDIN(getmapflag) str=script_getstr(st,2); i=script_getnum(st,3); - m = map_mapname2mapid(str); + m = iMap->mapname2mapid(str); if(m >= 0) { switch(i) { case MF_NOMEMO: script_pushint(st,map[m].flag.nomemo); break; @@ -10345,7 +10322,7 @@ BUILDIN(getmapflag) static int script_mapflag_pvp_sub(struct block_list *bl,va_list ap) { TBL_PC* sd = (TBL_PC*)bl; if (sd->pvp_timer == INVALID_TIMER) { - sd->pvp_timer = add_timer(gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0); + sd->pvp_timer = iTimer->add_timer(iTimer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0); sd->pvp_rank = 0; sd->pvp_lastusers = 0; sd->pvp_point = 5; @@ -10369,7 +10346,7 @@ BUILDIN(setmapflag) if(script_hasdata(st,4)){ data = script_getdata(st,4); - get_val(st, data); + script->get_val(st, data); if( data_isstring(data) ) @@ -10378,7 +10355,7 @@ BUILDIN(setmapflag) val = script_getnum(st, 4); } - m = map_mapname2mapid(str); + m = iMap->mapname2mapid(str); if(m >= 0) { switch(i) { @@ -10391,7 +10368,7 @@ BUILDIN(setmapflag) case MF_PVP: map[m].flag.pvp = 1; if( !battle_config.pk_mode ) { - map_foreachinmap(script_mapflag_pvp_sub,m,BL_PC); + iMap->foreachinmap(script_mapflag_pvp_sub,m,BL_PC); } break; case MF_PVP_NOPARTY: map[m].flag.pvp_noparty = 1; break; @@ -10469,7 +10446,7 @@ BUILDIN(removemapflag) if(script_hasdata(st,4)){ val=script_getnum(st,4); } - m = map_mapname2mapid(str); + m = iMap->mapname2mapid(str); if(m >= 0) { switch(i) { case MF_NOMEMO: map[m].flag.nomemo = 0; break; @@ -10522,7 +10499,7 @@ BUILDIN(removemapflag) case MF_NOWARPTO: map[m].flag.nowarpto = 0; break; case MF_NIGHTMAREDROP: map[m].flag.pvp_nightmaredrop = 0; break; case MF_ZONE: - map_zone_change2(m, map[m].prev_zone); + iMap->zone_change2(m, map[m].prev_zone); break; case MF_NOCOMMAND: map[m].nocommand = 0; break; case MF_NODROP: map[m].flag.nodrop = 0; break; @@ -10555,11 +10532,11 @@ BUILDIN(pvpon) struct block_list bl; str = script_getstr(st,2); - m = map_mapname2mapid(str); + m = iMap->mapname2mapid(str); if( m < 0 || map[m].flag.pvp ) return true; // nothing to do - map_zone_change2(m, strdb_get(zone_db, MAP_ZONE_PVP_NAME)); + iMap->zone_change2(m, strdb_get(zone_db, MAP_ZONE_PVP_NAME)); map[m].flag.pvp = 1; clif->map_property_mapall(m, MAPPROPERTY_FREEPVPZONE); bl.type = BL_NUL; @@ -10576,7 +10553,7 @@ BUILDIN(pvpon) if( sd->bl.m != m || sd->pvp_timer != INVALID_TIMER ) continue; // not applicable - sd->pvp_timer = add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0); + sd->pvp_timer = iTimer->add_timer(iTimer->gettick()+200,pc->calc_pvprank_timer,sd->bl.id,0); sd->pvp_rank = 0; sd->pvp_lastusers = 0; sd->pvp_point = 5; @@ -10593,7 +10570,7 @@ static int buildin_pvpoff_sub(struct block_list *bl,va_list ap) TBL_PC* sd = (TBL_PC*)bl; clif->pvpset(sd, 0, 0, 2); if (sd->pvp_timer != INVALID_TIMER) { - delete_timer(sd->pvp_timer, pc_calc_pvprank_timer); + iTimer->delete_timer(sd->pvp_timer, pc->calc_pvprank_timer); sd->pvp_timer = INVALID_TIMER; } return 0; @@ -10606,11 +10583,11 @@ BUILDIN(pvpoff) struct block_list bl; str=script_getstr(st,2); - m = map_mapname2mapid(str); + m = iMap->mapname2mapid(str); if(m < 0 || !map[m].flag.pvp) return true; //fixed Lupus - map_zone_change2(m, map[m].prev_zone); + iMap->zone_change2(m, map[m].prev_zone); map[m].flag.pvp = 0; clif->map_property_mapall(m, MAPPROPERTY_NOTHING); bl.type = BL_NUL; @@ -10620,7 +10597,7 @@ BUILDIN(pvpoff) if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris] return true; - map_foreachinmap(buildin_pvpoff_sub, m, BL_PC); + iMap->foreachinmap(buildin_pvpoff_sub, m, BL_PC); return true; } @@ -10630,10 +10607,10 @@ BUILDIN(gvgon) const char *str; str=script_getstr(st,2); - m = map_mapname2mapid(str); + m = iMap->mapname2mapid(str); if(m >= 0 && !map[m].flag.gvg) { struct block_list bl; - map_zone_change2(m, strdb_get(zone_db, MAP_ZONE_GVG_NAME)); + iMap->zone_change2(m, strdb_get(zone_db, MAP_ZONE_GVG_NAME)); map[m].flag.gvg = 1; clif->map_property_mapall(m, MAPPROPERTY_AGITZONE); bl.type = BL_NUL; @@ -10649,10 +10626,10 @@ BUILDIN(gvgoff) const char *str; str=script_getstr(st,2); - m = map_mapname2mapid(str); + m = iMap->mapname2mapid(str); if(m >= 0 && map[m].flag.gvg) { struct block_list bl; - map_zone_change2(m, map[m].prev_zone); + iMap->zone_change2(m, map[m].prev_zone); map[m].flag.gvg = 0; clif->map_property_mapall(m, MAPPROPERTY_NOTHING); bl.type = BL_NUL; @@ -10682,7 +10659,7 @@ BUILDIN(emotion) if (player) { TBL_PC *sd = NULL; if( script_hasdata(st,4) ) - sd = map_nick2sd(script_getstr(st,4)); + sd = iMap->nick2sd(script_getstr(st,4)); else sd = script_rid2sd(st); if (sd) @@ -10695,7 +10672,7 @@ BUILDIN(emotion) clif->emotion(&nd->bl,type); } else - clif->emotion(map_id2bl(st->oid),type); + clif->emotion(iMap->id2bl(st->oid),type); return true; } @@ -10712,7 +10689,7 @@ static int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list (sd->status.guild_id != g_id && flag&2) || //Warp out outsiders (sd->status.guild_id == 0) // Warp out players not in guild [Valaris] ) - pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); + pc->setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT); return 1; } @@ -10732,46 +10709,46 @@ BUILDIN(maprespawnguildid) int g_id=script_getnum(st,3); int flag=script_getnum(st,4); - int16 m=map_mapname2mapid(mapname); + int16 m=iMap->mapname2mapid(mapname); if(m == -1) return true; //Catch ALL players (in case some are 'between maps' on execution time) - map_foreachpc(buildin_maprespawnguildid_sub_pc,m,g_id,flag); + iMap->map_foreachpc(buildin_maprespawnguildid_sub_pc,m,g_id,flag); if (flag&4) //Remove script mobs. - map_foreachinmap(buildin_maprespawnguildid_sub_mob,m,BL_MOB); + iMap->foreachinmap(buildin_maprespawnguildid_sub_mob,m,BL_MOB); return true; } BUILDIN(agitstart) { - if(agit_flag==1) return true; // Agit already Start. - agit_flag=1; + if(iMap->agit_flag==1) return true; // Agit already Start. + iMap->agit_flag=1; guild->agit_start(); return true; } BUILDIN(agitend) { - if(agit_flag==0) return true; // Agit already End. - agit_flag=0; + if(iMap->agit_flag==0) return true; // Agit already End. + iMap->agit_flag=0; guild->agit_end(); return true; } BUILDIN(agitstart2) { - if(agit2_flag==1) return true; // Agit2 already Start. - agit2_flag=1; + if(iMap->agit2_flag==1) return true; // Agit2 already Start. + iMap->agit2_flag=1; guild->agit2_start(); return true; } BUILDIN(agitend2) { - if(agit2_flag==0) return true; // Agit2 already End. - agit2_flag=0; + if(iMap->agit2_flag==0) return true; // Agit2 already End. + iMap->agit2_flag=0; guild->agit2_end(); return true; } @@ -10781,7 +10758,7 @@ BUILDIN(agitend2) *------------------------------------------*/ BUILDIN(agitcheck) { - script_pushint(st,agit_flag); + script_pushint(st,iMap->agit_flag); return true; } @@ -10790,7 +10767,7 @@ BUILDIN(agitcheck) *------------------------------------------*/ BUILDIN(agitcheck2) { - script_pushint(st,agit2_flag); + script_pushint(st,iMap->agit2_flag); return true; } @@ -10804,7 +10781,7 @@ BUILDIN(flagemblem) if(g_id < 0) return true; - nd = (TBL_NPC*)map_id2nd(st->oid); + nd = (TBL_NPC*)iMap->id2nd(st->oid); if( nd == NULL ) { ShowError("script:flagemblem: npc %d not found\n", st->oid); } else if( nd->subtype != SCRIPT ) { @@ -10923,7 +10900,7 @@ BUILDIN(getequipcardcnt) num=script_getnum(st,2); sd=script_rid2sd(st); if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if (i < 0 || !sd->inventory_data[i]) { script_pushint(st,0); @@ -10955,7 +10932,7 @@ BUILDIN(successremovecards) { int num = script_getnum(st,2); if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if (i < 0 || !sd->inventory_data[i]) { return true; @@ -10973,9 +10950,9 @@ BUILDIN(successremovecards) { item_tmp.nameid = sd->status.inventory[i].card[c]; item_tmp.identify = 1; - if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ // get back the cart in inventory + if((flag=pc->additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ // get back the cart in inventory clif->additem(sd,0,0,flag); - map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + iMap->addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } @@ -10994,10 +10971,10 @@ BUILDIN(successremovecards) { for (j = sd->inventory_data[i]->slot; j < MAX_SLOTS; j++) item_tmp.card[j]=sd->status.inventory[i].card[j]; - pc_delitem(sd,i,1,0,3,LOG_TYPE_SCRIPT); - if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ //chk if can be spawn in inventory otherwise put on floor + pc->delitem(sd,i,1,0,3,LOG_TYPE_SCRIPT); + if((flag=pc->additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ //chk if can be spawn in inventory otherwise put on floor clif->additem(sd,0,0,flag); - map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + iMap->addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } clif->misceffect(&sd->bl,3); @@ -11019,7 +10996,7 @@ BUILDIN(failedremovecards) { int typefail = script_getnum(st,3); if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if (i < 0 || !sd->inventory_data[i]) return true; @@ -11040,9 +11017,9 @@ BUILDIN(failedremovecards) { item_tmp.nameid = sd->status.inventory[i].card[c]; item_tmp.identify = 1; - if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ + if((flag=pc->additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ clif->additem(sd,0,0,flag); - map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + iMap->addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } @@ -11050,7 +11027,7 @@ BUILDIN(failedremovecards) { if(cardflag == 1) { if(typefail == 0 || typefail == 2){ // destroy the item - pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); + pc->delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); } if(typefail == 1){ // destroy the card int flag; @@ -11067,11 +11044,11 @@ BUILDIN(failedremovecards) { for (j = sd->inventory_data[i]->slot; j < MAX_SLOTS; j++) item_tmp.card[j]=sd->status.inventory[i].card[j]; - pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); + pc->delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT); - if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ + if((flag=pc->additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ clif->additem(sd,0,0,flag); - map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + iMap->addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } clif->misceffect(&sd->bl,2); @@ -11102,7 +11079,7 @@ BUILDIN(mapwarp) // Added by RoVeRT check_ID=script_getnum(st,7); } - if((m=map_mapname2mapid(mapname))< 0) + if((m=iMap->mapname2mapid(mapname))< 0) return true; if(!(index=mapindex_name2id(str))) @@ -11115,23 +11092,23 @@ BUILDIN(mapwarp) // Added by RoVeRT for( i=0; i < g->max_member; i++) { if(g->member[i].sd && g->member[i].sd->bl.m==m){ - pc_setpos(g->member[i].sd,index,x,y,CLR_TELEPORT); + pc->setpos(g->member[i].sd,index,x,y,CLR_TELEPORT); } } } break; case 2: - p = party_search(check_ID); + p = party->search(check_ID); if(p){ for(i=0;i<MAX_PARTY; i++){ if(p->data[i].sd && p->data[i].sd->bl.m == m){ - pc_setpos(p->data[i].sd,index,x,y,CLR_TELEPORT); + pc->setpos(p->data[i].sd,index,x,y,CLR_TELEPORT); } } } break; default: - map_foreachinmap(buildin_areawarp_sub,m,BL_PC,index,x,y,0,0); + iMap->foreachinmap(buildin_areawarp_sub,m,BL_PC,index,x,y,0,0); break; } @@ -11158,7 +11135,7 @@ BUILDIN(mobcount) // Added by RoVeRT event = NULL; else check_event(st, event); - + if( strcmp(mapname, "this") == 0 ) { struct map_session_data *sd = script_rid2sd(st); if( sd ) @@ -11167,19 +11144,17 @@ BUILDIN(mobcount) // Added by RoVeRT script_pushint(st,-1); return true; } - } - else if( (m = map_mapname2mapid(mapname)) < 0 ) { + } else if( (m = iMap->mapname2mapid(mapname)) < 0 ) { script_pushint(st,-1); return true; } - - if( map[m].flag.src4instance && map[m].instance_id == 0 && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 ) - { + + if( map[m].flag.src4instance && map[m].instance_id == -1 && st->instance_id >= 0 && (m = instance->mapid2imapid(m, st->instance_id)) < 0 ) { script_pushint(st,-1); return true; } - - script_pushint(st,map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event)); + + script_pushint(st,iMap->foreachinmap(buildin_mobcount_sub, m, BL_MOB, event)); return true; } @@ -11188,9 +11163,9 @@ BUILDIN(marriage) { const char *partner=script_getstr(st,2); TBL_PC *sd=script_rid2sd(st); - TBL_PC *p_sd=map_nick2sd(partner); + TBL_PC *p_sd=iMap->nick2sd(partner); - if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){ + if(sd==NULL || p_sd==NULL || pc->marriage(sd,p_sd) < 0){ script_pushint(st,0); return true; } @@ -11203,7 +11178,7 @@ BUILDIN(wedding_effect) struct block_list *bl; if(sd==NULL) { - bl=map_id2bl(st->oid); + bl=iMap->id2bl(st->oid); } else bl=&sd->bl; clif->wedding_effect(bl); @@ -11212,7 +11187,7 @@ BUILDIN(wedding_effect) BUILDIN(divorce) { TBL_PC *sd=script_rid2sd(st); - if(sd==NULL || pc_divorce(sd) < 0){ + if(sd==NULL || pc->divorce(sd) < 0){ script_pushint(st,0); return true; } @@ -11224,8 +11199,8 @@ BUILDIN(ispartneron) { TBL_PC *sd=script_rid2sd(st); - if(sd==NULL || !pc_ismarried(sd) || - map_charid2sd(sd->status.partner_id) == NULL) { + if(sd==NULL || !pc->ismarried(sd) || + iMap->charid2sd(sd->status.partner_id) == NULL) { script_pushint(st,0); return true; } @@ -11290,8 +11265,8 @@ BUILDIN(warppartner) TBL_PC *sd=script_rid2sd(st); TBL_PC *p_sd=NULL; - if(sd==NULL || !pc_ismarried(sd) || - (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) { + if(sd==NULL || !pc->ismarried(sd) || + (p_sd=iMap->charid2sd(sd->status.partner_id)) == NULL) { script_pushint(st,0); return true; } @@ -11302,7 +11277,7 @@ BUILDIN(warppartner) mapindex = mapindex_name2id(str); if (mapindex) { - pc_setpos(p_sd,mapindex,x,y,CLR_OUTSIGHT); + pc->setpos(p_sd,mapindex,x,y,CLR_OUTSIGHT); script_pushint(st,1); } else script_pushint(st,0); @@ -11366,7 +11341,7 @@ BUILDIN(guardian) has_index = true; } else if( script_hasdata(st,7) ){ data=script_getdata(st,7); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ) {// "<event label>" evt=script_getstr(st,7); @@ -11403,16 +11378,16 @@ BUILDIN(setwall) shootable = script_getnum(st,7); name = script_getstr(st,8); - if( (m = map_mapname2mapid(map)) < 0 ) + if( (m = iMap->mapname2mapid(map)) < 0 ) return true; // Invalid Map - map_iwall_set(m, x, y, size, dir, shootable, name); + iMap->iwall_set(m, x, y, size, dir, shootable, name); return true; } BUILDIN(delwall) { const char *name = script_getstr(st,2); - map_iwall_remove(name); + iMap->iwall_remove(name); return true; } @@ -11445,7 +11420,7 @@ BUILDIN(guardianinfo) if( !gc->guardian[id].visible ) script_pushint(st,-1); else - if( (gd = map_id2md(gc->guardian[id].id)) == NULL ) + if( (gd = iMap->id2md(gc->guardian[id].id)) == NULL ) script_pushint(st,-1); else { @@ -11469,7 +11444,7 @@ BUILDIN(getitemname) struct script_data *data; data=script_getdata(st,2); - get_val(st,data); + script->get_val(st,data); if( data_isstring(data) ){ const char *name=script->conv_str(st,data); @@ -11597,7 +11572,7 @@ BUILDIN(setiteminfo) /*========================================== * Returns value from equipped item slot n [Lupus] - getequipcardid(num,slot) + getequpcardid(num,slot) where num = eqip position slot slot = 0,1,2,3 (Card Slot N) @@ -11616,7 +11591,7 @@ BUILDIN(getequipcardid) slot=script_getnum(st,3); sd=script_rid2sd(st); if (num > 0 && num <= ARRAYLENGTH(equip)) - i=pc_checkequip(sd,equip[num-1]); + i=pc->checkequip(sd,equip[num-1]); if(i >= 0 && slot>=0 && slot<4) script_pushint(st,sd->status.inventory[i].card[slot]); else @@ -11641,7 +11616,7 @@ BUILDIN(petskillbonus) if (pd->bonus) { //Clear previous bonus if (pd->bonus->timer != INVALID_TIMER) - delete_timer(pd->bonus->timer, pet_skill_bonus_timer); + iTimer->delete_timer(pd->bonus->timer, pet_skill_bonus_timer); } else //init pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus)); @@ -11657,7 +11632,7 @@ BUILDIN(petskillbonus) if (battle_config.pet_equip_required && pd->pet.equip == 0) pd->bonus->timer = INVALID_TIMER; else - pd->bonus->timer = add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0); + pd->bonus->timer = iTimer->add_timer(iTimer->gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0); return true; } @@ -11714,22 +11689,22 @@ BUILDIN(getinventorylist) if(!sd) return true; for(i=0;i<MAX_INVENTORY;i++){ if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){ - pc_setreg(sd,reference_uid(add_str("@inventorylist_id"), j),sd->status.inventory[i].nameid); - pc_setreg(sd,reference_uid(add_str("@inventorylist_amount"), j),sd->status.inventory[i].amount); - pc_setreg(sd,reference_uid(add_str("@inventorylist_equip"), j),sd->status.inventory[i].equip); - pc_setreg(sd,reference_uid(add_str("@inventorylist_refine"), j),sd->status.inventory[i].refine); - pc_setreg(sd,reference_uid(add_str("@inventorylist_identify"), j),sd->status.inventory[i].identify); - pc_setreg(sd,reference_uid(add_str("@inventorylist_attribute"), j),sd->status.inventory[i].attribute); + pc->setreg(sd,reference_uid(add_str("@inventorylist_id"), j),sd->status.inventory[i].nameid); + pc->setreg(sd,reference_uid(add_str("@inventorylist_amount"), j),sd->status.inventory[i].amount); + pc->setreg(sd,reference_uid(add_str("@inventorylist_equip"), j),sd->status.inventory[i].equip); + pc->setreg(sd,reference_uid(add_str("@inventorylist_refine"), j),sd->status.inventory[i].refine); + pc->setreg(sd,reference_uid(add_str("@inventorylist_identify"), j),sd->status.inventory[i].identify); + pc->setreg(sd,reference_uid(add_str("@inventorylist_attribute"), j),sd->status.inventory[i].attribute); for (k = 0; k < MAX_SLOTS; k++) { sprintf(card_var, "@inventorylist_card%d",k+1); - pc_setreg(sd,reference_uid(add_str(card_var), j),sd->status.inventory[i].card[k]); + pc->setreg(sd,reference_uid(add_str(card_var), j),sd->status.inventory[i].card[k]); } - pc_setreg(sd,reference_uid(add_str("@inventorylist_expire"), j),sd->status.inventory[i].expire_time); + pc->setreg(sd,reference_uid(add_str("@inventorylist_expire"), j),sd->status.inventory[i].expire_time); j++; } } - pc_setreg(sd,add_str("@inventorylist_count"),j); + pc->setreg(sd,add_str("@inventorylist_count"),j); return true; } @@ -11740,13 +11715,13 @@ BUILDIN(getskilllist) if(!sd) return true; for(i=0;i<MAX_SKILL;i++){ if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){ - pc_setreg(sd,reference_uid(add_str("@skilllist_id"), j),sd->status.skill[i].id); - pc_setreg(sd,reference_uid(add_str("@skilllist_lv"), j),sd->status.skill[i].lv); - pc_setreg(sd,reference_uid(add_str("@skilllist_flag"), j),sd->status.skill[i].flag); + pc->setreg(sd,reference_uid(add_str("@skilllist_id"), j),sd->status.skill[i].id); + pc->setreg(sd,reference_uid(add_str("@skilllist_lv"), j),sd->status.skill[i].lv); + pc->setreg(sd,reference_uid(add_str("@skilllist_flag"), j),sd->status.skill[i].flag); j++; } } - pc_setreg(sd,add_str("@skilllist_count"),j); + pc->setreg(sd,add_str("@skilllist_count"),j); return true; } @@ -11757,7 +11732,7 @@ BUILDIN(clearitem) if(sd==NULL) return true; for (i=0; i<MAX_INVENTORY; i++) { if (sd->status.inventory[i].amount) { - pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_SCRIPT); + pc->delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_SCRIPT); } } return true; @@ -11775,7 +11750,7 @@ BUILDIN(disguise) id = script_getnum(st,2); if (mobdb_checkid(id) || npcdb_checkid(id)) { - pc_disguise(sd, id); + pc->disguise(sd, id); script_pushint(st,id); } else script_pushint(st,0); @@ -11792,7 +11767,7 @@ BUILDIN(undisguise) if (sd == NULL) return true; if (sd->disguise != -1) { - pc_disguise(sd, -1); + pc->disguise(sd, -1); script_pushint(st,0); } else { script_pushint(st,1); @@ -11807,7 +11782,7 @@ BUILDIN(undisguise) BUILDIN(classchange) { int _class,type; - struct block_list *bl=map_id2bl(st->oid); + struct block_list *bl=iMap->id2bl(st->oid); if(bl==NULL) return true; @@ -11826,7 +11801,7 @@ BUILDIN(misceffect) type=script_getnum(st,2); if(st->oid && st->oid != fake_nd->bl.id) { - struct block_list *bl = map_id2bl(st->oid); + struct block_list *bl = iMap->id2bl(st->oid); if (bl) clif->specialeffect(bl,type,AREA); } else{ @@ -11888,17 +11863,17 @@ BUILDIN(playBGMall) int x1 = script_getnum(st,6); int y1 = script_getnum(st,7); - map_foreachinarea(playBGM_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name); + iMap->foreachinarea(playBGM_sub, iMap->mapname2mapid(map), x0, y0, x1, y1, BL_PC, name); } else if( script_hasdata(st,3) ) {// entire map const char* map = script_getstr(st,3); - map_foreachinmap(playBGM_sub, map_mapname2mapid(map), BL_PC, name); + iMap->foreachinmap(playBGM_sub, iMap->mapname2mapid(map), BL_PC, name); } else {// entire server - map_foreachpc(&playBGM_foreachpc_sub, name); + iMap->map_foreachpc(&playBGM_foreachpc_sub, name); } return true; @@ -11940,14 +11915,14 @@ BUILDIN(soundeffectall) const char* name; int type; - bl = (st->rid) ? &(script_rid2sd(st)->bl) : map_id2bl(st->oid); + bl = (st->rid) ? &(script_rid2sd(st)->bl) : iMap->id2bl(st->oid); if (!bl) return true; name = script_getstr(st,2); type = script_getnum(st,3); - //FIXME: enumerating map squares (map_foreach) is slower than enumerating the list of online players (map_foreachpc?) [ultramage] + //FIXME: enumerating map squares (iMap->foreach) is slower than enumerating the list of online players (iMap->foreachpc?) [ultramage] if(!script_hasdata(st,4)) { // area around @@ -11957,7 +11932,7 @@ BUILDIN(soundeffectall) if(!script_hasdata(st,5)) { // entire map const char* map = script_getstr(st,4); - map_foreachinmap(soundeffect_sub, map_mapname2mapid(map), BL_PC, name, type); + iMap->foreachinmap(soundeffect_sub, iMap->mapname2mapid(map), BL_PC, name, type); } else if(script_hasdata(st,8)) @@ -11967,7 +11942,7 @@ BUILDIN(soundeffectall) int y0 = script_getnum(st,6); int x1 = script_getnum(st,7); int y1 = script_getnum(st,8); - map_foreachinarea(soundeffect_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name, type); + iMap->foreachinarea(soundeffect_sub, iMap->mapname2mapid(map), x0, y0, x1, y1, BL_PC, name, type); } else { @@ -11992,7 +11967,7 @@ BUILDIN(petrecovery) if (pd->recovery) { //Halt previous bonus if (pd->recovery->timer != INVALID_TIMER) - delete_timer(pd->recovery->timer, pet_recovery_timer); + iTimer->delete_timer(pd->recovery->timer, pet_recovery_timer); } else //Init pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery)); @@ -12020,9 +11995,9 @@ BUILDIN(petheal) if (pd->s_skill->timer != INVALID_TIMER) { if (pd->s_skill->id) - delete_timer(pd->s_skill->timer, pet_skill_support_timer); + iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer); else - delete_timer(pd->s_skill->timer, pet_heal_timer); + iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer); } } else //init memory pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support)); @@ -12038,7 +12013,7 @@ BUILDIN(petheal) if (battle_config.pet_equip_required && pd->pet.equip == 0) pd->s_skill->timer = INVALID_TIMER; else - pd->s_skill->timer = add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0); + pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0); return true; } @@ -12114,9 +12089,9 @@ BUILDIN(petskillsupport) if (pd->s_skill->timer != INVALID_TIMER) { if (pd->s_skill->id) - delete_timer(pd->s_skill->timer, pet_skill_support_timer); + iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer); else - delete_timer(pd->s_skill->timer, pet_heal_timer); + iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer); } } else //init memory pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support)); @@ -12131,7 +12106,7 @@ BUILDIN(petskillsupport) if (battle_config.pet_equip_required && pd->pet.equip == 0) pd->s_skill->timer = INVALID_TIMER; else - pd->s_skill->timer = add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0); + pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0); return true; } @@ -12161,7 +12136,7 @@ BUILDIN(skilleffect) /// npcskilleffect "<skill name>",<level>,<x>,<y> BUILDIN(npcskilleffect) { - struct block_list *bl= map_id2bl(st->oid); + struct block_list *bl= iMap->id2bl(st->oid); uint16 skill_id=( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); uint16 skill_lv=script_getnum(st,3); @@ -12169,7 +12144,7 @@ BUILDIN(npcskilleffect) int y=script_getnum(st,5); if (bl) - clif->skill_poseffect(bl,skill_id,skill_lv,x,y,gettick()); + clif->skill_poseffect(bl,skill_id,skill_lv,x,y,iTimer->gettick()); return true; } @@ -12179,7 +12154,7 @@ BUILDIN(npcskilleffect) *------------------------------------------*/ BUILDIN(specialeffect) { - struct block_list *bl=map_id2bl(st->oid); + struct block_list *bl=iMap->id2bl(st->oid); int type = script_getnum(st,2); enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA; @@ -12213,7 +12188,7 @@ BUILDIN(specialeffect2) enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA; if( script_hasdata(st,4) ) - sd = map_nick2sd(script_getstr(st,4)); + sd = iMap->nick2sd(script_getstr(st,4)); if (sd) clif->specialeffect(&sd->bl, type, target); @@ -12236,7 +12211,7 @@ BUILDIN(nude) if( sd->equip_index[ i ] >= 0 ) { if( !calcflag ) calcflag = 1; - pc_unequipitem( sd , sd->equip_index[ i ] , 2); + pc->unequipitem( sd , sd->equip_index[ i ] , 2); } } @@ -12268,7 +12243,7 @@ BUILDIN(atcommand) memset(&dummy_sd, 0, sizeof(TBL_PC)); if (st->oid) { - struct block_list* bl = map_id2bl(st->oid); + struct block_list* bl = iMap->id2bl(st->oid); memcpy(&dummy_sd.bl, bl, sizeof(struct block_list)); if (bl->type == BL_NPC) safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); @@ -12402,7 +12377,7 @@ BUILDIN(getmercinfo) { char_id = script_getnum(st,3); - if( ( sd = map_charid2sd(char_id) ) == NULL ) + if( ( sd = iMap->charid2sd(char_id) ) == NULL ) { ShowError("buildin_getmercinfo: No such character (char_id=%d).\n", char_id); script_pushnil(st); @@ -12496,8 +12471,7 @@ BUILDIN(jump_zero) /*========================================== * movenpc [MouseJstr] *------------------------------------------*/ -BUILDIN(movenpc) -{ +BUILDIN(movenpc) { TBL_NPC *nd = NULL; const char *npc; int x,y; @@ -12510,7 +12484,7 @@ BUILDIN(movenpc) return -1; if (script_hasdata(st,5)) - nd->ud.dir = script_getnum(st,5) % 8; + nd->dir = script_getnum(st,5) % 8; npc_movenpc(nd, x, y); return true; } @@ -12526,7 +12500,7 @@ BUILDIN(message) player = script_getstr(st,2); msg = script_getstr(st,3); - if((pl_sd=map_nick2sd((char *) player)) == NULL) + if((pl_sd=iMap->nick2sd((char *) player)) == NULL) return true; clif->message(pl_sd->fd, msg); @@ -12541,7 +12515,7 @@ BUILDIN(npctalk) const char* str; char name[NAME_LENGTH], message[256]; - struct npc_data* nd = (struct npc_data *)map_id2bl(st->oid); + struct npc_data* nd = (struct npc_data *)iMap->id2bl(st->oid); str = script_getstr(st,2); if(nd) @@ -12562,26 +12536,35 @@ BUILDIN(npcspeed) int speed; speed = script_getnum(st,2); - nd =(struct npc_data *)map_id2bl(st->oid); + nd =(struct npc_data *)iMap->id2bl(st->oid); - if( nd ) - { + if( nd ) { + if( nd->ud == &npc_base_ud ) { + nd->ud = NULL; + CREATE(nd->ud, struct unit_data, 1); + unit_dataset(&nd->bl); + } nd->speed = speed; - nd->ud.state.speed_changed = 1; + nd->ud->state.speed_changed = 1; } return true; } // make an npc walk to a position [Valaris] -BUILDIN(npcwalkto) -{ - struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid); +BUILDIN(npcwalkto) { + struct npc_data *nd=(struct npc_data *)iMap->id2bl(st->oid); int x=0,y=0; x=script_getnum(st,2); y=script_getnum(st,3); if(nd) { + if( nd->ud == &npc_base_ud ) { + nd->ud = NULL; + CREATE(nd->ud, struct unit_data, 1); + unit_dataset(&nd->bl); + } + if (!nd->status.hp) { status_calc_npc(nd, true); } else { @@ -12595,7 +12578,7 @@ BUILDIN(npcwalkto) // stop an npc's movement [Valaris] BUILDIN(npcstop) { - struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid); + struct npc_data *nd=(struct npc_data *)iMap->id2bl(st->oid); if(nd) { unit_stop_walking(&nd->bl,1|4); @@ -12716,7 +12699,7 @@ BUILDIN(getmapxy) switch (type){ case 0: //Get Character Position if( script_hasdata(st,6) ) - sd=map_nick2sd(script_getstr(st,6)); + sd=iMap->nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); @@ -12731,11 +12714,11 @@ BUILDIN(getmapxy) if (nd) bl = &nd->bl; } else //In case the origin is not an npc? - bl=map_id2bl(st->oid); + bl=iMap->id2bl(st->oid); break; case 2: //Get Pet Position if(script_hasdata(st,6)) - sd=map_nick2sd(script_getstr(st,6)); + sd=iMap->nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); @@ -12746,7 +12729,7 @@ BUILDIN(getmapxy) break; //Not supported? case 4: //Get Homun Position if(script_hasdata(st,6)) - sd=map_nick2sd(script_getstr(st,6)); + sd=iMap->nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); @@ -12755,7 +12738,7 @@ BUILDIN(getmapxy) break; case 5: //Get Mercenary Position if(script_hasdata(st,6)) - sd=map_nick2sd(script_getstr(st,6)); + sd=iMap->nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); @@ -12764,7 +12747,7 @@ BUILDIN(getmapxy) break; case 6: //Get Elemental Position if(script_hasdata(st,6)) - sd=map_nick2sd(script_getstr(st,6)); + sd=iMap->nick2sd(script_getstr(st,6)); else sd=script_rid2sd(st); @@ -12776,7 +12759,7 @@ BUILDIN(getmapxy) script_pushint(st,-1); return false; } - if (!bl) { //No object found. + if (!bl || bl->m == -1) { //No object found. script_pushint(st,-1); return true; } @@ -12846,7 +12829,7 @@ BUILDIN(summon) const char *str,*event=""; TBL_PC *sd; struct mob_data *md; - int tick = gettick(); + int tick = iTimer->gettick(); sd=script_rid2sd(st); if (!sd) return true; @@ -12867,8 +12850,8 @@ BUILDIN(summon) md->master_id=sd->bl.id; md->special_state.ai = AI_ATTACK; if( md->deletetimer != INVALID_TIMER ) - delete_timer(md->deletetimer, mob_timer_delete); - md->deletetimer = add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,md->bl.id,0); + iTimer->delete_timer(md->deletetimer, mob_timer_delete); + md->deletetimer = iTimer->add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,md->bl.id,0); mob_spawn (md); //Now it is ready for spawning. clif->specialeffect(&md->bl,344,AREA); sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000); @@ -12881,13 +12864,13 @@ BUILDIN(summon) *------------------------------------------*/ BUILDIN(isnight) { - script_pushint(st,(night_flag == 1)); + script_pushint(st,(iMap->night_flag == 1)); return true; } BUILDIN(isday) { - script_pushint(st,(night_flag == 0)); + script_pushint(st,(iMap->night_flag == 0)); return true; } @@ -13087,12 +13070,12 @@ BUILDIN(getrefine) *-------------------------------------------------------*/ BUILDIN(night) { - if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1); + if (iMap->night_flag != 1) pc->map_night_timer(pc->night_timer_tid, 0, 0, 1); return true; } BUILDIN(day) { - if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1); + if (iMap->night_flag != 0) pc->map_day_timer(pc->day_timer_tid, 0, 0, 1); return true; } @@ -13109,9 +13092,9 @@ BUILDIN(unequip) sd = script_rid2sd(st); if( sd != NULL && num >= 1 && num <= ARRAYLENGTH(equip) ) { - i = pc_checkequip(sd,equip[num-1]); + i = pc->checkequip(sd,equip[num-1]); if (i >= 0) - pc_unequipitem(sd,i,1|2); + pc->unequipitem(sd,i,1|2); } return true; } @@ -13132,7 +13115,7 @@ BUILDIN(equip) } ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == nameid ); if( i < MAX_INVENTORY ) - pc_equipitem(sd,i,item_data->equip); + pc->equipitem(sd,i,item_data->equip); return true; } @@ -13521,7 +13504,7 @@ BUILDIN(implode) sprintf(output,"%s","NULL"); } else { for(i = 0; i <= array_size; ++i) { - temp = (char*) get_val2(st, reference_uid(id, i), reference_getref(data)); + temp = (char*) script->get_val2(st, reference_uid(id, i), reference_getref(data)); len += strlen(temp); script_removetop(st, -1, 0); } @@ -13536,7 +13519,7 @@ BUILDIN(implode) //build output for(i = 0; i < array_size; ++i) { - temp = (char*) get_val2(st, reference_uid(id, i), reference_getref(data)); + temp = (char*) script->get_val2(st, reference_uid(id, i), reference_getref(data)); len = strlen(temp); memcpy(&output[k], temp, len); k += len; @@ -13546,7 +13529,7 @@ BUILDIN(implode) } script_removetop(st, -1, 0); } - temp = (char*) get_val2(st, reference_uid(id, array_size), reference_getref(data)); + temp = (char*) script->get_val2(st, reference_uid(id, array_size), reference_getref(data)); len = strlen(temp); memcpy(&output[k], temp, len); k += len; @@ -14001,14 +13984,14 @@ BUILDIN(setnpcdisplay) if( script_hasdata(st,5) ) size = script_getnum(st,5); - get_val(st, data); + script->get_val(st, data); if( data_isstring(data) ) newname = script->conv_str(st,data); else if( data_isint(data) ) class_ = script->conv_num(st,data); else { - ShowError("script:setnpcdisplay: expected a string or number\n"); + ShowError("script:setnpcdisplay: expected string or number\n"); script_reportdata(data); return false; } @@ -14266,7 +14249,7 @@ BUILDIN(getd) elem = 0; // Push the 'pointer' so it's more flexible [Lance] - push_val(st->stack, C_NAME, reference_uid(add_str(varname), elem)); + script->push_val(st->stack, C_NAME, reference_uid(add_str(varname), elem),NULL); return true; } @@ -14455,7 +14438,7 @@ BUILDIN(npcshopattach) } if (flag) - nd->master_nd = ((struct npc_data *)map_id2bl(st->oid)); + nd->master_nd = ((struct npc_data *)iMap->id2bl(st->oid)); else nd->master_nd = NULL; @@ -14589,7 +14572,7 @@ BUILDIN(checkvending) // check vending [Nab4] TBL_PC *sd = NULL; if(script_hasdata(st,2)) - sd = map_nick2sd(script_getstr(st,2)); + sd = iMap->nick2sd(script_getstr(st,2)); else sd = script_rid2sd(st); @@ -14607,7 +14590,7 @@ BUILDIN(checkchatting) // check chatting [Marka] TBL_PC *sd = NULL; if(script_hasdata(st,2)) - sd = map_nick2sd(script_getstr(st,2)); + sd = iMap->nick2sd(script_getstr(st,2)); else sd = script_rid2sd(st); @@ -14624,7 +14607,7 @@ BUILDIN(checkidle) TBL_PC *sd = NULL; if (script_hasdata(st, 2)) - sd = map_nick2sd(script_getstr(st, 2)); + sd = iMap->nick2sd(script_getstr(st, 2)); else sd = script_rid2sd(st); @@ -14751,7 +14734,7 @@ BUILDIN(rid2name) { struct block_list *bl = NULL; int rid = script_getnum(st,2); - if((bl = map_id2bl(rid))) + if((bl = iMap->id2bl(rid))) { switch(bl->type) { case BL_MOB: script_pushstrcopy(st,((TBL_MOB*)bl)->name); break; @@ -14781,7 +14764,7 @@ BUILDIN(pcblockmove) flag = script_getnum(st,3); if(id) - sd = map_id2sd(id); + sd = iMap->id2sd(id); else sd = script_rid2sd(st); @@ -14801,12 +14784,12 @@ BUILDIN(pcfollow) targetid = script_getnum(st,3); if(id) - sd = map_id2sd(id); + sd = iMap->id2sd(id); else sd = script_rid2sd(st); if(sd) - pc_follow(sd, targetid); + pc->follow(sd, targetid); return true; } @@ -14820,12 +14803,12 @@ BUILDIN(pcstopfollow) id = script_getnum(st,2); if(id) - sd = map_id2sd(id); + sd = iMap->id2sd(id); else sd = script_rid2sd(st); if(sd) - pc_stop_following(sd); + pc->stop_following(sd); return true; } @@ -14842,7 +14825,7 @@ BUILDIN(unitwalk) { struct block_list* bl; - bl = map_id2bl(script_getnum(st,2)); + bl = iMap->id2bl(script_getnum(st,2)); if( bl == NULL ) { script_pushint(st, 0); @@ -14856,7 +14839,7 @@ BUILDIN(unitwalk) else { int map_id = script_getnum(st,3); - script_pushint(st, unit_walktobl(bl,map_id2bl(map_id),65025,1)); + script_pushint(st, unit_walktobl(bl,iMap->id2bl(map_id),65025,1)); } return true; @@ -14867,7 +14850,7 @@ BUILDIN(unitwalk) /// unitkill <unit_id>; BUILDIN(unitkill) { - struct block_list* bl = map_id2bl(script_getnum(st,2)); + struct block_list* bl = iMap->id2bl(script_getnum(st,2)); if( bl != NULL ) status_kill(bl); @@ -14893,14 +14876,14 @@ BUILDIN(unitwarp) y = (short)script_getnum(st,5); if (!unit_id) //Warp the script's runner - bl = map_id2bl(st->rid); + bl = iMap->id2bl(st->rid); else - bl = map_id2bl(unit_id); + bl = iMap->id2bl(unit_id); if( strcmp(mapname,"this") == 0 ) map = bl?bl->m:-1; else - map = map_mapname2mapid(mapname); + map = iMap->mapname2mapid(mapname); if( map >= 0 && bl != NULL ) script_pushint(st, unit_warp(bl,map,x,y,CLR_OUTSIGHT)); @@ -14925,21 +14908,21 @@ BUILDIN(unitattack) int actiontype = 0; // get unit - unit_bl = map_id2bl(script_getnum(st,2)); + unit_bl = iMap->id2bl(script_getnum(st,2)); if( unit_bl == NULL ) { script_pushint(st, 0); return true; } data = script_getdata(st, 3); - get_val(st, data); + script->get_val(st, data); if( data_isstring(data) ) { - TBL_PC* sd = map_nick2sd(script->conv_str(st, data)); + TBL_PC* sd = iMap->nick2sd(script->conv_str(st, data)); if( sd != NULL ) target_bl = &sd->bl; } else - target_bl = map_id2bl(script->conv_num(st, data)); + target_bl = iMap->id2bl(script->conv_num(st, data)); // request the attack if( target_bl == NULL ) { @@ -14954,7 +14937,7 @@ BUILDIN(unitattack) switch( unit_bl->type ) { case BL_PC: - clif->pActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick()); + clif->pActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, iTimer->gettick()); script_pushint(st, 1); return true; case BL_MOB: @@ -14982,7 +14965,7 @@ BUILDIN(unitstop) unit_id = script_getnum(st,2); - bl = map_id2bl(unit_id); + bl = iMap->id2bl(unit_id); if( bl != NULL ) { unit_stop_attack(bl); @@ -15006,7 +14989,7 @@ BUILDIN(unittalk) unit_id = script_getnum(st,2); message = script_getstr(st, 3); - bl = map_id2bl(unit_id); + bl = iMap->id2bl(unit_id); if( bl != NULL ) { struct StringBuf sbuf; @@ -15034,7 +15017,7 @@ BUILDIN(unitemote) unit_id = script_getnum(st,2); emotion = script_getnum(st,3); - bl = map_id2bl(unit_id); + bl = iMap->id2bl(unit_id); if( bl != NULL ) clif->emotion(bl, emotion); @@ -15058,7 +15041,7 @@ BUILDIN(unitskilluseid) skill_lv = script_getnum(st,4); target_id = ( script_hasdata(st,5) ? script_getnum(st,5) : unit_id ); - bl = map_id2bl(unit_id); + bl = iMap->id2bl(unit_id); if( bl != NULL ) unit_skilluse_id(bl, target_id, skill_id, skill_lv); @@ -15084,7 +15067,7 @@ BUILDIN(unitskillusepos) skill_x = script_getnum(st,5); skill_y = script_getnum(st,6); - bl = map_id2bl(unit_id); + bl = iMap->id2bl(unit_id); if( bl != NULL ) unit_skilluse_pos(bl, skill_x, skill_y, skill_id, skill_lv); @@ -15133,7 +15116,7 @@ BUILDIN(sleep2) if( ticks <= 0 ) {// do nothing - script_pushint(st, (map_id2sd(st->rid)!=NULL)); + script_pushint(st, (iMap->id2sd(st->rid)!=NULL)); } else if( !st->sleep.tick ) {// sleep for the target amount of time @@ -15144,7 +15127,7 @@ BUILDIN(sleep2) {// sleep time is over st->state = RUN; st->sleep.tick = 0; - script_pushint(st, (map_id2sd(st->rid)!=NULL)); + script_pushint(st, (iMap->id2sd(st->rid)!=NULL)); } return true; } @@ -15152,47 +15135,41 @@ BUILDIN(sleep2) /// Awakes all the sleep timers of the target npc /// /// awake "<npc name>"; -BUILDIN(awake) -{ +BUILDIN(awake) { + DBIterator *iter; + struct script_state *tst; struct npc_data* nd; - struct linkdb_node *node = (struct linkdb_node *)sleep_db; - nd = npc_name2id(script_getstr(st, 2)); - if( nd == NULL ) { + if( ( nd = npc_name2id(script_getstr(st, 2)) ) == NULL ) { ShowError("awake: NPC \"%s\" not found\n", script_getstr(st, 2)); return false; } - while( node ) - { - if( (int)__64BPTRSIZE(node->key) == nd->bl.id ) - {// sleep timer for the npc - struct script_state* tst = (struct script_state*)node->data; - TBL_PC* sd = map_id2sd(tst->rid); + iter = db_iterator(script->st_db); + + for( tst = dbi_first(iter); dbi_exists(iter); tst = dbi_next(iter) ) { + if( tst->oid == nd->bl.id ) { + TBL_PC* sd = iMap->id2sd(tst->rid); - if( tst->sleep.timer == INVALID_TIMER ) - {// already awake ??? - node = node->next; + if( tst->sleep.timer == INVALID_TIMER ) {// already awake ??? continue; } - if( (sd && sd->status.char_id != tst->sleep.charid) || (tst->rid && !sd)) - {// char not online anymore / another char of the same account is online - Cancel execution + if( (sd && sd->status.char_id != tst->sleep.charid) || (tst->rid && !sd)) { + // char not online anymore / another char of the same account is online - Cancel execution tst->state = END; tst->rid = 0; } - delete_timer(tst->sleep.timer, run_script_timer); - node = script_erase_sleepdb(node); + iTimer->delete_timer(tst->sleep.timer, run_script_timer); tst->sleep.timer = INVALID_TIMER; if(tst->state != RERUNLINE) tst->sleep.tick = 0; run_script_main(tst); } - else - { - node = node->next; - } } + + dbi_destroy(iter); + return true; } @@ -15235,7 +15212,7 @@ BUILDIN(getvariableofnpc) return false; } - push_val2(st->stack, C_NAME, reference_getuid(data), &nd->u.scr.script->script_vars ); + script->push_val(st->stack, C_NAME, reference_getuid(data), &nd->u.scr.script->script_vars ); return true; } @@ -15255,7 +15232,7 @@ BUILDIN(warpportal) struct skill_unit_group* group; struct block_list* bl; - bl = map_id2bl(st->oid); + bl = iMap->id2bl(st->oid); if( bl == NULL ) { ShowError("script:warpportal: npc is needed\n"); @@ -15289,7 +15266,7 @@ BUILDIN(openmail) if( sd == NULL ) return true; - mail_openmail(sd); + mail->openmail(sd); return true; } @@ -15314,12 +15291,12 @@ BUILDIN(openauction) /// @see cell_chk* constants in const.txt for the types BUILDIN(checkcell) { - int16 m = map_mapname2mapid(script_getstr(st,2)); + int16 m = iMap->mapname2mapid(script_getstr(st,2)); int16 x = script_getnum(st,3); int16 y = script_getnum(st,4); cell_chk type = (cell_chk)script_getnum(st,5); - script_pushint(st, map_getcell(m, x, y, type)); + script_pushint(st, iMap->getcell(m, x, y, type)); return true; } @@ -15331,7 +15308,7 @@ BUILDIN(checkcell) /// @see cell_* constants in const.txt for the types BUILDIN(setcell) { - int16 m = map_mapname2mapid(script_getstr(st,2)); + int16 m = iMap->mapname2mapid(script_getstr(st,2)); int16 x1 = script_getnum(st,3); int16 y1 = script_getnum(st,4); int16 x2 = script_getnum(st,5); @@ -15346,7 +15323,7 @@ BUILDIN(setcell) for( y = y1; y <= y2; ++y ) for( x = x1; x <= x2; ++x ) - map_setcell(m, x, y, type, flag); + map[m].setcell(m, x, y, type, flag); return true; } @@ -15601,7 +15578,7 @@ BUILDIN(checkquest) BUILDIN(showevent) { TBL_PC *sd = script_rid2sd(st); - struct npc_data *nd = map_id2nd(st->oid); + struct npc_data *nd = iMap->id2nd(st->oid); int state, color; if( sd == NULL || nd == NULL ) @@ -15630,9 +15607,9 @@ BUILDIN(waitingroom2bg) if( script_hasdata(st,7) ) nd = npc_name2id(script_getstr(st,7)); else - nd = (struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)iMap->id2bl(st->oid); - if( nd == NULL || (cd = (struct chat_data *)map_id2bl(nd->chat_id)) == NULL ) + if( nd == NULL || (cd = (struct chat_data *)iMap->id2bl(nd->chat_id)) == NULL ) { script_pushint(st,0); return true; @@ -15691,7 +15668,7 @@ BUILDIN(waitingroom2bg_single) y = script_getnum(st,5); nd = npc_name2id(script_getstr(st,6)); - if( nd == NULL || (cd = (struct chat_data *)map_id2bl(nd->chat_id)) == NULL || cd->users <= 0 ) + if( nd == NULL || (cd = (struct chat_data *)iMap->id2bl(nd->chat_id)) == NULL || cd->users <= 0 ) return true; if( (sd = cd->usersd[0]) == NULL ) @@ -15699,7 +15676,7 @@ BUILDIN(waitingroom2bg_single) if( bg_team_join(bg_id, sd) ) { - pc_setpos(sd, mapindex, x, y, CLR_TELEPORT); + pc->setpos(sd, mapindex, x, y, CLR_TELEPORT); script_pushint(st,1); } else @@ -15761,7 +15738,7 @@ BUILDIN(bg_monster_set_team) int id = script_getnum(st,2), bg_id = script_getnum(st,3); - if( (mbl = map_id2bl(id)) == NULL || mbl->type != BL_MOB ) + if( (mbl = iMap->id2bl(id)) == NULL || mbl->type != BL_MOB ) return true; md = (TBL_MOB *)mbl; md->bg_id = bg_id; @@ -15803,7 +15780,7 @@ BUILDIN(bg_getareausers) bg_id = script_getnum(st,2); str = script_getstr(st,3); - if( (bg = bg_team_search(bg_id)) == NULL || (m = map_mapname2mapid(str)) < 0 ) + if( (bg = bg_team_search(bg_id)) == NULL || (m = iMap->mapname2mapid(str)) < 0 ) { script_pushint(st,0); return true; @@ -15833,7 +15810,7 @@ BUILDIN(bg_updatescore) int16 m; str = script_getstr(st,2); - if( (m = map_mapname2mapid(str)) < 0 ) + if( (m = iMap->mapname2mapid(str)) < 0 ) return true; map[m].bgscore_lion = script_getnum(st,3); @@ -15870,25 +15847,28 @@ BUILDIN(bg_get_data) * Instancing Script Commands *------------------------------------------*/ -BUILDIN(instance_create) -{ +BUILDIN(instance_create) { const char *name; - int party_id, res; + int owner_id, res; + int type = IOT_PARTY; name = script_getstr(st, 2); - party_id = script_getnum(st, 3); + owner_id = script_getnum(st, 3); + if( script_hasdata(st,4) ) { + type = script_getnum(st, 4); + if( type < IOT_NONE || type >= IOT_MAX ) { + ShowError("buildin_instance_create: unknown instance type %d for '%s'\n",type,name); + return true; + } + } - res = instance_create(party_id, name); - if( res == -4 ) // Already exists - { + res = instance->create(owner_id, name, (enum instance_owner_type) type); + if( res == -4 ) { // Already exists script_pushint(st, -1); return true; - } - else if( res < 0 ) - { + } else if( res < 0 ) { const char *err; - switch(res) - { + switch(res) { case -3: err = "No free instances"; break; case -2: err = "Invalid party ID"; break; case -1: err = "Invalid type"; break; @@ -15903,44 +15883,39 @@ BUILDIN(instance_create) return true; } -BUILDIN(instance_destroy) -{ - int instance_id; - struct map_session_data *sd; - struct party_data *p; +BUILDIN(instance_destroy) { + int instance_id = -1; if( script_hasdata(st, 2) ) instance_id = script_getnum(st, 2); - else if( st->instance_id ) + else if( st->instance_id >= 0 ) instance_id = st->instance_id; - else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) - instance_id = p->instance_id; else return true; - if( instance_id <= 0 || instance_id >= MAX_INSTANCE ) - { + if( !instance->valid(instance_id) ) { ShowError("buildin_instance_destroy: Trying to destroy invalid instance %d.\n", instance_id); return true; } - instance_destroy(instance_id); + instance->destroy(instance_id); return true; } -BUILDIN(instance_attachmap) -{ - const char *name; +BUILDIN(instance_attachmap) { + const char *name, *map_name = NULL; int16 m; - int instance_id; + int instance_id = -1; bool usebasename = false; name = script_getstr(st,2); instance_id = script_getnum(st,3); - if( script_hasdata(st,4) && script_getnum(st,4) > 0) + if( script_hasdata(st,4) && script_getnum(st,4) > 0 ) usebasename = true; - if( (m = instance_add_map(name, instance_id, usebasename)) < 0 ) // [Saithis] - { + if( script_hasdata(st, 5) ) + map_name = script_getstr(st, 5); + + if( (m = instance->add_map(name, instance_id, usebasename, map_name)) < 0 ) { // [Saithis] ShowError("buildin_instance_attachmap: instance creation failed (%s): %d\n", name, m); script_pushconststr(st, ""); return true; @@ -15950,109 +15925,81 @@ BUILDIN(instance_attachmap) return true; } -BUILDIN(instance_detachmap) -{ - struct map_session_data *sd; - struct party_data *p; +BUILDIN(instance_detachmap) { const char *str; int16 m; - int instance_id; + int instance_id = -1; str = script_getstr(st, 2); if( script_hasdata(st, 3) ) instance_id = script_getnum(st, 3); - else if( st->instance_id ) + else if( st->instance_id >= 0 ) instance_id = st->instance_id; - else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) - instance_id = p->instance_id; else return true; - if( (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m,instance_id)) < 0 ) - { + if( (m = iMap->mapname2mapid(str)) < 0 || (m = instance->map2imap(m,instance_id)) < 0 ) { ShowError("buildin_instance_detachmap: Trying to detach invalid map %s\n", str); return true; } - instance_del_map(m); + instance->del_map(m); return true; } -BUILDIN(instance_attach) -{ - int instance_id; +BUILDIN(instance_attach) { + int instance_id = -1; instance_id = script_getnum(st, 2); - if( instance_id <= 0 || instance_id >= MAX_INSTANCE ) + if( !instance->valid(instance_id) ) return true; st->instance_id = instance_id; return true; } -BUILDIN(instance_id) -{ - int instance_id; - - if( script_hasdata(st, 2) ) - { - struct party_data *p; - struct map_session_data *sd; - int type; - type = script_getnum(st, 2); - if( type == 0 ) - instance_id = st->instance_id; - else if( type == 1 && (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL ) - instance_id = p->instance_id; - else - instance_id = 0; - } - else - instance_id = st->instance_id; - - script_pushint(st, instance_id); +BUILDIN(instance_id) { + script_pushint(st, st->instance_id); return true; } BUILDIN(instance_set_timeout) { int progress_timeout, idle_timeout; - int instance_id; - struct map_session_data *sd; - struct party_data *p; + int instance_id = -1; progress_timeout = script_getnum(st, 2); idle_timeout = script_getnum(st, 3); if( script_hasdata(st, 4) ) instance_id = script_getnum(st, 4); - else if( st->instance_id ) + else if( st->instance_id >= 0 ) instance_id = st->instance_id; - else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) - instance_id = p->instance_id; else return true; - if( instance_id > 0 ) - instance_set_timeout(instance_id, progress_timeout, idle_timeout); + if( instance_id >= 0 ) + instance->set_timeout(instance_id, progress_timeout, idle_timeout); return true; } -BUILDIN(instance_init) -{ +BUILDIN(instance_init) { int instance_id = script_getnum(st, 2); - if( instance[instance_id].state != INSTANCE_IDLE ) - { + if( !instance->valid(instance_id) ) { + ShowError("instance_init: invalid instance id %d.\n",instance_id); + return true; + } + + if( instances[instance_id].state != INSTANCE_IDLE ) { ShowError("instance_init: instance already initialized.\n"); return true; } - instance_init(instance_id); + instance->start(instance_id); return true; } -BUILDIN(instance_announce) -{ +BUILDIN(instance_announce) { int instance_id = script_getnum(st,2); const char *mes = script_getstr(st,3); int flag = script_getnum(st,4); @@ -16063,53 +16010,40 @@ BUILDIN(instance_announce) int fontY = script_hasdata(st,9) ? script_getnum(st,9) : 0; // default fontY int i; - struct map_session_data *sd; - struct party_data *p; - if( instance_id == 0 ) - { - if( st->instance_id ) + if( instance_id == -1 ) { + if( st->instance_id >= 0 ) instance_id = st->instance_id; - else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) - instance_id = p->instance_id; - else return true; + else + return true; } - if( instance_id <= 0 || instance_id >= MAX_INSTANCE ) + if( !instance->valid(instance_id) ) return true; - for( i = 0; i < instance[instance_id].num_map; i++ ) - map_foreachinmap(buildin_announce_sub, instance[instance_id].map[i], BL_PC, + for( i = 0; i < instances[instance_id].num_map; i++ ) + iMap->foreachinmap(buildin_announce_sub, instances[instance_id].map[i], BL_PC, mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY); return true; } -BUILDIN(instance_npcname) -{ +BUILDIN(instance_npcname) { const char *str; - int instance_id = 0; - - struct map_session_data *sd; - struct party_data *p; + int instance_id = -1; struct npc_data *nd; str = script_getstr(st, 2); if( script_hasdata(st, 3) ) instance_id = script_getnum(st, 3); - else if( st->instance_id ) + else if( st->instance_id >= 0 ) instance_id = st->instance_id; - else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) - instance_id = p->instance_id; - if( instance_id && (nd = npc_name2id(str)) != NULL ) - { + if( instance_id >= 0 && (nd = npc_name2id(str)) != NULL ) { static char npcname[NAME_LENGTH]; snprintf(npcname, sizeof(npcname), "dup_%d_%d", instance_id, nd->bl.id); script_pushconststr(st,npcname); - } - else - { + } else { ShowError("script:instance_npcname: invalid instance NPC (instance_id: %d, NPC name: \"%s\".)\n", instance_id, str); st->state = END; return false; @@ -16118,24 +16052,56 @@ BUILDIN(instance_npcname) return true; } -BUILDIN(has_instance) -{ +BUILDIN(has_instance) { struct map_session_data *sd; - struct party_data *p; const char *str; int16 m; - int instance_id = 0; + int instance_id = -1; str = script_getstr(st, 2); + + if( (m = iMap->mapname2mapid(str)) < 0 ) { + script_pushconststr(st, ""); + return true; + } + if( script_hasdata(st, 3) ) instance_id = script_getnum(st, 3); - else if( st->instance_id ) + else if( st->instance_id >= 0 ) instance_id = st->instance_id; - else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id ) - instance_id = p->instance_id; + else if( (sd = script_rid2sd(st)) != NULL ) { + struct party_data *p; + int i = 0, j = 0; + if( sd->instances ) { + for( i = 0; i < sd->instances; i++ ) { + ARR_FIND(0, instances[sd->instance[i]].num_map, j, map[instances[sd->instance[i]].map[j]].instance_src_map == m); + if( j != instances[sd->instance[i]].num_map ) + break; + } + if( i != sd->instances ) + instance_id = sd->instance[i]; + } + if( instance_id == -1 && sd->status.party_id && (p = party->search(sd->status.party_id)) && p->instances ) { + for( i = 0; i < p->instances; i++ ) { + ARR_FIND(0, instances[p->instance[i]].num_map, j, map[instances[p->instance[i]].map[j]].instance_src_map == m); + if( j != instances[p->instance[i]].num_map ) + break; + } + if( i != p->instances ) + instance_id = p->instance[i]; + } + if( instance_id == -1 && sd->guild && sd->guild->instances ) { + for( i = 0; i < sd->guild->instances; i++ ) { + ARR_FIND(0, instances[sd->guild->instance[i]].num_map, j, map[instances[sd->guild->instance[i]].map[j]].instance_src_map == m); + if( j != instances[sd->guild->instance[i]].num_map ) + break; + } + if( i != sd->guild->instances ) + instance_id = sd->guild->instance[i]; + } + } - if( !instance_id || (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m, instance_id)) < 0 ) - { + if( !instance->valid(instance_id) || (m = instance->map2imap(m, instance_id)) < 0 ) { script_pushconststr(st, ""); return true; } @@ -16143,38 +16109,41 @@ BUILDIN(has_instance) script_pushconststr(st, map[m].name); return true; } - -BUILDIN(instance_warpall) -{ - struct map_session_data *pl_sd; - int16 m, i; - int instance_id; +static int buildin_instance_warpall_sub(struct block_list *bl,va_list ap) { + struct map_session_data *sd = ((TBL_PC*)bl); + int mapindex = va_arg(ap,int); + int x = va_arg(ap,int); + int y = va_arg(ap,int); + + pc->setpos(sd,mapindex,x,y,CLR_TELEPORT); + + return 0; +} +BUILDIN(instance_warpall) { + int16 m; + int instance_id = -1; const char *mapn; int x, y; - unsigned short mapindex; - struct party_data *p = NULL; + int mapindex; mapn = script_getstr(st,2); x = script_getnum(st,3); y = script_getnum(st,4); + if( script_hasdata(st,5) ) instance_id = script_getnum(st,5); - else if( st->instance_id ) + else if( st->instance_id >= 0 ) instance_id = st->instance_id; - else if( (pl_sd = script_rid2sd(st)) != NULL && pl_sd->status.party_id && (p = party_search(pl_sd->status.party_id)) != NULL && p->instance_id ) - instance_id = p->instance_id; - else return true; - - if( (m = map_mapname2mapid(mapn)) < 0 || (map[m].flag.src4instance && (m = instance_mapid2imapid(m, instance_id)) < 0) ) + else return true; - if( !(p = party_search(instance[instance_id].party_id)) ) + if( (m = iMap->mapname2mapid(mapn)) < 0 || (map[m].flag.src4instance && (m = instance->mapid2imapid(m, instance_id)) < 0) ) return true; - + mapindex = map_id2index(m); - for( i = 0; i < MAX_PARTY; i++ ) - if( (pl_sd = p->data[i].sd) && map[pl_sd->bl.m].instance_id == st->instance_id ) pc_setpos(pl_sd,mapindex,x,y,CLR_TELEPORT); + iMap->foreachininstance(buildin_instance_warpall_sub, instance_id, BL_PC,mapindex,x,y); + return true; } @@ -16188,8 +16157,7 @@ BUILDIN(instance_warpall) * Example: instance_check_party (getcharid(1){,amount}{,min}{,max}); * Example 2: instance_check_party (getcharid(1),1,1,99); *------------------------------------------*/ -BUILDIN(instance_check_party) -{ +BUILDIN(instance_check_party) { struct map_session_data *pl_sd; int amount, min, max, i, party_id, c = 0; struct party_data *p = NULL; @@ -16201,7 +16169,7 @@ BUILDIN(instance_check_party) if( min < 1 || min > MAX_LEVEL){ ShowError("instance_check_party: Invalid min level, %d\n", min); return true; - }else if( max < 1 || max > MAX_LEVEL){ + } else if( max < 1 || max > MAX_LEVEL){ ShowError("instance_check_party: Invalid max level, %d\n", max); return true; } @@ -16210,14 +16178,14 @@ BUILDIN(instance_check_party) party_id = script_getnum(st,2); else return true; - if( !(p = party_search(party_id)) ){ + if( !(p = party->search(party_id)) ){ script_pushint(st, 0); // Returns false if party does not exist. return true; } for( i = 0; i < MAX_PARTY; i++ ) if( (pl_sd = p->data[i].sd) ) - if(map_id2bl(pl_sd->bl.id)){ + if(iMap->id2bl(pl_sd->bl.id)){ if(pl_sd->status.base_level < min){ script_pushint(st, 0); return true; @@ -16273,9 +16241,9 @@ static int buildin_mobuseskill_sub(struct block_list *bl,va_list ap) // 0:self, 1:target, 2:master, default:random switch( target ) { - case 0: tbl = map_id2bl(md->bl.id); break; - case 1: tbl = map_id2bl(md->target_id); break; - case 2: tbl = map_id2bl(md->master_id); break; + case 0: tbl = iMap->id2bl(md->bl.id); break; + case 1: tbl = iMap->id2bl(md->target_id); break; + case 2: tbl = iMap->id2bl(md->master_id); break; default:tbl = battle->get_enemy(&md->bl, DEFAULT_ENEMY_TYPE(md),skill->get_range2(&md->bl, skill_id, skill_lv)); break; } @@ -16303,13 +16271,12 @@ BUILDIN(areamobuseskill) int16 m; int range,mobid,skill_id,skill_lv,casttime,emotion,target,cancel; - if( (m = map_mapname2mapid(script_getstr(st,2))) < 0 ) - { + if( (m = iMap->mapname2mapid(script_getstr(st,2))) < 0 ) { ShowError("areamobuseskill: invalid map name.\n"); return true; } - if( map[m].flag.src4instance && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 ) + if( map[m].flag.src4instance && st->instance_id >= 0 && (m = instance->mapid2imapid(m, st->instance_id)) < 0 ) return true; center.m = m; @@ -16324,7 +16291,7 @@ BUILDIN(areamobuseskill) emotion = script_getnum(st,11); target = script_getnum(st,12); - map_foreachinrange(buildin_mobuseskill_sub, ¢er, range, BL_MOB, mobid, skill_id, skill_lv, casttime, cancel, emotion, target); + iMap->foreachinrange(buildin_mobuseskill_sub, ¢er, range, BL_MOB, mobid, skill_id, skill_lv, casttime, cancel, emotion, target); return true; } @@ -16344,7 +16311,8 @@ BUILDIN(progressbar) second = script_getnum(st,3); sd->progressbar.npc_id = st->oid; - sd->progressbar.timeout = gettick() + second*1000; + sd->progressbar.timeout = iTimer->gettick() + second*1000; + sd->state.workinprogress = 3; clif->progressbar(sd, strtol(color, (char **)NULL, 0), second); return true; @@ -16505,10 +16473,10 @@ BUILDIN(setdragon) { if( (sd = script_rid2sd(st)) == NULL ) return true; - if( !pc_checkskill(sd,RK_DRAGONTRAINING) || (sd->class_&MAPID_THIRDMASK) != MAPID_RUNE_KNIGHT ) + if( !pc->checkskill(sd,RK_DRAGONTRAINING) || (sd->class_&MAPID_THIRDMASK) != MAPID_RUNE_KNIGHT ) script_pushint(st,0);//Doesn't have the skill or it's not a Rune Knight else if ( pc_isridingdragon(sd) ) {//Is mounted; release - pc_setoption(sd, sd->sc.option&~OPTION_DRAGON); + pc->setoption(sd, sd->sc.option&~OPTION_DRAGON); script_pushint(st,1); } else {//Not mounted; Mount now. unsigned int option = OPTION_DRAGON1; @@ -16523,7 +16491,7 @@ BUILDIN(setdragon) { option = OPTION_DRAGON1; } } - pc_setoption(sd, sd->sc.option|option); + pc->setoption(sd, sd->sc.option|option); script_pushint(st,1); } return true; @@ -16553,9 +16521,10 @@ BUILDIN(setmounting) { TBL_PC* sd; if( (sd = script_rid2sd(st)) == NULL ) return true; - if( sd->sc.option&(OPTION_WUGRIDER|OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR) ) + if( sd->sc.option&(OPTION_WUGRIDER|OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR) ){ + clif->msgtable(sd->fd, 0X78b); script_pushint(st,0);//can't mount with one of these - else { + }else { if( sd->sc.data[SC_ALL_RIDING] ) status_change_end(&sd->bl, SC_ALL_RIDING, INVALID_TIMER); else @@ -16593,12 +16562,12 @@ BUILDIN(getcharip) if( script_hasdata(st, 2) ) { if (script_isstring(st, 2)) - sd = map_nick2sd(script_getstr(st, 2)); + sd = iMap->nick2sd(script_getstr(st, 2)); else if (script_isint(st, 2) || script_getnum(st, 2)) { int id; id = script_getnum(st, 2); - sd = (map_id2sd(id) ? map_id2sd(id) : map_charid2sd(id)); + sd = (iMap->id2sd(id) ? iMap->id2sd(id) : iMap->charid2sd(id)); } } else @@ -16784,7 +16753,7 @@ BUILDIN(useatcmd) memset(&dummy_sd, 0, sizeof(TBL_PC)); if( st->oid ) { - struct block_list* bl = map_id2bl(st->oid); + struct block_list* bl = iMap->id2bl(st->oid); memcpy(&dummy_sd.bl, bl, sizeof(struct block_list)); if( bl->type == BL_NPC ) safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); @@ -16902,10 +16871,10 @@ BUILDIN(getrandgroupitem) { for (i = 0; i < qty; i += get_count) { // if not pet egg if (!pet_create_egg(sd, nameid)) { - if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) { + if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) { clif->additem(sd, 0, 0, flag); - if( pc_candrop(sd,&item_tmp) ) - map_addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + if( pc->candrop(sd,&item_tmp) ) + iMap->addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); } } } @@ -16918,7 +16887,7 @@ BUILDIN(getrandgroupitem) { static int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap) { nullpo_ret(bl); - map_clearflooritem(bl); + iMap->clearflooritem(bl); return 0; } @@ -16930,19 +16899,19 @@ BUILDIN(cleanmap) int16 x0 = 0, y0 = 0, x1 = 0, y1 = 0; map = script_getstr(st, 2); - m = map_mapname2mapid(map); + m = iMap->mapname2mapid(map); if (!m) return false; if ((script_lastdata(st) - 2) < 4) { - map_foreachinmap(atcommand_cleanfloor_sub, m, BL_ITEM); + iMap->foreachinmap(atcommand_cleanfloor_sub, m, BL_ITEM); } else { x0 = script_getnum(st, 3); y0 = script_getnum(st, 4); x1 = script_getnum(st, 5); y1 = script_getnum(st, 6); if (x0 > 0 && y0 > 0 && x1 > 0 && y1 > 0) { - map_foreachinarea(atcommand_cleanfloor_sub, m, x0, y0, x1, y1, BL_ITEM); + iMap->foreachinarea(atcommand_cleanfloor_sub, m, x0, y0, x1, y1, BL_ITEM); } else { ShowError("cleanarea: invalid coordinate defined!\n"); return false; @@ -16968,7 +16937,7 @@ BUILDIN(npcskill) stat_point = script_getnum(st, 4); npc_level = script_getnum(st, 5); sd = script_rid2sd(st); - nd = (struct npc_data *)map_id2bl(sd->npc_id); + nd = (struct npc_data *)iMap->id2bl(sd->npc_id); if (stat_point > battle_config.max_third_parameter) { ShowError("npcskill: stat point exceeded maximum of %d.\n",battle_config.max_third_parameter ); @@ -16999,6 +16968,309 @@ BUILDIN(npcskill) return true; } +struct hQueue *script_hqueue_get(int idx) { + if( idx < 0 || idx >= script->hqs || script->hq[idx].items == -1 ) + return NULL; + return &script->hq[idx]; +} +/* set .@id,queue(); */ +/* creates queue, returns created queue id */ +BUILDIN(queue) { + int idx = script->hqs; + int i; + + for(i = 0; i < script->hqs; i++) { + if( script->hq[i].items == -1 ) { + break; + } + } + + if( i == script->hqs ) { + RECREATE(script->hq, struct hQueue, ++script->hqs); + script->hq[ idx ].item = NULL; + } else + idx = i; + + script->hq[ idx ].id = idx; + script->hq[ idx ].items = 0; + script->hq[ idx ].onDeath[0] = '\0'; + script->hq[ idx ].onLogOut[0] = '\0'; + script->hq[ idx ].onMapChange[0] = '\0'; + + script_pushint(st,idx); + return true; +} +/* set .@length,queuesize(.@queue_id); */ +/* returns queue length */ +BUILDIN(queuesize) { + int idx = script_getnum(st, 2); + + if( idx < 0 || idx >= script->hqs || script->hq[idx].items == -1 ) { + ShowWarning("buildin_queuesize: unknown queue id %d\n",idx); + script_pushint(st, 0); + } else + script_pushint(st, script->hq[ idx ].items ); + + return true; +} +bool script_hqueue_add(int idx, int var) { + if( idx < 0 || idx >= script->hqs || script->hq[idx].items == -1 ) { + ShowWarning("script_hqueue_add: unknown queue id %d\n",idx); + return true; + } else { + struct map_session_data *sd; + int i; + + for(i = 0; i < script->hq[idx].items; i++) { + if( script->hq[idx].item[i] == var ) { + return true; + } + } + + if( i == script->hq[idx].items ) { + + for(i = 0; i < script->hq[idx].items; i++) { + if( script->hq[idx].item[i] == 0 ) { + break; + } + } + + if( i == script->hq[idx].items ) + RECREATE(script->hq[idx].item, int, ++script->hq[idx].items); + + script->hq[idx].item[i] = var; + + if( var >= START_ACCOUNT_NUM && (sd = iMap->id2sd(var)) ) { + for(i = 0; i < sd->queues_count; i++) { + if( sd->queues[i] == -1 ) { + break; + } + } + + if( i == sd->queues_count ) + RECREATE(sd->queues, int, ++sd->queues_count); + + sd->queues[i] = idx; + } + + } + } + return false; +} +/* queueadd(.@queue_id,.@var_id); */ +/* adds a new entry to the queue, returns 1 if already in queue, 0 otherwise */ +BUILDIN(queueadd) { + int idx = script_getnum(st, 2); + int var = script_getnum(st, 3); + + script_pushint(st,script->queue_add(idx,var)?1:0); + + return true; +} +bool script_hqueue_remove(int idx, int var) { + if( idx < 0 || idx >= script->hqs || script->hq[idx].items == -1 ) { + ShowWarning("script_hqueue_remove: unknown queue id %d (used with var %d)\n",idx,var); + return true; + } else { + int i; + + for(i = 0; i < script->hq[idx].items; i++) { + if( script->hq[idx].item[i] == var ) { + return true; + } + } + + if( i != script->hq[idx].items ) { + struct map_session_data *sd; + script->hq[idx].item[i] = 0; + + if( var >= START_ACCOUNT_NUM && (sd = iMap->id2sd(var)) ) { + for(i = 0; i < sd->queues_count; i++) { + if( sd->queues[i] == var ) { + break; + } + } + + if( i != sd->queues_count ) + sd->queues[i] = -1; + } + + } + } + return false; +} +/* queueremove(.@queue_id,.@var_id); */ +/* removes a entry from the queue, returns 1 if not in queue, 0 otherwise */ +BUILDIN(queueremove) { + int idx = script_getnum(st, 2); + int var = script_getnum(st, 3); + + script_pushint(st, script->queue_remove(idx,var)?1:0); + + return true; +} + +/* queueopt(.@queue_id,optionType,<optional val>); */ +/* modifies the queue's options, when val is not provided the option is removed */ +/* when OnMapChange event is triggered, it sets a temp char var @QMapChangeTo$ with the destination map name */ +/* returns 1 when fails, 0 on success */ +BUILDIN(queueopt) { + int idx = script_getnum(st, 2); + int var = script_getnum(st, 3); + + if( idx < 0 || idx >= script->hqs || script->hq[idx].items == -1 ) { + ShowWarning("buildin_queueopt: unknown queue id %d\n",idx); + script_pushint(st, 1); + } else if( var <= HQO_NONE || var >= HQO_MAX ) { + ShowWarning("buildin_queueopt: unknown optionType %d\n",var); + script_pushint(st, 1); + } else { + switch( (enum hQueueOpt)var ) { + case HQO_OnDeath: + if( script_hasdata(st, 4) ) + safestrncpy(script->hq[idx].onDeath, script_getstr(st, 4), EVENT_NAME_LENGTH); + else + script->hq[idx].onDeath[0] = '\0'; + break; + case HQO_onLogOut: + if( script_hasdata(st, 4) ) + safestrncpy(script->hq[idx].onLogOut, script_getstr(st, 4), EVENT_NAME_LENGTH); + else + script->hq[idx].onLogOut[0] = '\0'; + break; + case HQO_OnMapChange: + if( script_hasdata(st, 4) ) + safestrncpy(script->hq[idx].onMapChange, script_getstr(st, 4), EVENT_NAME_LENGTH); + else + script->hq[idx].onMapChange[0] = '\0'; + break; + default: + ShowWarning("buildin_queueopt: unsupported optionType %d\n",var); + script_pushint(st, 1); + break; + } + } + + return true; +} +bool script_hqueue_del(int idx) { + if( idx < 0 || idx >= script->hqs || script->hq[idx].items == -1 ) { + ShowWarning("script_queue_del: unknown queue id %d\n",idx); + return true; + } else { + struct map_session_data *sd; + int i; + + for(i = 0; i < script->hq[idx].items; i++) { + if( script->hq[idx].item[i] >= START_ACCOUNT_NUM && (sd = iMap->id2sd(script->hq[idx].item[i])) ) { + int j; + for(j = 0; j < sd->queues_count; j++) { + if( sd->queues[j] == script->hq[idx].item[i] ) { + break; + } + } + + if( j != sd->queues_count ) + sd->queues[j] = -1; + } + } + + script->hq[idx].items = -1; + } + return false; +} +/* queuedel(.@queue_id); */ +/* deletes queue of id .@queue_id, returns 1 if id not found, 0 otherwise */ +BUILDIN(queuedel) { + int idx = script_getnum(st, 2); + + script_pushint(st,script->queue_del(idx)?1:0); + + return true; +} + +/* set .@id, queueiterator(.@queue_id); */ +/* creates a new queue iterator, returns its id */ +BUILDIN(queueiterator) { + int qid = script_getnum(st, 2); + struct hQueue *queue = NULL; + int idx = script->hqis; + int i; + + if( qid < 0 || qid >= script->hqs || script->hq[idx].items == -1 || !(queue = script->queue(qid)) ) { + ShowWarning("queueiterator: invalid queue id %d\n",qid); + return true; + } + + for(i = 0; i < script->hqis; i++) { + if( script->hqi[i].items == -1 ) { + break; + } + } + + if( i == script->hqis ) + RECREATE(script->hqi, struct hQueueIterator, ++script->hqis); + else + idx = i; + + RECREATE(script->hqi[ idx ].item, int, queue->items); + + memcpy(&script->hqi[idx].item, &queue->item, sizeof(int)*queue->items); + + script->hqi[ idx ].items = queue->items; + script->hqi[ idx ].pos = 0; + + script_pushint(st,idx); + return true; +} +/* Queue Iterator Get Next */ +/* returns next/first member in the iterator, 0 if none */ +BUILDIN(qiget) { + int idx = script_getnum(st, 2); + + if( idx < 0 || idx >= script->hqis ) { + ShowWarning("buildin_qiget: unknown queue iterator id %d\n",idx); + script_pushint(st, 0); + } else if ( script->hqi[idx].pos == script->hqi[idx].items ) { + script_pushint(st, 0); + } else { + struct hQueueIterator *it = &script->hqi[idx]; + script_pushint(st, it->item[it->pos++]); + } + + return true; +} +/* Queue Iterator Check */ +/* returns 1:0 if there is a next member in the iterator */ +BUILDIN(qicheck) { + int idx = script_getnum(st, 2); + + if( idx < 0 || idx >= script->hqis ) { + ShowWarning("buildin_qicheck: unknown queue iterator id %d\n",idx); + script_pushint(st, 0); + } else if ( script->hqi[idx].pos == script->hqi[idx].items ) { + script_pushint(st, 0); + } else { + script_pushint(st, 1); + } + + return true; +} +/* Queue Iterator Check */ +BUILDIN(qiclear) { + int idx = script_getnum(st, 2); + + if( idx < 0 || idx >= script->hqis ) { + ShowWarning("buildin_qiclear: unknown queue iterator id %d\n",idx); + script_pushint(st, 1); + } else { + script->hqi[idx].items = -1; + script_pushint(st, 0); + } + + return true; +} + // declarations that were supposed to be exported from npc_chat.c #ifdef PCRE_SUPPORT BUILDIN(defpattern); @@ -17010,9 +17282,9 @@ BUILDIN(npcskill) bool script_hp_add(char *name, char *args, bool (*func)(struct script_state *st)) { int n = add_str(name), i = 0; - if( str_data[n].type == C_FUNC ) { - str_data[n].func = func; - i = str_data[n].val; + if( script->str_data[n].type == C_FUNC ) { + script->str_data[n].func = func; + i = script->str_data[n].val; if( args ) { int slen = strlen(args); if( script->buildin[i] ) { @@ -17028,9 +17300,9 @@ bool script_hp_add(char *name, char *args, bool (*func)(struct script_state *st) } else { i = script->buildin_count; - str_data[n].type = C_FUNC; - str_data[n].val = i; - str_data[n].func = func; + script->str_data[n].type = C_FUNC; + script->str_data[n].val = i; + script->str_data[n].func = func; RECREATE(script->buildin, char *, ++script->buildin_count); @@ -17401,6 +17673,7 @@ void script_parse_builtin(void) { BUILDIN_DEF2(homunculus_evolution,"homevolution",""), //[orn] BUILDIN_DEF2(homunculus_mutate,"hommutate","?"), BUILDIN_DEF2(homunculus_shuffle,"homshuffle",""), //[Zephyrus] + BUILDIN_DEF(checkhomcall,""), BUILDIN_DEF(eaclass,"?"), //[Skotlex] BUILDIN_DEF(roclass,"i?"), //[Skotlex] BUILDIN_DEF(checkvending,"?"), @@ -17447,12 +17720,12 @@ void script_parse_builtin(void) { BUILDIN_DEF(bg_updatescore,"sii"), // Instancing - BUILDIN_DEF(instance_create,"si"), + BUILDIN_DEF(instance_create,"si?"), BUILDIN_DEF(instance_destroy,"?"), - BUILDIN_DEF(instance_attachmap,"si?"), + BUILDIN_DEF(instance_attachmap,"si??"), BUILDIN_DEF(instance_detachmap,"s?"), BUILDIN_DEF(instance_attach,"i"), - BUILDIN_DEF(instance_id,"?"), + BUILDIN_DEF(instance_id,""), BUILDIN_DEF(instance_set_timeout,"ii?"), BUILDIN_DEF(instance_init,"i"), BUILDIN_DEF(instance_announce,"isi?????"), @@ -17497,6 +17770,20 @@ void script_parse_builtin(void) { BUILDIN_DEF(checkquest, "i?"), BUILDIN_DEF(changequest, "ii"), BUILDIN_DEF(showevent, "ii"), + + /** + * hQueue [Ind/Hercules] + **/ + BUILDIN_DEF(queue,""), + BUILDIN_DEF(queuesize,"i"), + BUILDIN_DEF(queueadd,"ii"), + BUILDIN_DEF(queueremove,"ii"), + BUILDIN_DEF(queueopt,"ii?"), + BUILDIN_DEF(queuedel,"i"), + BUILDIN_DEF(queueiterator,"i"), + BUILDIN_DEF(qicheck,"i"), + BUILDIN_DEF(qiget,"i"), + BUILDIN_DEF(qiclear,"i"), }; int i,n, len = ARRAYLENGTH(BUILDIN), start = script->buildin_count; char* p; @@ -17527,12 +17814,12 @@ void script_parse_builtin(void) { else if (!strcmp(BUILDIN[i].name, "callfunc")) buildin_callfunc_ref = n; else if (!strcmp(BUILDIN[i].name, "getelementofarray") ) buildin_getelementofarray_ref = n; - if( str_data[n].func && str_data[n].func != BUILDIN[i].func ) + if( script->str_data[n].func && script->str_data[n].func != BUILDIN[i].func ) continue;/* something replaced it, skip. */ - str_data[n].type = C_FUNC; - str_data[n].val = offset; - str_data[n].func = BUILDIN[i].func; + script->str_data[n].type = C_FUNC; + script->str_data[n].val = offset; + script->str_data[n].func = BUILDIN[i].func; /* we only store the arguments, its the only thing used out of this */ if( slen ) { @@ -17550,9 +17837,30 @@ void script_parse_builtin(void) { void script_defaults(void) { script = &script_s; + script->st_db = NULL; + script->active_scripts = 0; + script->next_id = 0; + script->st_ers = NULL; + script->stack_ers = NULL; + + script->hq = NULL; + script->hqi = NULL; + script->hqs = script->hqis = 0; + memset(&script->hqe, 0, sizeof(script->hqe)); + script->buildin_count = 0; script->buildin = NULL; + script->str_data = NULL; + script->str_data_size = 0; + script->str_num = LABEL_START; + script->str_buf = NULL; + script->str_size = 0; + script->str_pos = 0; + + script->word_buf = NULL; + script->word_size = 0; + script->init = do_init_script; script->final = do_final_script; @@ -17560,4 +17868,17 @@ void script_defaults(void) { script->addScript = script_hp_add; script->conv_num = conv_num; script->conv_str = conv_str; + script->rid2sd = script_rid2sd; + script->detach_rid = script_detach_rid; + script->push_val = push_val; + script->get_val = get_val; + script->get_val2 = get_val2; + script->push_str = push_str; + script->push_copy = push_copy; + script->pop_stack = pop_stack; + + script->queue = script_hqueue_get; + script->queue_add = script_hqueue_add; + script->queue_del = script_hqueue_del; + script->queue_remove = script_hqueue_remove; } |