root/src/map/script.h @ 15

Revision 1, 4.2 kB (checked in by jinshiro, 17 years ago)
Line 
1// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
2// For more information, see LICENCE in the main folder
3
4#ifndef _SCRIPT_H_
5#define _SCRIPT_H_
6
7extern int potion_flag; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
8extern int potion_hp, potion_per_hp, potion_sp, potion_per_sp;
9extern int potion_target;
10
11extern struct Script_Config {
12        unsigned warn_func_mismatch_paramnum : 1;
13        int check_cmdcount;
14        int check_gotocount;
15        int input_min_value;
16        int input_max_value;
17
18        const char *die_event_name;
19        const char *kill_pc_event_name;
20        const char *kill_mob_event_name;
21        const char *login_event_name;
22        const char *logout_event_name;
23        const char *loadmap_event_name;
24        const char *baselvup_event_name;
25        const char *joblvup_event_name;
26} script_config;
27
28typedef enum c_op {
29        C_NOP, // end of script/no value (nil)
30        C_POS,
31        C_INT, // number
32        C_PARAM, // parameter variable (see pc_readparam/pc_setparam)
33        C_FUNC, // buildin function call
34        C_STR, // string (free'd automatically)
35        C_CONSTSTR, // string (not free'd)
36        C_ARG, // start of argument list
37        C_NAME,
38        C_EOL, // end of line (extra stack values are cleared)
39        C_RETINFO,
40        C_USERFUNC, // internal script function
41        C_USERFUNC_POS, // internal script function label
42
43        // operators
44        C_OP3, // a ? b : c
45        C_LOR, // a || b
46        C_LAND, // a && b
47        C_LE, // a <= b
48        C_LT, // a < b
49        C_GE, // a >= b
50        C_GT, // a > b
51        C_EQ, // a == b
52        C_NE, // a != b
53        C_XOR, // a ^ b
54        C_OR, // a | b
55        C_AND, // a & b
56        C_ADD, // a + b
57        C_SUB, // a - b
58        C_MUL, // a * b
59        C_DIV, // a / b
60        C_MOD, // a % b
61        C_NEG, // - a
62        C_LNOT, // ! a
63        C_NOT, // ~ a
64        C_R_SHIFT, // a >> b
65        C_L_SHIFT // a << b
66} c_op;
67
68struct script_data {
69        enum c_op type;
70        union script_data_val {
71                int num;
72                char *str;
73        } u;
74        struct linkdb_node** ref;
75};
76
77// Moved defsp from script_state to script_stack since
78// it must be saved when script state is RERUNLINE. [Eoe / jA 1094]
79struct script_code {
80        int script_size;
81        unsigned char* script_buf;
82        struct linkdb_node* script_vars;
83};
84
85struct script_stack {
86        int sp;// number of entries in the stack
87        int sp_max;// capacity of the stack
88        int defsp;
89        struct script_data *stack_data;// stack
90        struct linkdb_node **var_function;      // ŠÖ”ˆË‘¶•ϐ”
91};
92
93struct script_state {
94        struct script_stack* stack;
95        int start,end;
96        int pos,state;
97        int rid,oid;
98        struct script_code *script, *scriptroot;
99        struct sleep_data {
100                int tick,timer,charid;
101        } sleep;
102};
103
104struct script_reg {
105        int index;
106        int data;
107};
108
109struct script_regstr {
110        int index;
111        char* data;
112};
113
114enum script_parse_options {
115        SCRIPT_USE_LABEL_DB = 0x1,// records labels in scriptlabel_db
116        SCRIPT_IGNORE_EXTERNAL_BRACKETS = 0x2,// ignores the check for {} brackets around the script
117        SCRIPT_RETURN_EMPTY_SCRIPT = 0x4// returns the script object instead of NULL for empty scripts
118};
119
120const char* skip_space(const char* p);
121void script_error(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos);
122
123struct script_code* parse_script(const char* src,const char* file,int line,int options);
124void run_script_sub(struct script_code *rootscript,int pos,int rid,int oid, char* file, int lineno);
125void run_script(struct script_code*,int,int,int);
126
127int set_var(struct map_session_data *sd, char *name, void *val);
128int conv_num(struct script_state *st,struct script_data *data);
129const char* conv_str(struct script_state *st,struct script_data *data);
130void setd_sub(struct script_state *st, struct map_session_data *sd, char *varname, int elem, void *value, struct linkdb_node **ref);
131int run_script_timer(int tid, unsigned int tick, int id, intptr data);
132void run_script_main(struct script_state *st);
133
134void script_stop_sleeptimers(int id);
135struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n);
136void script_free_stack(struct script_stack*); 
137void script_free_code(struct script_code* code);
138void script_free_vars(struct linkdb_node **node);
139
140struct DBMap* script_get_label_db(void);
141struct DBMap* script_get_userfunc_db(void);
142
143int script_config_read(char *cfgName);
144int do_init_script(void);
145int do_final_script(void);
146int add_str(const char *p);
147int script_reload(void);
148
149extern char mapreg_txt[];
150
151#endif /* _SCRIPT_H_ */
Note: See TracBrowser for help on using the browser.