script.h 4.9 KB

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