summaryrefslogtreecommitdiff
path: root/src/map/script.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/script.h')
-rw-r--r--src/map/script.h169
1 files changed, 117 insertions, 52 deletions
diff --git a/src/map/script.h b/src/map/script.h
index c00086ef9..3835a130b 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -2,10 +2,11 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#ifndef _SCRIPT_H_
-#define _SCRIPT_H_
+#ifndef _MAP_SCRIPT_H_
+#define _MAP_SCRIPT_H_
#include "../common/strlib.h" //StringBuf
+#include "../common/cbasetypes.h"
#include "map.h" //EVENT_NAME_LENGTH
#include <setjmp.h>
@@ -20,10 +21,17 @@ struct eri;
/**
* Defines
**/
+// TODO: Remove temporary code
+#define ENABLE_CASE_CHECK
+#define get_script_source(source) ((source) ? (source) : "Unknown (Possibly source or variables stored in database")
+#define DeprecationWarning(func, bad, good, file, line) ShowError("%s: use of deprecated keyword '%s' (use '%s' instead) in file '%s', line '%d'.\n", (func), (bad), (good), get_script_source(file), (line));
+#define DeprecationWarning2(func, bad, good, where) ShowError("%s: detected possible use of wrong case in a script. Found '%s', probably meant to be '%s' (in '%s').\n", (func), (bad), (good), get_script_source(where));
+#define disp_deprecation_message(func, good, p) disp_warning_message(func": use of deprecated keyword (use '"good"' instead).", (p));
+
#define NUM_WHISPER_VAR 10
-/// Maximum amount of elements in script arrays (soon getting ducked)
-#define SCRIPT_MAX_ARRAYSIZE 128
+/// Maximum amount of elements in script arrays
+#define SCRIPT_MAX_ARRAYSIZE (UINT_MAX - 1)
#define SCRIPT_BLOCK_SIZE 512
@@ -35,7 +43,7 @@ struct eri;
//#define SCRIPT_HASH_SDBM
#define SCRIPT_HASH_ELF
-#define SCRIPT_EQUIP_TABLE_SIZE 14
+#define SCRIPT_EQUIP_TABLE_SIZE 20
//#define SCRIPT_DEBUG_DISP
//#define SCRIPT_DEBUG_DISASM
@@ -65,24 +73,26 @@ struct eri;
/// Returns the index of the last data in the stack
#define script_lastdata(st) ( (st)->end - (st)->start - 1 )
/// Pushes an int into the stack
-#define script_pushint(st,val) script->push_val((st)->stack, C_INT, (val),NULL)
+#define script_pushint(st,val) (script->push_val((st)->stack, C_INT, (val),NULL))
/// Pushes a string into the stack (script engine frees it automatically)
-#define script_pushstr(st,val) script->push_str((st)->stack, C_STR, (val))
+#define script_pushstr(st,val) (script->push_str((st)->stack, C_STR, (val)))
/// Pushes a copy of a string into the stack
-#define script_pushstrcopy(st,val) script->push_str((st)->stack, C_STR, aStrdup(val))
+#define script_pushstrcopy(st,val) (script->push_str((st)->stack, C_STR, aStrdup(val)))
/// Pushes a constant string into the stack (must never change or be freed)
-#define script_pushconststr(st,val) script->push_str((st)->stack, C_CONSTSTR, (val))
+#define script_pushconststr(st,val) (script->push_str((st)->stack, C_CONSTSTR, (val)))
/// Pushes a nil into the stack
-#define script_pushnil(st) script->push_val((st)->stack, C_NOP, 0,NULL)
+#define script_pushnil(st) (script->push_val((st)->stack, C_NOP, 0,NULL))
/// Pushes a copy of the data in the target index
-#define script_pushcopy(st,i) script->push_copy((st)->stack, (st)->start + (i))
+#define script_pushcopy(st,i) (script->push_copy((st)->stack, (st)->start + (i)))
-#define script_isstring(st,i) data_isstring(script_getdata(st,i))
-#define script_isint(st,i) data_isint(script_getdata(st,i))
+#define script_isstring(st,i) data_isstring(script_getdata((st),(i)))
+#define script_isint(st,i) data_isint(script_getdata((st),(i)))
+#define script_isstringtype(st,i) data_isstring(script->get_val((st), script_getdata((st),(i))))
+#define script_isinttype(st,i) data_isint(script->get_val((st), script_getdata((st),(i))))
-#define script_getnum(st,val) script->conv_num(st, script_getdata(st,val))
-#define script_getstr(st,val) script->conv_str(st, script_getdata(st,val))
-#define script_getref(st,val) ( script_getdata(st,val)->ref )
+#define script_getnum(st,val) (script->conv_num((st), script_getdata((st),(val))))
+#define script_getstr(st,val) (script->conv_str((st), script_getdata((st),(val))))
+#define script_getref(st,val) ( script_getdata((st),(val))->ref )
// Note: "top" functions/defines use indexes relative to the top of the stack
// -1 is the index of the data at the top
@@ -119,9 +129,9 @@ struct eri;
/// Returns the unique id of the reference (id and index)
#define reference_getuid(data) ( (data)->u.num )
/// Returns the id of the reference
-#define reference_getid(data) ( (int32)(reference_getuid(data) & 0x00ffffff) )
+#define reference_getid(data) ( (int32)(int64)(reference_getuid(data) & 0xFFFFFFFF) )
/// Returns the array index of the reference
-#define reference_getindex(data) ( (int32)(((uint32)(reference_getuid(data) & 0xff000000)) >> 24) )
+#define reference_getindex(data) ( (uint32)(int64)((reference_getuid(data) >> 32) & 0xFFFFFFFF) )
/// Returns the name of the reference
#define reference_getname(data) ( script->str_buf + script->str_data[reference_getid(data)].str )
/// Returns the linked list of uid-value pairs of the reference (can be NULL)
@@ -132,18 +142,22 @@ struct eri;
#define reference_getparamtype(data) ( script->str_data[reference_getid(data)].val )
/// Composes the uid of a reference from the id and the index
-#define reference_uid(id,idx) ( (int32)((((uint32)(id)) & 0x00ffffff) | (((uint32)(idx)) << 24)) )
+#define reference_uid(id,idx) ( (int64) ((uint64)(id) & 0xFFFFFFFF) | ((uint64)(idx) << 32) )
+
+#define script_getvarid(var) ( (int32)(int64)(var & 0xFFFFFFFF) )
+#define script_getvaridx(var) ( (uint32)(int64)((var >> 32) & 0xFFFFFFFF) )
#define not_server_variable(prefix) ( (prefix) != '$' && (prefix) != '.' && (prefix) != '\'')
-#define not_array_variable(prefix) ( (prefix) != '$' && (prefix) != '@' && (prefix) != '.' && (prefix) != '\'' )
#define is_string_variable(name) ( (name)[strlen(name) - 1] == '$' )
#define BUILDIN(x) bool buildin_ ## x (struct script_state* st)
-#define BUILDIN_A(x) buildin_ ## x
-#define script_fetch(st, n, t) \
- if( script_hasdata(st,n) ) \
- (t)=script_getnum(st,n);
+#define script_fetch(st, n, t) do { \
+ if( script_hasdata((st),(n)) ) \
+ (t)=script_getnum((st),(n)); \
+ else \
+ (t) = 0; \
+} while(0)
/**
@@ -188,8 +202,10 @@ typedef enum c_op {
C_NOT, // ~ a
C_R_SHIFT, // a >> b
C_L_SHIFT, // a << b
- C_ADD_PP, // ++a
- C_SUB_PP, // --a
+ C_ADD_POST, // a++
+ C_SUB_POST, // a--
+ C_ADD_PRE, // ++a
+ C_SUB_PRE, // --a
} c_op;
enum hQueueOpt {
@@ -287,7 +303,8 @@ enum {
MF_PVP_NOCALCRANK, //50
MF_BATTLEGROUND,
MF_RESET,
- MF_NOTOMB
+ MF_NOTOMB,
+ MF_NOCASHSHOP
};
/**
@@ -326,7 +343,7 @@ struct script_retinfo {
struct script_data {
enum c_op type;
union script_data_val {
- int num;
+ int64 num;
char *str;
struct script_retinfo* ri;
} u;
@@ -337,8 +354,9 @@ struct script_data {
// it must be saved when script state is RERUNLINE. [Eoe / jA 1094]
struct script_code {
int script_size;
- unsigned char* script_buf;
- struct DBMap* script_vars;
+ unsigned char *script_buf;
+ struct DBMap *script_vars;
+ struct DBMap *script_arrays_db;
};
struct script_stack {
@@ -346,7 +364,8 @@ struct script_stack {
int sp_max;// capacity of the stack
int defsp;
struct script_data *stack_data;// stack
- struct DBMap* var_function;// scope variables
+ struct DBMap *var_function;// scope variables
+ struct DBMap *array_function_db;
};
/* [Ind/Hercules] */
@@ -388,13 +407,14 @@ struct script_state {
unsigned int id;
};
+/* TODO: HELLO DUCK THIS */
struct script_reg {
- int index;
+ int64 index;
int data;
};
-
+/* TODO: HELLO DUCK THIS */
struct script_regstr {
- int index;
+ int64 index;
char* data;
};
@@ -432,6 +452,25 @@ struct script_syntax_data {
int index; // Number of the syntax used in the script
};
+struct casecheck_data {
+ struct str_data_struct *str_data;
+ int str_data_size; // size of the data
+ int str_num; // next id to be assigned
+ // str_buf holds the strings themselves
+ char *str_buf;
+ int str_size; // size of the buffer
+ int str_pos; // next position to be assigned
+ int str_hash[SCRIPT_HASH_SIZE];
+ const char *(*add_str) (const char* p);
+ void (*clear) (void);
+};
+
+struct script_array {
+ unsigned int id;/* the first 32b of the 64b uid, aka the id */
+ unsigned int size;/* how many members */
+ unsigned int *members;/* member list */
+};
+
/**
* Interface
**/
@@ -446,22 +485,25 @@ struct script_interface {
struct hQueue *hq;
struct hQueueIterator *hqi;
int hqs, hqis;
- int hqe[HQO_MAX];
/* */
char **buildin;
unsigned int buildin_count;
+ /**
+ * used to generate quick script_array entries
+ **/
+ struct eri *array_ers;
/* */
struct str_data_struct *str_data;
int str_data_size; // size of the data
int str_num; // next id to be assigned
// str_buf holds the strings themselves
char *str_buf;
- int str_size; // size of the buffer
+ size_t str_size; // size of the buffer
int str_pos; // next position to be assigned
int str_hash[SCRIPT_HASH_SIZE];
/* */
char *word_buf;
- int word_size;
+ size_t word_size;
/* */
unsigned short current_item_id;
/* */
@@ -505,12 +547,16 @@ struct script_interface {
int potion_flag; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
int potion_hp, potion_per_hp, potion_sp, potion_per_sp;
int potion_target;
+ /* */
+ unsigned int *generic_ui_array;
+ unsigned int generic_ui_array_size;
/* */
- void (*init) (void);
+ void (*init) (bool minimal);
void (*final) (void);
int (*reload) (void);
/* parse */
struct script_code* (*parse) (const char* src,const char* file,int line,int options);
+ bool (*add_builtin) (const struct script_function *buildin, bool override);
void (*parse_builtin) (void);
const char* (*parse_subexpr) (const char* p,int limit);
const char* (*skip_space) (const char* p);
@@ -522,20 +568,19 @@ struct script_interface {
const char* (*conv_str) (struct script_state *st,struct script_data *data);
TBL_PC *(*rid2sd) (struct script_state *st);
void (*detach_rid) (struct script_state* st);
- struct script_data* (*push_val)(struct script_stack* stack, enum c_op type, int val, struct DBMap** ref);
- void (*get_val) (struct script_state* st, struct script_data* data);
- void* (*get_val2) (struct script_state* st, int uid, struct DBMap** ref);
+ struct script_data* (*push_val)(struct script_stack* stack, enum c_op type, int64 val, struct DBMap** ref);
+ struct script_data *(*get_val) (struct script_state* st, struct script_data* data);
+ void* (*get_val2) (struct script_state* st, int64 uid, struct DBMap** ref);
struct script_data* (*push_str) (struct script_stack* stack, enum c_op type, char* str);
struct script_data* (*push_copy) (struct script_stack* stack, int pos);
void (*pop_stack) (struct script_state* st, int start, int end);
void (*set_constant) (const char* name, int value, bool isparameter);
void (*set_constant2) (const char *name, int value, bool isparameter);
- void (*set_constant_force) (const char *name, int value, bool isparameter);
bool (*get_constant) (const char* name, int* value);
void (*label_add)(int key, int pos);
void (*run) (struct script_code *rootscript,int pos,int rid,int oid);
void (*run_main) (struct script_state *st);
- int (*run_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*run_timer) (int tid, int64 tick, int id, intptr_t data);
int (*set_var) (struct map_session_data *sd, char *name, void *val);
void (*stop_instances) (struct script_code *code);
void (*free_code) (struct script_code* code);
@@ -544,7 +589,7 @@ struct script_interface {
void (*free_state) (struct script_state* st);
void (*run_autobonus) (const char *autobonus,int id, int pos);
void (*cleararray_pc) (struct map_session_data* sd, const char* varname, void* value);
- void (*setarray_pc) (struct map_session_data* sd, const char* varname, uint8 idx, void* value, int* refcache);
+ void (*setarray_pc) (struct map_session_data* sd, const char* varname, uint32 idx, void* value, int* refcache);
int (*config_read) (char *cfgName);
int (*add_str) (const char* p);
const char* (*get_str) (int id);
@@ -569,7 +614,6 @@ struct script_interface {
void (*reportsrc) (struct script_state *st);
void (*reportdata) (struct script_data *data);
void (*reportfunc) (struct script_state *st);
- void (*disp_error_message2) (const char *mes, const char *pos, int report);
void (*disp_warning_message) (const char *mes, const char *pos);
void (*check_event) (struct script_state *st, const char *evt);
unsigned int (*calc_hash) (const char *p);
@@ -589,10 +633,9 @@ struct script_interface {
void (*read_constdb) (void);
const char* (*print_line) (StringBuf *buf, const char *p, const char *mark, int line);
void (*errorwarning_sub) (StringBuf *buf, const char *src, const char *file, int start_line, const char *error_msg, const char *error_pos);
- 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, int64 num, const char *name, const void *value, struct DBMap **ref);
void (*stack_expand) (struct script_stack *stack);
struct script_data* (*push_retinfo) (struct script_stack *stack, struct script_retinfo *ri, DBMap **ref);
- int (*pop_val) (struct script_state *st);
void (*op_3) (struct script_state *st, int op);
void (*op_2str) (struct script_state *st, int op, const char *s1, const char *s2);
void (*op_2num) (struct script_state *st, int op, int i1, int i2);
@@ -605,7 +648,6 @@ struct script_interface {
int (*menu_countoptions) (const char *str, int max_count, int *total);
int (*buildin_areawarp_sub) (struct block_list *bl, va_list ap);
int (*buildin_areapercentheal_sub) (struct block_list *bl, va_list ap);
- int32 (*getarraysize) (struct script_state *st, int32 id, int32 idx, int isstring, struct DBMap **ref);
void (*buildin_delitem_delete) (struct map_session_data *sd, int idx, int *amount, bool delete_items);
bool (*buildin_delitem_search) (struct map_session_data *sd, struct item *it, bool exact_match);
int (*buildin_killmonster_sub_strip) (struct block_list *bl, va_list ap);
@@ -620,19 +662,42 @@ struct script_interface {
int (*buildin_maprespawnguildid_sub_pc) (struct map_session_data *sd, va_list ap);
int (*buildin_maprespawnguildid_sub_mob) (struct block_list *bl, va_list ap);
int (*buildin_mobcount_sub) (struct block_list *bl, va_list ap);
- int (*playBGM_sub) (struct block_list *bl, va_list ap);
- int (*playBGM_foreachpc_sub) (struct map_session_data *sd, va_list args);
+ int (*playbgm_sub) (struct block_list *bl, va_list ap);
+ int (*playbgm_foreachpc_sub) (struct map_session_data *sd, va_list args);
int (*soundeffect_sub) (struct block_list *bl, va_list ap);
int (*buildin_query_sql_sub) (struct script_state *st, Sql *handle);
- int (*axtoi) (const char *hexStg);
int (*buildin_instance_warpall_sub) (struct block_list *bl, va_list ap);
int (*buildin_mobuseskill_sub) (struct block_list *bl, va_list ap);
int (*cleanfloor_sub) (struct block_list *bl, va_list ap);
int (*run_func) (struct script_state *st);
+ const char *(*getfuncname) (struct script_state *st);
+ // for ENABLE_CASE_CHECK
+ unsigned int (*calc_hash_ci) (const char *p);
+ struct casecheck_data local_casecheck;
+ struct casecheck_data global_casecheck;
+ // end ENABLE_CASE_CHECK
+ /**
+ * Array Handling
+ **/
+ struct DBMap *(*array_src) (struct script_state *st, struct map_session_data *sd, const char *name, struct DBMap **ref);
+ void (*array_update) (struct DBMap **src, int64 num, bool empty);
+ void (*array_delete) (struct DBMap *src, struct script_array *sa);
+ void (*array_remove_member) (struct DBMap *src, struct script_array *sa, unsigned int idx);
+ void (*array_add_member) (struct script_array *sa, unsigned int idx);
+ unsigned int (*array_size) (struct script_state *st, struct map_session_data *sd, const char *name, struct DBMap** ref);
+ unsigned int (*array_highest_key) (struct script_state *st, struct map_session_data *sd, const char *name, struct DBMap** ref);
+ int (*array_free_db) (DBKey key, DBData *data, va_list ap);
+ void (*array_ensure_zero) (struct script_state *st, struct map_session_data *sd, int64 uid, struct DBMap** ref);
+ /* */
+ void (*reg_destroy_single) (struct map_session_data *sd, int64 reg, struct script_reg_state *data);
+ int (*reg_destroy) (DBKey key, DBData *data, va_list ap);
+ /* */
+ void (*generic_ui_array_expand) (unsigned int plus);
+ unsigned int *(*array_cpy_list) (struct script_array *sa);
};
struct script_interface *script;
void script_defaults(void);
-#endif /* _SCRIPT_H_ */
+#endif /* _MAP_SCRIPT_H_ */