diff options
author | skyleo <skyleo@skyleo.de> | 2019-10-03 19:18:32 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2020-03-08 20:56:27 +0100 |
commit | 5a6b00556a6787b62a6b0f8b61929249db02ac33 (patch) | |
tree | 0954502eefb0f98bb90157021485efc1406f2463 /src | |
parent | 4e0b33282d2f8914fa5e425f65d6e15f8bd86526 (diff) | |
download | hercules-5a6b00556a6787b62a6b0f8b61929249db02ac33.tar.gz hercules-5a6b00556a6787b62a6b0f8b61929249db02ac33.tar.bz2 hercules-5a6b00556a6787b62a6b0f8b61929249db02ac33.tar.xz hercules-5a6b00556a6787b62a6b0f8b61929249db02ac33.zip |
Update error-code and some Coding Style in unit->step_timer
Diffstat (limited to 'src')
-rw-r--r-- | src/map/unit.c | 56 |
1 files changed, 23 insertions, 33 deletions
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) |