diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-02-15 20:54:36 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-02-15 20:54:36 +0000 |
commit | eea2f3a5d61f2235381614fee2e9983bcffa4e73 (patch) | |
tree | 296303d831282d0b314714bb3da241ee0bda601f | |
parent | 60027d5509cddf09a136261f8a56724b65e2f2b8 (diff) | |
download | hercules-eea2f3a5d61f2235381614fee2e9983bcffa4e73.tar.gz hercules-eea2f3a5d61f2235381614fee2e9983bcffa4e73.tar.bz2 hercules-eea2f3a5d61f2235381614fee2e9983bcffa4e73.tar.xz hercules-eea2f3a5d61f2235381614fee2e9983bcffa4e73.zip |
Cleaned up set_reg and the surrounding code
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9869 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r-- | Changelog-Trunk.txt | 3 | ||||
-rw-r--r-- | src/map/script.c | 130 |
2 files changed, 61 insertions, 72 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 9fdda5462..5df6c9ff6 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -4,6 +4,7 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. 2007/02/15 + * Cleaned up set_reg (the same procedure as get_val) [ultramage] * The default packet version is now 8. Clients from November2006 and before can no longer get past the char-server unless you change it back to 7. * Fixed Storm Gust counter freezing on fourth hit instead of third. @@ -11,6 +12,8 @@ IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. decimals get discarded on level up (so the real minimum/maximum displayed was off). 2007/02/13 + * Reverted some mobdb lines + * Cleaned up clif_party_info's interface a bit [ultramage] * Applied Rayce's dangling pointer fix when returning a temporary npc string variable (those starting with .@) * Required Weapon, ammo, and skill state are now only checked on begin diff --git a/src/map/script.c b/src/map/script.c index 8441763cc..a211bf73b 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1973,96 +1973,82 @@ int get_val(struct script_state* st, struct script_data* data) return 0; } /*========================================== - * 変数の読み取り2 - *------------------------------------------ - */ -void* get_val2(struct script_state*st,int num,struct linkdb_node **ref) + * Retrieves the value of a script variable + *------------------------------------------*/ +void* get_val2(struct script_state* st, int num, struct linkdb_node** ref) { struct script_data dat; - dat.type=C_NAME; - dat.u.num=num; - dat.ref=ref; - get_val(st,&dat); - if( dat.type==C_INT ) return (void*)dat.u.num; - else return (void*)dat.u.str; + dat.type = C_NAME; + dat.u.num = num; + dat.ref = ref; + get_val(st, &dat); + return (dat.type == C_INT) ? (void*)dat.u.num : (void*)dat.u.str; } /*========================================== - * 変数設定用 - *------------------------------------------ - */ -static int set_reg(struct script_state*st,struct map_session_data *sd,int num,char *name,void *v,struct linkdb_node** ref) + * Stores the value of a script variable + *------------------------------------------*/ +static int set_reg(struct script_state* st, struct map_session_data* sd, int num, char* name, void* value, struct linkdb_node** ref) { - char prefix=*name; - char postfix=name[strlen(name)-1]; + char prefix = name[0]; char postfix = name[strlen(name)-1]; - if( postfix=='$' ){ - char *str=(char*)v; - if( prefix=='@'){ - pc_setregstr(sd,num,str); - }else if(prefix=='$') { - mapreg_setregstr(num,str); - }else if(prefix=='#') { - if( name[1]=='#' ) - pc_setaccountreg2str(sd,name,str); - else - pc_setaccountregstr(sd,name,str); - }else if(prefix=='.') { - char *p; - struct linkdb_node **n; - if( ref ) { - n = ref; - } else if( name[1] == '@' ) { - n = st->stack->var_function; - } else { - n = &st->script->script_vars; - } + if (postfix == '$') { // string variable + + char* str = (char*)value; + switch (prefix) { + case '@': + pc_setregstr(sd, num, str); break; + case '$': + mapreg_setregstr(num, str); break; + case '#': + (name[1] == '#') ? pc_setaccountreg2str(sd, name, str) : pc_setaccountregstr(sd, name, str); break; + case '.': { + char* p; + struct linkdb_node** n; + n = (ref) ? ref : (name[1] == '@') ? st->stack->var_function : &st->script->script_vars; p = linkdb_search(n, (void*)num); - if(p) { + if (p) { linkdb_erase(n, (void*)num); aFree(p); } - if( ((char*)v)[0] ) - linkdb_insert(n, (void*)num, aStrdup(v)); - }else{ - pc_setglobalreg_str(sd,name,str); - } // [zBuffer] - }else{ - // 数値 - int val = (int)v; - if(str_data[num&0x00ffffff].type==C_PARAM){ - pc_setparam(sd,str_data[num&0x00ffffff].val,val); - }else if(prefix=='@') { - pc_setreg(sd,num,val); - }else if(prefix=='$') { - mapreg_setreg(num,val); - }else if(prefix=='#') { - if( name[1]=='#' ) - pc_setaccountreg2(sd,name,val); - else - pc_setaccountreg(sd,name,val); - }else if(prefix == '.') { - struct linkdb_node **n; - if( ref ) { - n = ref; - } else if( name[1] == '@' ) { - n = st->stack->var_function; - } else { - n = &st->script->script_vars; + if (str[0]) linkdb_insert(n, (void*)num, aStrdup(str)); } - if( val == 0 ) { + break; + default: + pc_setglobalreg_str(sd, name, str); break; + } + + } else { // integer variable + + int val = (int)value; + if(str_data[num&0x00ffffff].type == C_PARAM) + pc_setparam(sd, str_data[num&0x00ffffff].val, val); + else + switch (prefix) { + case '@': + pc_setreg(sd, num, val); break; + case '$': + mapreg_setreg(num, val); break; + case '#': + (name[1] == '#') ? pc_setaccountreg2(sd, name, val) : pc_setaccountreg(sd, name, val); break; + case '.': { + struct linkdb_node** n; + n = (ref) ? ref : (name[1] == '@') ? st->stack->var_function : &st->script->script_vars; + if (val == 0) linkdb_erase(n, (void*)num); - } else { + else linkdb_replace(n, (void*)num, (void*)val); } - }else{ - pc_setglobalreg(sd,name,val); + break; + default: + pc_setglobalreg(sd, name, val); break; } } + return 0; } -int set_var(struct map_session_data *sd, char *name, void *val) +int set_var(struct map_session_data* sd, char* name, void* val) { return set_reg(NULL, sd, add_str(name), name, val, NULL); } @@ -6015,13 +6001,13 @@ BUILDIN_FUNC(getpartyleader) push_val(st->stack,C_INT,p->party.member[i].class_); break; case 4: - push_str(st->stack,C_CONSTSTR,(char*)mapindex_id2name(p->party.member[i].map)); + push_str(st->stack,C_STR,aStrdup(mapindex_id2name(p->party.member[i].map))); break; case 5: push_val(st->stack,C_INT,p->party.member[i].lv); break; default: - push_str(st->stack,C_CONSTSTR,p->party.member[i].name); + push_str(st->stack,C_STR,aStrdup(p->party.member[i].name)); break; } return 0; |