summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c112
1 files changed, 57 insertions, 55 deletions
diff --git a/src/map/script.c b/src/map/script.c
index adea269c7..7ca6a7ddd 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2275,7 +2275,10 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
for(i=0; i<size; i++)
linkdb_final(&script->syntax.curly[i].case_label);
#ifdef ENABLE_CASE_CHECK
- script->local_casecheck.clear();
+ script->local_casecheck.clear();
+ script->parser_current_src = NULL;
+ script->parser_current_file = NULL;
+ script->parser_current_line = 0;
#endif // ENABLE_CASE_CHECK
return NULL;
}
@@ -2292,7 +2295,10 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
script->size = 0;
script->buf = NULL;
#ifdef ENABLE_CASE_CHECK
- script->local_casecheck.clear();
+ script->local_casecheck.clear();
+ script->parser_current_src = NULL;
+ script->parser_current_file = NULL;
+ script->parser_current_line = 0;
#endif // ENABLE_CASE_CHECK
return NULL;
}
@@ -2310,7 +2316,10 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
script->size = 0;
script->buf = NULL;
#ifdef ENABLE_CASE_CHECK
- script->local_casecheck.clear();
+ script->local_casecheck.clear();
+ script->parser_current_src = NULL;
+ script->parser_current_file = NULL;
+ script->parser_current_line = 0;
#endif // ENABLE_CASE_CHECK
return NULL;
}
@@ -2428,6 +2437,9 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
code->script_vars = NULL;
#ifdef ENABLE_CASE_CHECK
script->local_casecheck.clear();
+ script->parser_current_src = NULL;
+ script->parser_current_file = NULL;
+ script->parser_current_line = 0;
#endif // ENABLE_CASE_CHECK
return code;
}
@@ -7654,9 +7666,8 @@ BUILDIN(getequippercentrefinery) {
/*==========================================
* Refine +1 item at pos and log and display refine
*------------------------------------------*/
-BUILDIN(successrefitem)
-{
- int i=-1,num,ep;
+BUILDIN(successrefitem) {
+ int i = -1 , num, ep, up = 1;
TBL_PC *sd;
num = script_getnum(st,2);
@@ -7664,6 +7675,9 @@ BUILDIN(successrefitem)
if( sd == NULL )
return true;
+ if( script_hasdata(st, 3) )
+ up = script_getnum(st, 3);
+
if (num > 0 && num <= ARRAYLENGTH(script->equip))
i=pc->checkequip(sd,script->equip[num-1]);
if(i >= 0) {
@@ -7675,7 +7689,8 @@ BUILDIN(successrefitem)
if (sd->status.inventory[i].refine >= MAX_REFINE)
return true;
- sd->status.inventory[i].refine++;
+ sd->status.inventory[i].refine += up;
+ sd->status.inventory[i].refine = cap_value( sd->status.inventory[i].refine, 0, MAX_REFINE);
pc->unequipitem(sd,i,2); // status calc will happen in pc->equipitem() below
clif->refine(sd->fd,0,i,sd->status.inventory[i].refine);
@@ -7803,8 +7818,7 @@ BUILDIN(delequip)
/*==========================================
*
*------------------------------------------*/
-BUILDIN(statusup)
-{
+BUILDIN(statusup) {
int type;
TBL_PC *sd;
@@ -7813,7 +7827,7 @@ BUILDIN(statusup)
if( sd == NULL )
return true;
- pc->statusup(sd,type);
+ pc->statusup(sd, type, 1);
return true;
}
@@ -14065,6 +14079,15 @@ BUILDIN(sscanf) {
argc = script_lastdata(st)-3;
len = strlen(format);
+
+ if (len != 0 && strlen(str) == 0) {
+ // If the source string is empty but the format string is not, we return -1
+ // according to the C specs. (if the format string is also empty, we shall
+ // continue and return 0: 0 conversions took place out of the 0 attempted.)
+ script_pushint(st, -1);
+ return true;
+ }
+
CREATE(buf, char, len*2+1);
// Issue sscanf for each parameter
@@ -14380,14 +14403,34 @@ BUILDIN(setnpcdisplay) {
return true;
}
-BUILDIN(atoi)
-{
+BUILDIN(atoi) {
const char *value;
value = script_getstr(st,2);
script_pushint(st,atoi(value));
return true;
}
+BUILDIN(axtoi) {
+ const char *hex = script_getstr(st,2);
+ long value = strtol(hex, NULL, 16);
+#if LONG_MAX > INT_MAX || LONG_MIN < INT_MIN
+ value = cap_value(value, INT_MIN, INT_MAX);
+#endif
+ script_pushint(st, (int)value);
+ return true;
+}
+
+BUILDIN(strtol) {
+ const char *string = script_getstr(st, 2);
+ int base = script_getnum(st, 3);
+ long value = strtol(string, NULL, base);
+#if LONG_MAX > INT_MAX || LONG_MIN < INT_MIN
+ value = cap_value(value, INT_MIN, INT_MAX);
+#endif
+ script_pushint(st, (int)value);
+ return true;
+}
+
// case-insensitive substring search [lordalfa]
BUILDIN(compare)
{
@@ -15113,47 +15156,6 @@ BUILDIN(searchitem)
return true;
}
-int axtoi(const char *hexStg)
-{
- int n = 0; // position in string
- int16 m = 0; // position in digit[] to shift
- int count; // loop index
- int intValue = 0; // integer value of hex string
- int digit[11]; // hold values to convert
- while (n < 10) {
- if (hexStg[n]=='\0')
- break;
- if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
- digit[n] = hexStg[n] & 0x0f; //convert to int
- else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
- digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
- else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
- digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
- else break;
- n++;
- }
- count = n;
- m = n - 1;
- n = 0;
- while(n < count) {
- // digit[n] is value of hex digit at position n
- // (m << 2) is the number of positions to shift
- // OR the bits into return value
- intValue = intValue | (digit[n] << (m << 2));
- m--; // adjust the position to set
- n++; // next digit to process
- }
- return (intValue);
-}
-
-// [Lance] Hex string to integer converter
-BUILDIN(axtoi)
-{
- const char *hex = script_getstr(st,2);
- script_pushint(st,script->axtoi(hex));
- return true;
-}
-
// [zBuffer] List of player cont commands --->
BUILDIN(rid2name) {
struct block_list *bl = NULL;
@@ -18581,7 +18583,7 @@ void script_parse_builtin(void) {
BUILDIN_DEF(getequiprefinerycnt,"i"),
BUILDIN_DEF(getequipweaponlv,"i"),
BUILDIN_DEF(getequippercentrefinery,"i"),
- BUILDIN_DEF(successrefitem,"i"),
+ BUILDIN_DEF(successrefitem,"i?"),
BUILDIN_DEF(failedrefitem,"i"),
BUILDIN_DEF(downrefitem,"i?"),
BUILDIN_DEF(statusup,"i"),
@@ -18838,6 +18840,7 @@ void script_parse_builtin(void) {
BUILDIN_DEF(query_logsql,"s*"),
BUILDIN_DEF(escape_sql,"v"),
BUILDIN_DEF(atoi,"s"),
+ BUILDIN_DEF(strtol,"si"),
// [zBuffer] List of player cont commands --->
BUILDIN_DEF(rid2name,"i"),
BUILDIN_DEF(pcfollow,"ii"),
@@ -19221,7 +19224,6 @@ void script_defaults(void) {
script->playbgm_foreachpc_sub = playbgm_foreachpc_sub;
script->soundeffect_sub = soundeffect_sub;
script->buildin_query_sql_sub = buildin_query_sql_sub;
- script->axtoi = axtoi;
script->buildin_instance_warpall_sub = buildin_instance_warpall_sub;
script->buildin_mobuseskill_sub = buildin_mobuseskill_sub;
script->cleanfloor_sub = script_cleanfloor_sub;