script.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. const char *die_event_name;
  127. const char *kill_pc_event_name;
  128. const char *kill_mob_event_name;
  129. const char *login_event_name;
  130. const char *logout_event_name;
  131. const char *loadmap_event_name;
  132. const char *baselvup_event_name;
  133. const char *joblvup_event_name;
  134. const char *stat_calc_event_name;
  135. const char* ontouch_name;
  136. const char* ontouch2_name;
  137. const char* onwhisper_event_name;
  138. } script_config;
  139. typedef enum c_op {
  140. C_NOP, // end of script/no value (nil)
  141. C_POS,
  142. C_INT, // number
  143. C_PARAM, // parameter variable (see pc_readparam/pc_setparam)
  144. C_FUNC, // buildin function call
  145. C_STR, // string (free'd automatically)
  146. C_CONSTSTR, // string (not free'd)
  147. C_ARG, // start of argument list
  148. C_NAME,
  149. C_EOL, // end of line (extra stack values are cleared)
  150. C_RETINFO,
  151. C_USERFUNC, // internal script function
  152. C_USERFUNC_POS, // internal script function label
  153. C_REF, // the next call to c_op2 should push back a ref to the left operand
  154. // operators
  155. C_OP3, // a ? b : c
  156. C_LOR, // a || b
  157. C_LAND, // a && b
  158. C_LE, // a <= b
  159. C_LT, // a < b
  160. C_GE, // a >= b
  161. C_GT, // a > b
  162. C_EQ, // a == b
  163. C_NE, // a != b
  164. C_XOR, // a ^ b
  165. C_OR, // a | b
  166. C_AND, // a & b
  167. C_ADD, // a + b
  168. C_SUB, // a - b
  169. C_MUL, // a * b
  170. C_DIV, // a / b
  171. C_MOD, // a % b
  172. C_NEG, // - a
  173. C_LNOT, // ! a
  174. C_NOT, // ~ a
  175. C_R_SHIFT, // a >> b
  176. C_L_SHIFT, // a << b
  177. C_ADD_POST, // a++
  178. C_SUB_POST, // a--
  179. C_ADD_PRE, // ++a
  180. C_SUB_PRE, // --a
  181. } c_op;
  182. /**
  183. * Generic reg database abstraction to be used with various types of regs/script variables.
  184. */
  185. struct reg_db {
  186. struct DBMap *vars;
  187. struct DBMap *arrays;
  188. };
  189. struct script_retinfo {
  190. struct reg_db scope; ///< scope variables
  191. struct script_code* script; ///< script code
  192. int pos; ///< script location
  193. int nargs; ///< argument count
  194. int defsp; ///< default stack pointer
  195. };
  196. struct script_data {
  197. enum c_op type;
  198. union script_data_val {
  199. int64 num;
  200. char *str;
  201. struct script_retinfo* ri;
  202. } u;
  203. struct reg_db *ref;
  204. };
  205. // Moved defsp from script_state to script_stack since
  206. // it must be saved when script state is RERUNLINE. [Eoe / jA 1094]
  207. struct script_code {
  208. int script_size;
  209. unsigned char* script_buf;
  210. struct reg_db local;
  211. unsigned short instances;
  212. };
  213. struct script_stack {
  214. int sp; ///< number of entries in the stack
  215. int sp_max; ///< capacity of the stack
  216. int defsp;
  217. struct script_data *stack_data; ///< stack
  218. struct reg_db scope; ///< scope variables
  219. };
  220. //
  221. // Script state
  222. //
  223. enum e_script_state { RUN,STOP,END,RERUNLINE,GOTO,RETFUNC,CLOSE };
  224. struct script_state {
  225. struct script_stack* stack;
  226. int start,end;
  227. int pos;
  228. enum e_script_state state;
  229. int rid,oid;
  230. struct script_code *script;
  231. struct sleep_data {
  232. int tick,timer,charid;
  233. } sleep;
  234. //For backing up purposes
  235. struct script_state *bk_st;
  236. int bk_npcid;
  237. unsigned freeloop : 1;// used by buildin_freeloop
  238. unsigned op2ref : 1;// used by op_2
  239. unsigned npc_item_flag : 1;
  240. unsigned mes_active : 1; // Store if invoking character has a NPC dialog box open.
  241. char* funcname; // Stores the current running function name
  242. unsigned int id;
  243. };
  244. struct script_reg {
  245. int64 index;
  246. int data;
  247. };
  248. struct script_regstr {
  249. int64 index;
  250. char* data;
  251. };
  252. struct script_array {
  253. unsigned int id; ///< the first 32b of the 64b uid, aka the id
  254. unsigned int size; ///< how many members
  255. unsigned int *members; ///< member list
  256. };
  257. enum script_parse_options {
  258. SCRIPT_USE_LABEL_DB = 0x1,// records labels in scriptlabel_db
  259. SCRIPT_IGNORE_EXTERNAL_BRACKETS = 0x2,// ignores the check for {} brackets around the script
  260. SCRIPT_RETURN_EMPTY_SCRIPT = 0x4// returns the script object instead of NULL for empty scripts
  261. };
  262. enum monsterinfo_types {
  263. MOB_NAME = 0,
  264. MOB_LV,
  265. MOB_MAXHP,
  266. MOB_BASEEXP,
  267. MOB_JOBEXP,
  268. MOB_ATK1,
  269. MOB_ATK2,
  270. MOB_DEF,
  271. MOB_MDEF,
  272. MOB_STR,
  273. MOB_AGI,
  274. MOB_VIT,
  275. MOB_INT,
  276. MOB_DEX,
  277. MOB_LUK,
  278. MOB_RANGE,
  279. MOB_RANGE2,
  280. MOB_RANGE3,
  281. MOB_SIZE,
  282. MOB_RACE,
  283. MOB_ELEMENT,
  284. MOB_MODE,
  285. MOB_MVPEXP
  286. };
  287. enum petinfo_types {
  288. PETINFO_ID = 0,
  289. PETINFO_CLASS,
  290. PETINFO_NAME,
  291. PETINFO_INTIMATE,
  292. PETINFO_HUNGRY,
  293. PETINFO_RENAMED,
  294. PETINFO_LEVEL,
  295. PETINFO_BLOCKID
  296. };
  297. enum questinfo_types {
  298. QTYPE_QUEST = 0,
  299. QTYPE_QUEST2,
  300. QTYPE_JOB,
  301. QTYPE_JOB2,
  302. QTYPE_EVENT,
  303. QTYPE_EVENT2,
  304. QTYPE_WARG,
  305. // 7 = free
  306. QTYPE_WARG2 = 8,
  307. // 9 - 9998 = free
  308. QTYPE_NONE = 9999
  309. };
  310. #ifndef WIN32
  311. // These are declared in wingdi.h
  312. /* Font Weights */
  313. #define FW_DONTCARE 0
  314. #define FW_THIN 100
  315. #define FW_EXTRALIGHT 200
  316. #define FW_LIGHT 300
  317. #define FW_NORMAL 400
  318. #define FW_MEDIUM 500
  319. #define FW_SEMIBOLD 600
  320. #define FW_BOLD 700
  321. #define FW_EXTRABOLD 800
  322. #define FW_HEAVY 900
  323. #endif
  324. enum getmapxy_types {
  325. UNITTYPE_PC = 0,
  326. UNITTYPE_NPC,
  327. UNITTYPE_PET,
  328. UNITTYPE_MOB,
  329. UNITTYPE_HOM,
  330. UNITTYPE_MER,
  331. UNITTYPE_ELEM,
  332. };
  333. enum unitdata_mobtypes {
  334. UMOB_SIZE = 0,
  335. UMOB_LEVEL,
  336. UMOB_HP,
  337. UMOB_MAXHP,
  338. UMOB_MASTERAID,
  339. UMOB_MAPID,
  340. UMOB_X,
  341. UMOB_Y,
  342. UMOB_SPEED,
  343. UMOB_MODE,
  344. UMOB_AI,
  345. UMOB_SCOPTION,
  346. UMOB_SEX,
  347. UMOB_CLASS,
  348. UMOB_HAIRSTYLE,
  349. UMOB_HAIRCOLOR,
  350. UMOB_HEADBOTTOM,
  351. UMOB_HEADMIDDLE,
  352. UMOB_HEADTOP,
  353. UMOB_CLOTHCOLOR,
  354. UMOB_SHIELD,
  355. UMOB_WEAPON,
  356. UMOB_LOOKDIR,
  357. UMOB_CANMOVETICK,
  358. UMOB_STR,
  359. UMOB_AGI,
  360. UMOB_VIT,
  361. UMOB_INT,
  362. UMOB_DEX,
  363. UMOB_LUK,
  364. UMOB_SLAVECPYMSTRMD,
  365. UMOB_DMGIMMUNE,
  366. UMOB_ATKRANGE,
  367. UMOB_ATKMIN,
  368. UMOB_ATKMAX,
  369. UMOB_MATKMIN,
  370. UMOB_MATKMAX,
  371. UMOB_DEF,
  372. UMOB_MDEF,
  373. UMOB_HIT,
  374. UMOB_FLEE,
  375. UMOB_PDODGE,
  376. UMOB_CRIT,
  377. UMOB_RACE,
  378. UMOB_ELETYPE,
  379. UMOB_ELELEVEL,
  380. UMOB_AMOTION,
  381. UMOB_ADELAY,
  382. UMOB_DMOTION,
  383. };
  384. enum unitdata_homuntypes {
  385. UHOM_SIZE = 0,
  386. UHOM_LEVEL,
  387. UHOM_HP,
  388. UHOM_MAXHP,
  389. UHOM_SP,
  390. UHOM_MAXSP,
  391. UHOM_MASTERCID,
  392. UHOM_MAPID,
  393. UHOM_X,
  394. UHOM_Y,
  395. UHOM_HUNGER,
  396. UHOM_INTIMACY,
  397. UHOM_SPEED,
  398. UHOM_LOOKDIR,
  399. UHOM_CANMOVETICK,
  400. UHOM_STR,
  401. UHOM_AGI,
  402. UHOM_VIT,
  403. UHOM_INT,
  404. UHOM_DEX,
  405. UHOM_LUK,
  406. UHOM_DMGIMMUNE,
  407. UHOM_ATKRANGE,
  408. UHOM_ATKMIN,
  409. UHOM_ATKMAX,
  410. UHOM_MATKMIN,
  411. UHOM_MATKMAX,
  412. UHOM_DEF,
  413. UHOM_MDEF,
  414. UHOM_HIT,
  415. UHOM_FLEE,
  416. UHOM_PDODGE,
  417. UHOM_CRIT,
  418. UHOM_RACE,
  419. UHOM_ELETYPE,
  420. UHOM_ELELEVEL,
  421. UHOM_AMOTION,
  422. UHOM_ADELAY,
  423. UHOM_DMOTION,
  424. };
  425. enum unitdata_pettypes {
  426. UPET_SIZE = 0,
  427. UPET_LEVEL,
  428. UPET_HP,
  429. UPET_MAXHP,
  430. UPET_MASTERAID,
  431. UPET_MAPID,
  432. UPET_X,
  433. UPET_Y,
  434. UPET_HUNGER,
  435. UPET_INTIMACY,
  436. UPET_SPEED,
  437. UPET_LOOKDIR,
  438. UPET_CANMOVETICK,
  439. UPET_STR,
  440. UPET_AGI,
  441. UPET_VIT,
  442. UPET_INT,
  443. UPET_DEX,
  444. UPET_LUK,
  445. UPET_DMGIMMUNE,
  446. UPET_ATKRANGE,
  447. UPET_ATKMIN,
  448. UPET_ATKMAX,
  449. UPET_MATKMIN,
  450. UPET_MATKMAX,
  451. UPET_DEF,
  452. UPET_MDEF,
  453. UPET_HIT,
  454. UPET_FLEE,
  455. UPET_PDODGE,
  456. UPET_CRIT,
  457. UPET_RACE,
  458. UPET_ELETYPE,
  459. UPET_ELELEVEL,
  460. UPET_AMOTION,
  461. UPET_ADELAY,
  462. UPET_DMOTION,
  463. };
  464. enum unitdata_merctypes {
  465. UMER_SIZE = 0,
  466. UMER_HP,
  467. UMER_MAXHP,
  468. UMER_MASTERCID,
  469. UMER_MAPID,
  470. UMER_X,
  471. UMER_Y,
  472. UMER_KILLCOUNT,
  473. UMER_LIFETIME,
  474. UMER_SPEED,
  475. UMER_LOOKDIR,
  476. UMER_CANMOVETICK,
  477. UMER_STR,
  478. UMER_AGI,
  479. UMER_VIT,
  480. UMER_INT,
  481. UMER_DEX,
  482. UMER_LUK,
  483. UMER_DMGIMMUNE,
  484. UMER_ATKRANGE,
  485. UMER_ATKMIN,
  486. UMER_ATKMAX,
  487. UMER_MATKMIN,
  488. UMER_MATKMAX,
  489. UMER_DEF,
  490. UMER_MDEF,
  491. UMER_HIT,
  492. UMER_FLEE,
  493. UMER_PDODGE,
  494. UMER_CRIT,
  495. UMER_RACE,
  496. UMER_ELETYPE,
  497. UMER_ELELEVEL,
  498. UMER_AMOTION,
  499. UMER_ADELAY,
  500. UMER_DMOTION,
  501. };
  502. enum unitdata_elemtypes {
  503. UELE_SIZE = 0,
  504. UELE_HP,
  505. UELE_MAXHP,
  506. UELE_SP,
  507. UELE_MAXSP,
  508. UELE_MASTERCID,
  509. UELE_MAPID,
  510. UELE_X,
  511. UELE_Y,
  512. UELE_LIFETIME,
  513. UELE_MODE,
  514. UELE_SPEED,
  515. UELE_LOOKDIR,
  516. UELE_CANMOVETICK,
  517. UELE_STR,
  518. UELE_AGI,
  519. UELE_VIT,
  520. UELE_INT,
  521. UELE_DEX,
  522. UELE_LUK,
  523. UELE_DMGIMMUNE,
  524. UELE_ATKRANGE,
  525. UELE_ATKMIN,
  526. UELE_ATKMAX,
  527. UELE_MATKMIN,
  528. UELE_MATKMAX,
  529. UELE_DEF,
  530. UELE_MDEF,
  531. UELE_HIT,
  532. UELE_FLEE,
  533. UELE_PDODGE,
  534. UELE_CRIT,
  535. UELE_RACE,
  536. UELE_ELETYPE,
  537. UELE_ELELEVEL,
  538. UELE_AMOTION,
  539. UELE_ADELAY,
  540. UELE_DMOTION,
  541. };
  542. enum unitdata_npctypes {
  543. UNPC_DISPLAY = 0,
  544. UNPC_LEVEL,
  545. UNPC_HP,
  546. UNPC_MAXHP,
  547. UNPC_MAPID,
  548. UNPC_X,
  549. UNPC_Y,
  550. UNPC_LOOKDIR,
  551. UNPC_STR,
  552. UNPC_AGI,
  553. UNPC_VIT,
  554. UNPC_INT,
  555. UNPC_DEX,
  556. UNPC_LUK,
  557. UNPC_PLUSALLSTAT,
  558. UNPC_DMGIMMUNE,
  559. UNPC_ATKRANGE,
  560. UNPC_ATKMIN,
  561. UNPC_ATKMAX,
  562. UNPC_MATKMIN,
  563. UNPC_MATKMAX,
  564. UNPC_DEF,
  565. UNPC_MDEF,
  566. UNPC_HIT,
  567. UNPC_FLEE,
  568. UNPC_PDODGE,
  569. UNPC_CRIT,
  570. UNPC_RACE,
  571. UNPC_ELETYPE,
  572. UNPC_ELELEVEL,
  573. UNPC_AMOTION,
  574. UNPC_ADELAY,
  575. UNPC_DMOTION,
  576. };
  577. enum navigation_service {
  578. NAV_NONE = 0, ///< 0
  579. NAV_AIRSHIP_ONLY = 1, ///< 1 (actually 1-9)
  580. NAV_SCROLL_ONLY = 10, ///< 10
  581. NAV_AIRSHIP_AND_SCROLL = NAV_AIRSHIP_ONLY + NAV_SCROLL_ONLY, ///< 11 (actually 11-99)
  582. NAV_KAFRA_ONLY = 100, ///< 100
  583. NAV_KAFRA_AND_AIRSHIP = NAV_KAFRA_ONLY + NAV_AIRSHIP_ONLY, ///< 101 (actually 101-109)
  584. NAV_KAFRA_AND_SCROLL = NAV_KAFRA_ONLY + NAV_SCROLL_ONLY, ///< 110
  585. NAV_ALL = NAV_AIRSHIP_ONLY + NAV_SCROLL_ONLY + NAV_KAFRA_ONLY ///< 111 (actually 111-255)
  586. };
  587. enum random_option_attribute {
  588. ROA_ID = 0,
  589. ROA_VALUE,
  590. ROA_PARAM,
  591. };
  592. /**
  593. * used to generate quick script_array entries
  594. **/
  595. struct eri *array_ers;
  596. DBMap *st_db;
  597. unsigned int active_scripts;
  598. unsigned int next_id;
  599. struct eri *st_ers;
  600. struct eri *stack_ers;
  601. const char* skip_space(const char* p);
  602. void script_error(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos);
  603. void script_warning(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos);
  604. struct script_code* parse_script(const char* src,const char* file,int line,int options);
  605. void run_script_sub(struct script_code *rootscript,int pos,int rid,int oid, char* file, int lineno);
  606. void run_script(struct script_code *rootscript,int pos,int rid,int oid);
  607. int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, const void* value, struct reg_db *ref);
  608. int set_var(struct map_session_data *sd, char *name, void *val);
  609. int conv_num(struct script_state *st,struct script_data *data);
  610. const char* conv_str(struct script_state *st,struct script_data *data);
  611. void pop_stack(struct script_state* st, int start, int end);
  612. int run_script_timer(int tid, unsigned int tick, int id, intptr_t data);
  613. void run_script_main(struct script_state *st);
  614. void script_stop_instances(struct script_code *code);
  615. struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n);
  616. void script_free_code(struct script_code* code);
  617. void script_free_vars(struct DBMap *storage);
  618. struct script_state* script_alloc_state(struct script_code* rootscript, int pos, int rid, int oid);
  619. void script_free_state(struct script_state* st);
  620. struct DBMap* script_get_label_db(void);
  621. struct DBMap* script_get_userfunc_db(void);
  622. void script_run_autobonus(const char *autobonus, struct map_session_data *sd, unsigned int pos);
  623. bool script_get_constant(const char* name, int* value);
  624. void script_set_constant(const char* name, int value, bool isparameter);
  625. void script_hardcoded_constants(void);
  626. void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value);
  627. void script_setarray_pc(struct map_session_data* sd, const char* varname, uint32 idx, void* value, int* refcache);
  628. int script_config_read(char *cfgName);
  629. void do_init_script(void);
  630. void do_final_script(void);
  631. int add_str(const char* p);
  632. const char* get_str(int id);
  633. void script_reload(void);
  634. // @commands (script based)
  635. void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct reg_db *ref);
  636. /**
  637. * Array Handling
  638. **/
  639. struct reg_db *script_array_src(struct script_state *st, struct map_session_data *sd, const char *name, struct reg_db *ref);
  640. void script_array_update(struct reg_db *src, int64 num, bool empty);
  641. void script_array_delete(struct reg_db *src, struct script_array *sa);
  642. void script_array_remove_member(struct reg_db *src, struct script_array *sa, unsigned int idx);
  643. void script_array_add_member(struct script_array *sa, unsigned int idx);
  644. unsigned int script_array_size(struct script_state *st, struct map_session_data *sd, const char *name, struct reg_db *ref);
  645. unsigned int script_array_highest_key(struct script_state *st, struct map_session_data *sd, const char *name, struct reg_db *ref);
  646. void script_array_ensure_zero(struct script_state *st, struct map_session_data *sd, int64 uid, struct reg_db *ref);
  647. int script_free_array_db(DBKey key, DBData *data, va_list ap);
  648. /* */
  649. void script_reg_destroy_single(struct map_session_data *sd, int64 reg, struct script_reg_state *data);
  650. int script_reg_destroy(DBKey key, DBData *data, va_list ap);
  651. /* */
  652. void script_generic_ui_array_expand(unsigned int plus);
  653. unsigned int *script_array_cpy_list(struct script_array *sa);
  654. #ifdef BETA_THREAD_TEST
  655. void queryThread_log(char * entry, int length);
  656. #endif
  657. #endif /* _SCRIPT_H_ */