unit.hpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef UNIT_HPP
  4. #define UNIT_HPP
  5. #include <common/cbasetypes.hpp>
  6. #include <common/timer.hpp>
  7. #include "path.hpp" // struct walkpath_data
  8. #include "skill.hpp" // struct skill_timerskill, struct skill_unit_group, struct skill_unit_group_tickset
  9. enum sc_type : int16;
  10. struct block_list;
  11. struct unit_data;
  12. class map_session_data;
  13. enum clr_type : uint8;
  14. extern const int16 dirx[DIR_MAX]; ///lookup to know where will move to x according dir
  15. extern const int16 diry[DIR_MAX]; ///lookup to know where will move to y according dir
  16. struct unit_data {
  17. struct block_list *bl; ///link to owner object BL_PC|BL_MOB|BL_PET|BL_NPC|BL_HOM|BL_MER|BL_ELEM
  18. struct walkpath_data walkpath;
  19. struct skill_timerskill *skilltimerskill[MAX_SKILLTIMERSKILL];
  20. std::vector<std::shared_ptr<s_skill_unit_group>> skillunits;
  21. struct skill_unit_group_tickset skillunittick[MAX_SKILLUNITGROUPTICKSET];
  22. int16 attacktarget_lv;
  23. int16 to_x, to_y;
  24. uint8 sx, sy; // Subtile position (0-15, with 8 being center of cell)
  25. int16 skillx, skilly;
  26. uint16 skill_id, skill_lv;
  27. int32 skilltarget;
  28. int32 skilltimer;
  29. int32 target;
  30. int32 target_to;
  31. int32 attacktimer;
  32. int32 walktimer;
  33. int32 chaserange;
  34. bool stepaction; //Action should be executed on step [Playtester]
  35. int32 steptimer; //Timer that triggers the action [Playtester]
  36. uint16 stepskill_id, stepskill_lv; //Remembers skill that should be casted on step [Playtester]
  37. t_tick attackabletime;
  38. t_tick canact_tick;
  39. t_tick canmove_tick;
  40. bool immune_attack; ///< Whether the unit is immune to attacks
  41. uint8 dir;
  42. unsigned char target_count;
  43. struct s_udState {
  44. unsigned change_walk_target : 1 ;
  45. unsigned skillcastcancel : 1 ;
  46. unsigned attack_continue : 1 ;
  47. unsigned step_attack : 1;
  48. unsigned walk_easy : 1 ;
  49. unsigned running : 1;
  50. unsigned walk_script : 1;
  51. unsigned blockedmove : 1;
  52. unsigned blockedskill : 1;
  53. unsigned ignore_cell_stack_limit : 1;
  54. bool force_walk; ///< Used with script commands unitwalk/unitwalkto. Disables monster idle and random walk.
  55. } state;
  56. char walk_done_event[EVENT_NAME_LENGTH];
  57. char title[NAME_LENGTH];
  58. int32 group_id;
  59. std::vector<int32> shadow_scar_timer;
  60. };
  61. struct view_data {
  62. uint16 class_;
  63. t_itemid
  64. weapon,
  65. shield, //Or left-hand weapon.
  66. robe,
  67. head_top,
  68. head_mid,
  69. head_bottom;
  70. uint16
  71. hair_style,
  72. hair_color,
  73. cloth_color,
  74. body_style;
  75. char sex;
  76. unsigned dead_sit : 2; // 0: Standing, 1: Dead, 2: Sitting
  77. };
  78. /// Enum for unit_blown_immune
  79. enum e_unit_blown {
  80. UB_KNOCKABLE = 0, // Can be knocked back / stopped
  81. UB_NO_KNOCKBACK_MAP, // On a WoE/BG map
  82. UB_MD_KNOCKBACK_IMMUNE, // Target is MD_KNOCKBACK_IMMUNE
  83. UB_TARGET_BASILICA, // Target is in Basilica area
  84. UB_TARGET_NO_KNOCKBACK, // Target has 'special_state.no_knockback'
  85. UB_TARGET_TRAP, // Target is a trap that cannot be knocked back
  86. };
  87. /// Enum for unit_stop_walking
  88. enum e_unit_stop_walking {
  89. USW_NONE = 0x0, /// Unit will keep walking to their original destination
  90. USW_FIXPOS = 0x1, /// Issue a fixpos packet afterwards
  91. USW_MOVE_ONCE = 0x2, /// Force the unit to move one cell if it hasn't yet
  92. USW_MOVE_FULL_CELL = 0x4, /// Enable moving to the next cell when unit was already half-way there (may cause on-touch/place side-effects, such as a scripted map change)
  93. USW_FORCE_STOP = 0x8, /// Force stop moving, even if walktimer is currently INVALID_TIMER
  94. USW_RELEASE_TARGET = 0x10, /// Release chase target
  95. USW_ALL = 0x1f,
  96. };
  97. // PC, MOB, PET
  98. // Does walk action for unit
  99. int32 unit_walktoxy(struct block_list *bl, int16 x, int16 y, unsigned char flag);
  100. int32 unit_walktobl(struct block_list *bl, struct block_list *target, int32 range, unsigned char flag);
  101. void unit_run_hit(struct block_list *bl, status_change *sc, map_session_data *sd, enum sc_type type);
  102. bool unit_run(struct block_list *bl, map_session_data *sd, enum sc_type type);
  103. int32 unit_calc_pos(struct block_list *bl, int32 tx, int32 ty, uint8 dir);
  104. TIMER_FUNC(unit_delay_walktoxy_timer);
  105. TIMER_FUNC(unit_delay_walktobl_timer);
  106. void unit_stop_walking_soon(struct block_list& bl);
  107. // Causes the target object to stop moving.
  108. bool unit_stop_walking( block_list* bl, int32 type, t_tick canmove_delay = 0 );
  109. bool unit_can_move(struct block_list *bl);
  110. int32 unit_is_walking(struct block_list *bl);
  111. int32 unit_set_walkdelay(struct block_list *bl, t_tick tick, t_tick delay, int32 type);
  112. t_tick unit_get_walkpath_time(struct block_list& bl);
  113. t_tick unit_escape(struct block_list *bl, struct block_list *target, int16 dist, uint8 flag = 0);
  114. // Instant unit changes
  115. bool unit_movepos(struct block_list *bl, int16 dst_x, int16 dst_y, int32 easy, bool checkpath);
  116. int32 unit_warp(struct block_list *bl, int16 map, int16 x, int16 y, clr_type type);
  117. bool unit_setdir(block_list *bl, uint8 dir, bool send_update = true);
  118. uint8 unit_getdir(struct block_list *bl);
  119. int32 unit_blown(struct block_list* bl, int32 dx, int32 dy, int32 count, enum e_skill_blown flag);
  120. enum e_unit_blown unit_blown_immune(struct block_list* bl, uint8 flag);
  121. // Can-reach checks
  122. bool unit_can_reach_pos(struct block_list *bl,int32 x,int32 y,int32 easy);
  123. bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int32 range, int32 easy, int16 *x, int16 *y);
  124. // Unit attack functions
  125. int32 unit_stopattack(struct block_list *bl, va_list ap);
  126. void unit_stop_attack(struct block_list *bl);
  127. int32 unit_attack(struct block_list *src,int32 target_id,int32 continuous);
  128. int32 unit_cancel_combo(struct block_list *bl);
  129. bool unit_can_attack(struct block_list *bl, int32 target_id);
  130. // Cast on a unit
  131. int32 unit_skilluse_id(struct block_list *src, int32 target_id, uint16 skill_id, uint16 skill_lv);
  132. int32 unit_skilluse_pos(struct block_list *src, int16 skill_x, int16 skill_y, uint16 skill_id, uint16 skill_lv);
  133. int32 unit_skilluse_id2(struct block_list *src, int32 target_id, uint16 skill_id, uint16 skill_lv, int32 casttime, int32 castcancel, bool ignore_range = false);
  134. int32 unit_skilluse_pos2( struct block_list *src, int16 skill_x, int16 skill_y, uint16 skill_id, uint16 skill_lv, int32 casttime, int32 castcancel, bool ignore_range = false);
  135. // Step timer used for delayed attack and skill use
  136. TIMER_FUNC(unit_step_timer);
  137. void unit_stop_stepaction(struct block_list *bl);
  138. // Cancel unit cast
  139. int32 unit_skillcastcancel(struct block_list *bl, char type);
  140. int32 unit_counttargeted(struct block_list *bl);
  141. int32 unit_set_target(struct unit_data* ud, int32 target_id);
  142. // unit_data
  143. void unit_dataset(struct block_list *bl);
  144. void unit_skillunit_maxcount(unit_data& ud, uint16 skill_id, int& maxcount);
  145. // Remove unit
  146. struct unit_data* unit_bl2ud(struct block_list *bl);
  147. void unit_remove_map_pc(map_session_data *sd, clr_type clrtype);
  148. void unit_refresh(struct block_list *bl, bool walking = false);
  149. void unit_free_pc(map_session_data *sd);
  150. #define unit_remove_map(bl,clrtype) unit_remove_map_(bl,clrtype,__FILE__,__LINE__,__func__)
  151. int32 unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file, int32 line, const char* func);
  152. int32 unit_free(struct block_list *bl, clr_type clrtype);
  153. int32 unit_changetarget(block_list *bl,va_list ap);
  154. void unit_changetarget_sub(unit_data& ud, block_list& target);
  155. // Shadow Scar
  156. void unit_addshadowscar(unit_data &ud, int32 interval);
  157. void do_init_unit(void);
  158. void do_final_unit(void);
  159. #endif /* UNIT_HPP */