script.h 20 KB

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