OSDN Git Service

First version
[st-ro/stro.git] / src / map / script.h
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
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 #include "../common/cbasetypes.h"
12 #include "map.h"
13
14 #define NUM_WHISPER_VAR 10
15
16 ///////////////////////////////////////////////////////////////////////////////
17 //## TODO possible enhancements: [FlavioJS]
18 // - 'callfunc' supporting labels in the current npc "::LabelName"
19 // - 'callfunc' supporting labels in other npcs "NpcName::LabelName"
20 // - 'function FuncName;' function declarations reverting to global functions
21 //   if local label isn't found
22 // - join callfunc and callsub's functionality
23 // - remove dynamic allocation in add_word()
24 // - remove GETVALUE / SETVALUE
25 // - clean up the set_reg / set_val / setd_sub mess
26 // - detect invalid label references at parse-time
27
28 //
29 // struct script_state* st;
30 //
31
32 /// Returns the script_data at the target index
33 #define script_getdata(st,i) ( &((st)->stack->stack_data[(st)->start + (i)]) )
34 /// Returns if the stack contains data at the target index
35 #define script_hasdata(st,i) ( (st)->end > (st)->start + (i) )
36 /// Returns the index of the last data in the stack
37 #define script_lastdata(st) ( (st)->end - (st)->start - 1 )
38 /// Pushes an int into the stack
39 #define script_pushint(st,val) push_val((st)->stack, C_INT, (val))
40 /// Pushes a string into the stack (script engine frees it automatically)
41 #define script_pushstr(st,val) push_str((st)->stack, C_STR, (val))
42 /// Pushes a copy of a string into the stack
43 #define script_pushstrcopy(st,val) push_str((st)->stack, C_STR, aStrdup(val))
44 /// Pushes a constant string into the stack (must never change or be freed)
45 #define script_pushconststr(st,val) push_str((st)->stack, C_CONSTSTR, const_cast<char *>(val))
46 /// Pushes a nil into the stack
47 #define script_pushnil(st) push_val((st)->stack, C_NOP, 0)
48 /// Pushes a copy of the data in the target index
49 #define script_pushcopy(st,i) push_copy((st)->stack, (st)->start + (i))
50
51 #define script_isstring(st,i) data_isstring(script_getdata(st,i))
52 #define script_isint(st,i) data_isint(script_getdata(st,i))
53
54 #define script_getnum(st,val) conv_num(st, script_getdata(st,val))
55 #define script_getstr(st,val) conv_str(st, script_getdata(st,val))
56 #define script_getref(st,val) ( script_getdata(st,val)->ref )
57 // Returns name of currently running function
58 #define script_getfuncname(st) ( st->funcname )
59
60 // Note: "top" functions/defines use indexes relative to the top of the stack
61 //       -1 is the index of the data at the top
62
63 /// Returns the script_data at the target index relative to the top of the stack
64 #define script_getdatatop(st,i) ( &((st)->stack->stack_data[(st)->stack->sp + (i)]) )
65 /// Pushes a copy of the data in the target index relative to the top of the stack
66 #define script_pushcopytop(st,i) push_copy((st)->stack, (st)->stack->sp + (i))
67 /// Removes the range of values [start,end[ relative to the top of the stack
68 #define script_removetop(st,start,end) ( pop_stack((st), ((st)->stack->sp + (start)), (st)->stack->sp + (end)) )
69
70 //
71 // struct script_data* data;
72 //
73
74 /// Returns if the script data is a string
75 #define data_isstring(data) ( (data)->type == C_STR || (data)->type == C_CONSTSTR )
76 /// Returns if the script data is an int
77 #define data_isint(data) ( (data)->type == C_INT )
78 /// Returns if the script data is a reference
79 #define data_isreference(data) ( (data)->type == C_NAME )
80 /// Returns if the script data is a label
81 #define data_islabel(data) ( (data)->type == C_POS )
82 /// Returns if the script data is an internal script function label
83 #define data_isfunclabel(data) ( (data)->type == C_USERFUNC_POS )
84
85 /// Returns if this is a reference to a constant
86 #define reference_toconstant(data) ( str_data[reference_getid(data)].type == C_INT )
87 /// Returns if this a reference to a param
88 #define reference_toparam(data) ( str_data[reference_getid(data)].type == C_PARAM )
89 /// Returns if this a reference to a variable
90 //##TODO confirm it's C_NAME [FlavioJS]
91 #define reference_tovariable(data) ( str_data[reference_getid(data)].type == C_NAME )
92 /// Returns the unique id of the reference (id and index)
93 #define reference_getuid(data) ( (data)->u.num )
94 /// Returns the id of the reference
95 #define reference_getid(data) ( (int32)(int64)(reference_getuid(data) & 0xffffffff) )
96 /// Returns the array index of the reference
97 #define reference_getindex(data) ( (uint32)(int64)((reference_getuid(data) >> 32) & 0xffffffff) )
98 /// Returns the name of the reference
99 #define reference_getname(data) ( str_buf + str_data[reference_getid(data)].str )
100 /// Returns the linked list of uid-value pairs of the reference (can be NULL)
101 #define reference_getref(data) ( (data)->ref )
102 /// Returns the value of the constant
103 #define reference_getconstant(data) ( str_data[reference_getid(data)].val )
104 /// Returns the type of param
105 #define reference_getparamtype(data) ( str_data[reference_getid(data)].val )
106
107 /// Composes the uid of a reference from the id and the index
108 #define reference_uid(id,idx) ( (int64) ((uint64)(id) & 0xFFFFFFFF) | ((uint64)(idx) << 32) )
109
110 /// Checks whether two references point to the same variable (or array)
111 #define is_same_reference(data1, data2) \
112         (  reference_getid(data1) == reference_getid(data2) \
113         && ( (data1->ref == data2->ref && data1->ref == NULL) \
114           || (data1->ref != NULL && data2->ref != NULL && data1->ref->vars == data2->ref->vars \
115              ) ) )
116
117 #define script_getvarid(var) ( (int32)(int64)(var & 0xFFFFFFFF) )
118 #define script_getvaridx(var) ( (uint32)(int64)((var >> 32) & 0xFFFFFFFF) )
119
120 #define not_server_variable(prefix) ( (prefix) != '$' && (prefix) != '.' && (prefix) != '\'')
121 #define is_string_variable(name) ( (name)[strlen(name) - 1] == '$' )
122
123 #define FETCH(n, t) \
124                 if( script_hasdata(st,n) ) \
125                         (t)=script_getnum(st,n);
126
127 /// Maximum amount of elements in script arrays
128 #define SCRIPT_MAX_ARRAYSIZE (UINT_MAX - 1)
129
130 enum script_cmd_result {
131         SCRIPT_CMD_SUCCESS = 0, ///when a buildin cmd was correctly done
132         SCRIPT_CMD_FAILURE = 1, ///when an errors appear in cmd, show_debug will follow
133 };
134
135 #define SCRIPT_BLOCK_SIZE 512
136 enum { LABEL_NEXTLINE = 1, LABEL_START };
137
138 struct map_session_data;
139 struct eri;
140
141 extern int potion_flag; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
142 extern int potion_hp, potion_per_hp, potion_sp, potion_per_sp;
143 extern int potion_target;
144 extern unsigned int *generic_ui_array;
145 extern unsigned int generic_ui_array_size;
146
147 extern struct Script_Config {
148         unsigned warn_func_mismatch_argtypes : 1;
149         unsigned warn_func_mismatch_paramnum : 1;
150         int check_cmdcount;
151         int check_gotocount;
152         int input_min_value;
153         int input_max_value;
154
155         // PC related
156         const char *die_event_name;
157         const char *kill_pc_event_name;
158         const char *kill_mob_event_name;
159         const char *login_event_name;
160         const char *logout_event_name;
161         const char *loadmap_event_name;
162         const char *baselvup_event_name;
163         const char *joblvup_event_name;
164         const char *stat_calc_event_name;
165
166         // NPC related
167         const char* ontouch_event_name;
168         const char* ontouch2_event_name;
169         const char* ontouchnpc_event_name;
170         const char* onwhisper_event_name;
171         const char* oncommand_event_name;
172
173         // Init related
174         const char* init_event_name;
175         const char* inter_init_event_name;
176         const char* inter_init_once_event_name;
177
178         // Guild related
179         const char* guild_break_event_name;
180         const char* agit_start_event_name;
181         const char* agit_init_event_name;
182         const char* agit_end_event_name;
183         const char* agit_start2_event_name;
184         const char* agit_init2_event_name;
185         const char* agit_end2_event_name;
186         const char* agit_start3_event_name;
187         const char* agit_init3_event_name;
188         const char* agit_end3_event_name;
189
190         // Timer related
191         const char* timer_event_name;
192         const char* timer_minute_event_name;
193         const char* timer_hour_event_name;
194         const char* timer_clock_event_name;
195         const char* timer_day_event_name;
196         const char* timer_sunday_event_name;
197         const char* timer_monday_event_name;
198         const char* timer_tuesday_event_name;
199         const char* timer_wednesday_event_name;
200         const char* timer_thursday_event_name;
201         const char* timer_friday_event_name;
202         const char* timer_saturday_event_name;
203
204         // Instance related
205         const char* instance_init_event_name;
206         const char* instance_destroy_event_name;
207 } script_config;
208
209 typedef enum c_op {
210         C_NOP, // end of script/no value (nil)
211         C_POS,
212         C_INT, // number
213         C_PARAM, // parameter variable (see pc_readparam/pc_setparam)
214         C_FUNC, // buildin function call
215         C_STR, // string (free'd automatically)
216         C_CONSTSTR, // string (not free'd)
217         C_ARG, // start of argument list
218         C_NAME,
219         C_EOL, // end of line (extra stack values are cleared)
220         C_RETINFO,
221         C_USERFUNC, // internal script function
222         C_USERFUNC_POS, // internal script function label
223         C_REF, // the next call to c_op2 should push back a ref to the left operand
224
225         // operators
226         C_OP3, // a ? b : c
227         C_LOR, // a || b
228         C_LAND, // a && b
229         C_LE, // a <= b
230         C_LT, // a < b
231         C_GE, // a >= b
232         C_GT, // a > b
233         C_EQ, // a == b
234         C_NE, // a != b
235         C_XOR, // a ^ b
236         C_OR, // a | b
237         C_AND, // a & b
238         C_ADD, // a + b
239         C_SUB, // a - b
240         C_MUL, // a * b
241         C_DIV, // a / b
242         C_MOD, // a % b
243         C_NEG, // - a
244         C_LNOT, // ! a
245         C_NOT, // ~ a
246         C_R_SHIFT, // a >> b
247         C_L_SHIFT, // a << b
248         C_ADD_POST, // a++
249         C_SUB_POST, // a--
250         C_ADD_PRE, // ++a
251         C_SUB_PRE, // --a
252 } c_op;
253
254 /**
255  * Generic reg database abstraction to be used with various types of regs/script variables.
256  */
257 struct reg_db {
258         struct DBMap *vars;
259         struct DBMap *arrays;
260 };
261
262 struct script_retinfo {
263         struct reg_db scope;        ///< scope variables
264         struct script_code* script; ///< script code
265         int pos;                    ///< script location
266         int nargs;                  ///< argument count
267         int defsp;                  ///< default stack pointer
268 };
269
270 struct script_data {
271         enum c_op type;
272         union script_data_val {
273                 int64 num;
274                 char *str;
275                 struct script_retinfo* ri;
276         } u;
277         struct reg_db *ref;
278 };
279
280 // Moved defsp from script_state to script_stack since
281 // it must be saved when script state is RERUNLINE. [Eoe / jA 1094]
282 struct script_code {
283         int script_size;
284         unsigned char* script_buf;
285         struct reg_db local;
286         unsigned short instances;
287 };
288
289 struct script_stack {
290         int sp;                         ///< number of entries in the stack
291         int sp_max;                     ///< capacity of the stack
292         int defsp;
293         struct script_data *stack_data; ///< stack
294         struct reg_db scope;            ///< scope variables
295 };
296
297
298 //
299 // Script state
300 //
301 enum e_script_state { RUN,STOP,END,RERUNLINE,GOTO,RETFUNC,CLOSE };
302
303 struct script_state {
304         struct script_stack* stack;
305         int start,end;
306         int pos;
307         enum e_script_state state;
308         int rid,oid;
309         struct script_code *script;
310         struct sleep_data {
311                 int tick,timer,charid;
312         } sleep;
313         //For backing up purposes
314         struct script_state *bk_st;
315         int bk_npcid;
316         unsigned freeloop : 1;// used by buildin_freeloop
317         unsigned op2ref : 1;// used by op_2
318         unsigned npc_item_flag : 1;
319         unsigned mes_active : 1;  // Store if invoking character has a NPC dialog box open.
320         char* funcname; // Stores the current running function name
321         unsigned int id;
322 };
323
324 struct script_reg {
325         int64 index;
326         int data;
327 };
328
329 struct script_regstr {
330         int64 index;
331         char* data;
332 };
333
334 struct script_array {
335         unsigned int id;       ///< the first 32b of the 64b uid, aka the id
336         unsigned int size;     ///< how many members
337         unsigned int *members; ///< member list
338 };
339
340 enum script_parse_options {
341         SCRIPT_USE_LABEL_DB = 0x1,// records labels in scriptlabel_db
342         SCRIPT_IGNORE_EXTERNAL_BRACKETS = 0x2,// ignores the check for {} brackets around the script
343         SCRIPT_RETURN_EMPTY_SCRIPT = 0x4// returns the script object instead of NULL for empty scripts
344 };
345
346 enum monsterinfo_types {
347         MOB_NAME = 0,
348         MOB_LV,
349         MOB_MAXHP,
350         MOB_BASEEXP,
351         MOB_JOBEXP,
352         MOB_ATK1,
353         MOB_ATK2,
354         MOB_DEF,
355         MOB_MDEF,
356         MOB_STR,
357         MOB_AGI,
358         MOB_VIT,
359         MOB_INT,
360         MOB_DEX,
361         MOB_LUK,
362         MOB_RANGE,
363         MOB_RANGE2,
364         MOB_RANGE3,
365         MOB_SIZE,
366         MOB_RACE,
367         MOB_ELEMENT,
368         MOB_MODE,
369         MOB_MVPEXP
370 };
371
372 enum petinfo_types {
373         PETINFO_ID = 0,
374         PETINFO_CLASS,
375         PETINFO_NAME,
376         PETINFO_INTIMATE,
377         PETINFO_HUNGRY,
378         PETINFO_RENAMED,
379         PETINFO_LEVEL,
380         PETINFO_BLOCKID
381 };
382
383 enum questinfo_types {
384         QTYPE_QUEST = 0,
385         QTYPE_QUEST2,
386         QTYPE_JOB,
387         QTYPE_JOB2,
388         QTYPE_EVENT,
389         QTYPE_EVENT2,
390         QTYPE_WARG,
391         // 7 = free
392         QTYPE_WARG2 = 8,
393         // 9 - 9998 = free
394         QTYPE_NONE = 9999
395 };
396
397 #ifndef WIN32
398         // These are declared in wingdi.h
399         /* Font Weights */
400         #define FW_DONTCARE         0
401         #define FW_THIN             100
402         #define FW_EXTRALIGHT       200
403         #define FW_LIGHT            300
404         #define FW_NORMAL           400
405         #define FW_MEDIUM           500
406         #define FW_SEMIBOLD         600
407         #define FW_BOLD             700
408         #define FW_EXTRABOLD        800
409         #define FW_HEAVY            900
410 #endif
411
412 enum getmapxy_types {
413         UNITTYPE_PC = 0,
414         UNITTYPE_NPC,
415         UNITTYPE_PET,
416         UNITTYPE_MOB,
417         UNITTYPE_HOM,
418         UNITTYPE_MER,
419         UNITTYPE_ELEM,
420 };
421
422 enum unitdata_mobtypes {
423         UMOB_SIZE = 0,
424         UMOB_LEVEL,
425         UMOB_HP,
426         UMOB_MAXHP,
427         UMOB_MASTERAID,
428         UMOB_MAPID,
429         UMOB_X,
430         UMOB_Y,
431         UMOB_SPEED,
432         UMOB_MODE,
433         UMOB_AI,
434         UMOB_SCOPTION,
435         UMOB_SEX,
436         UMOB_CLASS,
437         UMOB_HAIRSTYLE,
438         UMOB_HAIRCOLOR,
439         UMOB_HEADBOTTOM,
440         UMOB_HEADMIDDLE,
441         UMOB_HEADTOP,
442         UMOB_CLOTHCOLOR,
443         UMOB_SHIELD,
444         UMOB_WEAPON,
445         UMOB_LOOKDIR,
446         UMOB_CANMOVETICK,
447         UMOB_STR,
448         UMOB_AGI,
449         UMOB_VIT,
450         UMOB_INT,
451         UMOB_DEX,
452         UMOB_LUK,
453         UMOB_SLAVECPYMSTRMD,
454         UMOB_DMGIMMUNE,
455         UMOB_ATKRANGE,
456         UMOB_ATKMIN,
457         UMOB_ATKMAX,
458         UMOB_MATKMIN,
459         UMOB_MATKMAX,
460         UMOB_DEF,
461         UMOB_MDEF,
462         UMOB_HIT,
463         UMOB_FLEE,
464         UMOB_PDODGE,
465         UMOB_CRIT,
466         UMOB_RACE,
467         UMOB_ELETYPE,
468         UMOB_ELELEVEL,
469         UMOB_AMOTION,
470         UMOB_ADELAY,
471         UMOB_DMOTION,
472 };
473
474 enum unitdata_homuntypes {
475         UHOM_SIZE = 0,
476         UHOM_LEVEL,
477         UHOM_HP,
478         UHOM_MAXHP,
479         UHOM_SP,
480         UHOM_MAXSP,
481         UHOM_MASTERCID,
482         UHOM_MAPID,
483         UHOM_X,
484         UHOM_Y,
485         UHOM_HUNGER,
486         UHOM_INTIMACY,
487         UHOM_SPEED,
488         UHOM_LOOKDIR,
489         UHOM_CANMOVETICK,
490         UHOM_STR,
491         UHOM_AGI,
492         UHOM_VIT,
493         UHOM_INT,
494         UHOM_DEX,
495         UHOM_LUK,
496         UHOM_DMGIMMUNE,
497         UHOM_ATKRANGE,
498         UHOM_ATKMIN,
499         UHOM_ATKMAX,
500         UHOM_MATKMIN,
501         UHOM_MATKMAX,
502         UHOM_DEF,
503         UHOM_MDEF,
504         UHOM_HIT,
505         UHOM_FLEE,
506         UHOM_PDODGE,
507         UHOM_CRIT,
508         UHOM_RACE,
509         UHOM_ELETYPE,
510         UHOM_ELELEVEL,
511         UHOM_AMOTION,
512         UHOM_ADELAY,
513         UHOM_DMOTION,
514 };
515
516 enum unitdata_pettypes {
517         UPET_SIZE = 0,
518         UPET_LEVEL,
519         UPET_HP,
520         UPET_MAXHP,
521         UPET_MASTERAID,
522         UPET_MAPID,
523         UPET_X,
524         UPET_Y,
525         UPET_HUNGER,
526         UPET_INTIMACY,
527         UPET_SPEED,
528         UPET_LOOKDIR,
529         UPET_CANMOVETICK,
530         UPET_STR,
531         UPET_AGI,
532         UPET_VIT,
533         UPET_INT,
534         UPET_DEX,
535         UPET_LUK,
536         UPET_DMGIMMUNE,
537         UPET_ATKRANGE,
538         UPET_ATKMIN,
539         UPET_ATKMAX,
540         UPET_MATKMIN,
541         UPET_MATKMAX,
542         UPET_DEF,
543         UPET_MDEF,
544         UPET_HIT,
545         UPET_FLEE,
546         UPET_PDODGE,
547         UPET_CRIT,
548         UPET_RACE,
549         UPET_ELETYPE,
550         UPET_ELELEVEL,
551         UPET_AMOTION,
552         UPET_ADELAY,
553         UPET_DMOTION,
554 };
555
556 enum unitdata_merctypes {
557         UMER_SIZE = 0,
558         UMER_HP,
559         UMER_MAXHP,
560         UMER_MASTERCID,
561         UMER_MAPID,
562         UMER_X,
563         UMER_Y,
564         UMER_KILLCOUNT,
565         UMER_LIFETIME,
566         UMER_SPEED,
567         UMER_LOOKDIR,
568         UMER_CANMOVETICK,
569         UMER_STR,
570         UMER_AGI,
571         UMER_VIT,
572         UMER_INT,
573         UMER_DEX,
574         UMER_LUK,
575         UMER_DMGIMMUNE,
576         UMER_ATKRANGE,
577         UMER_ATKMIN,
578         UMER_ATKMAX,
579         UMER_MATKMIN,
580         UMER_MATKMAX,
581         UMER_DEF,
582         UMER_MDEF,
583         UMER_HIT,
584         UMER_FLEE,
585         UMER_PDODGE,
586         UMER_CRIT,
587         UMER_RACE,
588         UMER_ELETYPE,
589         UMER_ELELEVEL,
590         UMER_AMOTION,
591         UMER_ADELAY,
592         UMER_DMOTION,
593 };
594
595 enum unitdata_elemtypes {
596         UELE_SIZE = 0,
597         UELE_HP,
598         UELE_MAXHP,
599         UELE_SP,
600         UELE_MAXSP,
601         UELE_MASTERCID,
602         UELE_MAPID,
603         UELE_X,
604         UELE_Y,
605         UELE_LIFETIME,
606         UELE_MODE,
607         UELE_SPEED,
608         UELE_LOOKDIR,
609         UELE_CANMOVETICK,
610         UELE_STR,
611         UELE_AGI,
612         UELE_VIT,
613         UELE_INT,
614         UELE_DEX,
615         UELE_LUK,
616         UELE_DMGIMMUNE,
617         UELE_ATKRANGE,
618         UELE_ATKMIN,
619         UELE_ATKMAX,
620         UELE_MATKMIN,
621         UELE_MATKMAX,
622         UELE_DEF,
623         UELE_MDEF,
624         UELE_HIT,
625         UELE_FLEE,
626         UELE_PDODGE,
627         UELE_CRIT,
628         UELE_RACE,
629         UELE_ELETYPE,
630         UELE_ELELEVEL,
631         UELE_AMOTION,
632         UELE_ADELAY,
633         UELE_DMOTION,
634 };
635
636 enum unitdata_npctypes {
637         UNPC_DISPLAY = 0,
638         UNPC_LEVEL,
639         UNPC_HP,
640         UNPC_MAXHP,
641         UNPC_MAPID,
642         UNPC_X,
643         UNPC_Y,
644         UNPC_LOOKDIR,
645         UNPC_STR,
646         UNPC_AGI,
647         UNPC_VIT,
648         UNPC_INT,
649         UNPC_DEX,
650         UNPC_LUK,
651         UNPC_PLUSALLSTAT,
652         UNPC_DMGIMMUNE,
653         UNPC_ATKRANGE,
654         UNPC_ATKMIN,
655         UNPC_ATKMAX,
656         UNPC_MATKMIN,
657         UNPC_MATKMAX,
658         UNPC_DEF,
659         UNPC_MDEF,
660         UNPC_HIT,
661         UNPC_FLEE,
662         UNPC_PDODGE,
663         UNPC_CRIT,
664         UNPC_RACE,
665         UNPC_ELETYPE,
666         UNPC_ELELEVEL,
667         UNPC_AMOTION,
668         UNPC_ADELAY,
669         UNPC_DMOTION,
670 };
671
672 enum navigation_service {
673         NAV_NONE = 0, ///< 0
674         NAV_AIRSHIP_ONLY = 1, ///< 1 (actually 1-9)
675         NAV_SCROLL_ONLY = 10, ///< 10
676         NAV_AIRSHIP_AND_SCROLL = NAV_AIRSHIP_ONLY + NAV_SCROLL_ONLY, ///< 11 (actually 11-99)
677         NAV_KAFRA_ONLY = 100, ///< 100
678         NAV_KAFRA_AND_AIRSHIP = NAV_KAFRA_ONLY + NAV_AIRSHIP_ONLY, ///< 101 (actually 101-109)
679         NAV_KAFRA_AND_SCROLL = NAV_KAFRA_ONLY + NAV_SCROLL_ONLY, ///< 110
680         NAV_ALL = NAV_AIRSHIP_ONLY + NAV_SCROLL_ONLY + NAV_KAFRA_ONLY ///< 111 (actually 111-255)
681 };
682
683 enum random_option_attribute {
684         ROA_ID = 0,
685         ROA_VALUE,
686         ROA_PARAM,
687 };
688
689 enum instance_info_type {
690         IIT_ID,
691         IIT_TIME_LIMIT,
692         IIT_IDLE_TIMEOUT,
693         IIT_ENTER_MAP,
694         IIT_ENTER_X,
695         IIT_ENTER_Y,
696         IIT_MAPCOUNT,
697         IIT_MAP
698 };
699
700 enum vip_status_type {
701         VIP_STATUS_ACTIVE = 1,
702         VIP_STATUS_EXPIRE,
703         VIP_STATUS_REMAINING
704 };
705
706 /**
707  * used to generate quick script_array entries
708  **/
709 extern struct eri *array_ers;
710 extern DBMap *st_db;
711 extern unsigned int active_scripts;
712 extern unsigned int next_id;
713 extern struct eri *st_ers;
714 extern struct eri *stack_ers;
715
716 const char* skip_space(const char* p);
717 void script_error(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos);
718 void script_warning(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos);
719
720 bool is_number(const char *p);
721 struct script_code* parse_script(const char* src,const char* file,int line,int options);
722 void run_script(struct script_code *rootscript,int pos,int rid,int oid);
723
724 int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, const void* value, struct reg_db *ref);
725 int set_var(struct map_session_data *sd, char *name, void *val);
726 int conv_num(struct script_state *st,struct script_data *data);
727 const char* conv_str(struct script_state *st,struct script_data *data);
728 void pop_stack(struct script_state* st, int start, int end);
729 int run_script_timer(int tid, unsigned int tick, int id, intptr_t data);
730 void script_stop_sleeptimers(int id);
731 struct linkdb_node *script_erase_sleepdb(struct linkdb_node *n);
732 void run_script_main(struct script_state *st);
733
734 void script_stop_scriptinstances(struct script_code *code);
735 void script_free_code(struct script_code* code);
736 void script_free_vars(struct DBMap *storage);
737 struct script_state* script_alloc_state(struct script_code* rootscript, int pos, int rid, int oid);
738 void script_free_state(struct script_state* st);
739
740 struct DBMap* script_get_label_db(void);
741 struct DBMap* script_get_userfunc_db(void);
742 void script_run_autobonus(const char *autobonus, struct map_session_data *sd, unsigned int pos);
743
744 bool script_get_parameter(const char* name, int* value);
745 bool script_get_constant(const char* name, int* value);
746 void script_set_constant(const char* name, int value, bool isparameter, bool deprecated);
747 void script_hardcoded_constants(void);
748
749 void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value);
750 void script_setarray_pc(struct map_session_data* sd, const char* varname, uint32 idx, void* value, int* refcache);
751
752 int script_config_read(const char *cfgName);
753 void do_init_script(void);
754 void do_final_script(void);
755 int add_str(const char* p);
756 const char* get_str(int id);
757 void script_reload(void);
758
759 // @commands (script based)
760 void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct reg_db *ref);
761
762 /**
763  * Array Handling
764  **/
765 struct reg_db *script_array_src(struct script_state *st, struct map_session_data *sd, const char *name, struct reg_db *ref);
766 void script_array_update(struct reg_db *src, int64 num, bool empty);
767 void script_array_delete(struct reg_db *src, struct script_array *sa);
768 void script_array_remove_member(struct reg_db *src, struct script_array *sa, unsigned int idx);
769 void script_array_add_member(struct script_array *sa, unsigned int idx);
770 unsigned int script_array_size(struct script_state *st, struct map_session_data *sd, const char *name, struct reg_db *ref);
771 unsigned int script_array_highest_key(struct script_state *st, struct map_session_data *sd, const char *name, struct reg_db *ref);
772 void script_array_ensure_zero(struct script_state *st, struct map_session_data *sd, int64 uid, struct reg_db *ref);
773 int script_free_array_db(DBKey key, DBData *data, va_list ap);
774 /* */
775 void script_reg_destroy_single(struct map_session_data *sd, int64 reg, struct script_reg_state *data);
776 int script_reg_destroy(DBKey key, DBData *data, va_list ap);
777 /* */
778 void script_generic_ui_array_expand(unsigned int plus);
779 unsigned int *script_array_cpy_list(struct script_array *sa);
780
781 #ifdef BETA_THREAD_TEST
782 void queryThread_log(char * entry, int length);
783 #endif
784
785 #ifdef __cplusplus
786 }
787 #endif
788
789 #endif /* _SCRIPT_H_ */