unit.hpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 short dirx[DIR_MAX]; ///lookup to know where will move to x according dir
  15. extern const short 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. short attacktarget_lv;
  23. short to_x, to_y;
  24. short skillx, skilly;
  25. uint16 skill_id, skill_lv;
  26. int skilltarget;
  27. int skilltimer;
  28. int target;
  29. int target_to;
  30. int attacktimer;
  31. int walktimer;
  32. int chaserange;
  33. bool stepaction; //Action should be executed on step [Playtester]
  34. int steptimer; //Timer that triggers the action [Playtester]
  35. uint16 stepskill_id, stepskill_lv; //Remembers skill that should be casted on step [Playtester]
  36. t_tick attackabletime;
  37. t_tick canact_tick;
  38. t_tick canmove_tick;
  39. bool immune_attack; ///< Whether the unit is immune to attacks
  40. uint8 dir;
  41. unsigned char target_count;
  42. struct s_udState {
  43. unsigned change_walk_target : 1 ;
  44. unsigned skillcastcancel : 1 ;
  45. unsigned attack_continue : 1 ;
  46. unsigned step_attack : 1;
  47. unsigned walk_easy : 1 ;
  48. unsigned running : 1;
  49. unsigned speed_changed : 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<int> 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_ALL = 0xf,
  95. };
  96. // PC, MOB, PET
  97. // Does walk action for unit
  98. int unit_walktoxy(struct block_list *bl, short x, short y, unsigned char flag);
  99. int unit_walktobl(struct block_list *bl, struct block_list *target, int range, unsigned char flag);
  100. void unit_run_hit(struct block_list *bl, status_change *sc, map_session_data *sd, enum sc_type type);
  101. bool unit_run(struct block_list *bl, map_session_data *sd, enum sc_type type);
  102. int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir);
  103. TIMER_FUNC(unit_delay_walktoxy_timer);
  104. TIMER_FUNC(unit_delay_walktobl_timer);
  105. // Causes the target object to stop moving.
  106. int unit_stop_walking(struct block_list *bl,int type);
  107. bool unit_can_move(struct block_list *bl);
  108. int unit_is_walking(struct block_list *bl);
  109. int unit_set_walkdelay(struct block_list *bl, t_tick tick, t_tick delay, int type);
  110. t_tick unit_get_walkpath_time(struct block_list& bl);
  111. t_tick unit_escape(struct block_list *bl, struct block_list *target, short dist, uint8 flag = 0);
  112. // Instant unit changes
  113. bool unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath);
  114. int unit_warp(struct block_list *bl, short map, short x, short y, clr_type type);
  115. bool unit_setdir(block_list *bl, uint8 dir, bool send_update = true);
  116. uint8 unit_getdir(struct block_list *bl);
  117. int unit_blown(struct block_list* bl, int dx, int dy, int count, enum e_skill_blown flag);
  118. enum e_unit_blown unit_blown_immune(struct block_list* bl, uint8 flag);
  119. // Can-reach checks
  120. bool unit_can_reach_pos(struct block_list *bl,int x,int y,int easy);
  121. bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range, int easy, short *x, short *y);
  122. // Unit attack functions
  123. int unit_stopattack(struct block_list *bl, va_list ap);
  124. void unit_stop_attack(struct block_list *bl);
  125. int unit_attack(struct block_list *src,int target_id,int continuous);
  126. int unit_cancel_combo(struct block_list *bl);
  127. bool unit_can_attack(struct block_list *bl, int target_id);
  128. // Cast on a unit
  129. int unit_skilluse_id(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv);
  130. int unit_skilluse_pos(struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv);
  131. int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel, bool ignore_range = false);
  132. int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel, bool ignore_range = false);
  133. // Step timer used for delayed attack and skill use
  134. TIMER_FUNC(unit_step_timer);
  135. void unit_stop_stepaction(struct block_list *bl);
  136. // Cancel unit cast
  137. int unit_skillcastcancel(struct block_list *bl, char type);
  138. int unit_counttargeted(struct block_list *bl);
  139. int unit_set_target(struct unit_data* ud, int target_id);
  140. // unit_data
  141. void unit_dataset(struct block_list *bl);
  142. void unit_skillunit_maxcount(unit_data& ud, uint16 skill_id, int& maxcount);
  143. // Remove unit
  144. struct unit_data* unit_bl2ud(struct block_list *bl);
  145. void unit_remove_map_pc(map_session_data *sd, clr_type clrtype);
  146. void unit_refresh(struct block_list *bl, bool walking = false);
  147. void unit_free_pc(map_session_data *sd);
  148. #define unit_remove_map(bl,clrtype) unit_remove_map_(bl,clrtype,__FILE__,__LINE__,__func__)
  149. int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file, int line, const char* func);
  150. int unit_free(struct block_list *bl, clr_type clrtype);
  151. int unit_changeviewsize(struct block_list *bl,short size);
  152. int unit_changetarget(struct block_list *bl,va_list ap);
  153. // Shadow Scar
  154. void unit_addshadowscar(unit_data &ud, int interval);
  155. void do_init_unit(void);
  156. void do_final_unit(void);
  157. #endif /* UNIT_HPP */