From a51003dda282a5aeed0e63b93b8a213acd82cafb Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 18:37:05 +0200 Subject: Refactor unit->bl2ud --- src/map/unit.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 29a01aea7..f0125ec79 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -76,15 +76,26 @@ struct unit_interface *unit; **/ static struct unit_data *unit_bl2ud(struct block_list *bl) { - if (bl == NULL) return NULL; - if (bl->type == BL_PC) return &BL_UCAST(BL_PC, bl)->ud; - if (bl->type == BL_MOB) return &BL_UCAST(BL_MOB, bl)->ud; - if (bl->type == BL_PET) return &BL_UCAST(BL_PET, bl)->ud; - if (bl->type == BL_NPC) return BL_UCAST(BL_NPC, bl)->ud; - if (bl->type == BL_HOM) return &BL_UCAST(BL_HOM, bl)->ud; - if (bl->type == BL_MER) return &BL_UCAST(BL_MER, bl)->ud; - if (bl->type == BL_ELEM) return &BL_UCAST(BL_ELEM, bl)->ud; - return NULL; + if (bl == NULL) + return NULL; + switch (bl->type) { + case BL_PC: + return &BL_UCAST(BL_PC, bl)->ud; + case BL_MOB: + return &BL_UCAST(BL_MOB, bl)->ud; + case BL_PET: + return &BL_UCAST(BL_PET, bl)->ud; + case BL_NPC: + return BL_UCAST(BL_NPC, bl)->ud; + case BL_HOM: + return &BL_UCAST(BL_HOM, bl)->ud; + case BL_MER: + return &BL_UCAST(BL_MER, bl)->ud; + case BL_ELEM: + return &BL_UCAST(BL_ELEM, bl)->ud; + default: + return NULL; + } } /** -- cgit v1.2.3-70-g09d2 From d4a40467c5fb99b34b235a7fa8cde423fbdf24c0 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 18:39:58 +0200 Subject: Add documentation for unit->walktoxy_sub --- src/map/unit.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index f0125ec79..db4fc47e7 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -116,6 +116,11 @@ static struct unit_data *unit_bl2ud2(struct block_list *bl) return unit->bl2ud(bl); } +/** + * TODO: understand purpose of this function + * @param bl block_list to process + * @return 0: success, 1: fail, 2: nullpointer + */ static int unit_walktoxy_sub(struct block_list *bl) { int i; -- cgit v1.2.3-70-g09d2 From 0ca593266e3d7f78eb4648ffe7bad7a7db9b6490 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 18:47:06 +0200 Subject: Move declarations to initializations in unit->walktoxy_sub --- src/map/unit.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index db4fc47e7..12d53df13 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -124,14 +124,12 @@ static struct unit_data *unit_bl2ud2(struct block_list *bl) static int unit_walktoxy_sub(struct block_list *bl) { int i; - struct walkpath_data wpd; - struct unit_data *ud = NULL; - - nullpo_retr(1, bl); - ud = unit->bl2ud(bl); - if(ud == NULL) return 0; + nullpo_retr(2, bl); + struct unit_data *ud = unit->bl2ud(bl); + if (ud == NULL) + return 2; - memset(&wpd, 0, sizeof(wpd)); + struct walkpath_data wpd = {0}; if( !path->search(&wpd,bl,bl->m,bl->x,bl->y,ud->to_x,ud->to_y,ud->state.walk_easy,CELL_CHKNOPASS) ) return 0; @@ -143,7 +141,7 @@ static int unit_walktoxy_sub(struct block_list *bl) return 0; #endif - memcpy(&ud->walkpath,&wpd,sizeof(wpd)); + ud->walkpath = wpd; if (ud->target_to && ud->chaserange>1) { //Generally speaking, the walk path is already to an adjacent tile -- cgit v1.2.3-70-g09d2 From f4039d8b2c28b06b160fa44e27908856646633a7 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 19:09:16 +0200 Subject: Rename reused var appropriately in unit->walktoxy_sub --- src/map/unit.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 12d53df13..d6eb6c30f 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -123,7 +123,6 @@ static struct unit_data *unit_bl2ud2(struct block_list *bl) */ static int unit_walktoxy_sub(struct block_list *bl) { - int i; nullpo_retr(2, bl); struct unit_data *ud = unit->bl2ud(bl); if (ud == NULL) @@ -147,9 +146,9 @@ static int unit_walktoxy_sub(struct block_list *bl) //Generally speaking, the walk path is already to an adjacent tile //so we only need to shorten the path if the range is greater than 1. - //Trim the last part of the path to account for range, - //but always move at least one cell when requested to move. - for (i = (ud->chaserange*10)-10; i > 0 && ud->walkpath.path_len>1;) { + // Trim the last part of the path to account for range, + // but always move at least one cell when requested to move. + for (int i = ud->chaserange * 10 - 10; i > 0 && ud->walkpath.path_len > 1;) { uint8 dir; ud->walkpath.path_len--; dir = ud->walkpath.path[ud->walkpath.path_len]; @@ -171,14 +170,16 @@ static int unit_walktoxy_sub(struct block_list *bl) } clif->move(ud); - if(ud->walkpath.path_pos>=ud->walkpath.path_len) - i = -1; - else if(ud->walkpath.path[ud->walkpath.path_pos]&1) - i = status->get_speed(bl)*MOVE_DIAGONAL_COST/MOVE_COST; + int timer_delay; + if (ud->walkpath.path_pos >= ud->walkpath.path_len) + timer_delay = -1; + else if ((ud->walkpath.path[ud->walkpath.path_pos] & 1) != 0) + timer_delay = status->get_speed(bl) * MOVE_DIAGONAL_COST / MOVE_COST; else - i = status->get_speed(bl); - if( i > 0) - ud->walktimer = timer->add(timer->gettick()+i,unit->walktoxy_timer,bl->id,i); + timer_delay = status->get_speed(bl); + + if (timer_delay > 0) + ud->walktimer = timer->add(timer->gettick() + timer_delay, unit->walktoxy_timer, bl->id, 0); //TODO: check if unit->walktoxy_timer uses any intptr data return 1; } -- cgit v1.2.3-70-g09d2 From 2351fb29487eb11df3c9d563f5ade84ece4e8d0b Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 19:12:15 +0200 Subject: Update Coding Style in unit->walktoxy_sub --- src/map/unit.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index d6eb6c30f..d1abed1d0 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -130,21 +130,22 @@ static int unit_walktoxy_sub(struct block_list *bl) struct walkpath_data wpd = {0}; - if( !path->search(&wpd,bl,bl->m,bl->x,bl->y,ud->to_x,ud->to_y,ud->state.walk_easy,CELL_CHKNOPASS) ) + if (!path->search(&wpd, bl, bl->m, bl->x, bl->y, ud->to_x, ud->to_y, ud->state.walk_easy, CELL_CHKNOPASS)) return 0; #ifdef OFFICIAL_WALKPATH - if( !path->search_long(NULL, bl, bl->m, bl->x, bl->y, ud->to_x, ud->to_y, CELL_CHKNOPASS) // Check if there is an obstacle between - && wpd.path_len > 14 // Official number of walkable cells is 14 if and only if there is an obstacle between. [malufett] - && (bl->type != BL_NPC) ) // If type is a NPC, please disregard. + if (bl->type != BL_NPC // If type is an NPC, disregard. + && !path->search_long(NULL, bl, bl->m, bl->x, bl->y, ud->to_x, ud->to_y, CELL_CHKNOPASS) // Check if there is an obstacle between + && wpd.path_len > 14) { // Official number of walkable cells is 14 if and only if there is an obstacle between. [malufett] return 0; + } #endif ud->walkpath = wpd; - if (ud->target_to && ud->chaserange>1) { - //Generally speaking, the walk path is already to an adjacent tile - //so we only need to shorten the path if the range is greater than 1. + if (ud->target_to != 0 && ud->chaserange > 1) { + // Generally speaking, the walk path is already to an adjacent tile + // so we only need to shorten the path if the range is greater than 1. // Trim the last part of the path to account for range, // but always move at least one cell when requested to move. @@ -152,8 +153,8 @@ static int unit_walktoxy_sub(struct block_list *bl) uint8 dir; ud->walkpath.path_len--; dir = ud->walkpath.path[ud->walkpath.path_len]; - if (dir&1) - i -= MOVE_COST*20; //When chasing, units will target a diamond-shaped area in range [Playtester] + if ((dir & 1) != 0) + i -= MOVE_COST * 20; // When chasing, units will target a diamond-shaped area in range [Playtester] else i -= MOVE_COST; ud->to_x -= dirx[dir]; @@ -161,7 +162,7 @@ static int unit_walktoxy_sub(struct block_list *bl) } } - ud->state.change_walk_target=0; + ud->state.change_walk_target = 0; if (bl->type == BL_PC) { struct map_session_data *sd = BL_UCAST(BL_PC, bl); -- cgit v1.2.3-70-g09d2 From 4e0b33282d2f8914fa5e425f65d6e15f8bd86526 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 19:15:04 +0200 Subject: Change returning error-code in unit->walktoxy_sub --- src/map/unit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index d1abed1d0..d8d4f1144 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -131,13 +131,13 @@ static int unit_walktoxy_sub(struct block_list *bl) struct walkpath_data wpd = {0}; if (!path->search(&wpd, bl, bl->m, bl->x, bl->y, ud->to_x, ud->to_y, ud->state.walk_easy, CELL_CHKNOPASS)) - return 0; + return 1; #ifdef OFFICIAL_WALKPATH if (bl->type != BL_NPC // If type is an NPC, disregard. && !path->search_long(NULL, bl, bl->m, bl->x, bl->y, ud->to_x, ud->to_y, CELL_CHKNOPASS) // Check if there is an obstacle between && wpd.path_len > 14) { // Official number of walkable cells is 14 if and only if there is an obstacle between. [malufett] - return 0; + return 1; } #endif @@ -181,7 +181,7 @@ static int unit_walktoxy_sub(struct block_list *bl) if (timer_delay > 0) ud->walktimer = timer->add(timer->gettick() + timer_delay, unit->walktoxy_timer, bl->id, 0); //TODO: check if unit->walktoxy_timer uses any intptr data - return 1; + return 0; } /** -- cgit v1.2.3-70-g09d2 From 5a6b00556a6787b62a6b0f8b61929249db02ac33 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 19:18:32 +0200 Subject: Update error-code and some Coding Style in unit->step_timer --- src/map/unit.c | 56 +++++++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index d8d4f1144..5f8ff0c42 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -189,40 +189,33 @@ static int unit_walktoxy_sub(struct block_list *bl) * @param tid: Timer ID * @param tick: Unused * @param id: ID of bl to do the action - * @param data: Not used - * @return 1: Success 0: Fail (No valid bl) + * @param data: Unused + * @return 0: success, 1: fail, 2: nullpointer */ static int unit_step_timer(int tid, int64 tick, int id, intptr_t data) { - struct block_list *bl; - struct unit_data *ud; - int target_id; - - bl = map->id2bl(id); - - if (!bl || bl->prev == NULL) - return 0; - - ud = unit->bl2ud(bl); - - if(!ud) - return 0; + struct block_list *bl = map->id2bl(id); + if (bl == NULL || bl->prev == NULL) + return 2; + struct unit_data *ud = unit->bl2ud(bl); + if (ud == NULL) + return 2; - if(ud->steptimer != tid) { - ShowError("unit_step_timer mismatch %d != %d\n",ud->steptimer,tid); - return 0; + if (ud->steptimer != tid) { + ShowError("unit_step_timer mismatch %d != %d\n", ud->steptimer, tid); + return 1; } ud->steptimer = INVALID_TIMER; - if(!ud->stepaction) - return 0; + if (!ud->stepaction) + return 1; //Set to false here because if an error occurs, it should not be executed again ud->stepaction = false; - if(!ud->target_to) - return 0; + if (ud->target_to == 0) + return 1; //Flush target_to as it might contain map coordinates which should not be used by other functions target_id = ud->target_to; @@ -237,19 +230,16 @@ static int unit_step_timer(int tid, int64 tick, int id, intptr_t data) } else { //If a player has target_id set and target is in range, attempt attack struct block_list *tbl = map->id2bl(target_id); - if (!tbl || !status->check_visibility(bl, tbl)) { - return 0; - } - if(ud->stepskill_id == 0) { - //Execute normal attack - unit->attack(bl, tbl->id, (ud->state.attack_continue) + 2); - } else { - //Execute non-ground skill - unit->skilluse_id(bl, tbl->id, ud->stepskill_id, ud->stepskill_lv); - } + nullpo_retr(2, tbl); + if (status->check_visibility(bl, tbl) == 0) // Target not visible + return 1; + if (ud->stepskill_id == 0) + unit->attack(bl, tbl->id, ud->state.attack_continue + 2); // Execute normal attack + else + unit->skilluse_id(bl, tbl->id, ud->stepskill_id, ud->stepskill_lv); // Execute non-ground skill } - return 1; + return 0; } static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) -- cgit v1.2.3-70-g09d2 From cd0a421095215933f40b20f9b1108b03f4f51dca Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 19:20:12 +0200 Subject: Update Coding Style in unit->step_timer --- src/map/unit.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 5f8ff0c42..eb9bd9e37 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -211,24 +211,24 @@ static int unit_step_timer(int tid, int64 tick, int id, intptr_t data) if (!ud->stepaction) return 1; - //Set to false here because if an error occurs, it should not be executed again + // Set to false here because if an error occurs, it should not be executed again ud->stepaction = false; if (ud->target_to == 0) return 1; - //Flush target_to as it might contain map coordinates which should not be used by other functions - target_id = ud->target_to; + // Flush target_to as it might contain map coordinates which should not be used by other functions + int target_id = ud->target_to; ud->target_to = 0; - //If stepaction is set then we remembered a client request that should be executed on the next step - //Execute request now if target is in attack range - if(ud->stepskill_id && skill->get_inf(ud->stepskill_id) & INF_GROUND_SKILL) { - //Execute ground skill + // If stepaction is set then we remembered a client request that should be executed on the next step + // Execute request now if target is in attack range + if (ud->stepskill_id != 0 && (skill->get_inf(ud->stepskill_id) & INF_GROUND_SKILL) != 0) { + // Execute ground skill struct map_data *md = &map->list[bl->m]; - unit->skilluse_pos(bl, target_id%md->xs, target_id/md->xs, ud->stepskill_id, ud->stepskill_lv); + unit->skilluse_pos(bl, target_id % md->xs, target_id / md->xs, ud->stepskill_id, ud->stepskill_lv); } else { - //If a player has target_id set and target is in range, attempt attack + // If a player has target_id set and target is in range, attempt attack struct block_list *tbl = map->id2bl(target_id); nullpo_retr(2, tbl); if (status->check_visibility(bl, tbl) == 0) // Target not visible -- cgit v1.2.3-70-g09d2 From fe378985d5267bee1f73049c826ad4f1e9c2b9c4 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 19:45:53 +0200 Subject: Refactor unit_walktoxy_timer --- src/map/unit.c | 314 +++++++++++++++++++++++++++++---------------------------- src/map/unit.h | 1 + 2 files changed, 159 insertions(+), 156 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index eb9bd9e37..235a843eb 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -242,226 +242,226 @@ static int unit_step_timer(int tid, int64 tick, int id, intptr_t data) return 0; } -static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) +/** + * Warps homunuculus or mercenary towards his master in case he's too far away for 3 seconds. + * @param master_bl: block_list of master + * @param slave_bl: block_list of homunuculus/mercenary master owns + * @return 0: success, 1: fail + */ +static int unit_warpto_master(struct block_list *master_bl, struct block_list *slave_bl) { - int i; - int x,y,dx,dy; - unsigned char icewall_walk_block; - uint8 dir; - struct block_list *bl; - struct map_session_data *sd; - struct mob_data *md; - struct unit_data *ud; - struct mercenary_data *mrd; + nullpo_retr(1, master_bl); + nullpo_retr(1, slave_bl); + int64 *masterteleport_timer; + struct homun_data *hd = BL_CAST(BL_HOM, slave_bl); + struct mercenary_data *md = BL_CAST(BL_MER, slave_bl); + + bool check = true; + if (hd != NULL) { + masterteleport_timer = &hd->masterteleport_timer; + check = homun_alive(hd); + } else if (md != NULL) { + masterteleport_timer = &md->masterteleport_timer; + } else { + return 1; + } - bl = map->id2bl(id); - if(bl == NULL) - return 0; - sd = BL_CAST(BL_PC, bl); - md = BL_CAST(BL_MOB, bl); - mrd = BL_CAST(BL_MER, bl); - ud = unit->bl2ud(bl); + if (check && !check_distance_bl(master_bl, slave_bl, MAX_MER_DISTANCE)) { + if (*masterteleport_timer == 0) { + *masterteleport_timer = timer->gettick(); + return 0; + } else if (DIFF_TICK(timer->gettick(), *masterteleport_timer) > 3000) { + unit->warp(slave_bl, master_bl->m, master_bl->x, master_bl->y, CLR_TELEPORT); + } + } + *masterteleport_timer = 0; // resets tick in case he isn't far anymore. - if(ud == NULL) return 0; + return 0; +} + +/** + * Timer for walking to target coordinates or object. + * @param tid: timer id + * @param tick: tick + * @param id: id of bl to do the action + * @param data: unused + * @return 0: success, 1: fail + */ +static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) +{ + struct block_list *bl = map->id2bl(id); + if (bl == NULL || bl->prev == NULL) // Stop moved because it is missing from the block_list + return 1; + struct unit_data *ud = unit->bl2ud(bl); + if (ud == NULL) + return 1; - if(ud->walktimer != tid){ + if (ud->walktimer != tid) { ShowError("unit_walk_timer mismatch %d != %d\n",ud->walktimer,tid); - return 0; + return 1; } ud->walktimer = INVALID_TIMER; - if (bl->prev == NULL) return 0; // Stop moved because it is missing from the block_list - if(ud->walkpath.path_pos>=ud->walkpath.path_len) - return 0; + if (ud->walkpath.path_pos >= ud->walkpath.path_len) + return 1; - if(ud->walkpath.path[ud->walkpath.path_pos]>=8) + uint8 dir = ud->walkpath.path[ud->walkpath.path_pos]; + if (ud->walkpath.path[ud->walkpath.path_pos] >= 8) return 1; - x = bl->x; - y = bl->y; + int x = bl->x; + int y = bl->y; - dir = ud->walkpath.path[ud->walkpath.path_pos]; ud->dir = dir; - dx = dirx[(int)dir]; - dy = diry[(int)dir]; + int dx = dirx[(int) dir]; + int dy = diry[(int) dir]; - //Get icewall walk block depending on boss mode (players can't be trapped) - if(md && md->status.mode&MD_BOSS) - icewall_walk_block = battle_config.boss_icewall_walk_block; - else if(md) - icewall_walk_block = battle_config.mob_icewall_walk_block; - else - icewall_walk_block = 0; + // Get icewall walk block depending on boss mode (players can't be trapped) + unsigned char icewall_walk_block = 0; + struct mob_data *md = BL_CAST(BL_MOB, bl); + if (md != NULL) { + if ((md->status.mode & MD_BOSS) != 0) + icewall_walk_block = battle_config.boss_icewall_walk_block; + else + icewall_walk_block = battle_config.mob_icewall_walk_block; + } - //Monsters will walk into an icewall from the west and south if they already started walking + // Monsters will walk into an icewall from the west and south if they already started walking if (map->getcell(bl->m, bl, x + dx, y + dy, CELL_CHKNOPASS) && (icewall_walk_block == 0 || !map->getcell(bl->m, bl, x + dx, y + dy, CELL_CHKICEWALL) || dx < 0 || dy < 0)) return unit->walktoxy_sub(bl); - //Monsters can only leave icewalls to the west and south - //But if movement fails more than icewall_walk_block times, they can ignore this rule - if (md && md->walktoxy_fail_count < icewall_walk_block && map->getcell(bl->m, bl, x, y, CELL_CHKICEWALL) && (dx > 0 || dy > 0)) { - //Needs to be done here so that rudeattack skills are invoked + // Monsters can only leave icewalls to the west and south + // But if movement fails more than icewall_walk_block times, they can ignore this rule + if (md != NULL && md->walktoxy_fail_count < icewall_walk_block && map->getcell(bl->m, bl, x, y, CELL_CHKICEWALL) != 0 && (dx > 0 || dy > 0)) { + // Needs to be done here so that rudeattack skills are invoked md->walktoxy_fail_count++; clif->fixpos(bl); - //Monsters in this situation first use a chase skill, then unlock target and then use an idle skill - if (!(++ud->walk_count%WALK_SKILL_INTERVAL)) + // Monsters in this situation first use a chase skill, then unlock target and then use an idle skill + if ((++ud->walk_count % WALK_SKILL_INTERVAL) == 0) mob->skill_use(md, tick, -1); mob->unlocktarget(md, tick); - if (!(++ud->walk_count%WALK_SKILL_INTERVAL)) + if ((++ud->walk_count % WALK_SKILL_INTERVAL) != 0) mob->skill_use(md, tick, -1); - return 0; + return 1; } + struct map_session_data *sd = BL_CAST(BL_PC, bl); //Refresh view for all those we lose sight - map->foreachinmovearea(clif->outsight, bl, AREA_SIZE, dx, dy, sd?BL_ALL:BL_PC, bl); + map->foreachinmovearea(clif->outsight, bl, AREA_SIZE, dx, dy, (sd != NULL ? BL_ALL : BL_PC), bl); x += dx; y += dy; map->moveblock(bl, x, y, tick); - ud->walk_count++; //walked cell counter, to be used for walk-triggered skills. [Skotlex] + ud->walk_count++; // walked cell counter, to be used for walk-triggered skills. [Skotlex] status_change_end(bl, SC_ROLLINGCUTTER, INVALID_TIMER); //If you move, you lose your counters. [malufett] if (bl->x != x || bl->y != y || ud->walktimer != INVALID_TIMER) - return 0; //map->moveblock has altered the object beyond what we expected (moved/warped it) + return 1; // map->moveblock has altered the object beyond what we expected (moved/warped it) ud->walktimer = -2; // arbitrary non-INVALID_TIMER value to make the clif code send walking packets - map->foreachinmovearea(clif->insight, bl, AREA_SIZE, -dx, -dy, sd?BL_ALL:BL_PC, bl); + map->foreachinmovearea(clif->insight, bl, AREA_SIZE, -dx, -dy, (sd != NULL ? BL_ALL : BL_PC), bl); ud->walktimer = INVALID_TIMER; - if(sd) { - if( sd->touching_id ) - npc->touchnext_areanpc(sd,false); + struct mercenary_data *mrd = BL_CAST(BL_MER, bl); + if (sd != NULL) { + if (sd->touching_id != 0) + npc->touchnext_areanpc(sd, false); if (map->getcell(bl->m, bl, x, y, CELL_CHKNPC)) { - npc->touch_areanpc(sd,bl->m,x,y); + npc->touch_areanpc(sd, bl->m, x, y); if (bl->prev == NULL) //Script could have warped char, abort remaining of the function. return 0; - } else + } else { npc->untouch_areanpc(sd, bl->m, x, y); - - if( sd->md ) { // mercenary should be warped after being 3 seconds too far from the master [greenbox] - if( !check_distance_bl(&sd->bl, &sd->md->bl, MAX_MER_DISTANCE) ) { - if (sd->md->masterteleport_timer == 0) - sd->md->masterteleport_timer = timer->gettick(); - else if (DIFF_TICK(timer->gettick(), sd->md->masterteleport_timer) > 3000) { - sd->md->masterteleport_timer = 0; - unit->warp( &sd->md->bl, sd->bl.m, sd->bl.x, sd->bl.y, CLR_TELEPORT ); - } - } else // reset the tick, he is not far anymore - sd->md->masterteleport_timer = 0; - } - if( sd->hd ) { - if( homun_alive(sd->hd) && !check_distance_bl(&sd->bl, &sd->hd->bl, MAX_MER_DISTANCE) ) { - if (sd->hd->masterteleport_timer == 0) - sd->hd->masterteleport_timer = timer->gettick(); - else if (DIFF_TICK(timer->gettick(), sd->hd->masterteleport_timer) > 3000) { - sd->hd->masterteleport_timer = 0; - unit->warp( &sd->hd->bl, sd->bl.m, sd->bl.x, sd->bl.y, CLR_TELEPORT ); - } - } else - sd->hd->masterteleport_timer = 0; } + + if (sd->md != NULL) // mercenary should be warped after being 3 seconds too far from the master [greenbox] + unit->warpto_master(bl, &sd->md->bl); + if (sd->hd != NULL) + unit->warpto_master(bl, &sd->hd->bl); } else if (md) { - //Movement was successful, reset walktoxy_fail_count + // Movement was successful, reset walktoxy_fail_count md->walktoxy_fail_count = 0; - if (map->getcell(bl->m, bl, x, y, CELL_CHKNPC)) { - if( npc->touch_areanpc2(md) ) return 0; // Warped - } else + + if (map->getcell(bl->m, bl, x, y, CELL_CHKNPC) != 0 && npc->touch_areanpc2(md)) + return 0; // Warped + else md->areanpc_id = 0; - if (md->min_chase > md->db->range3) md->min_chase--; - //Walk skills are triggered regardless of target due to the idle-walk mob state. - //But avoid triggering on stop-walk calls. - if (tid != INVALID_TIMER - && !(ud->walk_count%WALK_SKILL_INTERVAL) - && map->list[bl->m].users > 0 - && mob->skill_use(md, tick, -1) - ) { + + if (md->min_chase > md->db->range3) + md->min_chase--; + // Walk skills are triggered regardless of target due to the idle-walk mob state. + // But avoid triggering on stop-walk calls. + if (tid != INVALID_TIMER && (ud->walk_count % WALK_SKILL_INTERVAL) == 0 + && map->list[bl->m].users > 0 && mob->skill_use(md, tick, -1) == 1) { + // Walk skills are supposed to be used while walking if (!(ud->skill_id == NPC_SELFDESTRUCTION && ud->skilltimer != INVALID_TIMER) - && md->state.skillstate != MSS_WALK //Walk skills are supposed to be used while walking - ) { - //Skill used, abort walking - clif->fixpos(bl); //Fix position as walk has been canceled. - return 0; + && md->state.skillstate != MSS_WALK) { + // Skill used, abort walking + clif->fixpos(bl); // Fix position as walk has been canceled. + return 1; } - //Resend walk packet for proper Self Destruction display. + // Resend walk packet for proper Self Destruction display. clif->move(ud); } - } - else if( mrd && mrd->master ) - { - if (!check_distance_bl(&mrd->master->bl, bl, MAX_MER_DISTANCE)) - { - // mercenary should be warped after being 3 seconds too far from the master [greenbox] - if (mrd->masterteleport_timer == 0) - { - mrd->masterteleport_timer = timer->gettick(); - } - else if (DIFF_TICK(timer->gettick(), mrd->masterteleport_timer) > 3000) - { - mrd->masterteleport_timer = 0; - unit->warp( bl, mrd->master->bl.m, mrd->master->bl.x, mrd->master->bl.y, CLR_TELEPORT ); - } - } - else - { - mrd->masterteleport_timer = 0; - } + } else if (mrd != NULL && mrd->master != NULL) { + unit->warpto_master(&mrd->master->bl, bl); } - if(tid == INVALID_TIMER) //A directly invoked timer is from battle_stop_walking, therefore the rest is irrelevant. + if(tid == INVALID_TIMER) // A directly invoked timer is from battle_stop_walking, therefore the rest is irrelevant. return 0; - //If stepaction is set then we remembered a client request that should be executed on the next step - if (ud->stepaction && ud->target_to) { - //Delete old stepaction even if not executed yet, the latest command is what counts - if(ud->steptimer != INVALID_TIMER) { + // If stepaction is set then we remembered a client request that should be executed on the next step + if (ud->stepaction && ud->target_to != 0) { + // Delete old stepaction even if not executed yet, the latest command is what counts + if (ud->steptimer != INVALID_TIMER) { timer->delete(ud->steptimer, unit->step_timer); ud->steptimer = INVALID_TIMER; } - //Delay stepactions by half a step (so they are executed at full step) - if(ud->walkpath.path[ud->walkpath.path_pos]&1) - i = status->get_speed(bl)*14/20; + // Delay stepactions by half a step (so they are executed at full step) + int timer_delay; + if ((ud->walkpath.path[ud->walkpath.path_pos] & 1) != 0) + timer_delay = status->get_speed(bl) * 14 / 20; else - i = status->get_speed(bl)/2; - ud->steptimer = timer->add(tick+i, unit->step_timer, bl->id, 0); + timer_delay = status->get_speed(bl) / 2; + ud->steptimer = timer->add(tick + timer_delay, unit->step_timer, bl->id, 0); } - if(ud->state.change_walk_target) { - if(unit->walktoxy_sub(bl)) { - return 1; - } else { - clif->fixpos(bl); + if (ud->state.change_walk_target) { + if (unit->walktoxy_sub(bl) == 0) return 0; - } + clif->fixpos(bl); + return 1; } + int timer_delay; ud->walkpath.path_pos++; if(ud->walkpath.path_pos>=ud->walkpath.path_len) - i = -1; - else if(ud->walkpath.path[ud->walkpath.path_pos]&1) - i = status->get_speed(bl)*14/10; + timer_delay = -1; + else if ((ud->walkpath.path[ud->walkpath.path_pos] & 1) != 0) + timer_delay = status->get_speed(bl) * 14 / 10; else - i = status->get_speed(bl); + timer_delay = status->get_speed(bl); - if(i > 0) { - ud->walktimer = timer->add(tick+i,unit->walktoxy_timer,id,i); - if( md && DIFF_TICK(tick,md->dmgtick) < 3000 )//not required not damaged recently + if (timer_delay > 0) { + ud->walktimer = timer->add(tick + timer_delay, unit->walktoxy_timer, id, 0); + if (md != NULL && DIFF_TICK(tick, md->dmgtick) < 3000) // not required not damaged recently clif->move(ud); - } else if(ud->state.running) { - //Keep trying to run. - if ( !(unit->run(bl, NULL, SC_RUN) || unit->run(bl, sd, SC_WUGDASH)) ) + } else if (ud->state.running != 0) { + // Keep trying to run. + if (!(unit->run(bl, NULL, SC_RUN) || unit->run(bl, sd, SC_WUGDASH))) ud->state.running = 0; - } else if (!ud->stepaction && ud->target_to) { - //Update target trajectory. + } else if (!ud->stepaction && ud->target_to != 0) { + // Update target trajectory. struct block_list *tbl = map->id2bl(ud->target_to); - if (!tbl || !status->check_visibility(bl, tbl)) { - //Cancel chase. + if (tbl == NULL || status->check_visibility(bl, tbl) == 0) { // not visible + // Cancel chase. ud->to_x = bl->x; ud->to_y = bl->y; - if (tbl && bl->type == BL_MOB && mob->warpchase(BL_UCAST(BL_MOB, bl), tbl)) + if (tbl != NULL && bl->type == BL_MOB && mob->warpchase(BL_UCAST(BL_MOB, bl), tbl) != 0) return 0; ud->target_to = 0; - return 0; + return 1; } if (tbl->m == bl->m && check_distance_bl(bl, tbl, ud->chaserange)) { //Reached destination. @@ -472,19 +472,19 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) clif->fixpos(bl); unit->attack(bl, tbl->id, ud->state.attack_continue); } - } else { //Update chase-path - unit->walktobl(bl, tbl, ud->chaserange, ud->state.walk_easy|(ud->state.attack_continue? 1 : 0)); + } else { // Update chase-path + unit->walktobl(bl, tbl, ud->chaserange, ud->state.walk_easy | ud->state.attack_continue); return 0; } } else { - //Stopped walking. Update to_x and to_y to current location [Skotlex] + // Stopped walking. Update to_x and to_y to current location [Skotlex] ud->to_x = bl->x; ud->to_y = bl->y; - if (battle_config.official_cell_stack_limit && map->count_oncell(bl->m, x, y, BL_CHAR|BL_NPC, 0x1 | 0x2) > battle_config.official_cell_stack_limit) { - //Walked on occupied cell, call unit_walktoxy again - if(ud->steptimer != INVALID_TIMER) { - //Execute step timer on next step instead + if (battle_config.official_cell_stack_limit != 0 && map->count_oncell(bl->m, x, y, BL_CHAR | BL_NPC, 0x1 | 0x2) > battle_config.official_cell_stack_limit) { + // Walked on occupied cell, call unit->walktoxy again + if (ud->steptimer != INVALID_TIMER) { + // Execute step timer on next step instead timer->delete(ud->steptimer, unit->step_timer); ud->steptimer = INVALID_TIMER; } @@ -494,6 +494,7 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) return 0; } +//TODO: CONTINUE REFACTORING HERE static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); @@ -589,7 +590,7 @@ static int unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data) if (DIFF_TICK(ud->canmove_tick, tick) > 0) //Keep waiting? timer->add(ud->canmove_tick+1, unit->walktobl_sub, id, data); else if (unit->can_move(bl)) { - if (unit->walktoxy_sub(bl)) + if (unit->walktoxy_sub(bl) == 0) set_mobstate(bl, ud->state.attack_continue); } } @@ -648,9 +649,9 @@ static int unit_walktobl(struct block_list *bl, struct block_list *tbl, int rang if(!unit->can_move(bl)) return 0; - if (unit->walktoxy_sub(bl)) { + if (unit->walktoxy_sub(bl) == 0) { //ALREADY REFACTORED set_mobstate(bl, flag&2); - return 1; + return 0; } return 0; } @@ -3013,6 +3014,7 @@ void unit_defaults(void) unit->getdir = unit_getdir; unit->blown = unit_blown; unit->warp = unit_warp; + unit->warpto_master = unit_warpto_master; unit->stop_walking = unit_stop_walking; unit->skilluse_id = unit_skilluse_id; unit->step_timer = unit_step_timer; diff --git a/src/map/unit.h b/src/map/unit.h index 5437a172a..315cc0515 100644 --- a/src/map/unit.h +++ b/src/map/unit.h @@ -119,6 +119,7 @@ struct unit_interface { uint8 (*getdir) (struct block_list *bl); int (*blown) (struct block_list *bl, int dx, int dy, int count, int flag); int (*warp) (struct block_list *bl, short m, short x, short y, enum clr_type type); + int (*warpto_master) (struct block_list *master_bl, struct block_list *slave_bl); int (*stop_walking) (struct block_list *bl, int type); int (*skilluse_id) (struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv); int (*step_timer) (int tid, int64 tick, int id, intptr_t data); -- cgit v1.2.3-70-g09d2 From feb1f9d96a9cfc12602c96235106397b67f2aeb4 Mon Sep 17 00:00:00 2001 From: skyleo Date: Sun, 8 Sep 2019 02:42:37 +0200 Subject: Add enum unit_dir and make direction functions use it Without a doubt the readability of code will be increased by this greatly --- src/map/map.c | 89 +++++++++++++++++++++++++++------------------------ src/map/map.h | 5 +-- src/map/unit.c | 33 ++++++++++++------- src/map/unit.h | 7 ++-- src/map/unitdefines.h | 58 +++++++++++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 57 deletions(-) create mode 100644 src/map/unitdefines.h (limited to 'src') diff --git a/src/map/map.c b/src/map/map.c index 70623ae22..9637609ec 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2845,63 +2845,70 @@ static int map_mapname2ipport(unsigned short name, uint32 *ip, uint16 *port) return 0; } -/*========================================== +/** * Checks if both dirs point in the same direction. - *------------------------------------------*/ -static int map_check_dir(int s_dir, int t_dir) + * @param s_dir: direction source is facing + * @param t_dir: direction target is facing + * @return 0: success(both face the same direction), 1: failure + **/ +static int map_check_dir(enum unit_dir s_dir, enum unit_dir t_dir) { - if(s_dir == t_dir) + if (s_dir == t_dir || ((t_dir + UNIT_DIR_MAX - 1) % UNIT_DIR_MAX) == s_dir + || ((t_dir + UNIT_DIR_MAX + 1) % UNIT_DIR_MAX) == s_dir) return 0; - switch(s_dir) { - case 0: if(t_dir == 7 || t_dir == 1 || t_dir == 0) return 0; break; - case 1: if(t_dir == 0 || t_dir == 2 || t_dir == 1) return 0; break; - case 2: if(t_dir == 1 || t_dir == 3 || t_dir == 2) return 0; break; - case 3: if(t_dir == 2 || t_dir == 4 || t_dir == 3) return 0; break; - case 4: if(t_dir == 3 || t_dir == 5 || t_dir == 4) return 0; break; - case 5: if(t_dir == 4 || t_dir == 6 || t_dir == 5) return 0; break; - case 6: if(t_dir == 5 || t_dir == 7 || t_dir == 6) return 0; break; - case 7: if(t_dir == 6 || t_dir == 0 || t_dir == 7) return 0; break; - } return 1; } -/*========================================== +/** * Returns the direction of the given cell, relative to 'src' - *------------------------------------------*/ -static uint8 map_calc_dir(struct block_list *src, int16 x, int16 y) + * @param src: object to put in relation between coordinates + * @param x: x-coordinate of cell + * @param y: y-coordinate of cell + * @return the direction of the given cell, relative to 'src' + **/ +static enum unit_dir map_calc_dir(struct block_list *src, int16 x, int16 y) { - uint8 dir = 0; - int dx, dy; - - nullpo_ret(src); + nullpo_retr(UNIT_DIR_NORTH, src); + enum unit_dir dir = UNIT_DIR_NORTH; - dx = x-src->x; - dy = y-src->y; + int dx = x - src->x; + int dy = y - src->y; if (dx == 0 && dy == 0) { // both are standing on the same spot. // aegis-style, makes knockback default to the left. // athena-style, makes knockback default to behind 'src'. - dir = (battle_config.knockback_left ? 6 : unit->getdir(src)); - } else if (dx >= 0 && dy >=0) { - // upper-right - if( dx*2 < dy || dx == 0 ) dir = 0; // up - else if( dx > dy*2+1 || dy == 0 ) dir = 6; // right - else dir = 7; // up-right + if (battle_config.knockback_left != 0) + dir = UNIT_DIR_EAST; + else + dir = unit->getdir(src); + } else if (dx >= 0 && dy >= 0) { + if (dx * 2 < dy || dx == 0) + dir = UNIT_DIR_NORTH; + else if (dx > dy * 2 + 1 || dy == 0) + dir = UNIT_DIR_EAST; + else + dir = UNIT_DIR_NORTHEAST; } else if (dx >= 0 && dy <= 0) { - // lower-right - if( dx*2 < -dy || dx == 0 ) dir = 4; // down - else if( dx > -dy*2+1 || dy == 0 ) dir = 6; // right - else dir = 5; // down-right + if (dx * 2 < -dy || dx == 0) + dir = UNIT_DIR_SOUTH; + else if (dx > -dy * 2 + 1 || dy == 0) + dir = UNIT_DIR_EAST; + else + dir = UNIT_DIR_SOUTHEAST; } else if (dx <= 0 && dy <= 0) { - // lower-left - if( dx*2 > dy || dx == 0 ) dir = 4; // down - else if( dx < dy*2-1 || dy == 0 ) dir = 2; // left - else dir = 3; // down-left + if (dx * 2 > dy || dx == 0 ) + dir = UNIT_DIR_SOUTH; + else if (dx < dy * 2 + 1 || dy == 0) + dir = UNIT_DIR_WEST; + else + dir = UNIT_DIR_SOUTHWEST; } else { - // upper-left - if( -dx*2 < dy || dx == 0 ) dir = 0; // up - else if( -dx > dy*2+1 || dy == 0) dir = 2; // left - else dir = 1; // up-left + if (-dx * 2 < dy || dx == 0 ) + dir = UNIT_DIR_NORTH; + else if (-dx > dy * 2 + 1 || dy == 0) + dir = UNIT_DIR_WEST; + else + dir = UNIT_DIR_NORTHWEST; } return dir; } diff --git a/src/map/map.h b/src/map/map.h index dbd9c0fba..e0fbcf9b2 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -27,6 +27,7 @@ #include "common/db.h" #include "common/mapindex.h" #include "common/mmo.h" +#include "map/unitdefines.h" // enum unit_dir #include #include @@ -1216,8 +1217,8 @@ END_ZEROED_BLOCK; // reload config file looking only for npcs void (*reloadnpc) (bool clear); - int (*check_dir) (int s_dir,int t_dir); - uint8 (*calc_dir) (struct block_list *src,int16 x,int16 y); + int (*check_dir) (enum unit_dir s_dir, enum unit_dir t_dir); + enum unit_dir (*calc_dir) (struct block_list *src, int16 x, int16 y); int (*random_dir) (struct block_list *bl, short *x, short *y); // [Skotlex] int (*cleanup_sub) (struct block_list *bl, va_list ap); diff --git a/src/map/unit.c b/src/map/unit.c index 235a843eb..3a940665d 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -832,12 +832,18 @@ static int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int eas return 1; } -static int unit_setdir(struct block_list *bl, unsigned char dir) +/** + * Sets the facing direction of a unit + * @param bl: unit to modify + * @param dir: the facing direction @see enum unit_dir + * @return 0: success, 1: failure + */ +static int unit_setdir(struct block_list *bl, enum unit_dir dir) { - struct unit_data *ud; - nullpo_ret(bl ); - ud = unit->bl2ud(bl); - if (!ud) return 0; + nullpo_retr(1, bl); + struct unit_data *ud = unit->bl2ud(bl); + if (ud == NULL) + return 1; ud->dir = dir; if (bl->type == BL_PC) BL_UCAST(BL_PC, bl)->head_dir = 0; @@ -845,15 +851,20 @@ static int unit_setdir(struct block_list *bl, unsigned char dir) return 0; } -static uint8 unit_getdir(struct block_list *bl) +/** + * Get the facing direction of a unit + * @param bl: unit to request data from + * @return the facing direction @see enum unit_dir + */ +static enum unit_dir unit_getdir(struct block_list *bl) { - struct unit_data *ud; - nullpo_ret(bl); + nullpo_retr(UNIT_DIR_NORTH, bl); - if( bl->type == BL_NPC ) + if (bl->type == BL_NPC) return BL_UCCAST(BL_NPC, bl)->dir; - ud = unit->bl2ud(bl); - if (!ud) return 0; + struct unit_data *ud = unit->bl2ud(bl); + if (ud == NULL) + return UNIT_DIR_NORTH; return ud->dir; } diff --git a/src/map/unit.h b/src/map/unit.h index 315cc0515..bdee032f8 100644 --- a/src/map/unit.h +++ b/src/map/unit.h @@ -24,6 +24,7 @@ #include "map/clif.h" // clr_type #include "map/path.h" // struct walkpath_data #include "map/skill.h" // 'MAX_SKILLTIMERSKILL, struct skill_timerskill, struct skill_unit_group, struct skill_unit_group_tickset +#include "map/unitdefines.h" // enum unit_dir #include "common/hercules.h" struct map_session_data; @@ -67,7 +68,7 @@ struct unit_data { int64 attackabletime; int64 canact_tick; int64 canmove_tick; - uint8 dir; + enum unit_dir dir; unsigned char walk_count; unsigned char target_count; struct { @@ -115,8 +116,8 @@ struct unit_interface { void (*run_hit) (struct block_list *bl, struct status_change *sc, struct map_session_data *sd, enum sc_type type); int (*escape) (struct block_list *bl, struct block_list *target, short dist); int (*movepos) (struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath); - int (*setdir) (struct block_list *bl, unsigned char dir); - uint8 (*getdir) (struct block_list *bl); + int (*setdir) (struct block_list *bl, enum unit_dir dir); + enum unit_dir (*getdir) (struct block_list *bl); int (*blown) (struct block_list *bl, int dx, int dy, int count, int flag); int (*warp) (struct block_list *bl, short m, short x, short y, enum clr_type type); int (*warpto_master) (struct block_list *master_bl, struct block_list *slave_bl); diff --git a/src/map/unitdefines.h b/src/map/unitdefines.h new file mode 100644 index 000000000..70b6e8d4d --- /dev/null +++ b/src/map/unitdefines.h @@ -0,0 +1,58 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2012-2019 Hercules Dev Team + * Copyright (C) Athena Dev Teams + * + * Hercules is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef UNIT_UNITDEFINES_H +#define UNIT_UNITDEFINES_H + +/** + * Used for directions, @see unit_data.dir + */ +enum unit_dir { + UNIT_DIR_UNDEFINED = -1, + UNIT_DIR_FIRST = 0, + UNIT_DIR_NORTH = 0, + UNIT_DIR_NORTHWEST = 1, + UNIT_DIR_WEST = 2, + UNIT_DIR_SOUTHWEST = 3, + UNIT_DIR_SOUTH = 4, + UNIT_DIR_SOUTHEAST = 5, + UNIT_DIR_EAST = 6, + UNIT_DIR_NORTHEAST = 7, + UNIT_DIR_MAX = 8, + /* IMPORTANT: Changing the order would break the above macros + * and several usages of directions anywhere */ +}; + +/* Returns the opposite of the facing direction */ +#define unit_get_opposite_dir(dir) ( ((dir) + 4) % UNIT_DIR_MAX ) + +/* Returns true when direction is diagonal/combined (ex. UNIT_DIR_NORTHWEST, UNIT_DIR_SOUTHWEST, ...) */ +#define unit_is_diagonal_dir(dir) ( ((dir) % 2) == UNIT_DIR_NORTHWEST ) + +/* Returns true if direction equals val or the opposite direction of val */ +#define unit_is_dir_or_opposite(dir, val) ( ((dir) % 4) == (val) ) + +/* Returns the next direction after 90° CCW on a compass */ +#define unit_get_ccw90_dir(dir) ( ((dir) + 2) % UNIT_DIR_MAX ) + +/* Returns a random diagonal direction */ +#define unit_get_rnd_diagonal_dir() ( UNIT_DIR_NORTHWEST + 2 * (rnd() % 4) ) + +#endif /* UNIT_UNITDEFINES_H */ -- cgit v1.2.3-70-g09d2 From d13b24a62ac933364839c7ece1f70eba001e7c2d Mon Sep 17 00:00:00 2001 From: skyleo Date: Sun, 8 Sep 2019 02:53:24 +0200 Subject: 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. --- src/map/atcommand.c | 42 +++++++--- src/map/battle.c | 23 +++--- src/map/clif.c | 10 +-- src/map/map.c | 40 ++++++---- src/map/npc.c | 2 +- src/map/npc.h | 4 +- src/map/script.c | 26 +++--- src/map/skill.c | 225 ++++++++++++++++++++++++---------------------------- src/map/skill.h | 10 +-- src/map/unit.c | 28 +++---- src/map/unit.h | 2 +- 11 files changed, 207 insertions(+), 205 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 707522423..410cd7af7 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -4123,16 +4123,36 @@ ACMD(mapinfo) for (i = 0; i < map->list[m_id].npc_num;) { struct npc_data *nd = map->list[m_id].npc[i]; switch(nd->dir) { - case 0: strcpy(direction, msg_fd(fd,1101)); break; // North - case 1: strcpy(direction, msg_fd(fd,1102)); break; // North West - case 2: strcpy(direction, msg_fd(fd,1103)); break; // West - case 3: strcpy(direction, msg_fd(fd,1104)); break; // South West - case 4: strcpy(direction, msg_fd(fd,1105)); break; // South - case 5: strcpy(direction, msg_fd(fd,1106)); break; // South East - case 6: strcpy(direction, msg_fd(fd,1107)); break; // East - case 7: strcpy(direction, msg_fd(fd,1108)); break; // North East - case 9: strcpy(direction, msg_fd(fd,1109)); break; // North - default: strcpy(direction, msg_fd(fd,1110)); break; // Unknown + case UNIT_DIR_NORTH: + strcpy(direction, msg_fd(fd, 1101)); // North + break; + case UNIT_DIR_NORTHWEST: + strcpy(direction, msg_fd(fd, 1102)); // North West + break; + case UNIT_DIR_WEST: + strcpy(direction, msg_fd(fd, 1103)); // West + break; + case UNIT_DIR_SOUTHWEST: + strcpy(direction, msg_fd(fd, 1104)); // South West + break; + case UNIT_DIR_SOUTH: + strcpy(direction, msg_fd(fd, 1105)); // South + break; + case UNIT_DIR_SOUTHEAST: + strcpy(direction, msg_fd(fd, 1106)); // South East + break; + case UNIT_DIR_EAST: + strcpy(direction, msg_fd(fd, 1107)); // East + break; + case UNIT_DIR_NORTHEAST: + strcpy(direction, msg_fd(fd, 1108)); // North East + break; + case 9: // is this actually used? [skyleo] + strcpy(direction, msg_fd(fd, 1109)); // North + break; + default: + strcpy(direction, msg_fd(fd, 1110)); // Unknown + break; } if(strcmp(nd->name,nd->exname) == 0) safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1111), // NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d @@ -6899,7 +6919,7 @@ ACMD(identify) } } } - + if (num == 0) clif->message(fd,msg_fd(fd,1238)); // There are no items to appraise. else if (!identifyall) 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. diff --git a/src/map/clif.c b/src/map/clif.c index 3022d7f69..a0ffeac32 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -11348,15 +11348,7 @@ static void clif_parse_MapMove(int fd, struct map_session_data *sd) /// 0 = straight /// 1 = turned CW /// 2 = turned CCW -/// dir: -/// 0 = north -/// 1 = northwest -/// 2 = west -/// 3 = southwest -/// 4 = south -/// 5 = southeast -/// 6 = east -/// 7 = northeast +/// dir: @see enum unit_dir static void clif_changed_dir(struct block_list *bl, enum send_target target) { unsigned char buf[64]; diff --git a/src/map/map.c b/src/map/map.c index 9637609ec..e0ab2b08d 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1670,7 +1670,7 @@ static int map_search_freecell(struct block_list *src, int16 m, int16 *x, int16 *------------------------------------------*/ static bool map_closest_freecell(int16 m, const struct block_list *bl, int16 *x, int16 *y, int type, int flag) { - uint8 dir = 6; + enum unit_dir dir = UNIT_DIR_EAST; int16 tx; int16 ty; int costrange = 10; @@ -1689,7 +1689,7 @@ static bool map_closest_freecell(int16 m, const struct block_list *bl, int16 *x, short dy = diry[dir]; //Linear search - if(dir%2 == 0 && costrange%MOVE_COST == 0) { + if (!unit_is_diagonal_dir(dir) && (costrange % MOVE_COST) == 0) { tx = *x+dx*(costrange/MOVE_COST); ty = *y+dy*(costrange/MOVE_COST); if (!map->count_oncell(m, tx, ty, type, flag) && map->getcell(m, bl, tx, ty, CELL_CHKPASS)) { @@ -1699,7 +1699,7 @@ static bool map_closest_freecell(int16 m, const struct block_list *bl, int16 *x, } } //Full diagonal search - else if(dir%2 == 1 && costrange%MOVE_DIAGONAL_COST == 0) { + else if (unit_is_diagonal_dir(dir) && (costrange % MOVE_DIAGONAL_COST) == 0) { tx = *x+dx*(costrange/MOVE_DIAGONAL_COST); ty = *y+dy*(costrange/MOVE_DIAGONAL_COST); if (!map->count_oncell(m, tx, ty, type, flag) && map->getcell(m, bl, tx, ty, CELL_CHKPASS)) { @@ -1709,16 +1709,24 @@ static bool map_closest_freecell(int16 m, const struct block_list *bl, int16 *x, } } //One cell diagonal, rest linear (TODO: Find a better algorithm for this) - else if(dir%2 == 1 && costrange%MOVE_COST == 4) { - tx = *x+dx*((dir%4==3)?(costrange/MOVE_COST):1); - ty = *y+dy*((dir%4==1)?(costrange/MOVE_COST):1); + else if (unit_is_diagonal_dir(dir) && (costrange % MOVE_COST) == 4) { + tx = *x + dx; + ty = *y + dy; + if (unit_is_dir_or_opposite(dir, UNIT_DIR_SOUTHWEST)) + tx *= costrange / MOVE_COST; + if (unit_is_dir_or_opposite(dir, UNIT_DIR_NORTHWEST)) + ty *= costrange / MOVE_COST; if (!map->count_oncell(m, tx, ty, type, flag) && map->getcell(m, bl, tx, ty, CELL_CHKPASS)) { *x = tx; *y = ty; return true; } - tx = *x+dx*((dir%4==1)?(costrange/MOVE_COST):1); - ty = *y+dy*((dir%4==3)?(costrange/MOVE_COST):1); + tx = *x + dx; + ty = *y + dy; + if (unit_is_dir_or_opposite(dir, UNIT_DIR_NORTHWEST)) + tx *= costrange / MOVE_COST; + if (unit_is_dir_or_opposite(dir, UNIT_DIR_SOUTHWEST)) + ty *= costrange / MOVE_COST; if (!map->count_oncell(m, tx, ty, type, flag) && map->getcell(m, bl, tx, ty, CELL_CHKPASS)) { *x = tx; *y = ty; @@ -1727,17 +1735,17 @@ static bool map_closest_freecell(int16 m, const struct block_list *bl, int16 *x, } //Get next direction - if (dir == 5) { + if (dir == UNIT_DIR_SOUTHEAST) { //Diagonal search complete, repeat with higher cost range if(costrange == 14) costrange += 6; else if(costrange == 28 || costrange >= 38) costrange += 2; else costrange += 4; - dir = 6; - } else if (dir == 4) { + dir = UNIT_DIR_EAST; + } else if (dir == UNIT_DIR_SOUTH) { //Linear search complete, switch to diagonal directions - dir = 7; + dir = UNIT_DIR_NORTHEAST; } else { - dir = (dir+2)%8; + dir = unit_get_ccw90_dir(dir); } } @@ -2936,11 +2944,11 @@ static int map_random_dir(struct block_list *bl, int16 *x, int16 *y) if (dist < 1) dist =1; do { - int j = 1 + 2*(rnd()%4); //Pick a random diagonal direction + enum unit_dir dir = unit_get_rnd_diagonal_dir(); short segment = 1+(rnd()%dist); //Pick a random interval from the whole vector in that direction - xi = bl->x + segment*dirx[j]; + xi = bl->x + segment * dirx[dir]; segment = (short)sqrt((float)(dist2 - segment*segment)); //The complement of the previously picked segment - yi = bl->y + segment*diry[j]; + yi = bl->y + segment * diry[dir]; } while ((map->getcell(bl->m, bl, xi, yi, CELL_CHKNOPASS) || !path->search(NULL, bl, bl->m, bl->x, bl->y, xi, yi, 1, CELL_CHKNOREACH)) && (++i)<100); diff --git a/src/map/npc.c b/src/map/npc.c index e66888a74..2ac99948b 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -3391,7 +3391,7 @@ static bool npc_viewisid(const char *viewid) * @param class_ The NPC view class. * @return A pointer to the created NPC data (ownership passed to the caller). */ -static struct npc_data *npc_create_npc(enum npc_subtype subtype, int m, int x, int y, uint8 dir, int class_) +static struct npc_data *npc_create_npc(enum npc_subtype subtype, int m, int x, int y, enum unit_dir dir, int class_) { struct npc_data *nd; diff --git a/src/map/npc.h b/src/map/npc.h index 65c9796d9..1585a2bc8 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -95,7 +95,7 @@ struct npc_data { int chat_id; int touching_id; int64 next_walktime; - uint8 dir; + enum unit_dir dir; uint8 area_size; int clan_id; @@ -281,7 +281,7 @@ struct npc_interface { void (*parsename) (struct npc_data *nd, const char *name, const char *start, const char *buffer, const char *filepath); int (*parseview) (const char *w4, const char *start, const char *buffer, const char *filepath); bool (*viewisid) (const char *viewid); - struct npc_data *(*create_npc) (enum npc_subtype subtype, int m, int x, int y, uint8 dir, int class_); + struct npc_data *(*create_npc) (enum npc_subtype subtype, int m, int x, int y, enum unit_dir dir, int class_); struct npc_data* (*add_warp) (char *name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y); const char *(*parse_warp) (const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval); const char *(*parse_shop) (const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval); diff --git a/src/map/script.c b/src/map/script.c index 0e30708d9..28d06a8f1 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -19727,7 +19727,7 @@ static BUILDIN(setunitdata) clif->changelook(bl, LOOK_WEAPON, val); break; case UDT_LOOKDIR: - unit->setdir(bl, (uint8) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: md->ud.canmove_tick = val; @@ -19859,7 +19859,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &hd->base_status, hd->homunculus.level); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: hd->ud.canmove_tick = val; @@ -19998,7 +19998,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &pd->status, pd->pet.level); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: pd->ud.canmove_tick = val; @@ -20131,7 +20131,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &mc->base_status, mc->db->lv); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: mc->ud.canmove_tick = val; @@ -20265,7 +20265,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &ed->base_status, ed->db->lv); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: ed->ud.canmove_tick = val; @@ -20397,7 +20397,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &nd->status, nd->level); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_STR: nd->status.str = (unsigned short) val; @@ -23250,7 +23250,6 @@ static BUILDIN(progressbar_unit) } static BUILDIN(pushpc) { - uint8 dir; int cells, dx, dy; struct map_session_data* sd; @@ -23259,14 +23258,14 @@ static BUILDIN(pushpc) return true; } - dir = script_getnum(st,2); - cells = script_getnum(st,3); + enum unit_dir dir = script_getnum(st, 2); + cells = script_getnum(st,3); - if (dir > 7) { + if (dir >= UNIT_DIR_MAX) { ShowWarning("buildin_pushpc: Invalid direction %d specified.\n", dir); script->reportsrc(st); - dir%= 8; // trim spin-over + dir %= UNIT_DIR_MAX; // trim spin-over } if(!cells) @@ -23275,10 +23274,11 @@ static BUILDIN(pushpc) } else if(cells<0) {// pushing backwards - dir = (dir+4)%8; // turn around - cells = -cells; + dir = unit_get_opposite_dir(dir); + cells = -cells; } + Assert_retr(false, dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); dx = dirx[dir]; dy = diry[dir]; diff --git a/src/map/skill.c b/src/map/skill.c index a8dbefbd7..668c1849c 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -1180,7 +1180,6 @@ static int skillnotok_mercenary(uint16 skill_id, struct mercenary_data *md) static struct s_skill_unit_layout *skill_get_unit_layout(uint16 skill_id, uint16 skill_lv, struct block_list *src, int x, int y) { int pos = skill->get_unit_layout_type(skill_id,skill_lv); - uint8 dir; nullpo_retr(&skill->dbs->unit_layout[0], src); if (pos < -1 || pos >= MAX_SKILL_UNIT_LAYOUT) { @@ -1191,7 +1190,9 @@ static struct s_skill_unit_layout *skill_get_unit_layout(uint16 skill_id, uint16 if (pos != -1) // simple single-definition layout return &skill->dbs->unit_layout[pos]; - dir = (src->x == x && src->y == y) ? 6 : map->calc_dir(src,x,y); // 6 - default aegis direction + enum unit_dir dir = UNIT_DIR_EAST; // default aegis direction + if (src->x != x || src->y != y) + dir = map->calc_dir(src, x, y); if (skill_id == MG_FIREWALL) return &skill->dbs->unit_layout [skill->firewall_unit_pos + dir]; @@ -2626,11 +2627,11 @@ static int skill_strip_equip(struct block_list *bl, unsigned short where, int ra /*========================================================================= * Used to knock back players, monsters, traps, etc * 'count' is the number of squares to knock back - * 'direction' indicates the way OPPOSITE to the knockback direction (or -1 for default behavior) + * 'direction' indicates the way OPPOSITE to the knockback direction (or UNIT_DIR_UNDEFINED for default behavior) * if 'flag&0x1', position update packets must not be sent. * if 'flag&0x2', skill blown ignores players' special_state.no_knockback */ -static int skill_blown(struct block_list *src, struct block_list *target, int count, int8 dir, int flag) +static int skill_blown(struct block_list *src, struct block_list *target, int count, enum unit_dir dir, int flag) { int dx = 0, dy = 0; struct status_change *tsc = status->get_sc(target); @@ -2672,10 +2673,10 @@ static int skill_blown(struct block_list *src, struct block_list *target, int co break; } - if (dir == -1) // : do the computation here instead of outside + if (dir == UNIT_DIR_UNDEFINED) // : do the computation here instead of outside dir = map->calc_dir(target, src->x, src->y); // direction from src to target, reversed - if (dir >= 0 && dir < 8) { + if (dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX) { // take the reversed 'direction' and reverse it dx = -dirx[dir]; dy = -diry[dir]; @@ -3297,7 +3298,7 @@ static int skill_attack(int attack_type, struct block_list *src, struct block_li //Only knockback if it's still alive, otherwise a "ghost" is left behind. [Skotlex] //Reflected spells do not bounce back (bl == dsrc since it only happens for direct skills) if (dmg.blewcount > 0 && bl!=dsrc && !status->isdead(bl)) { - int8 dir = -1; // default + enum unit_dir dir = UNIT_DIR_UNDEFINED; // default switch(skill_id) {//direction case MG_FIREWALL: case PR_SANCTUARY: @@ -3310,16 +3311,16 @@ static int skill_attack(int attack_type, struct block_list *src, struct block_li // This ensures the storm randomly pushes instead of exactly a cell backwards per official mechanics. case WZ_STORMGUST: if(!battle_config.stormgust_knockback) - dir = rnd()%8; + dir = rnd() % UNIT_DIR_MAX; break; case WL_CRIMSONROCK: dir = map->calc_dir(bl,skill->area_temp[4],skill->area_temp[5]); break; case MC_CARTREVOLUTION: - dir = 6; // Official servers push target to the West + dir = UNIT_DIR_EAST; // Official servers push target to the West break; default: - dir = skill->attack_dir_unknown(&attack_type, src, dsrc, bl, &skill_id, &skill_lv, &tick, &flag); + dir = UNIT_DIR_UNDEFINED; break; } @@ -3337,8 +3338,9 @@ static int skill_attack(int attack_type, struct block_list *src, struct block_li case SR_KNUCKLEARROW: if( skill->blown(dsrc,bl,dmg.blewcount,dir,0) && !(flag&4) ) { short dir_x, dir_y; - dir_x = dirx[(dir+4)%8]; - dir_y = diry[(dir+4)%8]; + Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + dir_x = dirx[unit_get_opposite_dir(dir)]; + dir_y = diry[unit_get_opposite_dir(dir)]; if (map->getcell(bl->m, bl, bl->x + dir_x, bl->y + dir_y, CELL_CHKNOPASS) != 0) skill->addtimerskill(src, tick + 300 * ((flag&2) ? 1 : 2), bl->id, 0, 0, skill_id, skill_lv, BF_WEAPON, flag|4); } @@ -3496,12 +3498,9 @@ static int skill_attack_copy_unknown(int *attack_type, struct block_list *src, s return *skill_id; } -static int skill_attack_dir_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag) -{ - return -1; -} - -static void skill_attack_blow_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, int8 *dir) +static void skill_attack_blow_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, + uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, + struct Damage *dmg, int64 *damage, enum unit_dir *dir) { nullpo_retv(bl); nullpo_retv(dmg); @@ -3512,7 +3511,7 @@ static void skill_attack_blow_unknown(int *attack_type, struct block_list *src, if (!dmg->blewcount && bl->type == BL_SKILL && *damage > 0){ struct skill_unit *su = BL_UCAST(BL_SKILL, bl); if (su->group && su->group->skill_id == HT_BLASTMINE) - skill->blown(src, bl, 3, -1, 0); + skill->blown(src, bl, 3, UNIT_DIR_UNDEFINED, 0); } } @@ -4406,7 +4405,7 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl case KN_CHARGEATK: { bool path_exists = path->search_long(NULL, src, src->m, src->x, src->y, bl->x, bl->y,CELL_CHKWALL); unsigned int dist = distance_bl(src, bl); - uint8 dir = map->calc_dir(bl, src->x, src->y); + enum unit_dir dir = map->calc_dir(bl, src->x, src->y); // teleport to target (if not on WoE grounds) if( !map_flag_gvg2(src->m) && !map->list[src->m].flag.battleground && unit->movepos(src, bl->x, bl->y, 0, 1) ) @@ -4418,7 +4417,7 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl skill->blown(src, bl, dist, dir, 0); //HACK: since knockback officially defaults to the left, the client also turns to the left... therefore, // make the caster look in the direction of the target - unit->setdir(src, (dir+4)%8); + unit->setdir(src, unit_get_opposite_dir(dir)); } } @@ -4457,11 +4456,12 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl case RG_BACKSTAP: { - uint8 dir = map->calc_dir(src, bl->x, bl->y), t_dir = unit->getdir(bl); - if ((!check_distance_bl(src, bl, 0) && !map->check_dir(dir, t_dir)) || bl->type == BL_SKILL) { + enum unit_dir dir = map->calc_dir(src, bl->x, bl->y); + enum unit_dir t_dir = unit->getdir(bl); + if ((!check_distance_bl(src, bl, 0) && map->check_dir(dir, t_dir) == 0) || bl->type == BL_SKILL) { status_change_end(src, SC_HIDING, INVALID_TIMER); skill->attack(BF_WEAPON, src, src, bl, skill_id, skill_lv, tick, flag); - dir = dir < 4 ? dir+4 : dir-4; // change direction [Celest] + dir = unit_get_opposite_dir(dir); // change direction [Celest] unit->setdir(bl,dir); } else if (sd) @@ -4489,7 +4489,6 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl { short x, y, i = 2; // Move 2 cells for Issen(from target) struct block_list *mbl = bl; - short dir = 0; skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,flag); @@ -4511,13 +4510,13 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl status->set_hp(src, 1, STATUS_HEAL_DEFAULT); #endif // RENEWAL } - dir = map->calc_dir(src,bl->x,bl->y); - if( dir > 0 && dir < 4) x = -i; - else if( dir > 4 ) x = i; - else x = 0; - if( dir > 2 && dir < 6 ) y = -i; - else if( dir == 7 || dir < 2 ) y = i; - else y = 0; + enum unit_dir dir = map->calc_dir(src, bl->x, bl->y); + if (Assert_chk(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX)) { + map->freeblock_unlock(); // unblock before assert-returning + return 0; + } + x = i * dirx[dir]; + y = i * diry[dir]; if ((mbl == src || (!map_flag_gvg2(src->m) && !map->list[src->m].flag.battleground))) { // only NJ_ISSEN don't have slide effect in GVG if (!(unit->movepos(src, mbl->x+x, mbl->y+y, 1, 1))) { // The cell is not reachable (wall, object, ...), move next to the target @@ -4744,12 +4743,12 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl if(idb_exists(skill->bowling_db, bl->id)) break; // Random direction - dir = rnd()%8; + dir = rnd() % UNIT_DIR_MAX; } else { // Create an empty list of already hit targets db_clear(skill->bowling_db); // Direction is walkpath - dir = (unit->getdir(src)+4)%8; + dir = unit_get_opposite_dir(unit->getdir(src)); } // Add current target to the list of already hit targets idb_put(skill->bowling_db, bl->id, bl); @@ -4758,6 +4757,7 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl ty = bl->y; for(i=0;i= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); tx -= dirx[dir]; ty -= diry[dir]; // If target cell is a wall then break @@ -4786,18 +4786,21 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl if (bl->id==skill->area_temp[1]) break; if (skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,SD_ANIMATION)) - skill->blown(src,bl,skill->area_temp[2],-1,0); + skill->blown(src, bl, skill->area_temp[2], UNIT_DIR_UNDEFINED, 0); } else { - int x=bl->x,y=bl->y,i,dir; - dir = map->calc_dir(bl,src->x,src->y); + int x = bl->x; + int y = bl->y; + int i; + enum unit_dir dir = map->calc_dir(bl, src->x, src->y); skill->area_temp[1] = bl->id; skill->area_temp[2] = skill->get_blewcount(skill_id,skill_lv); // all the enemies between the caster and the target are hit, as well as the target if (skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,0)) - skill->blown(src,bl,skill->area_temp[2],-1,0); + skill->blown(src, bl, skill->area_temp[2], UNIT_DIR_UNDEFINED, 0); for (i=0;i<4;i++) { map->foreachincell(skill->area_sub,bl->m,x,y,BL_CHAR,src,skill_id,skill_lv, tick,flag|BCT_ENEMY|1,skill->castend_damage_id); + Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); x += dirx[dir]; y += diry[dir]; } @@ -5019,7 +5022,7 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl if(rnd()%100 < (10 + 3*skill_lv)) { if( !sd || pc->checkskill(sd,KN_SPEARBOOMERANG) == 0 ) break; // Spear Boomerang auto cast chance only works if you have mastered Spear Boomerang. - skill->blown(src,bl,6,-1,0); + skill->blown(src, bl, 6, UNIT_DIR_UNDEFINED, 0); skill->addtimerskill(src,tick+800,bl->id,0,0,skill_id,skill_lv,BF_WEAPON,flag); skill->castend_damage_id(src,bl,KN_SPEARBOOMERANG,1,tick,0); } @@ -5041,16 +5044,10 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl case KO_JYUMONJIKIRI: case GC_DARKILLUSION: { - short x, y; - short dir = map->calc_dir(bl, src->x, src->y); - - if ( dir < 4 ) { - x = bl->x + 2 * (dir > 0) - 3 * (dir > 0); - y = bl->y + 1 - (dir / 2) - (dir > 2); - } else { - x = bl->x + 2 * (dir > 4) - 1 * (dir > 4); - y = bl->y + (dir / 6) - 1 + (dir > 6); - } + enum unit_dir dir = map->calc_dir(bl, src->x, src->y); + Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + short x = bl->x + dirx[dir]; + short y = bl->y + diry[dir]; if ( unit->movepos(src, x, y, 1, 1) ) { clif->slide(src, x, y); @@ -5207,14 +5204,13 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl skill->attack(BF_MAGIC,src,src,bl,skill_id,skill_lv,tick,flag|ELE_DARK); break; case RA_WUGSTRIKE: - if( sd && pc_isridingwug(sd) ){ - short x[8]={0,-1,-1,-1,0,1,1,1}; - short y[8]={1,1,0,-1,-1,-1,0,1}; - uint8 dir = map->calc_dir(bl, src->x, src->y); - - if( unit->movepos(src, bl->x+x[dir], bl->y+y[dir], 1, 1) ) - { - clif->slide(src, bl->x+x[dir], bl->y+y[dir]); + if (sd != NULL && pc_isridingwug(sd)) { + enum unit_dir dir = map->calc_dir(bl, src->x, src->y); + Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + short x = bl->x + dirx[dir]; + short y = bl->y + diry[dir]; + if (unit->movepos(src, x, y, 1, 1) != 0) { + clif->slide(src, x, y); clif->fixpos(src); skill->attack(BF_WEAPON, src, src, bl, skill_id, skill_lv, tick, flag); } @@ -5657,8 +5653,9 @@ static int skill_castend_id(int tid, int64 tick, int id, intptr_t data) } if(ud->skill_id == RG_BACKSTAP) { - uint8 dir = map->calc_dir(src,target->x,target->y),t_dir = unit->getdir(target); - if(check_distance_bl(src, target, 0) || map->check_dir(dir,t_dir)) { + enum unit_dir dir = map->calc_dir(src, target->x, target->y); + enum unit_dir t_dir = unit->getdir(target); + if (check_distance_bl(src, target, 0) || map->check_dir(dir, t_dir) != 0) { break; } } @@ -5877,25 +5874,13 @@ static int skill_castend_id(int tid, int64 tick, int id, intptr_t data) } if (target && target->m == src->m) { //Move character to target anyway. - int dir, x, y; + enum unit_dir dir = map->calc_dir(src, target->x, target->y); + Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); int dist = 3; // number of cells that asura caster will walk + int x = dist * dirx[dir]; + int y = dist * diry[dir]; - dir = map->calc_dir(src,target->x,target->y); - if (dir > 0 && dir < 4) - x = -dist; - else if (dir > 4) - x = dist; - else - x = 0; - - if (dir > 2 && dir < 6) - y = -dist; - else if (dir == 7 || dir < 2) - y = dist; - else - y = 0; - - if (unit->movepos(src, src->x + x, src->y + y, 1, 1) == 1) { + if (unit->movepos(src, src->x + x, src->y + y, 1, 1) != 0) { //Display movement + animation. clif->slide(src, src->x, src->y); clif->spiritball(src); @@ -7835,7 +7820,9 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list * case TK_HIGHJUMP: { - int x,y, dir = unit->getdir(src); + int x; + int y; + enum unit_dir dir = unit->getdir(src); //Fails on noteleport maps, except for GvG and BG maps [Skotlex] if( map->list[src->m].flag.noteleport @@ -8084,11 +8071,16 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list * case NPC_RUN: { - const int mask[8][2] = {{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1}}; - uint8 dir = (bl == src)?unit->getdir(src):map->calc_dir(src,bl->x,bl->y); //If cast on self, run forward, else run away. + enum unit_dir dir; + if (bl == src) //If cast on self, run forward, else run away. + dir = unit->getdir(src); + else + dir = map->calc_dir(src, bl->x, bl->y); + Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); unit->stop_attack(src); //Run skillv tiles overriding the can-move check. - if (unit->walktoxy(src, src->x + skill_lv * mask[dir][0], src->y + skill_lv * mask[dir][1], 2) && md) + if (unit->walktoxy(src, (src->x + skill_lv * -dirx[dir]), + (src->y + skill_lv * -diry[dir]), 2) != 0 && md != NULL) md->state.skillstate = MSS_WALK; //Otherwise it isn't updated in the AI. } break; @@ -9449,7 +9441,9 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list * case NC_F_SIDESLIDE: case NC_B_SIDESLIDE: { - uint8 dir = (skill_id == NC_F_SIDESLIDE) ? (unit->getdir(src)+4)%8 : unit->getdir(src); + enum unit_dir dir = unit->getdir(src); + if (skill_id == NC_F_SIDESLIDE) + dir = unit_get_opposite_dir(dir); skill->blown(src,bl,skill->get_blewcount(skill_id,skill_lv),dir,0); clif->slide(src,src->x,src->y); clif->skill_nodamage(src,bl,skill_id,skill_lv,1); @@ -11606,17 +11600,16 @@ static int skill_castend_pos2(struct block_list *src, int x, int y, uint16 skill case WL_EARTHSTRAIN: { - int i, wave = skill_lv + 4, dir = map->calc_dir(src,x,y); + int i; + int wave = skill_lv + 4; + enum unit_dir dir = map->calc_dir(src, x, y); + Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); int sx = x = src->x, sy = y = src->y; // Store first caster's location to avoid glitch on unit setting - for( i = 1; i <= wave; i++ ) - { - switch( dir ){ - case 0: case 1: case 7: sy = y + i; break; - case 3: case 4: case 5: sy = y - i; break; - case 2: sx = x - i; break; - case 6: sx = x + i; break; - } + for (i = 1; i <= wave; i++) { + sy = y + i * diry[dir]; + if (dir == UNIT_DIR_WEST || dir == UNIT_DIR_EAST) + sx = x + i * dirx[dir]; skill->addtimerskill(src,timer->gettick() + (140 * i),0,sx,sy,skill_id,skill_lv,dir,flag&2); } } @@ -13835,12 +13828,14 @@ static int skill_check_condition_char_sub(struct block_list *bl, va_list ap) } else { switch(skill_id) { - case PR_BENEDICTIO: { - uint8 dir = map->calc_dir(&sd->bl,tsd->bl.x,tsd->bl.y); - dir = (unit->getdir(&sd->bl) + dir)%8; //This adjusts dir to account for the direction the sd is facing. - if ((tsd->job & MAPID_BASEMASK) == MAPID_ACOLYTE && (dir == 2 || dir == 6) //Must be standing to the left/right of Priest. - && sd->status.sp >= 10) + case PR_BENEDICTIO: + { + enum unit_dir dir = map->calc_dir(&sd->bl, tsd->bl.x, tsd->bl.y); + dir = (unit->getdir(&sd->bl) + dir) % UNIT_DIR_MAX; //This adjusts dir to account for the direction the sd is facing. + if ((tsd->job & MAPID_BASEMASK) == MAPID_ACOLYTE && (dir == UNIT_DIR_WEST || dir == UNIT_DIR_EAST) //Must be standing to the left/right of Priest. + && sd->status.sp >= 10) { p_sd[(*c)++]=tsd->bl.id; + } return 1; } case AB_ADORAMUS: @@ -15976,11 +15971,11 @@ struct square { int val2[5]; }; -static void skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int16 y) +static void skill_brandishspear_first(struct square *tc, enum unit_dir dir, int16 x, int16 y) { nullpo_retv(tc); - if(dir == 0){ + if (dir == UNIT_DIR_NORTH) { tc->val1[0]=x-2; tc->val1[1]=x-1; tc->val1[2]=x; @@ -15991,7 +15986,7 @@ static void skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int tc->val2[2]= tc->val2[3]= tc->val2[4]=y-1; - } else if(dir==2){ + } else if (dir == UNIT_DIR_WEST) { tc->val1[0]= tc->val1[1]= tc->val1[2]= @@ -16002,7 +15997,7 @@ static void skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int tc->val2[2]=y; tc->val2[3]=y-1; tc->val2[4]=y-2; - } else if(dir==4){ + } else if (dir == UNIT_DIR_SOUTH) { tc->val1[0]=x-2; tc->val1[1]=x-1; tc->val1[2]=x; @@ -16013,7 +16008,7 @@ static void skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int tc->val2[2]= tc->val2[3]= tc->val2[4]=y+1; - } else if(dir==6){ + } else if (dir == UNIT_DIR_EAST) { tc->val1[0]= tc->val1[1]= tc->val1[2]= @@ -16024,7 +16019,7 @@ static void skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int tc->val2[2]=y; tc->val2[3]=y-1; tc->val2[4]=y-2; - } else if(dir==1){ + } else if (dir == UNIT_DIR_NORTHWEST) { tc->val1[0]=x-1; tc->val1[1]=x; tc->val1[2]=x+1; @@ -16035,7 +16030,7 @@ static void skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int tc->val2[2]=y-1; tc->val2[3]=y; tc->val2[4]=y+1; - } else if(dir==3){ + } else if (dir == UNIT_DIR_SOUTHWEST) { tc->val1[0]=x+3; tc->val1[1]=x+2; tc->val1[2]=x+1; @@ -16046,7 +16041,7 @@ static void skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int tc->val2[2]=y+1; tc->val2[3]=y+2; tc->val2[4]=y+3; - } else if(dir==5){ + } else if (dir == UNIT_DIR_SOUTHEAST) { tc->val1[0]=x+1; tc->val1[1]=x; tc->val1[2]=x-1; @@ -16057,7 +16052,7 @@ static void skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int tc->val2[2]=y+1; tc->val2[3]=y; tc->val2[4]=y-1; - } else if(dir==7){ + } else if (dir == UNIT_DIR_NORTHEAST) { tc->val1[0]=x-3; tc->val1[1]=x-2; tc->val1[2]=x-1; @@ -16072,36 +16067,27 @@ static void skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int } -static void skill_brandishspear_dir(struct square *tc, uint8 dir, int are) +static void skill_brandishspear_dir(struct square *tc, enum unit_dir dir, int are) { - int c; nullpo_retv(tc); + Assert_retv(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); - for( c = 0; c < 5; c++ ) { - switch( dir ) { - case 0: tc->val2[c]+=are; break; - case 1: tc->val1[c]-=are; tc->val2[c]+=are; break; - case 2: tc->val1[c]-=are; break; - case 3: tc->val1[c]-=are; tc->val2[c]-=are; break; - case 4: tc->val2[c]-=are; break; - case 5: tc->val1[c]+=are; tc->val2[c]-=are; break; - case 6: tc->val1[c]+=are; break; - case 7: tc->val1[c]+=are; tc->val2[c]+=are; break; - } + for (int c = 0; c < 5; c++) { + tc->val1[c] += dirx[dir] * are; + tc->val2[c] += diry[dir] * are; } } static void skill_brandishspear(struct block_list *src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int64 tick, int flag) { int c,n=4; - uint8 dir; struct square tc; int x, y; nullpo_retv(bl); x = bl->x; y = bl->y; - dir = map->calc_dir(src, x, y); + enum unit_dir dir = map->calc_dir(src, x, y); skill->brandishspear_first(&tc,dir,x,y); skill->brandishspear_dir(&tc,dir,4); skill->area_temp[1] = bl->id; @@ -21764,7 +21750,6 @@ void skill_defaults(void) skill->attack_combo2_unknown = skill_attack_combo2_unknown; skill->attack_display_unknown = skill_attack_display_unknown; skill->attack_copy_unknown = skill_attack_copy_unknown; - skill->attack_dir_unknown = skill_attack_dir_unknown; skill->attack_blow_unknown = skill_attack_blow_unknown; skill->attack_post_unknown = skill_attack_post_unknown; skill->timerskill_dead_unknown = skill_timerskill_dead_unknown; diff --git a/src/map/skill.h b/src/map/skill.h index eff9ed7fc..03062b199 100644 --- a/src/map/skill.h +++ b/src/map/skill.h @@ -23,6 +23,7 @@ #include "map/map.h" // struct block_list #include "map/status.h" // enum sc_type +#include "map/unitdefines.h" // enum unit_dir #include "common/hercules.h" #include "common/db.h" #include "common/mmo.h" // MAX_SKILL_DB, struct square @@ -2002,7 +2003,7 @@ struct skill_interface { int (*addtimerskill) (struct block_list *src, int64 tick, int target, int x, int y, uint16 skill_id, uint16 skill_lv, int type, int flag); int (*additional_effect) (struct block_list* src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int attack_type, int dmg_lv, int64 tick); int (*counter_additional_effect) (struct block_list* src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int attack_type, int64 tick); - int (*blown) (struct block_list* src, struct block_list* target, int count, int8 dir, int flag); + int (*blown) (struct block_list* src, struct block_list* target, int count, enum unit_dir dir, int flag); int (*break_equip) (struct block_list *bl, unsigned short where, int rate, int flag); int (*strip_equip) (struct block_list *bl, unsigned short where, int rate, int lv, int time); struct skill_unit_group* (*id2group) (int group_id); @@ -2085,8 +2086,8 @@ struct skill_interface { bool (*dance_switch) (struct skill_unit* su, int flag); int (*check_condition_char_sub) (struct block_list *bl, va_list ap); int (*check_condition_mob_master_sub) (struct block_list *bl, va_list ap); - void (*brandishspear_first) (struct square *tc, uint8 dir, int16 x, int16 y); - void (*brandishspear_dir) (struct square* tc, uint8 dir, int are); + void (*brandishspear_first) (struct square *tc, enum unit_dir dir, int16 x, int16 y); + void (*brandishspear_dir) (struct square* tc, enum unit_dir dir, int are); int (*get_fixed_cast) (int skill_id, int skill_lv); int (*sit_count) (struct block_list *bl, va_list ap); int (*sit_in) (struct block_list *bl, va_list ap); @@ -2162,8 +2163,7 @@ struct skill_interface { void (*attack_combo2_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *combo); void (*attack_display_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage); int (*attack_copy_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); - int (*attack_dir_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); - void (*attack_blow_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, int8 *dir); + void (*attack_blow_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, enum unit_dir *dir); void (*attack_post_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); bool (*timerskill_dead_unknown) (struct block_list *src, struct unit_data *ud, struct skill_timerskill *skl); void (*timerskill_target_unknown) (int tid, int64 tick, struct block_list *src, struct block_list *target, struct unit_data *ud, struct skill_timerskill *skl); diff --git a/src/map/unit.c b/src/map/unit.c index 3a940665d..19ad5423d 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -150,10 +150,11 @@ static int unit_walktoxy_sub(struct block_list *bl) // Trim the last part of the path to account for range, // but always move at least one cell when requested to move. for (int i = ud->chaserange * 10 - 10; i > 0 && ud->walkpath.path_len > 1;) { - uint8 dir; + enum unit_dir dir; ud->walkpath.path_len--; dir = ud->walkpath.path[ud->walkpath.path_len]; - if ((dir & 1) != 0) + Assert_retr(1, dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + if (unit_is_diagonal_dir(dir)) i -= MOVE_COST * 20; // When chasing, units will target a diamond-shaped area in range [Playtester] else i -= MOVE_COST; @@ -305,16 +306,15 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) if (ud->walkpath.path_pos >= ud->walkpath.path_len) return 1; - uint8 dir = ud->walkpath.path[ud->walkpath.path_pos]; - if (ud->walkpath.path[ud->walkpath.path_pos] >= 8) - return 1; + enum unit_dir dir = ud->walkpath.path[ud->walkpath.path_pos]; + Assert_retr(1, dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); int x = bl->x; int y = bl->y; ud->dir = dir; - int dx = dirx[(int) dir]; - int dy = diry[(int) dir]; + int dx = dirx[dir]; + int dy = diry[dir]; // Get icewall walk block depending on boss mode (players can't be trapped) unsigned char icewall_walk_block = 0; @@ -759,9 +759,9 @@ static bool unit_run(struct block_list *bl, struct map_session_data *sd, enum sc //Makes bl attempt to run dist cells away from target. Uses hard-paths. static int unit_escape(struct block_list *bl, struct block_list *target, short dist) { - uint8 dir; nullpo_ret(bl); - dir = map->calc_dir(target, bl->x, bl->y); + enum unit_dir dir = map->calc_dir(target, bl->x, bl->y); + Assert_retr(1, dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); while (dist > 0 && map->getcell(bl->m, bl, bl->x + dist * dirx[dir], bl->y + dist * diry[dir], CELL_CHKNOREACH)) dist--; return ( dist > 0 && unit->walktoxy(bl, bl->x + dist*dirx[dir], bl->y + dist*diry[dir], 0) ); @@ -771,7 +771,6 @@ static int unit_escape(struct block_list *bl, struct block_list *target, short d static int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath) { short dx,dy; - uint8 dir; struct unit_data *ud = NULL; struct map_session_data *sd = NULL; @@ -790,7 +789,7 @@ static int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int eas ud->to_x = dst_x; ud->to_y = dst_y; - dir = map->calc_dir(bl, dst_x, dst_y); + enum unit_dir dir = map->calc_dir(bl, dst_x, dst_y); ud->dir = dir; dx = dst_x - bl->x; @@ -2100,14 +2099,13 @@ static bool unit_can_reach_bl(struct block_list *bl, struct block_list *tbl, int /*========================================== * Calculates position of Pet/Mercenary/Homunculus/Elemental *------------------------------------------*/ -static int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir) +static int unit_calc_pos(struct block_list *bl, int tx, int ty, enum unit_dir dir) { int dx, dy, x, y; struct unit_data *ud = unit->bl2ud(bl); nullpo_ret(ud); - if(dir > 7) - return 1; + Assert_retr(1, dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); ud->to_x = tx; ud->to_y = ty; @@ -2124,7 +2122,7 @@ static int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir) if (!unit->can_reach_pos(bl, x, y, 0)) { int i; for (i = 0; i < 12; i++) { - int k = rnd()%8; // Pick a Random Dir + enum unit_dir k = rnd() % UNIT_DIR_MAX; // Pick a Random Dir dx = -dirx[k] * 2; dy = -diry[k] * 2; x = tx + dx; diff --git a/src/map/unit.h b/src/map/unit.h index bdee032f8..7c9dc1095 100644 --- a/src/map/unit.h +++ b/src/map/unit.h @@ -139,7 +139,7 @@ struct unit_interface { int (*cancel_combo) (struct block_list *bl); bool (*can_reach_pos) (struct block_list *bl, int x, int y, int easy); bool (*can_reach_bl) (struct block_list *bl, struct block_list *tbl, int range, int easy, short *x, short *y); - int (*calc_pos) (struct block_list *bl, int tx, int ty, uint8 dir); + int (*calc_pos) (struct block_list *bl, int tx, int ty, enum unit_dir dir); int (*attack_timer_sub) (struct block_list *src, int tid, int64 tick); int (*skillcastcancel) (struct block_list *bl, int type); void (*dataset) (struct block_list *bl); -- cgit v1.2.3-70-g09d2 From 5ab1da123f7bdad1aa448eb4552c44913855279c Mon Sep 17 00:00:00 2001 From: skyleo Date: Sun, 8 Sep 2019 19:37:45 +0200 Subject: Update HPM Hooks --- src/plugins/HPMHooking/HPMHooking.Defs.inc | 44 ++++---- .../HPMHooking/HPMHooking_map.HPMHooksCore.inc | 8 +- .../HPMHooking/HPMHooking_map.HookingPoints.inc | 2 +- src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 120 +++++++++++---------- 4 files changed, 88 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index 7996a59f9..4be3accf8 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -4734,10 +4734,10 @@ typedef uint32 (*HPMHOOK_pre_map_race_id2mask) (int *race); typedef uint32 (*HPMHOOK_post_map_race_id2mask) (uint32 retVal___, int race); typedef void (*HPMHOOK_pre_map_reloadnpc) (bool *clear); typedef void (*HPMHOOK_post_map_reloadnpc) (bool clear); -typedef int (*HPMHOOK_pre_map_check_dir) (int *s_dir, int *t_dir); -typedef int (*HPMHOOK_post_map_check_dir) (int retVal___, int s_dir, int t_dir); -typedef uint8 (*HPMHOOK_pre_map_calc_dir) (struct block_list **src, int16 *x, int16 *y); -typedef uint8 (*HPMHOOK_post_map_calc_dir) (uint8 retVal___, struct block_list *src, int16 x, int16 y); +typedef int (*HPMHOOK_pre_map_check_dir) (enum unit_dir *s_dir, enum unit_dir *t_dir); +typedef int (*HPMHOOK_post_map_check_dir) (int retVal___, enum unit_dir s_dir, enum unit_dir t_dir); +typedef enum unit_dir (*HPMHOOK_pre_map_calc_dir) (struct block_list **src, int16 *x, int16 *y); +typedef enum unit_dir (*HPMHOOK_post_map_calc_dir) (enum unit_dir retVal___, struct block_list *src, int16 x, int16 y); typedef int (*HPMHOOK_pre_map_random_dir) (struct block_list **bl, short **x, short **y); typedef int (*HPMHOOK_post_map_random_dir) (int retVal___, struct block_list *bl, short *x, short *y); typedef int (*HPMHOOK_pre_map_cleanup_sub) (struct block_list **bl, va_list ap); @@ -5708,8 +5708,8 @@ typedef int (*HPMHOOK_pre_npc_parseview) (const char **w4, const char **start, c typedef int (*HPMHOOK_post_npc_parseview) (int retVal___, const char *w4, const char *start, const char *buffer, const char *filepath); typedef bool (*HPMHOOK_pre_npc_viewisid) (const char **viewid); typedef bool (*HPMHOOK_post_npc_viewisid) (bool retVal___, const char *viewid); -typedef struct npc_data* (*HPMHOOK_pre_npc_create_npc) (enum npc_subtype *subtype, int *m, int *x, int *y, uint8 *dir, int *class_); -typedef struct npc_data* (*HPMHOOK_post_npc_create_npc) (struct npc_data* retVal___, enum npc_subtype subtype, int m, int x, int y, uint8 dir, int class_); +typedef struct npc_data* (*HPMHOOK_pre_npc_create_npc) (enum npc_subtype *subtype, int *m, int *x, int *y, enum unit_dir *dir, int *class_); +typedef struct npc_data* (*HPMHOOK_post_npc_create_npc) (struct npc_data* retVal___, enum npc_subtype subtype, int m, int x, int y, enum unit_dir dir, int class_); typedef struct npc_data* (*HPMHOOK_pre_npc_add_warp) (char **name, short *from_mapid, short *from_x, short *from_y, short *xs, short *ys, unsigned short *to_mapindex, short *to_x, short *to_y); typedef struct npc_data* (*HPMHOOK_post_npc_add_warp) (struct npc_data* retVal___, char *name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y); typedef const char* (*HPMHOOK_pre_npc_parse_warp) (const char **w1, const char **w2, const char **w3, const char **w4, const char **start, const char **buffer, const char **filepath, int **retval); @@ -7298,8 +7298,8 @@ typedef int (*HPMHOOK_pre_skill_additional_effect) (struct block_list **src, str typedef int (*HPMHOOK_post_skill_additional_effect) (int retVal___, struct block_list *src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int attack_type, int dmg_lv, int64 tick); typedef int (*HPMHOOK_pre_skill_counter_additional_effect) (struct block_list **src, struct block_list **bl, uint16 *skill_id, uint16 *skill_lv, int *attack_type, int64 *tick); typedef int (*HPMHOOK_post_skill_counter_additional_effect) (int retVal___, struct block_list *src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int attack_type, int64 tick); -typedef int (*HPMHOOK_pre_skill_blown) (struct block_list **src, struct block_list **target, int *count, int8 *dir, int *flag); -typedef int (*HPMHOOK_post_skill_blown) (int retVal___, struct block_list *src, struct block_list *target, int count, int8 dir, int flag); +typedef int (*HPMHOOK_pre_skill_blown) (struct block_list **src, struct block_list **target, int *count, enum unit_dir *dir, int *flag); +typedef int (*HPMHOOK_post_skill_blown) (int retVal___, struct block_list *src, struct block_list *target, int count, enum unit_dir dir, int flag); typedef int (*HPMHOOK_pre_skill_break_equip) (struct block_list **bl, unsigned short *where, int *rate, int *flag); typedef int (*HPMHOOK_post_skill_break_equip) (int retVal___, struct block_list *bl, unsigned short where, int rate, int flag); typedef int (*HPMHOOK_pre_skill_strip_equip) (struct block_list **bl, unsigned short *where, int *rate, int *lv, int *time); @@ -7464,10 +7464,10 @@ typedef int (*HPMHOOK_pre_skill_check_condition_char_sub) (struct block_list **b typedef int (*HPMHOOK_post_skill_check_condition_char_sub) (int retVal___, struct block_list *bl, va_list ap); typedef int (*HPMHOOK_pre_skill_check_condition_mob_master_sub) (struct block_list **bl, va_list ap); typedef int (*HPMHOOK_post_skill_check_condition_mob_master_sub) (int retVal___, struct block_list *bl, va_list ap); -typedef void (*HPMHOOK_pre_skill_brandishspear_first) (struct square **tc, uint8 *dir, int16 *x, int16 *y); -typedef void (*HPMHOOK_post_skill_brandishspear_first) (struct square *tc, uint8 dir, int16 x, int16 y); -typedef void (*HPMHOOK_pre_skill_brandishspear_dir) (struct square **tc, uint8 *dir, int *are); -typedef void (*HPMHOOK_post_skill_brandishspear_dir) (struct square *tc, uint8 dir, int are); +typedef void (*HPMHOOK_pre_skill_brandishspear_first) (struct square **tc, enum unit_dir *dir, int16 *x, int16 *y); +typedef void (*HPMHOOK_post_skill_brandishspear_first) (struct square *tc, enum unit_dir dir, int16 x, int16 y); +typedef void (*HPMHOOK_pre_skill_brandishspear_dir) (struct square **tc, enum unit_dir *dir, int *are); +typedef void (*HPMHOOK_post_skill_brandishspear_dir) (struct square *tc, enum unit_dir dir, int are); typedef int (*HPMHOOK_pre_skill_get_fixed_cast) (int *skill_id, int *skill_lv); typedef int (*HPMHOOK_post_skill_get_fixed_cast) (int retVal___, int skill_id, int skill_lv); typedef int (*HPMHOOK_pre_skill_sit_count) (struct block_list **bl, va_list ap); @@ -7606,10 +7606,8 @@ typedef void (*HPMHOOK_pre_skill_attack_display_unknown) (int **attack_type, str typedef void (*HPMHOOK_post_skill_attack_display_unknown) (int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage); typedef int (*HPMHOOK_pre_skill_attack_copy_unknown) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag); typedef int (*HPMHOOK_post_skill_attack_copy_unknown) (int retVal___, int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); -typedef int (*HPMHOOK_pre_skill_attack_dir_unknown) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag); -typedef int (*HPMHOOK_post_skill_attack_dir_unknown) (int retVal___, int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); -typedef void (*HPMHOOK_pre_skill_attack_blow_unknown) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag, int **type, struct Damage **dmg, int64 **damage, int8 **dir); -typedef void (*HPMHOOK_post_skill_attack_blow_unknown) (int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, int8 *dir); +typedef void (*HPMHOOK_pre_skill_attack_blow_unknown) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag, int **type, struct Damage **dmg, int64 **damage, enum unit_dir **dir); +typedef void (*HPMHOOK_post_skill_attack_blow_unknown) (int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, enum unit_dir *dir); typedef void (*HPMHOOK_pre_skill_attack_post_unknown) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag); typedef void (*HPMHOOK_post_skill_attack_post_unknown) (int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); typedef bool (*HPMHOOK_pre_skill_timerskill_dead_unknown) (struct block_list **src, struct unit_data **ud, struct skill_timerskill **skl); @@ -8314,14 +8312,16 @@ typedef int (*HPMHOOK_pre_unit_escape) (struct block_list **bl, struct block_lis typedef int (*HPMHOOK_post_unit_escape) (int retVal___, struct block_list *bl, struct block_list *target, short dist); typedef int (*HPMHOOK_pre_unit_movepos) (struct block_list **bl, short *dst_x, short *dst_y, int *easy, bool *checkpath); typedef int (*HPMHOOK_post_unit_movepos) (int retVal___, struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath); -typedef int (*HPMHOOK_pre_unit_setdir) (struct block_list **bl, unsigned char *dir); -typedef int (*HPMHOOK_post_unit_setdir) (int retVal___, struct block_list *bl, unsigned char dir); -typedef uint8 (*HPMHOOK_pre_unit_getdir) (struct block_list **bl); -typedef uint8 (*HPMHOOK_post_unit_getdir) (uint8 retVal___, struct block_list *bl); +typedef int (*HPMHOOK_pre_unit_setdir) (struct block_list **bl, enum unit_dir *dir); +typedef int (*HPMHOOK_post_unit_setdir) (int retVal___, struct block_list *bl, enum unit_dir dir); +typedef enum unit_dir (*HPMHOOK_pre_unit_getdir) (struct block_list **bl); +typedef enum unit_dir (*HPMHOOK_post_unit_getdir) (enum unit_dir retVal___, struct block_list *bl); typedef int (*HPMHOOK_pre_unit_blown) (struct block_list **bl, int *dx, int *dy, int *count, int *flag); typedef int (*HPMHOOK_post_unit_blown) (int retVal___, struct block_list *bl, int dx, int dy, int count, int flag); typedef int (*HPMHOOK_pre_unit_warp) (struct block_list **bl, short *m, short *x, short *y, enum clr_type *type); typedef int (*HPMHOOK_post_unit_warp) (int retVal___, struct block_list *bl, short m, short x, short y, enum clr_type type); +typedef int (*HPMHOOK_pre_unit_warpto_master) (struct block_list **master_bl, struct block_list **slave_bl); +typedef int (*HPMHOOK_post_unit_warpto_master) (int retVal___, struct block_list *master_bl, struct block_list *slave_bl); typedef int (*HPMHOOK_pre_unit_stop_walking) (struct block_list **bl, int *type); typedef int (*HPMHOOK_post_unit_stop_walking) (int retVal___, struct block_list *bl, int type); typedef int (*HPMHOOK_pre_unit_skilluse_id) (struct block_list **src, int *target_id, uint16 *skill_id, uint16 *skill_lv); @@ -8358,8 +8358,8 @@ typedef bool (*HPMHOOK_pre_unit_can_reach_pos) (struct block_list **bl, int *x, typedef bool (*HPMHOOK_post_unit_can_reach_pos) (bool retVal___, struct block_list *bl, int x, int y, int easy); typedef bool (*HPMHOOK_pre_unit_can_reach_bl) (struct block_list **bl, struct block_list **tbl, int *range, int *easy, short **x, short **y); typedef bool (*HPMHOOK_post_unit_can_reach_bl) (bool retVal___, struct block_list *bl, struct block_list *tbl, int range, int easy, short *x, short *y); -typedef int (*HPMHOOK_pre_unit_calc_pos) (struct block_list **bl, int *tx, int *ty, uint8 *dir); -typedef int (*HPMHOOK_post_unit_calc_pos) (int retVal___, struct block_list *bl, int tx, int ty, uint8 dir); +typedef int (*HPMHOOK_pre_unit_calc_pos) (struct block_list **bl, int *tx, int *ty, enum unit_dir *dir); +typedef int (*HPMHOOK_post_unit_calc_pos) (int retVal___, struct block_list *bl, int tx, int ty, enum unit_dir dir); typedef int (*HPMHOOK_pre_unit_attack_timer_sub) (struct block_list **src, int *tid, int64 *tick); typedef int (*HPMHOOK_post_unit_attack_timer_sub) (int retVal___, struct block_list *src, int tid, int64 tick); typedef int (*HPMHOOK_pre_unit_skillcastcancel) (struct block_list **bl, int *type); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index 6d8776f18..3e1b8af78 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -6130,8 +6130,6 @@ struct { struct HPMHookPoint *HP_skill_attack_display_unknown_post; struct HPMHookPoint *HP_skill_attack_copy_unknown_pre; struct HPMHookPoint *HP_skill_attack_copy_unknown_post; - struct HPMHookPoint *HP_skill_attack_dir_unknown_pre; - struct HPMHookPoint *HP_skill_attack_dir_unknown_post; struct HPMHookPoint *HP_skill_attack_blow_unknown_pre; struct HPMHookPoint *HP_skill_attack_blow_unknown_post; struct HPMHookPoint *HP_skill_attack_post_unknown_pre; @@ -6820,6 +6818,8 @@ struct { struct HPMHookPoint *HP_unit_blown_post; struct HPMHookPoint *HP_unit_warp_pre; struct HPMHookPoint *HP_unit_warp_post; + struct HPMHookPoint *HP_unit_warpto_master_pre; + struct HPMHookPoint *HP_unit_warpto_master_post; struct HPMHookPoint *HP_unit_stop_walking_pre; struct HPMHookPoint *HP_unit_stop_walking_post; struct HPMHookPoint *HP_unit_skilluse_id_pre; @@ -13001,8 +13001,6 @@ struct { int HP_skill_attack_display_unknown_post; int HP_skill_attack_copy_unknown_pre; int HP_skill_attack_copy_unknown_post; - int HP_skill_attack_dir_unknown_pre; - int HP_skill_attack_dir_unknown_post; int HP_skill_attack_blow_unknown_pre; int HP_skill_attack_blow_unknown_post; int HP_skill_attack_post_unknown_pre; @@ -13691,6 +13689,8 @@ struct { int HP_unit_blown_post; int HP_unit_warp_pre; int HP_unit_warp_post; + int HP_unit_warpto_master_pre; + int HP_unit_warpto_master_post; int HP_unit_stop_walking_pre; int HP_unit_stop_walking_post; int HP_unit_skilluse_id_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index 672b94dd8..2ec13f3ab 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -3134,7 +3134,6 @@ struct HookingPointData HookingPoints[] = { { HP_POP(skill->attack_combo2_unknown, HP_skill_attack_combo2_unknown) }, { HP_POP(skill->attack_display_unknown, HP_skill_attack_display_unknown) }, { HP_POP(skill->attack_copy_unknown, HP_skill_attack_copy_unknown) }, - { HP_POP(skill->attack_dir_unknown, HP_skill_attack_dir_unknown) }, { HP_POP(skill->attack_blow_unknown, HP_skill_attack_blow_unknown) }, { HP_POP(skill->attack_post_unknown, HP_skill_attack_post_unknown) }, { HP_POP(skill->timerskill_dead_unknown, HP_skill_timerskill_dead_unknown) }, @@ -3492,6 +3491,7 @@ struct HookingPointData HookingPoints[] = { { HP_POP(unit->getdir, HP_unit_getdir) }, { HP_POP(unit->blown, HP_unit_blown) }, { HP_POP(unit->warp, HP_unit_warp) }, + { HP_POP(unit->warpto_master, HP_unit_warpto_master) }, { HP_POP(unit->stop_walking, HP_unit_stop_walking) }, { HP_POP(unit->skilluse_id, HP_unit_skilluse_id) }, { HP_POP(unit->step_timer, HP_unit_step_timer) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 423490182..1623cadb6 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -48284,11 +48284,11 @@ void HP_map_reloadnpc(bool clear) { } return; } -int HP_map_check_dir(int s_dir, int t_dir) { +int HP_map_check_dir(enum unit_dir s_dir, enum unit_dir t_dir) { int hIndex = 0; int retVal___ = 0; if (HPMHooks.count.HP_map_check_dir_pre > 0) { - int (*preHookFunc) (int *s_dir, int *t_dir); + int (*preHookFunc) (enum unit_dir *s_dir, enum unit_dir *t_dir); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_map_check_dir_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_map_check_dir_pre[hIndex].func; @@ -48303,7 +48303,7 @@ int HP_map_check_dir(int s_dir, int t_dir) { retVal___ = HPMHooks.source.map.check_dir(s_dir, t_dir); } if (HPMHooks.count.HP_map_check_dir_post > 0) { - int (*postHookFunc) (int retVal___, int s_dir, int t_dir); + int (*postHookFunc) (int retVal___, enum unit_dir s_dir, enum unit_dir t_dir); for (hIndex = 0; hIndex < HPMHooks.count.HP_map_check_dir_post; hIndex++) { postHookFunc = HPMHooks.list.HP_map_check_dir_post[hIndex].func; retVal___ = postHookFunc(retVal___, s_dir, t_dir); @@ -48311,11 +48311,12 @@ int HP_map_check_dir(int s_dir, int t_dir) { } return retVal___; } -uint8 HP_map_calc_dir(struct block_list *src, int16 x, int16 y) { +enum unit_dir HP_map_calc_dir(struct block_list *src, int16 x, int16 y) { +/* Unknown return type 'enum unit_dir'. Initializing to '0'. */ int hIndex = 0; - uint8 retVal___ = 0; + enum unit_dir retVal___ = 0; if (HPMHooks.count.HP_map_calc_dir_pre > 0) { - uint8 (*preHookFunc) (struct block_list **src, int16 *x, int16 *y); + enum unit_dir (*preHookFunc) (struct block_list **src, int16 *x, int16 *y); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_map_calc_dir_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_map_calc_dir_pre[hIndex].func; @@ -48330,7 +48331,7 @@ uint8 HP_map_calc_dir(struct block_list *src, int16 x, int16 y) { retVal___ = HPMHooks.source.map.calc_dir(src, x, y); } if (HPMHooks.count.HP_map_calc_dir_post > 0) { - uint8 (*postHookFunc) (uint8 retVal___, struct block_list *src, int16 x, int16 y); + enum unit_dir (*postHookFunc) (enum unit_dir retVal___, struct block_list *src, int16 x, int16 y); for (hIndex = 0; hIndex < HPMHooks.count.HP_map_calc_dir_post; hIndex++) { postHookFunc = HPMHooks.list.HP_map_calc_dir_post[hIndex].func; retVal___ = postHookFunc(retVal___, src, x, y); @@ -57108,11 +57109,11 @@ bool HP_npc_viewisid(const char *viewid) { } return retVal___; } -struct npc_data* HP_npc_create_npc(enum npc_subtype subtype, int m, int x, int y, uint8 dir, int class_) { +struct npc_data* HP_npc_create_npc(enum npc_subtype subtype, int m, int x, int y, enum unit_dir dir, int class_) { int hIndex = 0; struct npc_data* retVal___ = NULL; if (HPMHooks.count.HP_npc_create_npc_pre > 0) { - struct npc_data* (*preHookFunc) (enum npc_subtype *subtype, int *m, int *x, int *y, uint8 *dir, int *class_); + struct npc_data* (*preHookFunc) (enum npc_subtype *subtype, int *m, int *x, int *y, enum unit_dir *dir, int *class_); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_npc_create_npc_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_npc_create_npc_pre[hIndex].func; @@ -57127,7 +57128,7 @@ struct npc_data* HP_npc_create_npc(enum npc_subtype subtype, int m, int x, int y retVal___ = HPMHooks.source.npc.create_npc(subtype, m, x, y, dir, class_); } if (HPMHooks.count.HP_npc_create_npc_post > 0) { - struct npc_data* (*postHookFunc) (struct npc_data* retVal___, enum npc_subtype subtype, int m, int x, int y, uint8 dir, int class_); + struct npc_data* (*postHookFunc) (struct npc_data* retVal___, enum npc_subtype subtype, int m, int x, int y, enum unit_dir dir, int class_); for (hIndex = 0; hIndex < HPMHooks.count.HP_npc_create_npc_post; hIndex++) { postHookFunc = HPMHooks.list.HP_npc_create_npc_post[hIndex].func; retVal___ = postHookFunc(retVal___, subtype, m, x, y, dir, class_); @@ -77704,11 +77705,11 @@ int HP_skill_counter_additional_effect(struct block_list *src, struct block_list } return retVal___; } -int HP_skill_blown(struct block_list *src, struct block_list *target, int count, int8 dir, int flag) { +int HP_skill_blown(struct block_list *src, struct block_list *target, int count, enum unit_dir dir, int flag) { int hIndex = 0; int retVal___ = 0; if (HPMHooks.count.HP_skill_blown_pre > 0) { - int (*preHookFunc) (struct block_list **src, struct block_list **target, int *count, int8 *dir, int *flag); + int (*preHookFunc) (struct block_list **src, struct block_list **target, int *count, enum unit_dir *dir, int *flag); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_blown_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_skill_blown_pre[hIndex].func; @@ -77723,7 +77724,7 @@ int HP_skill_blown(struct block_list *src, struct block_list *target, int count, retVal___ = HPMHooks.source.skill.blown(src, target, count, dir, flag); } if (HPMHooks.count.HP_skill_blown_post > 0) { - int (*postHookFunc) (int retVal___, struct block_list *src, struct block_list *target, int count, int8 dir, int flag); + int (*postHookFunc) (int retVal___, struct block_list *src, struct block_list *target, int count, enum unit_dir dir, int flag); for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_blown_post; hIndex++) { postHookFunc = HPMHooks.list.HP_skill_blown_post[hIndex].func; retVal___ = postHookFunc(retVal___, src, target, count, dir, flag); @@ -80034,10 +80035,10 @@ int HP_skill_check_condition_mob_master_sub(struct block_list *bl, va_list ap) { } return retVal___; } -void HP_skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int16 y) { +void HP_skill_brandishspear_first(struct square *tc, enum unit_dir dir, int16 x, int16 y) { int hIndex = 0; if (HPMHooks.count.HP_skill_brandishspear_first_pre > 0) { - void (*preHookFunc) (struct square **tc, uint8 *dir, int16 *x, int16 *y); + void (*preHookFunc) (struct square **tc, enum unit_dir *dir, int16 *x, int16 *y); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_brandishspear_first_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_skill_brandishspear_first_pre[hIndex].func; @@ -80052,7 +80053,7 @@ void HP_skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int16 y HPMHooks.source.skill.brandishspear_first(tc, dir, x, y); } if (HPMHooks.count.HP_skill_brandishspear_first_post > 0) { - void (*postHookFunc) (struct square *tc, uint8 dir, int16 x, int16 y); + void (*postHookFunc) (struct square *tc, enum unit_dir dir, int16 x, int16 y); for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_brandishspear_first_post; hIndex++) { postHookFunc = HPMHooks.list.HP_skill_brandishspear_first_post[hIndex].func; postHookFunc(tc, dir, x, y); @@ -80060,10 +80061,10 @@ void HP_skill_brandishspear_first(struct square *tc, uint8 dir, int16 x, int16 y } return; } -void HP_skill_brandishspear_dir(struct square *tc, uint8 dir, int are) { +void HP_skill_brandishspear_dir(struct square *tc, enum unit_dir dir, int are) { int hIndex = 0; if (HPMHooks.count.HP_skill_brandishspear_dir_pre > 0) { - void (*preHookFunc) (struct square **tc, uint8 *dir, int *are); + void (*preHookFunc) (struct square **tc, enum unit_dir *dir, int *are); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_brandishspear_dir_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_skill_brandishspear_dir_pre[hIndex].func; @@ -80078,7 +80079,7 @@ void HP_skill_brandishspear_dir(struct square *tc, uint8 dir, int are) { HPMHooks.source.skill.brandishspear_dir(tc, dir, are); } if (HPMHooks.count.HP_skill_brandishspear_dir_post > 0) { - void (*postHookFunc) (struct square *tc, uint8 dir, int are); + void (*postHookFunc) (struct square *tc, enum unit_dir dir, int are); for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_brandishspear_dir_post; hIndex++) { postHookFunc = HPMHooks.list.HP_skill_brandishspear_dir_post[hIndex].func; postHookFunc(tc, dir, are); @@ -81968,37 +81969,10 @@ int HP_skill_attack_copy_unknown(int *attack_type, struct block_list *src, struc } return retVal___; } -int HP_skill_attack_dir_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag) { - int hIndex = 0; - int retVal___ = 0; - if (HPMHooks.count.HP_skill_attack_dir_unknown_pre > 0) { - int (*preHookFunc) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag); - *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_attack_dir_unknown_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_skill_attack_dir_unknown_pre[hIndex].func; - retVal___ = preHookFunc(&attack_type, &src, &dsrc, &bl, &skill_id, &skill_lv, &tick, &flag); - } - if (*HPMforce_return) { - *HPMforce_return = false; - return retVal___; - } - } - { - retVal___ = HPMHooks.source.skill.attack_dir_unknown(attack_type, src, dsrc, bl, skill_id, skill_lv, tick, flag); - } - if (HPMHooks.count.HP_skill_attack_dir_unknown_post > 0) { - int (*postHookFunc) (int retVal___, int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); - for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_attack_dir_unknown_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_skill_attack_dir_unknown_post[hIndex].func; - retVal___ = postHookFunc(retVal___, attack_type, src, dsrc, bl, skill_id, skill_lv, tick, flag); - } - } - return retVal___; -} -void HP_skill_attack_blow_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, int8 *dir) { +void HP_skill_attack_blow_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, enum unit_dir *dir) { int hIndex = 0; if (HPMHooks.count.HP_skill_attack_blow_unknown_pre > 0) { - void (*preHookFunc) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag, int **type, struct Damage **dmg, int64 **damage, int8 **dir); + void (*preHookFunc) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag, int **type, struct Damage **dmg, int64 **damage, enum unit_dir **dir); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_attack_blow_unknown_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_skill_attack_blow_unknown_pre[hIndex].func; @@ -82013,7 +81987,7 @@ void HP_skill_attack_blow_unknown(int *attack_type, struct block_list *src, stru HPMHooks.source.skill.attack_blow_unknown(attack_type, src, dsrc, bl, skill_id, skill_lv, tick, flag, type, dmg, damage, dir); } if (HPMHooks.count.HP_skill_attack_blow_unknown_post > 0) { - void (*postHookFunc) (int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, int8 *dir); + void (*postHookFunc) (int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, enum unit_dir *dir); for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_attack_blow_unknown_post; hIndex++) { postHookFunc = HPMHooks.list.HP_skill_attack_blow_unknown_post[hIndex].func; postHookFunc(attack_type, src, dsrc, bl, skill_id, skill_lv, tick, flag, type, dmg, damage, dir); @@ -91155,11 +91129,11 @@ int HP_unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, b } return retVal___; } -int HP_unit_setdir(struct block_list *bl, unsigned char dir) { +int HP_unit_setdir(struct block_list *bl, enum unit_dir dir) { int hIndex = 0; int retVal___ = 0; if (HPMHooks.count.HP_unit_setdir_pre > 0) { - int (*preHookFunc) (struct block_list **bl, unsigned char *dir); + int (*preHookFunc) (struct block_list **bl, enum unit_dir *dir); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_setdir_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_unit_setdir_pre[hIndex].func; @@ -91174,7 +91148,7 @@ int HP_unit_setdir(struct block_list *bl, unsigned char dir) { retVal___ = HPMHooks.source.unit.setdir(bl, dir); } if (HPMHooks.count.HP_unit_setdir_post > 0) { - int (*postHookFunc) (int retVal___, struct block_list *bl, unsigned char dir); + int (*postHookFunc) (int retVal___, struct block_list *bl, enum unit_dir dir); for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_setdir_post; hIndex++) { postHookFunc = HPMHooks.list.HP_unit_setdir_post[hIndex].func; retVal___ = postHookFunc(retVal___, bl, dir); @@ -91182,11 +91156,12 @@ int HP_unit_setdir(struct block_list *bl, unsigned char dir) { } return retVal___; } -uint8 HP_unit_getdir(struct block_list *bl) { +enum unit_dir HP_unit_getdir(struct block_list *bl) { +/* Unknown return type 'enum unit_dir'. Initializing to '0'. */ int hIndex = 0; - uint8 retVal___ = 0; + enum unit_dir retVal___ = 0; if (HPMHooks.count.HP_unit_getdir_pre > 0) { - uint8 (*preHookFunc) (struct block_list **bl); + enum unit_dir (*preHookFunc) (struct block_list **bl); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_getdir_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_unit_getdir_pre[hIndex].func; @@ -91201,7 +91176,7 @@ uint8 HP_unit_getdir(struct block_list *bl) { retVal___ = HPMHooks.source.unit.getdir(bl); } if (HPMHooks.count.HP_unit_getdir_post > 0) { - uint8 (*postHookFunc) (uint8 retVal___, struct block_list *bl); + enum unit_dir (*postHookFunc) (enum unit_dir retVal___, struct block_list *bl); for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_getdir_post; hIndex++) { postHookFunc = HPMHooks.list.HP_unit_getdir_post[hIndex].func; retVal___ = postHookFunc(retVal___, bl); @@ -91263,6 +91238,33 @@ int HP_unit_warp(struct block_list *bl, short m, short x, short y, enum clr_type } return retVal___; } +int HP_unit_warpto_master(struct block_list *master_bl, struct block_list *slave_bl) { + int hIndex = 0; + int retVal___ = 0; + if (HPMHooks.count.HP_unit_warpto_master_pre > 0) { + int (*preHookFunc) (struct block_list **master_bl, struct block_list **slave_bl); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_warpto_master_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_unit_warpto_master_pre[hIndex].func; + retVal___ = preHookFunc(&master_bl, &slave_bl); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.unit.warpto_master(master_bl, slave_bl); + } + if (HPMHooks.count.HP_unit_warpto_master_post > 0) { + int (*postHookFunc) (int retVal___, struct block_list *master_bl, struct block_list *slave_bl); + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_warpto_master_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_unit_warpto_master_post[hIndex].func; + retVal___ = postHookFunc(retVal___, master_bl, slave_bl); + } + } + return retVal___; +} int HP_unit_stop_walking(struct block_list *bl, int type) { int hIndex = 0; int retVal___ = 0; @@ -91747,11 +91749,11 @@ bool HP_unit_can_reach_bl(struct block_list *bl, struct block_list *tbl, int ran } return retVal___; } -int HP_unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir) { +int HP_unit_calc_pos(struct block_list *bl, int tx, int ty, enum unit_dir dir) { int hIndex = 0; int retVal___ = 0; if (HPMHooks.count.HP_unit_calc_pos_pre > 0) { - int (*preHookFunc) (struct block_list **bl, int *tx, int *ty, uint8 *dir); + int (*preHookFunc) (struct block_list **bl, int *tx, int *ty, enum unit_dir *dir); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_calc_pos_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_unit_calc_pos_pre[hIndex].func; @@ -91766,7 +91768,7 @@ int HP_unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir) { retVal___ = HPMHooks.source.unit.calc_pos(bl, tx, ty, dir); } if (HPMHooks.count.HP_unit_calc_pos_post > 0) { - int (*postHookFunc) (int retVal___, struct block_list *bl, int tx, int ty, uint8 dir); + int (*postHookFunc) (int retVal___, struct block_list *bl, int tx, int ty, enum unit_dir dir); for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_calc_pos_post; hIndex++) { postHookFunc = HPMHooks.list.HP_unit_calc_pos_post[hIndex].func; retVal___ = postHookFunc(retVal___, bl, tx, ty, dir); -- cgit v1.2.3-70-g09d2 From 0074b7b2b3e667942fb593428408d8432558fdc2 Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 8 Sep 2019 20:36:43 +0200 Subject: HPM Hooks Update --- src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 1623cadb6..2aab594c1 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -48312,9 +48312,8 @@ int HP_map_check_dir(enum unit_dir s_dir, enum unit_dir t_dir) { return retVal___; } enum unit_dir HP_map_calc_dir(struct block_list *src, int16 x, int16 y) { -/* Unknown return type 'enum unit_dir'. Initializing to '0'. */ int hIndex = 0; - enum unit_dir retVal___ = 0; + enum unit_dir retVal___ = UNIT_DIR_UNDEFINED; if (HPMHooks.count.HP_map_calc_dir_pre > 0) { enum unit_dir (*preHookFunc) (struct block_list **src, int16 *x, int16 *y); *HPMforce_return = false; @@ -91157,9 +91156,8 @@ int HP_unit_setdir(struct block_list *bl, enum unit_dir dir) { return retVal___; } enum unit_dir HP_unit_getdir(struct block_list *bl) { -/* Unknown return type 'enum unit_dir'. Initializing to '0'. */ int hIndex = 0; - enum unit_dir retVal___ = 0; + enum unit_dir retVal___ = UNIT_DIR_UNDEFINED; if (HPMHooks.count.HP_unit_getdir_pre > 0) { enum unit_dir (*preHookFunc) (struct block_list **bl); *HPMforce_return = false; -- cgit v1.2.3-70-g09d2 From bf40cd64e6bee575ee03eddee8efb033c8b084b5 Mon Sep 17 00:00:00 2001 From: skyleo Date: Tue, 10 Sep 2019 21:55:48 +0200 Subject: Remove refactor-continue comment --- src/map/unit.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 19ad5423d..d70f76113 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -494,7 +494,6 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) return 0; } -//TODO: CONTINUE REFACTORING HERE static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); -- cgit v1.2.3-70-g09d2 From d663f0c9df2c66211718d84ca5f62a8a387445fb Mon Sep 17 00:00:00 2001 From: skyleo Date: Tue, 10 Sep 2019 22:00:14 +0200 Subject: Apply code-style to nullpointer-checks in unit->delay_walktoxy_timer --- src/map/unit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index d70f76113..790f6b802 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -497,8 +497,7 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); - - if (!bl || bl->prev == NULL) + if (bl == NULL || bl->prev == NULL) return 0; unit->walktoxy(bl, (short)((data>>16)&0xffff), (short)(data&0xffff), 0); return 1; -- cgit v1.2.3-70-g09d2 From 6295bf32b22f6a6193b5434ff001a9993211c8ed Mon Sep 17 00:00:00 2001 From: skyleo Date: Tue, 10 Sep 2019 22:42:12 +0200 Subject: Move bitwise-operations into named variables in unit->delay_walktoxy_timer --- src/map/unit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 790f6b802..d37998e9a 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -499,7 +499,9 @@ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) struct block_list *bl = map->id2bl(id); if (bl == NULL || bl->prev == NULL) return 0; - unit->walktoxy(bl, (short)((data>>16)&0xffff), (short)(data&0xffff), 0); + short x = (short) ((data >> 16) & 0xffff); + short y = (short) (data & 0xffff); + unit->walktoxy(bl, x, y, 0); return 1; } -- cgit v1.2.3-70-g09d2 From 3d34c37c8affc7ca5711245dadaaf3f3cecbba41 Mon Sep 17 00:00:00 2001 From: skyleo Date: Tue, 10 Sep 2019 22:44:37 +0200 Subject: Change returning error-code in unit->delay_walktoxy_timer to obey code-style guidelines --- src/map/unit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index d37998e9a..75bed7eca 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -498,11 +498,11 @@ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); if (bl == NULL || bl->prev == NULL) - return 0; + return 1; short x = (short) ((data >> 16) & 0xffff); short y = (short) (data & 0xffff); unit->walktoxy(bl, x, y, 0); - return 1; + return 0; } //flag parameter: -- cgit v1.2.3-70-g09d2 From 02f661dc3b112efb9d4e61d3b15f9f0fa840e9ee Mon Sep 17 00:00:00 2001 From: skyleo Date: Tue, 10 Sep 2019 22:50:48 +0200 Subject: Add documentation for unit->delay_walktoxy_timer --- src/map/unit.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 75bed7eca..8eb490c34 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -494,6 +494,14 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) return 0; } +/** + * Timer for delayed execution of unit->walktoxy once triggered + * @param tid: Timer ID, unused + * @param tick: Tick, unused + * @param id: ID of block_list to execute the action + * @param data: intptr_t filled with x-coord in highest 16 bits and y-coord in lowest 16 bits + * @return 0: success, 1: failure + */ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); -- cgit v1.2.3-70-g09d2 From 769f5801f3499f525071cd0363ca9e66ef46f2cf Mon Sep 17 00:00:00 2001 From: skyleo Date: Wed, 11 Sep 2019 02:21:31 +0200 Subject: Use *DWord functions for saving x & y into data of unit->delay_walktoxy_timer --- src/map/unit.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 8eb490c34..f5784b405 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -57,6 +57,7 @@ #include "common/showmsg.h" #include "common/socket.h" #include "common/timer.h" +#include "common/utils.h" #include #include @@ -499,7 +500,7 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) * @param tid: Timer ID, unused * @param tick: Tick, unused * @param id: ID of block_list to execute the action - * @param data: intptr_t filled with x-coord in highest 16 bits and y-coord in lowest 16 bits + * @param data: uint32 data cast to intptr_t with x-coord in lowest 16 bits and y-coord in highest 16 bits * @return 0: success, 1: failure */ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) @@ -507,8 +508,8 @@ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) struct block_list *bl = map->id2bl(id); if (bl == NULL || bl->prev == NULL) return 1; - short x = (short) ((data >> 16) & 0xffff); - short y = (short) (data & 0xffff); + short x = (short)GetWord((uint32)data, 0); + short y = (short)GetWord((uint32)data, 1); unit->walktoxy(bl, x, y, 0); return 0; } @@ -548,7 +549,7 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) if (flag&4 && DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) < 2000) { // Delay walking command. [Skotlex] - timer->add(ud->canmove_tick+1, unit->delay_walktoxy_timer, bl->id, (x<<16)|(y&0xFFFF)); + timer->add(ud->canmove_tick + 1, unit->delay_walktoxy_timer, bl->id, (intptr_t)MakeDWord((uint16)x, (uint16)y)); return 1; } -- cgit v1.2.3-70-g09d2 From 40e0422b8754dc5b0f57b2dd5c5892798a598c22 Mon Sep 17 00:00:00 2001 From: skyleo Date: Wed, 11 Sep 2019 21:55:37 +0200 Subject: Cleanup nullpointer checks in unit->walktoxy --- src/map/unit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index f5784b405..61a85d431 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -529,7 +529,8 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) ud = unit->bl2ud(bl); - if( ud == NULL) return 0; + if (ud == NULL) + return 0; if (battle_config.check_occupied_cells && (flag&8) && !map->closest_freecell(bl->m, bl, &x, &y, BL_CHAR|BL_NPC, 1)) //This might change x and y return 0; @@ -564,7 +565,7 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) unit->stop_stepaction(bl); // unit->walktoxy removes any remembered stepaction and resets ud->target_to sc = status->get_sc(bl); - if( sc ) { + if (sc != NULL) { if( sc->data[SC_CONFUSION] || sc->data[SC__CHAOS] ) //Randomize the target position map->random_dir(bl, &ud->to_x, &ud->to_y); if( sc->data[SC_COMBOATTACK] ) -- cgit v1.2.3-70-g09d2 From 43bc7911460a53a2ebed4b54d81c473b9e6567b8 Mon Sep 17 00:00:00 2001 From: skyleo Date: Wed, 11 Sep 2019 22:19:28 +0200 Subject: Correct checks mistreating non-boolean values in unit->walktoxy --- src/map/unit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 61a85d431..9526a1f79 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -532,7 +532,7 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) if (ud == NULL) return 0; - if (battle_config.check_occupied_cells && (flag&8) && !map->closest_freecell(bl->m, bl, &x, &y, BL_CHAR|BL_NPC, 1)) //This might change x and y + if (battle_config.check_occupied_cells != 0 && (flag & 8) != 0 && !map->closest_freecell(bl->m, bl, &x, &y, BL_CHAR | BL_NPC, 1)) // This might change x and y return 0; if (!path->search(&wpd, bl, bl->m, bl->x, bl->y, x, y, flag&1, CELL_CHKNOPASS)) // Count walk path cells @@ -547,14 +547,14 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) if ((wpd.path_len > battle_config.max_walk_path) && (bl->type != BL_NPC)) return 0; - if (flag&4 && DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0 && + if ((flag & 4) != 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) < 2000) { // Delay walking command. [Skotlex] timer->add(ud->canmove_tick + 1, unit->delay_walktoxy_timer, bl->id, (intptr_t)MakeDWord((uint16)x, (uint16)y)); return 1; } - if(!(flag&2) && (!(status_get_mode(bl)&MD_CANMOVE) || !unit->can_move(bl))) + if ((flag & 2) == 0 && ((status_get_mode(bl) & MD_CANMOVE) == 0 || unit->can_move(bl) == 0)) return 0; ud->state.walk_easy = flag&1; @@ -566,9 +566,9 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) sc = status->get_sc(bl); if (sc != NULL) { - if( sc->data[SC_CONFUSION] || sc->data[SC__CHAOS] ) //Randomize the target position + if (sc->data[SC_CONFUSION] != NULL || sc->data[SC__CHAOS] != NULL) //Randomize the target position map->random_dir(bl, &ud->to_x, &ud->to_y); - if( sc->data[SC_COMBOATTACK] ) + if (sc->data[SC_COMBOATTACK] != NULL) status_change_end(bl, SC_COMBOATTACK, INVALID_TIMER); } -- cgit v1.2.3-70-g09d2 From 0817191184bd867836a7fcc30d65305b10964a5f Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 12 Sep 2019 00:33:54 +0200 Subject: Change returning error-code in unit->walktoxy to obey code-style guidelines --- src/map/elemental.c | 4 ++-- src/map/mob.c | 6 +++--- src/map/pet.c | 5 +++-- src/map/script.c | 17 ++++++++++------- src/map/skill.c | 2 +- src/map/unit.c | 28 ++++++++++++++++------------ 6 files changed, 35 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/map/elemental.c b/src/map/elemental.c index 1c1d98634..e9b6fa372 100644 --- a/src/map/elemental.c +++ b/src/map/elemental.c @@ -788,8 +788,8 @@ static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_ return 0; //Already walking to him if( DIFF_TICK(tick, ed->ud.canmove_tick) < 0 ) return 0; //Can't move yet. - if( map->search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1) - && unit->walktoxy(&ed->bl, x, y, 0) ) + if (map->search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1) != 0 + && unit->walktoxy(&ed->bl, x, y, 0) == 0) return 0; } diff --git a/src/map/mob.c b/src/map/mob.c index 0830e5a5a..431bdbe0d 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1462,7 +1462,7 @@ static int mob_ai_sub_hard_slavemob(struct mob_data *md, int64 tick) // If master is BL_MOB and in battle, lock & chase to master's target instead, unless configured not to. if ((battle_config.slave_chase_masters_chasetarget == 0 || (m_md != NULL && !mob->is_in_battle_state(m_md))) && map->search_freecell(&md->bl, bl->m, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 1) - && unit->walktoxy(&md->bl, x, y, 0)) + && unit->walktoxy(&md->bl, x, y, 0) == 0) return 1; } } else if (bl->m != md->bl.m && map_flag_gvg(md->bl.m)) { @@ -1576,9 +1576,9 @@ static int mob_randomwalk(struct mob_data *md, int64 tick) x+=md->bl.x; y+=md->bl.y; - if (((x != md->bl.x) || (y != md->bl.y)) && map->getcell(md->bl.m, &md->bl, x, y, CELL_CHKPASS) && unit->walktoxy(&md->bl, x, y, 8)) { + if ((x != md->bl.x || y != md->bl.y) && map->getcell(md->bl.m, &md->bl, x, y, CELL_CHKPASS) != 0 + && unit->walktoxy(&md->bl, x, y, 8) == 0) break; - } } if(i==retrycount){ md->move_fail_count++; diff --git a/src/map/pet.c b/src/map/pet.c index f20de2650..0537baaa7 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -891,7 +891,8 @@ static int pet_randomwalk(struct pet_data *pd, int64 tick) int r=rnd(); int x=pd->bl.x+r%(d*2+1)-d; int y=pd->bl.y+r/(d*2+1)%(d*2+1)-d; - if(map->getcell (pd->bl.m, &pd->bl, x, y, CELL_CHKPASS) && unit->walktoxy(&pd->bl, x, y, 0)) { + if (map->getcell(pd->bl.m, &pd->bl, x, y, CELL_CHKPASS) != 0 + && unit->walktoxy(&pd->bl, x, y, 0) == 0) { pd->move_fail_count=0; break; } @@ -991,7 +992,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, int return 0; //Already walking to him unit->calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir); - if(!unit->walktoxy(&pd->bl,pd->ud.to_x,pd->ud.to_y,0)) + if (unit->walktoxy(&pd->bl, pd->ud.to_x, pd->ud.to_y, 0) != 0) pet->randomwalk(pd,tick); return 0; diff --git a/src/map/script.c b/src/map/script.c index 28d06a8f1..d6462384d 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -19680,7 +19680,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (!unit->walktoxy(bl, (short) val, (short) val2, 2)) + if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -19851,7 +19851,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (!unit->walktoxy(bl, (short) val, (short) val2, 2)) + if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -19990,7 +19990,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (!unit->walktoxy(bl, (short) val, (short) val2, 2)) + if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -20123,7 +20123,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (!unit->walktoxy(bl, (short) val, (short) val2, 2)) + if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -20257,7 +20257,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (!unit->walktoxy(bl, (short) val, (short) val2, 2)) + if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -20386,7 +20386,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (!unit->walktoxy(bl, (short) val, (short) val2, 2)) + if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_CLASS: @@ -21121,7 +21121,10 @@ static BUILDIN(unitwalk) if (script_hasdata(st, 4)) { int x = script_getnum(st, 3); int y = script_getnum(st, 4); - script_pushint(st, unit->walktoxy(bl, x, y, 0));// We'll use harder calculations. + if (unit->walktoxy(bl, x, y, 0) == 0) // We'll use harder calculations. + script_pushint(st, 1); + else + script_pushint(st, 0); } else { int target_id = script_getnum(st, 3); diff --git a/src/map/skill.c b/src/map/skill.c index 668c1849c..693cbfe2c 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -8080,7 +8080,7 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list * unit->stop_attack(src); //Run skillv tiles overriding the can-move check. if (unit->walktoxy(src, (src->x + skill_lv * -dirx[dir]), - (src->y + skill_lv * -diry[dir]), 2) != 0 && md != NULL) + (src->y + skill_lv * -diry[dir]), 2) == 0 && md != NULL) md->state.skillstate = MSS_WALK; //Otherwise it isn't updated in the AI. } break; diff --git a/src/map/unit.c b/src/map/unit.c index 9526a1f79..ba0dec9dc 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -519,43 +519,44 @@ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) //&2 -> force walking //&4 -> Delay walking if the reason you can't walk is the canwalk delay //&8 -> Search for an unoccupied cell and cancel if none available +//@return 0: success, 1: failure static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) { struct unit_data* ud = NULL; struct status_change* sc = NULL; struct walkpath_data wpd; - nullpo_ret(bl); + nullpo_retr(1, bl); ud = unit->bl2ud(bl); if (ud == NULL) - return 0; + return 1; if (battle_config.check_occupied_cells != 0 && (flag & 8) != 0 && !map->closest_freecell(bl->m, bl, &x, &y, BL_CHAR | BL_NPC, 1)) // This might change x and y - return 0; + return 1; if (!path->search(&wpd, bl, bl->m, bl->x, bl->y, x, y, flag&1, CELL_CHKNOPASS)) // Count walk path cells - return 0; + return 1; #ifdef OFFICIAL_WALKPATH if( !path->search_long(NULL, bl, bl->m, bl->x, bl->y, x, y, CELL_CHKNOPASS) // Check if there is an obstacle between && (wpd.path_len > (battle_config.max_walk_path/17)*14) // Official number of walkable cells is 14 if and only if there is an obstacle between. [malufett] && (bl->type != BL_NPC) ) // If type is a NPC, please disregard. - return 0; + return 1; #endif if ((wpd.path_len > battle_config.max_walk_path) && (bl->type != BL_NPC)) - return 0; + return 1; if ((flag & 4) != 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) < 2000) { // Delay walking command. [Skotlex] timer->add(ud->canmove_tick + 1, unit->delay_walktoxy_timer, bl->id, (intptr_t)MakeDWord((uint16)x, (uint16)y)); - return 1; + return 0; } if ((flag & 2) == 0 && ((status_get_mode(bl) & MD_CANMOVE) == 0 || unit->can_move(bl) == 0)) - return 0; + return 1; ud->state.walk_easy = flag&1; ud->to_x = x; @@ -576,7 +577,7 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) // When you come to the center of the grid because the change of destination while you're walking right now // Call a function from a timer unit->walktoxy_sub ud->state.change_walk_target = 1; - return 1; + return 0; } return unit->walktoxy_sub(bl); @@ -749,14 +750,14 @@ static bool unit_run(struct block_list *bl, struct map_session_data *sd, enum sc return false; } - if( unit->walktoxy(bl, to_x, to_y, 1) ) + if (unit->walktoxy(bl, to_x, to_y, 1) == 0) return true; //There must be an obstacle nearby. Attempt walking one cell at a time. do { to_x -= dir_x; to_y -= dir_y; - } while (--i > 0 && !unit->walktoxy(bl, to_x, to_y, 1)); + } while (--i > 0 && unit->walktoxy(bl, to_x, to_y, 1) != 0); if ( i == 0 ) { unit->run_hit(bl, sc, sd, type); @@ -774,7 +775,10 @@ static int unit_escape(struct block_list *bl, struct block_list *target, short d Assert_retr(1, dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); while (dist > 0 && map->getcell(bl->m, bl, bl->x + dist * dirx[dir], bl->y + dist * diry[dir], CELL_CHKNOREACH)) dist--; - return ( dist > 0 && unit->walktoxy(bl, bl->x + dist*dirx[dir], bl->y + dist*diry[dir], 0) ); + if (dist > 0 && unit->walktoxy(bl, bl->x + dist * dirx[dir], bl->y + dist * diry[dir], 0) == 0) + return 1; + else + return 0; } //Instant warp function. -- cgit v1.2.3-70-g09d2 From f6986831b06044def3e389283d382d54f4d41e7c Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 12 Sep 2019 00:37:07 +0200 Subject: Remove "already refactored" comment --- src/map/unit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index ba0dec9dc..d1d73ff30 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -660,7 +660,7 @@ static int unit_walktobl(struct block_list *bl, struct block_list *tbl, int rang if(!unit->can_move(bl)) return 0; - if (unit->walktoxy_sub(bl) == 0) { //ALREADY REFACTORED + if (unit->walktoxy_sub(bl) == 0) { set_mobstate(bl, flag&2); return 0; } -- cgit v1.2.3-70-g09d2 From 33eb8cd6bf37336da5a7305531aa010e1b9ace30 Mon Sep 17 00:00:00 2001 From: skyleo Date: Wed, 2 Oct 2019 22:37:43 +0200 Subject: Update Coding Style of unit->walktoxy --- src/map/unit.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index d1d73ff30..c67a7e919 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -533,32 +533,38 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) if (ud == NULL) return 1; - if (battle_config.check_occupied_cells != 0 && (flag & 8) != 0 && !map->closest_freecell(bl->m, bl, &x, &y, BL_CHAR | BL_NPC, 1)) // This might change x and y - return 1; + if ((flag & 8) != 0 && battle_config.check_occupied_cells != 0) { + if (!map->closest_freecell(bl->m, bl, &x, &y, BL_CHAR | BL_NPC, 1)) // This might change x and y + return 1; + } - if (!path->search(&wpd, bl, bl->m, bl->x, bl->y, x, y, flag&1, CELL_CHKNOPASS)) // Count walk path cells + if (!path->search(&wpd, bl, bl->m, bl->x, bl->y, x, y, flag & 1, CELL_CHKNOPASS)) // Count walk path cells return 1; + if (bl->type != BL_NPC) { #ifdef OFFICIAL_WALKPATH - if( !path->search_long(NULL, bl, bl->m, bl->x, bl->y, x, y, CELL_CHKNOPASS) // Check if there is an obstacle between - && (wpd.path_len > (battle_config.max_walk_path/17)*14) // Official number of walkable cells is 14 if and only if there is an obstacle between. [malufett] - && (bl->type != BL_NPC) ) // If type is a NPC, please disregard. - return 1; + // Check if there is an obstacle between + // Official number of walkable cells is 14 if and only if there is an obstacle between. [malufett] + if (!path->search_long(NULL, bl, bl->m, bl->x, bl->y, x, y, CELL_CHKNOPASS) + && (wpd.path_len > (battle_config.max_walk_path / 17) * 14)) + return 1; #endif - if ((wpd.path_len > battle_config.max_walk_path) && (bl->type != BL_NPC)) - return 1; + if (wpd.path_len > battle_config.max_walk_path) + return 1; + } - if ((flag & 4) != 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0 && - DIFF_TICK(ud->canmove_tick, timer->gettick()) < 2000) { + if ((flag & 4) != 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0 + && DIFF_TICK(ud->canmove_tick, timer->gettick()) < 2000) { // Delay walking command. [Skotlex] - timer->add(ud->canmove_tick + 1, unit->delay_walktoxy_timer, bl->id, (intptr_t)MakeDWord((uint16)x, (uint16)y)); + timer->add(ud->canmove_tick + 1, unit->delay_walktoxy_timer, bl->id, + (intptr_t)MakeDWord((uint16)x, (uint16)y)); return 0; } if ((flag & 2) == 0 && ((status_get_mode(bl) & MD_CANMOVE) == 0 || unit->can_move(bl) == 0)) return 1; - ud->state.walk_easy = flag&1; + ud->state.walk_easy = flag & 1; ud->to_x = x; ud->to_y = y; unit->stop_attack(bl); //Sets target to 0 @@ -567,13 +573,13 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) sc = status->get_sc(bl); if (sc != NULL) { - if (sc->data[SC_CONFUSION] != NULL || sc->data[SC__CHAOS] != NULL) //Randomize the target position + if (sc->data[SC_CONFUSION] != NULL || sc->data[SC__CHAOS] != NULL) // Randomize the target position map->random_dir(bl, &ud->to_x, &ud->to_y); if (sc->data[SC_COMBOATTACK] != NULL) status_change_end(bl, SC_COMBOATTACK, INVALID_TIMER); } - if(ud->walktimer != INVALID_TIMER) { + if (ud->walktimer != INVALID_TIMER) { // When you come to the center of the grid because the change of destination while you're walking right now // Call a function from a timer unit->walktoxy_sub ud->state.change_walk_target = 1; -- cgit v1.2.3-70-g09d2 From 7879d7be752fe7488c8d1653b0ca88e6574b9e4a Mon Sep 17 00:00:00 2001 From: skyleo Date: Wed, 2 Oct 2019 23:58:30 +0200 Subject: Add documentation for unit->walktoxy --- src/map/unit.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index c67a7e919..3a1f2a9f9 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -514,12 +514,19 @@ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) return 0; } -//flag parameter: -//&1 -> 1/0 = easy/hard -//&2 -> force walking -//&4 -> Delay walking if the reason you can't walk is the canwalk delay -//&8 -> Search for an unoccupied cell and cancel if none available -//@return 0: success, 1: failure +/** + * Makes a unit walk to (x, y) coordinates + * @param bl: block_list of unit to move + * @param x: x-coordinate + * @param y: y-coordinate + * @param flag: flag paramater with following options: + * - `& 1` -> 1/0 = easy / hard + * - `& 2` -> Force walking + * - `& 4` -> Delay walking, if the reason you can't walk is the `canwalk delay` + * - `& 8` -> Search for an unoccupied cell and cancel if none available + * . + * @return 0: success, 1: failure + */ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) { struct unit_data* ud = NULL; -- cgit v1.2.3-70-g09d2 From a70f43dc90f634b1e840d3e77895c433bcc91d71 Mon Sep 17 00:00:00 2001 From: skyleo Date: Wed, 2 Oct 2019 23:59:32 +0200 Subject: Add TODO-comment suggesting enum for unit->walktoxy --- src/map/unit.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 3a1f2a9f9..b0d7a6767 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -529,6 +529,7 @@ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) */ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) { + // TODO: change flag to enum? [skyleo] struct unit_data* ud = NULL; struct status_change* sc = NULL; struct walkpath_data wpd; -- cgit v1.2.3-70-g09d2 From 349f811ab9921e5e2d91411f822b9b6c916a60f7 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 00:04:01 +0200 Subject: Add documentation for set_mobstate --- src/map/unit.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index b0d7a6767..37a211ba1 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -597,7 +597,12 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) return unit->walktoxy_sub(bl); } -//To set Mob's CHASE/FOLLOW states (shouldn't be done if there's no path to reach) +/** + * Sets mob's CHASE / FOLLOW states. + * WARNING: This shouldn't be done if there's no path to reach + * @param bl: block_list of mob + * @param flag: if set to 0 this function will set nothing + */ static inline void set_mobstate(struct block_list *bl, int flag) { struct mob_data* md = BL_CAST(BL_MOB,bl); -- cgit v1.2.3-70-g09d2 From 38108320a6ab0a27d9deba967f553b2a6f8b9537 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 00:15:13 +0200 Subject: Update Coding Style for set_mobstate --- src/map/unit.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 37a211ba1..5d3011aba 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -605,10 +605,14 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) */ static inline void set_mobstate(struct block_list *bl, int flag) { - struct mob_data* md = BL_CAST(BL_MOB,bl); + struct mob_data* md = BL_CAST(BL_MOB, bl); - if( md && flag ) - md->state.skillstate = md->state.aggressive ? MSS_FOLLOW : MSS_RUSH; + if (md != NULL && flag != 0) { + if (md->state.aggressive != 0) + md->state.skillstate = MSS_FOLLOW; + else + md->state.skillstate = MSS_RUSH; + } } static int unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data) -- cgit v1.2.3-70-g09d2 From 193956af55b94852917fc236a431ae384bf78d84 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 01:25:04 +0200 Subject: Add nullpo_retr for unit_data in unit->walktobl_sub --- src/map/unit.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 5d3011aba..64a849384 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -618,9 +618,13 @@ static inline void set_mobstate(struct block_list *bl, int flag) static int unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); - struct unit_data *ud = bl?unit->bl2ud(bl):NULL; + if (bl == NULL) + return 1; + struct unit_data *ud = unit->bl2ud(bl); + if (ud == NULL) + return 1; - if (ud && ud->walktimer == INVALID_TIMER && ud->target == data) { + if (ud->walktimer == INVALID_TIMER && ud->target == data) { if (DIFF_TICK(ud->canmove_tick, tick) > 0) //Keep waiting? timer->add(ud->canmove_tick+1, unit->walktobl_sub, id, data); else if (unit->can_move(bl)) { -- cgit v1.2.3-70-g09d2 From 665855f460eb454d028f9f81c6779539bef7e494 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 02:11:48 +0200 Subject: Update Coding Style for unit->walktobl_sub --- src/map/unit.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 64a849384..bff75d6bd 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -625,12 +625,10 @@ static int unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data) return 1; if (ud->walktimer == INVALID_TIMER && ud->target == data) { - if (DIFF_TICK(ud->canmove_tick, tick) > 0) //Keep waiting? - timer->add(ud->canmove_tick+1, unit->walktobl_sub, id, data); - else if (unit->can_move(bl)) { - if (unit->walktoxy_sub(bl) == 0) - set_mobstate(bl, ud->state.attack_continue); - } + if (DIFF_TICK(ud->canmove_tick, tick) > 0) // Keep waiting? + timer->add(ud->canmove_tick + 1, unit->walktobl_sub, id, data); + else if (unit->can_move(bl) != 0 && unit->walktoxy_sub(bl) == 0) + set_mobstate(bl, ud->state.attack_continue); } return 0; } -- cgit v1.2.3-70-g09d2 From 63b3f95389e56437fc630e7f6051f1a419322fee Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 03:16:15 +0200 Subject: Rename unit->walktobl_sub to unit->walktobl_timer --- src/map/unit.c | 12 ++++++------ src/map/unit.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index bff75d6bd..644fd47bb 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -615,7 +615,7 @@ static inline void set_mobstate(struct block_list *bl, int flag) } } -static int unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data) +static int unit_walktobl_timer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); if (bl == NULL) @@ -626,7 +626,7 @@ static int unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data) if (ud->walktimer == INVALID_TIMER && ud->target == data) { if (DIFF_TICK(ud->canmove_tick, tick) > 0) // Keep waiting? - timer->add(ud->canmove_tick + 1, unit->walktobl_sub, id, data); + timer->add(ud->canmove_tick + 1, unit->walktobl_timer, id, data); else if (unit->can_move(bl) != 0 && unit->walktoxy_sub(bl) == 0) set_mobstate(bl, ud->state.attack_continue); } @@ -678,7 +678,7 @@ static int unit_walktobl(struct block_list *bl, struct block_list *tbl, int rang if (DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0) { //Can't move, wait a bit before invoking the movement. - timer->add(ud->canmove_tick+1, unit->walktobl_sub, bl->id, ud->target); + timer->add(ud->canmove_tick + 1, unit->walktobl_timer, bl->id, ud->target); return 1; } @@ -1291,7 +1291,7 @@ static int unit_set_walkdelay(struct block_list *bl, int64 tick, int delay, int } else { unit->stop_walking(bl, STOPWALKING_FLAG_NEXTCELL); if (ud->target) - timer->add(ud->canmove_tick+1, unit->walktobl_sub, bl->id, ud->target); + timer->add(ud->canmove_tick + 1, unit->walktobl_timer, bl->id, ud->target); } } } @@ -3025,7 +3025,7 @@ static int do_init_unit(bool minimal) timer->add_func_list(unit->attack_timer, "unit_attack_timer"); timer->add_func_list(unit->walktoxy_timer,"unit_walktoxy_timer"); - timer->add_func_list(unit->walktobl_sub, "unit_walktobl_sub"); + timer->add_func_list(unit->walktobl_timer, "unit_walktobl_timer"); timer->add_func_list(unit->delay_walktoxy_timer,"unit_delay_walktoxy_timer"); timer->add_func_list(unit->step_timer,"unit_step_timer"); return 0; @@ -3052,7 +3052,7 @@ void unit_defaults(void) unit->walktoxy_sub = unit_walktoxy_sub; unit->delay_walktoxy_timer = unit_delay_walktoxy_timer; unit->walktoxy = unit_walktoxy; - unit->walktobl_sub = unit_walktobl_sub; + unit->walktobl_timer = unit_walktobl_timer; unit->walktobl = unit_walktobl; unit->run = unit_run; unit->run_hit = unit_run_hit; diff --git a/src/map/unit.h b/src/map/unit.h index 7c9dc1095..dd338d076 100644 --- a/src/map/unit.h +++ b/src/map/unit.h @@ -110,7 +110,7 @@ struct unit_interface { int (*walktoxy_sub) (struct block_list *bl); int (*delay_walktoxy_timer) (int tid, int64 tick, int id, intptr_t data); int (*walktoxy) (struct block_list *bl, short x, short y, int flag); - int (*walktobl_sub) (int tid, int64 tick, int id, intptr_t data); + int (*walktobl_timer) (int tid, int64 tick, int id, intptr_t data); int (*walktobl) (struct block_list *bl, struct block_list *tbl, int range, int flag); bool (*run) (struct block_list *bl, struct map_session_data *sd, enum sc_type type); void (*run_hit) (struct block_list *bl, struct status_change *sc, struct map_session_data *sd, enum sc_type type); -- cgit v1.2.3-70-g09d2 From 6b7bfcf7508a7d3778082190a0f709775453649a Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 03:59:08 +0200 Subject: Add documentation for unit->walktobl_timer --- src/map/unit.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 644fd47bb..3c86ff02d 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -615,6 +615,15 @@ static inline void set_mobstate(struct block_list *bl, int flag) } } +/** + * Timer used for when a unit can't walk towards its target yet due to it's canmove_tick, + * keeps retrying until it works or target changes. + * @param tid: Timer ID, unused + * @param tick: Tick, unused + * @param id: ID of block_list to execute the action + * @param data: ID of block_list to walk towards + * @return 0: success, 1: failure + */ static int unit_walktobl_timer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); -- cgit v1.2.3-70-g09d2 From c9f4cabfbd516155d4ad9222dfaa4ec2d228fc13 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 03:59:54 +0200 Subject: Remove unnecessary parameter of set_mobstate --- src/map/unit.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 3c86ff02d..04035da98 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -598,16 +598,15 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) } /** - * Sets mob's CHASE / FOLLOW states. + * Sets CHASE / FOLLOW states, in case bl is a mob. * WARNING: This shouldn't be done if there's no path to reach * @param bl: block_list of mob - * @param flag: if set to 0 this function will set nothing */ -static inline void set_mobstate(struct block_list *bl, int flag) +static inline void set_mobstate(struct block_list *bl) { struct mob_data* md = BL_CAST(BL_MOB, bl); - if (md != NULL && flag != 0) { + if (md != NULL) { if (md->state.aggressive != 0) md->state.skillstate = MSS_FOLLOW; else @@ -636,8 +635,8 @@ static int unit_walktobl_timer(int tid, int64 tick, int id, intptr_t data) if (ud->walktimer == INVALID_TIMER && ud->target == data) { if (DIFF_TICK(ud->canmove_tick, tick) > 0) // Keep waiting? timer->add(ud->canmove_tick + 1, unit->walktobl_timer, id, data); - else if (unit->can_move(bl) != 0 && unit->walktoxy_sub(bl) == 0) - set_mobstate(bl, ud->state.attack_continue); + else if (unit->can_move(bl) != 0 && unit->walktoxy_sub(bl) == 0 && ud->state.attack_continue != 0) + set_mobstate(bl); } return 0; } @@ -681,7 +680,8 @@ static int unit_walktobl(struct block_list *bl, struct block_list *tbl, int rang if(ud->walktimer != INVALID_TIMER) { ud->state.change_walk_target = 1; - set_mobstate(bl, flag&2); + if ((flag & 2) != 0) + set_mobstate(bl); return 1; } @@ -694,8 +694,8 @@ static int unit_walktobl(struct block_list *bl, struct block_list *tbl, int rang if(!unit->can_move(bl)) return 0; - if (unit->walktoxy_sub(bl) == 0) { - set_mobstate(bl, flag&2); + if (unit->walktoxy_sub(bl) == 0 && (flag & 2) != 0) { + set_mobstate(bl); return 0; } return 0; -- cgit v1.2.3-70-g09d2 From 9087aa77f925f5eeee809467839b526795b07170 Mon Sep 17 00:00:00 2001 From: skyleo Date: Thu, 3 Oct 2019 23:01:03 +0200 Subject: Update HPM Hooks --- src/plugins/HPMHooking/HPMHooking.Defs.inc | 4 ++-- src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc | 8 ++++---- src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc | 2 +- src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index 4be3accf8..d2300fdc2 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -8300,8 +8300,8 @@ typedef int (*HPMHOOK_pre_unit_delay_walktoxy_timer) (int *tid, int64 *tick, int typedef int (*HPMHOOK_post_unit_delay_walktoxy_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data); typedef int (*HPMHOOK_pre_unit_walktoxy) (struct block_list **bl, short *x, short *y, int *flag); typedef int (*HPMHOOK_post_unit_walktoxy) (int retVal___, struct block_list *bl, short x, short y, int flag); -typedef int (*HPMHOOK_pre_unit_walktobl_sub) (int *tid, int64 *tick, int *id, intptr_t *data); -typedef int (*HPMHOOK_post_unit_walktobl_sub) (int retVal___, int tid, int64 tick, int id, intptr_t data); +typedef int (*HPMHOOK_pre_unit_walktobl_timer) (int *tid, int64 *tick, int *id, intptr_t *data); +typedef int (*HPMHOOK_post_unit_walktobl_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data); typedef int (*HPMHOOK_pre_unit_walktobl) (struct block_list **bl, struct block_list **tbl, int *range, int *flag); typedef int (*HPMHOOK_post_unit_walktobl) (int retVal___, struct block_list *bl, struct block_list *tbl, int range, int flag); typedef bool (*HPMHOOK_pre_unit_run) (struct block_list **bl, struct map_session_data **sd, enum sc_type *type); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index 3e1b8af78..2f8420162 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -6798,8 +6798,8 @@ struct { struct HPMHookPoint *HP_unit_delay_walktoxy_timer_post; struct HPMHookPoint *HP_unit_walktoxy_pre; struct HPMHookPoint *HP_unit_walktoxy_post; - struct HPMHookPoint *HP_unit_walktobl_sub_pre; - struct HPMHookPoint *HP_unit_walktobl_sub_post; + struct HPMHookPoint *HP_unit_walktobl_timer_pre; + struct HPMHookPoint *HP_unit_walktobl_timer_post; struct HPMHookPoint *HP_unit_walktobl_pre; struct HPMHookPoint *HP_unit_walktobl_post; struct HPMHookPoint *HP_unit_run_pre; @@ -13669,8 +13669,8 @@ struct { int HP_unit_delay_walktoxy_timer_post; int HP_unit_walktoxy_pre; int HP_unit_walktoxy_post; - int HP_unit_walktobl_sub_pre; - int HP_unit_walktobl_sub_post; + int HP_unit_walktobl_timer_pre; + int HP_unit_walktobl_timer_post; int HP_unit_walktobl_pre; int HP_unit_walktobl_post; int HP_unit_run_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index 2ec13f3ab..5c1e2a2c0 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -3481,7 +3481,7 @@ struct HookingPointData HookingPoints[] = { { HP_POP(unit->walktoxy_sub, HP_unit_walktoxy_sub) }, { HP_POP(unit->delay_walktoxy_timer, HP_unit_delay_walktoxy_timer) }, { HP_POP(unit->walktoxy, HP_unit_walktoxy) }, - { HP_POP(unit->walktobl_sub, HP_unit_walktobl_sub) }, + { HP_POP(unit->walktobl_timer, HP_unit_walktobl_timer) }, { HP_POP(unit->walktobl, HP_unit_walktobl) }, { HP_POP(unit->run, HP_unit_run) }, { HP_POP(unit->run_hit, HP_unit_run_hit) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 2aab594c1..c9cc29e83 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -90967,14 +90967,14 @@ int HP_unit_walktoxy(struct block_list *bl, short x, short y, int flag) { } return retVal___; } -int HP_unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data) { +int HP_unit_walktobl_timer(int tid, int64 tick, int id, intptr_t data) { int hIndex = 0; int retVal___ = 0; - if (HPMHooks.count.HP_unit_walktobl_sub_pre > 0) { + if (HPMHooks.count.HP_unit_walktobl_timer_pre > 0) { int (*preHookFunc) (int *tid, int64 *tick, int *id, intptr_t *data); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktobl_sub_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_unit_walktobl_sub_pre[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktobl_timer_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_unit_walktobl_timer_pre[hIndex].func; retVal___ = preHookFunc(&tid, &tick, &id, &data); } if (*HPMforce_return) { @@ -90983,12 +90983,12 @@ int HP_unit_walktobl_sub(int tid, int64 tick, int id, intptr_t data) { } } { - retVal___ = HPMHooks.source.unit.walktobl_sub(tid, tick, id, data); + retVal___ = HPMHooks.source.unit.walktobl_timer(tid, tick, id, data); } - if (HPMHooks.count.HP_unit_walktobl_sub_post > 0) { + if (HPMHooks.count.HP_unit_walktobl_timer_post > 0) { int (*postHookFunc) (int retVal___, int tid, int64 tick, int id, intptr_t data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktobl_sub_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_unit_walktobl_sub_post[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktobl_timer_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_unit_walktobl_timer_post[hIndex].func; retVal___ = postHookFunc(retVal___, tid, tick, id, data); } } -- cgit v1.2.3-70-g09d2 From 729d2f274dafcf979157e388a35b62b5e9887f2e Mon Sep 17 00:00:00 2001 From: Leo Pflug Date: Wed, 30 Oct 2019 17:34:19 +0100 Subject: Undo removal of attack->dir_unknown --- src/map/skill.c | 8 +++++++- src/map/skill.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/map/skill.c b/src/map/skill.c index 693cbfe2c..d0affb248 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -3320,7 +3320,7 @@ static int skill_attack(int attack_type, struct block_list *src, struct block_li dir = UNIT_DIR_EAST; // Official servers push target to the West break; default: - dir = UNIT_DIR_UNDEFINED; + dir = skill->attack_dir_unknown(&attack_type, src, dsrc, bl, &skill_id, &skill_lv, &tick, &flag); break; } @@ -3498,6 +3498,11 @@ static int skill_attack_copy_unknown(int *attack_type, struct block_list *src, s return *skill_id; } +static int skill_attack_dir_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag) +{ + return UNIT_DIR_UNDEFINED; +} + static void skill_attack_blow_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, enum unit_dir *dir) @@ -21750,6 +21755,7 @@ void skill_defaults(void) skill->attack_combo2_unknown = skill_attack_combo2_unknown; skill->attack_display_unknown = skill_attack_display_unknown; skill->attack_copy_unknown = skill_attack_copy_unknown; + skill->attack_dir_unknown = skill_attack_dir_unknown; skill->attack_blow_unknown = skill_attack_blow_unknown; skill->attack_post_unknown = skill_attack_post_unknown; skill->timerskill_dead_unknown = skill_timerskill_dead_unknown; diff --git a/src/map/skill.h b/src/map/skill.h index 03062b199..c65547181 100644 --- a/src/map/skill.h +++ b/src/map/skill.h @@ -2163,6 +2163,7 @@ struct skill_interface { void (*attack_combo2_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *combo); void (*attack_display_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage); int (*attack_copy_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); + int (*attack_dir_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); void (*attack_blow_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, enum unit_dir *dir); void (*attack_post_unknown) (int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); bool (*timerskill_dead_unknown) (struct block_list *src, struct unit_data *ud, struct skill_timerskill *skl); -- cgit v1.2.3-70-g09d2 From 697383108c8c6423c4bb1f4a20f79ca6e9aa32bc Mon Sep 17 00:00:00 2001 From: Leo Pflug Date: Wed, 30 Oct 2019 17:37:29 +0100 Subject: Do not split assignment on comma --- src/map/battle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/battle.c b/src/map/battle.c index 24e58cc09..985d2bca4 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -6228,8 +6228,8 @@ 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) ) { - enum unit_dir 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); int dist = distance_bl(src, target); if(dist <= 0 || (map->check_dir(dir, t_dir) == 0 && dist <= tstatus->rhw.range + 1)) { uint16 skill_lv = tsc->data[SC_AUTOCOUNTER]->val1; -- cgit v1.2.3-70-g09d2 From bc0b77acd3e6565653b3efadaab695189beddd72 Mon Sep 17 00:00:00 2001 From: Leo Pflug Date: Wed, 30 Oct 2019 17:40:31 +0100 Subject: Rename UNIT_UNITDEFINES_H to MAP_UNITDEFINES_H --- src/map/unitdefines.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/map/unitdefines.h b/src/map/unitdefines.h index 70b6e8d4d..0ee30998c 100644 --- a/src/map/unitdefines.h +++ b/src/map/unitdefines.h @@ -18,8 +18,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef UNIT_UNITDEFINES_H -#define UNIT_UNITDEFINES_H +#ifndef MAP_UNITDEFINES_H +#define MAP_UNITDEFINES_H /** * Used for directions, @see unit_data.dir @@ -55,4 +55,4 @@ enum unit_dir { /* Returns a random diagonal direction */ #define unit_get_rnd_diagonal_dir() ( UNIT_DIR_NORTHWEST + 2 * (rnd() % 4) ) -#endif /* UNIT_UNITDEFINES_H */ +#endif /* MAP_UNITDEFINES_H */ -- cgit v1.2.3-70-g09d2 From 3077a395f8ff1bc86972914f2f94d58e893e2aa7 Mon Sep 17 00:00:00 2001 From: Leo Pflug Date: Wed, 30 Oct 2019 18:18:09 +0100 Subject: Execute map->freeblock_unlock() if assertion fails --- src/map/skill.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/map/skill.c b/src/map/skill.c index d0affb248..eb9efa071 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -3338,7 +3338,10 @@ static int skill_attack(int attack_type, struct block_list *src, struct block_li case SR_KNUCKLEARROW: if( skill->blown(dsrc,bl,dmg.blewcount,dir,0) && !(flag&4) ) { short dir_x, dir_y; - Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + if (Assert_chk(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX)) { + map->freeblock_unlock(); // unblock before assert-returning + return 0; + } dir_x = dirx[unit_get_opposite_dir(dir)]; dir_y = diry[unit_get_opposite_dir(dir)]; if (map->getcell(bl->m, bl, bl->x + dir_x, bl->y + dir_y, CELL_CHKNOPASS) != 0) @@ -4762,7 +4765,10 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl ty = bl->y; for(i=0;i= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + if (Assert_chk(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX)) { + map->freeblock_unlock(); // unblock before assert-returning + return 0; + } tx -= dirx[dir]; ty -= diry[dir]; // If target cell is a wall then break @@ -4805,7 +4811,10 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl for (i=0;i<4;i++) { map->foreachincell(skill->area_sub,bl->m,x,y,BL_CHAR,src,skill_id,skill_lv, tick,flag|BCT_ENEMY|1,skill->castend_damage_id); - Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + if (Assert_chk(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX)) { + map->freeblock_unlock(); // unblock before assert-returning + return 0; + } x += dirx[dir]; y += diry[dir]; } @@ -5050,7 +5059,10 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl case GC_DARKILLUSION: { enum unit_dir dir = map->calc_dir(bl, src->x, src->y); - Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + if (Assert_chk(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX)) { + map->freeblock_unlock(); // unblock before assert-returning + return 0; + } short x = bl->x + dirx[dir]; short y = bl->y + diry[dir]; @@ -5211,7 +5223,10 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl case RA_WUGSTRIKE: if (sd != NULL && pc_isridingwug(sd)) { enum unit_dir dir = map->calc_dir(bl, src->x, src->y); - Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + if (Assert_chk(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX)) { + map->freeblock_unlock(); // unblock before assert-returning + return 0; + } short x = bl->x + dirx[dir]; short y = bl->y + diry[dir]; if (unit->movepos(src, x, y, 1, 1) != 0) { @@ -8081,7 +8096,10 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list * dir = unit->getdir(src); else dir = map->calc_dir(src, bl->x, bl->y); - Assert_ret(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); + if (Assert_chk(dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX)) { + map->freeblock_unlock(); // unblock before assert-returning + return 0; + } unit->stop_attack(src); //Run skillv tiles overriding the can-move check. if (unit->walktoxy(src, (src->x + skill_lv * -dirx[dir]), -- cgit v1.2.3-70-g09d2 From ddd62450518afd71bd72f914196b6a2eac7e6bd3 Mon Sep 17 00:00:00 2001 From: skyleo Date: Sun, 17 Nov 2019 13:35:15 +0100 Subject: Change the name of all functions which got their return-value meaning changed --- src/map/clif.c | 8 ++--- src/map/elemental.c | 2 +- src/map/mob.c | 6 ++-- src/map/pet.c | 4 +-- src/map/script.c | 28 ++++++++--------- src/map/skill.c | 14 ++++----- src/map/unit.c | 88 ++++++++++++++++++++++++++--------------------------- src/map/unit.h | 12 ++++---- 8 files changed, 81 insertions(+), 81 deletions(-) (limited to 'src') diff --git a/src/map/clif.c b/src/map/clif.c index a0ffeac32..a8b6ea768 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -4900,7 +4900,7 @@ static int clif_damage(struct block_list *src, struct block_list *dst, int sdela } if(src == dst) { - unit->setdir(src,unit->getdir(src)); + unit->set_dir(src, unit->getdir(src)); } //Return adjusted can't walk delay for further processing. @@ -11130,7 +11130,7 @@ static void clif_parse_WalkToXY(int fd, struct map_session_data *sd) //Set last idle time... [Skotlex] pc->update_idle_time(sd, BCIDLE_WALK); - unit->walktoxy(&sd->bl, x, y, 4); + unit->walk_toxy(&sd->bl, x, y, 4); } /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT). @@ -16451,7 +16451,7 @@ static void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd) unit->calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir); ud = unit->bl2ud(bl); - unit->walktoxy(bl, ud->to_x, ud->to_y, 4); + unit->walk_toxy(bl, ud->to_x, ud->to_y, 4); } static void clif_parse_HomMoveTo(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); @@ -16475,7 +16475,7 @@ static void clif_parse_HomMoveTo(int fd, struct map_session_data *sd) else return; - unit->walktoxy(bl, x, y, 4); + unit->walk_toxy(bl, x, y, 4); } static void clif_parse_HomAttack(int fd, struct map_session_data *sd) __attribute__((nonnull (2))); diff --git a/src/map/elemental.c b/src/map/elemental.c index e9b6fa372..f176bb9e2 100644 --- a/src/map/elemental.c +++ b/src/map/elemental.c @@ -789,7 +789,7 @@ static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_ if( DIFF_TICK(tick, ed->ud.canmove_tick) < 0 ) return 0; //Can't move yet. if (map->search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1) != 0 - && unit->walktoxy(&ed->bl, x, y, 0) == 0) + && unit->walk_toxy(&ed->bl, x, y, 0) == 0) return 0; } diff --git a/src/map/mob.c b/src/map/mob.c index 431bdbe0d..51a32abd9 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1462,7 +1462,7 @@ static int mob_ai_sub_hard_slavemob(struct mob_data *md, int64 tick) // If master is BL_MOB and in battle, lock & chase to master's target instead, unless configured not to. if ((battle_config.slave_chase_masters_chasetarget == 0 || (m_md != NULL && !mob->is_in_battle_state(m_md))) && map->search_freecell(&md->bl, bl->m, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 1) - && unit->walktoxy(&md->bl, x, y, 0) == 0) + && unit->walk_toxy(&md->bl, x, y, 0) == 0) return 1; } } else if (bl->m != md->bl.m && map_flag_gvg(md->bl.m)) { @@ -1544,7 +1544,7 @@ static int mob_unlocktarget(struct mob_data *md, int64 tick) unit->set_target(&md->ud, 0); } if(battle_config.official_cell_stack_limit && map->count_oncell(md->bl.m, md->bl.x, md->bl.y, BL_CHAR|BL_NPC, 0x1 | 0x2) > battle_config.official_cell_stack_limit) { - unit->walktoxy(&md->bl, md->bl.x, md->bl.y, 8); + unit->walk_toxy(&md->bl, md->bl.x, md->bl.y, 8); } return 0; @@ -1577,7 +1577,7 @@ static int mob_randomwalk(struct mob_data *md, int64 tick) y+=md->bl.y; if ((x != md->bl.x || y != md->bl.y) && map->getcell(md->bl.m, &md->bl, x, y, CELL_CHKPASS) != 0 - && unit->walktoxy(&md->bl, x, y, 8) == 0) + && unit->walk_toxy(&md->bl, x, y, 8) == 0) break; } if(i==retrycount){ diff --git a/src/map/pet.c b/src/map/pet.c index 0537baaa7..aeb372c05 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -892,7 +892,7 @@ static int pet_randomwalk(struct pet_data *pd, int64 tick) int x=pd->bl.x+r%(d*2+1)-d; int y=pd->bl.y+r/(d*2+1)%(d*2+1)-d; if (map->getcell(pd->bl.m, &pd->bl, x, y, CELL_CHKPASS) != 0 - && unit->walktoxy(&pd->bl, x, y, 0) == 0) { + && unit->walk_toxy(&pd->bl, x, y, 0) == 0) { pd->move_fail_count=0; break; } @@ -992,7 +992,7 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, int return 0; //Already walking to him unit->calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir); - if (unit->walktoxy(&pd->bl, pd->ud.to_x, pd->ud.to_y, 0) != 0) + if (unit->walk_toxy(&pd->bl, pd->ud.to_x, pd->ud.to_y, 0) != 0) pet->randomwalk(pd,tick); return 0; diff --git a/src/map/script.c b/src/map/script.c index d6462384d..3bf0464e7 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -16558,7 +16558,7 @@ static BUILDIN(npcwalkto) } else { status_calc_npc(nd, SCO_NONE); } - unit->walktoxy(&nd->bl, x, y, 0); + unit->walk_toxy(&nd->bl, x, y, 0); } return true; @@ -19680,7 +19680,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) + if (unit->walk_toxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -19727,7 +19727,7 @@ static BUILDIN(setunitdata) clif->changelook(bl, LOOK_WEAPON, val); break; case UDT_LOOKDIR: - unit->setdir(bl, (enum unit_dir) val); + unit->set_dir(bl, (enum unit_dir)val); break; case UDT_CANMOVETICK: md->ud.canmove_tick = val; @@ -19851,7 +19851,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) + if (unit->walk_toxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -19859,7 +19859,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &hd->base_status, hd->homunculus.level); break; case UDT_LOOKDIR: - unit->setdir(bl, (enum unit_dir) val); + unit->set_dir(bl, (enum unit_dir)val); break; case UDT_CANMOVETICK: hd->ud.canmove_tick = val; @@ -19990,7 +19990,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) + if (unit->walk_toxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -19998,7 +19998,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &pd->status, pd->pet.level); break; case UDT_LOOKDIR: - unit->setdir(bl, (enum unit_dir) val); + unit->set_dir(bl, (enum unit_dir)val); break; case UDT_CANMOVETICK: pd->ud.canmove_tick = val; @@ -20123,7 +20123,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) + if (unit->walk_toxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -20131,7 +20131,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &mc->base_status, mc->db->lv); break; case UDT_LOOKDIR: - unit->setdir(bl, (enum unit_dir) val); + unit->set_dir(bl, (enum unit_dir)val); break; case UDT_CANMOVETICK: mc->ud.canmove_tick = val; @@ -20257,7 +20257,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) + if (unit->walk_toxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_SPEED: @@ -20265,7 +20265,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &ed->base_status, ed->db->lv); break; case UDT_LOOKDIR: - unit->setdir(bl, (enum unit_dir) val); + unit->set_dir(bl, (enum unit_dir)val); break; case UDT_CANMOVETICK: ed->ud.canmove_tick = val; @@ -20386,7 +20386,7 @@ static BUILDIN(setunitdata) unit->warp(bl, (short) val, (short) val2, (short) val3, CLR_TELEPORT); break; case UDT_WALKTOXY: - if (unit->walktoxy(bl, (short)val, (short)val2, 2) != 0) + if (unit->walk_toxy(bl, (short)val, (short)val2, 2) != 0) unit->movepos(bl, (short) val, (short) val2, 0, 0); break; case UDT_CLASS: @@ -20397,7 +20397,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &nd->status, nd->level); break; case UDT_LOOKDIR: - unit->setdir(bl, (enum unit_dir) val); + unit->set_dir(bl, (enum unit_dir)val); break; case UDT_STR: nd->status.str = (unsigned short) val; @@ -21121,7 +21121,7 @@ static BUILDIN(unitwalk) if (script_hasdata(st, 4)) { int x = script_getnum(st, 3); int y = script_getnum(st, 4); - if (unit->walktoxy(bl, x, y, 0) == 0) // We'll use harder calculations. + if (unit->walk_toxy(bl, x, y, 0) == 0) // We'll use harder calculations. script_pushint(st, 1); else script_pushint(st, 0); diff --git a/src/map/skill.c b/src/map/skill.c index eb9efa071..b3ed46fbd 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -4425,7 +4425,7 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl skill->blown(src, bl, dist, dir, 0); //HACK: since knockback officially defaults to the left, the client also turns to the left... therefore, // make the caster look in the direction of the target - unit->setdir(src, unit_get_opposite_dir(dir)); + unit->set_dir(src, unit_get_opposite_dir(dir)); } } @@ -4470,7 +4470,7 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl status_change_end(src, SC_HIDING, INVALID_TIMER); skill->attack(BF_WEAPON, src, src, bl, skill_id, skill_lv, tick, flag); dir = unit_get_opposite_dir(dir); // change direction [Celest] - unit->setdir(bl,dir); + unit->set_dir(bl, dir); } else if (sd) clif->skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0, 0); @@ -5044,7 +5044,7 @@ static int skill_castend_damage_id(struct block_list *src, struct block_list *bl case RK_PHANTOMTHRUST: { struct map_session_data *tsd = BL_CAST(BL_PC, bl); - unit->setdir(src,map->calc_dir(src, bl->x, bl->y)); + unit->set_dir(src, map->calc_dir(src, bl->x, bl->y)); clif->skill_nodamage(src,bl,skill_id,skill_lv,1); skill->blown(src,bl,distance_bl(src,bl)-1,unit->getdir(src),0); @@ -5871,7 +5871,7 @@ static int skill_castend_id(int tid, int64 tick, int id, intptr_t data) // Asura Strike caster doesn't look to their target in the end if (src->id != target->id && !is_asura) - unit->setdir(src, map->calc_dir(src, target->x, target->y)); + unit->set_dir(src, map->calc_dir(src, target->x, target->y)); map->freeblock_unlock(); return 1; @@ -8102,8 +8102,8 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list * } unit->stop_attack(src); //Run skillv tiles overriding the can-move check. - if (unit->walktoxy(src, (src->x + skill_lv * -dirx[dir]), - (src->y + skill_lv * -diry[dir]), 2) == 0 && md != NULL) + if (unit->walk_toxy(src, src->x + skill_lv * -dirx[dir], src->y + skill_lv * -diry[dir], 2) == 0 + && md != NULL) md->state.skillstate = MSS_WALK; //Otherwise it isn't updated in the AI. } break; @@ -10844,7 +10844,7 @@ static int skill_castend_pos(int tid, int64 tick, int id, intptr_t data) if( sd && sd->skillitem != AL_WARP ) // Warp-Portal thru items will clear data in skill_castend_map. [Inkfish] sd->skillitem = sd->skillitemlv = 0; - unit->setdir(src, map->calc_dir(src, ud->skillx, ud->skilly)); + unit->set_dir(src, map->calc_dir(src, ud->skillx, ud->skilly)); if (ud->skilltimer == INVALID_TIMER) { if (md) md->skill_idx = -1; diff --git a/src/map/unit.c b/src/map/unit.c index 04035da98..418bbe4b0 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -122,7 +122,7 @@ static struct unit_data *unit_bl2ud2(struct block_list *bl) * @param bl block_list to process * @return 0: success, 1: fail, 2: nullpointer */ -static int unit_walktoxy_sub(struct block_list *bl) +static int unit_walk_toxy_sub(struct block_list *bl) { nullpo_retr(2, bl); struct unit_data *ud = unit->bl2ud(bl); @@ -182,7 +182,7 @@ static int unit_walktoxy_sub(struct block_list *bl) timer_delay = status->get_speed(bl); if (timer_delay > 0) - ud->walktimer = timer->add(timer->gettick() + timer_delay, unit->walktoxy_timer, bl->id, 0); //TODO: check if unit->walktoxy_timer uses any intptr data + ud->walktimer = timer->add(timer->gettick() + timer_delay, unit->walk_toxy_timer, bl->id, 0); //TODO: check if unit->walk_toxy_timer uses any intptr data return 0; } @@ -194,7 +194,7 @@ static int unit_walktoxy_sub(struct block_list *bl) * @param data: Unused * @return 0: success, 1: fail, 2: nullpointer */ -static int unit_step_timer(int tid, int64 tick, int id, intptr_t data) +static int unit_steptimer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); if (bl == NULL || bl->prev == NULL) @@ -204,7 +204,7 @@ static int unit_step_timer(int tid, int64 tick, int id, intptr_t data) return 2; if (ud->steptimer != tid) { - ShowError("unit_step_timer mismatch %d != %d\n", ud->steptimer, tid); + ShowError("unit_steptimer mismatch %d != %d\n", ud->steptimer, tid); return 1; } @@ -289,7 +289,7 @@ static int unit_warpto_master(struct block_list *master_bl, struct block_list *s * @param data: unused * @return 0: success, 1: fail */ -static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) +static int unit_walk_toxy_timer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); if (bl == NULL || bl->prev == NULL) // Stop moved because it is missing from the block_list @@ -330,7 +330,7 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) // Monsters will walk into an icewall from the west and south if they already started walking if (map->getcell(bl->m, bl, x + dx, y + dy, CELL_CHKNOPASS) && (icewall_walk_block == 0 || !map->getcell(bl->m, bl, x + dx, y + dy, CELL_CHKICEWALL) || dx < 0 || dy < 0)) - return unit->walktoxy_sub(bl); + return unit->walk_toxy_sub(bl); // Monsters can only leave icewalls to the west and south // But if movement fails more than icewall_walk_block times, they can ignore this rule @@ -416,7 +416,7 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) if (ud->stepaction && ud->target_to != 0) { // Delete old stepaction even if not executed yet, the latest command is what counts if (ud->steptimer != INVALID_TIMER) { - timer->delete(ud->steptimer, unit->step_timer); + timer->delete(ud->steptimer, unit->steptimer); ud->steptimer = INVALID_TIMER; } // Delay stepactions by half a step (so they are executed at full step) @@ -425,11 +425,11 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) timer_delay = status->get_speed(bl) * 14 / 20; else timer_delay = status->get_speed(bl) / 2; - ud->steptimer = timer->add(tick + timer_delay, unit->step_timer, bl->id, 0); + ud->steptimer = timer->add(tick + timer_delay, unit->steptimer, bl->id, 0); } if (ud->state.change_walk_target) { - if (unit->walktoxy_sub(bl) == 0) + if (unit->walk_toxy_sub(bl) == 0) return 0; clif->fixpos(bl); return 1; @@ -445,7 +445,7 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) timer_delay = status->get_speed(bl); if (timer_delay > 0) { - ud->walktimer = timer->add(tick + timer_delay, unit->walktoxy_timer, id, 0); + ud->walktimer = timer->add(tick + timer_delay, unit->walk_toxy_timer, id, 0); if (md != NULL && DIFF_TICK(tick, md->dmgtick) < 3000) // not required not damaged recently clif->move(ud); } else if (ud->state.running != 0) { @@ -483,34 +483,34 @@ static int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) ud->to_y = bl->y; if (battle_config.official_cell_stack_limit != 0 && map->count_oncell(bl->m, x, y, BL_CHAR | BL_NPC, 0x1 | 0x2) > battle_config.official_cell_stack_limit) { - // Walked on occupied cell, call unit->walktoxy again + // Walked on occupied cell, call unit->walk_toxy again if (ud->steptimer != INVALID_TIMER) { // Execute step timer on next step instead - timer->delete(ud->steptimer, unit->step_timer); + timer->delete(ud->steptimer, unit->steptimer); ud->steptimer = INVALID_TIMER; } - return unit->walktoxy(bl, x, y, 8); + return unit->walk_toxy(bl, x, y, 8); } } return 0; } /** - * Timer for delayed execution of unit->walktoxy once triggered + * Timer for delayed execution of unit->walk_toxy once triggered * @param tid: Timer ID, unused * @param tick: Tick, unused * @param id: ID of block_list to execute the action * @param data: uint32 data cast to intptr_t with x-coord in lowest 16 bits and y-coord in highest 16 bits * @return 0: success, 1: failure */ -static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) +static int unit_delay_walk_toxy_timer(int tid, int64 tick, int id, intptr_t data) { struct block_list *bl = map->id2bl(id); if (bl == NULL || bl->prev == NULL) return 1; short x = (short)GetWord((uint32)data, 0); short y = (short)GetWord((uint32)data, 1); - unit->walktoxy(bl, x, y, 0); + unit->walk_toxy(bl, x, y, 0); return 0; } @@ -527,7 +527,7 @@ static int unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) * . * @return 0: success, 1: failure */ -static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) +static int unit_walk_toxy(struct block_list *bl, short x, short y, int flag) { // TODO: change flag to enum? [skyleo] struct unit_data* ud = NULL; @@ -564,7 +564,7 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) if ((flag & 4) != 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) > 0 && DIFF_TICK(ud->canmove_tick, timer->gettick()) < 2000) { // Delay walking command. [Skotlex] - timer->add(ud->canmove_tick + 1, unit->delay_walktoxy_timer, bl->id, + timer->add(ud->canmove_tick + 1, unit->delay_walk_toxy_timer, bl->id, (intptr_t)MakeDWord((uint16)x, (uint16)y)); return 0; } @@ -589,12 +589,12 @@ static int unit_walktoxy(struct block_list *bl, short x, short y, int flag) if (ud->walktimer != INVALID_TIMER) { // When you come to the center of the grid because the change of destination while you're walking right now - // Call a function from a timer unit->walktoxy_sub + // Call a function from a timer unit->walk_toxy_sub ud->state.change_walk_target = 1; return 0; } - return unit->walktoxy_sub(bl); + return unit->walk_toxy_sub(bl); } /** @@ -635,7 +635,7 @@ static int unit_walktobl_timer(int tid, int64 tick, int id, intptr_t data) if (ud->walktimer == INVALID_TIMER && ud->target == data) { if (DIFF_TICK(ud->canmove_tick, tick) > 0) // Keep waiting? timer->add(ud->canmove_tick + 1, unit->walktobl_timer, id, data); - else if (unit->can_move(bl) != 0 && unit->walktoxy_sub(bl) == 0 && ud->state.attack_continue != 0) + else if (unit->can_move(bl) != 0 && unit->walk_toxy_sub(bl) == 0 && ud->state.attack_continue != 0) set_mobstate(bl); } return 0; @@ -694,7 +694,7 @@ static int unit_walktobl(struct block_list *bl, struct block_list *tbl, int rang if(!unit->can_move(bl)) return 0; - if (unit->walktoxy_sub(bl) == 0 && (flag & 2) != 0) { + if (unit->walk_toxy_sub(bl) == 0 && (flag & 2) != 0) { set_mobstate(bl); return 0; } @@ -784,14 +784,14 @@ static bool unit_run(struct block_list *bl, struct map_session_data *sd, enum sc return false; } - if (unit->walktoxy(bl, to_x, to_y, 1) == 0) + if (unit->walk_toxy(bl, to_x, to_y, 1) == 0) return true; //There must be an obstacle nearby. Attempt walking one cell at a time. do { to_x -= dir_x; to_y -= dir_y; - } while (--i > 0 && unit->walktoxy(bl, to_x, to_y, 1) != 0); + } while (--i > 0 && unit->walk_toxy(bl, to_x, to_y, 1) != 0); if ( i == 0 ) { unit->run_hit(bl, sc, sd, type); @@ -809,7 +809,7 @@ static int unit_escape(struct block_list *bl, struct block_list *target, short d Assert_retr(1, dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); while (dist > 0 && map->getcell(bl->m, bl, bl->x + dist * dirx[dir], bl->y + dist * diry[dir], CELL_CHKNOREACH)) dist--; - if (dist > 0 && unit->walktoxy(bl, bl->x + dist * dirx[dir], bl->y + dist * diry[dir], 0) == 0) + if (dist > 0 && unit->walk_toxy(bl, bl->x + dist * dirx[dir], bl->y + dist * diry[dir], 0) == 0) return 1; else return 0; @@ -885,7 +885,7 @@ static int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int eas * @param dir: the facing direction @see enum unit_dir * @return 0: success, 1: failure */ -static int unit_setdir(struct block_list *bl, enum unit_dir dir) +static int unit_set_dir(struct block_list *bl, enum unit_dir dir) { nullpo_retr(1, bl); struct unit_data *ud = unit->bl2ud(bl); @@ -1075,7 +1075,7 @@ static int unit_stop_walking(struct block_list *bl, int flag) //timer->delete function does not messes with it. If the function's //behavior changes in the future, this code could break! td = timer->get(ud->walktimer); - timer->delete(ud->walktimer, unit->walktoxy_timer); + timer->delete(ud->walktimer, unit->walk_toxy_timer); ud->walktimer = INVALID_TIMER; ud->state.change_walk_target = 0; tick = timer->gettick(); @@ -1083,7 +1083,7 @@ static int unit_stop_walking(struct block_list *bl, int flag) || (flag&STOPWALKING_FLAG_NEXTCELL && td && DIFF_TICK(td->tick, tick) <= td->data/2) //Enough time has passed to cover half-cell ) { ud->walkpath.path_len = ud->walkpath.path_pos+1; - unit->walktoxy_timer(INVALID_TIMER, tick, bl->id, ud->walkpath.path_pos); + unit->walk_toxy_timer(INVALID_TIMER, tick, bl->id, ud->walkpath.path_pos); } if(flag&STOPWALKING_FLAG_FIXPOS) @@ -1515,7 +1515,7 @@ static int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill ud->target_to = target_id; ud->stepskill_id = skill_id; ud->stepskill_lv = skill_lv; - return 0; // Attacking will be handled by unit_walktoxy_timer in this case + return 0; // Attacking will be handled by unit_walk_toxy_timer in this case } //Check range when not using skill on yourself or is a combo-skill during attack @@ -1728,7 +1728,7 @@ static int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill if( casttime > 0 ) { if (src->id != target->id) // self-targeted skills shouldn't show different direction - unit->setdir(src, map->calc_dir(src, target->x, target->y)); + unit->set_dir(src, map->calc_dir(src, target->x, target->y)); ud->skilltimer = timer->add( tick+casttime, skill->castend_id, src->id, 0 ); if (sd && (pc->checkskill(sd, SA_FREECAST) > 0 || skill_id == LG_EXEEDBREAK || (skill->get_inf2(ud->skill_id) & INF2_FREE_CAST_REDUCED) != 0)) status_calc_bl(&sd->bl, SCB_SPEED|SCB_ASPD); @@ -1822,7 +1822,7 @@ static int unit_skilluse_pos2(struct block_list *src, short skill_x, short skill ud->target_to = (skill_x + skill_y*md->xs); ud->stepskill_id = skill_id; ud->stepskill_lv = skill_lv; - return 0; // Attacking will be handled by unit_walktoxy_timer in this case + return 0; // Attacking will be handled by unit_walk_toxy_timer in this case } if( skill->get_state(ud->skill_id) == ST_MOVE_ENABLE ) { @@ -1883,7 +1883,7 @@ static int unit_skilluse_pos2(struct block_list *src, short skill_x, short skill // in official this is triggered even if no cast time. clif->useskill(src, src->id, 0, skill_x, skill_y, skill_id, skill_lv, casttime); if( casttime > 0 ) { - unit->setdir(src, map->calc_dir(src, skill_x, skill_y)); + unit->set_dir(src, map->calc_dir(src, skill_x, skill_y)); ud->skilltimer = timer->add( tick+casttime, skill->castend_pos, src->id, 0 ); if ((sd && pc->checkskill(sd, SA_FREECAST) > 0) || skill_id == LG_EXEEDBREAK || (skill->get_inf2(ud->skill_id) & INF2_FREE_CAST_REDUCED) != 0) { status_calc_bl(&sd->bl, SCB_SPEED|SCB_ASPD); @@ -1962,7 +1962,7 @@ static void unit_stop_stepaction(struct block_list *bl) return; //Clear timer - timer->delete(ud->steptimer, unit->step_timer); + timer->delete(ud->steptimer, unit->steptimer); ud->steptimer = INVALID_TIMER; } @@ -2046,7 +2046,7 @@ static int unit_attack(struct block_list *src, int target_id, int continuous) ud->target_to = ud->target; ud->stepskill_id = 0; ud->stepskill_lv = 0; - return 0; // Attacking will be handled by unit_walktoxy_timer in this case + return 0; // Attacking will be handled by unit_walk_toxy_timer in this case } if(DIFF_TICK(ud->attackabletime, timer->gettick()) > 0) @@ -2336,7 +2336,7 @@ static int unit_attack_timer_sub(struct block_list *src, int tid, int64 tick) } if(ud->state.attack_continue) { - unit->setdir(src, map->calc_dir(src, target->x, target->y)); + unit->set_dir(src, map->calc_dir(src, target->x, target->y)); if( src->type == BL_PC ) pc->update_idle_time(sd, BCIDLE_ATTACK); ud->attacktimer = timer->add(ud->attackabletime,unit->attack_timer,src->id,0); @@ -3033,10 +3033,10 @@ static int do_init_unit(bool minimal) return 0; timer->add_func_list(unit->attack_timer, "unit_attack_timer"); - timer->add_func_list(unit->walktoxy_timer,"unit_walktoxy_timer"); + timer->add_func_list(unit->walk_toxy_timer, "unit_walk_toxy_timer"); timer->add_func_list(unit->walktobl_timer, "unit_walktobl_timer"); - timer->add_func_list(unit->delay_walktoxy_timer,"unit_delay_walktoxy_timer"); - timer->add_func_list(unit->step_timer,"unit_step_timer"); + timer->add_func_list(unit->delay_walk_toxy_timer, "unit_delay_walk_toxy_timer"); + timer->add_func_list(unit->steptimer, "unit_steptimer"); return 0; } @@ -3057,24 +3057,24 @@ void unit_defaults(void) unit->bl2ud2 = unit_bl2ud2; unit->init_ud = unit_init_ud; unit->attack_timer = unit_attack_timer; - unit->walktoxy_timer = unit_walktoxy_timer; - unit->walktoxy_sub = unit_walktoxy_sub; - unit->delay_walktoxy_timer = unit_delay_walktoxy_timer; - unit->walktoxy = unit_walktoxy; + unit->walk_toxy_timer = unit_walk_toxy_timer; + unit->walk_toxy_sub = unit_walk_toxy_sub; + unit->delay_walk_toxy_timer = unit_delay_walk_toxy_timer; + unit->walk_toxy = unit_walk_toxy; unit->walktobl_timer = unit_walktobl_timer; unit->walktobl = unit_walktobl; unit->run = unit_run; unit->run_hit = unit_run_hit; unit->escape = unit_escape; unit->movepos = unit_movepos; - unit->setdir = unit_setdir; + unit->set_dir = unit_set_dir; unit->getdir = unit_getdir; unit->blown = unit_blown; unit->warp = unit_warp; unit->warpto_master = unit_warpto_master; unit->stop_walking = unit_stop_walking; unit->skilluse_id = unit_skilluse_id; - unit->step_timer = unit_step_timer; + unit->steptimer = unit_steptimer; unit->stop_stepaction = unit_stop_stepaction; unit->is_walking = unit_is_walking; unit->can_move = unit_can_move; diff --git a/src/map/unit.h b/src/map/unit.h index dd338d076..57f04b57a 100644 --- a/src/map/unit.h +++ b/src/map/unit.h @@ -106,24 +106,24 @@ struct unit_interface { struct unit_data* (*bl2ud2) (struct block_list *bl); void (*init_ud) (struct unit_data *ud); int (*attack_timer) (int tid, int64 tick, int id, intptr_t data); - int (*walktoxy_timer) (int tid, int64 tick, int id, intptr_t data); - int (*walktoxy_sub) (struct block_list *bl); - int (*delay_walktoxy_timer) (int tid, int64 tick, int id, intptr_t data); - int (*walktoxy) (struct block_list *bl, short x, short y, int flag); + int (*walk_toxy_timer) (int tid, int64 tick, int id, intptr_t data); + int (*walk_toxy_sub) (struct block_list *bl); + int (*delay_walk_toxy_timer) (int tid, int64 tick, int id, intptr_t data); + int (*walk_toxy) (struct block_list *bl, short x, short y, int flag); int (*walktobl_timer) (int tid, int64 tick, int id, intptr_t data); int (*walktobl) (struct block_list *bl, struct block_list *tbl, int range, int flag); bool (*run) (struct block_list *bl, struct map_session_data *sd, enum sc_type type); void (*run_hit) (struct block_list *bl, struct status_change *sc, struct map_session_data *sd, enum sc_type type); int (*escape) (struct block_list *bl, struct block_list *target, short dist); int (*movepos) (struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath); - int (*setdir) (struct block_list *bl, enum unit_dir dir); + int (*set_dir) (struct block_list *bl, enum unit_dir dir); enum unit_dir (*getdir) (struct block_list *bl); int (*blown) (struct block_list *bl, int dx, int dy, int count, int flag); int (*warp) (struct block_list *bl, short m, short x, short y, enum clr_type type); int (*warpto_master) (struct block_list *master_bl, struct block_list *slave_bl); int (*stop_walking) (struct block_list *bl, int type); int (*skilluse_id) (struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv); - int (*step_timer) (int tid, int64 tick, int id, intptr_t data); + int (*steptimer) (int tid, int64 tick, int id, intptr_t data); void (*stop_stepaction) (struct block_list *bl); int (*is_walking) (struct block_list *bl); int (*can_move) (struct block_list *bl); -- cgit v1.2.3-70-g09d2 From 1d17449c0cb809cec8ca16f2ac860f6377bfa305 Mon Sep 17 00:00:00 2001 From: skyleo Date: Mon, 2 Dec 2019 19:58:08 +0100 Subject: Add unit->cbl2ud for when using const block_list --- src/map/unit.c | 33 +++++++++++++++++++++++++++++++++ src/map/unit.h | 1 + 2 files changed, 34 insertions(+) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 418bbe4b0..acf64e820 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -99,6 +99,38 @@ static struct unit_data *unit_bl2ud(struct block_list *bl) } } +/** + * Returns the const unit_data for the given const block_list. If the object is using + * shared unit_data (i.e. in case of BL_NPC), it returns the shared data. + * + * __Warning:__ if bl->type is not known or NULL, + * an assertion will be triggered and NULL returned. + * @param bl block_list to process, it is expected to be not NULL. + * @return a pointer to the given object's unit_data + **/ +static const struct unit_data *unit_cbl2ud(const struct block_list *bl) +{ + Assert_retr(NULL, bl != NULL); + switch (bl->type) { + case BL_PC: + return &BL_UCCAST(BL_PC, bl)->ud; + case BL_MOB: + return &BL_UCCAST(BL_MOB, bl)->ud; + case BL_PET: + return &BL_UCCAST(BL_PET, bl)->ud; + case BL_NPC: + return BL_UCCAST(BL_NPC, bl)->ud; + case BL_HOM: + return &BL_UCCAST(BL_HOM, bl)->ud; + case BL_MER: + return &BL_UCCAST(BL_MER, bl)->ud; + case BL_ELEM: + return &BL_UCCAST(BL_ELEM, bl)->ud; + default: + Assert_retr(NULL, false); + } +} + /** * Returns the unit_data for the given block_list. If the object is using * shared unit_data (i.e. in case of BL_NPC), it recreates a copy of the @@ -3054,6 +3086,7 @@ void unit_defaults(void) unit->final = do_final_unit; /* */ unit->bl2ud = unit_bl2ud; + unit->cbl2ud = unit_cbl2ud; unit->bl2ud2 = unit_bl2ud2; unit->init_ud = unit_init_ud; unit->attack_timer = unit_attack_timer; diff --git a/src/map/unit.h b/src/map/unit.h index 57f04b57a..7bf94d3e1 100644 --- a/src/map/unit.h +++ b/src/map/unit.h @@ -103,6 +103,7 @@ struct unit_interface { int (*final) (void); /* */ struct unit_data* (*bl2ud) (struct block_list *bl); + const struct unit_data* (*cbl2ud) (const struct block_list *bl); struct unit_data* (*bl2ud2) (struct block_list *bl); void (*init_ud) (struct unit_data *ud); int (*attack_timer) (int tid, int64 tick, int id, intptr_t data); -- cgit v1.2.3-70-g09d2 From 01f807099010544eadc1327124cf3772ca0952d6 Mon Sep 17 00:00:00 2001 From: skyleo Date: Sun, 17 Nov 2019 13:43:56 +0100 Subject: Change src parameter to be const in map_calc_dir --- src/map/map.c | 2 +- src/map/map.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/map.c b/src/map/map.c index e0ab2b08d..defa56b2e 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2874,7 +2874,7 @@ static int map_check_dir(enum unit_dir s_dir, enum unit_dir t_dir) * @param y: y-coordinate of cell * @return the direction of the given cell, relative to 'src' **/ -static enum unit_dir map_calc_dir(struct block_list *src, int16 x, int16 y) +static enum unit_dir map_calc_dir(const struct block_list *src, int16 x, int16 y) { nullpo_retr(UNIT_DIR_NORTH, src); enum unit_dir dir = UNIT_DIR_NORTH; diff --git a/src/map/map.h b/src/map/map.h index e0fbcf9b2..a876539d0 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -1218,7 +1218,7 @@ END_ZEROED_BLOCK; void (*reloadnpc) (bool clear); int (*check_dir) (enum unit_dir s_dir, enum unit_dir t_dir); - enum unit_dir (*calc_dir) (struct block_list *src, int16 x, int16 y); + enum unit_dir (*calc_dir) (const struct block_list *src, int16 x, int16 y); int (*random_dir) (struct block_list *bl, short *x, short *y); // [Skotlex] int (*cleanup_sub) (struct block_list *bl, va_list ap); -- cgit v1.2.3-70-g09d2 From dad727a34acf286ef0f30ca0ee396d3e106be2ec Mon Sep 17 00:00:00 2001 From: skyleo Date: Mon, 2 Dec 2019 18:22:24 +0100 Subject: Expect bl to be not NULL in unit->bl2ud --- src/map/unit.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index acf64e820..96222a62f 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -72,13 +72,12 @@ struct unit_interface *unit; /** * Returns the unit_data for the given block_list. If the object is using * shared unit_data (i.e. in case of BL_NPC), it returns the shared data. - * @param bl block_list to process + * @param bl block_list to process, it is expected to be not NULL. * @return a pointer to the given object's unit_data **/ static struct unit_data *unit_bl2ud(struct block_list *bl) { - if (bl == NULL) - return NULL; + Assert_retr(NULL, bl != NULL); switch (bl->type) { case BL_PC: return &BL_UCAST(BL_PC, bl)->ud; -- cgit v1.2.3-70-g09d2 From 88cca0d976bdd6fbe07c8646939fc1512e97cf72 Mon Sep 17 00:00:00 2001 From: skyleo Date: Mon, 2 Dec 2019 18:26:42 +0100 Subject: Handle not known values of bl->type with assertion --- src/map/unit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 96222a62f..28f81017f 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -72,6 +72,9 @@ struct unit_interface *unit; /** * Returns the unit_data for the given block_list. If the object is using * shared unit_data (i.e. in case of BL_NPC), it returns the shared data. + * + * __Warning:__ if bl->type is not known or NULL, + * an assertion will be triggered and NULL returned. * @param bl block_list to process, it is expected to be not NULL. * @return a pointer to the given object's unit_data **/ @@ -94,7 +97,7 @@ static struct unit_data *unit_bl2ud(struct block_list *bl) case BL_ELEM: return &BL_UCAST(BL_ELEM, bl)->ud; default: - return NULL; + Assert_retr(NULL, false); } } -- cgit v1.2.3-70-g09d2 From 2a6299822436e560319fd288dc44d8997943e731 Mon Sep 17 00:00:00 2001 From: skyleo Date: Mon, 2 Dec 2019 18:39:24 +0100 Subject: Update HPM Hooks --- src/plugins/HPMHooking/HPMHooking.Defs.inc | 26 +++-- .../HPMHooking/HPMHooking_map.HPMHooksCore.inc | 52 +++++---- .../HPMHooking/HPMHooking_map.HookingPoints.inc | 13 ++- src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 123 +++++++++++++-------- 4 files changed, 124 insertions(+), 90 deletions(-) (limited to 'src') diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index d2300fdc2..3d4d0d7ef 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -7606,6 +7606,8 @@ typedef void (*HPMHOOK_pre_skill_attack_display_unknown) (int **attack_type, str typedef void (*HPMHOOK_post_skill_attack_display_unknown) (int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage); typedef int (*HPMHOOK_pre_skill_attack_copy_unknown) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag); typedef int (*HPMHOOK_post_skill_attack_copy_unknown) (int retVal___, int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); +typedef int (*HPMHOOK_pre_skill_attack_dir_unknown) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag); +typedef int (*HPMHOOK_post_skill_attack_dir_unknown) (int retVal___, int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); typedef void (*HPMHOOK_pre_skill_attack_blow_unknown) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag, int **type, struct Damage **dmg, int64 **damage, enum unit_dir **dir); typedef void (*HPMHOOK_post_skill_attack_blow_unknown) (int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, enum unit_dir *dir); typedef void (*HPMHOOK_pre_skill_attack_post_unknown) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag); @@ -8292,14 +8294,14 @@ typedef void (*HPMHOOK_pre_unit_init_ud) (struct unit_data **ud); typedef void (*HPMHOOK_post_unit_init_ud) (struct unit_data *ud); typedef int (*HPMHOOK_pre_unit_attack_timer) (int *tid, int64 *tick, int *id, intptr_t *data); typedef int (*HPMHOOK_post_unit_attack_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data); -typedef int (*HPMHOOK_pre_unit_walktoxy_timer) (int *tid, int64 *tick, int *id, intptr_t *data); -typedef int (*HPMHOOK_post_unit_walktoxy_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data); -typedef int (*HPMHOOK_pre_unit_walktoxy_sub) (struct block_list **bl); -typedef int (*HPMHOOK_post_unit_walktoxy_sub) (int retVal___, struct block_list *bl); -typedef int (*HPMHOOK_pre_unit_delay_walktoxy_timer) (int *tid, int64 *tick, int *id, intptr_t *data); -typedef int (*HPMHOOK_post_unit_delay_walktoxy_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data); -typedef int (*HPMHOOK_pre_unit_walktoxy) (struct block_list **bl, short *x, short *y, int *flag); -typedef int (*HPMHOOK_post_unit_walktoxy) (int retVal___, struct block_list *bl, short x, short y, int flag); +typedef int (*HPMHOOK_pre_unit_walk_toxy_timer) (int *tid, int64 *tick, int *id, intptr_t *data); +typedef int (*HPMHOOK_post_unit_walk_toxy_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data); +typedef int (*HPMHOOK_pre_unit_walk_toxy_sub) (struct block_list **bl); +typedef int (*HPMHOOK_post_unit_walk_toxy_sub) (int retVal___, struct block_list *bl); +typedef int (*HPMHOOK_pre_unit_delay_walk_toxy_timer) (int *tid, int64 *tick, int *id, intptr_t *data); +typedef int (*HPMHOOK_post_unit_delay_walk_toxy_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data); +typedef int (*HPMHOOK_pre_unit_walk_toxy) (struct block_list **bl, short *x, short *y, int *flag); +typedef int (*HPMHOOK_post_unit_walk_toxy) (int retVal___, struct block_list *bl, short x, short y, int flag); typedef int (*HPMHOOK_pre_unit_walktobl_timer) (int *tid, int64 *tick, int *id, intptr_t *data); typedef int (*HPMHOOK_post_unit_walktobl_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data); typedef int (*HPMHOOK_pre_unit_walktobl) (struct block_list **bl, struct block_list **tbl, int *range, int *flag); @@ -8312,8 +8314,8 @@ typedef int (*HPMHOOK_pre_unit_escape) (struct block_list **bl, struct block_lis typedef int (*HPMHOOK_post_unit_escape) (int retVal___, struct block_list *bl, struct block_list *target, short dist); typedef int (*HPMHOOK_pre_unit_movepos) (struct block_list **bl, short *dst_x, short *dst_y, int *easy, bool *checkpath); typedef int (*HPMHOOK_post_unit_movepos) (int retVal___, struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath); -typedef int (*HPMHOOK_pre_unit_setdir) (struct block_list **bl, enum unit_dir *dir); -typedef int (*HPMHOOK_post_unit_setdir) (int retVal___, struct block_list *bl, enum unit_dir dir); +typedef int (*HPMHOOK_pre_unit_set_dir) (struct block_list **bl, enum unit_dir *dir); +typedef int (*HPMHOOK_post_unit_set_dir) (int retVal___, struct block_list *bl, enum unit_dir dir); typedef enum unit_dir (*HPMHOOK_pre_unit_getdir) (struct block_list **bl); typedef enum unit_dir (*HPMHOOK_post_unit_getdir) (enum unit_dir retVal___, struct block_list *bl); typedef int (*HPMHOOK_pre_unit_blown) (struct block_list **bl, int *dx, int *dy, int *count, int *flag); @@ -8326,8 +8328,8 @@ typedef int (*HPMHOOK_pre_unit_stop_walking) (struct block_list **bl, int *type) typedef int (*HPMHOOK_post_unit_stop_walking) (int retVal___, struct block_list *bl, int type); typedef int (*HPMHOOK_pre_unit_skilluse_id) (struct block_list **src, int *target_id, uint16 *skill_id, uint16 *skill_lv); typedef int (*HPMHOOK_post_unit_skilluse_id) (int retVal___, struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv); -typedef int (*HPMHOOK_pre_unit_step_timer) (int *tid, int64 *tick, int *id, intptr_t *data); -typedef int (*HPMHOOK_post_unit_step_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data); +typedef int (*HPMHOOK_pre_unit_steptimer) (int *tid, int64 *tick, int *id, intptr_t *data); +typedef int (*HPMHOOK_post_unit_steptimer) (int retVal___, int tid, int64 tick, int id, intptr_t data); typedef void (*HPMHOOK_pre_unit_stop_stepaction) (struct block_list **bl); typedef void (*HPMHOOK_post_unit_stop_stepaction) (struct block_list *bl); typedef int (*HPMHOOK_pre_unit_is_walking) (struct block_list **bl); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index 2f8420162..84aa203ac 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -6130,6 +6130,8 @@ struct { struct HPMHookPoint *HP_skill_attack_display_unknown_post; struct HPMHookPoint *HP_skill_attack_copy_unknown_pre; struct HPMHookPoint *HP_skill_attack_copy_unknown_post; + struct HPMHookPoint *HP_skill_attack_dir_unknown_pre; + struct HPMHookPoint *HP_skill_attack_dir_unknown_post; struct HPMHookPoint *HP_skill_attack_blow_unknown_pre; struct HPMHookPoint *HP_skill_attack_blow_unknown_post; struct HPMHookPoint *HP_skill_attack_post_unknown_pre; @@ -6790,14 +6792,14 @@ struct { struct HPMHookPoint *HP_unit_init_ud_post; struct HPMHookPoint *HP_unit_attack_timer_pre; struct HPMHookPoint *HP_unit_attack_timer_post; - struct HPMHookPoint *HP_unit_walktoxy_timer_pre; - struct HPMHookPoint *HP_unit_walktoxy_timer_post; - struct HPMHookPoint *HP_unit_walktoxy_sub_pre; - struct HPMHookPoint *HP_unit_walktoxy_sub_post; - struct HPMHookPoint *HP_unit_delay_walktoxy_timer_pre; - struct HPMHookPoint *HP_unit_delay_walktoxy_timer_post; - struct HPMHookPoint *HP_unit_walktoxy_pre; - struct HPMHookPoint *HP_unit_walktoxy_post; + struct HPMHookPoint *HP_unit_walk_toxy_timer_pre; + struct HPMHookPoint *HP_unit_walk_toxy_timer_post; + struct HPMHookPoint *HP_unit_walk_toxy_sub_pre; + struct HPMHookPoint *HP_unit_walk_toxy_sub_post; + struct HPMHookPoint *HP_unit_delay_walk_toxy_timer_pre; + struct HPMHookPoint *HP_unit_delay_walk_toxy_timer_post; + struct HPMHookPoint *HP_unit_walk_toxy_pre; + struct HPMHookPoint *HP_unit_walk_toxy_post; struct HPMHookPoint *HP_unit_walktobl_timer_pre; struct HPMHookPoint *HP_unit_walktobl_timer_post; struct HPMHookPoint *HP_unit_walktobl_pre; @@ -6810,8 +6812,8 @@ struct { struct HPMHookPoint *HP_unit_escape_post; struct HPMHookPoint *HP_unit_movepos_pre; struct HPMHookPoint *HP_unit_movepos_post; - struct HPMHookPoint *HP_unit_setdir_pre; - struct HPMHookPoint *HP_unit_setdir_post; + struct HPMHookPoint *HP_unit_set_dir_pre; + struct HPMHookPoint *HP_unit_set_dir_post; struct HPMHookPoint *HP_unit_getdir_pre; struct HPMHookPoint *HP_unit_getdir_post; struct HPMHookPoint *HP_unit_blown_pre; @@ -6824,8 +6826,8 @@ struct { struct HPMHookPoint *HP_unit_stop_walking_post; struct HPMHookPoint *HP_unit_skilluse_id_pre; struct HPMHookPoint *HP_unit_skilluse_id_post; - struct HPMHookPoint *HP_unit_step_timer_pre; - struct HPMHookPoint *HP_unit_step_timer_post; + struct HPMHookPoint *HP_unit_steptimer_pre; + struct HPMHookPoint *HP_unit_steptimer_post; struct HPMHookPoint *HP_unit_stop_stepaction_pre; struct HPMHookPoint *HP_unit_stop_stepaction_post; struct HPMHookPoint *HP_unit_is_walking_pre; @@ -13001,6 +13003,8 @@ struct { int HP_skill_attack_display_unknown_post; int HP_skill_attack_copy_unknown_pre; int HP_skill_attack_copy_unknown_post; + int HP_skill_attack_dir_unknown_pre; + int HP_skill_attack_dir_unknown_post; int HP_skill_attack_blow_unknown_pre; int HP_skill_attack_blow_unknown_post; int HP_skill_attack_post_unknown_pre; @@ -13661,14 +13665,14 @@ struct { int HP_unit_init_ud_post; int HP_unit_attack_timer_pre; int HP_unit_attack_timer_post; - int HP_unit_walktoxy_timer_pre; - int HP_unit_walktoxy_timer_post; - int HP_unit_walktoxy_sub_pre; - int HP_unit_walktoxy_sub_post; - int HP_unit_delay_walktoxy_timer_pre; - int HP_unit_delay_walktoxy_timer_post; - int HP_unit_walktoxy_pre; - int HP_unit_walktoxy_post; + int HP_unit_walk_toxy_timer_pre; + int HP_unit_walk_toxy_timer_post; + int HP_unit_walk_toxy_sub_pre; + int HP_unit_walk_toxy_sub_post; + int HP_unit_delay_walk_toxy_timer_pre; + int HP_unit_delay_walk_toxy_timer_post; + int HP_unit_walk_toxy_pre; + int HP_unit_walk_toxy_post; int HP_unit_walktobl_timer_pre; int HP_unit_walktobl_timer_post; int HP_unit_walktobl_pre; @@ -13681,8 +13685,8 @@ struct { int HP_unit_escape_post; int HP_unit_movepos_pre; int HP_unit_movepos_post; - int HP_unit_setdir_pre; - int HP_unit_setdir_post; + int HP_unit_set_dir_pre; + int HP_unit_set_dir_post; int HP_unit_getdir_pre; int HP_unit_getdir_post; int HP_unit_blown_pre; @@ -13695,8 +13699,8 @@ struct { int HP_unit_stop_walking_post; int HP_unit_skilluse_id_pre; int HP_unit_skilluse_id_post; - int HP_unit_step_timer_pre; - int HP_unit_step_timer_post; + int HP_unit_steptimer_pre; + int HP_unit_steptimer_post; int HP_unit_stop_stepaction_pre; int HP_unit_stop_stepaction_post; int HP_unit_is_walking_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index 5c1e2a2c0..e05000c1f 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -3134,6 +3134,7 @@ struct HookingPointData HookingPoints[] = { { HP_POP(skill->attack_combo2_unknown, HP_skill_attack_combo2_unknown) }, { HP_POP(skill->attack_display_unknown, HP_skill_attack_display_unknown) }, { HP_POP(skill->attack_copy_unknown, HP_skill_attack_copy_unknown) }, + { HP_POP(skill->attack_dir_unknown, HP_skill_attack_dir_unknown) }, { HP_POP(skill->attack_blow_unknown, HP_skill_attack_blow_unknown) }, { HP_POP(skill->attack_post_unknown, HP_skill_attack_post_unknown) }, { HP_POP(skill->timerskill_dead_unknown, HP_skill_timerskill_dead_unknown) }, @@ -3477,24 +3478,24 @@ struct HookingPointData HookingPoints[] = { { HP_POP(unit->bl2ud2, HP_unit_bl2ud2) }, { HP_POP(unit->init_ud, HP_unit_init_ud) }, { HP_POP(unit->attack_timer, HP_unit_attack_timer) }, - { HP_POP(unit->walktoxy_timer, HP_unit_walktoxy_timer) }, - { HP_POP(unit->walktoxy_sub, HP_unit_walktoxy_sub) }, - { HP_POP(unit->delay_walktoxy_timer, HP_unit_delay_walktoxy_timer) }, - { HP_POP(unit->walktoxy, HP_unit_walktoxy) }, + { HP_POP(unit->walk_toxy_timer, HP_unit_walk_toxy_timer) }, + { HP_POP(unit->walk_toxy_sub, HP_unit_walk_toxy_sub) }, + { HP_POP(unit->delay_walk_toxy_timer, HP_unit_delay_walk_toxy_timer) }, + { HP_POP(unit->walk_toxy, HP_unit_walk_toxy) }, { HP_POP(unit->walktobl_timer, HP_unit_walktobl_timer) }, { HP_POP(unit->walktobl, HP_unit_walktobl) }, { HP_POP(unit->run, HP_unit_run) }, { HP_POP(unit->run_hit, HP_unit_run_hit) }, { HP_POP(unit->escape, HP_unit_escape) }, { HP_POP(unit->movepos, HP_unit_movepos) }, - { HP_POP(unit->setdir, HP_unit_setdir) }, + { HP_POP(unit->set_dir, HP_unit_set_dir) }, { HP_POP(unit->getdir, HP_unit_getdir) }, { HP_POP(unit->blown, HP_unit_blown) }, { HP_POP(unit->warp, HP_unit_warp) }, { HP_POP(unit->warpto_master, HP_unit_warpto_master) }, { HP_POP(unit->stop_walking, HP_unit_stop_walking) }, { HP_POP(unit->skilluse_id, HP_unit_skilluse_id) }, - { HP_POP(unit->step_timer, HP_unit_step_timer) }, + { HP_POP(unit->steptimer, HP_unit_steptimer) }, { HP_POP(unit->stop_stepaction, HP_unit_stop_stepaction) }, { HP_POP(unit->is_walking, HP_unit_is_walking) }, { HP_POP(unit->can_move, HP_unit_can_move) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index c9cc29e83..8302411ad 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -81968,6 +81968,33 @@ int HP_skill_attack_copy_unknown(int *attack_type, struct block_list *src, struc } return retVal___; } +int HP_skill_attack_dir_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag) { + int hIndex = 0; + int retVal___ = 0; + if (HPMHooks.count.HP_skill_attack_dir_unknown_pre > 0) { + int (*preHookFunc) (int **attack_type, struct block_list **src, struct block_list **dsrc, struct block_list **bl, uint16 **skill_id, uint16 **skill_lv, int64 **tick, int **flag); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_attack_dir_unknown_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_skill_attack_dir_unknown_pre[hIndex].func; + retVal___ = preHookFunc(&attack_type, &src, &dsrc, &bl, &skill_id, &skill_lv, &tick, &flag); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.skill.attack_dir_unknown(attack_type, src, dsrc, bl, skill_id, skill_lv, tick, flag); + } + if (HPMHooks.count.HP_skill_attack_dir_unknown_post > 0) { + int (*postHookFunc) (int retVal___, int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag); + for (hIndex = 0; hIndex < HPMHooks.count.HP_skill_attack_dir_unknown_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_skill_attack_dir_unknown_post[hIndex].func; + retVal___ = postHookFunc(retVal___, attack_type, src, dsrc, bl, skill_id, skill_lv, tick, flag); + } + } + return retVal___; +} void HP_skill_attack_blow_unknown(int *attack_type, struct block_list *src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, enum unit_dir *dir) { int hIndex = 0; if (HPMHooks.count.HP_skill_attack_blow_unknown_pre > 0) { @@ -90859,14 +90886,14 @@ int HP_unit_attack_timer(int tid, int64 tick, int id, intptr_t data) { } return retVal___; } -int HP_unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { +int HP_unit_walk_toxy_timer(int tid, int64 tick, int id, intptr_t data) { int hIndex = 0; int retVal___ = 0; - if (HPMHooks.count.HP_unit_walktoxy_timer_pre > 0) { + if (HPMHooks.count.HP_unit_walk_toxy_timer_pre > 0) { int (*preHookFunc) (int *tid, int64 *tick, int *id, intptr_t *data); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktoxy_timer_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_unit_walktoxy_timer_pre[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walk_toxy_timer_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_unit_walk_toxy_timer_pre[hIndex].func; retVal___ = preHookFunc(&tid, &tick, &id, &data); } if (*HPMforce_return) { @@ -90875,25 +90902,25 @@ int HP_unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { } } { - retVal___ = HPMHooks.source.unit.walktoxy_timer(tid, tick, id, data); + retVal___ = HPMHooks.source.unit.walk_toxy_timer(tid, tick, id, data); } - if (HPMHooks.count.HP_unit_walktoxy_timer_post > 0) { + if (HPMHooks.count.HP_unit_walk_toxy_timer_post > 0) { int (*postHookFunc) (int retVal___, int tid, int64 tick, int id, intptr_t data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktoxy_timer_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_unit_walktoxy_timer_post[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walk_toxy_timer_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_unit_walk_toxy_timer_post[hIndex].func; retVal___ = postHookFunc(retVal___, tid, tick, id, data); } } return retVal___; } -int HP_unit_walktoxy_sub(struct block_list *bl) { +int HP_unit_walk_toxy_sub(struct block_list *bl) { int hIndex = 0; int retVal___ = 0; - if (HPMHooks.count.HP_unit_walktoxy_sub_pre > 0) { + if (HPMHooks.count.HP_unit_walk_toxy_sub_pre > 0) { int (*preHookFunc) (struct block_list **bl); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktoxy_sub_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_unit_walktoxy_sub_pre[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walk_toxy_sub_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_unit_walk_toxy_sub_pre[hIndex].func; retVal___ = preHookFunc(&bl); } if (*HPMforce_return) { @@ -90902,25 +90929,25 @@ int HP_unit_walktoxy_sub(struct block_list *bl) { } } { - retVal___ = HPMHooks.source.unit.walktoxy_sub(bl); + retVal___ = HPMHooks.source.unit.walk_toxy_sub(bl); } - if (HPMHooks.count.HP_unit_walktoxy_sub_post > 0) { + if (HPMHooks.count.HP_unit_walk_toxy_sub_post > 0) { int (*postHookFunc) (int retVal___, struct block_list *bl); - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktoxy_sub_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_unit_walktoxy_sub_post[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walk_toxy_sub_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_unit_walk_toxy_sub_post[hIndex].func; retVal___ = postHookFunc(retVal___, bl); } } return retVal___; } -int HP_unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { +int HP_unit_delay_walk_toxy_timer(int tid, int64 tick, int id, intptr_t data) { int hIndex = 0; int retVal___ = 0; - if (HPMHooks.count.HP_unit_delay_walktoxy_timer_pre > 0) { + if (HPMHooks.count.HP_unit_delay_walk_toxy_timer_pre > 0) { int (*preHookFunc) (int *tid, int64 *tick, int *id, intptr_t *data); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_delay_walktoxy_timer_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_unit_delay_walktoxy_timer_pre[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_delay_walk_toxy_timer_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_unit_delay_walk_toxy_timer_pre[hIndex].func; retVal___ = preHookFunc(&tid, &tick, &id, &data); } if (*HPMforce_return) { @@ -90929,25 +90956,25 @@ int HP_unit_delay_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { } } { - retVal___ = HPMHooks.source.unit.delay_walktoxy_timer(tid, tick, id, data); + retVal___ = HPMHooks.source.unit.delay_walk_toxy_timer(tid, tick, id, data); } - if (HPMHooks.count.HP_unit_delay_walktoxy_timer_post > 0) { + if (HPMHooks.count.HP_unit_delay_walk_toxy_timer_post > 0) { int (*postHookFunc) (int retVal___, int tid, int64 tick, int id, intptr_t data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_delay_walktoxy_timer_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_unit_delay_walktoxy_timer_post[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_delay_walk_toxy_timer_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_unit_delay_walk_toxy_timer_post[hIndex].func; retVal___ = postHookFunc(retVal___, tid, tick, id, data); } } return retVal___; } -int HP_unit_walktoxy(struct block_list *bl, short x, short y, int flag) { +int HP_unit_walk_toxy(struct block_list *bl, short x, short y, int flag) { int hIndex = 0; int retVal___ = 0; - if (HPMHooks.count.HP_unit_walktoxy_pre > 0) { + if (HPMHooks.count.HP_unit_walk_toxy_pre > 0) { int (*preHookFunc) (struct block_list **bl, short *x, short *y, int *flag); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktoxy_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_unit_walktoxy_pre[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walk_toxy_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_unit_walk_toxy_pre[hIndex].func; retVal___ = preHookFunc(&bl, &x, &y, &flag); } if (*HPMforce_return) { @@ -90956,12 +90983,12 @@ int HP_unit_walktoxy(struct block_list *bl, short x, short y, int flag) { } } { - retVal___ = HPMHooks.source.unit.walktoxy(bl, x, y, flag); + retVal___ = HPMHooks.source.unit.walk_toxy(bl, x, y, flag); } - if (HPMHooks.count.HP_unit_walktoxy_post > 0) { + if (HPMHooks.count.HP_unit_walk_toxy_post > 0) { int (*postHookFunc) (int retVal___, struct block_list *bl, short x, short y, int flag); - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walktoxy_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_unit_walktoxy_post[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_walk_toxy_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_unit_walk_toxy_post[hIndex].func; retVal___ = postHookFunc(retVal___, bl, x, y, flag); } } @@ -91128,14 +91155,14 @@ int HP_unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, b } return retVal___; } -int HP_unit_setdir(struct block_list *bl, enum unit_dir dir) { +int HP_unit_set_dir(struct block_list *bl, enum unit_dir dir) { int hIndex = 0; int retVal___ = 0; - if (HPMHooks.count.HP_unit_setdir_pre > 0) { + if (HPMHooks.count.HP_unit_set_dir_pre > 0) { int (*preHookFunc) (struct block_list **bl, enum unit_dir *dir); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_setdir_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_unit_setdir_pre[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_set_dir_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_unit_set_dir_pre[hIndex].func; retVal___ = preHookFunc(&bl, &dir); } if (*HPMforce_return) { @@ -91144,12 +91171,12 @@ int HP_unit_setdir(struct block_list *bl, enum unit_dir dir) { } } { - retVal___ = HPMHooks.source.unit.setdir(bl, dir); + retVal___ = HPMHooks.source.unit.set_dir(bl, dir); } - if (HPMHooks.count.HP_unit_setdir_post > 0) { + if (HPMHooks.count.HP_unit_set_dir_post > 0) { int (*postHookFunc) (int retVal___, struct block_list *bl, enum unit_dir dir); - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_setdir_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_unit_setdir_post[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_set_dir_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_unit_set_dir_post[hIndex].func; retVal___ = postHookFunc(retVal___, bl, dir); } } @@ -91317,14 +91344,14 @@ int HP_unit_skilluse_id(struct block_list *src, int target_id, uint16 skill_id, } return retVal___; } -int HP_unit_step_timer(int tid, int64 tick, int id, intptr_t data) { +int HP_unit_steptimer(int tid, int64 tick, int id, intptr_t data) { int hIndex = 0; int retVal___ = 0; - if (HPMHooks.count.HP_unit_step_timer_pre > 0) { + if (HPMHooks.count.HP_unit_steptimer_pre > 0) { int (*preHookFunc) (int *tid, int64 *tick, int *id, intptr_t *data); *HPMforce_return = false; - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_step_timer_pre; hIndex++) { - preHookFunc = HPMHooks.list.HP_unit_step_timer_pre[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_steptimer_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_unit_steptimer_pre[hIndex].func; retVal___ = preHookFunc(&tid, &tick, &id, &data); } if (*HPMforce_return) { @@ -91333,12 +91360,12 @@ int HP_unit_step_timer(int tid, int64 tick, int id, intptr_t data) { } } { - retVal___ = HPMHooks.source.unit.step_timer(tid, tick, id, data); + retVal___ = HPMHooks.source.unit.steptimer(tid, tick, id, data); } - if (HPMHooks.count.HP_unit_step_timer_post > 0) { + if (HPMHooks.count.HP_unit_steptimer_post > 0) { int (*postHookFunc) (int retVal___, int tid, int64 tick, int id, intptr_t data); - for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_step_timer_post; hIndex++) { - postHookFunc = HPMHooks.list.HP_unit_step_timer_post[hIndex].func; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_steptimer_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_unit_steptimer_post[hIndex].func; retVal___ = postHookFunc(retVal___, tid, tick, id, data); } } -- cgit v1.2.3-70-g09d2 From d21fd8e6727f1fba7cb57994aa9c74d4dd0cf05b Mon Sep 17 00:00:00 2001 From: skyleo Date: Mon, 2 Dec 2019 19:03:05 +0100 Subject: Change bl parameter to be const in unit->getdir --- src/map/unit.c | 4 ++-- src/map/unit.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 28f81017f..4a0d98cc4 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -937,13 +937,13 @@ static int unit_set_dir(struct block_list *bl, enum unit_dir dir) * @param bl: unit to request data from * @return the facing direction @see enum unit_dir */ -static enum unit_dir unit_getdir(struct block_list *bl) +static enum unit_dir unit_getdir(const struct block_list *bl) { nullpo_retr(UNIT_DIR_NORTH, bl); if (bl->type == BL_NPC) return BL_UCCAST(BL_NPC, bl)->dir; - struct unit_data *ud = unit->bl2ud(bl); + const struct unit_data *ud = unit->cbl2ud(bl); if (ud == NULL) return UNIT_DIR_NORTH; return ud->dir; diff --git a/src/map/unit.h b/src/map/unit.h index 7bf94d3e1..3f288e0d3 100644 --- a/src/map/unit.h +++ b/src/map/unit.h @@ -118,7 +118,7 @@ struct unit_interface { int (*escape) (struct block_list *bl, struct block_list *target, short dist); int (*movepos) (struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath); int (*set_dir) (struct block_list *bl, enum unit_dir dir); - enum unit_dir (*getdir) (struct block_list *bl); + enum unit_dir (*getdir) (const struct block_list *bl); int (*blown) (struct block_list *bl, int dx, int dy, int count, int flag); int (*warp) (struct block_list *bl, short m, short x, short y, enum clr_type type); int (*warpto_master) (struct block_list *master_bl, struct block_list *slave_bl); -- cgit v1.2.3-70-g09d2 From d4fe2c164c472b3ff580631a6643589e8c70aca8 Mon Sep 17 00:00:00 2001 From: skyleo Date: Mon, 2 Dec 2019 20:06:29 +0100 Subject: Update HPM Hooks --- src/plugins/HPMHooking/HPMHooking.Defs.inc | 10 +++--- .../HPMHooking/HPMHooking_map.HPMHooksCore.inc | 4 +++ .../HPMHooking/HPMHooking_map.HookingPoints.inc | 1 + src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 39 ++++++++++++++++++---- 4 files changed, 44 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index 3d4d0d7ef..28f81b97f 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -4736,8 +4736,8 @@ typedef void (*HPMHOOK_pre_map_reloadnpc) (bool *clear); typedef void (*HPMHOOK_post_map_reloadnpc) (bool clear); typedef int (*HPMHOOK_pre_map_check_dir) (enum unit_dir *s_dir, enum unit_dir *t_dir); typedef int (*HPMHOOK_post_map_check_dir) (int retVal___, enum unit_dir s_dir, enum unit_dir t_dir); -typedef enum unit_dir (*HPMHOOK_pre_map_calc_dir) (struct block_list **src, int16 *x, int16 *y); -typedef enum unit_dir (*HPMHOOK_post_map_calc_dir) (enum unit_dir retVal___, struct block_list *src, int16 x, int16 y); +typedef enum unit_dir (*HPMHOOK_pre_map_calc_dir) (const struct block_list **src, int16 *x, int16 *y); +typedef enum unit_dir (*HPMHOOK_post_map_calc_dir) (enum unit_dir retVal___, const struct block_list *src, int16 x, int16 y); typedef int (*HPMHOOK_pre_map_random_dir) (struct block_list **bl, short **x, short **y); typedef int (*HPMHOOK_post_map_random_dir) (int retVal___, struct block_list *bl, short *x, short *y); typedef int (*HPMHOOK_pre_map_cleanup_sub) (struct block_list **bl, va_list ap); @@ -8288,6 +8288,8 @@ typedef int (*HPMHOOK_pre_unit_final) (void); typedef int (*HPMHOOK_post_unit_final) (int retVal___); typedef struct unit_data* (*HPMHOOK_pre_unit_bl2ud) (struct block_list **bl); typedef struct unit_data* (*HPMHOOK_post_unit_bl2ud) (struct unit_data* retVal___, struct block_list *bl); +typedef const struct unit_data* (*HPMHOOK_pre_unit_cbl2ud) (const struct block_list **bl); +typedef const struct unit_data* (*HPMHOOK_post_unit_cbl2ud) (const struct unit_data* retVal___, const struct block_list *bl); typedef struct unit_data* (*HPMHOOK_pre_unit_bl2ud2) (struct block_list **bl); typedef struct unit_data* (*HPMHOOK_post_unit_bl2ud2) (struct unit_data* retVal___, struct block_list *bl); typedef void (*HPMHOOK_pre_unit_init_ud) (struct unit_data **ud); @@ -8316,8 +8318,8 @@ typedef int (*HPMHOOK_pre_unit_movepos) (struct block_list **bl, short *dst_x, s typedef int (*HPMHOOK_post_unit_movepos) (int retVal___, struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath); typedef int (*HPMHOOK_pre_unit_set_dir) (struct block_list **bl, enum unit_dir *dir); typedef int (*HPMHOOK_post_unit_set_dir) (int retVal___, struct block_list *bl, enum unit_dir dir); -typedef enum unit_dir (*HPMHOOK_pre_unit_getdir) (struct block_list **bl); -typedef enum unit_dir (*HPMHOOK_post_unit_getdir) (enum unit_dir retVal___, struct block_list *bl); +typedef enum unit_dir (*HPMHOOK_pre_unit_getdir) (const struct block_list **bl); +typedef enum unit_dir (*HPMHOOK_post_unit_getdir) (enum unit_dir retVal___, const struct block_list *bl); typedef int (*HPMHOOK_pre_unit_blown) (struct block_list **bl, int *dx, int *dy, int *count, int *flag); typedef int (*HPMHOOK_post_unit_blown) (int retVal___, struct block_list *bl, int dx, int dy, int count, int flag); typedef int (*HPMHOOK_pre_unit_warp) (struct block_list **bl, short *m, short *x, short *y, enum clr_type *type); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index 84aa203ac..f94606bab 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -6786,6 +6786,8 @@ struct { struct HPMHookPoint *HP_unit_final_post; struct HPMHookPoint *HP_unit_bl2ud_pre; struct HPMHookPoint *HP_unit_bl2ud_post; + struct HPMHookPoint *HP_unit_cbl2ud_pre; + struct HPMHookPoint *HP_unit_cbl2ud_post; struct HPMHookPoint *HP_unit_bl2ud2_pre; struct HPMHookPoint *HP_unit_bl2ud2_post; struct HPMHookPoint *HP_unit_init_ud_pre; @@ -13659,6 +13661,8 @@ struct { int HP_unit_final_post; int HP_unit_bl2ud_pre; int HP_unit_bl2ud_post; + int HP_unit_cbl2ud_pre; + int HP_unit_cbl2ud_post; int HP_unit_bl2ud2_pre; int HP_unit_bl2ud2_post; int HP_unit_init_ud_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index e05000c1f..a360b3f53 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -3475,6 +3475,7 @@ struct HookingPointData HookingPoints[] = { { HP_POP(unit->init, HP_unit_init) }, { HP_POP(unit->final, HP_unit_final) }, { HP_POP(unit->bl2ud, HP_unit_bl2ud) }, + { HP_POP(unit->cbl2ud, HP_unit_cbl2ud) }, { HP_POP(unit->bl2ud2, HP_unit_bl2ud2) }, { HP_POP(unit->init_ud, HP_unit_init_ud) }, { HP_POP(unit->attack_timer, HP_unit_attack_timer) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 8302411ad..592279cc4 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -48311,11 +48311,11 @@ int HP_map_check_dir(enum unit_dir s_dir, enum unit_dir t_dir) { } return retVal___; } -enum unit_dir HP_map_calc_dir(struct block_list *src, int16 x, int16 y) { +enum unit_dir HP_map_calc_dir(const struct block_list *src, int16 x, int16 y) { int hIndex = 0; enum unit_dir retVal___ = UNIT_DIR_UNDEFINED; if (HPMHooks.count.HP_map_calc_dir_pre > 0) { - enum unit_dir (*preHookFunc) (struct block_list **src, int16 *x, int16 *y); + enum unit_dir (*preHookFunc) (const struct block_list **src, int16 *x, int16 *y); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_map_calc_dir_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_map_calc_dir_pre[hIndex].func; @@ -48330,7 +48330,7 @@ enum unit_dir HP_map_calc_dir(struct block_list *src, int16 x, int16 y) { retVal___ = HPMHooks.source.map.calc_dir(src, x, y); } if (HPMHooks.count.HP_map_calc_dir_post > 0) { - enum unit_dir (*postHookFunc) (enum unit_dir retVal___, struct block_list *src, int16 x, int16 y); + enum unit_dir (*postHookFunc) (enum unit_dir retVal___, const struct block_list *src, int16 x, int16 y); for (hIndex = 0; hIndex < HPMHooks.count.HP_map_calc_dir_post; hIndex++) { postHookFunc = HPMHooks.list.HP_map_calc_dir_post[hIndex].func; retVal___ = postHookFunc(retVal___, src, x, y); @@ -90806,6 +90806,33 @@ struct unit_data* HP_unit_bl2ud(struct block_list *bl) { } return retVal___; } +const struct unit_data* HP_unit_cbl2ud(const struct block_list *bl) { + int hIndex = 0; + const struct unit_data* retVal___ = NULL; + if (HPMHooks.count.HP_unit_cbl2ud_pre > 0) { + const struct unit_data* (*preHookFunc) (const struct block_list **bl); + *HPMforce_return = false; + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_cbl2ud_pre; hIndex++) { + preHookFunc = HPMHooks.list.HP_unit_cbl2ud_pre[hIndex].func; + retVal___ = preHookFunc(&bl); + } + if (*HPMforce_return) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.unit.cbl2ud(bl); + } + if (HPMHooks.count.HP_unit_cbl2ud_post > 0) { + const struct unit_data* (*postHookFunc) (const struct unit_data* retVal___, const struct block_list *bl); + for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_cbl2ud_post; hIndex++) { + postHookFunc = HPMHooks.list.HP_unit_cbl2ud_post[hIndex].func; + retVal___ = postHookFunc(retVal___, bl); + } + } + return retVal___; +} struct unit_data* HP_unit_bl2ud2(struct block_list *bl) { int hIndex = 0; struct unit_data* retVal___ = NULL; @@ -91182,11 +91209,11 @@ int HP_unit_set_dir(struct block_list *bl, enum unit_dir dir) { } return retVal___; } -enum unit_dir HP_unit_getdir(struct block_list *bl) { +enum unit_dir HP_unit_getdir(const struct block_list *bl) { int hIndex = 0; enum unit_dir retVal___ = UNIT_DIR_UNDEFINED; if (HPMHooks.count.HP_unit_getdir_pre > 0) { - enum unit_dir (*preHookFunc) (struct block_list **bl); + enum unit_dir (*preHookFunc) (const struct block_list **bl); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_getdir_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_unit_getdir_pre[hIndex].func; @@ -91201,7 +91228,7 @@ enum unit_dir HP_unit_getdir(struct block_list *bl) { retVal___ = HPMHooks.source.unit.getdir(bl); } if (HPMHooks.count.HP_unit_getdir_post > 0) { - enum unit_dir (*postHookFunc) (enum unit_dir retVal___, struct block_list *bl); + enum unit_dir (*postHookFunc) (enum unit_dir retVal___, const struct block_list *bl); for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_getdir_post; hIndex++) { postHookFunc = HPMHooks.list.HP_unit_getdir_post[hIndex].func; retVal___ = postHookFunc(retVal___, bl); -- cgit v1.2.3-70-g09d2 From 2f32871ca7790a4924dec19aeeabc1da6cb1fc32 Mon Sep 17 00:00:00 2001 From: skyleo Date: Wed, 5 Feb 2020 21:51:21 +0100 Subject: Correct some typos in doc of unit->walk_toxy_timer --- src/map/unit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/unit.c b/src/map/unit.c index 4a0d98cc4..99682e2d3 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -279,9 +279,9 @@ static int unit_steptimer(int tid, int64 tick, int id, intptr_t data) } /** - * Warps homunuculus or mercenary towards his master in case he's too far away for 3 seconds. + * Warps homunculus or mercenary towards his master in case he's too far away for 3 seconds. * @param master_bl: block_list of master - * @param slave_bl: block_list of homunuculus/mercenary master owns + * @param slave_bl: block_list of homunculus/mercenary master owns * @return 0: success, 1: fail */ static int unit_warpto_master(struct block_list *master_bl, struct block_list *slave_bl) -- cgit v1.2.3-70-g09d2