diff options
-rw-r--r-- | src/common/timer.c | 10 | ||||
-rw-r--r-- | src/map/npc.c | 10 | ||||
-rw-r--r-- | src/map/unit.c | 17 | ||||
-rw-r--r-- | src/map/unit.h | 1 |
4 files changed, 24 insertions, 14 deletions
diff --git a/src/common/timer.c b/src/common/timer.c index e7a57481a..0b28f6a06 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -51,7 +51,7 @@ struct timer_interface *timer; // timers (array) static struct TimerData* timer_data = NULL; static int timer_data_max = 0; -static int timer_data_num = 0; +static int timer_data_num = 1; // free timers (array) static int* free_timer_list = NULL; @@ -369,6 +369,7 @@ int timer_add_interval(int64 tick, TimerFunc func, int id, intptr_t data, int in /// Retrieves internal timer data const struct TimerData* timer_get(int tid) { + Assert_retr(NULL, tid > 0); return ( tid >= 0 && tid < timer_data_num ) ? &timer_data[tid] : NULL; } @@ -379,7 +380,7 @@ int timer_do_delete(int tid, TimerFunc func) { nullpo_ret(func); - if( tid < 0 || tid >= timer_data_num ) { + if (tid < 1 || tid >= timer_data_num) { ShowError("timer_do_delete error : no such timer [%d](%p(%s))\n", tid, func, search_timer_func_list(func)); Assert_retr(-1, 0); return -1; @@ -406,6 +407,11 @@ int timer_do_delete(int tid, TimerFunc func) /// Adjusts a timer's expiration time. /// Returns the new tick value, or -1 if it fails. int64 timer_addtick(int tid, int64 tick) { + if (tid < 1 || tid >= timer_data_num) { + ShowError("timer_addtick error : no such timer [%d]\n", tid); + Assert_retr(-1, 0); + return -1; + } return timer->settick(tid, timer_data[tid].tick+tick); } diff --git a/src/map/npc.c b/src/map/npc.c index 1b784b0c8..86e9e5e7a 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -4965,14 +4965,8 @@ static void npc_debug_warps(void) { int do_init_npc(bool minimal) { int i; - memset(&npc->base_ud, 0, sizeof( struct unit_data) ); - npc->base_ud.bl = NULL; - npc->base_ud.walktimer = INVALID_TIMER; - npc->base_ud.skilltimer = INVALID_TIMER; - npc->base_ud.attacktimer = INVALID_TIMER; - npc->base_ud.attackabletime = - npc->base_ud.canact_tick = - npc->base_ud.canmove_tick = timer->gettick(); + unit->init_ud(&npc->base_ud); + npc->base_ud.bl = NULL; //Stock view data for normal npcs. memset(&npc_viewdb, 0, sizeof(npc_viewdb)); diff --git a/src/map/unit.c b/src/map/unit.c index 7e4d94e0b..ac1e3e9b5 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -1220,6 +1220,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui ud = unit->bl2ud(src); if(ud == NULL) return 0; + sc = status->get_sc(src); if (sc && !sc->count) sc = NULL; //Unneeded @@ -2289,11 +2290,18 @@ int unit_skillcastcancel(struct block_list *bl,int type) // unit_data initialization process void unit_dataset(struct block_list *bl) { - struct unit_data *ud; - nullpo_retv(ud = unit->bl2ud(bl)); + struct unit_data *ud = unit->bl2ud(bl); + nullpo_retv(ud); + + unit->init_ud(ud); + ud->bl = bl; +} + +void unit_init_ud(struct unit_data *ud) +{ + nullpo_retv(ud); - memset( ud, 0, sizeof( struct unit_data) ); - ud->bl = bl; + memset (ud, 0, sizeof(struct unit_data)); ud->walktimer = INVALID_TIMER; ud->skilltimer = INVALID_TIMER; ud->attacktimer = INVALID_TIMER; @@ -2895,6 +2903,7 @@ void unit_defaults(void) { /* */ unit->bl2ud = unit_bl2ud; 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; diff --git a/src/map/unit.h b/src/map/unit.h index 0279d73c1..8c4c34696 100644 --- a/src/map/unit.h +++ b/src/map/unit.h @@ -105,6 +105,7 @@ struct unit_interface { /* */ struct unit_data* (*bl2ud) (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); int (*walktoxy_timer) (int tid, int64 tick, int id, intptr_t data); int (*walktoxy_sub) (struct block_list *bl); |