diff options
author | Haru <haru@dotalux.com> | 2015-12-28 15:13:02 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2016-01-06 15:17:44 +0100 |
commit | 0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be (patch) | |
tree | a10d3acba71b7dfd643c3bfcd626fb2f592c2335 /src/map/unit.c | |
parent | 5db8be91c0e1b256a3c9d615ede2957218e69d3a (diff) | |
download | hercules-0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be.tar.gz hercules-0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be.tar.bz2 hercules-0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be.tar.xz hercules-0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be.zip |
Replaced some explicit casts with BL_UCAST
- Replaced safe casts (bl type already checked)
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/unit.c')
-rw-r--r-- | src/map/unit.c | 114 |
1 files changed, 61 insertions, 53 deletions
diff --git a/src/map/unit.c b/src/map/unit.c index e095672e8..53d0a9bf4 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -73,15 +73,16 @@ struct unit_interface *unit; * @param bl block_list to process * @return a pointer to the given object's unit_data **/ -struct unit_data* unit_bl2ud(struct block_list *bl) { - if( bl == NULL) return NULL; - if( bl->type == BL_PC) return &((struct map_session_data*)bl)->ud; - if( bl->type == BL_MOB) return &((struct mob_data*)bl)->ud; - if( bl->type == BL_PET) return &((struct pet_data*)bl)->ud; - if( bl->type == BL_NPC) return ((struct npc_data*)bl)->ud; - if( bl->type == BL_HOM) return &((struct homun_data*)bl)->ud; - if( bl->type == BL_MER) return &((struct mercenary_data*)bl)->ud; - if( bl->type == BL_ELEM) return &((struct elemental_data*)bl)->ud; +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; } @@ -148,8 +149,9 @@ int unit_walktoxy_sub(struct block_list *bl) ud->state.change_walk_target=0; if (bl->type == BL_PC) { - ((struct map_session_data *)bl)->head_dir = 0; - clif->walkok((struct map_session_data *)bl); + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + sd->head_dir = 0; + clif->walkok(sd); } clif->move(ud); @@ -448,7 +450,7 @@ int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { //Cancel chase. ud->to_x = bl->x; ud->to_y = bl->y; - if (tbl && bl->type == BL_MOB && mob->warpchase((struct mob_data *)bl, tbl)) + if (tbl && bl->type == BL_MOB && mob->warpchase(BL_UCAST(BL_MOB, bl), tbl)) return 0; ud->target_to = 0; return 0; @@ -813,7 +815,7 @@ int unit_setdir(struct block_list *bl,unsigned char dir) if (!ud) return 0; ud->dir = dir; if (bl->type == BL_PC) - ((struct map_session_data *)bl)->head_dir = 0; + BL_UCAST(BL_PC, bl)->head_dir = 0; clif->changed_dir(bl, AREA); return 0; } @@ -823,7 +825,7 @@ uint8 unit_getdir(struct block_list *bl) { nullpo_ret(bl); if( bl->type == BL_NPC ) - return ((struct npc_data *)bl)->dir; + return BL_UCCAST(BL_NPC, bl)->dir; ud = unit->bl2ud(bl); if (!ud) return 0; return ud->dir; @@ -917,10 +919,13 @@ int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type) switch (bl->type) { case BL_MOB: - if (map->list[bl->m].flag.monster_noteleport && ((struct mob_data *)bl)->master_id == 0) + { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); + if (map->list[bl->m].flag.monster_noteleport && md->master_id == 0) return 1; - if (m != bl->m && map->list[m].flag.nobranch && battle_config.mob_warp&4 && ((struct mob_data *)bl)->master_id == 0) + if (m != bl->m && map->list[m].flag.nobranch && battle_config.mob_warp&4 && md->master_id == 0) return 1; + } break; case BL_PC: if (map->list[bl->m].flag.noteleport) @@ -947,7 +952,7 @@ int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type) } if (bl->type == BL_PC) //Use pc_setpos - return pc->setpos((struct map_session_data *)bl, map_id2index(m), x, y, type); + return pc->setpos(BL_UCAST(BL_PC, bl), map_id2index(m), x, y, type); if (!unit->remove_map(bl, type, ALC_MARK)) return 3; @@ -1164,7 +1169,7 @@ int unit_set_walkdelay(struct block_list *bl, int64 tick, int delay, int type) { if (type) { //Bosses can ignore skill induced walkdelay (but not damage induced) - if (bl->type == BL_MOB && (((struct mob_data *)bl)->status.mode&MD_BOSS)) + if (bl->type == BL_MOB && (BL_UCCAST(BL_MOB, bl)->status.mode&MD_BOSS)) return 0; //Make sure walk delay is not decreased if (DIFF_TICK(ud->canmove_tick, tick+delay) > 0) @@ -1381,14 +1386,16 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui return 0; } - if( src->type == BL_MOB ) - switch( skill_id ) { + if (src->type == BL_MOB) { + const struct mob_data *src_md = BL_UCCAST(BL_MOB, src); + switch (skill_id) { case NPC_SUMMONSLAVE: case NPC_SUMMONMONSTER: case AL_TELEPORT: - if (((struct mob_data *)src)->master_id && ((struct mob_data *)src)->special_state.ai != AI_NONE) + if (src_md->master_id != 0 && src_md->special_state.ai != AI_NONE) return 0; } + } if (src->type == BL_NPC) // NPC-objects can override cast distance range = AREA_SIZE; // Maximum visible distance before NPC goes out of sight @@ -1564,9 +1571,8 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui clif->skillcasting(src, src->id, target_id, 0,0, skill_id, skill->get_ele(skill_id, skill_lv), casttime); if( casttime > 0 || temp ) { - if (sd && target->type == BL_MOB) - { - struct mob_data *md = (struct mob_data *)target; + if (sd != NULL && target->type == BL_MOB) { + struct mob_data *md = BL_UCAST(BL_MOB, target); mob->skill_event(md, src, tick, -1); //Cast targeted skill event. if (tstatus->mode&(MD_CASTSENSOR_IDLE|MD_CASTSENSOR_CHASE) && battle->check_target(target, src, BCT_ENEMY) > 0) @@ -1848,10 +1854,10 @@ int unit_unattackable(struct block_list *bl) unit->set_target(ud, 0); } - if(bl->type == BL_MOB) - mob->unlocktarget((struct mob_data*)bl, timer->gettick()) ; - else if(bl->type == BL_PET) - pet->unlocktarget((struct pet_data*)bl); + if (bl->type == BL_MOB) + mob->unlocktarget(BL_UCAST(BL_MOB, bl), timer->gettick()); + else if (bl->type == BL_PET) + pet->unlocktarget(BL_UCAST(BL_PET, bl)); return 0; } @@ -1872,10 +1878,10 @@ int unit_attack(struct block_list *src,int target_id,int continuous) { return 1; } - if( src->type == BL_PC ) { - struct map_session_data *sd = (struct map_session_data *)src; + if (src->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, src); if( target->type == BL_NPC ) { // monster npcs [Valaris] - npc->click(sd, (struct npc_data *)target); // submitted by leinsirk10 [Celest] + npc->click(sd, BL_UCAST(BL_NPC, target)); // submitted by leinsirk10 [Celest] return 0; } if( pc_is90overweight(sd) || pc_isridingwug(sd) ) { // overweight or mounted on warg - stop attacking @@ -2086,9 +2092,8 @@ int unit_attack_timer_sub(struct block_list* src, int tid, int64 tick) { ) return 0; // can't attack under these conditions - if( src->m != target->m ) - { - if (src->type == BL_MOB && mob->warpchase((struct mob_data *)src, target)) + if (src->m != target->m) { + if (src->type == BL_MOB && mob->warpchase(BL_UCAST(BL_MOB, src), target)) return 1; // Follow up. return 0; } @@ -2161,7 +2166,7 @@ int unit_attack_timer_sub(struct block_list* src, int tid, int64 tick) { map->foreachinrange(mob->linksearch, src, md->db->range2, BL_MOB, md->class_, target, tick); } } - if (src->type == BL_PET && pet->attackskill((struct pet_data *)src, target->id)) + if (src->type == BL_PET && pet->attackskill(BL_UCAST(BL_PET, src), target->id)) return 1; map->freeblock_lock(); @@ -2257,7 +2262,7 @@ int unit_skillcastcancel(struct block_list *bl,int type) } if (bl->type == BL_MOB) - ((struct mob_data *)bl)->skill_idx = -1; + BL_UCAST(BL_MOB, bl)->skill_idx = -1; clif->skillcastcancel(bl); return 1; @@ -2312,9 +2317,9 @@ int unit_changeviewsize(struct block_list *bl,short size) size=(size<0)?-1:(size>0)?1:0; if(bl->type == BL_PC) { - ((struct map_session_data *)bl)->state.size = size; + BL_UCAST(BL_PC, bl)->state.size = size; } else if(bl->type == BL_MOB) { - ((struct mob_data *)bl)->special_state.size = size; + BL_UCAST(BL_MOB, bl)->special_state.size = size; } else return 0; if(size!=0) @@ -2399,8 +2404,9 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i } switch( bl->type ) { - case BL_PC: { - struct map_session_data *sd = (struct map_session_data*)bl; + case BL_PC: + { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); if(sd->shadowform_id) { struct block_list *d_bl = map->id2bl(sd->shadowform_id); @@ -2495,8 +2501,9 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } - case BL_MOB: { - struct mob_data *md = (struct mob_data*)bl; + case BL_MOB: + { + struct mob_data *md = BL_UCAST(BL_MOB, bl); // Drop previous target mob_slave_keep_target: no. if (!battle_config.mob_slave_keep_target) md->target_id=0; @@ -2506,8 +2513,9 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } - case BL_PET: { - struct pet_data *pd = (struct pet_data*)bl; + case BL_PET: + { + struct pet_data *pd = BL_UCAST(BL_PET, bl); if( pd->pet.intimate <= 0 && !(pd->msd && !pd->msd->state.active) ) { //If logging out, this is deleted on unit->free clif->clearunit_area(bl,clrtype); @@ -2520,7 +2528,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } case BL_HOM: { - struct homun_data *hd = (struct homun_data *)bl; + struct homun_data *hd = BL_UCAST(BL_HOM, bl); if( !hd->homunculus.intimacy && !(hd->master && !hd->master->state.active) ) { //If logging out, this is deleted on unit->free clif->emotion(bl, E_SOB); @@ -2533,7 +2541,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } case BL_MER: { - struct mercenary_data *md = (struct mercenary_data *)bl; + struct mercenary_data *md = BL_UCAST(BL_MER, bl); ud->canact_tick = ud->canmove_tick; if( mercenary->get_lifetime(md) <= 0 && !(md->master && !md->master->state.active) ) { clif->clearunit_area(bl,clrtype); @@ -2545,7 +2553,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } case BL_ELEM: { - struct elemental_data *ed = (struct elemental_data *)bl; + struct elemental_data *ed = BL_UCAST(BL_ELEM, bl); ud->canact_tick = ud->canmove_tick; if( elemental->get_lifetime(ed) <= 0 && !(ed->master && !ed->master->state.active) ) { clif->clearunit_area(bl,clrtype); @@ -2609,7 +2617,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { switch( bl->type ) { case BL_PC: { - struct map_session_data *sd = (struct map_session_data*)bl; + struct map_session_data *sd = BL_UCAST(BL_PC, bl); sd->state.loggingout = 1; @@ -2673,7 +2681,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { } case BL_PET: { - struct pet_data *pd = (struct pet_data*)bl; + struct pet_data *pd = BL_UCAST(BL_PET, bl); struct map_session_data *sd = pd->msd; pet->hungry_timer_delete(pd); if( pd->a_skill ) @@ -2724,7 +2732,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { } case BL_MOB: { - struct mob_data *md = (struct mob_data*)bl; + struct mob_data *md = BL_UCAST(BL_MOB, bl); if( md->spawn_timer != INVALID_TIMER ) { timer->delete(md->spawn_timer,mob->delayspawn); @@ -2784,7 +2792,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { } case BL_HOM: { - struct homun_data *hd = (struct homun_data *)bl; + struct homun_data *hd = BL_UCAST(BL_HOM, bl); struct map_session_data *sd = hd->master; homun->hunger_timer_delete(hd); if( hd->homunculus.intimacy > 0 ) @@ -2800,7 +2808,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { } case BL_MER: { - struct mercenary_data *md = (struct mercenary_data *)bl; + struct mercenary_data *md = BL_UCAST(BL_MER, bl); struct map_session_data *sd = md->master; if( mercenary->get_lifetime(md) > 0 ) mercenary->save(md); @@ -2817,7 +2825,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { break; } case BL_ELEM: { - struct elemental_data *ed = (struct elemental_data *)bl; + struct elemental_data *ed = BL_UCAST(BL_ELEM, bl); struct map_session_data *sd = ed->master; if( elemental->get_lifetime(ed) > 0 ) elemental->save(ed); |