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.c634
1 files changed, 388 insertions, 246 deletions
diff --git a/src/map/script.c b/src/map/script.c
index befb85304..fd653523d 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -55,6 +55,7 @@
#include "map/storage.h"
#include "map/unit.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/memmgr.h"
#include "common/md5calc.h"
#include "common/mmo.h" // NEW_CARTS
@@ -159,10 +160,8 @@ const char* script_op2name(int op) {
RETURN_OP_NAME(C_SUB_POST);
RETURN_OP_NAME(C_ADD_PRE);
RETURN_OP_NAME(C_SUB_PRE);
-#ifdef PCRE_SUPPORT
RETURN_OP_NAME(C_RE_EQ);
RETURN_OP_NAME(C_RE_NE);
-#endif // PCRE_SUPPORT
default:
ShowDebug("script_op2name: unexpected op=%d\n", op);
@@ -236,9 +235,9 @@ void script_reportsrc(struct script_state *st) {
break;
default:
if( bl->m >= 0 )
- ShowDebug("Source (Non-NPC type %d): name %s at %s (%d,%d)\n", bl->type, status->get_name(bl), map->list[bl->m].name, bl->x, bl->y);
+ ShowDebug("Source (Non-NPC type %u): name %s at %s (%d,%d)\n", bl->type, clif->get_bl_name(bl), map->list[bl->m].name, bl->x, bl->y);
else
- ShowDebug("Source (Non-NPC type %d): name %s (invisible/not on a map)\n", bl->type, status->get_name(bl));
+ ShowDebug("Source (Non-NPC type %u): name %s (invisible/not on a map)\n", bl->type, clif->get_bl_name(bl));
break;
}
}
@@ -266,7 +265,7 @@ void script_reportdata(struct script_data* data)
case C_NAME:// reference
if( reference_tovariable(data) ) {// variable
const char* name = reference_getname(data);
- ShowDebug("Data: variable name='%s' index=%d\n", name, reference_getindex(data));
+ ShowDebug("Data: variable name='%s' index=%u\n", name, reference_getindex(data));
} else if( reference_toconstant(data) ) {// constant
ShowDebug("Data: constant name='%s' value=%d\n", reference_getname(data), reference_getconstant(data));
} else if( reference_toparam(data) ) {// param
@@ -1379,6 +1378,10 @@ const char* parse_simpleexpr(const char *p)
return pv;
}
+ if (script->str_data[l].type == C_INT && script->str_data[l].deprecated) {
+ disp_warning_message("This constant is deprecated and it will be removed in a future version. Please see the script documentation and constants.conf for an alternative.\n", p);
+ }
+
p=script->skip_word(p);
if( *p == '[' ) {
// array(name[i] => getelementofarray(name,i) )
@@ -1442,10 +1445,8 @@ const char* script_parse_subexpr(const char* p,int limit)
|| (op=C_XOR, opl=4, len=1,*p=='^') // ^
|| (op=C_EQ, opl=6, len=2,*p=='=' && p[1]=='=') // ==
|| (op=C_NE, opl=6, len=2,*p=='!' && p[1]=='=') // !=
-#ifdef PCRE_SUPPORT
|| (op=C_RE_EQ, opl=6, len=2,*p=='~' && p[1]=='=') // ~=
|| (op=C_RE_NE, opl=6, len=2,*p=='~' && p[1]=='!') // ~!
-#endif // PCRE_SUPPORT
|| (op=C_R_SHIFT,opl=8, len=2,*p=='>' && p[1]=='>') // >>
|| (op=C_GE, opl=7, len=2,*p=='>' && p[1]=='=') // >=
|| (op=C_GT, opl=7, len=1,*p=='>') // >
@@ -1565,32 +1566,32 @@ const char* parse_curly_close(const char* p)
char label[256];
int l;
// Remove temporary variables
- sprintf(label,"__setr $@__SW%x_VAL,0;",script->syntax.curly[pos].index);
+ sprintf(label, "__setr $@__SW%x_VAL,0;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// Go to the end pointer unconditionally
- sprintf(label,"goto __SW%x_FIN;",script->syntax.curly[pos].index);
+ sprintf(label,"goto __SW%x_FIN;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// You are here labeled
- sprintf(label,"__SW%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
+ sprintf(label,"__SW%x_%x", (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].count);
l=script->add_str(label);
script->set_label(l,script->pos, p);
if(script->syntax.curly[pos].flag) {
//Exists default
- sprintf(label,"goto __SW%x_DEF;",script->syntax.curly[pos].index);
+ sprintf(label,"goto __SW%x_DEF;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
}
// Label end
- sprintf(label,"__SW%x_FIN",script->syntax.curly[pos].index);
+ sprintf(label,"__SW%x_FIN", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos, p);
linkdb_final(&script->syntax.curly[pos].case_label); // free the list of case label
@@ -1620,16 +1621,16 @@ const char* parse_syntax(const char* p)
int pos = script->syntax.curly_count - 1;
while(pos >= 0) {
if(script->syntax.curly[pos].type == TYPE_DO) {
- sprintf(label,"goto __DO%x_FIN;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __DO%x_FIN;", (unsigned int)script->syntax.curly[pos].index);
break;
} else if(script->syntax.curly[pos].type == TYPE_FOR) {
- sprintf(label,"goto __FR%x_FIN;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __FR%x_FIN;", (unsigned int)script->syntax.curly[pos].index);
break;
} else if(script->syntax.curly[pos].type == TYPE_WHILE) {
- sprintf(label,"goto __WL%x_FIN;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __WL%x_FIN;", (unsigned int)script->syntax.curly[pos].index);
break;
} else if(script->syntax.curly[pos].type == TYPE_SWITCH) {
- sprintf(label,"goto __SW%x_FIN;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __SW%x_FIN;", (unsigned int)script->syntax.curly[pos].index);
break;
}
pos--;
@@ -1663,13 +1664,13 @@ const char* parse_syntax(const char* p)
char *np;
if(script->syntax.curly[pos].count != 1) {
//Jump for FALLTHRU
- sprintf(label,"goto __SW%x_%xJ;",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
+ sprintf(label,"goto __SW%x_%xJ;", (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].count);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// You are here labeled
- sprintf(label,"__SW%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
+ sprintf(label,"__SW%x_%x", (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].count);
l=script->add_str(label);
script->set_label(l,script->pos, p);
}
@@ -1701,7 +1702,7 @@ const char* parse_syntax(const char* p)
if(*p != ':')
disp_error_message("parse_syntax: expect ':'",p);
sprintf(label,"if(%d != $@__SW%x_VAL) goto __SW%x_%x;",
- v,script->syntax.curly[pos].index,script->syntax.curly[pos].index,script->syntax.curly[pos].count+1);
+ v, (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].count+1);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
// Bad I do not parse twice
p2 = script->parse_line(label);
@@ -1709,7 +1710,7 @@ const char* parse_syntax(const char* p)
script->syntax.curly_count--;
if(script->syntax.curly[pos].count != 1) {
// Label after the completion of FALLTHRU
- sprintf(label,"__SW%x_%xJ",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
+ sprintf(label, "__SW%x_%xJ", (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].count);
l=script->add_str(label);
script->set_label(l,script->pos,p);
}
@@ -1718,7 +1719,7 @@ const char* parse_syntax(const char* p)
disp_error_message("parse_syntax: dup 'case'",p);
linkdb_insert(&script->syntax.curly[pos].case_label, (void*)h64BPTRSIZE(v), (void*)1);
- sprintf(label,"__setr $@__SW%x_VAL,0;",script->syntax.curly[pos].index);
+ sprintf(label, "__setr $@__SW%x_VAL,0;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
@@ -1732,14 +1733,14 @@ const char* parse_syntax(const char* p)
int pos = script->syntax.curly_count - 1;
while(pos >= 0) {
if(script->syntax.curly[pos].type == TYPE_DO) {
- sprintf(label,"goto __DO%x_NXT;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __DO%x_NXT;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[pos].flag = 1; //Flag put the link for continue
break;
} else if(script->syntax.curly[pos].type == TYPE_FOR) {
- sprintf(label,"goto __FR%x_NXT;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __FR%x_NXT;", (unsigned int)script->syntax.curly[pos].index);
break;
} else if(script->syntax.curly[pos].type == TYPE_WHILE) {
- sprintf(label,"goto __WL%x_NXT;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __WL%x_NXT;", (unsigned int)script->syntax.curly[pos].index);
break;
}
pos--;
@@ -1776,18 +1777,18 @@ const char* parse_syntax(const char* p)
if(*p != ':') {
disp_error_message("parse_syntax: need ':'",p);
}
- sprintf(label,"__SW%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
+ sprintf(label, "__SW%x_%x", (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].count);
l=script->add_str(label);
script->set_label(l,script->pos,p);
// Skip to the next link w/o condition
- sprintf(label,"goto __SW%x_%x;",script->syntax.curly[pos].index,script->syntax.curly[pos].count+1);
+ sprintf(label, "goto __SW%x_%x;", (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].count + 1);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// The default label
- sprintf(label,"__SW%x_DEF",script->syntax.curly[pos].index);
+ sprintf(label, "__SW%x_DEF", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
@@ -1805,7 +1806,7 @@ const char* parse_syntax(const char* p)
script->syntax.curly[script->syntax.curly_count].index = script->syntax.index++;
script->syntax.curly[script->syntax.curly_count].flag = 0;
// Label of the (do) form here
- sprintf(label,"__DO%x_BGN",script->syntax.curly[script->syntax.curly_count].index);
+ sprintf(label, "__DO%x_BGN", (unsigned int)script->syntax.curly[script->syntax.curly_count].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
script->syntax.curly_count++;
@@ -1836,7 +1837,7 @@ const char* parse_syntax(const char* p)
script->syntax.curly_count--;
// Form the start of label decision
- sprintf(label,"__FR%x_J",script->syntax.curly[pos].index);
+ sprintf(label, "__FR%x_J", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
@@ -1846,7 +1847,7 @@ const char* parse_syntax(const char* p)
;
} else {
// Skip to the end point if the condition is false
- sprintf(label,"__FR%x_FIN",script->syntax.curly[pos].index);
+ sprintf(label, "__FR%x_FIN", (unsigned int)script->syntax.curly[pos].index);
script->addl(script->add_str("__jump_zero"));
script->addc(C_ARG);
p=script->parse_expr(p);
@@ -1859,13 +1860,13 @@ const char* parse_syntax(const char* p)
p++;
// Skip to the beginning of the loop
- sprintf(label,"goto __FR%x_BGN;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __FR%x_BGN;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// Labels to form the next loop
- sprintf(label,"__FR%x_NXT",script->syntax.curly[pos].index);
+ sprintf(label, "__FR%x_NXT", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
@@ -1878,13 +1879,13 @@ const char* parse_syntax(const char* p)
script->parse_syntax_for_flag = 0;
// Skip to the determination process conditions
- sprintf(label,"goto __FR%x_J;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __FR%x_J;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// Loop start labeling
- sprintf(label,"__FR%x_BGN",script->syntax.curly[pos].index);
+ sprintf(label, "__FR%x_BGN", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
return p;
@@ -1925,7 +1926,7 @@ const char* parse_syntax(const char* p)
++script->syntax.curly_count;
// Jump over the function code
- sprintf(label, "goto __FN%x_FIN;", script->syntax.curly[script->syntax.curly_count-1].index);
+ sprintf(label, "goto __FN%x_FIN;", (unsigned int)script->syntax.curly[script->syntax.curly_count-1].index);
script->syntax.curly[script->syntax.curly_count].type = TYPE_NULL;
++script->syntax.curly_count;
script->parse_line(label);
@@ -1964,7 +1965,7 @@ const char* parse_syntax(const char* p)
script->syntax.curly[script->syntax.curly_count].count = 1;
script->syntax.curly[script->syntax.curly_count].index = script->syntax.index++;
script->syntax.curly[script->syntax.curly_count].flag = 0;
- sprintf(label,"__IF%x_%x",script->syntax.curly[script->syntax.curly_count].index,script->syntax.curly[script->syntax.curly_count].count);
+ sprintf(label, "__IF%x_%x", (unsigned int)script->syntax.curly[script->syntax.curly_count].index, (unsigned int)script->syntax.curly[script->syntax.curly_count].count);
script->syntax.curly_count++;
script->addl(script->add_str("__jump_zero"));
script->addc(C_ARG);
@@ -1988,7 +1989,7 @@ const char* parse_syntax(const char* p)
script->syntax.curly[script->syntax.curly_count].count = 1;
script->syntax.curly[script->syntax.curly_count].index = script->syntax.index++;
script->syntax.curly[script->syntax.curly_count].flag = 0;
- sprintf(label,"$@__SW%x_VAL",script->syntax.curly[script->syntax.curly_count].index);
+ sprintf(label, "$@__SW%x_VAL", (unsigned int)script->syntax.curly[script->syntax.curly_count].index);
script->syntax.curly_count++;
script->addl(script->add_str("__setr"));
script->addc(C_ARG);
@@ -2016,12 +2017,12 @@ const char* parse_syntax(const char* p)
script->syntax.curly[script->syntax.curly_count].index = script->syntax.index++;
script->syntax.curly[script->syntax.curly_count].flag = 0;
// Form the start of label decision
- sprintf(label,"__WL%x_NXT",script->syntax.curly[script->syntax.curly_count].index);
+ sprintf(label, "__WL%x_NXT", (unsigned int)script->syntax.curly[script->syntax.curly_count].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
// Skip to the end point if the condition is false
- sprintf(label,"__WL%x_FIN",script->syntax.curly[script->syntax.curly_count].index);
+ sprintf(label, "__WL%x_FIN", (unsigned int)script->syntax.curly[script->syntax.curly_count].index);
script->syntax.curly_count++;
script->addl(script->add_str("__jump_zero"));
script->addc(C_ARG);
@@ -2067,13 +2068,13 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
script->parse_nextline(false, p);
// Skip to the last location if
- sprintf(label,"goto __IF%x_FIN;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __IF%x_FIN;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// Put the label of the location
- sprintf(label,"__IF%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
+ sprintf(label, "__IF%x_%x", (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].count);
l=script->add_str(label);
script->set_label(l,script->pos,p);
@@ -2090,7 +2091,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
if(*p != '(') {
disp_error_message("need '('",p);
}
- sprintf(label,"__IF%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
+ sprintf(label, "__IF%x_%x", (unsigned int)script->syntax.curly[pos].index, (unsigned int)script->syntax.curly[pos].count);
script->addl(script->add_str("__jump_zero"));
script->addc(C_ARG);
p=script->parse_expr(p);
@@ -2111,7 +2112,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
// Close if
script->syntax.curly_count--;
// Put the label of the final location
- sprintf(label,"__IF%x_FIN",script->syntax.curly[pos].index);
+ sprintf(label, "__IF%x_FIN", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
if(script->syntax.curly[pos].flag == 1) {
@@ -2124,7 +2125,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
if(script->syntax.curly[pos].flag) {
// (Come here continue) to form the label here
- sprintf(label,"__DO%x_NXT",script->syntax.curly[pos].index);
+ sprintf(label, "__DO%x_NXT", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
}
@@ -2144,7 +2145,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
// do-block end is a new line
script->parse_nextline(false, p);
- sprintf(label,"__DO%x_FIN",script->syntax.curly[pos].index);
+ sprintf(label, "__DO%x_FIN", (unsigned int)script->syntax.curly[pos].index);
script->addl(script->add_str("__jump_zero"));
script->addc(C_ARG);
p=script->parse_expr(p);
@@ -2153,13 +2154,13 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
script->addc(C_FUNC);
// Skip to the starting point
- sprintf(label,"goto __DO%x_BGN;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __DO%x_BGN;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// Form label of the end point conditions
- sprintf(label,"__DO%x_FIN",script->syntax.curly[pos].index);
+ sprintf(label, "__DO%x_FIN", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
p = script->skip_space(p);
@@ -2175,13 +2176,13 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
script->parse_nextline(false, p);
// Skip to the next loop
- sprintf(label,"goto __FR%x_NXT;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __FR%x_NXT;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// End for labeling
- sprintf(label,"__FR%x_FIN",script->syntax.curly[pos].index);
+ sprintf(label, "__FR%x_FIN", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
script->syntax.curly_count--;
@@ -2191,13 +2192,13 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
script->parse_nextline(false, p);
// Skip to the decision while
- sprintf(label,"goto __WL%x_NXT;",script->syntax.curly[pos].index);
+ sprintf(label, "goto __WL%x_NXT;", (unsigned int)script->syntax.curly[pos].index);
script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
script->parse_line(label);
script->syntax.curly_count--;
// End while labeling
- sprintf(label,"__WL%x_FIN",script->syntax.curly[pos].index);
+ sprintf(label, "__WL%x_FIN", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
script->syntax.curly_count--;
@@ -2210,7 +2211,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
script->syntax.curly_count--;
// Put the label of the location
- sprintf(label,"__FN%x_FIN",script->syntax.curly[pos].index);
+ sprintf(label, "__FN%x_FIN", (unsigned int)script->syntax.curly[pos].index);
l=script->add_str(label);
script->set_label(l,script->pos,p);
script->syntax.curly_count--;
@@ -2231,25 +2232,31 @@ bool script_get_constant(const char* name, int* value)
return false;
}
value[0] = script->str_data[n].val;
+ if (script->str_data[n].deprecated) {
+ ShowWarning("The constant '%s' is deprecated and it will be removed in a future version. Please see the script documentation and constants.conf for an alternative.\n", name);
+ }
return true;
}
/// Creates new constant or parameter with given value.
-void script_set_constant(const char* name, int value, bool isparameter) {
+void script_set_constant(const char *name, int value, bool is_parameter, bool is_deprecated)
+{
int n = script->add_str(name);
if( script->str_data[n].type == C_NOP ) {// new
- script->str_data[n].type = isparameter ? C_PARAM : C_INT;
+ script->str_data[n].type = is_parameter ? C_PARAM : C_INT;
script->str_data[n].val = value;
+ script->str_data[n].deprecated = is_deprecated ? 1 : 0;
} 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", ( 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(script->str_data[n].type));
+ ShowError("script_set_constant: Invalid name for %s '%s' (already defined as %s).\n", is_parameter ? "parameter" : "constant", name, script->op2name(script->str_data[n].type));
}
}
/* adds data to a existent constant in the database, inserted normally via parse */
-void script_set_constant2(const char *name, int value, bool isparameter) {
+void script_set_constant2(const char *name, int value, bool is_parameter, bool is_deprecated)
+{
int n = script->add_str(name);
if( script->str_data[n].type == C_PARAM ) {
@@ -2273,38 +2280,138 @@ void script_set_constant2(const char *name, int value, bool isparameter) {
script->str_data[n].label = -1;
}
- script->str_data[n].type = isparameter ? C_PARAM : C_INT;
+ script->str_data[n].type = is_parameter ? C_PARAM : C_INT;
script->str_data[n].val = value;
-
+ script->str_data[n].deprecated = is_deprecated ? 1 : 0;
}
-/*==========================================
- * Reading constant databases
- * const.txt
- *------------------------------------------*/
-void read_constdb(void) {
- FILE *fp;
- char line[1024],name[1024],val[1024];
- int type;
- sprintf(line, "%s/const.txt", map->db_path);
- fp=fopen(line, "r");
- if(fp==NULL) {
- ShowError("can't read %s\n", line);
- return ;
+/**
+ * Loads the constants database from constants.conf
+ */
+void read_constdb(void)
+{
+ struct config_t constants_conf;
+ char filepath[256];
+ struct config_setting_t *cdb;
+ struct config_setting_t *t;
+ int i = 0;
+
+ sprintf(filepath, "%s/constants.conf", map->db_path);
+
+ if (!libconfig->load_file(&constants_conf, filepath))
+ return;
+
+ if ((cdb = libconfig->setting_get_member(constants_conf.root, "constants_db")) == NULL) {
+ ShowError("can't read %s\n", filepath);
+ return;
}
- while (fgets(line, sizeof(line), fp)) {
- if (line[0] == '/' && line[1] == '/')
+
+ while ((t = libconfig->setting_get_elem(cdb, i++))) {
+ bool is_parameter = false;
+ bool is_deprecated = false;
+ int value = 0;
+ const char *name = config_setting_name(t);
+ const char *p = name;
+
+ while (*p != '\0') {
+ if (!ISALNUM(*p) && *p != '_')
+ break;
+ p++;
+ }
+ if (*p != '\0') {
+ ShowWarning("read_constdb: Invalid constant name %s. Skipping.\n", name);
+ continue;
+ }
+ if (strcmp(name, "comment__") == 0) {
+ const char *comment = libconfig->setting_get_string(t);
+ if (comment == NULL)
+ continue;
+ if (*comment == '\0')
+ comment = NULL;
+ script->constdb_comment(comment);
continue;
- type = 0;
- if (sscanf(line, "%1023[A-Za-z0-9_],%1023[-0-9xXA-Fa-f],%d", name, val, &type) >=2
- || sscanf(line, "%1023[A-Za-z0-9_] %1023[-0-9xXA-Fa-f] %d", name, val, &type) >=2
- ) {
- script->set_constant(name, (int)strtol(val, NULL, 0), (bool)type);
}
+ if (config_setting_is_aggregate(t)) {
+ int i32;
+ if (!libconfig->setting_lookup_int(t, "Value", &i32)) {
+ ShowWarning("read_constdb: Invalid entry for %s. Skipping.\n", name);
+ continue;
+ }
+ value = i32;
+ if (libconfig->setting_lookup_bool(t, "Parameter", &i32)) {
+ if (i32 != 0)
+ is_parameter = true;
+ }
+ if (libconfig->setting_lookup_bool(t, "Deprecated", &i32)) {
+ if (i32 != 0)
+ is_deprecated = true;
+ }
+ } else {
+ value = libconfig->setting_get_int(t);
+ }
+ if (is_parameter)
+ ShowWarning("read_constdb: Defining parameters in the constants configuration is deprecated and will no longer be possible in a future version. Parameters should be defined in source. (parameter = '%s')\n", name);
+ script->set_constant(name, value, is_parameter, is_deprecated);
}
- fclose(fp);
+ script->constdb_comment(NULL);
+ libconfig->destroy(&constants_conf);
}
+/**
+ * Sets the current constdb comment.
+ *
+ * This function does nothing (used by plugins only)
+ *
+ * @param comment The comment to set (NULL to unset)
+ */
+void script_constdb_comment(const char *comment)
+{
+ (void)comment;
+}
+
+void script_load_parameters(void)
+{
+ int i = 0;
+ struct {
+ char *name;
+ enum status_point_types type;
+ } parameters[] = {
+ {"BaseExp", SP_BASEEXP},
+ {"JobExp", SP_JOBEXP},
+ {"Karma", SP_KARMA},
+ {"Manner", SP_MANNER},
+ {"Hp", SP_HP},
+ {"MaxHp", SP_MAXHP},
+ {"Sp", SP_SP},
+ {"MaxSp", SP_MAXSP},
+ {"StatusPoint", SP_STATUSPOINT},
+ {"BaseLevel", SP_BASELEVEL},
+ {"SkillPoint", SP_SKILLPOINT},
+ {"Class", SP_CLASS},
+ {"Zeny", SP_ZENY},
+ {"Sex", SP_SEX},
+ {"NextBaseExp", SP_NEXTBASEEXP},
+ {"NextJobExp", SP_NEXTJOBEXP},
+ {"Weight", SP_WEIGHT},
+ {"MaxWeight", SP_MAXWEIGHT},
+ {"JobLevel", SP_JOBLEVEL},
+ {"Upper", SP_UPPER},
+ {"BaseJob", SP_BASEJOB},
+ {"BaseClass", SP_BASECLASS},
+ {"killerrid", SP_KILLERRID},
+ {"killedrid", SP_KILLEDRID},
+ {"SlotChange", SP_SLOTCHANGE},
+ {"CharRename", SP_CHARRENAME},
+ {"ModExp", SP_MOD_EXP},
+ {"ModDrop", SP_MOD_DROP},
+ {"ModDeath", SP_MOD_DEATH},
+ };
+
+ script->constdb_comment("Parameters");
+ for (i=0; i < ARRAYLENGTH(parameters); ++i)
+ script->set_constant(parameters[i].name, parameters[i].type, true, false);
+ script->constdb_comment(NULL);
+}
// Standard UNIX tab size is 8
#define TAB_SIZE 8
#define update_tabstop(tabstop,chars) \
@@ -3553,7 +3660,7 @@ void script_free_state(struct script_state* st) {
struct map_session_data *sd = st->rid ? map->id2sd(st->rid) : NULL;
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);
+ ShowDebug("script_free_state: Previous script state lost (rid=%d, oid=%d, state=%u, bk_npcid=%d).\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
}
if(sd && sd->st == st) { //Current script is aborted.
@@ -3699,7 +3806,6 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
case C_GE: a = (strcmp(s1,s2) >= 0); break;
case C_LT: a = (strcmp(s1,s2) < 0); break;
case C_LE: a = (strcmp(s1,s2) <= 0); break;
-#ifdef PCRE_SUPPORT
case C_RE_EQ:
case C_RE_NE:
{
@@ -3764,7 +3870,6 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
libpcre->free(extra_regex);
}
break;
-#endif // PCRE_SUPPORT
case C_ADD:
{
char* buf = (char *)aMalloc((strlen(s1)+strlen(s2)+1)*sizeof(char));
@@ -3789,7 +3894,7 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
void op_2num(struct script_state* st, int op, int i1, int i2)
{
int ret;
- double ret_double;
+ int64 ret64;
switch( op ) {
case C_AND: ret = i1 & i2; break;
@@ -3821,25 +3926,21 @@ void op_2num(struct script_state* st, int op, int i1, int i2)
ret = i1 % i2;
break;
default:
- switch( op )
- {// operators that can overflow/underflow
- case C_ADD: ret = i1 + i2; ret_double = (double)i1 + (double)i2; break;
- case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
- case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
+ switch (op) { // operators that can overflow/underflow
+ case C_ADD: ret = i1 + i2; ret64 = (int64)i1 + i2; break;
+ case C_SUB: ret = i1 - i2; ret64 = (int64)i1 - i2; break;
+ case C_MUL: ret = i1 * i2; ret64 = (int64)i1 * i2; break;
default:
ShowError("script:op_2num: unexpected number operator %s i1=%d i2=%d\n", script->op2name(op), i1, i2);
script->reportsrc(st);
script_pushnil(st);
return;
}
- if( ret_double < (double)INT_MIN )
- {
+ if (ret64 < INT_MIN) {
ShowWarning("script:op_2num: underflow detected op=%s i1=%d i2=%d\n", script->op2name(op), i1, i2);
script->reportsrc(st);
ret = INT_MIN;
- }
- else if( ret_double > (double)INT_MAX )
- {
+ } else if (ret64 > INT_MAX) {
ShowWarning("script:op_2num: overflow detected op=%s i1=%d i2=%d\n", script->op2name(op), i1, i2);
script->reportsrc(st);
ret = INT_MAX;
@@ -4206,7 +4307,7 @@ void script_detach_state(struct script_state* st, bool dequeue_event) {
npc->event_dequeue(sd);
}
} 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);
+ ShowError("script_detach_state: Found previous script state without attached player (rid=%d, oid=%d, state=%u, bk_npcid=%d)\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
script->reportsrc(st->bk_st);
script->free_state(st->bk_st);
@@ -4226,7 +4327,7 @@ void script_attach_state(struct script_state* st) {
{
if(st->bk_st)
{// there is already a backup
- 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);
+ ShowDebug("script_free_state: Previous script state lost (rid=%d, oid=%d, state=%u, bk_npcid=%d).\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
}
st->bk_st = sd->st;
st->bk_npcid = sd->npc_id;
@@ -4361,10 +4462,8 @@ void run_script_main(struct script_state *st) {
case C_LOR:
case C_R_SHIFT:
case C_L_SHIFT:
-#ifdef PCRE_SUPPORT
case C_RE_EQ:
case C_RE_NE:
-#endif // PCRE_SUPPORT
script->op_2(st, c);
break;
@@ -4377,7 +4476,7 @@ void run_script_main(struct script_state *st) {
break;
default:
- ShowError("unknown command : %d @ %d\n",c,st->pos);
+ ShowError("unknown command : %u @ %d\n", c, st->pos);
st->state=END;
break;
}
@@ -4750,9 +4849,9 @@ uint8 script_add_language(const char *name) {
* Goes thru db/translations.conf file
**/
void script_load_translations(void) {
- config_t translations_conf;
+ struct config_t translations_conf;
const char *config_filename = "db/translations.conf"; // FIXME hardcoded name
- config_setting_t *translations = NULL;
+ struct config_setting_t *translations = NULL;
int i, size;
uint32 total = 0;
uint8 lang_id = 0, k;
@@ -4772,12 +4871,10 @@ void script_load_translations(void) {
script->add_language("English");/* 0 is default, which is whatever is in the npc files hardcoded (in our case, English) */
- if (libconfig->read_file(&translations_conf, config_filename)) {
- ShowError("load_translations: can't read '%s'\n", config_filename);
+ if (!libconfig->load_file(&translations_conf, config_filename))
return;
- }
- if( !(translations = libconfig->lookup(&translations_conf, "translations")) ) {
+ if ((translations = libconfig->lookup(&translations_conf, "translations")) == NULL) {
ShowError("load_translations: invalid format on '%s'\n",config_filename);
return;
}
@@ -4951,7 +5048,7 @@ void script_load_translation(const char *file, uint8 lang_id, uint32 *total) {
RECREATE(st->buf, char, st->len + inner_len);
WBUFB(st->buf, st->len) = lang_id;
- safestrncpy((char*)WBUFP(st->buf, st->len + 1), msgstr.ptr, msgstr_len + 1);
+ safestrncpy(WBUFP(st->buf, st->len + 1), msgstr.ptr, msgstr_len + 1);
st->translations++;
st->len += inner_len;
@@ -5089,6 +5186,7 @@ void do_init_script(bool minimal) {
script->parse_builtin();
script->read_constdb();
+ script->load_parameters();
script->hardcoded_constants();
if (minimal)
@@ -6599,7 +6697,7 @@ BUILDIN(getarraysize)
return true;
}
int script_array_index_cmp(const void *a, const void *b) {
- return ( *(unsigned int*)a - *(unsigned int*)b );
+ return ( *(const unsigned int*)a - *(const unsigned int*)b );
}
/// Deletes count or all the elements in an array, from the starting index.
@@ -6950,7 +7048,7 @@ BUILDIN(checkweight)
// item id
id = itemdb->exists(script_getnum(st, i));
} else {
- ShowError("buildin_checkweight: invalid type for argument '%d'.\n", i);
+ ShowError("buildin_checkweight: invalid type for argument '%u'.\n", i);
script_pushint(st,0);
return false;
}
@@ -7253,7 +7351,7 @@ BUILDIN(getitem2)
int get_count, i;
memset(&item_tmp,0,sizeof(item_tmp));
if (item_data == NULL)
- return -1;
+ return false;
if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR) {
ref = cap_value(ref, 0, MAX_REFINE);
}
@@ -9648,20 +9746,18 @@ BUILDIN(makepet)
BUILDIN(getexp)
{
int base=0,job=0;
- double bonus;
struct map_session_data *sd = script->rid2sd(st);
if (sd == NULL)
return true;
- base=script_getnum(st,2);
- job =script_getnum(st,3);
- if(base<0 || job<0)
+ base = script_getnum(st,2);
+ job = script_getnum(st,3);
+ if (base < 0 || job < 0)
return true;
// bonus for npc-given exp
- bonus = battle_config.quest_exp_rate / 100.;
- base = (int) cap_value(base * bonus, 0, INT_MAX);
- job = (int) cap_value(job * bonus, 0, INT_MAX);
+ base = cap_value(apply_percentrate(base, battle_config.quest_exp_rate, 100), 0, INT_MAX);
+ job = cap_value(apply_percentrate(job, battle_config.quest_exp_rate, 100), 0, INT_MAX);
pc->gainexp(sd, &sd->bl, base, job, true);
@@ -9743,7 +9839,7 @@ BUILDIN(monster)
size = script_getnum(st, 9);
if (size > 3)
{
- ShowWarning("buildin_monster: Attempted to spawn non-existing size %d for monster class %d\n", size, class_);
+ ShowWarning("buildin_monster: Attempted to spawn non-existing size %u for monster class %d\n", size, class_);
return false;
}
}
@@ -9752,7 +9848,7 @@ BUILDIN(monster)
{
ai = script_getnum(st, 10);
if (ai > AI_FLORA) {
- ShowWarning("buildin_monster: Attempted to spawn non-existing ai %d for monster class %d\n", ai, class_);
+ ShowWarning("buildin_monster: Attempted to spawn non-existing ai %u for monster class %d\n", ai, class_);
return false;
}
}
@@ -9848,7 +9944,7 @@ BUILDIN(areamonster) {
if (script_hasdata(st, 11)) {
size = script_getnum(st, 11);
if (size > 3) {
- ShowWarning("buildin_monster: Attempted to spawn non-existing size %d for monster class %d\n", size, class_);
+ ShowWarning("buildin_monster: Attempted to spawn non-existing size %u for monster class %d\n", size, class_);
return false;
}
}
@@ -9856,7 +9952,7 @@ BUILDIN(areamonster) {
if (script_hasdata(st, 12)) {
ai = script_getnum(st, 12);
if (ai > AI_FLORA) {
- ShowWarning("buildin_monster: Attempted to spawn non-existing ai %d for monster class %d\n", ai, class_);
+ ShowWarning("buildin_monster: Attempted to spawn non-existing ai %u for monster class %d\n", ai, class_);
return false;
}
}
@@ -10001,7 +10097,8 @@ BUILDIN(killmonsterall) {
*------------------------------------------*/
BUILDIN(clone) {
struct map_session_data *sd, *msd = NULL;
- int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
+ int char_id, master_id = 0, x, y, flag = 0, m;
+ uint32 mode = 0;
unsigned int duration = 0;
const char *mapname, *event;
@@ -10014,8 +10111,8 @@ BUILDIN(clone) {
if( script_hasdata(st,7) )
master_id=script_getnum(st,7);
- if( script_hasdata(st,8) )
- mode=script_getnum(st,8);
+ if (script_hasdata(st,8))
+ mode = script_getnum(st,8);
if( script_hasdata(st,9) )
flag=script_getnum(st,9);
@@ -10957,7 +11054,7 @@ BUILDIN(getstatus)
case 4: script_pushint(st, sd->sc.data[id]->val4); break;
case 5:
{
- struct TimerData* td = (struct TimerData*)timer->get(sd->sc.data[id]->timer);
+ const struct TimerData* td = (const struct TimerData*)timer->get(sd->sc.data[id]->timer);
if( td ) {
// return the amount of time remaining
@@ -11684,7 +11781,7 @@ BUILDIN(getmapflag)
case MF_RESET: script_pushint(st,map->list[m].flag.reset); break;
case MF_NOTOMB: script_pushint(st,map->list[m].flag.notomb); break;
case MF_NOCASHSHOP: script_pushint(st,map->list[m].flag.nocashshop); break;
- case MF_NOVIEWID: script_pushint(st,map->list[m].flag.noviewid); break;
+ case MF_NOVIEWID: script_pushint(st,map->list[m].flag.noviewid); break;
}
}
@@ -11808,7 +11905,7 @@ BUILDIN(setmapflag) {
case MF_RESET: map->list[m].flag.reset = 1; break;
case MF_NOTOMB: map->list[m].flag.notomb = 1; break;
case MF_NOCASHSHOP: map->list[m].flag.nocashshop = 1; break;
- case MF_NOVIEWID: map->list[m].flag.noviewid = (val <= 0) ? 0 : val; break;
+ case MF_NOVIEWID: map->list[m].flag.noviewid = (val <= 0) ? EQP_NONE : val; break;
}
}
@@ -11895,7 +11992,7 @@ BUILDIN(removemapflag) {
case MF_RESET: map->list[m].flag.reset = 0; break;
case MF_NOTOMB: map->list[m].flag.notomb = 0; break;
case MF_NOCASHSHOP: map->list[m].flag.nocashshop = 0; break;
- case MF_NOVIEWID: map->list[m].flag.noviewid = 0; break;
+ case MF_NOVIEWID: map->list[m].flag.noviewid = EQP_NONE; break;
}
}
@@ -12055,7 +12152,7 @@ BUILDIN(emotion) {
clif->emotion(&sd->bl,type);
} else if( script_hasdata(st,4) ) {
struct npc_data *nd = npc->name2id(script_getstr(st,4));
- if (nd == NULL)
+ if (nd != NULL)
clif->emotion(&nd->bl,type);
} else {
clif->emotion(map->id2bl(st->oid),type);
@@ -12169,7 +12266,7 @@ BUILDIN(flagemblem)
if( nd == NULL ) {
ShowError("script:flagemblem: npc %d not found\n", st->oid);
} else if( nd->subtype != SCRIPT ) {
- ShowError("script:flagemblem: unexpected subtype %d for npc %d '%s'\n", nd->subtype, st->oid, nd->exname);
+ ShowError("script:flagemblem: unexpected subtype %u for npc %d '%s'\n", nd->subtype, st->oid, nd->exname);
} else {
bool changed = ( nd->u.scr.guild_id != g_id )?true:false;
nd->u.scr.guild_id = g_id;
@@ -13534,25 +13631,27 @@ BUILDIN(npcskilleffect) {
* Special effects [Valaris]
*------------------------------------------*/
BUILDIN(specialeffect) {
- struct block_list *bl=map->id2bl(st->oid);
+ struct block_list *bl = NULL;
int type = script_getnum(st,2);
enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA;
- if(bl==NULL)
- return true;
-
if (script_hasdata(st,4)) {
struct npc_data *nd = npc->name2id(script_getstr(st,4));
if (nd != NULL)
- clif->specialeffect(&nd->bl, type, target);
+ bl = &nd->bl;
} else {
- if (target == SELF) {
- struct map_session_data *sd = script->rid2sd(st);
- if (sd != NULL)
- clif->specialeffect_single(bl,type,sd->fd);
- } else {
- clif->specialeffect(bl, type, target);
- }
+ bl = map->id2bl(st->oid);
+ }
+
+ if (bl == NULL)
+ return true;
+
+ if (target == SELF) {
+ struct map_session_data *sd = script->rid2sd(st);
+ if (sd != NULL)
+ clif->specialeffect_single(bl, type, sd->fd);
+ } else {
+ clif->specialeffect(bl, type, target);
}
return true;
@@ -13862,7 +13961,7 @@ BUILDIN(movenpc)
y = script_getnum(st,4);
if ((nd = npc->name2id(npc_name)) == NULL)
- return -1;
+ return false;
if (script_hasdata(st,5))
nd->dir = script_getnum(st,5) % 8;
@@ -15886,7 +15985,7 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle)
}
}
if( i == max_rows && max_rows < SQL->NumRows(handle) ) {
- ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)SQL->NumRows(handle));
+ ShowWarning("script:query_sql: Only %u/%u rows have been stored.\n", max_rows, (unsigned int)SQL->NumRows(handle));
script->reportsrc(st);
}
@@ -16294,7 +16393,7 @@ BUILDIN(getmonsterinfo)
script_pushconststr(st,"null");
else
script_pushint(st,-1);
- return -1;
+ return false;
}
monster = mob->db(mob_id);
switch ( script_getnum(st,3) ) {
@@ -16676,7 +16775,7 @@ BUILDIN(unitattack) {
BL_UCAST(BL_PET, unit_bl)->target_id = target_bl->id;
break;
default:
- ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type);
+ ShowError("script:unitattack: unsupported source unit type %u\n", unit_bl->type);
script_pushint(st, 0);
return false;
}
@@ -16720,7 +16819,7 @@ BUILDIN(unittalk) {
if( bl != NULL ) {
struct StringBuf sbuf;
StrBuf->Init(&sbuf);
- StrBuf->Printf(&sbuf, "%s : %s", status->get_name(bl), message);
+ StrBuf->Printf(&sbuf, "%s : %s", clif->get_bl_name(bl), message);
clif->disp_overhead(bl, StrBuf->Value(&sbuf));
StrBuf->Destroy(&sbuf);
}
@@ -17034,7 +17133,7 @@ BUILDIN(checkcell) {
cell_chk type = (cell_chk)script_getnum(st,5);
if ( m == -1 ) {
- ShowWarning("checkcell: Attempted to run on unexsitent map '%s', type %d, x/y %d,%d\n",script_getstr(st,2),type,x,y);
+ ShowWarning("checkcell: Attempted to run on unexsitent map '%s', type %u, x/y %d,%d\n", script_getstr(st,2), type, x, y);
return true;
}
@@ -17060,7 +17159,7 @@ BUILDIN(setcell) {
int x,y;
if ( m == -1 ) {
- ShowWarning("setcell: Attempted to run on unexistent map '%s', type %d, x1/y1 - %d,%d | x2/y2 - %d,%d\n",script_getstr(st, 2),type,x1,y1,x2,y2);
+ ShowWarning("setcell: Attempted to run on unexistent map '%s', type %u, x1/y1 - %d,%d | x2/y2 - %d,%d\n", script_getstr(st, 2), type, x1, y1, x2, y2);
return true;
}
@@ -18450,7 +18549,7 @@ BUILDIN(setcashmount)
if (sd->sc.data[SC_ALL_RIDING])
status_change_end(&sd->bl, SC_ALL_RIDING, INVALID_TIMER);
else
- sc_start(NULL,&sd->bl, SC_ALL_RIDING, 100, 0, -1);
+ sc_start(NULL, &sd->bl, SC_ALL_RIDING, 100, 25, INFINITE_DURATION);
script_pushint(st,1);//in both cases, return 1.
}
return true;
@@ -19590,7 +19689,7 @@ BUILDIN(countbound)
}
script_pushint(st,j);
- return 0;
+ return true;
}
/*==========================================
@@ -19646,7 +19745,7 @@ BUILDIN(checkbound)
/* returns 0 when successful, 1 otherwise */
BUILDIN(bg_match_over) {
bool canceled = script_hasdata(st,3) ? true : false;
- struct bg_arena *arena = bg->name2arena((char*)script_getstr(st, 2));
+ struct bg_arena *arena = bg->name2arena((const char*)script_getstr(st, 2));
if( arena ) {
bg->match_over(arena,canceled);
@@ -20067,7 +20166,6 @@ BUILDIN(_) {
}
// declarations that were supposed to be exported from npc_chat.c
-#ifdef PCRE_SUPPORT
BUILDIN(defpattern);
BUILDIN(activatepset);
BUILDIN(deactivatepset);
@@ -20080,7 +20178,6 @@ BUILDIN(pcre_match) {
script->op_2str(st, C_RE_EQ, input, regex);
return true;
}
-#endif
/**
* Adds a built-in script function.
@@ -20497,13 +20594,11 @@ void script_parse_builtin(void) {
BUILDIN_DEF(getrefine,""), // returns the refined number of the current item, or an item with index specified [celest]
BUILDIN_DEF(night,""), // sets the server to night time
BUILDIN_DEF(day,""), // sets the server to day time
-#ifdef PCRE_SUPPORT
BUILDIN_DEF(defpattern,"iss"), // Define pattern to listen for [MouseJstr]
BUILDIN_DEF(activatepset,"i"), // Activate a pattern set [MouseJstr]
BUILDIN_DEF(deactivatepset,"i"), // Deactive a pattern set [MouseJstr]
BUILDIN_DEF(deletepset,"i"), // Delete a pattern set [MouseJstr]
BUILDIN_DEF(pcre_match,"ss"),
-#endif
BUILDIN_DEF(dispbottom,"s?"), //added from jA [Lupus]
BUILDIN_DEF(getusersname,""),
BUILDIN_DEF(recovery,""),
@@ -20778,119 +20873,164 @@ void script_label_add(int key, int pos) {
/**
* Sets source-end constants for scripts to play with
**/
-void script_hardcoded_constants(void) {
- /* server defines */
- script->set_constant("PACKETVER",PACKETVER,false);
- script->set_constant("MAX_LEVEL",MAX_LEVEL,false);
- script->set_constant("MAX_STORAGE",MAX_STORAGE,false);
- script->set_constant("MAX_GUILD_STORAGE",MAX_GUILD_STORAGE,false);
- script->set_constant("MAX_CART",MAX_INVENTORY,false);
- script->set_constant("MAX_INVENTORY",MAX_INVENTORY,false);
- script->set_constant("MAX_ZENY",MAX_ZENY,false);
- script->set_constant("MAX_BG_MEMBERS",MAX_BG_MEMBERS,false);
- script->set_constant("MAX_CHAT_USERS",MAX_CHAT_USERS,false);
- script->set_constant("MAX_REFINE",MAX_REFINE,false);
-
- /* status options */
- script->set_constant("Option_Nothing",OPTION_NOTHING,false);
- script->set_constant("Option_Sight",OPTION_SIGHT,false);
- script->set_constant("Option_Hide",OPTION_HIDE,false);
- script->set_constant("Option_Cloak",OPTION_CLOAK,false);
- script->set_constant("Option_Falcon",OPTION_FALCON,false);
- script->set_constant("Option_Riding",OPTION_RIDING,false);
- script->set_constant("Option_Invisible",OPTION_INVISIBLE,false);
- script->set_constant("Option_Orcish",OPTION_ORCISH,false);
- script->set_constant("Option_Wedding",OPTION_WEDDING,false);
- script->set_constant("Option_Chasewalk",OPTION_CHASEWALK,false);
- script->set_constant("Option_Flying",OPTION_FLYING,false);
- script->set_constant("Option_Xmas",OPTION_XMAS,false);
- script->set_constant("Option_Transform",OPTION_TRANSFORM,false);
- script->set_constant("Option_Summer",OPTION_SUMMER,false);
- script->set_constant("Option_Dragon1",OPTION_DRAGON1,false);
- script->set_constant("Option_Wug",OPTION_WUG,false);
- script->set_constant("Option_Wugrider",OPTION_WUGRIDER,false);
- script->set_constant("Option_Madogear",OPTION_MADOGEAR,false);
- script->set_constant("Option_Dragon2",OPTION_DRAGON2,false);
- script->set_constant("Option_Dragon3",OPTION_DRAGON3,false);
- script->set_constant("Option_Dragon4",OPTION_DRAGON4,false);
- script->set_constant("Option_Dragon5",OPTION_DRAGON5,false);
- script->set_constant("Option_Hanbok",OPTION_HANBOK,false);
- script->set_constant("Option_Oktoberfest",OPTION_OKTOBERFEST,false);
-
- /* status option compounds */
- script->set_constant("Option_Dragon",OPTION_DRAGON,false);
- script->set_constant("Option_Costume",OPTION_COSTUME,false);
-
- /* send_target */
- script->set_constant("ALL_CLIENT",ALL_CLIENT,false);
- script->set_constant("ALL_SAMEMAP",ALL_SAMEMAP,false);
- script->set_constant("AREA",AREA,false);
- script->set_constant("AREA_WOS",AREA_WOS,false);
- script->set_constant("AREA_WOC",AREA_WOC,false);
- script->set_constant("AREA_WOSC",AREA_WOSC,false);
- script->set_constant("AREA_CHAT_WOC",AREA_CHAT_WOC,false);
- script->set_constant("CHAT",CHAT,false);
- script->set_constant("CHAT_WOS",CHAT_WOS,false);
- script->set_constant("PARTY",PARTY,false);
- script->set_constant("PARTY_WOS",PARTY_WOS,false);
- script->set_constant("PARTY_SAMEMAP",PARTY_SAMEMAP,false);
- script->set_constant("PARTY_SAMEMAP_WOS",PARTY_SAMEMAP_WOS,false);
- script->set_constant("PARTY_AREA",PARTY_AREA,false);
- script->set_constant("PARTY_AREA_WOS",PARTY_AREA_WOS,false);
- script->set_constant("GUILD",GUILD,false);
- script->set_constant("GUILD_WOS",GUILD_WOS,false);
- script->set_constant("GUILD_SAMEMAP",GUILD_SAMEMAP,false);
- script->set_constant("GUILD_SAMEMAP_WOS",GUILD_SAMEMAP_WOS,false);
- script->set_constant("GUILD_AREA",GUILD_AREA,false);
- script->set_constant("GUILD_AREA_WOS",GUILD_AREA_WOS,false);
- script->set_constant("GUILD_NOBG",GUILD_NOBG,false);
- script->set_constant("DUEL",DUEL,false);
- script->set_constant("DUEL_WOS",DUEL_WOS,false);
- script->set_constant("SELF",SELF,false);
- script->set_constant("BG",BG,false);
- script->set_constant("BG_WOS",BG_WOS,false);
- script->set_constant("BG_SAMEMAP",BG_SAMEMAP,false);
- script->set_constant("BG_SAMEMAP_WOS",BG_SAMEMAP_WOS,false);
- script->set_constant("BG_AREA",BG_AREA,false);
- script->set_constant("BG_AREA_WOS",BG_AREA_WOS,false);
- script->set_constant("BG_QUEUE",BG_QUEUE,false);
-
- /* Renewal */
+void script_hardcoded_constants(void)
+{
+ script->constdb_comment("Boolean");
+ script->set_constant("true", 1, false, false);
+ script->set_constant("false", 0, false, false);
+
+ script->constdb_comment("Server defines");
+ script->set_constant("PACKETVER",PACKETVER,false, false);
+ script->set_constant("MAX_LEVEL",MAX_LEVEL,false, false);
+ script->set_constant("MAX_STORAGE",MAX_STORAGE,false, false);
+ script->set_constant("MAX_GUILD_STORAGE",MAX_GUILD_STORAGE,false, false);
+ script->set_constant("MAX_CART",MAX_INVENTORY,false, false);
+ script->set_constant("MAX_INVENTORY",MAX_INVENTORY,false, false);
+ script->set_constant("MAX_ZENY",MAX_ZENY,false, false);
+ script->set_constant("MAX_BG_MEMBERS",MAX_BG_MEMBERS,false, false);
+ script->set_constant("MAX_CHAT_USERS",MAX_CHAT_USERS,false, false);
+ script->set_constant("MAX_REFINE",MAX_REFINE,false, false);
+
+ script->constdb_comment("status options");
+ script->set_constant("Option_Nothing",OPTION_NOTHING,false, false);
+ script->set_constant("Option_Sight",OPTION_SIGHT,false, false);
+ script->set_constant("Option_Hide",OPTION_HIDE,false, false);
+ script->set_constant("Option_Cloak",OPTION_CLOAK,false, false);
+ script->set_constant("Option_Falcon",OPTION_FALCON,false, false);
+ script->set_constant("Option_Riding",OPTION_RIDING,false, false);
+ script->set_constant("Option_Invisible",OPTION_INVISIBLE,false, false);
+ script->set_constant("Option_Orcish",OPTION_ORCISH,false, false);
+ script->set_constant("Option_Wedding",OPTION_WEDDING,false, false);
+ script->set_constant("Option_Chasewalk",OPTION_CHASEWALK,false, false);
+ script->set_constant("Option_Flying",OPTION_FLYING,false, false);
+ script->set_constant("Option_Xmas",OPTION_XMAS,false, false);
+ script->set_constant("Option_Transform",OPTION_TRANSFORM,false, false);
+ script->set_constant("Option_Summer",OPTION_SUMMER,false, false);
+ script->set_constant("Option_Dragon1",OPTION_DRAGON1,false, false);
+ script->set_constant("Option_Wug",OPTION_WUG,false, false);
+ script->set_constant("Option_Wugrider",OPTION_WUGRIDER,false, false);
+ script->set_constant("Option_Madogear",OPTION_MADOGEAR,false, false);
+ script->set_constant("Option_Dragon2",OPTION_DRAGON2,false, false);
+ script->set_constant("Option_Dragon3",OPTION_DRAGON3,false, false);
+ script->set_constant("Option_Dragon4",OPTION_DRAGON4,false, false);
+ script->set_constant("Option_Dragon5",OPTION_DRAGON5,false, false);
+ script->set_constant("Option_Hanbok",OPTION_HANBOK,false, false);
+ script->set_constant("Option_Oktoberfest",OPTION_OKTOBERFEST,false, false);
+
+ script->constdb_comment("status option compounds");
+ script->set_constant("Option_Dragon",OPTION_DRAGON,false, false);
+ script->set_constant("Option_Costume",OPTION_COSTUME,false, false);
+
+ script->constdb_comment("send_target");
+ script->set_constant("ALL_CLIENT",ALL_CLIENT,false, false);
+ script->set_constant("ALL_SAMEMAP",ALL_SAMEMAP,false, false);
+ script->set_constant("AREA",AREA,false, false);
+ script->set_constant("AREA_WOS",AREA_WOS,false, false);
+ script->set_constant("AREA_WOC",AREA_WOC,false, false);
+ script->set_constant("AREA_WOSC",AREA_WOSC,false, false);
+ script->set_constant("AREA_CHAT_WOC",AREA_CHAT_WOC,false, false);
+ script->set_constant("CHAT",CHAT,false, false);
+ script->set_constant("CHAT_WOS",CHAT_WOS,false, false);
+ script->set_constant("PARTY",PARTY,false, false);
+ script->set_constant("PARTY_WOS",PARTY_WOS,false, false);
+ script->set_constant("PARTY_SAMEMAP",PARTY_SAMEMAP,false, false);
+ script->set_constant("PARTY_SAMEMAP_WOS",PARTY_SAMEMAP_WOS,false, false);
+ script->set_constant("PARTY_AREA",PARTY_AREA,false, false);
+ script->set_constant("PARTY_AREA_WOS",PARTY_AREA_WOS,false, false);
+ script->set_constant("GUILD",GUILD,false, false);
+ script->set_constant("GUILD_WOS",GUILD_WOS,false, false);
+ script->set_constant("GUILD_SAMEMAP",GUILD_SAMEMAP,false, false);
+ script->set_constant("GUILD_SAMEMAP_WOS",GUILD_SAMEMAP_WOS,false, false);
+ script->set_constant("GUILD_AREA",GUILD_AREA,false, false);
+ script->set_constant("GUILD_AREA_WOS",GUILD_AREA_WOS,false, false);
+ script->set_constant("GUILD_NOBG",GUILD_NOBG,false, false);
+ script->set_constant("DUEL",DUEL,false, false);
+ script->set_constant("DUEL_WOS",DUEL_WOS,false, false);
+ script->set_constant("SELF",SELF,false, false);
+ script->set_constant("BG",BG,false, false);
+ script->set_constant("BG_WOS",BG_WOS,false, false);
+ script->set_constant("BG_SAMEMAP",BG_SAMEMAP,false, false);
+ script->set_constant("BG_SAMEMAP_WOS",BG_SAMEMAP_WOS,false, false);
+ script->set_constant("BG_AREA",BG_AREA,false, false);
+ script->set_constant("BG_AREA_WOS",BG_AREA_WOS,false, false);
+ script->set_constant("BG_QUEUE",BG_QUEUE,false, false);
+
+ script->constdb_comment("LOOK_ constants, use in setlook/changelook script commands");
+ script->set_constant("LOOK_BASE", LOOK_BASE, false, false);
+ script->set_constant("LOOK_HAIR", LOOK_HAIR, false, false);
+ script->set_constant("LOOK_WEAPON", LOOK_WEAPON, false, false);
+ script->set_constant("LOOK_HEAD_BOTTOM", LOOK_HEAD_BOTTOM, false, false);
+ script->set_constant("LOOK_HEAD_TOP", LOOK_HEAD_TOP, false, false);
+ script->set_constant("LOOK_HEAD_MID", LOOK_HEAD_MID, false, false);
+ script->set_constant("LOOK_HAIR_COLOR", LOOK_HAIR_COLOR, false, false);
+ script->set_constant("LOOK_CLOTHES_COLOR", LOOK_CLOTHES_COLOR, false, false);
+ script->set_constant("LOOK_SHIELD", LOOK_SHIELD, false, false);
+ script->set_constant("LOOK_SHOES", LOOK_SHOES, false, false);
+ script->set_constant("LOOK_BODY", LOOK_BODY, false, false);
+ script->set_constant("LOOK_FLOOR", LOOK_FLOOR, false, false);
+ script->set_constant("LOOK_ROBE", LOOK_ROBE, false, false);
+ script->set_constant("LOOK_BODY2", LOOK_BODY2, false, false);
+
+ script->constdb_comment("Equip Position in Bits, use with *getiteminfo type 5, or @inventorylist_equip");
+ script->set_constant("EQP_HEAD_LOW", EQP_HEAD_LOW, false, false);
+ script->set_constant("EQP_HEAD_MID", EQP_HEAD_MID, false, false);
+ script->set_constant("EQP_HEAD_TOP", EQP_HEAD_TOP, false, false);
+ script->set_constant("EQP_HAND_R", EQP_HAND_R, false, false);
+ script->set_constant("EQP_HAND_L", EQP_HAND_L, false, false);
+ script->set_constant("EQP_ARMOR", EQP_ARMOR, false, false);
+ script->set_constant("EQP_SHOES", EQP_SHOES, false, false);
+ script->set_constant("EQP_GARMENT", EQP_GARMENT, false, false);
+ script->set_constant("EQP_ACC_L", EQP_ACC_L, false, false);
+ script->set_constant("EQP_ACC_R", EQP_ACC_R, false, false);
+ script->set_constant("EQP_COSTUME_HEAD_TOP", EQP_COSTUME_HEAD_TOP, false, false);
+ script->set_constant("EQP_COSTUME_HEAD_MID", EQP_COSTUME_HEAD_MID, false, false);
+ script->set_constant("EQP_COSTUME_HEAD_LOW", EQP_COSTUME_HEAD_LOW, false, false);
+ script->set_constant("EQP_COSTUME_GARMENT", EQP_COSTUME_GARMENT, false, false);
+ script->set_constant("EQP_AMMO", EQP_AMMO, false, false);
+ script->set_constant("EQP_SHADOW_ARMOR", EQP_SHADOW_ARMOR, false, false);
+ script->set_constant("EQP_SHADOW_WEAPON", EQP_SHADOW_WEAPON, false, false);
+ script->set_constant("EQP_SHADOW_SHIELD", EQP_SHADOW_SHIELD, false, false);
+ script->set_constant("EQP_SHADOW_SHOES", EQP_SHADOW_SHOES, false, false);
+ script->set_constant("EQP_SHADOW_ACC_R", EQP_SHADOW_ACC_R, false, false);
+ script->set_constant("EQP_SHADOW_ACC_L", EQP_SHADOW_ACC_L, false, false);
+
+ script->constdb_comment("Renewal");
#ifdef RENEWAL
- script->set_constant("RENEWAL", 1, false);
+ script->set_constant("RENEWAL", 1, false, false);
#else
- script->set_constant("RENEWAL", 0, false);
+ script->set_constant("RENEWAL", 0, false, false);
#endif
#ifdef RENEWAL_CAST
- script->set_constant("RENEWAL_CAST", 1, false);
+ script->set_constant("RENEWAL_CAST", 1, false, false);
#else
- script->set_constant("RENEWAL_CAST", 0, false);
+ script->set_constant("RENEWAL_CAST", 0, false, false);
#endif
#ifdef RENEWAL_DROP
- script->set_constant("RENEWAL_DROP", 1, false);
+ script->set_constant("RENEWAL_DROP", 1, false, false);
#else
- script->set_constant("RENEWAL_DROP", 0, false);
+ script->set_constant("RENEWAL_DROP", 0, false, false);
#endif
#ifdef RENEWAL_EXP
- script->set_constant("RENEWAL_EXP", 1, false);
+ script->set_constant("RENEWAL_EXP", 1, false, false);
#else
- script->set_constant("RENEWAL_EXP", 0, false);
+ script->set_constant("RENEWAL_EXP", 0, false, false);
#endif
#ifdef RENEWAL_LVDMG
- script->set_constant("RENEWAL_LVDMG", 1, false);
+ script->set_constant("RENEWAL_LVDMG", 1, false, false);
#else
- script->set_constant("RENEWAL_LVDMG", 0, false);
+ script->set_constant("RENEWAL_LVDMG", 0, false, false);
#endif
#ifdef RENEWAL_EDP
- script->set_constant("RENEWAL_EDP", 1, false);
+ script->set_constant("RENEWAL_EDP", 1, false, false);
#else
- script->set_constant("RENEWAL_EDP", 0, false);
+ script->set_constant("RENEWAL_EDP", 0, false, false);
#endif
#ifdef RENEWAL_ASPD
- script->set_constant("RENEWAL_ASPD", 1, false);
+ script->set_constant("RENEWAL_ASPD", 1, false, false);
#else
- script->set_constant("RENEWAL_ASPD", 0, false);
+ script->set_constant("RENEWAL_ASPD", 0, false, false);
#endif
+ script->constdb_comment(NULL);
}
/**
@@ -21068,6 +21208,8 @@ void script_defaults(void) {
script->parse_expr = parse_expr;
script->parse_line = parse_line;
script->read_constdb = read_constdb;
+ script->constdb_comment = script_constdb_comment;
+ script->load_parameters = script_load_parameters;
script->print_line = script_print_line;
script->errorwarning_sub = script_errorwarning_sub;
script->set_reg = set_reg;