summaryrefslogtreecommitdiff
path: root/src/map/battle.c
diff options
context:
space:
mode:
authorskyleo <skyleo@skyleo.de>2019-09-08 02:53:24 +0200
committerHaru <haru@dotalux.com>2020-03-08 20:56:27 +0100
commitd13b24a62ac933364839c7ece1f70eba001e7c2d (patch)
treec10d9f953cf017579a22c9d58b9fc74fefc2956e /src/map/battle.c
parentfeb1f9d96a9cfc12602c96235106397b67f2aeb4 (diff)
downloadhercules-d13b24a62ac933364839c7ece1f70eba001e7c2d.tar.gz
hercules-d13b24a62ac933364839c7ece1f70eba001e7c2d.tar.bz2
hercules-d13b24a62ac933364839c7ece1f70eba001e7c2d.tar.xz
hercules-d13b24a62ac933364839c7ece1f70eba001e7c2d.zip
Refactor code using directions to use enum unit_dir
This removes a lot of duplicated code, especially related to people not using the arrays dirx and diry. Assertions for whenever these arrays are used have been added as well, to ensure valid index range. Some trailing white space has been removed as well.
Diffstat (limited to 'src/map/battle.c')
-rw-r--r--src/map/battle.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/map/battle.c b/src/map/battle.c
index c057ad81a..24e58cc09 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -3231,12 +3231,11 @@ static int64 battle_calc_damage(struct block_list *src, struct block_list *bl, s
if (!damage) return 0;
if( (sce = sc->data[SC_LIGHTNINGWALK]) && flag&BF_LONG && rnd()%100 < sce->val1 ) {
- int dx[8]={0,-1,-1,-1,0,1,1,1};
- int dy[8]={1,1,0,-1,-1,-1,0,1};
- uint8 dir = map->calc_dir(bl, src->x, src->y);
- if( unit->movepos(bl, src->x-dx[dir], src->y-dy[dir], 1, 1) ) {
- clif->slide(bl,src->x-dx[dir],src->y-dy[dir]);
- unit->setdir(bl, dir);
+ enum unit_dir dir = map->calc_dir(bl, src->x, src->y);
+ Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX);
+ if (unit->movepos(bl, src->x - dirx[dir], src->y - diry[dir], 1, 1)) {
+ clif->slide(bl, src->x - dirx[dir], src->y - diry[dir]);
+ unit->set_dir(bl, dir);
}
d->dmg_lv = ATK_DEF;
status_change_end(bl, SC_LIGHTNINGWALK, INVALID_TIMER);
@@ -5858,10 +5857,10 @@ static void battle_reflect_damage(struct block_list *target, struct block_list *
if( wd->flag & BF_SHORT ) {
if( !is_boss(src) ) {
if( sc->data[SC_DEATHBOUND] && skill_id != WS_CARTTERMINATION ) {
- uint8 dir = map->calc_dir(target,src->x,src->y),
- t_dir = unit->getdir(target);
+ enum unit_dir dir = map->calc_dir(target, src->x, src->y);
+ enum unit_dir t_dir = unit->getdir(target);
- if( !map->check_dir(dir,t_dir) ) {
+ if (map->check_dir(dir, t_dir) == 0) {
int64 rd1 = damage * sc->data[SC_DEATHBOUND]->val2 / 100; // Amplify damage.
trdamage += rdamage = rd1 - (damage = rd1 * 30 / 100); // not normalized as intended.
@@ -6229,10 +6228,10 @@ static enum damage_lv battle_weapon_attack(struct block_list *src, struct block_
status_change_end(src, SC_CLOAKINGEXCEED, INVALID_TIMER);
}
if( tsc && tsc->data[SC_AUTOCOUNTER] && status->check_skilluse(target, src, KN_AUTOCOUNTER, 1) ) {
- uint8 dir = map->calc_dir(target,src->x,src->y);
- int t_dir = unit->getdir(target);
+ enum unit_dir dir = map->calc_dir(target, src->x, src->y),
+ t_dir = unit->getdir(target);
int dist = distance_bl(src, target);
- if(dist <= 0 || (!map->check_dir(dir,t_dir) && dist <= tstatus->rhw.range+1)) {
+ if(dist <= 0 || (map->check_dir(dir, t_dir) == 0 && dist <= tstatus->rhw.range + 1)) {
uint16 skill_lv = tsc->data[SC_AUTOCOUNTER]->val1;
clif->skillcastcancel(target); //Remove the casting bar. [Skotlex]
clif->damage(src, target, sstatus->amotion, 1, 0, 1, BDT_NORMAL, 0); //Display MISS.