summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-09-29 09:32:23 -0300
committershennetsind <ind@henn.et>2013-09-29 09:32:23 -0300
commitc7af219aec5c8a5909ebfa1c7bb1fd4b5597f42a (patch)
treef8eb48486518ccf6ec14a87c806d7324203dd6b8 /src/map/script.c
parentfe624087b2495fb258afd9177c6299139a1f914d (diff)
downloadhercules-c7af219aec5c8a5909ebfa1c7bb1fd4b5597f42a.tar.gz
hercules-c7af219aec5c8a5909ebfa1c7bb1fd4b5597f42a.tar.bz2
hercules-c7af219aec5c8a5909ebfa1c7bb1fd4b5597f42a.tar.xz
hercules-c7af219aec5c8a5909ebfa1c7bb1fd4b5597f42a.zip
HPM: Script.c Completed
Fully Interfaced. Moved missing vars and declarations of interest into the interface, removed duplicate mentions of script within calls to shorten wherever it made sense to. Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c2222
1 files changed, 1082 insertions, 1140 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 59af8d2b7..875ecd841 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2,12 +2,6 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-//#define DEBUG_DISP
-//#define DEBUG_DISASM
-//#define DEBUG_RUN
-//#define DEBUG_HASH
-//#define DEBUG_DUMP_STACK
-
#include "../common/cbasetypes.h"
#include "../common/malloc.h"
#include "../common/md5calc.h"
@@ -60,165 +54,18 @@
#include <sys/time.h>
#endif
#include <time.h>
-#include <setjmp.h>
-#include <errno.h>
-
-
-#define FETCH(n, t) \
- if( script_hasdata(st,n) ) \
- (t)=script_getnum(st,n);
-
-/// Maximum amount of elements in script arrays
-#define SCRIPT_MAX_ARRAYSIZE 128
-#define SCRIPT_BLOCK_SIZE 512
-enum { LABEL_NEXTLINE=1,LABEL_START };
-
-/// temporary buffer for passing around compiled bytecode
-/// @see add_scriptb, set_label, parse_script
-static unsigned char* script_buf = NULL;
-static int script_pos = 0, script_size = 0;
-
-static inline int GETVALUE(const unsigned char* buf, int i)
-{
+static inline int GETVALUE(const unsigned char* buf, int i) {
return (int)MakeDWord(MakeWord(buf[i], buf[i+1]), MakeWord(buf[i+2], 0));
}
-static inline void SETVALUE(unsigned char* buf, int i, int n)
-{
+static inline void SETVALUE(unsigned char* buf, int i, int n) {
buf[i] = GetByte(n, 0);
buf[i+1] = GetByte(n, 1);
buf[i+2] = GetByte(n, 2);
}
-// Using a prime number for SCRIPT_HASH_SIZE should give better distributions
-#define SCRIPT_HASH_SIZE 1021
-int str_hash[SCRIPT_HASH_SIZE];
-// Specifies which string hashing method to use
-//#define SCRIPT_HASH_DJB2
-//#define SCRIPT_HASH_SDBM
-#define SCRIPT_HASH_ELF
-
-static int parse_options=0;
-
-// important buildin function references for usage in scripts
-static int buildin_set_ref = 0;
-static int buildin_callsub_ref = 0;
-static int buildin_callfunc_ref = 0;
-static int buildin_getelementofarray_ref = 0;
-
-static jmp_buf error_jump;
-static char* error_msg;
-static const char* error_pos;
-static int error_report; // if the error should produce output
-// Used by disp_warning_message
-static const char* parser_current_src;
-static const char* parser_current_file;
-static int parser_current_line;
-
-// for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
-// [Eoe / jA 1080, 1081, 1094, 1164]
-enum curly_type {
- TYPE_NULL = 0,
- TYPE_IF,
- TYPE_SWITCH,
- TYPE_WHILE,
- TYPE_FOR,
- TYPE_DO,
- TYPE_USERFUNC,
- TYPE_ARGLIST // function argument list
-};
-
-enum e_arglist
-{
- ARGLIST_UNDEFINED = 0,
- ARGLIST_NO_PAREN = 1,
- ARGLIST_PAREN = 2,
-};
-
-static struct {
- struct {
- enum curly_type type;
- int index;
- int count;
- int flag;
- struct linkdb_node *case_label;
- } curly[256]; // Information right parenthesis
- int curly_count; // The number of right brackets
- int index; // Number of the syntax used in the script
-} syntax;
-
-const char* parse_curly_close(const char* p);
-const char* parse_syntax_close(const char* p);
-const char* parse_syntax_close_sub(const char* p,int* flag);
-const char* parse_syntax(const char* p);
-static int parse_syntax_for_flag = 0;
-
-extern int status_current_equip_item_index; //for New CARDS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
-
struct script_interface script_s;
-c_op get_com(unsigned char *scriptbuf,int *pos);
-int get_num(unsigned char *scriptbuf,int *pos);
-
-/*==========================================
- * (Only those needed) local declaration prototype
- *------------------------------------------*/
-
-enum {
- MF_NOMEMO, //0
- MF_NOTELEPORT,
- MF_NOSAVE,
- MF_NOBRANCH,
- MF_NOPENALTY,
- MF_NOZENYPENALTY,
- MF_PVP,
- MF_PVP_NOPARTY,
- MF_PVP_NOGUILD,
- MF_GVG,
- MF_GVG_NOPARTY, //10
- MF_NOTRADE,
- MF_NOSKILL,
- MF_NOWARP,
- MF_PARTYLOCK,
- MF_NOICEWALL,
- MF_SNOW,
- MF_FOG,
- MF_SAKURA,
- MF_LEAVES,
- /* 21 - 22 free */
- MF_CLOUDS = 23,
- MF_CLOUDS2,
- MF_FIREWORKS,
- MF_GVG_CASTLE,
- MF_GVG_DUNGEON,
- MF_NIGHTENABLED,
- MF_NOBASEEXP,
- MF_NOJOBEXP, //30
- MF_NOMOBLOOT,
- MF_NOMVPLOOT,
- MF_NORETURN,
- MF_NOWARPTO,
- MF_NIGHTMAREDROP,
- MF_ZONE,
- MF_NOCOMMAND,
- MF_NODROP,
- MF_JEXP,
- MF_BEXP, //40
- MF_NOVENDING,
- MF_LOADEVENT,
- MF_NOCHAT,
- MF_NOEXPPENALTY,
- MF_GUILDLOCK,
- MF_TOWN,
- MF_AUTOTRADE,
- MF_ALLOWKS,
- MF_MONSTER_NOTELEPORT,
- MF_PVP_NOCALCRANK, //50
- MF_BATTLEGROUND,
- MF_RESET,
- MF_NOTOMB
-};
-
const char* script_op2name(int op)
{
#define RETURN_OP_NAME(type) case type: return #type
@@ -269,7 +116,7 @@ const char* script_op2name(int op)
#undef RETURN_OP_NAME
}
-#ifdef DEBUG_DUMP_STACK
+#ifdef SCRIPT_DEBUG_DUMP_STACK
static void script_dump_stack(struct script_state* st)
{
int i;
@@ -312,7 +159,7 @@ static void script_dump_stack(struct script_state* st)
#endif
/// Reports on the console the src of a script error.
-static void script_reportsrc(struct script_state *st) {
+void script_reportsrc(struct script_state *st) {
struct block_list* bl;
if( st->oid == 0 )
@@ -339,7 +186,7 @@ static void script_reportsrc(struct script_state *st) {
}
/// Reports on the console information about the script data.
-static void script_reportdata(struct script_data* data)
+void script_reportdata(struct script_data* data)
{
if( data == NULL )
return;
@@ -370,22 +217,22 @@ static void script_reportdata(struct script_data* data)
} else if( reference_toparam(data) ) {// param
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!!! - script->str_data.type=%s\n", script_op2name(script->str_data[reference_getid(data)].type));
+ ShowDebug("Data: reference name='%s' type=%s\n", reference_getname(data), script->op2name(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
ShowDebug("Data: label pos=%d\n", data->u.num);
break;
default:
- ShowDebug("Data: %s\n", script_op2name(data->type));
+ ShowDebug("Data: %s\n", script->op2name(data->type));
break;
}
}
/// Reports on the console information about the current built-in function.
-static void script_reportfunc(struct script_state* st)
+void script_reportfunc(struct script_state* st)
{
int i, params, id;
struct script_data* data;
@@ -411,7 +258,7 @@ static void script_reportfunc(struct script_state* st)
for( i = 2; i <= script_lastdata(st); i++ )
{
- script_reportdata(script_getdata(st,i));
+ script->reportdata(script_getdata(st,i));
}
}
else
@@ -424,33 +271,33 @@ static void script_reportfunc(struct script_state* st)
/*==========================================
* Output error message
*------------------------------------------*/
-static void disp_error_message2(const char *mes,const char *pos,int report)
+void disp_error_message2(const char *mes,const char *pos,int report)
{
- error_msg = aStrdup(mes);
- error_pos = pos;
- error_report = report;
- longjmp( error_jump, 1 );
+ script->error_msg = aStrdup(mes);
+ script->error_pos = pos;
+ script->error_report = report;
+ longjmp( script->error_jump, 1 );
}
-#define disp_error_message(mes,pos) disp_error_message2(mes,pos,1)
+#define disp_error_message(mes,pos) script->disp_error_message2(mes,pos,1)
-static void disp_warning_message(const char *mes, const char *pos) {
- script->warning(parser_current_src,parser_current_file,parser_current_line,mes,pos);
+void disp_warning_message(const char *mes, const char *pos) {
+ script->warning(script->parser_current_src,script->parser_current_file,script->parser_current_line,mes,pos);
}
/// Checks event parameter validity
-static void check_event(struct script_state *st, const char *evt)
+void check_event(struct script_state *st, const char *evt)
{
if( evt && evt[0] && !stristr(evt, "::On") )
{
ShowWarning("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n", evt);
- script_reportsrc(st);
+ script->reportsrc(st);
}
}
/*==========================================
* Hashes the input string
*------------------------------------------*/
-static unsigned int calc_hash(const char* p)
+unsigned int calc_hash(const char* p)
{
unsigned int h;
@@ -500,7 +347,7 @@ int script_search_str(const char* p)
{
int i;
- for( i = str_hash[calc_hash(p)]; i != 0; i = script->str_data[i].next )
+ for( i = script->str_hash[script->calc_hash(p)]; i != 0; i = script->str_data[i].next )
if( strcasecmp(script->get_str(i),p) == 0 )
return i;
@@ -514,12 +361,12 @@ int script_add_str(const char* p)
int i, h;
int len;
- h = calc_hash(p);
+ h = script->calc_hash(p);
- if( str_hash[h] == 0 ) {// empty bucket, add new node here
- str_hash[h] = script->str_num;
+ if( script->str_hash[h] == 0 ) {// empty bucket, add new node here
+ script->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 ) {
+ for( i = script->str_hash[h]; ; i = script->str_data[i].next ) {
if( strcasecmp(script->get_str(i),p) == 0 )
return i; // string already in list
if( script->str_data[i].next == 0 )
@@ -561,43 +408,43 @@ int script_add_str(const char* p)
/// Appends 1 byte to the script buffer.
-static void add_scriptb(int a)
+void add_scriptb(int a)
{
- if( script_pos+1 >= script_size )
+ if( script->pos+1 >= script->size )
{
- script_size += SCRIPT_BLOCK_SIZE;
- RECREATE(script_buf,unsigned char,script_size);
+ script->size += SCRIPT_BLOCK_SIZE;
+ RECREATE(script->buf,unsigned char,script->size);
}
- script_buf[script_pos++] = (uint8)(a);
+ script->buf[script->pos++] = (uint8)(a);
}
/// Appends a c_op value to the script buffer.
/// The value is variable-length encoded into 8-bit blocks.
/// The encoding scheme is ( 01?????? )* 00??????, LSB first.
/// All blocks but the last hold 7 bits of data, topmost bit is always 1 (carries).
-static void add_scriptc(int a)
+void add_scriptc(int a)
{
while( a >= 0x40 )
{
- add_scriptb((a&0x3f)|0x40);
+ script->addb((a&0x3f)|0x40);
a = (a - 0x40) >> 6;
}
- add_scriptb(a);
+ script->addb(a);
}
/// Appends an integer value to the script buffer.
/// The value is variable-length encoded into 8-bit blocks.
/// The encoding scheme is ( 11?????? )* 10??????, LSB first.
/// All blocks but the last hold 7 bits of data, topmost bit is always 1 (carries).
-static void add_scripti(int a)
+void add_scripti(int a)
{
while( a >= 0x40 )
{
- add_scriptb((a&0x3f)|0xc0);
+ script->addb((a&0x3f)|0xc0);
a = (a - 0x40) >> 6;
}
- add_scriptb(a|0x80);
+ script->addb(a|0x80);
}
/// Appends a script->str_data object (label/function/variable/integer) to the script buffer.
@@ -605,37 +452,37 @@ static void add_scripti(int a)
///
/// @param l The id of the script->str_data entry
// Maximum up to 16M
-static void add_scriptl(int l)
+void add_scriptl(int l)
{
int backpatch = script->str_data[l].backpatch;
switch(script->str_data[l].type){
case C_POS:
case C_USERFUNC_POS:
- add_scriptc(C_POS);
- add_scriptb(script->str_data[l].label);
- add_scriptb(script->str_data[l].label>>8);
- add_scriptb(script->str_data[l].label>>16);
+ script->addc(C_POS);
+ script->addb(script->str_data[l].label);
+ script->addb(script->str_data[l].label>>8);
+ script->addb(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);
- script->str_data[l].backpatch = script_pos;
- add_scriptb(backpatch);
- add_scriptb(backpatch>>8);
- add_scriptb(backpatch>>16);
+ script->addc(C_NAME);
+ script->str_data[l].backpatch = script->pos;
+ script->addb(backpatch);
+ script->addb(backpatch>>8);
+ script->addb(backpatch>>16);
break;
case C_INT:
- add_scripti(abs(script->str_data[l].val));
+ script->addi(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);
+ script->addc(C_NEG);
break;
default: // assume C_NAME
- add_scriptc(C_NAME);
- add_scriptb(l);
- add_scriptb(l>>8);
- add_scriptb(l>>16);
+ script->addc(C_NAME);
+ script->addb(l);
+ script->addb(l>>8);
+ script->addb(l>>16);
break;
}
}
@@ -659,9 +506,9 @@ void set_label(int l,int pos, const char* script_pos)
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]=(script->str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
- SETVALUE(script_buf,i,pos);
+ next=GETVALUE(script->buf,i);
+ script->buf[i-1]=(script->str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
+ SETVALUE(script->buf,i,pos);
i=next;
}
}
@@ -686,7 +533,7 @@ const char* script_skip_space(const char* p)
for(;;)
{
if( *p == '\0' ) {
- disp_warning_message("script:script->skip_space: end of file while parsing block comment. expected "CL_BOLD"*/"CL_NORM, p);
+ script->disp_warning_message("script:script->skip_space: end of file while parsing block comment. expected "CL_BOLD"*/"CL_NORM, p);
return p;
}
if( *p == '*' && p[1] == '/' )
@@ -706,7 +553,7 @@ const char* script_skip_space(const char* p)
/// Skips a word.
/// A word consists of undercores and/or alphanumeric characters,
/// and valid variable prefixes/postfixes.
-static const char* skip_word(const char* p) {
+const char* skip_word(const char* p) {
// prefix
switch( *p ) {
case '@':// temporary char variable
@@ -733,12 +580,12 @@ static const char* skip_word(const char* p) {
/// Adds a word to script->str_data.
/// @see skip_word
/// @see script->add_str
-static int add_word(const char* p) {
+int add_word(const char* p) {
int len;
int i;
// Check for a word
- len = skip_word(p) - p;
+ len = script->skip_word(p) - p;
if( len == 0 )
disp_error_message("script:add_word: invalid word. A word consists of undercores and/or alphanumeric characters, and valid variable prefixes/postfixes.", p);
@@ -765,20 +612,20 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom)
char *arg = NULL;
int func;
- func = add_word(p);
+ func = script->add_word(p);
if( script->str_data[func].type == C_FUNC ){
char argT = 0;
// buildin function
- add_scriptl(func);
- add_scriptc(C_ARG);
+ script->addl(func);
+ script->addc(C_ARG);
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[script->str_data[buildin_callsub_ref].val];
+ script->addl(script->buildin_callsub_ref);
+ script->addc(C_ARG);
+ script->addl(func);
+ arg = script->buildin[script->str_data[script->buildin_callsub_ref].val];
if( *arg == 0 )
disp_error_message("parse_callfunc: callsub has no arguments, please review its definition",p);
if( *arg != '*' )
@@ -791,45 +638,45 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom)
disp_error_message("parse_line: expect command, missing function name or calling undeclared function",p);
#ifdef SCRIPT_CALLFUNC_CHECK
} else {;
- add_scriptl(buildin_callfunc_ref);
- add_scriptc(C_ARG);
- add_scriptc(C_STR);
- while( *name ) add_scriptb(*name ++);
- add_scriptb(0);
- arg = script->buildin[script->str_data[buildin_callfunc_ref].val];
+ script->addl(script->buildin_callfunc_ref);
+ script->addc(C_ARG);
+ script->addc(C_STR);
+ while( *name ) script->addb(*name ++);
+ script->addb(0);
+ arg = script->buildin[script->str_data[script->buildin_callfunc_ref].val];
if( *arg != '*' ) ++ arg;
}
#endif
}
- p = skip_word(p);
+ p = script->skip_word(p);
p = script->skip_space(p);
- syntax.curly[syntax.curly_count].type = TYPE_ARGLIST;
- syntax.curly[syntax.curly_count].count = 0;
+ script->syntax.curly[script->syntax.curly_count].type = TYPE_ARGLIST;
+ script->syntax.curly[script->syntax.curly_count].count = 0;
if( *p == ';' )
{// <func name> ';'
- syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
+ script->syntax.curly[script->syntax.curly_count].flag = ARGLIST_NO_PAREN;
} else if( *p == '(' && *(p2=script->skip_space(p+1)) == ')' )
{// <func name> '(' ')'
- syntax.curly[syntax.curly_count].flag = ARGLIST_PAREN;
+ script->syntax.curly[script->syntax.curly_count].flag = ARGLIST_PAREN;
p = p2;
/*
} else if( 0 && require_paren && *p != '(' )
{// <func name>
- syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
+ script->syntax.curly[script->syntax.curly_count].flag = ARGLIST_NO_PAREN;
*/
} else {// <func name> <arg list>
if( require_paren ){
if( *p != '(' )
disp_error_message("need '('",p);
++p; // skip '('
- syntax.curly[syntax.curly_count].flag = ARGLIST_PAREN;
+ script->syntax.curly[script->syntax.curly_count].flag = ARGLIST_PAREN;
} else if( *p == '(' ){
- syntax.curly[syntax.curly_count].flag = ARGLIST_UNDEFINED;
+ script->syntax.curly[script->syntax.curly_count].flag = ARGLIST_UNDEFINED;
} else {
- syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
+ script->syntax.curly[script->syntax.curly_count].flag = ARGLIST_NO_PAREN;
}
- ++syntax.curly_count;
+ ++script->syntax.curly_count;
while( *arg ) {
p2=script->parse_subexpr(p,-1);
if( p == p2 )
@@ -842,30 +689,30 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom)
break; // no more arguments
++p; // skip comma
}
- --syntax.curly_count;
+ --script->syntax.curly_count;
}
if( arg && *arg && *arg != '?' && *arg != '*' )
disp_error_message2("parse_callfunc: not enough arguments, expected ','", p, script->config.warn_func_mismatch_paramnum);
- if( syntax.curly[syntax.curly_count].type != TYPE_ARGLIST )
+ if( script->syntax.curly[script->syntax.curly_count].type != TYPE_ARGLIST )
disp_error_message("parse_callfunc: DEBUG last curly is not an argument list",p);
- if( syntax.curly[syntax.curly_count].flag == ARGLIST_PAREN ){
+ if( script->syntax.curly[script->syntax.curly_count].flag == ARGLIST_PAREN ){
if( *p != ')' )
disp_error_message("parse_callfunc: expected ')' to close argument list",p);
++p;
}
- add_scriptc(C_FUNC);
+ script->addc(C_FUNC);
return p;
}
/// Processes end of logical script line.
/// @param first When true, only fix up scheduling data is initialized
/// @param p Script position for error reporting in set_label
-static void parse_nextline(bool first, const char* p)
+void parse_nextline(bool first, const char* p)
{
if( !first )
{
- add_scriptc(C_EOL); // mark end of line for stack cleanup
- set_label(LABEL_NEXTLINE, script_pos, p); // fix up '-' labels
+ script->addc(C_EOL); // mark end of line for stack cleanup
+ script->set_label(LABEL_NEXTLINE, script->pos, p); // fix up '-' labels
}
// initialize data for new '-' label fix up scheduling
@@ -884,7 +731,7 @@ const char* parse_variable(const char* p) {
const char *var = p;
// skip the variable where applicable
- p = skip_word(p);
+ p = script->skip_word(p);
p = script->skip_space(p);
if( p == NULL ) {// end of the line or invalid buffer
@@ -944,19 +791,19 @@ const char* parse_variable(const char* p) {
}
// push the set function onto the stack
- add_scriptl(buildin_set_ref);
- add_scriptc(C_ARG);
+ script->addl(script->buildin_set_ref);
+ script->addc(C_ARG);
// always append parenthesis to avoid errors
- syntax.curly[syntax.curly_count].type = TYPE_ARGLIST;
- syntax.curly[syntax.curly_count].count = 0;
- syntax.curly[syntax.curly_count].flag = ARGLIST_PAREN;
+ script->syntax.curly[script->syntax.curly_count].type = TYPE_ARGLIST;
+ script->syntax.curly[script->syntax.curly_count].count = 0;
+ script->syntax.curly[script->syntax.curly_count].flag = ARGLIST_PAREN;
// increment the total curly count for the position in the script
- ++ syntax.curly_count;
+ ++ script->syntax.curly_count;
// parse the variable currently being modified
- word = add_word(var);
+ word = script->add_word(var);
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
@@ -967,9 +814,9 @@ const char* parse_variable(const char* p) {
const char* p3 = NULL;
// push the getelementofarray method into the stack
- add_scriptl(buildin_getelementofarray_ref);
- add_scriptc(C_ARG);
- add_scriptl(word);
+ script->addl(script->buildin_getelementofarray_ref);
+ script->addc(C_ARG);
+ script->addl(word);
// process the sub-expression for this assignment
p3 = script->parse_subexpr(p2 + 1, 1);
@@ -980,32 +827,32 @@ const char* parse_variable(const char* p) {
}
// push the closing function stack operator onto the stack
- add_scriptc(C_FUNC);
+ script->addc(C_FUNC);
p3 ++;
} else {// simply push the variable or value onto the stack
- add_scriptl(word);
+ script->addl(word);
}
if( type != C_EQ )
- add_scriptc(C_REF);
+ script->addc(C_REF);
if( type == C_ADD_PP || type == C_SUB_PP ) {// incremental operator for the method
- add_scripti(1);
- add_scriptc(type == C_ADD_PP ? C_ADD : C_SUB);
+ script->addi(1);
+ script->addc(type == C_ADD_PP ? C_ADD : C_SUB);
} else {// process the value as an expression
p = script->parse_subexpr(p, -1);
if( type != C_EQ )
{// push the type of modifier onto the stack
- add_scriptc(type);
+ script->addc(type);
}
}
// decrement the curly count for the position within the script
- -- syntax.curly_count;
+ -- script->syntax.curly_count;
// close the script by appending the function operator
- add_scriptc(C_FUNC);
+ script->addc(C_FUNC);
// push the buffer from the method
return p;
@@ -1022,18 +869,18 @@ const char* parse_simpleexpr(const char *p)
if(*p==';' || *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;
+ if( (i=script->syntax.curly_count-1) >= 0 && script->syntax.curly[i].type == TYPE_ARGLIST )
+ ++script->syntax.curly[i].count;
p=script->parse_subexpr(p+1,-1);
p=script->skip_space(p);
- if( (i=syntax.curly_count-1) >= 0 && syntax.curly[i].type == TYPE_ARGLIST &&
- syntax.curly[i].flag == ARGLIST_UNDEFINED && --syntax.curly[i].count == 0
+ if( (i=script->syntax.curly_count-1) >= 0 && script->syntax.curly[i].type == TYPE_ARGLIST &&
+ script->syntax.curly[i].flag == ARGLIST_UNDEFINED && --script->syntax.curly[i].count == 0
){
if( *p == ',' ){
- syntax.curly[i].flag = ARGLIST_PAREN;
+ script->syntax.curly[i].flag = ARGLIST_PAREN;
return p;
} else
- syntax.curly[i].flag = ARGLIST_NO_PAREN;
+ script->syntax.curly[i].flag = ARGLIST_NO_PAREN;
}
if( *p != ')' )
disp_error_message("parse_simpleexpr: unmatched ')'",p);
@@ -1044,15 +891,15 @@ const char* parse_simpleexpr(const char *p)
i=strtoll(p,&np,0);
if( i < INT_MIN ) {
i = INT_MIN;
- disp_warning_message("parse_simpleexpr: underflow detected, capping value to INT_MIN",p);
+ script->disp_warning_message("parse_simpleexpr: underflow detected, capping value to INT_MIN",p);
} else if( i > INT_MAX ) {
i = INT_MAX;
- disp_warning_message("parse_simpleexpr: overflow detected, capping value to INT_MAX",p);
+ script->disp_warning_message("parse_simpleexpr: overflow detected, capping value to INT_MAX",p);
}
- add_scripti((int)i);
+ script->addi((int)i);
p=np;
} else if(*p=='"'){
- add_scriptc(C_STR);
+ script->addc(C_STR);
p++;
while( *p && *p != '"' ){
if( (unsigned char)p[-1] <= 0x7e && *p == '\\' ) {
@@ -1062,56 +909,56 @@ const char* parse_simpleexpr(const char *p)
if( n != 1 )
ShowDebug("parse_simpleexpr: unexpected length %d after unescape (\"%.*s\" -> %.*s)\n", (int)n, (int)len, p, (int)n, buf);
p += len;
- add_scriptb(*buf);
+ script->addb(*buf);
continue;
} else if( *p == '\n' )
disp_error_message("parse_simpleexpr: unexpected newline @ string",p);
- add_scriptb(*p++);
+ script->addb(*p++);
}
if(!*p)
disp_error_message("parse_simpleexpr: unexpected end of file @ string",p);
- add_scriptb(0);
+ script->addb(0);
p++; //'"'
} else {
int l;
const char* pv;
// label , register , function etc
- if(skip_word(p)==p)
+ if(script->skip_word(p)==p)
disp_error_message("parse_simpleexpr: unexpected character",p);
- l=add_word(p);
+ l=script->add_word(p);
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);
+ return script->parse_callfunc(p,1,0);
#ifdef SCRIPT_CALLFUNC_CHECK
else {
const char* name = script->get_str(l);
if( strdb_get(script->userfunc_db,name) != NULL ) {
- return parse_callfunc(p,1,1);
+ return script->parse_callfunc(p,1,1);
}
}
#endif
- if( (pv = parse_variable(p)) )
+ if( (pv = script->parse_variable(p)) )
{// successfully processed a variable assignment
return pv;
}
- p=skip_word(p);
+ p=script->skip_word(p);
if( *p == '[' ){
// array(name[i] => getelementofarray(name,i) )
- add_scriptl(buildin_getelementofarray_ref);
- add_scriptc(C_ARG);
- add_scriptl(l);
+ script->addl(script->buildin_getelementofarray_ref);
+ script->addc(C_ARG);
+ script->addl(l);
p=script->parse_subexpr(p+1,-1);
p=script->skip_space(p);
if( *p != ']' )
disp_error_message("parse_simpleexpr: unmatched ']'",p);
++p;
- add_scriptc(C_FUNC);
+ script->addc(C_FUNC);
}else
- add_scriptl(l);
+ script->addl(l);
}
@@ -1131,7 +978,7 @@ const char* script_parse_subexpr(const char* p,int limit)
if( *p == '-' ){
tmpp = script->skip_space(p+1);
if( *tmpp == ';' || *tmpp == ',' ){
- add_scriptl(LABEL_NEXTLINE);
+ script->addl(LABEL_NEXTLINE);
p++;
return p;
}
@@ -1139,9 +986,9 @@ const char* script_parse_subexpr(const char* p,int limit)
if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
p=script->parse_subexpr(p+1,10);
- add_scriptc(op);
+ script->addc(op);
} else
- p=parse_simpleexpr(p);
+ p=script->parse_simpleexpr(p);
p=script->skip_space(p);
while((
(op=C_OP3,opl=0,len=1,*p=='?') ||
@@ -1173,7 +1020,7 @@ const char* script_parse_subexpr(const char* p,int limit)
} else {
p=script->parse_subexpr(p,opl);
}
- add_scriptc(op);
+ script->addc(op);
p=script->skip_space(p);
}
@@ -1204,40 +1051,40 @@ const char* parse_line(const char* p)
p=script->skip_space(p);
if(*p==';') {
//Close decision for if(); for(); while();
- p = parse_syntax_close(p + 1);
+ p = script->parse_syntax_close(p + 1);
return p;
}
- if(*p==')' && parse_syntax_for_flag)
+ if(*p==')' && script->parse_syntax_for_flag)
return p+1;
p = script->skip_space(p);
if(p[0] == '{') {
- syntax.curly[syntax.curly_count].type = TYPE_NULL;
- syntax.curly[syntax.curly_count].count = -1;
- syntax.curly[syntax.curly_count].index = -1;
- syntax.curly_count++;
+ script->syntax.curly[script->syntax.curly_count].type = TYPE_NULL;
+ script->syntax.curly[script->syntax.curly_count].count = -1;
+ script->syntax.curly[script->syntax.curly_count].index = -1;
+ script->syntax.curly_count++;
return p + 1;
} else if(p[0] == '}') {
- return parse_curly_close(p);
+ return script->parse_curly_close(p);
}
// Syntax-related processing
- p2 = parse_syntax(p);
+ p2 = script->parse_syntax(p);
if(p2 != NULL)
return p2;
// attempt to process a variable assignment
- p2 = parse_variable(p);
+ p2 = script->parse_variable(p);
if( p2 != NULL )
{// variable assignment processed so leave the method
- return parse_syntax_close(p2 + 1);
+ return script->parse_syntax_close(p2 + 1);
}
- p = parse_callfunc(p,0,0);
+ p = script->parse_callfunc(p,0,0);
p = script->skip_space(p);
- if(parse_syntax_for_flag) {
+ if(script->parse_syntax_for_flag) {
if( *p != ')' )
disp_error_message("parse_line: need ')'",p);
} else {
@@ -1246,7 +1093,7 @@ const char* parse_line(const char* p)
}
//Binding decision for if(), for(), while()
- p = parse_syntax_close(p+1);
+ p = script->parse_syntax_close(p+1);
return p;
}
@@ -1254,52 +1101,52 @@ const char* parse_line(const char* p)
// { ... } Closing process
const char* parse_curly_close(const char* p)
{
- if(syntax.curly_count <= 0) {
+ if(script->syntax.curly_count <= 0) {
disp_error_message("parse_curly_close: unexpected string",p);
return p + 1;
- } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
- syntax.curly_count--;
+ } else if(script->syntax.curly[script->syntax.curly_count-1].type == TYPE_NULL) {
+ script->syntax.curly_count--;
//Close decision if, for , while
- p = parse_syntax_close(p + 1);
+ p = script->parse_syntax_close(p + 1);
return p;
- } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
+ } else if(script->syntax.curly[script->syntax.curly_count-1].type == TYPE_SWITCH) {
//Closing switch()
- int pos = syntax.curly_count-1;
+ int pos = script->syntax.curly_count-1;
char label[256];
int l;
// Remove temporary variables
- sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"set $@__SW%x_VAL,0;",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;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __SW%x_FIN;",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",syntax.curly[pos].index,syntax.curly[pos].count);
+ sprintf(label,"__SW%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
l=script->add_str(label);
- set_label(l,script_pos, p);
+ script->set_label(l,script->pos, p);
- if(syntax.curly[pos].flag) {
+ if(script->syntax.curly[pos].flag) {
//Exists default
- sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __SW%x_DEF;",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",syntax.curly[pos].index);
+ sprintf(label,"__SW%x_FIN",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos, p);
- linkdb_final(&syntax.curly[pos].case_label); // free the list of case label
- syntax.curly_count--;
+ script->set_label(l,script->pos, p);
+ linkdb_final(&script->syntax.curly[pos].case_label); // free the list of case label
+ script->syntax.curly_count--;
//Closing decision if, for , while
- p = parse_syntax_close(p + 1);
+ p = script->parse_syntax_close(p + 1);
return p;
} else {
disp_error_message("parse_curly_close: unexpected string",p);
@@ -1312,7 +1159,7 @@ const char* parse_curly_close(const char* p)
// if, switch, while ? will handle this internally.
const char* parse_syntax(const char* p)
{
- const char *p2 = skip_word(p);
+ const char *p2 = script->skip_word(p);
switch(*p) {
case 'B':
@@ -1320,19 +1167,19 @@ const char* parse_syntax(const char* p)
if(p2 - p == 5 && !strncasecmp(p,"break",5)) {
// break Processing
char label[256];
- int pos = syntax.curly_count - 1;
+ int pos = script->syntax.curly_count - 1;
while(pos >= 0) {
- if(syntax.curly[pos].type == TYPE_DO) {
- sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
+ if(script->syntax.curly[pos].type == TYPE_DO) {
+ sprintf(label,"goto __DO%x_FIN;",script->syntax.curly[pos].index);
break;
- } else if(syntax.curly[pos].type == TYPE_FOR) {
- sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
+ } else if(script->syntax.curly[pos].type == TYPE_FOR) {
+ sprintf(label,"goto __FR%x_FIN;",script->syntax.curly[pos].index);
break;
- } else if(syntax.curly[pos].type == TYPE_WHILE) {
- sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
+ } else if(script->syntax.curly[pos].type == TYPE_WHILE) {
+ sprintf(label,"goto __WL%x_FIN;",script->syntax.curly[pos].index);
break;
- } else if(syntax.curly[pos].type == TYPE_SWITCH) {
- sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
+ } else if(script->syntax.curly[pos].type == TYPE_SWITCH) {
+ sprintf(label,"goto __SW%x_FIN;",script->syntax.curly[pos].index);
break;
}
pos--;
@@ -1340,15 +1187,15 @@ const char* parse_syntax(const char* p)
if(pos < 0) {
disp_error_message("parse_syntax: unexpected 'break'",p);
} else {
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
+ script->parse_line(label);
+ script->syntax.curly_count--;
}
p = script->skip_space(p2);
if(*p != ';')
disp_error_message("parse_syntax: need ';'",p);
// Closing decision if, for , while
- p = parse_syntax_close(p + 1);
+ p = script->parse_syntax_close(p + 1);
return p;
}
break;
@@ -1356,25 +1203,25 @@ const char* parse_syntax(const char* p)
case 'C':
if(p2 - p == 4 && !strncasecmp(p,"case",4)) {
//Processing case
- int pos = syntax.curly_count-1;
- if(pos < 0 || syntax.curly[pos].type != TYPE_SWITCH) {
+ int pos = script->syntax.curly_count-1;
+ if(pos < 0 || script->syntax.curly[pos].type != TYPE_SWITCH) {
disp_error_message("parse_syntax: unexpected 'case' ",p);
return p+1;
} else {
char label[256];
int l,v;
char *np;
- if(syntax.curly[pos].count != 1) {
+ if(script->syntax.curly[pos].count != 1) {
//Jump for FALLTHRU
- sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __SW%x_%xJ;",script->syntax.curly[pos].index,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",syntax.curly[pos].index,syntax.curly[pos].count);
+ sprintf(label,"__SW%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
l=script->add_str(label);
- set_label(l,script_pos, p);
+ script->set_label(l,script->pos, p);
}
//Decision statement switch
p = script->skip_space(p2);
@@ -1384,17 +1231,17 @@ const char* parse_syntax(const char* p)
// check whether case label is integer or not
v = strtol(p,&np,0);
if(np == p) { //Check for constants
- p2 = skip_word(p);
+ p2 = script->skip_word(p);
v = p2-p; // length of word at p2
memcpy(label,p,v);
label[v]='\0';
if( !script->get_constant(label, &v) )
disp_error_message("parse_syntax: 'case' label is not an integer",p);
- p = skip_word(p);
+ p = script->skip_word(p);
} else { //Numeric value
if((*p == '-' || *p == '+') && ISDIGIT(p[1])) // pre-skip because '-' can not skip_word
p++;
- p = skip_word(p);
+ p = script->skip_word(p);
if(np != p)
disp_error_message("parse_syntax: 'case' label is not an integer",np);
}
@@ -1402,45 +1249,45 @@ 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,syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
+ v,script->syntax.curly[pos].index,script->syntax.curly[pos].index,script->syntax.curly[pos].count+1);
+ script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
// Bad I do not parse twice
- p2 = parse_line(label);
- parse_line(p2);
- syntax.curly_count--;
- if(syntax.curly[pos].count != 1) {
+ p2 = script->parse_line(label);
+ script->parse_line(p2);
+ script->syntax.curly_count--;
+ if(script->syntax.curly[pos].count != 1) {
// Label after the completion of FALLTHRU
- sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
+ sprintf(label,"__SW%x_%xJ",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
}
// check duplication of case label [Rayce]
- if(linkdb_search(&syntax.curly[pos].case_label, (void*)__64BPTRSIZE(v)) != NULL)
+ if(linkdb_search(&script->syntax.curly[pos].case_label, (void*)__64BPTRSIZE(v)) != NULL)
disp_error_message("parse_syntax: dup 'case'",p);
- linkdb_insert(&syntax.curly[pos].case_label, (void*)__64BPTRSIZE(v), (void*)1);
+ linkdb_insert(&script->syntax.curly[pos].case_label, (void*)__64BPTRSIZE(v), (void*)1);
- sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
+ sprintf(label,"set $@__SW%x_VAL,0;",script->syntax.curly[pos].index);
+ script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- syntax.curly[pos].count++;
+ script->parse_line(label);
+ script->syntax.curly_count--;
+ script->syntax.curly[pos].count++;
}
return p + 1;
} else if(p2 - p == 8 && !strncasecmp(p,"continue",8)) {
// Processing continue
char label[256];
- int pos = syntax.curly_count - 1;
+ int pos = script->syntax.curly_count - 1;
while(pos >= 0) {
- if(syntax.curly[pos].type == TYPE_DO) {
- sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
- syntax.curly[pos].flag = 1; //Flag put the link for continue
+ if(script->syntax.curly[pos].type == TYPE_DO) {
+ sprintf(label,"goto __DO%x_NXT;",script->syntax.curly[pos].index);
+ script->syntax.curly[pos].flag = 1; //Flag put the link for continue
break;
- } else if(syntax.curly[pos].type == TYPE_FOR) {
- sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
+ } else if(script->syntax.curly[pos].type == TYPE_FOR) {
+ sprintf(label,"goto __FR%x_NXT;",script->syntax.curly[pos].index);
break;
- } else if(syntax.curly[pos].type == TYPE_WHILE) {
- sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
+ } else if(script->syntax.curly[pos].type == TYPE_WHILE) {
+ sprintf(label,"goto __WL%x_NXT;",script->syntax.curly[pos].index);
break;
}
pos--;
@@ -1448,15 +1295,15 @@ const char* parse_syntax(const char* p)
if(pos < 0) {
disp_error_message("parse_syntax: unexpected 'continue'",p);
} else {
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
+ script->parse_line(label);
+ script->syntax.curly_count--;
}
p = script->skip_space(p2);
if(*p != ';')
disp_error_message("parse_syntax: need ';'",p);
//Closing decision if, for , while
- p = parse_syntax_close(p + 1);
+ p = script->parse_syntax_close(p + 1);
return p;
}
break;
@@ -1464,10 +1311,10 @@ const char* parse_syntax(const char* p)
case 'D':
if(p2 - p == 7 && !strncasecmp(p,"default",7)) {
// Switch - default processing
- int pos = syntax.curly_count-1;
- if(pos < 0 || syntax.curly[pos].type != TYPE_SWITCH) {
+ int pos = script->syntax.curly_count-1;
+ if(pos < 0 || script->syntax.curly[pos].type != TYPE_SWITCH) {
disp_error_message("parse_syntax: unexpected 'default'",p);
- } else if(syntax.curly[pos].flag) {
+ } else if(script->syntax.curly[pos].flag) {
disp_error_message("parse_syntax: dup 'default'",p);
} else {
char label[256];
@@ -1477,23 +1324,23 @@ const char* parse_syntax(const char* p)
if(*p != ':') {
disp_error_message("parse_syntax: need ':'",p);
}
- sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
+ sprintf(label,"__SW%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
// Skip to the next link w/o condition
- sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __SW%x_%x;",script->syntax.curly[pos].index,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",syntax.curly[pos].index);
+ sprintf(label,"__SW%x_DEF",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
- syntax.curly[syntax.curly_count - 1].flag = 1;
- syntax.curly[pos].count++;
+ script->syntax.curly[script->syntax.curly_count - 1].flag = 1;
+ script->syntax.curly[pos].count++;
}
return p + 1;
} else if(p2 - p == 2 && !strncasecmp(p,"do",2)) {
@@ -1501,15 +1348,15 @@ const char* parse_syntax(const char* p)
char label[256];
p=script->skip_space(p2);
- syntax.curly[syntax.curly_count].type = TYPE_DO;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
+ script->syntax.curly[script->syntax.curly_count].type = TYPE_DO;
+ 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;
// Label of the (do) form here
- sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
+ sprintf(label,"__DO%x_BGN",script->syntax.curly[script->syntax.curly_count].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count++;
+ script->set_label(l,script->pos,p);
+ script->syntax.curly_count++;
return p;
}
break;
@@ -1518,12 +1365,12 @@ const char* parse_syntax(const char* p)
if(p2 - p == 3 && !strncasecmp(p,"for",3)) {
int l;
char label[256];
- int pos = syntax.curly_count;
- syntax.curly[syntax.curly_count].type = TYPE_FOR;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- syntax.curly_count++;
+ int pos = script->syntax.curly_count;
+ script->syntax.curly[script->syntax.curly_count].type = TYPE_FOR;
+ 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;
+ script->syntax.curly_count++;
p=script->skip_space(p2);
@@ -1532,14 +1379,14 @@ const char* parse_syntax(const char* p)
p++;
// Execute the initialization statement
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- p=parse_line(p);
- syntax.curly_count--;
+ script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
+ p=script->parse_line(p);
+ script->syntax.curly_count--;
// Form the start of label decision
- sprintf(label,"__FR%x_J",syntax.curly[pos].index);
+ sprintf(label,"__FR%x_J",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
p=script->skip_space(p);
if(*p == ';') {
@@ -1547,47 +1394,47 @@ const char* parse_syntax(const char* p)
;
} else {
// Skip to the end point if the condition is false
- sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
- add_scriptl(script->add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
+ sprintf(label,"__FR%x_FIN",script->syntax.curly[pos].index);
+ script->addl(script->add_str("jump_zero"));
+ script->addc(C_ARG);
+ p=script->parse_expr(p);
p=script->skip_space(p);
- add_scriptl(script->add_str(label));
- add_scriptc(C_FUNC);
+ script->addl(script->add_str(label));
+ script->addc(C_FUNC);
}
if(*p != ';')
disp_error_message("parse_syntax: need ';'",p);
p++;
// Skip to the beginning of the loop
- sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __FR%x_BGN;",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",syntax.curly[pos].index);
+ sprintf(label,"__FR%x_NXT",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
// Process the next time you enter the loop
// A ')' last for; flag to be treated as'
- parse_syntax_for_flag = 1;
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- p=parse_line(p);
- syntax.curly_count--;
- parse_syntax_for_flag = 0;
+ script->parse_syntax_for_flag = 1;
+ script->syntax.curly[script->syntax.curly_count++].type = TYPE_NULL;
+ p=script->parse_line(p);
+ script->syntax.curly_count--;
+ script->parse_syntax_for_flag = 0;
// Skip to the determination process conditions
- sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __FR%x_J;",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",syntax.curly[pos].index);
+ sprintf(label,"__FR%x_BGN",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
return p;
}
else if( p2 - p == 8 && strncasecmp(p,"function",8) == 0 )
@@ -1595,7 +1442,7 @@ const char* parse_syntax(const char* p)
const char *func_name;
func_name = script->skip_space(p2);
- p = skip_word(func_name);
+ p = script->skip_word(func_name);
if( p == func_name )
disp_error_message("parse_syntax:function: function name is missing or invalid", p);
p2 = script->skip_space(p);
@@ -1603,7 +1450,7 @@ const char* parse_syntax(const char* p)
{// function <name> ;
// function declaration - just register the name
int l;
- l = add_word(func_name);
+ l = script->add_word(func_name);
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 )
@@ -1612,7 +1459,7 @@ const char* parse_syntax(const char* p)
disp_error_message("parse_syntax:function: function name is invalid", func_name);
// Close condition of if, for, while
- p = parse_syntax_close(p2 + 1);
+ p = script->parse_syntax_close(p2 + 1);
return p;
}
else if(*p2 == '{')
@@ -1620,27 +1467,27 @@ const char* parse_syntax(const char* p)
char label[256];
int l;
- syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- ++syntax.curly_count;
+ script->syntax.curly[script->syntax.curly_count].type = TYPE_USERFUNC;
+ 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;
+ ++script->syntax.curly_count;
// Jump over the function code
- sprintf(label, "goto __FN%x_FIN;", syntax.curly[syntax.curly_count-1].index);
- syntax.curly[syntax.curly_count].type = TYPE_NULL;
- ++syntax.curly_count;
- parse_line(label);
- --syntax.curly_count;
+ sprintf(label, "goto __FN%x_FIN;", 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);
+ --script->syntax.curly_count;
// Set the position of the function (label)
- l=add_word(func_name);
+ l=script->add_word(func_name);
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
{
script->str_data[l].type = C_USERFUNC;
- set_label(l, script_pos, p);
- if( parse_options&SCRIPT_USE_LABEL_DB )
- script->label_add(l,script_pos);
+ script->set_label(l, script->pos, p);
+ if( script->parse_options&SCRIPT_USE_LABEL_DB )
+ script->label_add(l,script->pos);
}
else
disp_error_message("parse_syntax:function: function name is invalid", func_name);
@@ -1659,21 +1506,21 @@ const char* parse_syntax(const char* p)
// If process
char label[256];
p=script->skip_space(p2);
- if(*p != '(') { //Prevent if this {} non-c syntax. from Rayce (jA)
+ if(*p != '(') { //Prevent if this {} non-c script->syntax. from Rayce (jA)
disp_error_message("need '('",p);
}
- syntax.curly[syntax.curly_count].type = TYPE_IF;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
- syntax.curly_count++;
- add_scriptl(script->add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
+ script->syntax.curly[script->syntax.curly_count].type = TYPE_IF;
+ 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);
+ script->syntax.curly_count++;
+ script->addl(script->add_str("jump_zero"));
+ script->addc(C_ARG);
+ p=script->parse_expr(p);
p=script->skip_space(p);
- add_scriptl(script->add_str(label));
- add_scriptc(C_FUNC);
+ script->addl(script->add_str(label));
+ script->addc(C_FUNC);
return p;
}
break;
@@ -1686,21 +1533,21 @@ const char* parse_syntax(const char* p)
if(*p != '(') {
disp_error_message("need '('",p);
}
- syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
- syntax.curly_count++;
- add_scriptl(script->add_str("set"));
- add_scriptc(C_ARG);
- add_scriptl(script->add_str(label));
- p=parse_expr(p);
+ script->syntax.curly[script->syntax.curly_count].type = TYPE_SWITCH;
+ 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);
+ script->syntax.curly_count++;
+ script->addl(script->add_str("set"));
+ script->addc(C_ARG);
+ script->addl(script->add_str(label));
+ p=script->parse_expr(p);
p=script->skip_space(p);
if(*p != '{') {
disp_error_message("parse_syntax: need '{'",p);
}
- add_scriptc(C_FUNC);
+ script->addc(C_FUNC);
return p + 1;
}
break;
@@ -1713,24 +1560,24 @@ const char* parse_syntax(const char* p)
if(*p != '(') {
disp_error_message("need '('",p);
}
- syntax.curly[syntax.curly_count].type = TYPE_WHILE;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
+ script->syntax.curly[script->syntax.curly_count].type = TYPE_WHILE;
+ 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;
// Form the start of label decision
- sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
+ sprintf(label,"__WL%x_NXT",script->syntax.curly[script->syntax.curly_count].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
// Skip to the end point if the condition is false
- sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
- syntax.curly_count++;
- add_scriptl(script->add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
+ sprintf(label,"__WL%x_FIN",script->syntax.curly[script->syntax.curly_count].index);
+ script->syntax.curly_count++;
+ script->addl(script->add_str("jump_zero"));
+ script->addc(C_ARG);
+ p=script->parse_expr(p);
p=script->skip_space(p);
- add_scriptl(script->add_str(label));
- add_scriptc(C_FUNC);
+ script->addl(script->add_str(label));
+ script->addc(C_FUNC);
return p;
}
break;
@@ -1743,7 +1590,7 @@ const char* parse_syntax_close(const char *p) {
int flag;
do {
- p = parse_syntax_close_sub(p,&flag);
+ p = script->parse_syntax_close_sub(p,&flag);
} while(flag);
return p;
}
@@ -1754,88 +1601,88 @@ const char* parse_syntax_close(const char *p) {
const char* parse_syntax_close_sub(const char* p,int* flag)
{
char label[256];
- int pos = syntax.curly_count - 1;
+ int pos = script->syntax.curly_count - 1;
int l;
*flag = 1;
- if(syntax.curly_count <= 0) {
+ if(script->syntax.curly_count <= 0) {
*flag = 0;
return p;
- } else if(syntax.curly[pos].type == TYPE_IF) {
+ } else if(script->syntax.curly[pos].type == TYPE_IF) {
const char *bp = p;
const char *p2;
// if-block and else-block end is a new line
- parse_nextline(false, p);
+ script->parse_nextline(false, p);
// Skip to the last location if
- sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __IF%x_FIN;",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",syntax.curly[pos].index,syntax.curly[pos].count);
+ sprintf(label,"__IF%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
- syntax.curly[pos].count++;
+ script->syntax.curly[pos].count++;
p = script->skip_space(p);
- p2 = skip_word(p);
- if(!syntax.curly[pos].flag && p2 - p == 4 && !strncasecmp(p,"else",4)) {
+ p2 = script->skip_word(p);
+ if(!script->syntax.curly[pos].flag && p2 - p == 4 && !strncasecmp(p,"else",4)) {
// else or else - if
p = script->skip_space(p2);
- p2 = skip_word(p);
+ p2 = script->skip_word(p);
if(p2 - p == 2 && !strncasecmp(p,"if",2)) {
// else - if
p=script->skip_space(p2);
if(*p != '(') {
disp_error_message("need '('",p);
}
- sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- add_scriptl(script->add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
+ sprintf(label,"__IF%x_%x",script->syntax.curly[pos].index,script->syntax.curly[pos].count);
+ script->addl(script->add_str("jump_zero"));
+ script->addc(C_ARG);
+ p=script->parse_expr(p);
p=script->skip_space(p);
- add_scriptl(script->add_str(label));
- add_scriptc(C_FUNC);
+ script->addl(script->add_str(label));
+ script->addc(C_FUNC);
*flag = 0;
return p;
} else {
// else
- if(!syntax.curly[pos].flag) {
- syntax.curly[pos].flag = 1;
+ if(!script->syntax.curly[pos].flag) {
+ script->syntax.curly[pos].flag = 1;
*flag = 0;
return p;
}
}
}
// Close if
- syntax.curly_count--;
+ script->syntax.curly_count--;
// Put the label of the final location
- sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
+ sprintf(label,"__IF%x_FIN",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
- if(syntax.curly[pos].flag == 1) {
+ script->set_label(l,script->pos,p);
+ if(script->syntax.curly[pos].flag == 1) {
// Because the position of the pointer is the same if not else for this
return bp;
}
return p;
- } else if(syntax.curly[pos].type == TYPE_DO) {
+ } else if(script->syntax.curly[pos].type == TYPE_DO) {
int l;
char label[256];
const char *p2;
- if(syntax.curly[pos].flag) {
+ if(script->syntax.curly[pos].flag) {
// (Come here continue) to form the label here
- sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
+ sprintf(label,"__DO%x_NXT",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
}
// Skip to the end point if the condition is false
p = script->skip_space(p);
- p2 = skip_word(p);
+ p2 = script->skip_word(p);
if(p2 - p != 5 || strncasecmp(p,"while",5))
disp_error_message("parse_syntax: need 'while'",p);
@@ -1845,81 +1692,81 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
}
// do-block end is a new line
- parse_nextline(false, p);
+ script->parse_nextline(false, p);
- sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
- add_scriptl(script->add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
+ sprintf(label,"__DO%x_FIN",script->syntax.curly[pos].index);
+ script->addl(script->add_str("jump_zero"));
+ script->addc(C_ARG);
+ p=script->parse_expr(p);
p=script->skip_space(p);
- add_scriptl(script->add_str(label));
- add_scriptc(C_FUNC);
+ script->addl(script->add_str(label));
+ script->addc(C_FUNC);
// Skip to the starting point
- sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __DO%x_BGN;",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",syntax.curly[pos].index);
+ sprintf(label,"__DO%x_FIN",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
+ script->set_label(l,script->pos,p);
p = script->skip_space(p);
if(*p != ';') {
disp_error_message("parse_syntax: need ';'",p);
return p+1;
}
p++;
- syntax.curly_count--;
+ script->syntax.curly_count--;
return p;
- } else if(syntax.curly[pos].type == TYPE_FOR) {
+ } else if(script->syntax.curly[pos].type == TYPE_FOR) {
// for-block end is a new line
- parse_nextline(false, p);
+ script->parse_nextline(false, p);
// Skip to the next loop
- sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __FR%x_NXT;",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",syntax.curly[pos].index);
+ sprintf(label,"__FR%x_FIN",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count--;
+ script->set_label(l,script->pos,p);
+ script->syntax.curly_count--;
return p;
- } else if(syntax.curly[pos].type == TYPE_WHILE) {
+ } else if(script->syntax.curly[pos].type == TYPE_WHILE) {
// while-block end is a new line
- parse_nextline(false, p);
+ script->parse_nextline(false, p);
// Skip to the decision while
- sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ sprintf(label,"goto __WL%x_NXT;",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",syntax.curly[pos].index);
+ sprintf(label,"__WL%x_FIN",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count--;
+ script->set_label(l,script->pos,p);
+ script->syntax.curly_count--;
return p;
- } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
- int pos = syntax.curly_count-1;
+ } else if(script->syntax.curly[script->syntax.curly_count-1].type == TYPE_USERFUNC) {
+ int pos = script->syntax.curly_count-1;
char label[256];
int l;
// Back
sprintf(label,"return;");
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
+ 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,"__FN%x_FIN",syntax.curly[pos].index);
+ sprintf(label,"__FN%x_FIN",script->syntax.curly[pos].index);
l=script->add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count--;
+ script->set_label(l,script->pos,p);
+ script->syntax.curly_count--;
return p;
} else {
*flag = 0;
@@ -1951,7 +1798,7 @@ void script_set_constant(const char* name, int value, bool isparameter) {
} 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", isparameter ? "parameter" : "constant", name, script->op2name(script->str_data[n].type));
}
}
/* adds data to a existent constant in the database, inserted normally via parse */
@@ -1992,7 +1839,7 @@ void script_set_constant_force(const char *name, int value, bool isparameter) {
* Reading constant databases
* const.txt
*------------------------------------------*/
-static void read_constdb(void) {
+void read_constdb(void) {
FILE *fp;
char line[1024],name[1024],val[1024];
int type;
@@ -2010,7 +1857,7 @@ static void read_constdb(void) {
type=0;
if(sscanf(line,"%[A-Za-z0-9_],%[-0-9xXA-Fa-f],%d",name,val,&type)>=2 ||
sscanf(line,"%[A-Za-z0-9_] %[-0-9xXA-Fa-f] %d",name,val,&type)>=2){
- script_set_constant(name, (int)strtol(val, NULL, 0), (bool)type);
+ script->set_constant(name, (int)strtol(val, NULL, 0), (bool)type);
}
}
fclose(fp);
@@ -2019,7 +1866,7 @@ static void read_constdb(void) {
/*==========================================
* Display emplacement line of script
*------------------------------------------*/
-static const char* script_print_line(StringBuf* buf, const char* p, const char* mark, int line)
+const char* script_print_line(StringBuf* buf, const char* p, const char* mark, int line)
{
int i;
if( p == NULL || !p[0] ) return NULL;
@@ -2063,11 +1910,11 @@ void script_errorwarning_sub(StringBuf *buf, const char* src, const char* file,
StrBuf->Printf(buf, " %s\n", error_msg);
for(j = 0; j < 5; j++ ) {
- script_print_line(buf, linestart[j], NULL, line + j - 5);
+ script->print_line(buf, linestart[j], NULL, line + j - 5);
}
- p = script_print_line(buf, p, error_pos, -line);
+ p = script->print_line(buf, p, error_pos, -line);
for(j = 0; j < 5; j++) {
- p = script_print_line(buf, p, NULL, line + j + 1 );
+ p = script->print_line(buf, p, NULL, line + j + 1 );
}
}
@@ -2077,7 +1924,7 @@ void script_error(const char* src, const char* file, int start_line, const char*
StrBuf->Init(&buf);
StrBuf->AppendStr(&buf, "\a\n");
- script_errorwarning_sub(&buf, src, file, start_line, error_msg, error_pos);
+ script->errorwarning_sub(&buf, src, file, start_line, error_msg, error_pos);
ShowError("%s", StrBuf->Value(&buf));
StrBuf->Destroy(&buf);
@@ -2088,7 +1935,7 @@ void script_warning(const char* src, const char* file, int start_line, const cha
StrBuf->Init(&buf);
- script_errorwarning_sub(&buf, src, file, start_line, error_msg, error_pos);
+ script->errorwarning_sub(&buf, src, file, start_line, error_msg, error_pos);
ShowWarning("%s", StrBuf->Value(&buf));
StrBuf->Destroy(&buf);
@@ -2104,54 +1951,55 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
struct script_code* code = NULL;
char end;
bool unresolved_names = false;
- parser_current_src = src;
- parser_current_file = file;
- parser_current_line = line;
+
+ script->parser_current_src = src;
+ script->parser_current_file = file;
+ script->parser_current_line = line;
if( src == NULL )
return NULL;// empty script
- memset(&syntax,0,sizeof(syntax));
+ memset(&script->syntax,0,sizeof(script->syntax));
- script_buf=(unsigned char *)aMalloc(SCRIPT_BLOCK_SIZE*sizeof(unsigned char));
- script_pos=0;
- script_size=SCRIPT_BLOCK_SIZE;
- parse_nextline(true, NULL);
+ script->buf=(unsigned char *)aMalloc(SCRIPT_BLOCK_SIZE*sizeof(unsigned char));
+ script->pos=0;
+ script->size=SCRIPT_BLOCK_SIZE;
+ script->parse_nextline(true, NULL);
// who called parse_script is responsible for clearing the database after using it, but just in case... lets clear it here
if( options&SCRIPT_USE_LABEL_DB )
script->label_count = 0;
- parse_options = options;
+ script->parse_options = options;
- if( setjmp( error_jump ) != 0 ) {
+ if( setjmp( script->error_jump ) != 0 ) {
//Restore program state when script has problems. [from jA]
int i;
- const int size = ARRAYLENGTH(syntax.curly);
- if( error_report )
- script->error(src,file,line,error_msg,error_pos);
- aFree( error_msg );
- aFree( script_buf );
- script_pos = 0;
- script_size = 0;
- script_buf = NULL;
+ const int size = ARRAYLENGTH(script->syntax.curly);
+ if( script->error_report )
+ script->error(src,file,line,script->error_msg,script->error_pos);
+ aFree( script->error_msg );
+ aFree( script->buf );
+ script->pos = 0;
+ script->size = 0;
+ script->buf = NULL;
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);
+ linkdb_final(&script->syntax.curly[i].case_label);
return NULL;
}
- parse_syntax_for_flag=0;
+ script->parse_syntax_for_flag=0;
p=src;
p=script->skip_space(p);
if( options&SCRIPT_IGNORE_EXTERNAL_BRACKETS )
{// does not require brackets around the script
if( *p == '\0' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
{// empty script and can return NULL
- aFree( script_buf );
- script_pos = 0;
- script_size = 0;
- script_buf = NULL;
+ aFree( script->buf );
+ script->pos = 0;
+ script->size = 0;
+ script->buf = NULL;
return NULL;
}
end = '\0';
@@ -2163,10 +2011,10 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
p = script->skip_space(p+1);
if( *p == '}' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
{// empty script and can return NULL
- aFree( script_buf );
- script_pos = 0;
- script_size = 0;
- script_buf = NULL;
+ aFree( script->buf );
+ script->pos = 0;
+ script->size = 0;
+ script->buf = NULL;
return NULL;
}
end = '}';
@@ -2184,34 +2032,34 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
}
}
- while( syntax.curly_count != 0 || *p != end )
+ while( script->syntax.curly_count != 0 || *p != end )
{
if( *p == '\0' )
disp_error_message("unexpected end of script",p);
// Special handling only label
- tmpp=script->skip_space(skip_word(p));
+ tmpp=script->skip_space(script->skip_word(p));
if(*tmpp==':' && !(!strncasecmp(p,"default:",8) && p + 7 == tmpp)){
- i=add_word(p);
- set_label(i,script_pos,p);
- if( parse_options&SCRIPT_USE_LABEL_DB )
- script->label_add(i,script_pos);
+ i=script->add_word(p);
+ script->set_label(i,script->pos,p);
+ if( script->parse_options&SCRIPT_USE_LABEL_DB )
+ script->label_add(i,script->pos);
p=tmpp+1;
p=script->skip_space(p);
continue;
}
// All other lumped
- p=parse_line(p);
+ p=script->parse_line(p);
p=script->skip_space(p);
- parse_nextline(false, p);
+ script->parse_nextline(false, p);
}
- add_scriptc(C_NOP);
+ script->addc(C_NOP);
// trim code to size
- script_size = script_pos;
- RECREATE(script_buf,unsigned char,script_pos);
+ script->size = script->pos;
+ RECREATE(script->buf,unsigned char,script->pos);
// default unknown references to variables
for(i=LABEL_START;i<script->str_num;i++){
@@ -2220,8 +2068,8 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
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);
+ next=GETVALUE(script->buf,j);
+ SETVALUE(script->buf,j,i);
j=next;
}
}
@@ -2237,38 +2085,38 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
disp_error_message("parse_script: unresolved function references", p);
}
-#ifdef DEBUG_DISP
- for(i=0;i<script_pos;i++){
+#ifdef SCRIPT_DEBUG_DISP
+ for(i=0;i<script->pos;i++){
if((i&15)==0) ShowMessage("%04x : ",i);
- ShowMessage("%02x ",script_buf[i]);
+ ShowMessage("%02x ",script->buf[i]);
if((i&15)==15) ShowMessage("\n");
}
ShowMessage("\n");
#endif
-#ifdef DEBUG_DISASM
+#ifdef SCRIPT_DEBUG_DISASM
{
int i = 0,j;
- while(i < script_pos) {
- c_op op = get_com(script_buf,&i);
+ while(i < script->pos) {
+ c_op op = script->get_com(script->buf,&i);
- ShowMessage("%06x %s", i, script_op2name(op));
+ ShowMessage("%06x %s", i, script->op2name(op));
j = i;
switch(op) {
case C_INT:
- ShowMessage(" %d", get_num(script_buf,&i));
+ ShowMessage(" %d", script->get_num(script->buf,&i));
break;
case C_POS:
- ShowMessage(" 0x%06x", *(int*)(script_buf+i)&0xffffff);
+ ShowMessage(" 0x%06x", *(int*)(script->buf+i)&0xffffff);
i += 3;
break;
case C_NAME:
- j = (*(int*)(script_buf+i)&0xffffff);
+ j = (*(int*)(script->buf+i)&0xffffff);
ShowMessage(" %s", ( j == 0xffffff ) ? "?? unknown ??" : script->get_str(j));
i += 3;
break;
case C_STR:
- j = strlen(script_buf + i);
- ShowMessage(" %s", script_buf + i);
+ j = strlen(script->buf + i);
+ ShowMessage(" %s", script->buf + i);
i += j+1;
break;
}
@@ -2278,8 +2126,8 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
#endif
CREATE(code,struct script_code,1);
- code->script_buf = script_buf;
- code->script_size = script_size;
+ code->script_buf = script->buf;
+ code->script_size = script->size;
code->script_vars = NULL;
return code;
}
@@ -2290,8 +2138,8 @@ TBL_PC *script_rid2sd(struct script_state *st) {
TBL_PC *sd;
if( !( sd = map->id2sd(st->rid) ) ){
ShowError("script_rid2sd: fatal error ! player not attached!\n");
- script_reportfunc(st);
- script_reportsrc(st);
+ script->reportfunc(st);
+ script->reportsrc(st);
st->state = END;
}
return sd;
@@ -2317,7 +2165,7 @@ void get_val(struct script_state* st, struct script_data* data)
//##TODO use reference_tovariable(data) when it's confirmed that it works [FlavioJS]
if( !reference_toconstant(data) && not_server_variable(prefix) ) {
- sd = script_rid2sd(st);
+ 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);
@@ -2446,7 +2294,7 @@ void* get_val2(struct script_state* st, int uid, struct DBMap** ref) {
* Stores the value of a script variable
* Return value is 0 on fail, 1 on success.
*------------------------------------------*/
-static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* name, const void* value, struct DBMap** ref)
+int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* name, const void* value, struct DBMap** ref)
{
char prefix = name[0];
@@ -2492,7 +2340,7 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam
if( st != NULL )
{
ShowError("script:set_reg: failed to set param '%s' to %d.\n", name, val);
- script_reportsrc(st);
+ script->reportsrc(st);
st->state = END;
}
return 0;
@@ -2535,12 +2383,12 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam
int set_var(TBL_PC* sd, char* name, void* val)
{
- return set_reg(NULL, sd, reference_uid(script->add_str(name),0), name, val, NULL);
+ return script->set_reg(NULL, sd, reference_uid(script->add_str(name),0), name, val, NULL);
}
void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct DBMap **ref)
{
- set_reg(st, sd, reference_uid(script->add_str(varname),elem), varname, value, ref);
+ script->set_reg(st, sd, reference_uid(script->add_str(varname),elem), varname, value, ref);
}
/// Converts the data to a string
@@ -2569,8 +2417,8 @@ const char* conv_str(struct script_state* st, struct script_data* data)
else
{// unsupported data type
ShowError("script:conv_str: cannot convert to string, defaulting to \"\"\n");
- script_reportdata(data);
- script_reportsrc(st);
+ script->reportdata(data);
+ script->reportsrc(st);
data->type = C_CONSTSTR;
data->u.str = "";
}
@@ -2609,8 +2457,8 @@ int conv_num(struct script_state* st, struct script_data* data) {
num = INT_MAX;
ShowError("script:conv_num: overflow detected, capping to %ld\n", num);
}
- script_reportdata(data);
- script_reportsrc(st);
+ script->reportdata(data);
+ script->reportsrc(st);
}
if( data->type == C_STR )
aFree(p);
@@ -2623,8 +2471,8 @@ int conv_num(struct script_state* st, struct script_data* data) {
else
{// unsupported data type
ShowError("script:conv_num: cannot convert to number, defaulting to 0\n");
- script_reportdata(data);
- script_reportsrc(st);
+ script->reportdata(data);
+ script->reportsrc(st);
data->type = C_INT;
data->u.num = 0;
}
@@ -2648,7 +2496,7 @@ void stack_expand(struct script_stack* stack) {
/// Pushes a value into the stack (with reference)
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);
+ script->stack_expand(stack);
stack->stack_data[stack->sp].type = type;
stack->stack_data[stack->sp].u.num = val;
stack->stack_data[stack->sp].ref = ref;
@@ -2660,7 +2508,7 @@ struct script_data* push_val(struct script_stack* stack, enum c_op type, int val
struct script_data* push_str(struct script_stack* stack, enum c_op type, char* str)
{
if( stack->sp >= stack->sp_max )
- stack_expand(stack);
+ script->stack_expand(stack);
stack->stack_data[stack->sp].type = type;
stack->stack_data[stack->sp].u.str = str;
stack->stack_data[stack->sp].ref = NULL;
@@ -2672,7 +2520,7 @@ struct script_data* push_str(struct script_stack* stack, enum c_op type, char* s
struct script_data* push_retinfo(struct script_stack* stack, struct script_retinfo* ri, DBMap **ref)
{
if( stack->sp >= stack->sp_max )
- stack_expand(stack);
+ script->stack_expand(stack);
stack->stack_data[stack->sp].type = C_RETINFO;
stack->stack_data[stack->sp].u.ri = ri;
stack->stack_data[stack->sp].ref = ref;
@@ -2905,8 +2753,8 @@ void op_3(struct script_state* st, int op)
else
{
ShowError("script:op_3: invalid data for the ternary operator test\n");
- script_reportdata(data);
- script_reportsrc(st);
+ script->reportdata(data);
+ script->reportsrc(st);
script_removetop(st, -3, 0);
script_pushnil(st);
return;
@@ -2946,8 +2794,8 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
return;
}
default:
- ShowError("script:op2_str: unexpected string operator %s\n", script_op2name(op));
- script_reportsrc(st);
+ ShowError("script:op2_str: unexpected string operator %s\n", script->op2name(op));
+ script->reportsrc(st);
script_pushnil(st);
st->state = END;
return;
@@ -2982,8 +2830,8 @@ void op_2num(struct script_state* st, int op, int i1, int i2)
case C_MOD:
if( i2 == 0 )
{
- ShowError("script:op_2num: division by zero detected op=%s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
+ ShowError("script:op_2num: division by zero detected op=%s i1=%d i2=%d\n", script->op2name(op), i1, i2);
+ script->reportsrc(st);
script_pushnil(st);
st->state = END;
return;
@@ -3000,21 +2848,21 @@ void op_2num(struct script_state* st, int op, int i1, int i2)
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;
default:
- ShowError("script:op_2num: unexpected number operator %s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
+ 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 )
{
- ShowWarning("script:op_2num: underflow detected op=%s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
+ 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 )
{
- ShowWarning("script:op_2num: overflow detected op=%s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
+ ShowWarning("script:op_2num: overflow detected op=%s i1=%d i2=%d\n", script->op2name(op), i1, i2);
+ script->reportsrc(st);
ret = INT_MAX;
}
}
@@ -3060,7 +2908,7 @@ void op_2(struct script_state *st, int op)
if( data_isstring(left) && data_isstring(right) )
{// ss => op_2str
- op_2str(st, op, left->u.str, right->u.str);
+ script->op_2str(st, op, left->u.str, right->u.str);
script_removetop(st, leftref.type == C_NOP ? -3 : -2, -1);// pop the two values before the top one
if (leftref.type != C_NOP)
@@ -3076,17 +2924,17 @@ void op_2(struct script_state *st, int op)
int i2 = right->u.num;
script_removetop(st, leftref.type == C_NOP ? -2 : -1, 0);
- op_2num(st, op, i1, i2);
+ script->op_2num(st, op, i1, i2);
if (leftref.type != C_NOP)
*left = leftref;
}
else
{// invalid argument
- ShowError("script:op_2: invalid data for operator %s\n", script_op2name(op));
- script_reportdata(left);
- script_reportdata(right);
- script_reportsrc(st);
+ ShowError("script:op_2: invalid data for operator %s\n", script->op2name(op));
+ script->reportdata(left);
+ script->reportdata(right);
+ script->reportsrc(st);
script_removetop(st, -2, 0);
script_pushnil(st);
st->state = END;
@@ -3107,9 +2955,9 @@ void op_1(struct script_state* st, int op)
if( !data_isint(data) )
{// not a number
- ShowError("script:op_1: argument is not a number (op=%s)\n", script_op2name(op));
- script_reportdata(data);
- script_reportsrc(st);
+ ShowError("script:op_1: argument is not a number (op=%s)\n", script->op2name(op));
+ script->reportdata(data);
+ script->reportsrc(st);
script_pushnil(st);
st->state = END;
return;
@@ -3123,8 +2971,8 @@ void op_1(struct script_state* st, int op)
case C_NOT: i1 = ~i1; break;
case C_LNOT: i1 = !i1; break;
default:
- ShowError("script:op_1: unexpected operator %s i1=%d\n", script_op2name(op), i1);
- script_reportsrc(st);
+ ShowError("script:op_1: unexpected operator %s i1=%d\n", script->op2name(op), i1);
+ script->reportsrc(st);
script_pushnil(st);
st->state = END;
return;
@@ -3137,7 +2985,7 @@ void op_1(struct script_state* st, int op)
///
/// @param st Script state whose stack arguments should be inspected.
/// @param func Built-in function for which the arguments are intended.
-static void script_check_buildin_argtype(struct script_state* st, int func)
+void script_check_buildin_argtype(struct script_state* st, int func)
{
char type;
int idx, invalid = 0;
@@ -3151,7 +2999,7 @@ static void script_check_buildin_argtype(struct script_state* st, int func)
if( type == '?' || type == '*' ) {// optional argument or unknown number of optional parameters ( no types are after this )
break;
} else if( type == 0 ) {// more arguments than necessary ( should not happen, as it is checked before )
- ShowWarning("Found more arguments than necessary. unexpected arg type %s\n",script_op2name(data->type));
+ ShowWarning("Found more arguments than necessary. unexpected arg type %s\n",script->op2name(data->type));
invalid++;
break;
} else {
@@ -3167,7 +3015,7 @@ static void script_check_buildin_argtype(struct script_state* st, int func)
if( !data_isstring(data) && !data_isint(data) && !data_isreference(data) )
{// variant
ShowWarning("Unexpected type for argument %d. Expected string, number or variable.\n", idx-1);
- script_reportdata(data);
+ script->reportdata(data);
invalid++;
}
break;
@@ -3175,7 +3023,7 @@ static void script_check_buildin_argtype(struct script_state* st, int func)
if( !data_isstring(data) && !( data_isreference(data) && is_string_variable(name) ) )
{// string
ShowWarning("Unexpected type for argument %d. Expected string.\n", idx-1);
- script_reportdata(data);
+ script->reportdata(data);
invalid++;
}
break;
@@ -3183,23 +3031,23 @@ static void script_check_buildin_argtype(struct script_state* st, int func)
if( !data_isint(data) && !( data_isreference(data) && ( reference_toparam(data) || reference_toconstant(data) || !is_string_variable(name) ) ) )
{// int ( params and constants are always int )
ShowWarning("Unexpected type for argument %d. Expected number.\n", idx-1);
- script_reportdata(data);
+ script->reportdata(data);
invalid++;
}
break;
case 'r':
if( !data_isreference(data) )
{// variables
- ShowWarning("Unexpected type for argument %d. Expected variable, got %s.\n", idx-1,script_op2name(data->type));
- script_reportdata(data);
+ ShowWarning("Unexpected type for argument %d. Expected variable, got %s.\n", idx-1,script->op2name(data->type));
+ script->reportdata(data);
invalid++;
}
break;
case 'l':
if( !data_islabel(data) && !data_isfunclabel(data) )
{// label
- ShowWarning("Unexpected type for argument %d. Expected label, got %s\n", idx-1,script_op2name(data->type));
- script_reportdata(data);
+ ShowWarning("Unexpected type for argument %d. Expected label, got %s\n", idx-1,script->op2name(data->type));
+ script->reportdata(data);
invalid++;
}
break;
@@ -3209,7 +3057,7 @@ static void script_check_buildin_argtype(struct script_state* st, int func)
if(invalid) {
ShowDebug("Function: %s\n", script->get_str(func));
- script_reportsrc(st);
+ script->reportsrc(st);
}
}
@@ -3229,7 +3077,7 @@ int run_func(struct script_state *st)
{
ShowError("script:run_func: C_ARG not found. please report this!!!\n");
st->state = END;
- script_reportsrc(st);
+ script->reportsrc(st);
return 1;
}
start_sp = i-1;// C_NAME of the command
@@ -3242,22 +3090,22 @@ int run_func(struct script_state *st)
else
{
ShowError("script:run_func: not a buildin command.\n");
- script_reportdata(data);
- script_reportsrc(st);
+ script->reportdata(data);
+ script->reportsrc(st);
st->state = END;
return 1;
}
if( script->config.warn_func_mismatch_argtypes ) {
- script_check_buildin_argtype(st, func);
+ script->check_buildin_argtype(st, func);
}
if(script->str_data[func].func){
if (!(script->str_data[func].func(st))) //Report error
- script_reportsrc(st);
+ script->reportsrc(st);
} else {
- ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!\n", script->get_str(func), func, script_op2name(script->str_data[func].type));
- script_reportsrc(st);
+ ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!\n", script->get_str(func), func, script->op2name(script->str_data[func].type));
+ script->reportsrc(st);
st->state = END;
}
@@ -3276,7 +3124,7 @@ int run_func(struct script_state *st)
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");
- script_reportsrc(st);
+ script->reportsrc(st);
st->state = END;
return 1;
}
@@ -3357,7 +3205,7 @@ int run_script_timer(int tid, unsigned int tick, int id, intptr_t data) {
///
/// @param st Script state to detach.
/// @param dequeue_event Whether to schedule any queued events, when there was no previous script.
-static void script_detach_state(struct script_state* st, bool dequeue_event) {
+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) {
@@ -3385,7 +3233,7 @@ static void script_detach_state(struct script_state* st, bool dequeue_event) {
}
} 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);
+ script->reportsrc(st->bk_st);
script->free_state(st->bk_st);
st->bk_st = NULL;
@@ -3442,14 +3290,14 @@ void run_script_main(struct script_state *st) {
st->instance_id = -1;
if(st->state == RERUNLINE) {
- run_func(st);
+ script->run_func(st);
if(st->state == GOTO)
st->state = RUN;
} else if(st->state != END)
st->state = RUN;
while( st->state == RUN ){
- enum c_op c = get_com(st->script->script_buf,&st->pos);
+ enum c_op c = script->get_com(st->script->script_buf,&st->pos);
switch(c){
case C_EOL:
if( stack->defsp > stack->sp )
@@ -3458,7 +3306,7 @@ void run_script_main(struct script_state *st) {
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);
+ script->push_val(stack,C_INT,script->get_num(st->script->script_buf,&st->pos),NULL);
break;
case C_POS:
case C_NAME:
@@ -3473,12 +3321,12 @@ void run_script_main(struct script_state *st) {
while(st->script->script_buf[st->pos++]);
break;
case C_FUNC:
- run_func(st);
+ script->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);
+ script->reportsrc(st);
st->state=END;
}
}
@@ -3491,7 +3339,7 @@ void run_script_main(struct script_state *st) {
case C_NEG:
case C_NOT:
case C_LNOT:
- op_1(st ,c);
+ script->op_1(st ,c);
break;
case C_ADD:
@@ -3512,11 +3360,11 @@ void run_script_main(struct script_state *st) {
case C_LOR:
case C_R_SHIFT:
case C_L_SHIFT:
- op_2(st, c);
+ script->op_2(st, c);
break;
case C_OP3:
- op_3(st, c);
+ script->op_3(st, c);
break;
case C_NOP:
@@ -3530,14 +3378,14 @@ void run_script_main(struct script_state *st) {
}
if( !st->freeloop && cmdcount>0 && (--cmdcount)<=0 ){
ShowError("run_script: infinity loop !\n");
- script_reportsrc(st);
+ script->reportsrc(st);
st->state=END;
}
}
if(st->sleep.tick > 0) {
//Restore previous script
- script_detach_state(st, false);
+ script->detach_state(st, false);
//Delay execution
sd = map->id2sd(st->rid); // Get sd since script might have attached someone while running. [Inkfish]
st->sleep.charid = sd?sd->status.char_id:0;
@@ -3549,9 +3397,9 @@ void run_script_main(struct script_state *st) {
ShowWarning("Unable to restore stack! Double continuation!\n");
//Report BOTH scripts to see if that can help somehow.
ShowDebug("Previous script (lost):\n");
- script_reportsrc(st->bk_st);
+ script->reportsrc(st->bk_st);
ShowDebug("Current script:\n");
- script_reportsrc(st);
+ script->reportsrc(st);
script->free_state(st->bk_st);
st->bk_st = NULL;
@@ -3564,7 +3412,7 @@ void run_script_main(struct script_state *st) {
sd->state.using_fake_npc = 0;
}
//Restore previous script if any.
- script_detach_state(st, true);
+ script->detach_state(st, true);
if (sd->state.reg_dirty&2)
intif->saveregistry(sd,2);
if (sd->state.reg_dirty&1)
@@ -3625,7 +3473,7 @@ int script_config_read(char *cfgName) {
/**
* @see DBApply
*/
-static int db_script_free_code_sub(DBKey key, DBData *data, va_list ap)
+int db_script_free_code_sub(DBKey key, DBData *data, va_list ap)
{
struct script_code *code = DB->data2ptr(data);
if (code)
@@ -3727,7 +3575,7 @@ void do_final_script(void) {
DBIterator *iter;
struct script_state *st;
-#ifdef DEBUG_HASH
+#ifdef SCRIPT_DEBUG_HASH
if (battle_config.etc_log)
{
FILE *fp = fopen("hash_dump.txt","wt");
@@ -3744,7 +3592,7 @@ void do_final_script(void) {
fprintf(fp,"num : hash : data_name\n");
fprintf(fp,"---------------------------------------------------------------\n");
for(i=LABEL_START; i<script->str_num; i++) {
- unsigned int h = calc_hash(script->get_str(i));
+ unsigned int h = script->calc_hash(script->get_str(i));
fprintf(fp,"%04d : %4u : %s\n",i,h, script->get_str(i));
++count[h];
}
@@ -3792,8 +3640,8 @@ void do_final_script(void) {
mapreg->final();
- script->userfunc_db->destroy(script->userfunc_db, db_script_free_code_sub);
- script->autobonus_db->destroy(script->autobonus_db, db_script_free_code_sub);
+ script->userfunc_db->destroy(script->userfunc_db, script->db_free_code_sub);
+ script->autobonus_db->destroy(script->autobonus_db, script->db_free_code_sub);
if (script->str_data)
aFree(script->str_data);
@@ -3858,7 +3706,7 @@ void do_init_script(void) {
ers_chunk_size(script->stack_ers, 10);
script->parse_builtin();
- read_constdb();
+ script->read_constdb();
mapreg->init();
}
@@ -3875,7 +3723,7 @@ int script_reload(void) {
dbi_destroy(iter);
- script->userfunc_db->clear(script->userfunc_db, db_script_free_code_sub);
+ script->userfunc_db->clear(script->userfunc_db, script->db_free_code_sub);
script->label_count = 0;
for( i = 0; i < atcommand->binding_count; i++ ) {
@@ -3912,7 +3760,7 @@ int script_reload(void) {
///
/// mes "<message>";
BUILDIN(mes) {
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -3938,7 +3786,7 @@ BUILDIN(next)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
#ifdef SECURE_NPCTIMEOUT
@@ -3956,7 +3804,7 @@ BUILDIN(next)
BUILDIN(close) {
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -3972,7 +3820,7 @@ BUILDIN(close) {
BUILDIN(close2) {
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -3980,7 +3828,7 @@ BUILDIN(close2) {
st->state = STOP;
else {
ShowWarning("misuse of 'close2'! trying to use it without prior dialog! skipping...\n");
- script_reportsrc(st);
+ script->reportsrc(st);
}
clif->scriptclose(sd, st->oid);
@@ -3990,7 +3838,7 @@ BUILDIN(close2) {
/// Counts the number of valid and total number of options in 'str'
/// If max_count > 0 the counting stops when that valid option is reached
/// total is incremented for each option (NULL is supported)
-static int menu_countoptions(const char* str, int max_count, int* total)
+int menu_countoptions(const char* str, int max_count, int* total)
{
int count = 0;
int bogus_total;
@@ -4045,7 +3893,7 @@ BUILDIN(menu)
const char* text;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -4079,7 +3927,7 @@ BUILDIN(menu)
{// not a label
StrBuf->Destroy(&buf);
ShowError("script:menu: argument #%d (from 1) is not a label or label not found.\n", i);
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;
}
@@ -4090,7 +3938,7 @@ BUILDIN(menu)
if( sd->npc_menu > 0 )
StrBuf->AppendStr(&buf, ":");
StrBuf->AppendStr(&buf, text);
- sd->npc_menu += menu_countoptions(text, 0, NULL);
+ sd->npc_menu += script->menu_countoptions(text, 0, NULL);
}
st->state = RERUNLINE;
sd->state.menu_or_input = 1;
@@ -4114,7 +3962,7 @@ BUILDIN(menu)
if( sd->npc_menu >= 0xff )
{// client supports only up to 254 entries; 0 is not used and 255 is reserved for cancel; excess entries are displayed but cause 'uint8' overflow
ShowWarning("buildin_menu: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
- script_reportsrc(st);
+ script->reportsrc(st);
}
}
else if( sd->npc_menu == 0xff )
@@ -4138,7 +3986,7 @@ BUILDIN(menu)
for( i = 2; i < script_lastdata(st); i += 2 )
{
text = script_getstr(st, i);
- sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu);
+ sd->npc_menu -= script->menu_countoptions(text, sd->npc_menu, &menu);
if( sd->npc_menu <= 0 )
break;// entry found
}
@@ -4151,7 +3999,7 @@ BUILDIN(menu)
if( !data_islabel(script_getdata(st, i + 1)) )
{// TODO remove this temporary crash-prevention code (fallback for multiple scripts requesting user input)
ShowError("script:menu: unexpected data in label argument\n");
- script_reportdata(script_getdata(st, i + 1));
+ script->reportdata(script_getdata(st, i + 1));
st->state = END;
return false;
}
@@ -4174,7 +4022,7 @@ BUILDIN(select)
const char* text;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -4194,7 +4042,7 @@ BUILDIN(select)
StrBuf->AppendStr(&buf, ":");
StrBuf->AppendStr(&buf, text);
- sd->npc_menu += menu_countoptions(text, 0, NULL);
+ sd->npc_menu += script->menu_countoptions(text, 0, NULL);
}
st->state = RERUNLINE;
@@ -4217,7 +4065,7 @@ BUILDIN(select)
if( sd->npc_menu >= 0xff ) {
ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
- script_reportsrc(st);
+ script->reportsrc(st);
}
} else if( sd->npc_menu == 0xff ) {// Cancel was pressed
sd->state.menu_or_input = 0;
@@ -4228,7 +4076,7 @@ BUILDIN(select)
sd->state.menu_or_input = 0;
for( i = 2; i <= script_lastdata(st); ++i ) {
text = script_getstr(st, i);
- sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu);
+ sd->npc_menu -= script->menu_countoptions(text, sd->npc_menu, &menu);
if( sd->npc_menu <= 0 )
break;// entry found
}
@@ -4253,7 +4101,7 @@ BUILDIN(prompt)
const char *text;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -4273,7 +4121,7 @@ BUILDIN(prompt)
if( sd->npc_menu > 0 )
StrBuf->AppendStr(&buf, ":");
StrBuf->AppendStr(&buf, text);
- sd->npc_menu += menu_countoptions(text, 0, NULL);
+ sd->npc_menu += script->menu_countoptions(text, 0, NULL);
}
st->state = RERUNLINE;
@@ -4297,7 +4145,7 @@ BUILDIN(prompt)
if( sd->npc_menu >= 0xff )
{
ShowWarning("buildin_prompt: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
- script_reportsrc(st);
+ script->reportsrc(st);
}
}
else if( sd->npc_menu == 0xff )
@@ -4315,7 +4163,7 @@ BUILDIN(prompt)
for( i = 2; i <= script_lastdata(st); ++i )
{
text = script_getstr(st, i);
- sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu);
+ sd->npc_menu -= script->menu_countoptions(text, sd->npc_menu, &menu);
if( sd->npc_menu <= 0 )
break;// entry found
}
@@ -4338,7 +4186,7 @@ BUILDIN(goto)
if( !data_islabel(script_getdata(st,2)) )
{
ShowError("script:goto: not a label\n");
- script_reportdata(script_getdata(st,2));
+ script->reportdata(script_getdata(st,2));
st->state = END;
return false;
}
@@ -4389,7 +4237,7 @@ BUILDIN(callfunc)
ri->pos = st->pos;// script location
ri->nargs = j;// argument count
ri->defsp = st->stack->defsp;// default stack pointer
- push_retinfo(st->stack, ri, ref);
+ script->push_retinfo(st->stack, ri, ref);
st->pos = 0;
st->script = scr;
@@ -4412,7 +4260,7 @@ BUILDIN(callsub)
if( !data_islabel(script_getdata(st,2)) && !data_isfunclabel(script_getdata(st,2)) )
{
ShowError("script:callsub: argument is not a label\n");
- script_reportdata(script_getdata(st,2));
+ script->reportdata(script_getdata(st,2));
st->state = END;
return false;
}
@@ -4439,7 +4287,7 @@ BUILDIN(callsub)
ri->pos = st->pos;// script location
ri->nargs = j;// argument count
ri->defsp = st->stack->defsp;// default stack pointer
- push_retinfo(st->stack, ri, ref);
+ script->push_retinfo(st->stack, ri, ref);
st->pos = pos;
st->stack->defsp = st->stack->sp;
@@ -4558,7 +4406,7 @@ BUILDIN(warp)
const char* str;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -4575,7 +4423,7 @@ BUILDIN(warp)
if( ret ) {
ShowError("buildin_warp: moving player '%s' to \"%s\",%d,%d failed.\n", sd->status.name, str, x, y);
- script_reportsrc(st);
+ script->reportsrc(st);
}
return true;
@@ -4583,7 +4431,7 @@ BUILDIN(warp)
/*==========================================
* Warp a specified area
*------------------------------------------*/
-static int buildin_areawarp_sub(struct block_list *bl,va_list ap)
+int buildin_areawarp_sub(struct block_list *bl,va_list ap)
{
int x2,y2,x3,y3;
unsigned int index;
@@ -4651,14 +4499,14 @@ 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);
+ map->foreachinarea(script->buildin_areawarp_sub, m,x0,y0,x1,y1, BL_PC, index,x2,y2,x3,y3);
return true;
}
/*==========================================
* areapercentheal <map>,<x1>,<y1>,<x2>,<y2>,<hp>,<sp>
*------------------------------------------*/
-static int buildin_areapercentheal_sub(struct block_list *bl,va_list ap)
+int buildin_areapercentheal_sub(struct block_list *bl,va_list ap)
{
int hp, sp;
hp = va_arg(ap, int);
@@ -4682,7 +4530,7 @@ BUILDIN(areapercentheal) {
if( (m=map->mapname2mapid(mapname))< 0)
return true;
- map->foreachinarea(buildin_areapercentheal_sub,m,x0,y0,x1,y1,BL_PC,hp,sp);
+ map->foreachinarea(script->buildin_areapercentheal_sub,m,x0,y0,x1,y1,BL_PC,hp,sp);
return true;
}
@@ -4764,7 +4612,7 @@ BUILDIN(warpparty)
break;
case 2:
//"SavePoint" uses save point of the currently attached player
- if (( sd = script_rid2sd(st) ) == NULL )
+ if (( sd = script->rid2sd(st) ) == NULL )
return true;
default:
mapindex = 0;
@@ -4831,7 +4679,7 @@ BUILDIN(warpguild)
: ( strcmp(str,"SavePoint")==0 ) ? 2
: 3;
- if( type == 2 && ( sd = script_rid2sd(st) ) == NULL )
+ if( type == 2 && ( sd = script->rid2sd(st) ) == NULL )
{// "SavePoint" uses save point of the currently attached player
return true;
}
@@ -4873,7 +4721,7 @@ BUILDIN(heal) {
TBL_PC *sd;
int hp,sp;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (!sd) return true;
hp=script_getnum(st,2);
@@ -4898,7 +4746,7 @@ BUILDIN(itemheal)
return true;
}
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (!sd) return true;
pc->itemheal(sd,sd->itemid,hp,sp);
return true;
@@ -4920,7 +4768,7 @@ BUILDIN(percentheal)
return true;
}
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
#ifdef RENEWAL
@@ -4946,7 +4794,7 @@ BUILDIN(jobchange)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -4982,14 +4830,14 @@ BUILDIN(input)
int min;
int max;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
data = script_getdata(st,2);
if( !data_isreference(data) ){
ShowError("script:input: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;
}
@@ -5017,13 +4865,13 @@ BUILDIN(input)
if( is_string_variable(name) )
{
int len = (int)strlen(sd->npc_str);
- set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st,2));
+ script->set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st,2));
script_pushint(st, (len > max ? 1 : len < min ? -1 : 0));
}
else
{
int amount = sd->npc_amount;
- set_reg(st, sd, uid, name, (void*)__64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2));
+ script->set_reg(st, sd, uid, name, (void*)__64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2));
script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0));
}
st->state = RUN;
@@ -5052,7 +4900,7 @@ BUILDIN(set)
if( !data_isreference(data) )
{
ShowError("script:set: not a variable\n");
- script_reportdata(script_getdata(st,2));
+ script->reportdata(script_getdata(st,2));
st->state = END;
return false;
}
@@ -5063,7 +4911,7 @@ BUILDIN(set)
if( not_server_variable(prefix) )
{
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
{
ShowError("script:set: no player attached for player variable '%s'\n", name);
@@ -5078,7 +4926,7 @@ BUILDIN(set)
if( !not_array_variable(*namevalue) )
{// array variable being copied into another array variable
- if( sd == NULL && not_server_variable(*namevalue) && !(sd = script_rid2sd(st)) )
+ if( sd == NULL && not_server_variable(*namevalue) && !(sd = script->rid2sd(st)) )
{// player must be attached in order to copy a player variable
ShowError("script:set: no player attached for player variable '%s'\n", namevalue);
return true;
@@ -5100,9 +4948,9 @@ BUILDIN(set)
#endif
if( is_string_variable(name) )
- set_reg(st,sd,num,name,(void*)script_getstr(st,3),script_getref(st,2));
+ script->set_reg(st,sd,num,name,(void*)script_getstr(st,3),script_getref(st,2));
else
- set_reg(st,sd,num,name,(void*)__64BPTRSIZE(script_getnum(st,3)),script_getref(st,2));
+ script->set_reg(st,sd,num,name,(void*)__64BPTRSIZE(script_getnum(st,3)),script_getref(st,2));
// return a copy of the variable reference
script_pushcopy(st,2);
@@ -5115,7 +4963,7 @@ BUILDIN(set)
///
/// Returns the size of the specified array
-static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isstring, struct DBMap** ref)
+int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isstring, struct DBMap** ref)
{
int32 ret = idx;
@@ -5160,7 +5008,7 @@ BUILDIN(setarray)
if( !data_isreference(data) )
{
ShowError("script:setarray: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not a variable
}
@@ -5171,14 +5019,14 @@ BUILDIN(setarray)
if( not_array_variable(*name) )
{
ShowError("script:setarray: illegal scope\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not supported
}
if( not_server_variable(*name) )
{
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached
}
@@ -5190,12 +5038,12 @@ BUILDIN(setarray)
if( is_string_variable(name) )
{// string array
for( i = 3; start < end; ++start, ++i )
- set_reg(st, sd, reference_uid(id, start), name, (void*)script_getstr(st,i), reference_getref(data));
+ script->set_reg(st, sd, reference_uid(id, start), name, (void*)script_getstr(st,i), reference_getref(data));
}
else
{// int array
for( i = 3; start < end; ++start, ++i )
- set_reg(st, sd, reference_uid(id, start), name, (void*)__64BPTRSIZE(script_getnum(st,i)), reference_getref(data));
+ script->set_reg(st, sd, reference_uid(id, start), name, (void*)__64BPTRSIZE(script_getnum(st,i)), reference_getref(data));
}
return true;
}
@@ -5218,7 +5066,7 @@ BUILDIN(cleararray)
if( !data_isreference(data) )
{
ShowError("script:cleararray: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not a variable
}
@@ -5229,14 +5077,14 @@ BUILDIN(cleararray)
if( not_array_variable(*name) )
{
ShowError("script:cleararray: illegal scope\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not supported
}
if( not_server_variable(*name) )
{
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached
}
@@ -5251,7 +5099,7 @@ BUILDIN(cleararray)
end = SCRIPT_MAX_ARRAYSIZE;
for( ; start < end; ++start )
- set_reg(st, sd, reference_uid(id, start), name, v, script_getref(st,2));
+ script->set_reg(st, sd, reference_uid(id, start), name, v, script_getref(st,2));
return true;
}
@@ -5279,8 +5127,8 @@ BUILDIN(copyarray)
if( !data_isreference(data1) || !data_isreference(data2) )
{
ShowError("script:copyarray: not a variable\n");
- script_reportdata(data1);
- script_reportdata(data2);
+ script->reportdata(data1);
+ script->reportdata(data2);
st->state = END;
return false;// not a variable
}
@@ -5294,8 +5142,8 @@ BUILDIN(copyarray)
if( not_array_variable(*name1) || not_array_variable(*name2) )
{
ShowError("script:copyarray: illegal scope\n");
- script_reportdata(data1);
- script_reportdata(data2);
+ script->reportdata(data1);
+ script->reportdata(data2);
st->state = END;
return false;// not supported
}
@@ -5303,15 +5151,15 @@ BUILDIN(copyarray)
if( is_string_variable(name1) != is_string_variable(name2) )
{
ShowError("script:copyarray: type mismatch\n");
- script_reportdata(data1);
- script_reportdata(data2);
+ script->reportdata(data1);
+ script->reportdata(data2);
st->state = END;
return false;// data type mismatch
}
if( not_server_variable(*name1) || not_server_variable(*name2) )
{
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached
}
@@ -5327,7 +5175,7 @@ BUILDIN(copyarray)
for( i = count - 1; i >= 0; --i )
{
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->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1));
script_removetop(st, -1, 0);
}
}
@@ -5338,11 +5186,11 @@ BUILDIN(copyarray)
if( idx2 + i < SCRIPT_MAX_ARRAYSIZE )
{
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->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1));
script_removetop(st, -1, 0);
}
else// out of range - assume ""/0
- set_reg(st, sd, reference_uid(id1, idx1 + i), name1, (is_string_variable(name1)?(void*)"":(void*)0), reference_getref(data1));
+ script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, (is_string_variable(name1)?(void*)"":(void*)0), reference_getref(data1));
}
}
return true;
@@ -5362,7 +5210,7 @@ BUILDIN(getarraysize)
if( !data_isreference(data) )
{
ShowError("script:getarraysize: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
script_pushnil(st);
st->state = END;
return false;// not a variable
@@ -5372,13 +5220,13 @@ BUILDIN(getarraysize)
if( not_array_variable(*name) )
{
ShowError("script:getarraysize: illegal scope\n");
- script_reportdata(data);
+ script->reportdata(data);
script_pushnil(st);
st->state = END;
return false;// not supported
}
- script_pushint(st, getarraysize(st, reference_getid(data), reference_getindex(data), is_string_variable(name), reference_getref(data)));
+ script_pushint(st, script->getarraysize(st, reference_getid(data), reference_getindex(data), is_string_variable(name), reference_getref(data)));
return true;
}
@@ -5400,7 +5248,7 @@ BUILDIN(deletearray)
if( !data_isreference(data) )
{
ShowError("script:deletearray: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not a variable
}
@@ -5411,14 +5259,14 @@ BUILDIN(deletearray)
if( not_array_variable(*name) )
{
ShowError("script:deletearray: illegal scope\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not supported
}
if( not_server_variable(*name) )
{
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached
}
@@ -5440,7 +5288,7 @@ BUILDIN(deletearray)
for( ; start + count < end; ++start )
{
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->set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data));
script_removetop(st, -1, 0);
}
}
@@ -5449,12 +5297,12 @@ BUILDIN(deletearray)
if( is_string_variable(name) )
{
for( ; start < end; ++start )
- set_reg(st, sd, reference_uid(id, start), name, (void *)"", reference_getref(data));
+ script->set_reg(st, sd, reference_uid(id, start), name, (void *)"", reference_getref(data));
}
else
{
for( ; start < end; ++start )
- set_reg(st, sd, reference_uid(id, start), name, (void*)0, reference_getref(data));
+ script->set_reg(st, sd, reference_uid(id, start), name, (void*)0, reference_getref(data));
}
return true;
}
@@ -5474,7 +5322,7 @@ BUILDIN(getelementofarray)
if( !data_isreference(data) )
{
ShowError("script:getelementofarray: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
script_pushnil(st);
st->state = END;
return false;// not a variable
@@ -5485,7 +5333,7 @@ BUILDIN(getelementofarray)
if( not_array_variable(*name) )
{
ShowError("script:getelementofarray: illegal scope\n");
- script_reportdata(data);
+ script->reportdata(data);
script_pushnil(st);
st->state = END;
return false;// not supported
@@ -5495,7 +5343,7 @@ BUILDIN(getelementofarray)
if( i < 0 || i >= SCRIPT_MAX_ARRAYSIZE )
{
ShowWarning("script:getelementofarray: index out of range (%d)\n", i);
- script_reportdata(data);
+ script->reportdata(data);
script_pushnil(st);
st->state = END;
return false;// out of range
@@ -5520,7 +5368,7 @@ BUILDIN(setlook)
type=script_getnum(st,2);
val=script_getnum(st,3);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -5537,7 +5385,7 @@ BUILDIN(changelook)
type=script_getnum(st,2);
val=script_getnum(st,3);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -5553,7 +5401,7 @@ BUILDIN(cutin)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -5575,7 +5423,7 @@ BUILDIN(viewpoint)
id=script_getnum(st,5);
color=script_getnum(st,6);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -5594,7 +5442,7 @@ BUILDIN(countitem)
struct item_data* id = NULL;
struct script_data* data;
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
if (!sd) {
script_pushint(st,0);
return true;
@@ -5641,7 +5489,7 @@ BUILDIN(countitem2)
struct item_data* id = NULL;
struct script_data* data;
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
if (!sd) {
script_pushint(st,0);
return true;
@@ -5704,7 +5552,7 @@ BUILDIN(checkweight)
struct map_session_data* sd;
struct script_data* data;
- if( ( sd = script_rid2sd(st) ) == NULL ){
+ if( ( sd = script->rid2sd(st) ) == NULL ){
return true;
}
nbargs = script_lastdata(st)+1;
@@ -5790,7 +5638,7 @@ BUILDIN(checkweight2)
int32 idx_it, idx_nb;
int nb_it, nb_nb; //array size
- TBL_PC *sd = script_rid2sd(st);
+ TBL_PC *sd = script->rid2sd(st);
nullpo_retr(1,sd);
data_it = script_getdata(st, 2);
@@ -5820,8 +5668,8 @@ BUILDIN(checkweight2)
script_pushint(st,0);
return false;// not supported
}
- nb_it = getarraysize(st, id_it, idx_it, 0, reference_getref(data_it));
- nb_nb = getarraysize(st, id_nb, idx_nb, 0, reference_getref(data_nb));
+ nb_it = script->getarraysize(st, id_it, idx_it, 0, reference_getref(data_it));
+ nb_nb = script->getarraysize(st, id_nb, idx_nb, 0, reference_getref(data_nb));
if(nb_it != nb_nb){
ShowError("Size mistmatch: nb_it=%d, nb_nb=%d\n",nb_it,nb_nb);
fail = 1;
@@ -5928,7 +5776,7 @@ BUILDIN(getitem)
if( script_hasdata(st,4) )
sd=map->id2sd(script_getnum(st,4)); // <Account ID>
else
- sd=script_rid2sd(st); // Attached player
+ sd=script->rid2sd(st); // Attached player
if( sd == NULL ) // no target
return true;
@@ -5968,7 +5816,7 @@ BUILDIN(getitem2)
if( script_hasdata(st,11) )
sd=map->id2sd(script_getnum(st,11)); // <Account ID>
else
- sd=script_rid2sd(st); // Attached player
+ sd=script->rid2sd(st); // Attached player
if( sd == NULL ) // no target
return true;
@@ -6064,7 +5912,7 @@ BUILDIN(rentitem)
data = script_getdata(st,2);
script->get_val(st,data);
- if( (sd = script_rid2sd(st)) == NULL )
+ if( (sd = script->rid2sd(st)) == NULL )
return true;
if( data_isstring(data) )
@@ -6121,7 +5969,7 @@ BUILDIN(getnameditem)
TBL_PC *sd, *tsd;
struct script_data *data;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (sd == NULL)
{ //Player not attached!
script_pushint(st,0);
@@ -6242,7 +6090,7 @@ BUILDIN(makeitem)
if(strcmp(mapname,"this")==0) {
TBL_PC *sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (!sd) return true; //Failed...
m=sd->bl.m;
} else
@@ -6270,7 +6118,7 @@ BUILDIN(makeitem)
/// Counts / deletes the current item given by idx.
/// Used by buildin_delitem_search
/// Relies on all input data being already fully valid.
-static void buildin_delitem_delete(struct map_session_data* sd, int idx, int* amount, bool delete_items)
+void buildin_delitem_delete(struct map_session_data* sd, int idx, int* amount, bool delete_items)
{
int delamount;
struct item* inv = &sd->status.inventory[idx];
@@ -6295,7 +6143,7 @@ static void buildin_delitem_delete(struct map_session_data* sd, int idx, int* am
/// Relies on all input data being already fully valid.
/// @param exact_match will also match item attributes and cards, not just name id
/// @return true when all items could be deleted, false when there were not enough items to delete
-static bool buildin_delitem_search(struct map_session_data* sd, struct item* it, bool exact_match)
+bool buildin_delitem_search(struct map_session_data* sd, struct item* it, bool exact_match)
{
bool delete_items = false;
int i, amount, important;
@@ -6358,7 +6206,7 @@ static bool buildin_delitem_search(struct map_session_data* sd, struct item* it,
}
// count / delete item
- buildin_delitem_delete(sd, i, &amount, delete_items);
+ script->buildin_delitem_delete(sd, i, &amount, delete_items);
}
// 2nd pass -- any matching item
@@ -6389,7 +6237,7 @@ static bool buildin_delitem_search(struct map_session_data* sd, struct item* it,
}
// count / delete item
- buildin_delitem_delete(sd, i, &amount, delete_items);
+ script->buildin_delitem_delete(sd, i, &amount, delete_items);
}
if( amount )
@@ -6432,7 +6280,7 @@ BUILDIN(delitem)
}
else
{
- sd = script_rid2sd(st);// attached player
+ sd = script->rid2sd(st);// attached player
if( sd == NULL )
return true;
}
@@ -6467,7 +6315,7 @@ BUILDIN(delitem)
if( it.amount <= 0 )
return true;// nothing to do
- if( buildin_delitem_search(sd, &it, false) )
+ if( script->buildin_delitem_search(sd, &it, false) )
{// success
return true;
}
@@ -6498,7 +6346,7 @@ BUILDIN(delitem2) {
}
else
{
- sd = script_rid2sd(st);// attached player
+ sd = script->rid2sd(st);// attached player
if( sd == NULL )
return true;
}
@@ -6540,7 +6388,7 @@ BUILDIN(delitem2) {
if( it.amount <= 0 )
return true;// nothing to do
- if( buildin_delitem_search(sd, &it, true) )
+ if( script->buildin_delitem_search(sd, &it, true) )
{// success
return true;
}
@@ -6557,7 +6405,7 @@ BUILDIN(delitem2) {
BUILDIN(enableitemuse)
{
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (sd)
st->npc_item_flag = sd->npc_item_flag = 1;
return true;
@@ -6566,7 +6414,7 @@ BUILDIN(enableitemuse)
BUILDIN(disableitemuse)
{
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (sd)
st->npc_item_flag = sd->npc_item_flag = 0;
return true;
@@ -6584,7 +6432,7 @@ BUILDIN(readparam) {
if( script_hasdata(st,3) )
sd=map->nick2sd(script_getstr(st,3));
else
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if(sd==NULL){
script_pushint(st,-1);
@@ -6613,7 +6461,7 @@ BUILDIN(getcharid) {
if( script_hasdata(st,3) )
sd=map->nick2sd(script_getstr(st,3));
else
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if(sd==NULL){
script_pushint(st,0); //return 0, according docs
@@ -6842,7 +6690,7 @@ BUILDIN(strcharinfo)
struct guild* g;
struct party_data* p;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (!sd) { //Avoid crashing....
script_pushconststr(st,"");
return true;
@@ -6931,10 +6779,6 @@ BUILDIN(strnpcinfo) {
return true;
}
-
-// aegis->athena slot position conversion table
-static unsigned int equip[] = {EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW,EQP_COSTUME_HEAD_LOW,EQP_COSTUME_HEAD_MID,EQP_COSTUME_HEAD_TOP,EQP_COSTUME_GARMENT};
-
/*==========================================
* GetEquipID(Pos); Pos: 1-10
*------------------------------------------*/
@@ -6944,19 +6788,19 @@ BUILDIN(getequipid)
TBL_PC* sd;
struct item_data* item;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
num = script_getnum(st,2) - 1;
- if( num < 0 || num >= ARRAYLENGTH(equip) )
+ if( num < 0 || num >= ARRAYLENGTH(script->equip) )
{
script_pushint(st,-1);
return true;
}
// get inventory position of item
- i = pc->checkequip(sd,equip[num]);
+ i = pc->checkequip(sd,script->equip[num]);
if( i < 0 )
{
script_pushint(st,-1);
@@ -6982,19 +6826,19 @@ BUILDIN(getequipname)
TBL_PC* sd;
struct item_data* item;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
num = script_getnum(st,2) - 1;
- if( num < 0 || num >= ARRAYLENGTH(equip) )
+ if( num < 0 || num >= ARRAYLENGTH(script->equip) )
{
script_pushconststr(st,"");
return true;
}
// get inventory position of item
- i = pc->checkequip(sd,equip[num]);
+ i = pc->checkequip(sd,script->equip[num]);
if( i < 0 )
{
script_pushconststr(st,"");
@@ -7018,7 +6862,7 @@ BUILDIN(getbrokenid)
int i,num,id=0,brokencounter=0;
TBL_PC *sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -7047,7 +6891,7 @@ BUILDIN(repair)
int repaircounter=0;
TBL_PC *sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -7076,7 +6920,7 @@ BUILDIN(repairall)
int i, repaircounter = 0;
TBL_PC *sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if(sd == NULL)
return true;
@@ -7108,12 +6952,12 @@ BUILDIN(getequipisequiped)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if(i >= 0)
script_pushint(st,1);
@@ -7135,12 +6979,12 @@ BUILDIN(getequipisenableref)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if( num > 0 && num <= ARRAYLENGTH(equip) )
- i = pc->checkequip(sd,equip[num-1]);
+ if( num > 0 && num <= ARRAYLENGTH(script->equip) )
+ i = pc->checkequip(sd,script->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
@@ -7161,12 +7005,12 @@ BUILDIN(getequipisidentify)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if(i >= 0)
script_pushint(st,sd->status.inventory[i].identify);
else
@@ -7187,12 +7031,12 @@ BUILDIN(getequiprefinerycnt)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if(i >= 0)
script_pushint(st,sd->status.inventory[i].refine);
else
@@ -7214,12 +7058,12 @@ BUILDIN(getequipweaponlv)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if(i >= 0 && sd->inventory_data[i])
script_pushint(st,sd->inventory_data[i]->wlv);
else
@@ -7239,12 +7083,12 @@ BUILDIN(getequippercentrefinery) {
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->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
@@ -7262,12 +7106,12 @@ BUILDIN(successrefitem)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if(i >= 0) {
ep=sd->status.inventory[i].equip;
@@ -7319,12 +7163,12 @@ BUILDIN(failedrefitem)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if(i >= 0) {
sd->status.inventory[i].refine = 0;
pc->unequipitem(sd,i,3); //recalculate bonus
@@ -7347,12 +7191,12 @@ BUILDIN(downrefitem)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i = pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i = pc->checkequip(sd,script->equip[num-1]);
if(i >= 0) {
ep = sd->status.inventory[i].equip;
@@ -7385,12 +7229,12 @@ BUILDIN(delequip)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if(i >= 0) {
pc->unequipitem(sd,i,3); //recalculate bonus
pc->delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT);
@@ -7408,7 +7252,7 @@ BUILDIN(statusup)
TBL_PC *sd;
type=script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -7426,7 +7270,7 @@ BUILDIN(statusup2)
type=script_getnum(st,2);
val=script_getnum(st,3);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -7452,7 +7296,7 @@ BUILDIN(bonus)
int val5 = 0;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true; // no player attached
@@ -7531,7 +7375,7 @@ BUILDIN(autobonus) {
TBL_PC* sd;
const char *bonus_script, *other_script = NULL;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true; // no player attached
@@ -7552,9 +7396,9 @@ BUILDIN(autobonus) {
if( pc->addautobonus(sd->autobonus,ARRAYLENGTH(sd->autobonus),bonus_script,rate,dur,atk_type,other_script,
sd->status.inventory[status->current_equip_item_index].equip,false)
) {
- script_add_autobonus(bonus_script);
+ script->add_autobonus(bonus_script);
if( other_script )
- script_add_autobonus(other_script);
+ script->add_autobonus(other_script);
}
return true;
@@ -7567,7 +7411,7 @@ BUILDIN(autobonus2) {
TBL_PC* sd;
const char *bonus_script, *other_script = NULL;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true; // no player attached
@@ -7588,9 +7432,9 @@ BUILDIN(autobonus2) {
if( pc->addautobonus(sd->autobonus2,ARRAYLENGTH(sd->autobonus2),bonus_script,rate,dur,atk_type,other_script,
sd->status.inventory[status->current_equip_item_index].equip,false)
) {
- script_add_autobonus(bonus_script);
+ script->add_autobonus(bonus_script);
if( other_script )
- script_add_autobonus(other_script);
+ script->add_autobonus(other_script);
}
return true;
@@ -7602,7 +7446,7 @@ BUILDIN(autobonus3) {
TBL_PC* sd;
const char *bonus_script, *other_script = NULL;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true; // no player attached
@@ -7622,9 +7466,9 @@ BUILDIN(autobonus3) {
if( pc->addautobonus(sd->autobonus3,ARRAYLENGTH(sd->autobonus3),bonus_script,rate,dur,atk_type,other_script,
sd->status.inventory[status->current_equip_item_index].equip,true)
) {
- script_add_autobonus(bonus_script);
+ script->add_autobonus(bonus_script);
if( other_script )
- script_add_autobonus(other_script);
+ script->add_autobonus(other_script);
}
return true;
@@ -7647,7 +7491,7 @@ BUILDIN(skill)
int flag = 1;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7676,7 +7520,7 @@ BUILDIN(addtoskill)
int flag = 2;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7700,7 +7544,7 @@ BUILDIN(guildskill)
TBL_PC* sd;
int i;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7721,7 +7565,7 @@ BUILDIN(getskilllv)
int id;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7770,7 +7614,7 @@ BUILDIN(getgmlevel)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7786,7 +7630,7 @@ BUILDIN(getgroupid)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (sd == NULL)
return false; // no player attached, report source
script_pushint(st, pc_get_group_id(sd));
@@ -7810,7 +7654,7 @@ BUILDIN(checkoption)
int option;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7831,7 +7675,7 @@ BUILDIN(checkoption1)
int opt1;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7852,7 +7696,7 @@ BUILDIN(checkoption2)
int opt2;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7878,7 +7722,7 @@ BUILDIN(setoption)
int flag = 1;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7911,7 +7755,7 @@ BUILDIN(checkcart)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7939,7 +7783,7 @@ BUILDIN(setcart)
int type = 1;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7959,7 +7803,7 @@ BUILDIN(checkfalcon)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -7981,7 +7825,7 @@ BUILDIN(setfalcon)
int flag = 1;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -8002,7 +7846,7 @@ BUILDIN(checkriding)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -8024,7 +7868,7 @@ BUILDIN(setriding)
int flag = 1;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -8043,7 +7887,7 @@ BUILDIN(checkwug)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -8063,7 +7907,7 @@ BUILDIN(checkmadogear)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -8085,7 +7929,7 @@ BUILDIN(setmadogear)
int flag = 1;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -8107,7 +7951,7 @@ BUILDIN(savepoint) {
const char* str;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached, report source
@@ -8226,7 +8070,7 @@ BUILDIN(gettimestr)
BUILDIN(openstorage) {
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -8238,7 +8082,7 @@ BUILDIN(guildopenstorage) {
TBL_PC* sd;
int ret;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -8257,7 +8101,7 @@ BUILDIN(itemskill) {
int lv;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL || sd->ud.skilltimer != INVALID_TIMER )
return true;
@@ -8283,7 +8127,7 @@ BUILDIN(produce)
int trigger;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -8299,7 +8143,7 @@ BUILDIN(cooking)
int trigger;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -8316,7 +8160,7 @@ BUILDIN(makepet)
int id,pet_id;
id=script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -8344,7 +8188,7 @@ BUILDIN(getexp)
int base=0,job=0;
double bonus;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -8371,7 +8215,7 @@ BUILDIN(guildgetexp)
TBL_PC* sd;
int exp;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -8431,7 +8275,7 @@ BUILDIN(monster)
if (script_hasdata(st, 8))
{
event = script_getstr(st, 8);
- check_event(st, event);
+ script->check_event(st, event);
}
if (script_hasdata(st, 9))
@@ -8540,7 +8384,7 @@ BUILDIN(areamonster)
if (script_hasdata(st,10)) {
event = script_getstr(st, 10);
- check_event(st, event);
+ script->check_event(st, event);
}
if (script_hasdata(st, 11)) {
@@ -8584,7 +8428,7 @@ BUILDIN(areamonster)
/*==========================================
* KillMonster subcheck, verify if mob to kill ain't got an even to handle, could be force kill by allflag
*------------------------------------------*/
-static int buildin_killmonster_sub_strip(struct block_list *bl,va_list ap)
+int buildin_killmonster_sub_strip(struct block_list *bl,va_list ap)
{ //same fix but with killmonster instead - stripping events from mobs.
TBL_MOB* md = (TBL_MOB*)bl;
char *event=va_arg(ap,char *);
@@ -8602,7 +8446,7 @@ static int buildin_killmonster_sub_strip(struct block_list *bl,va_list ap)
md->state.npc_killmonster = 0;
return 0;
}
-static int buildin_killmonster_sub(struct block_list *bl,va_list ap)
+int buildin_killmonster_sub(struct block_list *bl,va_list ap)
{
TBL_MOB* md = (TBL_MOB*)bl;
char *event=va_arg(ap,char *);
@@ -8625,7 +8469,7 @@ BUILDIN(killmonster) {
if(strcmp(event,"All")==0)
allflag = 1;
else
- check_event(st, event);
+ script->check_event(st, event);
if( (m=map->mapname2mapid(mapname))<0 )
return true;
@@ -8635,18 +8479,18 @@ BUILDIN(killmonster) {
if( script_hasdata(st,4) ) {
if ( script_getnum(st,4) == 1 ) {
- map->foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
+ map->foreachinmap(script->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->foreachinmap(script->buildin_killmonster_sub_strip, m, BL_MOB, event ,allflag);
map->freeblock_unlock();
return true;
}
-static int buildin_killmonsterall_sub_strip(struct block_list *bl,va_list ap)
+int buildin_killmonsterall_sub_strip(struct block_list *bl,va_list ap)
{ //Strips the event from the mob if it's killed the old method.
struct mob_data *md;
@@ -8657,7 +8501,7 @@ static int buildin_killmonsterall_sub_strip(struct block_list *bl,va_list ap)
status_kill(bl);
return 0;
}
-static int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
+int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
{
status_kill(bl);
return 0;
@@ -8675,12 +8519,12 @@ BUILDIN(killmonsterall) {
if( script_hasdata(st,3) ) {
if ( script_getnum(st,3) == 1 ) {
- map->foreachinmap(buildin_killmonsterall_sub,m,BL_MOB);
+ map->foreachinmap(script->buildin_killmonsterall_sub,m,BL_MOB);
return true;
}
}
- map->foreachinmap(buildin_killmonsterall_sub_strip,m,BL_MOB);
+ map->foreachinmap(script->buildin_killmonsterall_sub_strip,m,BL_MOB);
return true;
}
@@ -8712,7 +8556,7 @@ BUILDIN(clone) {
if( script_hasdata(st,10) )
duration=script_getnum(st,10);
- check_event(st, event);
+ script->check_event(st, event);
m = map->mapname2mapid(mapname);
if (m < 0) return true;
@@ -8740,12 +8584,12 @@ BUILDIN(doevent)
const char* event = script_getstr(st,2);
struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) == NULL )
+ if( ( sd = script->rid2sd(st) ) == NULL )
{
return true;
}
- check_event(st, event);
+ script->check_event(st, event);
npc->event(sd, event, 0);
return true;
}
@@ -8754,7 +8598,7 @@ BUILDIN(doevent)
BUILDIN(donpcevent)
{
const char* event = script_getstr(st,2);
- check_event(st, event);
+ script->check_event(st, event);
if( !npc->event_do(event) ) {
struct npc_data * nd = map->id2nd(st->oid);
ShowDebug("NPCEvent '%s' not found! (source: %s)\n",event,nd?nd->name:"Unknown");
@@ -8772,7 +8616,7 @@ BUILDIN(cmdothernpc) // Added by RoVeRT
const char* command = script_getstr(st,3);
char event[EVENT_NAME_LENGTH];
snprintf(event, sizeof(event), "%s::OnCommand%s", npc_name, command);
- check_event(st, event);
+ script->check_event(st, event);
npc->event_do(event);
return true;
}
@@ -8785,8 +8629,8 @@ BUILDIN(addtimer)
const char* event = script_getstr(st, 3);
TBL_PC* sd;
- check_event(st, event);
- sd = script_rid2sd(st);
+ script->check_event(st, event);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -8801,11 +8645,11 @@ BUILDIN(deltimer)
TBL_PC* sd;
event=script_getstr(st, 2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- check_event(st, event);
+ script->check_event(st, event);
pc->deleventtimer(sd,event);
return true;
}
@@ -8819,11 +8663,11 @@ BUILDIN(addtimercount)
event=script_getstr(st, 2);
tick=script_getnum(st,3);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
- check_event(st, event);
+ script->check_event(st, event);
pc->addeventtimercount(sd,event,tick);
return true;
}
@@ -8862,7 +8706,7 @@ BUILDIN(initnpctimer)
return true;
if( flag ) //Attach
{
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
if( sd == NULL )
return true;
nd->u.scr.rid = sd->bl.id;
@@ -8907,7 +8751,7 @@ BUILDIN(startnpctimer)
return true;
if( flag ) //Attach
{
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
if( sd == NULL )
return true;
nd->u.scr.rid = sd->bl.id;
@@ -9034,7 +8878,7 @@ BUILDIN(attachnpctimer) {
if( script_hasdata(st,2) )
sd = map->nick2sd(script_getstr(st,2));
else
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( !sd )
{
@@ -9098,7 +8942,7 @@ BUILDIN(announce) {
if( flag&(BC_TARGET_MASK|BC_SOURCE_MASK) ) {
// Broadcast source or broadcast region defined
send_target target;
- struct block_list *bl = (flag&BC_NPC) ? 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&BC_NPC) ? map->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;
@@ -9123,7 +8967,7 @@ BUILDIN(announce) {
}
/*==========================================
*------------------------------------------*/
-static int buildin_announce_sub(struct block_list *bl, va_list ap)
+int buildin_announce_sub(struct block_list *bl, va_list ap)
{
char *mes = va_arg(ap, char *);
int len = va_arg(ap, int);
@@ -9148,7 +8992,7 @@ BUILDIN(itemeffect) {
struct script_data *data;
struct item_data *item_data;
- nullpo_retr( 1, ( sd = script_rid2sd( st ) ) );
+ nullpo_retr( 1, ( sd = script->rid2sd( st ) ) );
nullpo_retr( 1, ( nd = (TBL_NPC *)map->id2bl( sd->npc_id ) ) );
data = script_getdata( st, 2 );
@@ -9192,7 +9036,7 @@ BUILDIN(mapannounce) {
if ((m = map->mapname2mapid(mapname)) < 0)
return true;
- map->foreachinmap(buildin_announce_sub, m, BL_PC,
+ map->foreachinmap(script->buildin_announce_sub, m, BL_PC,
mes, strlen(mes)+1, flag&BC_COLOR_MASK, fontColor, fontType, fontSize, fontAlign, fontY);
return true;
}
@@ -9216,7 +9060,7 @@ BUILDIN(areaannounce) {
if ((m = map->mapname2mapid(mapname)) < 0)
return true;
- map->foreachinarea(buildin_announce_sub, m, x0, y0, x1, y1, BL_PC,
+ map->foreachinarea(script->buildin_announce_sub, m, x0, y0, x1, y1, BL_PC,
mes, strlen(mes)+1, flag&BC_COLOR_MASK, fontColor, fontType, fontSize, fontAlign, fontY);
return true;
}
@@ -9235,7 +9079,7 @@ BUILDIN(getusers) {
if(flag&0x8) {
// npc
bl = map->id2bl(st->oid);
- } else if((sd = script_rid2sd(st))!=NULL) {
+ } else if((sd = script->rid2sd(st))!=NULL) {
// pc
bl = &sd->bl;
}
@@ -9265,7 +9109,7 @@ BUILDIN(getusersname)
int /*disp_num=1,*/ group_level = 0;
struct s_mapiterator* iter;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (!sd) return true;
group_level = pc->get_group_level(sd);
@@ -9329,7 +9173,7 @@ BUILDIN(getmapusers) {
}
/*==========================================
*------------------------------------------*/
-static int buildin_getareausers_sub(struct block_list *bl,va_list ap)
+int buildin_getareausers_sub(struct block_list *bl,va_list ap)
{
int *users=va_arg(ap,int *);
(*users)++;
@@ -9348,7 +9192,7 @@ BUILDIN(getareausers)
script_pushint(st,-1);
return true;
}
- map->foreachinarea(buildin_getareausers_sub,
+ map->foreachinarea(script->buildin_getareausers_sub,
m,x0,y0,x1,y1,BL_PC,&users);
script_pushint(st,users);
return true;
@@ -9356,7 +9200,7 @@ BUILDIN(getareausers)
/*==========================================
*------------------------------------------*/
-static int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
+int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
{
int item=va_arg(ap,int);
int *amount=va_arg(ap,int *);
@@ -9395,7 +9239,7 @@ BUILDIN(getareadropitem)
script_pushint(st,-1);
return true;
}
- map->foreachinarea(buildin_getareadropitem_sub,
+ map->foreachinarea(script->buildin_getareadropitem_sub,
m,x0,y0,x1,y1,BL_ITEM,item,&amount);
script_pushint(st,amount);
return true;
@@ -9625,7 +9469,7 @@ BUILDIN(getscrate) {
BUILDIN(getstatus)
{
int id, type;
- struct map_session_data* sd = script_rid2sd(st);
+ struct map_session_data* sd = script->rid2sd(st);
if( sd == NULL )
{// no player attached
@@ -9687,7 +9531,7 @@ BUILDIN(catchpet)
TBL_PC *sd;
pet_id= script_getnum(st,2);
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if( sd == NULL )
return true;
@@ -9702,7 +9546,7 @@ BUILDIN(homunculus_evolution)
{
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if( sd == NULL )
return true;
@@ -9723,7 +9567,7 @@ BUILDIN(homunculus_mutate) {
enum homun_type m_class, m_id;
TBL_PC *sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL || sd->hd == NULL )
return true;
@@ -9748,7 +9592,7 @@ BUILDIN(homunculus_mutate) {
BUILDIN(homunculus_shuffle) {
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if( sd == NULL )
return true;
@@ -9767,7 +9611,7 @@ BUILDIN(homunculus_shuffle) {
*------------------------------------------*/
BUILDIN(checkhomcall)
{
- TBL_PC *sd = script_rid2sd(st);
+ TBL_PC *sd = script->rid2sd(st);
TBL_HOM *hd;
if( sd == NULL )
@@ -9791,7 +9635,7 @@ BUILDIN(eaclass)
class_ = script_getnum(st,2);
else {
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (!sd) {
script_pushint(st,-1);
return true;
@@ -9810,7 +9654,7 @@ BUILDIN(roclass)
sex = script_getnum(st,3);
else {
TBL_PC *sd;
- if (st->rid && (sd=script_rid2sd(st)))
+ if (st->rid && (sd=script->rid2sd(st)))
sex = sd->status.sex;
else
sex = 1; //Just use male when not found.
@@ -9825,7 +9669,7 @@ BUILDIN(roclass)
BUILDIN(birthpet)
{
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if( sd == NULL )
return true;
@@ -9852,7 +9696,7 @@ BUILDIN(resetlvl)
int type=script_getnum(st,2);
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if( sd == NULL )
return true;
@@ -9865,7 +9709,7 @@ BUILDIN(resetlvl)
BUILDIN(resetstatus)
{
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
pc->resetstate(sd);
return true;
}
@@ -9876,7 +9720,7 @@ BUILDIN(resetstatus)
BUILDIN(resetskill)
{
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
pc->resetskill(sd,1);
return true;
}
@@ -9887,7 +9731,7 @@ BUILDIN(resetskill)
BUILDIN(skillpointcount)
{
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
script_pushint(st,sd->status.skill_point + pc->resetskill(sd,2));
return true;
}
@@ -9902,7 +9746,7 @@ BUILDIN(changebase) {
if( script_hasdata(st,3) )
sd=map->id2sd(script_getnum(st,3));
else
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if(sd == NULL)
return true;
@@ -9936,7 +9780,7 @@ BUILDIN(changesex)
{
int i;
TBL_PC *sd = NULL;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
pc->resetskill(sd,4);
// to avoid any problem with equipment and invalid sex, equipment is unequiped.
@@ -10180,7 +10024,7 @@ BUILDIN(warpwaitingpc) {
/// @param st Script state to detach the character from.
void script_detach_rid(struct script_state* st) {
if(st->rid) {
- script_detach_state(st, false);
+ script->detach_state(st, false);
st->rid = 0;
}
}
@@ -10192,7 +10036,7 @@ BUILDIN(attachrid) {
int rid = script_getnum(st,2);
if (map->id2sd(rid) != NULL) {
- script_detach_rid(st);
+ script->detach_rid(st);
st->rid = rid;
script->attach_state(st);
@@ -10206,7 +10050,7 @@ BUILDIN(attachrid) {
*------------------------------------------*/
BUILDIN(detachrid)
{
- script_detach_rid(st);
+ script->detach_rid(st);
return true;
}
/*==========================================
@@ -10314,7 +10158,7 @@ BUILDIN(getmapflag)
return true;
}
/* pvp timer handling */
-static int script_mapflag_pvp_sub(struct block_list *bl,va_list ap) {
+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 = timer->add(timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0);
@@ -10362,7 +10206,7 @@ BUILDIN(setmapflag) {
case MF_PVP:
maplist[m].flag.pvp = 1;
if( !battle_config.pk_mode ) {
- map->foreachinmap(script_mapflag_pvp_sub,m,BL_PC);
+ map->foreachinmap(script->mapflag_pvp_sub,m,BL_PC);
}
break;
case MF_PVP_NOPARTY: maplist[m].flag.pvp_noparty = 1; break;
@@ -10556,7 +10400,7 @@ BUILDIN(pvpon) {
return true;
}
-static int buildin_pvpoff_sub(struct block_list *bl,va_list ap)
+int buildin_pvpoff_sub(struct block_list *bl,va_list ap)
{
TBL_PC* sd = (TBL_PC*)bl;
clif->pvpset(sd, 0, 0, 2);
@@ -10587,7 +10431,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);
+ map->foreachinmap(script->buildin_pvpoff_sub, m, BL_PC);
return true;
}
@@ -10648,7 +10492,7 @@ BUILDIN(emotion) {
if( script_hasdata(st,4) )
sd = map->nick2sd(script_getstr(st,4));
else
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (sd)
clif->emotion(&sd->bl,type);
} else if( script_hasdata(st,4) ) {
@@ -10660,7 +10504,7 @@ BUILDIN(emotion) {
return true;
}
-static int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list ap)
+int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list ap)
{
int16 m=va_arg(ap,int);
int g_id=va_arg(ap,int);
@@ -10677,7 +10521,7 @@ static int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list
return 1;
}
-static int buildin_maprespawnguildid_sub_mob(struct block_list *bl,va_list ap)
+int buildin_maprespawnguildid_sub_mob(struct block_list *bl,va_list ap)
{
struct mob_data *md=(struct mob_data *)bl;
@@ -10698,9 +10542,9 @@ BUILDIN(maprespawnguildid) {
return true;
//Catch ALL players (in case some are 'between maps' on execution time)
- map->map_foreachpc(buildin_maprespawnguildid_sub_pc,m,g_id,flag);
+ map->map_foreachpc(script->buildin_maprespawnguildid_sub_pc,m,g_id,flag);
if (flag&4) //Remove script mobs.
- map->foreachinmap(buildin_maprespawnguildid_sub_mob,m,BL_MOB);
+ map->foreachinmap(script->buildin_maprespawnguildid_sub_mob,m,BL_MOB);
return true;
}
@@ -10857,7 +10701,7 @@ BUILDIN(requestguildinfo)
if( script_hasdata(st,3) ){
event=script_getstr(st,3);
- check_event(st, event);
+ script->check_event(st, event);
}
if(guild_id>0)
@@ -10874,9 +10718,9 @@ BUILDIN(getequipcardcnt)
int count;
num=script_getnum(st,2);
- sd=script_rid2sd(st);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ sd=script->rid2sd(st);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if (i < 0 || !sd->inventory_data[i]) {
script_pushint(st,0);
@@ -10904,11 +10748,11 @@ BUILDIN(getequipcardcnt)
BUILDIN(successremovecards) {
int i=-1,j,c,cardflag=0;
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
int num = script_getnum(st,2);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if (i < 0 || !sd->inventory_data[i]) {
return true;
@@ -10967,12 +10811,12 @@ BUILDIN(successremovecards) {
BUILDIN(failedremovecards) {
int i=-1,j,c,cardflag=0;
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
int num = script_getnum(st,2);
int typefail = script_getnum(st,3);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if (i < 0 || !sd->inventory_data[i])
return true;
@@ -11084,14 +10928,14 @@ BUILDIN(mapwarp) {
}
break;
default:
- map->foreachinmap(buildin_areawarp_sub,m,BL_PC,index,x,y,0,0);
+ map->foreachinmap(script->buildin_areawarp_sub,m,BL_PC,index,x,y,0,0);
break;
}
return true;
}
-static int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
+int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
{
char *event=va_arg(ap,char *);
struct mob_data *md = ((struct mob_data *)bl);
@@ -11110,10 +10954,10 @@ BUILDIN(mobcount) {
if( strcmp(event, "all") == 0 )
event = NULL;
else
- check_event(st, event);
+ script->check_event(st, event);
if( strcmp(mapname, "this") == 0 ) {
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
if( sd )
m = sd->bl.m;
else {
@@ -11130,14 +10974,14 @@ BUILDIN(mobcount) {
return true;
}
- script_pushint(st,map->foreachinmap(buildin_mobcount_sub, m, BL_MOB, event));
+ script_pushint(st,map->foreachinmap(script->buildin_mobcount_sub, m, BL_MOB, event));
return true;
}
BUILDIN(marriage) {
const char *partner=script_getstr(st,2);
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
TBL_PC *p_sd=map->nick2sd(partner);
if(sd==NULL || p_sd==NULL || pc->marriage(sd,p_sd) < 0){
@@ -11148,7 +10992,7 @@ BUILDIN(marriage) {
return true;
}
BUILDIN(wedding_effect) {
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
struct block_list *bl;
if(sd==NULL) {
@@ -11160,7 +11004,7 @@ BUILDIN(wedding_effect) {
}
BUILDIN(divorce)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd==NULL || pc->divorce(sd) < 0){
script_pushint(st,0);
return true;
@@ -11170,7 +11014,7 @@ BUILDIN(divorce)
}
BUILDIN(ispartneron) {
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd==NULL || !pc->ismarried(sd) ||
map->charid2sd(sd->status.partner_id) == NULL) {
@@ -11184,7 +11028,7 @@ BUILDIN(ispartneron) {
BUILDIN(getpartnerid)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if (sd == NULL) {
script_pushint(st,0);
return true;
@@ -11196,7 +11040,7 @@ BUILDIN(getpartnerid)
BUILDIN(getchildid)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if (sd == NULL) {
script_pushint(st,0);
return true;
@@ -11208,7 +11052,7 @@ BUILDIN(getchildid)
BUILDIN(getmotherid)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if (sd == NULL) {
script_pushint(st,0);
return true;
@@ -11220,7 +11064,7 @@ BUILDIN(getmotherid)
BUILDIN(getfatherid)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if (sd == NULL) {
script_pushint(st,0);
return true;
@@ -11235,7 +11079,7 @@ BUILDIN(warppartner)
int x,y;
unsigned short mapindex;
const char *str;
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
TBL_PC *p_sd=NULL;
if(sd==NULL || !pc->ismarried(sd) ||
@@ -11323,12 +11167,12 @@ BUILDIN(guardian) {
has_index = true;
} else {
ShowError("script:guardian: invalid data type for argument #6 (from 1)\n");
- script_reportdata(data);
+ script->reportdata(data);
return false;
}
}
- check_event(st, evt);
+ script->check_event(st, evt);
script_pushint(st, mob->spawn_guardian(mapname,x,y,str,class_,evt,guardian,has_index));
return true;
@@ -11554,9 +11398,9 @@ BUILDIN(getequipcardid)
num=script_getnum(st,2);
slot=script_getnum(st,3);
- sd=script_rid2sd(st);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc->checkequip(sd,equip[num-1]);
+ sd=script->rid2sd(st);
+ if (num > 0 && num <= ARRAYLENGTH(script->equip))
+ i=pc->checkequip(sd,script->equip[num-1]);
if(i >= 0 && slot>=0 && slot<4)
script_pushint(st,sd->status.inventory[i].card[slot]);
else
@@ -11572,7 +11416,7 @@ BUILDIN(petskillbonus)
{
struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd==NULL || sd->pd==NULL)
return true;
@@ -11609,7 +11453,7 @@ BUILDIN(petloot)
{
int max;
struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd==NULL || sd->pd==NULL)
return true;
@@ -11647,7 +11491,7 @@ BUILDIN(petloot)
*------------------------------------------*/
BUILDIN(getinventorylist)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
char card_var[NAME_LENGTH];
int i,j=0,k;
@@ -11675,7 +11519,7 @@ BUILDIN(getinventorylist)
BUILDIN(getskilllist)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
int i,j=0;
if(!sd) return true;
for(i=0;i<MAX_SKILL;i++){
@@ -11692,7 +11536,7 @@ BUILDIN(getskilllist)
BUILDIN(clearitem)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
int i;
if(sd==NULL) return true;
for (i=0; i<MAX_INVENTORY; i++) {
@@ -11709,7 +11553,7 @@ BUILDIN(clearitem)
BUILDIN(disguise)
{
int id;
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
if (sd == NULL) return true;
id = script_getnum(st,2);
@@ -11728,7 +11572,7 @@ BUILDIN(disguise)
*------------------------------------------*/
BUILDIN(undisguise)
{
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
if (sd == NULL) return true;
if (sd->disguise != -1) {
@@ -11769,7 +11613,7 @@ BUILDIN(misceffect)
if (bl)
clif->specialeffect(bl,type,AREA);
} else{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd)
clif->specialeffect(&sd->bl,type,AREA);
}
@@ -11783,7 +11627,7 @@ BUILDIN(playBGM)
const char* name;
struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) != NULL )
+ if( ( sd = script->rid2sd(st) ) != NULL )
{
name = script_getstr(st,2);
@@ -11793,7 +11637,7 @@ BUILDIN(playBGM)
return true;
}
-static int playBGM_sub(struct block_list* bl,va_list ap)
+int playBGM_sub(struct block_list* bl,va_list ap)
{
const char* name = va_arg(ap,const char*);
@@ -11802,7 +11646,7 @@ static int playBGM_sub(struct block_list* bl,va_list ap)
return 0;
}
-static int playBGM_foreachpc_sub(struct map_session_data* sd, va_list args)
+int playBGM_foreachpc_sub(struct map_session_data* sd, va_list args)
{
const char* name = va_arg(args, const char*);
@@ -11832,7 +11676,7 @@ BUILDIN(playBGMall) {
return true;
}
- map->foreachinarea(playBGM_sub, m, x0, y0, x1, y1, BL_PC, name);
+ map->foreachinarea(script->playBGM_sub, m, x0, y0, x1, y1, BL_PC, name);
} else if( script_hasdata(st,3) ) {
// entire map
const char* mapname = script_getstr(st,3);
@@ -11843,10 +11687,10 @@ BUILDIN(playBGMall) {
return true;
}
- map->foreachinmap(playBGM_sub, m, BL_PC, name);
+ map->foreachinmap(script->playBGM_sub, m, BL_PC, name);
} else {
// entire server
- map->map_foreachpc(&playBGM_foreachpc_sub, name);
+ map->map_foreachpc(script->playBGM_foreachpc_sub, name);
}
return true;
@@ -11857,7 +11701,7 @@ BUILDIN(playBGMall) {
*------------------------------------------*/
BUILDIN(soundeffect)
{
- TBL_PC* sd = script_rid2sd(st);
+ TBL_PC* sd = script->rid2sd(st);
const char* name = script_getstr(st,2);
int type = script_getnum(st,3);
@@ -11887,7 +11731,7 @@ 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) : map->id2bl(st->oid);
if (!bl)
return true;
@@ -11908,7 +11752,7 @@ BUILDIN(soundeffectall) {
return true;
}
- map->foreachinmap(soundeffect_sub, m, BL_PC, name, type);
+ map->foreachinmap(script->soundeffect_sub, m, BL_PC, name, type);
} else if(script_hasdata(st,8)) { // specified part of map
const char *mapname = script_getstr(st,4);
int x0 = script_getnum(st,5);
@@ -11922,7 +11766,7 @@ BUILDIN(soundeffectall) {
return true;
}
- map->foreachinarea(soundeffect_sub, m, x0, y0, x1, y1, BL_PC, name, type);
+ map->foreachinarea(script->soundeffect_sub, m, x0, y0, x1, y1, BL_PC, name, type);
} else {
ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
}
@@ -11936,7 +11780,7 @@ BUILDIN(soundeffectall) {
BUILDIN(petrecovery)
{
struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd==NULL || sd->pd==NULL)
return true;
@@ -11963,7 +11807,7 @@ BUILDIN(petrecovery)
BUILDIN(petheal)
{
struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd==NULL || sd->pd==NULL)
return true;
@@ -12005,7 +11849,7 @@ BUILDIN(petheal)
BUILDIN(petskillattack)
{
struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd==NULL || sd->pd==NULL)
return true;
@@ -12031,7 +11875,7 @@ BUILDIN(petskillattack)
BUILDIN(petskillattack2)
{
struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd==NULL || sd->pd==NULL)
return true;
@@ -12057,7 +11901,7 @@ BUILDIN(petskillattack2)
BUILDIN(petskillsupport)
{
struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd==NULL || sd->pd==NULL)
return true;
@@ -12101,7 +11945,7 @@ BUILDIN(skilleffect)
uint16 skill_id=( script_isstring(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) );
uint16 skill_lv=script_getnum(st,3);
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
clif->skill_nodamage(&sd->bl,&sd->bl,skill_id,skill_lv,1);
@@ -12147,7 +11991,7 @@ BUILDIN(specialeffect) {
else
{
if (target == SELF) {
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if (sd)
clif->specialeffect_single(bl,type,sd->fd);
} else {
@@ -12159,7 +12003,7 @@ BUILDIN(specialeffect) {
}
BUILDIN(specialeffect2) {
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
int type = script_getnum(st,2);
enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA;
@@ -12177,7 +12021,7 @@ BUILDIN(specialeffect2) {
*------------------------------------------*/
BUILDIN(nude)
{
- TBL_PC *sd = script_rid2sd(st);
+ TBL_PC *sd = script->rid2sd(st);
int i, calcflag = 0;
if( sd == NULL )
@@ -12209,7 +12053,7 @@ BUILDIN(atcommand) {
cmd = script_getstr(st,2);
if (st->rid) {
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
fd = sd->fd;
} else { //Use a dummy character.
sd = dummy_sd = pc->get_dummy_sd();
@@ -12225,7 +12069,7 @@ BUILDIN(atcommand) {
if (!atcommand->parse(fd, sd, cmd, 0)) {
ShowWarning("script: buildin_atcommand: failed to execute command '%s'\n", cmd);
- script_reportsrc(st);
+ script->reportsrc(st);
ret = false;
}
if (dummy_sd) aFree(dummy_sd);
@@ -12237,7 +12081,7 @@ BUILDIN(atcommand) {
*------------------------------------------*/
BUILDIN(dispbottom)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
const char *message;
message=script_getstr(st,2);
if(sd)
@@ -12273,7 +12117,7 @@ BUILDIN(recovery)
*------------------------------------------*/
BUILDIN(getpetinfo)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
TBL_PET *pd;
int type=script_getnum(st,2);
@@ -12307,7 +12151,7 @@ BUILDIN(getpetinfo)
*------------------------------------------*/
BUILDIN(gethominfo)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
TBL_HOM *hd;
int type=script_getnum(st,2);
@@ -12354,7 +12198,7 @@ BUILDIN(getmercinfo) {
return false;
}
} else {
- if( ( sd = script_rid2sd(st) ) == NULL ) {
+ if( ( sd = script->rid2sd(st) ) == NULL ) {
script_pushnil(st);
return true;
}
@@ -12393,7 +12237,7 @@ BUILDIN(getmercinfo) {
*------------------------------------------*/
BUILDIN(checkequipedcard)
{
- TBL_PC *sd=script_rid2sd(st);
+ TBL_PC *sd=script->rid2sd(st);
if(sd){
int n,i,c=0;
@@ -12550,7 +12394,7 @@ BUILDIN(getlook)
{
int type,val;
TBL_PC *sd;
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
type=script_getnum(st,2);
val=-1;
@@ -12579,7 +12423,7 @@ BUILDIN(getsavepoint)
TBL_PC* sd;
int type;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (sd == NULL) {
script_pushint(st,0);
return true;
@@ -12656,7 +12500,7 @@ BUILDIN(getmapxy)
if( script_hasdata(st,6) )
sd=map->nick2sd(script_getstr(st,6));
else
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (sd)
bl = &sd->bl;
@@ -12675,7 +12519,7 @@ BUILDIN(getmapxy)
if(script_hasdata(st,6))
sd=map->nick2sd(script_getstr(st,6));
else
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (sd && sd->pd)
bl = &sd->pd->bl;
@@ -12686,7 +12530,7 @@ BUILDIN(getmapxy)
if(script_hasdata(st,6))
sd=map->nick2sd(script_getstr(st,6));
else
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (sd && sd->hd)
bl = &sd->hd->bl;
@@ -12695,7 +12539,7 @@ BUILDIN(getmapxy)
if(script_hasdata(st,6))
sd=map->nick2sd(script_getstr(st,6));
else
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (sd && sd->md)
bl = &sd->md->bl;
@@ -12704,7 +12548,7 @@ BUILDIN(getmapxy)
if(script_hasdata(st,6))
sd=map->nick2sd(script_getstr(st,6));
else
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (sd && sd->ed)
bl = &sd->ed->bl;
@@ -12729,10 +12573,10 @@ BUILDIN(getmapxy)
prefix=*name;
if(not_server_variable(prefix))
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
else
sd=NULL;
- set_reg(st,sd,num,name,(void*)mapname,script_getref(st,2));
+ script->set_reg(st,sd,num,name,(void*)mapname,script_getref(st,2));
//Set MapX
num=st->stack->stack_data[st->start+3].u.num;
@@ -12740,10 +12584,10 @@ BUILDIN(getmapxy)
prefix=*name;
if(not_server_variable(prefix))
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
else
sd=NULL;
- set_reg(st,sd,num,name,(void*)__64BPTRSIZE(x),script_getref(st,3));
+ script->set_reg(st,sd,num,name,(void*)__64BPTRSIZE(x),script_getref(st,3));
//Set MapY
num=st->stack->stack_data[st->start+4].u.num;
@@ -12751,10 +12595,10 @@ BUILDIN(getmapxy)
prefix=*name;
if(not_server_variable(prefix))
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
else
sd=NULL;
- set_reg(st,sd,num,name,(void*)__64BPTRSIZE(y),script_getref(st,4));
+ script->set_reg(st,sd,num,name,(void*)__64BPTRSIZE(y),script_getref(st,4));
//Return Success value
script_pushint(st,0);
@@ -12769,7 +12613,7 @@ BUILDIN(logmes)
const char *str;
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return false;
@@ -12786,7 +12630,7 @@ BUILDIN(summon)
struct mob_data *md;
int tick = timer->gettick();
- sd=script_rid2sd(st);
+ sd=script->rid2sd(st);
if (!sd) return true;
str =script_getstr(st,2);
@@ -12795,7 +12639,7 @@ BUILDIN(summon)
timeout=script_getnum(st,4);
if( script_hasdata(st,5) ){
event=script_getstr(st,5);
- check_event(st, event);
+ script->check_event(st, event);
}
clif->skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
@@ -12837,14 +12681,14 @@ BUILDIN(isequippedcnt)
int i, j, k, id = 1;
int ret = 0;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
script_pushint(st,0);
return true;
}
for (i=0; id!=0; i++) {
- FETCH (i+2, id) else id = 0;
+ script_fetch(st,i+2, id) else id = 0;
if (id <= 0)
continue;
@@ -12892,7 +12736,7 @@ BUILDIN(isequipped)
//Original hash to reverse it when full check fails.
unsigned int setitem_hash = 0, setitem_hash2 = 0;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
script_pushint(st,0);
@@ -12902,7 +12746,7 @@ BUILDIN(isequipped)
setitem_hash = sd->bonus.setitem_hash;
setitem_hash2 = sd->bonus.setitem_hash2;
for (i=0; id!=0; i++) {
- FETCH (i+2, id) else id = 0;
+ script_fetch(st,i+2, id) else id = 0;
if (id <= 0)
continue;
flag = 0;
@@ -12973,10 +12817,10 @@ BUILDIN(cardscnt) {
int ret = 0;
int index;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
for (i=0; id!=0; i++) {
- FETCH (i+2, id) else id = 0;
+ script_fetch(st,i+2, id) else id = 0;
if (id <= 0)
continue;
@@ -13009,7 +12853,7 @@ BUILDIN(cardscnt) {
*-------------------------------------------------------*/
BUILDIN(getrefine) {
TBL_PC *sd;
- if ((sd = script_rid2sd(st))!= NULL)
+ if ((sd = script->rid2sd(st))!= NULL)
script_pushint(st,sd->status.inventory[status->current_equip_item_index].refine);
else
script_pushint(st,0);
@@ -13038,10 +12882,10 @@ BUILDIN(unequip)
TBL_PC *sd;
num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd != NULL && num >= 1 && num <= ARRAYLENGTH(equip) )
+ sd = script->rid2sd(st);
+ if( sd != NULL && num >= 1 && num <= ARRAYLENGTH(script->equip) )
{
- i = pc->checkequip(sd,equip[num-1]);
+ i = pc->checkequip(sd,script->equip[num-1]);
if (i >= 0)
pc->unequipitem(sd,i,1|2);
}
@@ -13054,7 +12898,7 @@ BUILDIN(equip)
TBL_PC *sd;
struct item_data *item_data;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
nameid=script_getnum(st,2);
if((item_data = itemdb->exists(nameid)) == NULL)
@@ -13343,7 +13187,7 @@ BUILDIN(explode)
if( !data_isreference(data) )
{
ShowError("script:explode: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not a variable
}
@@ -13355,7 +13199,7 @@ BUILDIN(explode)
if( not_array_variable(*name) )
{
ShowError("script:explode: illegal scope\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not supported
}
@@ -13363,14 +13207,14 @@ BUILDIN(explode)
if( !is_string_variable(name) )
{
ShowError("script:explode: not string array\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// data type mismatch
}
if( not_server_variable(*name) )
{
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached
}
@@ -13378,7 +13222,7 @@ BUILDIN(explode)
while(str[i] != '\0') {
if(str[i] == delimiter && start < SCRIPT_MAX_ARRAYSIZE-1) { //break at delimiter but ignore after reaching last array index
temp[j] = '\0';
- set_reg(st, sd, reference_uid(id, start++), name, (void*)temp, reference_getref(data));
+ script->set_reg(st, sd, reference_uid(id, start++), name, (void*)temp, reference_getref(data));
j = 0;
++i;
} else {
@@ -13387,7 +13231,7 @@ BUILDIN(explode)
}
//set last string
temp[j] = '\0';
- set_reg(st, sd, reference_uid(id, start), name, (void*)temp, reference_getref(data));
+ script->set_reg(st, sd, reference_uid(id, start), name, (void*)temp, reference_getref(data));
aFree(temp);
return true;
@@ -13412,7 +13256,7 @@ BUILDIN(implode)
if( !data_isreference(data) )
{
ShowError("script:implode: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not a variable
}
@@ -13423,7 +13267,7 @@ BUILDIN(implode)
if( not_array_variable(*name) )
{
ShowError("script:implode: illegal scope\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not supported
}
@@ -13431,20 +13275,20 @@ BUILDIN(implode)
if( !is_string_variable(name) )
{
ShowError("script:implode: not string array\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// data type mismatch
}
if( not_server_variable(*name) )
{
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached
}
//count chars
- array_size = getarraysize(st, id, reference_getindex(data), is_string_variable(name), reference_getref(data)) - 1;
+ array_size = script->getarraysize(st, id, reference_getindex(data), is_string_variable(name), reference_getref(data)) - 1;
if(array_size == -1) //empty array check (AmsTaff)
{
@@ -13553,7 +13397,7 @@ BUILDIN(sprintf)
}
if(*p=='n'){ // %n
ShowWarning("buildin_sprintf: Format %%n not supported! Skipping...\n");
- script_reportsrc(st);
+ script->reportsrc(st);
q+=2;
continue;
}
@@ -13612,7 +13456,7 @@ BUILDIN(sprintf)
// Passed more, than needed
if(arg<argc){
ShowWarning("buildin_sprintf: Unused arguments passed.\n");
- script_reportsrc(st);
+ script->reportsrc(st);
}
script_pushstrcopy(st, StrBuf->Value(&final_buf));
@@ -13687,7 +13531,7 @@ BUILDIN(sscanf){
return false;
}
buf_p = reference_getname(data);
- if(not_server_variable(*buf_p) && (sd = script_rid2sd(st))==NULL){
+ if(not_server_variable(*buf_p) && (sd = script->rid2sd(st))==NULL){
script_pushint(st, -1);
if(buf) aFree(buf);
if(ref_str) aFree(ref_str);
@@ -13702,12 +13546,12 @@ BUILDIN(sscanf){
if(sscanf(str, buf, ref_str)==0){
break;
}
- set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)(ref_str), reference_getref(data));
+ script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)(ref_str), reference_getref(data));
} else { // Number
if(sscanf(str, buf, &ref_int)==0){
break;
}
- set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)__64BPTRSIZE(ref_int), reference_getref(data));
+ script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)__64BPTRSIZE(ref_int), reference_getref(data));
}
arg++;
@@ -13941,7 +13785,7 @@ BUILDIN(setnpcdisplay)
else
{
ShowError("script:setnpcdisplay: expected string or number\n");
- script_reportdata(data);
+ script->reportdata(data);
return false;
}
@@ -14054,7 +13898,7 @@ BUILDIN(setd)
if( not_server_variable(*varname) )
{
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
{
ShowError("script:setd: no player attached for player variable '%s'\n", buffer);
@@ -14088,9 +13932,9 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle)
if( data_isreference(data) ) { // it's a variable
name = reference_getname(data);
if( not_server_variable(*name) && sd == NULL ) { // requires a player
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL ) { // no player attached
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;
}
@@ -14099,7 +13943,7 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle)
max_rows = 1;// not an array, limit to one row
} else {
ShowError("script:query_sql: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;
}
@@ -14125,10 +13969,10 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle)
num_cols = SQL->NumColumns(handle);
if( num_vars < num_cols ) {
ShowWarning("script:query_sql: Too many columns, discarding last %u columns.\n", (unsigned int)(num_cols-num_vars));
- script_reportsrc(st);
+ script->reportsrc(st);
} else if( num_vars > num_cols ) {
ShowWarning("script:query_sql: Too many variables (%u extra).\n", (unsigned int)(num_vars-num_cols));
- script_reportsrc(st);
+ script->reportsrc(st);
}
// Store data
@@ -14149,7 +13993,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));
- script_reportsrc(st);
+ script->reportsrc(st);
}
// Free data
@@ -14159,7 +14003,7 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle)
return true;
}
BUILDIN(query_sql) {
- return buildin_query_sql_sub(st, mmysql_handle);
+ return script->buildin_query_sql_sub(st, mmysql_handle);
}
BUILDIN(query_logsql) {
@@ -14168,7 +14012,7 @@ BUILDIN(query_logsql) {
script_pushint(st,-1);
return false;
}
- return buildin_query_sql_sub(st, logmysql_handle);
+ return script->buildin_query_sql_sub(st, logmysql_handle);
}
//Allows escaping of a given string.
@@ -14210,7 +14054,7 @@ BUILDIN(petstat)
TBL_PC *sd = NULL;
struct pet_data *pd;
int flag = script_getnum(st,2);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if(!sd || !sd->status.pet_id || !sd->pd){
if(flag == 2)
script_pushconststr(st, "");
@@ -14238,7 +14082,7 @@ BUILDIN(callshop)
struct npc_data *nd;
const char *shopname;
int flag = 0;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (!sd) {
script_pushint(st,0);
return true;
@@ -14522,7 +14366,7 @@ BUILDIN(checkvending) // check vending [Nab4]
if(script_hasdata(st,2))
sd = map->nick2sd(script_getstr(st,2));
else
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if(sd)
script_pushint(st, sd->state.autotrade ? 2 : sd->state.vending);
@@ -14540,7 +14384,7 @@ BUILDIN(checkchatting) {
if(script_hasdata(st,2))
sd = map->nick2sd(script_getstr(st,2));
else
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if(sd)
script_pushint(st,(sd->chatID != 0));
@@ -14556,7 +14400,7 @@ BUILDIN(checkidle) {
if (script_hasdata(st, 2))
sd = map->nick2sd(script_getstr(st, 2));
else
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (sd)
script_pushint(st, DIFF_TICK(last_tick, sd->idletime));
@@ -14594,7 +14438,7 @@ BUILDIN(searchitem)
if( !data_isreference(data) )
{
ShowError("script:searchitem: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not a variable
}
@@ -14605,14 +14449,14 @@ BUILDIN(searchitem)
if( not_array_variable(*name) )
{
ShowError("script:searchitem: illegal scope\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not supported
}
if( not_server_variable(*name) )
{
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;// no player attached
}
@@ -14620,7 +14464,7 @@ BUILDIN(searchitem)
if( is_string_variable(name) )
{// string array
ShowError("script:searchitem: not an integer array reference\n");
- script_reportdata(data);
+ script->reportdata(data);
st->state = END;
return false;// not supported
}
@@ -14628,7 +14472,7 @@ BUILDIN(searchitem)
for( i = 0; i < count; ++start, ++i )
{// Set array
void* v = (void*)__64BPTRSIZE((int)items[i]->nameid);
- set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data));
+ script->set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data));
}
script_pushint(st, count);
@@ -14672,7 +14516,7 @@ int axtoi(const char *hexStg)
BUILDIN(axtoi)
{
const char *hex = script_getstr(st,2);
- script_pushint(st,axtoi(hex));
+ script_pushint(st,script->axtoi(hex));
return true;
}
@@ -14710,7 +14554,7 @@ BUILDIN(pcblockmove) {
if(id)
sd = map->id2sd(id);
else
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if(sd)
sd->state.blockedmove = flag > 0;
@@ -14729,7 +14573,7 @@ BUILDIN(pcfollow) {
if(id)
sd = map->id2sd(id);
else
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if(sd)
pc->follow(sd, targetid);
@@ -14748,7 +14592,7 @@ BUILDIN(pcstopfollow)
if(id)
sd = map->id2sd(id);
else
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if(sd)
pc->stop_following(sd);
@@ -15040,7 +14884,7 @@ BUILDIN(sleep)
ticks = script_getnum(st,2);
// detach the player
- script_detach_rid(st);
+ script->detach_rid(st);
if( ticks <= 0 )
{// do nothing
@@ -15138,7 +14982,7 @@ BUILDIN(getvariableofnpc)
if( !data_isreference(data) )
{// Not a reference (aka varaible name)
ShowError("script:getvariableofnpc: not a variable\n");
- script_reportdata(data);
+ script->reportdata(data);
script_pushnil(st);
st->state = END;
return false;
@@ -15148,7 +14992,7 @@ BUILDIN(getvariableofnpc)
if( *name != '.' || name[1] == '@' )
{// not a npc variable
ShowError("script:getvariableofnpc: invalid scope (not npc variable)\n");
- script_reportdata(data);
+ script->reportdata(data);
script_pushnil(st);
st->state = END;
return false;
@@ -15212,7 +15056,7 @@ BUILDIN(openmail)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -15225,7 +15069,7 @@ BUILDIN(openauction)
{
TBL_PC* sd;
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if( sd == NULL )
return true;
@@ -15294,7 +15138,7 @@ BUILDIN(mercenary_create)
struct map_session_data *sd;
int class_, contract_time;
- if( (sd = script_rid2sd(st)) == NULL || sd->md || sd->status.mer_id != 0 )
+ if( (sd = script->rid2sd(st)) == NULL || sd->md || sd->status.mer_id != 0 )
return true;
class_ = script_getnum(st,2);
@@ -15308,7 +15152,7 @@ BUILDIN(mercenary_create)
}
BUILDIN(mercenary_heal) {
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
int hp, sp;
if( sd == NULL || sd->md == NULL )
@@ -15321,7 +15165,7 @@ BUILDIN(mercenary_heal) {
}
BUILDIN(mercenary_sc_start) {
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
enum sc_type type;
int tick, val1;
@@ -15337,7 +15181,7 @@ BUILDIN(mercenary_sc_start) {
}
BUILDIN(mercenary_get_calls) {
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
int guild_id;
if( sd == NULL )
@@ -15363,7 +15207,7 @@ BUILDIN(mercenary_get_calls) {
}
BUILDIN(mercenary_set_calls) {
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
int guild_id, value, *calls;
if( sd == NULL )
@@ -15393,7 +15237,7 @@ BUILDIN(mercenary_set_calls) {
}
BUILDIN(mercenary_get_faith) {
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
int guild_id;
if( sd == NULL )
@@ -15419,7 +15263,7 @@ BUILDIN(mercenary_get_faith) {
}
BUILDIN(mercenary_set_faith) {
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
int guild_id, value, *calls;
if( sd == NULL )
@@ -15458,7 +15302,7 @@ BUILDIN(readbook)
struct map_session_data *sd;
int book_id, page;
- if( (sd = script_rid2sd(st)) == NULL )
+ if( (sd = script->rid2sd(st)) == NULL )
return true;
book_id = script_getnum(st,2);
@@ -15474,7 +15318,7 @@ BUILDIN(readbook)
BUILDIN(setquest)
{
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
nullpo_ret(sd);
quest->add(sd, script_getnum(st, 2));
@@ -15483,7 +15327,7 @@ BUILDIN(setquest)
BUILDIN(erasequest)
{
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
nullpo_ret(sd);
quest->delete(sd, script_getnum(st, 2));
@@ -15492,7 +15336,7 @@ BUILDIN(erasequest)
BUILDIN(completequest)
{
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
nullpo_ret(sd);
quest->update_status(sd, script_getnum(st, 2), Q_COMPLETE);
@@ -15501,7 +15345,7 @@ BUILDIN(completequest)
BUILDIN(changequest)
{
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
nullpo_ret(sd);
quest->change(sd, script_getnum(st, 2),script_getnum(st, 3));
@@ -15510,7 +15354,7 @@ BUILDIN(changequest)
BUILDIN(checkquest)
{
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
quest_check_type type = HAVEQUEST;
nullpo_ret(sd);
@@ -15524,7 +15368,7 @@ BUILDIN(checkquest)
}
BUILDIN(showevent) {
- TBL_PC *sd = script_rid2sd(st);
+ TBL_PC *sd = script->rid2sd(st);
struct npc_data *nd = map->id2nd(st->oid);
int state, color;
@@ -15670,7 +15514,7 @@ BUILDIN(bg_monster)
str = script_getstr(st,6);
class_ = script_getnum(st,7);
if( script_hasdata(st,8) ) evt = script_getstr(st,8);
- check_event(st, evt);
+ script->check_event(st, evt);
script_pushint(st, mob->spawn_bg(mapname,x,y,str,class_,evt,bg_id));
return true;
}
@@ -15696,7 +15540,7 @@ BUILDIN(bg_monster_set_team) {
BUILDIN(bg_leave)
{
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
if( sd == NULL || !sd->bg_id )
return true;
@@ -15962,7 +15806,7 @@ BUILDIN(instance_announce) {
return true;
for( i = 0; i < instance->list[instance_id].num_map; i++ )
- map->foreachinmap(buildin_announce_sub, instance->list[instance_id].map[i], BL_PC,
+ map->foreachinmap(script->buildin_announce_sub, instance->list[instance_id].map[i], BL_PC,
mes, strlen(mes)+1, flag&BC_COLOR_MASK, fontColor, fontType, fontSize, fontAlign, fontY);
return true;
@@ -16009,7 +15853,7 @@ BUILDIN(has_instance) {
instance_id = script_getnum(st, 3);
else if( st->instance_id >= 0 )
instance_id = st->instance_id;
- else if( (sd = script_rid2sd(st)) != NULL ) {
+ else if( (sd = script->rid2sd(st)) != NULL ) {
struct party_data *p;
int i = 0, j = 0;
if( sd->instances ) {
@@ -16055,7 +15899,7 @@ BUILDIN(has_instance) {
script_pushconststr(st, maplist[m].name);
return true;
}
-static int buildin_instance_warpall_sub(struct block_list *bl,va_list ap) {
+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);
@@ -16088,7 +15932,7 @@ BUILDIN(instance_warpall) {
mapindex = map_id2index(m);
- map->foreachininstance(buildin_instance_warpall_sub, instance_id, BL_PC,mapindex,x,y);
+ map->foreachininstance(script->buildin_instance_warpall_sub, instance_id, BL_PC,mapindex,x,y);
return true;
}
@@ -16155,7 +15999,7 @@ BUILDIN(instance_check_party) {
*------------------------------------------*/
BUILDIN(setfont)
{
- struct map_session_data *sd = script_rid2sd(st);
+ struct map_session_data *sd = script->rid2sd(st);
int font = script_getnum(st,2);
if( sd == NULL )
return true;
@@ -16169,7 +16013,7 @@ BUILDIN(setfont)
return true;
}
-static int buildin_mobuseskill_sub(struct block_list *bl,va_list ap)
+int buildin_mobuseskill_sub(struct block_list *bl,va_list ap)
{
TBL_MOB* md = (TBL_MOB*)bl;
struct block_list *tbl;
@@ -16236,14 +16080,14 @@ BUILDIN(areamobuseskill) {
emotion = script_getnum(st,11);
target = script_getnum(st,12);
- map->foreachinrange(buildin_mobuseskill_sub, &center, range, BL_MOB, mobid, skill_id, skill_lv, casttime, cancel, emotion, target);
+ map->foreachinrange(script->buildin_mobuseskill_sub, &center, range, BL_MOB, mobid, skill_id, skill_lv, casttime, cancel, emotion, target);
return true;
}
BUILDIN(progressbar)
{
- struct map_session_data * sd = script_rid2sd(st);
+ struct map_session_data * sd = script->rid2sd(st);
const char * color;
unsigned int second;
@@ -16269,7 +16113,7 @@ BUILDIN(pushpc)
int cells, dx, dy;
struct map_session_data* sd;
- if((sd = script_rid2sd(st))==NULL)
+ if((sd = script->rid2sd(st))==NULL)
{
return true;
}
@@ -16280,7 +16124,7 @@ BUILDIN(pushpc)
if(dir>7)
{
ShowWarning("buildin_pushpc: Invalid direction %d specified.\n", dir);
- script_reportsrc(st);
+ script->reportsrc(st);
dir%= 8; // trim spin-over
}
@@ -16309,7 +16153,7 @@ BUILDIN(buyingstore)
{
struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) == NULL ) {
+ if( ( sd = script->rid2sd(st) ) == NULL ) {
return true;
}
@@ -16326,7 +16170,7 @@ BUILDIN(searchstores)
unsigned int uses;
struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) == NULL )
+ if( ( sd = script->rid2sd(st) ) == NULL )
{
return true;
}
@@ -16357,7 +16201,7 @@ BUILDIN(showdigit)
int value;
struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) == NULL )
+ if( ( sd = script->rid2sd(st) ) == NULL )
{
return true;
}
@@ -16383,7 +16227,7 @@ BUILDIN(showdigit)
**/
BUILDIN(makerune) {
TBL_PC* sd;
- if( (sd = script_rid2sd(st)) == NULL )
+ if( (sd = script->rid2sd(st)) == NULL )
return true;
clif->skill_produce_mix_list(sd,RK_RUNEMASTERY,24);
sd->itemid = script_getnum(st,2);
@@ -16394,7 +16238,7 @@ BUILDIN(makerune) {
**/
BUILDIN(checkdragon) {
TBL_PC* sd;
- if( (sd = script_rid2sd(st)) == NULL )
+ if( (sd = script->rid2sd(st)) == NULL )
return true;
if( pc_isridingdragon(sd) )
script_pushint(st,1);
@@ -16416,7 +16260,7 @@ BUILDIN(setdragon) {
TBL_PC* sd;
int color = script_hasdata(st,2) ? script_getnum(st,2) : 0;
- if( (sd = script_rid2sd(st)) == NULL )
+ if( (sd = script->rid2sd(st)) == NULL )
return true;
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
@@ -16447,7 +16291,7 @@ BUILDIN(setdragon) {
**/
BUILDIN(ismounting) {
TBL_PC* sd;
- if( (sd = script_rid2sd(st)) == NULL )
+ if( (sd = script->rid2sd(st)) == NULL )
return true;
if( sd->sc.data[SC_ALL_RIDING] )
script_pushint(st,1);
@@ -16464,7 +16308,7 @@ BUILDIN(ismounting) {
**/
BUILDIN(setmounting) {
TBL_PC* sd;
- if( (sd = script_rid2sd(st)) == NULL )
+ if( (sd = script->rid2sd(st)) == NULL )
return true;
if( sd->sc.option&(OPTION_WUGRIDER|OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR) ){
clif->msgtable(sd->fd, 0X78b);
@@ -16513,7 +16357,7 @@ BUILDIN(getcharip) {
}
}
else
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
/* check for sd and IP */
if (!sd || !session[sd->fd]->client_addr)
@@ -16585,7 +16429,7 @@ BUILDIN(sit) {
sd = map->nick2sd(script_getstr(st, 2));
if (sd == NULL)
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (!pc_issit(sd))
{
@@ -16603,7 +16447,7 @@ BUILDIN(stand) {
sd = map->nick2sd(script_getstr(st, 2));
if (sd == NULL)
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (pc_issit(sd))
{
@@ -16621,7 +16465,7 @@ BUILDIN(issit) {
sd = map->nick2sd(script_getstr(st, 2));
if (sd == NULL)
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
if (pc_issit(sd))
script_pushint(st, 1);
@@ -16733,7 +16577,7 @@ BUILDIN(useatcmd) {
cmd = script_getstr(st,2);
if( st->rid ) {
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
fd = sd->fd;
} else {
// Use a dummy character.
@@ -16876,7 +16720,7 @@ BUILDIN(getrandgroupitem) {
/* cleanmap <map_name>;
* cleanarea <map_name>, <x0>, <y0>, <x1>, <y1>; */
-static int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap) {
+int script_cleanfloor_sub(struct block_list *bl, va_list ap) {
nullpo_ret(bl);
map->clearflooritem(bl);
@@ -16894,14 +16738,14 @@ BUILDIN(cleanmap) {
return false;
if ((script_lastdata(st) - 2) < 4) {
- map->foreachinmap(atcommand_cleanfloor_sub, m, BL_ITEM);
+ map->foreachinmap(script->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);
+ map->foreachinarea(script->cleanfloor_sub, m, x0, y0, x1, y1, BL_ITEM);
} else {
ShowError("cleanarea: invalid coordinate defined!\n");
return false;
@@ -16925,7 +16769,7 @@ BUILDIN(npcskill) {
skill_level = script_getnum(st, 3);
stat_point = script_getnum(st, 4);
npc_level = script_getnum(st, 5);
- sd = script_rid2sd(st);
+ sd = script->rid2sd(st);
nd = (struct npc_data *)map->id2bl(sd->npc_id);
if (stat_point > battle_config.max_third_parameter) {
@@ -17938,17 +17782,17 @@ void script_parse_builtin(void) {
while( *p == '?' ) ++p;
if( *p == '*' ) ++p;
if( *p != 0 ){
- ShowWarning("script_parse_builtin: ignoring function \"%s\" with invalid arg \"%s\".\n", BUILDIN[i].name, BUILDIN[i].arg);
- } else if( *skip_word(BUILDIN[i].name) != 0 ){
- ShowWarning("script_parse_builtin: ignoring function with invalid name \"%s\" (must be a word).\n", BUILDIN[i].name);
+ ShowWarning("parse_builtin: ignoring function \"%s\" with invalid arg \"%s\".\n", BUILDIN[i].name, BUILDIN[i].arg);
+ } else if( *script->skip_word(BUILDIN[i].name) != 0 ){
+ ShowWarning("parse_builtin: ignoring function with invalid name \"%s\" (must be a word).\n", BUILDIN[i].name);
} else {
int slen = strlen(BUILDIN[i].arg), offset = start + i;
n = script->add_str(BUILDIN[i].name);
- if (!strcmp(BUILDIN[i].name, "set")) buildin_set_ref = n;
- else if (!strcmp(BUILDIN[i].name, "callsub")) buildin_callsub_ref = n;
- else if (!strcmp(BUILDIN[i].name, "callfunc")) buildin_callfunc_ref = n;
- else if (!strcmp(BUILDIN[i].name, "getelementofarray") ) buildin_getelementofarray_ref = n;
+ if (!strcmp(BUILDIN[i].name, "set")) script->buildin_set_ref = n;
+ else if (!strcmp(BUILDIN[i].name, "callsub")) script->buildin_callsub_ref = n;
+ else if (!strcmp(BUILDIN[i].name, "callfunc")) script->buildin_callfunc_ref = n;
+ else if (!strcmp(BUILDIN[i].name, "getelementofarray") ) script->buildin_getelementofarray_ref = n;
if( script->str_data[n].func && script->str_data[n].func != BUILDIN[i].func )
continue;/* something replaced it, skip. */
@@ -17984,6 +17828,9 @@ void script_label_add(int key, int pos) {
}
void script_defaults(void) {
+ // aegis->athena slot position conversion table
+ unsigned int equip[SCRIPT_EQUIP_TABLE_SIZE] = {EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW,EQP_COSTUME_HEAD_LOW,EQP_COSTUME_HEAD_MID,EQP_COSTUME_HEAD_TOP,EQP_COSTUME_GARMENT};
+
script = &script_s;
script->st_db = NULL;
@@ -18006,6 +17853,7 @@ void script_defaults(void) {
script->str_buf = NULL;
script->str_size = 0;
script->str_pos = 0;
+ memset(script->str_hash, 0, sizeof(script->str_hash));
script->word_buf = NULL;
script->word_size = 0;
@@ -18016,6 +17864,29 @@ void script_defaults(void) {
script->label_count = 0;
script->labels_size = 0;
+ script->buf = NULL;
+ script->pos = 0, script->size = 0;
+
+ script->parse_options = 0;
+ script->buildin_set_ref = 0;
+ script->buildin_callsub_ref = 0;
+ script->buildin_callfunc_ref = 0;
+ script->buildin_getelementofarray_ref = 0;
+
+ memset(script->error_jump,0,sizeof(script->error_jump));
+ script->error_msg = NULL;
+ script->error_pos = NULL;
+ script->error_report = 0;
+ script->parser_current_src = NULL;
+ script->parser_current_file = NULL;
+ script->parser_current_line = 0;
+
+ memset(&script->syntax,0,sizeof(script->syntax));
+
+ script->parse_syntax_for_flag = 0;
+
+ memcpy(script->equip, &equip, sizeof(script->equip));
+
memset(&script->config, 0, sizeof(script->config));
script->autobonus_db = NULL;
@@ -18078,6 +17949,77 @@ void script_defaults(void) {
script->queue_create = script_hqueue_create;
script->queue_clear = script_hqueue_clear;
+ script->parse_curly_close = parse_curly_close;
+ script->parse_syntax_close = parse_syntax_close;
+ script->parse_syntax_close_sub = parse_syntax_close_sub;
+ script->parse_syntax = parse_syntax;
+ script->get_com = get_com;
+ script->get_num = get_num;
+ script->op2name = script_op2name;
+ script->reportsrc = script_reportsrc;
+ script->reportdata = script_reportdata;
+ script->reportfunc = script_reportfunc;
+ script->disp_error_message2 = disp_error_message2;
+ script->disp_warning_message = disp_warning_message;
+ script->check_event = check_event;
+ script->calc_hash = calc_hash;
+ script->addb = add_scriptb;
+ script->addc = add_scriptc;
+ script->addi = add_scripti;
+ script->addl = add_scriptl;
+ script->set_label = set_label;
+ script->skip_word = skip_word;
+ script->add_word = add_word;
+ script->parse_callfunc = parse_callfunc;
+ script->parse_nextline = parse_nextline;
+ script->parse_variable = parse_variable;
+ script->parse_simpleexpr = parse_simpleexpr;
+ script->parse_expr = parse_expr;
+ script->parse_line = parse_line;
+ script->read_constdb = read_constdb;
+ script->print_line = script_print_line;
+ script->errorwarning_sub = script_errorwarning_sub;
+ script->set_reg = set_reg;
+ script->stack_expand = stack_expand;
+ script->push_retinfo = push_retinfo;
+ script->pop_val = pop_val;
+ script->op_3 = op_3;
+ script->op_2str = op_2str;
+ script->op_2num = op_2num;
+ script->op_2 = op_2;
+ script->op_1 = op_1;
+ script->check_buildin_argtype = script_check_buildin_argtype;
+ script->detach_state = script_detach_state;
+ script->db_free_code_sub = db_script_free_code_sub;
+ script->add_autobonus = script_add_autobonus;
+ script->menu_countoptions = menu_countoptions;
+ script->buildin_areawarp_sub = buildin_areawarp_sub;
+ script->buildin_areapercentheal_sub = buildin_areapercentheal_sub;
+ script->getarraysize = getarraysize;
+ script->buildin_delitem_delete = buildin_delitem_delete;
+ script->buildin_delitem_search = buildin_delitem_search;
+ script->buildin_killmonster_sub_strip = buildin_killmonster_sub_strip;
+ script->buildin_killmonster_sub = buildin_killmonster_sub;
+ script->buildin_killmonsterall_sub_strip = buildin_killmonsterall_sub_strip;
+ script->buildin_killmonsterall_sub = buildin_killmonsterall_sub;
+ script->buildin_announce_sub = buildin_announce_sub;
+ script->buildin_getareausers_sub = buildin_getareausers_sub;
+ script->buildin_getareadropitem_sub = buildin_getareadropitem_sub;
+ script->mapflag_pvp_sub = script_mapflag_pvp_sub;
+ script->buildin_pvpoff_sub = buildin_pvpoff_sub;
+ script->buildin_maprespawnguildid_sub_pc = buildin_maprespawnguildid_sub_pc;
+ script->buildin_maprespawnguildid_sub_mob = buildin_maprespawnguildid_sub_mob;
+ script->buildin_mobcount_sub = buildin_mobcount_sub;
+ script->playBGM_sub = playBGM_sub;
+ 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;
+ script->run_func = run_func;
+
/* script_config base */
script->config.warn_func_mismatch_argtypes = 1;
script->config.warn_func_mismatch_paramnum = 1;