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 | |
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')
-rw-r--r-- | src/map/battle.c | 293 | ||||
-rw-r--r-- | src/map/battleground.c | 37 | ||||
-rw-r--r-- | src/map/clif.c | 206 | ||||
-rw-r--r-- | src/map/map.c | 16 | ||||
-rw-r--r-- | src/map/mob.c | 35 | ||||
-rw-r--r-- | src/map/npc.c | 9 | ||||
-rw-r--r-- | src/map/pc.c | 19 | ||||
-rw-r--r-- | src/map/pet.c | 2 | ||||
-rw-r--r-- | src/map/script.c | 58 | ||||
-rw-r--r-- | src/map/skill.c | 124 | ||||
-rw-r--r-- | src/map/status.c | 571 | ||||
-rw-r--r-- | src/map/unit.c | 114 |
12 files changed, 843 insertions, 641 deletions
diff --git a/src/map/battle.c b/src/map/battle.c index 06f41856c..273ea7fcb 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -61,18 +61,30 @@ struct Battle_Config battle_config; struct battle_interface battle_s; struct battle_interface *battle; -int battle_getcurrentskill(struct block_list *bl) { //Returns the current/last skill in use by this bl. - struct unit_data *ud; +/** + * Returns the current/last skill in use by this bl. + * + * @param bl The bl to check. + * @return The current/last skill ID. + */ +int battle_getcurrentskill(struct block_list *bl) +{ + const struct unit_data *ud; nullpo_ret(bl); if (bl->type == BL_SKILL) { - struct skill_unit * su = (struct skill_unit*)bl; - return su->group?su->group->skill_id:0; + const struct skill_unit *su = BL_UCCAST(BL_SKILL, bl); + if (su->group == NULL) + return 0; + return su->group->skill_id; } ud = unit->bl2ud(bl); - return ud?ud->skill_id:0; + if (ud == NULL) + return 0; + + return ud->skill_id; } /*========================================== @@ -125,12 +137,12 @@ int battle_gettarget(struct block_list* bl) { nullpo_ret(bl); switch (bl->type) { - case BL_PC: return ((struct map_session_data*)bl)->ud.target; - case BL_MOB: return ((struct mob_data*)bl)->target_id; - case BL_PET: return ((struct pet_data*)bl)->target_id; - case BL_HOM: return ((struct homun_data*)bl)->ud.target; - case BL_MER: return ((struct mercenary_data*)bl)->ud.target; - case BL_ELEM: return ((struct elemental_data*)bl)->ud.target; + case BL_PC: return BL_UCCAST(BL_PC, bl)->ud.target; + case BL_MOB: return BL_UCCAST(BL_MOB, bl)->target_id; + case BL_PET: return BL_UCCAST(BL_PET, bl)->target_id; + case BL_HOM: return BL_UCCAST(BL_HOM, bl)->ud.target; + case BL_MER: return BL_UCCAST(BL_MER, bl)->ud.target; + case BL_ELEM: return BL_UCCAST(BL_ELEM, bl)->ud.target; } return 0; @@ -325,8 +337,8 @@ int battle_delay_damage(int64 tick, int amotion, struct block_list *src, struct if (src->type != BL_PC && amotion > 1000) amotion = 1000; //Aegis places a damage-delay cap of 1 sec to non player attacks. [Skotlex] - if( src->type == BL_PC ) { - ((struct map_session_data *)src)->delayed_damage++; + if (src->type == BL_PC) { + BL_UCAST(BL_PC, src)->delayed_damage++; } timer->add(tick+amotion, battle->delay_damage_sub, 0, (intptr_t)dat); @@ -379,7 +391,7 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d } if( target && target->type == BL_SKILL ) { if( atk_elem == ELE_FIRE && battle->get_current_skill(target) == GN_WALLOFTHORN ) { - struct skill_unit *su = (struct skill_unit*)target; + struct skill_unit *su = BL_UCAST(BL_SKILL, target); struct skill_unit_group *sg; struct block_list *sgsrc; @@ -3067,10 +3079,11 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam // Compressed code, fixed by map.h [Epoque] if (src->type == BL_MOB) { + const struct mob_data *md = BL_UCCAST(BL_MOB, src); int i; if (sc->data[SC_MANU_DEF] != NULL) { for (i = 0; i < ARRAYLENGTH(mob->manuk); i++) { - if (mob->manuk[i] == ((struct mob_data *)src)->class_) { + if (mob->manuk[i] == md->class_) { damage -= damage * sc->data[SC_MANU_DEF]->val1 / 100; break; } @@ -3078,7 +3091,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam } if (sc->data[SC_SPL_DEF] != NULL) { for (i = 0; i < ARRAYLENGTH(mob->splendide); i++) { - if (mob->splendide[i] == ((struct mob_data *)src)->class_) { + if (mob->splendide[i] == md->class_) { damage -= damage * sc->data[SC_SPL_DEF]->val1 / 100; break; } @@ -3086,7 +3099,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam } if (sc->data[SC_MORA_BUFF] != NULL) { for (i = 0; i < ARRAYLENGTH(mob->mora); i++) { - if (mob->mora[i] == ((struct mob_data *)src)->class_) { + if (mob->mora[i] == md->class_) { damage -= damage * sc->data[SC_MORA_BUFF]->val1 / 100; break; } @@ -3221,24 +3234,25 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam damage += damage * 75 / 100; // [Epoque] if (bl->type == BL_MOB) { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); int i; - if ( ((sce=tsc->data[SC_MANU_ATK]) && (flag&BF_WEAPON)) || - ((sce=tsc->data[SC_MANU_MATK]) && (flag&BF_MAGIC)) - ) - for (i=0;ARRAYLENGTH(mob->manuk)>i;i++) - if (((struct mob_data *)bl)->class_ == mob->manuk[i]) { + if (((sce=tsc->data[SC_MANU_ATK]) != NULL && (flag&BF_WEAPON)) + || ((sce=tsc->data[SC_MANU_MATK]) != NULL && (flag&BF_MAGIC))) { + for (i = 0; i < ARRAYLENGTH(mob->manuk); i++) + if (md->class_ == mob->manuk[i]) { damage += damage * sce->val1 / 100; break; } - if ( ((sce=tsc->data[SC_SPL_ATK]) && (flag&BF_WEAPON)) || - ((sce=tsc->data[SC_SPL_MATK]) && (flag&BF_MAGIC)) - ) - for (i=0;ARRAYLENGTH(mob->splendide)>i;i++) - if (((struct mob_data *)bl)->class_ == mob->splendide[i]) { + } + if (((sce=tsc->data[SC_SPL_ATK]) != NULL && (flag&BF_WEAPON)) + || ((sce=tsc->data[SC_SPL_MATK]) != NULL && (flag&BF_MAGIC))) { + for (i = 0; i < ARRAYLENGTH(mob->splendide); i++) + if (md->class_ == mob->splendide[i]) { damage += damage * sce->val1 / 100; break; } + } } if( tsc->data[SC_POISONINGWEAPON] ) { struct status_data *tstatus = status->get_status_data(bl); @@ -3258,8 +3272,8 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam if (hd) homun->addspiritball(hd, 10); } if (src->type == BL_PC && damage > 0 && (sce = tsc->data[SC_GENTLETOUCH_ENERGYGAIN]) != NULL) { - struct map_session_data *tsd = (struct map_session_data *)src; - if ( tsd && rnd() % 100 < sce->val2 ) + struct map_session_data *tsd = BL_UCAST(BL_PC, src); + if (tsd != NULL && rnd() % 100 < sce->val2) pc->addspiritball(tsd, skill->get_time(MO_CALLSPIRITS, 1), pc->getmaxspiritball(tsd, 0)); } } @@ -3300,10 +3314,11 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam } if( bl->type == BL_MOB && !status->isdead(bl) && src != bl) { - if ( damage > 0 ) - mob->skill_event((struct mob_data *)bl, src, timer->gettick(), flag); + struct mob_data *md = BL_UCAST(BL_MOB, bl); + if (damage > 0) + mob->skill_event(md, src, timer->gettick(), flag); if (skill_id) - mob->skill_event((struct mob_data *)bl, src, timer->gettick(), MSC_SKILLUSED|(skill_id<<16)); + mob->skill_event(md, src, timer->gettick(), MSC_SKILLUSED|(skill_id<<16)); } if (sd && pc_ismadogear(sd) && rnd()%100 < 50) { int element = -1; @@ -3571,8 +3586,11 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list //Skill Range Criteria ad.flag |= battle->range_type(src, target, skill_id, skill_lv); flag.infdef = (tstatus->mode&MD_PLANT) ? 1 : 0; - if (!flag.infdef && target->type == BL_SKILL && ((struct skill_unit *)target)->group->unit_id == UNT_REVERBERATION) - flag.infdef = 1; // Reverberation takes 1 damage + if (!flag.infdef && target->type == BL_SKILL) { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, target); + if (su->group->unit_id == UNT_REVERBERATION) + flag.infdef = 1; // Reverberation takes 1 damage + } switch(skill_id) { case MG_FIREWALL: @@ -3700,12 +3718,11 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list if (skill_id) { for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { - if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { - if ((((struct mob_data *)target)->status.mode&MD_BOSS) - && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) + if (target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE) { + const struct mob_data *md = BL_UCCAST(BL_MOB, target); + if ((md->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) continue; - if (((struct mob_data *)target)->special_state.clone - && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) + if (md->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) continue; } if( ad.damage > map->list[target->m].zone->capped_skills[i]->cap ) @@ -4176,12 +4193,11 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * if (skill_id) { for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { - if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { - if ((((struct mob_data *)target)->status.mode&MD_BOSS) - && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) + if (target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE) { + const struct mob_data *t_md = BL_UCCAST(BL_MOB, target); + if ((t_md->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) continue; - if (((struct mob_data *)target)->special_state.clone - && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) + if (t_md->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) continue; } if( md.damage > map->list[target->m].zone->capped_skills[i]->cap ) @@ -4307,13 +4323,16 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list //Initial flag flag.rh=1; flag.weapon=1; - flag.infdef=(tstatus->mode&MD_PLANT && skill_id != RA_CLUSTERBOMB + flag.infdef = (tstatus->mode&MD_PLANT && skill_id != RA_CLUSTERBOMB?1:0); #ifdef RENEWAL - && skill_id != HT_FREEZINGTRAP + if (skill_id == HT_FREEZINGTRAP) + flag.infdef = 0; #endif - ?1:0); - if (!flag.infdef && target->type == BL_SKILL && ((struct skill_unit *)target)->group->unit_id == UNT_REVERBERATION) - flag.infdef = 1; // Reverberation takes 1 damage + if (!flag.infdef && target->type == BL_SKILL) { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, target); + if (su->group->unit_id == UNT_REVERBERATION) + flag.infdef = 1; // Reverberation takes 1 damage + } //Initial Values wd.type = BDT_NORMAL; @@ -4859,10 +4878,12 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list ATK_ADD(sstatus->rhw.atk2); //Else use Atk2 break; case HFLI_SBR44: //[orn] - if(src->type == BL_HOM) { - wd.damage = ((struct homun_data *)src)->homunculus.intimacy; + if (src->type == BL_HOM) { + const struct homun_data *hd = BL_UCCAST(BL_HOM, src); + wd.damage = hd->homunculus.intimacy; break; } + break; default: { i = (flag.cri @@ -5398,12 +5419,11 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list if (skill_id) { for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { - if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { - if ((((struct mob_data *)target)->status.mode&MD_BOSS) - && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) + if (target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE) { + const struct mob_data *md = BL_UCCAST(BL_MOB, target); + if ((md->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) continue; - if (((struct mob_data *)target)->special_state.clone - && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) + if (md->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) continue; } if( wd.damage > map->list[target->m].zone->capped_skills[i]->cap ) @@ -5657,12 +5677,11 @@ struct Damage battle_calc_attack(int attack_type,struct block_list *bl,struct bl int i; for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { - if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { - if ((((struct mob_data *)target)->status.mode&MD_BOSS) - && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) + if (target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE) { + const struct mob_data *md = BL_UCCAST(BL_MOB, target); + if ((md->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) continue; - if (((struct mob_data *)target)->special_state.clone - && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) + if (md->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) continue; } if( d.damage > map->list[target->m].zone->capped_skills[i]->cap ) @@ -6190,9 +6209,9 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t if (sd && sd->bonus.splash_range > 0 && damage > 0) skill->castend_damage_id(src, target, 0, 1, tick, 0); - if ( target->type == BL_SKILL && damage > 0 ){ - struct skill_unit *su = (struct skill_unit *)target; - if( su->group && su->group->skill_id == HT_BLASTMINE) + if (target->type == BL_SKILL && damage > 0) { + struct skill_unit *su = BL_UCAST(BL_SKILL, target); + if (su->group && su->group->skill_id == HT_BLASTMINE) skill->blown(src, target, 3, -1, 0); } map->freeblock_lock(); @@ -6221,7 +6240,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t status_change_end(target, SC_DEVOTION, INVALID_TIMER); } } else if( tsc->data[SC_CIRCLE_OF_FIRE_OPTION] && (wd.flag&BF_SHORT) && target->type == BL_PC ) { - struct elemental_data *ed = ((struct map_session_data *)target)->ed; + struct elemental_data *ed = BL_UCAST(BL_PC, target)->ed; if (ed != NULL) { clif->skill_damage(&ed->bl, target, tick, status_get_amotion(src), 0, -30000, 1, EL_CIRCLE_OF_FIRE, tsc->data[SC_CIRCLE_OF_FIRE_OPTION]->val1, BDT_SKILL); skill->attack(BF_MAGIC,&ed->bl,&ed->bl,src,EL_CIRCLE_OF_FIRE,tsc->data[SC_CIRCLE_OF_FIRE_OPTION]->val1,tick,wd.flag); @@ -6386,35 +6405,54 @@ bool battle_check_undead(int race,int element) } //Returns the upmost level master starting with the given object -struct block_list* battle_get_master(struct block_list *src) { - struct block_list *prev; //Used for infinite loop check (master of yourself?) +struct block_list *battle_get_master(struct block_list *src) +{ + struct block_list *prev = NULL; //Used for infinite loop check (master of yourself?) nullpo_retr(NULL, src); do { prev = src; switch (src->type) { case BL_PET: - if (((struct pet_data *)src)->msd != NULL) - src = (struct block_list *)((struct pet_data *)src)->msd; + { + struct pet_data *pd = BL_UCAST(BL_PET, src); + if (pd->msd != NULL) + src = &pd->msd->bl; + } break; case BL_MOB: - if (((struct mob_data *)src)->master_id != 0) - src = map->id2bl(((struct mob_data *)src)->master_id); + { + struct mob_data *md = BL_UCAST(BL_MOB, src); + if (md->master_id != 0) + src = map->id2bl(md->master_id); + } break; case BL_HOM: - if (((struct homun_data *)src)->master != NULL) - src = (struct block_list *)((struct homun_data *)src)->master; + { + struct homun_data *hd = BL_UCAST(BL_HOM, src); + if (hd->master != NULL) + src = &hd->master->bl; + } break; case BL_MER: - if (((struct mercenary_data *)src)->master != NULL) - src = (struct block_list *)((struct mercenary_data *)src)->master; + { + struct mercenary_data *md = BL_UCAST(BL_MER, src); + if (md->master != NULL) + src = &md->master->bl; + } break; case BL_ELEM: - if (((struct elemental_data *)src)->master != NULL) - src = (struct block_list *)((struct elemental_data *)src)->master; + { + struct elemental_data *ed = BL_UCAST(BL_ELEM, src); + if (ed->master != NULL) + src = &ed->master->bl; + } break; case BL_SKILL: - if (((struct skill_unit *)src)->group != NULL && ((struct skill_unit *)src)->group->src_id != 0) - src = map->id2bl(((struct skill_unit *)src)->group->src_id); + { + struct skill_unit *su = BL_UCAST(BL_SKILL, src); + if (su->group != NULL && su->group->src_id != 0) + src = map->id2bl(su->group->src_id); + } break; } } while (src && src != prev); @@ -6455,14 +6493,15 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f if( (s_bl = battle->get_master(src)) == NULL ) s_bl = src; - if ( s_bl->type == BL_PC ) { - switch( t_bl->type ) { + if (s_bl->type == BL_PC) { + const struct map_session_data *s_sd = BL_UCCAST(BL_PC, s_bl); + switch (t_bl->type) { case BL_MOB: // Source => PC, Target => MOB - if (pc_has_permission((struct map_session_data *)s_bl, PC_PERM_DISABLE_PVM) ) + if (pc_has_permission(s_sd, PC_PERM_DISABLE_PVM)) return 0; break; case BL_PC: - if (pc_has_permission((struct map_session_data *)s_bl, PC_PERM_DISABLE_PVP)) + if (pc_has_permission(s_sd, PC_PERM_DISABLE_PVP)) return 0; break; default:/* anything else goes */ @@ -6473,8 +6512,9 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f switch( target->type ) { // Checks on actual target case BL_PC: { - struct status_change *sc = status->get_sc(src); - if (((struct map_session_data *)target)->invincible_timer != INVALID_TIMER) { + const struct status_change *sc = status->get_sc(src); + const struct map_session_data *t_sd = BL_UCCAST(BL_PC, target); + if (t_sd->invincible_timer != INVALID_TIMER) { switch( battle->get_current_skill(src) ) { /* TODO a proper distinction should be established bugreport:8397 */ case PR_SANCTUARY: @@ -6484,7 +6524,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f return -1; } } - if (pc_isinvisible((struct map_session_data *)target)) + if (pc_isinvisible(t_sd)) return -1; //Cannot be targeted yet. if (sc && sc->count) { if (sc->data[SC_SIREN] && sc->data[SC_SIREN]->val2 == target->id) @@ -6494,7 +6534,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f break; case BL_MOB: { - struct mob_data *md = BL_CAST(BL_MOB, target); + const struct mob_data *md = BL_UCCAST(BL_MOB, target); if(( (md->special_state.ai == AI_SPHERE || (md->special_state.ai == AI_FLORA && battle_config.summon_flora&1)) && s_bl->type == BL_PC && src->type != BL_MOB @@ -6509,7 +6549,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f } case BL_SKILL: { - struct skill_unit *su = (struct skill_unit *)target; + const struct skill_unit *su = BL_UCCAST(BL_SKILL, target); if( !su->group ) return 0; if( skill->get_inf2(su->group->skill_id)&INF2_TRAP && @@ -6580,13 +6620,13 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f switch( t_bl->type ) { //Checks on target master case BL_PC: { - struct map_session_data *sd; - if( t_bl == s_bl ) break; - sd = BL_CAST(BL_PC, t_bl); + const struct map_session_data *sd = BL_UCCAST(BL_PC, t_bl); + if (t_bl == s_bl) + break; if( sd->state.monster_ignore && flag&BCT_ENEMY ) return 0; // Global immunity only to Attacks - if (sd->status.karma && s_bl->type == BL_PC && ((struct map_session_data *)s_bl)->status.karma) + if (sd->status.karma && s_bl->type == BL_PC && BL_UCCAST(BL_PC, s_bl)->status.karma) state |= BCT_ENEMY; // Characters with bad karma may fight amongst them if( sd->state.killable ) { state |= BCT_ENEMY; // Everything can kill it @@ -6596,7 +6636,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f } case BL_MOB: { - struct mob_data *md = BL_CAST(BL_MOB, t_bl); + const struct mob_data *md = BL_UCCAST(BL_MOB, t_bl); if( !((map->agit_flag || map->agit2_flag) && map->list[m].flag.gvg_castle) && md->guardian_data && (md->guardian_data->g || md->guardian_data->castle->guild_id) ) @@ -6610,31 +6650,32 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f case BL_PET: if (t_bl->type != BL_MOB && flag&BCT_ENEMY) return 0; //Pet may not attack non-mobs. - if (t_bl->type == BL_MOB && ((struct mob_data *)t_bl)->guardian_data && flag&BCT_ENEMY) + if (t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->guardian_data && flag&BCT_ENEMY) return 0; //pet may not attack Guardians/Emperium break; - case BL_SKILL: { - struct skill_unit *su = (struct skill_unit *)src; - struct status_change* sc = status->get_sc(target); - if (!su->group) - return 0; + case BL_SKILL: + { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, src); + const struct status_change *sc = status->get_sc(target); + if (su->group == NULL) + return 0; - if (su->group->src_id == target->id) { - int inf2 = skill->get_inf2(su->group->skill_id); - if (inf2&INF2_NO_TARGET_SELF) - return -1; - if (inf2&INF2_TARGET_SELF) - return 1; - } - //Status changes that prevent traps from triggering - if (sc && sc->count && skill->get_inf2(su->group->skill_id)&INF2_TRAP) { - if( sc->data[SC_WZ_SIGHTBLASTER] && sc->data[SC_WZ_SIGHTBLASTER]->val2 > 0 && sc->data[SC_WZ_SIGHTBLASTER]->val4%2 == 0) - return -1; - } + if (su->group->src_id == target->id) { + int inf2 = skill->get_inf2(su->group->skill_id); + if (inf2&INF2_NO_TARGET_SELF) + return -1; + if (inf2&INF2_TARGET_SELF) + return 1; } + //Status changes that prevent traps from triggering + if (sc != NULL && sc->count != 0 && skill->get_inf2(su->group->skill_id)&INF2_TRAP) { + if (sc->data[SC_WZ_SIGHTBLASTER] != NULL && sc->data[SC_WZ_SIGHTBLASTER]->val2 > 0 && sc->data[SC_WZ_SIGHTBLASTER]->val4%2 == 0) + return -1; + } + } break; case BL_MER: - if (t_bl->type == BL_MOB && ((struct mob_data *)t_bl)->class_ == MOBID_EMPELIUM && flag&BCT_ENEMY) + if (t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->class_ == MOBID_EMPELIUM && flag&BCT_ENEMY) return 0; //mercenary may not attack Emperium break; } //end switch actual src @@ -6642,7 +6683,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f switch( s_bl->type ) { //Checks on source master case BL_PC: { - struct map_session_data *sd = BL_CAST(BL_PC, s_bl); + const struct map_session_data *sd = BL_UCCAST(BL_PC, s_bl); if( s_bl != t_bl ) { if( sd->state.killer ) { state |= BCT_ENEMY; // Can kill anything @@ -6650,13 +6691,13 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f } else if( sd->duel_group && !((!battle_config.duel_allow_pvp && map->list[m].flag.pvp) || (!battle_config.duel_allow_gvg && map_flag_gvg(m))) ) { - if (t_bl->type == BL_PC && (sd->duel_group == ((struct map_session_data *)t_bl)->duel_group)) + if (t_bl->type == BL_PC && sd->duel_group == BL_UCCAST(BL_PC, t_bl)->duel_group) return (BCT_ENEMY&flag)?1:-1; // Duel targets can ONLY be your enemy, nothing else. else if (src->type != BL_SKILL || (flag&BCT_ALL) != BCT_ALL) return 0; } } - if (map_flag_gvg(m) && !sd->status.guild_id && t_bl->type == BL_MOB && ((struct mob_data *)t_bl)->class_ == MOBID_EMPELIUM) + if (map_flag_gvg(m) && !sd->status.guild_id && t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->class_ == MOBID_EMPELIUM) return 0; //If you don't belong to a guild, can't target emperium. if( t_bl->type != BL_PC ) state |= BCT_ENEMY; //Natural enemy. @@ -6664,21 +6705,21 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f } case BL_MOB: { - struct mob_data *md = BL_CAST(BL_MOB, s_bl); + const struct mob_data *md = BL_UCCAST(BL_MOB, s_bl); if( !((map->agit_flag || map->agit2_flag) && map->list[m].flag.gvg_castle) && md->guardian_data && (md->guardian_data->g || md->guardian_data->castle->guild_id) ) return 0; // Disable guardians/emperium owned by Guilds on non-woe times. if (md->special_state.ai == AI_NONE) { //Normal mobs - struct mob_data *target_md = BL_CAST(BL_MOB, target); + const struct mob_data *target_md = BL_CCAST(BL_MOB, target); if ((target_md != NULL && t_bl->type == BL_PC && target_md->special_state.ai != AI_ZANZOU && target_md->special_state.ai != AI_ATTACK) - || (t_bl->type == BL_MOB && !((struct mob_data *)t_bl)->special_state.ai)) + || (t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->special_state.ai == AI_NONE)) state |= BCT_PARTY; //Normal mobs with no ai are friends. else state |= BCT_ENEMY; //However, all else are enemies. } else { - if (t_bl->type == BL_MOB && ((struct mob_data *)t_bl)->special_state.ai == AI_NONE) + if (t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->special_state.ai == AI_NONE) state |= BCT_ENEMY; //Natural enemy for AI mobs are normal mobs. } break; @@ -6743,14 +6784,14 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f if (state&BCT_ENEMY && battle_config.pk_mode && !map_flag_gvg(m) && s_bl->type == BL_PC && t_bl->type == BL_PC) { // Prevent novice engagement on pk_mode (feature by Valaris) - struct map_session_data *sd = (struct map_session_data *)s_bl; - struct map_session_data *sd2 = (struct map_session_data *)t_bl; + const struct map_session_data *s_sd = BL_UCCAST(BL_PC, s_bl); + const struct map_session_data *t_sd = BL_UCCAST(BL_PC, t_bl); if ( - (sd->class_&MAPID_UPPERMASK) == MAPID_NOVICE || - (sd2->class_&MAPID_UPPERMASK) == MAPID_NOVICE || - (int)sd->status.base_level < battle_config.pk_min_level || - (int)sd2->status.base_level < battle_config.pk_min_level || - (battle_config.pk_level_range && abs((int)sd->status.base_level - (int)sd2->status.base_level) > battle_config.pk_level_range) + (s_sd->class_&MAPID_UPPERMASK) == MAPID_NOVICE || + (t_sd->class_&MAPID_UPPERMASK) == MAPID_NOVICE || + (int)s_sd->status.base_level < battle_config.pk_min_level || + (int)t_sd->status.base_level < battle_config.pk_min_level || + (battle_config.pk_level_range && abs((int)s_sd->status.base_level - (int)t_sd->status.base_level) > battle_config.pk_level_range) ) state &= ~BCT_ENEMY; } diff --git a/src/map/battleground.c b/src/map/battleground.c index a273784d4..e3fedbf34 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -220,29 +220,46 @@ int bg_team_get_id(struct block_list *bl) { nullpo_ret(bl); switch( bl->type ) { case BL_PC: - return ((struct map_session_data *)bl)->bg_id; + { + const struct map_session_data *sd = BL_UCCAST(BL_PC, bl); + return sd->bg_id; + } case BL_PET: - if (((struct pet_data *)bl)->msd != NULL) - return ((struct pet_data *)bl)->msd->bg_id; + { + const struct pet_data *pd = BL_UCCAST(BL_PET, bl); + if (pd->msd != NULL) + return pd->msd->bg_id; + } break; case BL_MOB: { - struct map_session_data *msd; - struct mob_data *md = (struct mob_data *)bl; + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); + const struct map_session_data *msd; if (md->special_state.ai != AI_NONE && (msd = map->id2sd(md->master_id)) != NULL) return msd->bg_id; return md->bg_id; } case BL_HOM: - if (((struct homun_data *)bl)->master != NULL) - return ((struct homun_data*)bl)->master->bg_id; + { + const struct homun_data *hd = BL_UCCAST(BL_HOM, bl); + if (hd->master != NULL) + return hd->master->bg_id; + } break; case BL_MER: - if (((struct mercenary_data *)bl)->master != NULL) - return ((struct mercenary_data *)bl)->master->bg_id; + { + const struct mercenary_data *md = BL_UCCAST(BL_MER, bl); + if (md->master != NULL) + return md->master->bg_id; + } break; case BL_SKILL: - return ((struct skill_unit *)bl)->group->bg_id; + { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, bl); + if (su->group != NULL) + return su->group->bg_id; + } + break; } return 0; diff --git a/src/map/clif.c b/src/map/clif.c index a1581553d..dbfd71fea 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -947,7 +947,7 @@ void clif_set_unit_idle2(struct block_list* bl, struct map_session_data *tsd, en p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? ((struct npc_data *)bl)->option : 0); + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.job = vd->class_; p.head = vd->hair_style; p.weapon = vd->weapon; @@ -1014,7 +1014,7 @@ void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enu p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? ((struct npc_data *)bl)->option : 0); + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.job = vd->class_; p.head = vd->hair_style; p.weapon = vd->weapon; @@ -1050,9 +1050,10 @@ void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enu #endif #if PACKETVER >= 20120221 if (battle_config.show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); p.maxHP = status_get_max_hp(bl); p.HP = status_get_hp(bl); - p.isBoss = (((struct mob_data *)bl)->spawn != NULL && ((struct mob_data *)bl)->spawn->state.boss) ? 1 : 0; + p.isBoss = (md->spawn != NULL && md->spawn->state.boss) ? 1 : 0; } else { p.maxHP = -1; p.HP = -1; @@ -1096,7 +1097,7 @@ void clif_spawn_unit2(struct block_list* bl, enum send_target target) { p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? ((struct npc_data *)bl)->option : 0); + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.head = vd->hair_style; p.weapon = vd->weapon; p.accessory = vd->head_bottom; @@ -1154,7 +1155,7 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) { p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? ((struct npc_data *)bl)->option : 0); + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.job = vd->class_; p.head = vd->hair_style; p.weapon = vd->weapon; @@ -1189,9 +1190,10 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) { #endif #if PACKETVER >= 20120221 if (battle_config.show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); p.maxHP = status_get_max_hp(bl); p.HP = status_get_hp(bl); - p.isBoss = (((struct mob_data *)bl)->spawn != NULL && ((struct mob_data *)bl)->spawn->state.boss) ? 1 : 0; + p.isBoss = (md->spawn != NULL && md->spawn->state.boss) ? 1 : 0; } else { p.maxHP = -1; p.HP = -1; @@ -1248,7 +1250,7 @@ void clif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd, p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? ((struct npc_data *)bl)->option : 0); + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.job = vd->class_; p.head = vd->hair_style; p.weapon = vd->weapon; @@ -1279,9 +1281,10 @@ void clif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd, #endif #if PACKETVER >= 20120221 if (battle_config.show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); p.maxHP = status_get_max_hp(bl); p.HP = status_get_hp(bl); - p.isBoss = (((struct mob_data*)bl)->spawn != NULL && ((struct mob_data *)bl)->spawn->state.boss) ? 1 : 0; + p.isBoss = (md->spawn != NULL && md->spawn->state.boss) ? 1 : 0; } else { p.maxHP = -1; p.HP = -1; @@ -1406,13 +1409,15 @@ bool clif_spawn(struct block_list *bl) if( !vd ) return false; - if ((bl->type == BL_NPC - && ((struct npc_data *)bl)->chat_id == 0 - && (((struct npc_data *)bl)->option&OPTION_INVISIBLE)) // Hide NPC from maya purple card. - || vd->class_ == INVISIBLE_CLASS - ) + if (vd->class_ == INVISIBLE_CLASS) return true; // Doesn't need to be spawned, so everything is alright + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->chat_id == 0 && (nd->option&OPTION_INVISIBLE)) // Hide NPC from maya purple card. + return true; // Doesn't need to be spawned, so everything is alright + } + clif->spawn_unit(bl,AREA_WOS); if (vd->cloth_color) @@ -1423,7 +1428,7 @@ bool clif_spawn(struct block_list *bl) 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); int i; if (sd->spiritball > 0) clif->spiritball(&sd->bl); @@ -1444,7 +1449,7 @@ bool clif_spawn(struct block_list *bl) break; case BL_MOB: { - struct mob_data *md = ((struct mob_data *)bl); + struct mob_data *md = BL_UCAST(BL_MOB, bl); if (md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris] clif->specialeffect(&md->bl,423,AREA); else if (md->special_state.size==SZ_MEDIUM) @@ -1453,7 +1458,7 @@ bool clif_spawn(struct block_list *bl) break; case BL_NPC: { - struct npc_data *nd = ((struct npc_data *)bl); + struct npc_data *nd = BL_UCAST(BL_NPC, bl); if (nd->size == SZ_BIG) clif->specialeffect(&nd->bl,423,AREA); else if (nd->size == SZ_MEDIUM) @@ -1462,7 +1467,7 @@ bool clif_spawn(struct block_list *bl) break; case BL_PET: if (vd->head_bottom) - clif->send_petdata(NULL, (struct pet_data *)bl, 3, vd->head_bottom); // needed to display pet equip properly + clif->send_petdata(NULL, BL_UCAST(BL_PET, bl), 3, vd->head_bottom); // needed to display pet equip properly break; } return true; @@ -1689,7 +1694,7 @@ void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *u 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); //clif_movepc(sd); if(sd->state.size==SZ_BIG) // tiny/big players [Valaris] clif->specialeffect(&sd->bl,423,AREA); @@ -1699,7 +1704,7 @@ void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *u break; case BL_MOB: { - struct mob_data *md = ((struct mob_data *)bl); + struct mob_data *md = BL_UCAST(BL_MOB, bl); if (md->special_state.size == SZ_BIG) // tiny/big mobs [Valaris] clif->specialeffect(&md->bl,423,AREA); else if (md->special_state.size == SZ_MEDIUM) @@ -1708,7 +1713,7 @@ void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *u break; case BL_PET: if( vd->head_bottom ) // needed to display pet equip properly - clif->send_petdata(NULL, (struct pet_data *)bl, 3, vd->head_bottom); + clif->send_petdata(NULL, BL_UCAST(BL_PET, bl), 3, vd->head_bottom); break; } #ifdef ANTI_MAYAP_CHEAT @@ -1735,11 +1740,12 @@ void clif_move(struct unit_data *ud) if (!vd || vd->class_ == INVISIBLE_CLASS) return; //This performance check is needed to keep GM-hidden objects from being notified to bots. - /** - * Hide NPC from maya purple card. - **/ - if (bl->type == BL_NPC && ((struct npc_data *)bl)->chat_id == 0 && (((struct npc_data *)bl)->option&OPTION_INVISIBLE)) - return; + if (bl->type == BL_NPC) { + // Hide NPC from maya purple card. + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->chat_id == 0 && (nd->option&OPTION_INVISIBLE)) + return; + } if (ud->state.speed_changed) { // Since we don't know how to update the speed of other objects, @@ -3490,7 +3496,7 @@ void clif_changeoption(struct block_list* bl) WBUFL(buf,2) = bl->id; WBUFW(buf,6) = (sc) ? sc->opt1 : 0; WBUFW(buf,8) = (sc) ? sc->opt2 : 0; - WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? ((struct npc_data *)bl)->option : 0); + WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); WBUFB(buf,14) = (sd)? sd->status.karma : 0; if(disguised(bl)) { clif->send(buf,packet_len(0x229),bl,AREA_WOS); @@ -3506,7 +3512,7 @@ void clif_changeoption(struct block_list* bl) WBUFL(buf,2) = bl->id; WBUFW(buf,6) = (sc) ? sc->opt1 : 0; WBUFW(buf,8) = (sc) ? sc->opt2 : 0; - WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? ((struct npc_data *)bl)->option : 0); + WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); WBUFB(buf,12) = (sd)? sd->status.karma : 0; if(disguised(bl)) { clif->send(buf,packet_len(0x119),bl,AREA_WOS); @@ -3531,7 +3537,7 @@ void clif_changeoption2(struct block_list* bl) { WBUFW(buf,0) = 0x28a; WBUFL(buf,2) = bl->id; - WBUFL(buf,6) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? ((struct npc_data *)bl)->option : 0); + WBUFL(buf,6) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); WBUFL(buf,10) = clif_setlevel(bl); WBUFL(buf,14) = (sc) ? sc->opt3 : 0; if(disguised(bl)) { @@ -3741,10 +3747,11 @@ void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd) WFIFOW(fd, 2) = 8 + (28*(cd->users+t)); WFIFOL(fd, 4) = cd->bl.id; - if(cd->owner->type == BL_NPC){ + if(cd->owner->type == BL_NPC) { + const struct npc_data *nd = BL_UCCAST(BL_NPC, cd->owner); WFIFOL(fd, 30) = 1; WFIFOL(fd, 8) = 0; - memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH); + memcpy(WFIFOP(fd, 12), nd->name, NAME_LENGTH); for (i = 0; i < cd->users; i++) { WFIFOL(fd, 8+(i+1)*28) = 1; memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH); @@ -4163,11 +4170,12 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) { if (!vd || vd->class_ == INVISIBLE_CLASS) return; - /** - * Hide NPC from maya purple card. - **/ - if (bl->type == BL_NPC && ((struct npc_data *)bl)->chat_id == 0 && (((struct npc_data *)bl)->option&OPTION_INVISIBLE)) - return; + if (bl->type == BL_NPC) { + // Hide NPC from maya purple card. + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->chat_id == 0 && (nd->option&OPTION_INVISIBLE)) + return; + } if ( ( ud = unit->bl2ud(bl) ) && ud->walktimer != INVALID_TIMER ) clif->set_unit_walking(bl,sd,ud,SELF); @@ -4182,7 +4190,7 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) { switch (bl->type) { case BL_PC: { - struct map_session_data *tsd = (struct map_session_data *)bl; + struct map_session_data *tsd = BL_UCAST(BL_PC, bl); clif->getareachar_pc(sd, tsd); if (tsd->state.size == SZ_BIG) // tiny/big players [Valaris] clif->specialeffect_single(bl,423,sd->fd); @@ -4195,12 +4203,15 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) { } break; case BL_MER: // Devotion Effects - if (((struct mercenary_data *)bl)->devotion_flag) + { + struct mercenary_data *md = BL_UCAST(BL_MER, bl); + if (md->devotion_flag) clif->devotion(bl, sd); + } break; case BL_NPC: { - struct npc_data *nd = (struct npc_data *)bl; + struct npc_data *nd = BL_UCAST(BL_NPC, bl); if (nd->chat_id != 0) clif->dispchat(map->id2cd(nd->chat_id), sd->fd); if (nd->size == SZ_BIG) @@ -4211,7 +4222,7 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) { break; case BL_MOB: { - struct mob_data *md = (struct mob_data *)bl; + struct mob_data *md = BL_UCAST(BL_MOB, bl); if (md->special_state.size == SZ_BIG) // tiny/big mobs [Valaris] clif->specialeffect_single(bl,423,sd->fd); else if (md->special_state.size == SZ_MEDIUM) @@ -4231,7 +4242,7 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) { break; case BL_PET: if (vd->head_bottom) - clif->send_petdata(NULL, (struct pet_data *)bl, 3, vd->head_bottom); // needed to display pet equip properly + clif->send_petdata(NULL, BL_UCAST(BL_PET, bl), 3, vd->head_bottom); // needed to display pet equip properly break; } } @@ -5667,7 +5678,8 @@ void clif_resurrection(struct block_list *bl,int type) clif->send(buf,packet_len(0x148),bl, type == 1 ? AREA : AREA_WOS); if (disguised(bl)) { - if (((struct map_session_data *)bl)->fontcolor) { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + if (sd->fontcolor) { WBUFL(buf,2)=-bl->id; clif->send(buf,packet_len(0x148),bl, SELF); } else { @@ -8352,75 +8364,75 @@ void clif_charnameack (int fd, struct block_list *bl) switch( bl->type ) { case BL_PC: - { - struct map_session_data *ssd = (struct map_session_data *)bl; - struct party_data *p = NULL; - struct guild *g = NULL; - int ps = -1; - - //Requesting your own "shadow" name. [Skotlex] - if (ssd->fd == fd && ssd->disguise != -1) - WBUFL(buf,2) = -bl->id; - - if( ssd->fakename[0] ) { - WBUFW(buf, 0) = cmd = 0x195; - memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH); - WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0; - break; - } - memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH); + { + const struct map_session_data *ssd = BL_UCCAST(BL_PC, bl); + const struct party_data *p = NULL; + const struct guild *g = NULL; + int ps = -1; - if( ssd->status.party_id ) { - p = party->search(ssd->status.party_id); - } - if( ssd->status.guild_id ) { - if ((g = ssd->guild ) != NULL) { - int i; - ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id); - if( i < g->max_member ) ps = g->member[i].position; - } - } + //Requesting your own "shadow" name. [Skotlex] + if (ssd->fd == fd && ssd->disguise != -1) + WBUFL(buf,2) = -bl->id; + + if (ssd->fakename[0] != '\0') { + WBUFW(buf, 0) = cmd = 0x195; + memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH); + WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0; + break; + } + memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH); - if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild - p = NULL; + if (ssd->status.party_id != 0) { + p = party->search(ssd->status.party_id); + } + if (ssd->status.guild_id != 0) { + if ((g = ssd->guild) != NULL) { + int i; + ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id); + if (i < g->max_member) + ps = g->member[i].position; } + } - if (p == NULL && g == NULL) - break; + if (!battle_config.display_party_name && g == NULL) { + // do not display party unless the player is also in a guild + p = NULL; + } - WBUFW(buf, 0) = cmd = 0x195; - if (p) - memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH); - else - WBUFB(buf,30) = 0; + if (p == NULL && g == NULL) + break; - if (g && ps >= 0 && ps < MAX_GUILDPOSITION) - { - memcpy(WBUFP(buf,54), g->name,NAME_LENGTH); - memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH); - } else { //Assume no guild. - WBUFB(buf,54) = 0; - WBUFB(buf,78) = 0; - } + WBUFW(buf, 0) = cmd = 0x195; + if (p != NULL) + memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH); + else + WBUFB(buf,30) = 0; + + if (g != NULL && ps >= 0 && ps < MAX_GUILDPOSITION) { + memcpy(WBUFP(buf,54), g->name,NAME_LENGTH); + memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH); + } else { //Assume no guild. + WBUFB(buf,54) = 0; + WBUFB(buf,78) = 0; } + } break; //[blackhole89] case BL_HOM: - memcpy(WBUFP(buf,6), ((struct homun_data *)bl)->homunculus.name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_HOM, bl)->homunculus.name, NAME_LENGTH); break; case BL_MER: - memcpy(WBUFP(buf,6), ((struct mercenary_data *)bl)->db->name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_MER, bl)->db->name, NAME_LENGTH); break; case BL_PET: - memcpy(WBUFP(buf,6), ((struct pet_data *)bl)->pet.name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_PET, bl)->pet.name, NAME_LENGTH); break; case BL_NPC: - memcpy(WBUFP(buf,6), ((struct npc_data *)bl)->name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_NPC, bl)->name, NAME_LENGTH); break; case BL_MOB: { - struct mob_data *md = (struct mob_data *)bl; - nullpo_retv(md); + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); memcpy(WBUFP(buf,6), md->name, NAME_LENGTH); if (md->guardian_data && md->guardian_data->g) { @@ -8450,12 +8462,12 @@ void clif_charnameack (int fd, struct block_list *bl) break; case BL_CHAT: #if 0 //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex] - memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_CHAT, bl)->title, NAME_LENGTH); break; #endif return; case BL_ELEM: - memcpy(WBUFP(buf,6), ((struct elemental_data *)bl)->db->name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_ELEM, bl)->db->name, NAME_LENGTH); break; default: ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id); @@ -9885,7 +9897,7 @@ void clif_changed_dir(struct block_list *bl, enum send_target target) nullpo_retv(bl); WBUFW(buf,0) = 0x9c; WBUFL(buf,2) = bl->id; - WBUFW(buf,6) = bl->type == BL_PC ? ((struct map_session_data *)bl)->head_dir : 0; + WBUFW(buf,6) = bl->type == BL_PC ? BL_UCCAST(BL_PC, bl)->head_dir : 0; WBUFB(buf,8) = unit->getdir(bl); clif->send(buf, packet_len(0x9c), bl, target); @@ -10484,7 +10496,7 @@ void clif_parse_NpcClicked(int fd,struct map_session_data *sd) break; } if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt) - npc->click(sd, (struct npc_data *)bl); + npc->click(sd, BL_UCAST(BL_NPC, bl)); break; } } @@ -13214,7 +13226,7 @@ void clif_parse_GMKick(int fd, struct map_session_data *sd) { case BL_NPC: { - struct npc_data* nd = (struct npc_data *)target; + struct npc_data *nd = BL_UCAST(BL_NPC, target); if( !pc->can_use_command(sd, "@unloadnpc")) { clif->GM_kickack(sd, 0); return; @@ -17598,7 +17610,7 @@ void clif_status_change_end(struct block_list *bl, int tid, enum send_target tar nullpo_retv(bl); - if (bl->type == BL_PC && !((struct map_session_data *)bl)->state.active) + if (bl->type == BL_PC && !BL_UCAST(BL_PC, bl)->state.active) return; p.PacketType = status_change_endType; diff --git a/src/map/map.c b/src/map/map.c index e17d18a1a..79c314aae 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -333,7 +333,7 @@ int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) { sc->data[SC_PROPERTYWALK]->val3 >= skill->get_maxcount(sc->data[SC_PROPERTYWALK]->val1,sc->data[SC_PROPERTYWALK]->val2) ) status_change_end(bl,SC_PROPERTYWALK,INVALID_TIMER); } else if (bl->type == BL_NPC) { - npc->unsetcells((struct npc_data *)bl); + npc->unsetcells(BL_UCAST(BL_NPC, bl)); } if (moveblock) map->delblock(bl); @@ -405,7 +405,7 @@ int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) { } } } else if (bl->type == BL_NPC) { - npc->setcells((struct npc_data *)bl); + npc->setcells(BL_UCAST(BL_NPC, bl)); } return 0; @@ -487,7 +487,7 @@ struct skill_unit* map_find_skill_unit_oncell(struct block_list* target,int16 x, if (bl->x != x || bl->y != y || bl->type != BL_SKILL) continue; - su = (struct skill_unit *) bl; + su = BL_UCAST(BL_SKILL, bl); if( su == out_unit || !su->alive || !su->group || su->group->skill_id != skill_id ) continue; if( !(flag&1) || battle->check_target(&su->bl,target,su->group->target_flag) > 0 ) @@ -1742,11 +1742,11 @@ void map_addiddb(struct block_list *bl) nullpo_retv(bl); if (bl->type == BL_PC) { - struct map_session_data *sd = (struct map_session_data *)bl; + struct map_session_data *sd = BL_UCAST(BL_PC, bl); idb_put(map->pc_db,sd->bl.id,sd); idb_put(map->charid_db,sd->status.char_id,sd); } else if (bl->type == BL_MOB) { - struct mob_data* md = (struct mob_data*)bl; + struct mob_data *md = BL_UCAST(BL_MOB, bl); idb_put(map->mobid_db,bl->id,bl); if( md->state.boss ) @@ -1767,7 +1767,7 @@ void map_deliddb(struct block_list *bl) nullpo_retv(bl); if (bl->type == BL_PC) { - struct map_session_data *sd = (struct map_session_data *)bl; + struct map_session_data *sd = BL_UCAST(BL_PC, bl); idb_remove(map->pc_db,sd->bl.id); idb_remove(map->charid_db,sd->status.char_id); } else if (bl->type == BL_MOB) { @@ -2283,8 +2283,8 @@ void map_vforeachnpc(int (*func)(struct npc_data* nd, va_list args), va_list arg iter = db_iterator(map->id_db); for (bl = dbi_first(iter); dbi_exists(iter); bl = dbi_next(iter)) { - if( bl->type == BL_NPC ) { - struct npc_data* nd = (struct npc_data*)bl; + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); va_list argscopy; int ret; diff --git a/src/map/mob.c b/src/map/mob.c index 338d886ca..708a2900b 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1576,7 +1576,7 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { //Target exists, attack or loot as applicable. if (tbl->type == BL_ITEM) { //Loot time. - struct flooritem_data *fitem; + struct flooritem_data *fitem = BL_UCAST(BL_ITEM, tbl); if (md->ud.target == tbl->id && md->ud.walktimer != INVALID_TIMER) return true; //Already locked. if (md->lootitem == NULL) { @@ -1602,7 +1602,6 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { if (md->ud.attacktimer != INVALID_TIMER) return true; //Busy attacking? - fitem = (struct flooritem_data *)tbl; //Logs items, taken by (L)ooter Mobs [Lupus] logs->pick_mob(md, LOG_TYPE_LOOT, fitem->item_data.amount, &fitem->item_data, NULL); @@ -1947,7 +1946,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) { case BL_PC: { - struct map_session_data *sd = (struct map_session_data *)src; + const struct map_session_data *sd = BL_UCCAST(BL_PC, src); char_id = sd->status.char_id; if( damage ) md->attacked_id = src->id; @@ -1955,7 +1954,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_HOM: { - struct homun_data *hd = (struct homun_data *)src; + const struct homun_data *hd = BL_UCCAST(BL_HOM, src); flag = MDLF_HOMUN; if( hd->master ) char_id = hd->master->status.char_id; @@ -1965,7 +1964,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_MER: { - struct mercenary_data *mer = (struct mercenary_data *)src; + const struct mercenary_data *mer = BL_UCCAST(BL_MER, src); if( mer->master ) char_id = mer->master->status.char_id; if( damage ) @@ -1974,7 +1973,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_PET: { - struct pet_data *pd = (struct pet_data *)src; + const struct pet_data *pd = BL_UCCAST(BL_PET, src); flag = MDLF_PET; if( pd->msd ) { @@ -1986,7 +1985,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_MOB: { - struct mob_data* md2 = (struct mob_data *)src; + const struct mob_data *md2 = BL_UCCAST(BL_MOB, src); if (md2->special_state.ai != AI_NONE && md2->master_id) { struct map_session_data* msd = map->id2sd(md2->master_id); if( msd ) @@ -2003,7 +2002,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_ELEM: { - struct elemental_data *ele = (struct elemental_data *)src; + const struct elemental_data *ele = BL_UCCAST(BL_ELEM, src); if( ele->master ) char_id = ele->master->status.char_id; if( damage ) @@ -2100,14 +2099,15 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) { *------------------------------------------*/ int mob_dead(struct mob_data *md, struct block_list *src, int type) { struct status_data *mstatus; - struct map_session_data *sd = NULL, *tmpsd[DAMAGELOG_SIZE]; + struct map_session_data *sd = NULL; + struct map_session_data *tmpsd[DAMAGELOG_SIZE] = { NULL }; struct map_session_data *mvp_sd = NULL, *second_sd = NULL, *third_sd = NULL; struct { struct party_data *p; int id,zeny; unsigned int base_exp,job_exp; - } pt[DAMAGELOG_SIZE]; + } pt[DAMAGELOG_SIZE] = { { 0 } }; int i, temp, count, m = md->bl.m; int dmgbltypes = 0; // bitfield of all bl types, that caused damage to the mob and are eligible for exp distribution unsigned int mvp_damage; @@ -2133,13 +2133,10 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) { map->freeblock_lock(); - memset(pt,0,sizeof(pt)); - - if(src && src->type == BL_MOB) - mob->unlocktarget((struct mob_data *)src,tick); + if (src != NULL && src->type == BL_MOB) + mob->unlocktarget(BL_UCAST(BL_MOB, src), tick); // filter out entries not eligible for exp distribution - memset(tmpsd,0,sizeof(tmpsd)); for(i = 0, count = 0, mvp_damage = 0; i < DAMAGELOG_SIZE && md->dmglog[i].id; i++) { struct map_session_data* tsd = map->charid2sd(md->dmglog[i].id); @@ -2584,10 +2581,10 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) { md->status.hp = 0; //So that npc_event invoked functions KNOW that mob is dead if( src ) { switch( src->type ) { - case BL_PET: sd = ((struct pet_data *)src)->msd; break; - case BL_HOM: sd = ((struct homun_data *)src)->master; break; - case BL_MER: sd = ((struct mercenary_data *)src)->master; break; - case BL_ELEM: sd = ((struct elemental_data *)src)->master; break; + case BL_PET: sd = BL_UCAST(BL_PET, src)->msd; break; + case BL_HOM: sd = BL_UCAST(BL_HOM, src)->master; break; + case BL_MER: sd = BL_UCAST(BL_MER, src)->master; break; + case BL_ELEM: sd = BL_UCAST(BL_ELEM, src)->master; break; } } diff --git a/src/map/npc.c b/src/map/npc.c index 11e4da147..6d495e531 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1637,10 +1637,9 @@ void npc_trader_update(int master) { iter = db_iterator(map->id_db); for (bl = dbi_first(iter); dbi_exists(iter); bl = dbi_next(iter)) { - if( bl->type == BL_NPC ) { - struct npc_data* nd = (struct npc_data*)bl; - - if( nd->src_id == master ) { + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->src_id == master) { nd->u.scr.shop = master_nd->u.scr.shop; } } @@ -4679,7 +4678,7 @@ int npc_reload(void) { switch(bl->type) { case BL_NPC: if( bl->id != npc->fake_nd->bl.id )// don't remove fake_nd - npc->unload((struct npc_data *)bl, false); + npc->unload(BL_UCAST(BL_NPC, bl), false); break; case BL_MOB: unit->free(bl,CLR_OUTSIGHT); diff --git a/src/map/pc.c b/src/map/pc.c index d1cd0592c..960001d37 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -7606,11 +7606,11 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) { if (sd->charm_type != CHARM_TYPE_NONE && sd->charm_count > 0) pc->del_charm(sd, sd->charm_count, sd->charm_type); - if (src) { + if (src != NULL) { switch (src->type) { case BL_MOB: { - struct mob_data *md=(struct mob_data *)src; + struct mob_data *md = BL_UCAST(BL_MOB, src); if (md->target_id==sd->bl.id) mob->unlocktarget(md,tick); if (battle_config.mobs_level_up && md->status.hp @@ -7632,19 +7632,19 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) { } break; case BL_PET: //Pass on to master... - src = &((struct pet_data *)src)->msd->bl; + src = &BL_UCAST(BL_PET, src)->msd->bl; break; case BL_HOM: - src = &((struct homun_data *)src)->master->bl; + src = &BL_UCAST(BL_HOM, src)->master->bl; break; case BL_MER: - src = &((struct mercenary_data *)src)->master->bl; + src = &BL_UCAST(BL_MER, src)->master->bl; break; } } - if (src && src->type == BL_PC) { - struct map_session_data *ssd = (struct map_session_data *)src; + if (src != NULL && src->type == BL_PC) { + struct map_session_data *ssd = BL_UCAST(BL_PC, src); pc->setparam(ssd, SP_KILLEDRID, sd->bl.id); npc->script_event(ssd, NPCE_KILLPC); @@ -7830,9 +7830,8 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) { if( map->list[sd->bl.m].flag.pvp && !battle_config.pk_mode && !map->list[sd->bl.m].flag.pvp_nocalcrank ) { sd->pvp_point -= 5; sd->pvp_lost++; - if( src && src->type == BL_PC ) - { - struct map_session_data *ssd = (struct map_session_data *)src; + if (src != NULL && src->type == BL_PC) { + struct map_session_data *ssd = BL_UCAST(BL_PC, src); ssd->pvp_point++; ssd->pvp_won++; } diff --git a/src/map/pet.c b/src/map/pet.c index 8726b611b..501dc8c27 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -937,7 +937,7 @@ int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, int64 tick pet->unlocktarget(pd); return 0; } else{ - struct flooritem_data *fitem = (struct flooritem_data *)target; + struct flooritem_data *fitem = BL_UCAST(BL_ITEM, target); if(pd->loot->count < pd->loot->max){ memcpy(&pd->loot->item[pd->loot->count++],&fitem->item_data,sizeof(pd->loot->item[0])); pd->loot->weight += itemdb_weight(fitem->item_data.nameid)*fitem->item_data.amount; diff --git a/src/map/script.c b/src/map/script.c index 4466d79f1..7581531da 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -226,10 +226,13 @@ void script_reportsrc(struct script_state *st) { switch( bl->type ) { case BL_NPC: - if( bl->m >= 0 ) - ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map->list[bl->m].name, bl->x, bl->y); + { + const struct npc_data *nd = BL_UCCAST(BL_NPC, bl); + if (bl->m >= 0) + ShowDebug("Source (NPC): %s at %s (%d,%d)\n", nd->name, map->list[bl->m].name, bl->x, bl->y); else - ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name); + ShowDebug("Source (NPC): %s (invisible/not on a map)\n", nd->name); + } break; default: if( bl->m >= 0 ) @@ -13613,7 +13616,7 @@ BUILDIN(atcommand) struct block_list* bl = map->id2bl(st->oid); memcpy(&sd->bl, bl, sizeof(struct block_list)); if (bl->type == BL_NPC) - safestrncpy(sd->status.name, ((struct npc_data *)bl)->name, NAME_LENGTH); + safestrncpy(sd->status.name, BL_UCAST(BL_NPC, bl)->name, NAME_LENGTH); } } @@ -16428,17 +16431,18 @@ BUILDIN(searchitem) } // [zBuffer] List of player cont commands ---> -BUILDIN(rid2name) { +BUILDIN(rid2name) +{ struct block_list *bl = NULL; int rid = script_getnum(st,2); if((bl = map->id2bl(rid))) { switch(bl->type) { - case BL_MOB: script_pushstrcopy(st, ((struct mob_data *)bl)->name); break; - case BL_PC: script_pushstrcopy(st, ((struct map_session_data *)bl)->status.name); break; - case BL_NPC: script_pushstrcopy(st, ((struct npc_data *)bl)->exname); break; - case BL_PET: script_pushstrcopy(st, ((struct pet_data *)bl)->pet.name); break; - case BL_HOM: script_pushstrcopy(st, ((struct homun_data *)bl)->homunculus.name); break; - case BL_MER: script_pushstrcopy(st, ((struct mercenary_data *)bl)->db->name); break; + case BL_MOB: script_pushstrcopy(st, BL_UCCAST(BL_MOB, bl)->name); break; + case BL_PC: script_pushstrcopy(st, BL_UCCAST(BL_PC, bl)->status.name); break; + case BL_NPC: script_pushstrcopy(st, BL_UCCAST(BL_NPC, bl)->exname); break; + case BL_PET: script_pushstrcopy(st, BL_UCCAST(BL_PET, bl)->pet.name); break; + case BL_HOM: script_pushstrcopy(st, BL_UCCAST(BL_HOM, bl)->homunculus.name); break; + case BL_MER: script_pushstrcopy(st, BL_UCCAST(BL_MER, bl)->db->name); break; default: ShowError("buildin_rid2name: BL type unknown.\n"); script_pushconststr(st,""); @@ -16654,14 +16658,14 @@ BUILDIN(unitattack) { switch( unit_bl->type ) { case BL_PC: - clif->pActionRequest_sub((struct map_session_data *)unit_bl, actiontype > 0 ? 0x07 : 0x00, target_bl->id, timer->gettick()); + clif->pActionRequest_sub(BL_UCAST(BL_PC, unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, timer->gettick()); script_pushint(st, 1); return true; case BL_MOB: - ((struct mob_data *)unit_bl)->target_id = target_bl->id; + BL_UCAST(BL_MOB, unit_bl)->target_id = target_bl->id; break; case BL_PET: - ((struct pet_data *)unit_bl)->target_id = target_bl->id; + BL_UCAST(BL_PET, unit_bl)->target_id = target_bl->id; break; default: ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type); @@ -16687,7 +16691,7 @@ BUILDIN(unitstop) { unit->stop_attack(bl); unit->stop_walking(bl, STOPWALKING_FLAG_NEXTCELL); if( bl->type == BL_MOB ) - ((struct mob_data *)bl)->target_id = 0; + BL_UCAST(BL_MOB, bl)->target_id = 0; } return true; @@ -16753,12 +16757,13 @@ BUILDIN(unitskilluseid) { bl = map->id2bl(unit_id); - if( bl != NULL ) { - if( bl->type == BL_NPC ) { - if (((struct npc_data *)bl)->status.hp == 0) { - status_calc_npc((struct npc_data *)bl, SCO_FIRST); + if (bl != NULL) { + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->status.hp == 0) { + status_calc_npc(nd, SCO_FIRST); } else { - status_calc_npc((struct npc_data *)bl, SCO_NONE); + status_calc_npc(nd, SCO_NONE); } } unit->skilluse_id(bl, target_id, skill_id, skill_lv); @@ -16787,12 +16792,13 @@ BUILDIN(unitskillusepos) { bl = map->id2bl(unit_id); - if( bl != NULL ) { - if( bl->type == BL_NPC ) { - if (((struct npc_data*)bl)->status.hp == 0) { - status_calc_npc((struct npc_data *)bl, SCO_FIRST); + if (bl != NULL) { + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->status.hp == 0) { + status_calc_npc(nd, SCO_FIRST); } else { - status_calc_npc((struct npc_data *)bl, SCO_NONE); + status_calc_npc(nd, SCO_NONE); } } unit->skilluse_pos(bl, skill_x, skill_y, skill_id, skill_lv); @@ -18708,7 +18714,7 @@ BUILDIN(useatcmd) { struct block_list* bl = map->id2bl(st->oid); memcpy(&sd->bl, bl, sizeof(struct block_list)); if (bl->type == BL_NPC) - safestrncpy(sd->status.name, ((struct npc_data *)bl)->name, NAME_LENGTH); + safestrncpy(sd->status.name, BL_UCAST(BL_NPC, bl)->name, NAME_LENGTH); } } diff --git a/src/map/skill.c b/src/map/skill.c index 1de4baff6..4632ca541 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -383,7 +383,7 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk #endif // RENEWAL if (sd && (skill2_lv = pc->checkskill(sd, HP_MEDITATIO)) > 0) hp += hp * skill2_lv * 2 / 100; - else if (src->type == BL_HOM && (skill2_lv = homun->checkskill(((struct homun_data *)src), HLIF_BRAIN)) > 0) + else if (src->type == BL_HOM && (skill2_lv = homun->checkskill(BL_UCAST(BL_HOM, src), HLIF_BRAIN)) > 0) hp += hp * skill2_lv * 2 / 100; break; } @@ -1766,7 +1766,7 @@ int skill_counter_additional_effect(struct block_list* src, struct block_list *b case HFLI_SBR44: // [orn] case HVAN_EXPLOSION: if (src->type == BL_HOM) { - struct homun_data *hd = (struct homun_data *)src; + struct homun_data *hd = BL_UCAST(BL_HOM, src); hd->homunculus.intimacy = 200; if (hd->master) clif->send_homdata(hd->master,SP_INTIMATE,hd->homunculus.intimacy/100); @@ -2073,9 +2073,9 @@ int skill_strip_equip(struct block_list *bl, unsigned short where, int rate, int - if 'flag&0x1', position update packets must not be sent. - if 'flag&0x2', skill blown ignores players' special_state.no_knockback -------------------------------------------------------------------------*/ -int skill_blown(struct block_list* src, struct block_list* target, int count, int8 dir, int flag) { +int skill_blown(struct block_list* src, struct block_list* target, int count, int8 dir, int flag) +{ int dx = 0, dy = 0; - struct skill_unit* su = NULL; nullpo_ret(src); @@ -2085,26 +2085,30 @@ int skill_blown(struct block_list* src, struct block_list* target, int count, in return 0; // Actual knockback distance is 0. switch (target->type) { - case BL_MOB: { - struct mob_data* md = BL_CAST(BL_MOB, target); - if (md->class_ == MOBID_EMPELIUM) - return 0; - if(src != target && is_boss(target)) // Bosses can't be knocked-back - return 0; - } + case BL_MOB: + { + const struct mob_data *md = BL_UCCAST(BL_MOB, target); + if (md->class_ == MOBID_EMPELIUM) + return 0; + if (src != target && is_boss(target)) // Bosses can't be knocked-back + return 0; + } break; - case BL_PC: { - struct map_session_data *sd = BL_CAST(BL_PC, target); - if( sd->sc.data[SC_BASILICA] && sd->sc.data[SC_BASILICA]->val4 == sd->bl.id && !is_boss(src)) - return 0; // Basilica caster can't be knocked-back by normal monsters. - if( !(flag&0x2) && src != target && sd->special_state.no_knockback ) - return 0; - } + case BL_PC: + { + struct map_session_data *sd = BL_UCAST(BL_PC, target); + if (sd->sc.data[SC_BASILICA] && sd->sc.data[SC_BASILICA]->val4 == sd->bl.id && !is_boss(src)) + return 0; // Basilica caster can't be knocked-back by normal monsters. + if (!(flag&0x2) && src != target && sd->special_state.no_knockback) + return 0; + } break; case BL_SKILL: - su = (struct skill_unit *)target; - if( su->group && (su->group->unit_id == UNT_ANKLESNARE || su->group->unit_id == UNT_REVERBERATION)) + { + struct skill_unit *su = BL_UCAST(BL_SKILL, target); + if (su->group && (su->group->unit_id == UNT_ANKLESNARE || su->group->unit_id == UNT_REVERBERATION)) return 0; // ankle snare cannot be knocked back + } break; } @@ -2232,7 +2236,7 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr //Skotlex: Adjusted to the new system if (src->type == BL_PET) { // [Valaris] - struct pet_data *pd = (struct pet_data *)src; + struct pet_data *pd = BL_UCAST(BL_PET, src); if (pd->a_skill && pd->a_skill->div_ && pd->a_skill->id == skill_id) { int element = skill->get_ele(skill_id, skill_lv); /*if (skill_id == -1) Does it ever worked? @@ -2876,8 +2880,8 @@ void skill_attack_combo2_unknown(int *attack_type, struct block_list* src, struc void 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) { if (*flag & SD_ANIMATION && dmg->div_ < 2) //Disabling skill animation doesn't works on multi-hit. *type = BDT_SPLASH; - if (bl->type == BL_SKILL ) { - struct skill_unit *su = (struct skill_unit *)bl; + if (bl->type == BL_SKILL) { + struct skill_unit *su = BL_UCAST(BL_SKILL, bl); if (su->group && skill->get_inf2(su->group->skill_id) & INF2_TRAP) // show damage on trap targets clif->skill_damage(src, bl, *tick, dmg->amotion, dmg->dmotion, *damage, dmg->div_, *skill_id, (*flag & SD_LEVEL) ? -1 : *skill_lv, BDT_SPLASH); } @@ -2895,7 +2899,7 @@ int skill_attack_dir_unknown(int *attack_type, struct block_list* src, struct bl 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) { skill->blown(dsrc, bl, dmg->blewcount, *dir, 0x0); if (!dmg->blewcount && bl->type == BL_SKILL && *damage > 0){ - struct skill_unit *su = (struct skill_unit *)bl; + 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); } @@ -3095,8 +3099,8 @@ int skill_check_condition_mercenary(struct block_list *bl, int skill_id, int lv, nullpo_ret(bl); switch( bl->type ) { - case BL_HOM: sd = ((struct homun_data *)bl)->master; break; - case BL_MER: sd = ((struct mercenary_data *)bl)->master; break; + case BL_HOM: sd = BL_UCAST(BL_HOM, bl)->master; break; + case BL_MER: sd = BL_UCAST(BL_MER, bl)->master; break; } st = status->get_status_data(bl); @@ -3326,9 +3330,9 @@ int skill_timerskill(int tid, int64 tick, int id, intptr_t data) { break; case LG_MOONSLASHER: case SR_WINDMILL: - if( target->type == BL_PC ) { - struct map_session_data *tsd = NULL; - if ((tsd = (struct map_session_data *)target) != NULL && !pc_issit(tsd)) { + if (target->type == BL_PC) { + struct map_session_data *tsd = BL_UCAST(BL_PC, target); + if (!pc_issit(tsd)) { pc_setsit(tsd); skill->sit(tsd,1); clif->sitting(&tsd->bl); @@ -3347,11 +3351,12 @@ int skill_timerskill(int tid, int64 tick, int id, intptr_t data) { case SR_FALLENEMPIRE: case SR_TIGERCANNON: case SR_SKYNETBLOW: - if( src->type == BL_PC ) { + if (src->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, src); if( distance_xy(src->x, src->y, target->x, target->y) >= 3 ) break; - skill->castend_damage_id(src, target, skl->skill_id, pc->checkskill((struct map_session_data *)src, skl->skill_id), tick, 0); + skill->castend_damage_id(src, target, skl->skill_id, pc->checkskill(sd, skl->skill_id), tick, 0); } break; case SC_ESCAPE: @@ -3362,12 +3367,14 @@ int skill_timerskill(int tid, int64 tick, int id, intptr_t data) { } break; case RK_HUNDREDSPEAR: - if(src->type == BL_PC) { - int skill_lv = pc->checkskill((struct map_session_data *)src, KN_SPEARBOOMERANG); - if(skill_lv > 0) + if (src->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, src); + int skill_lv = pc->checkskill(sd, KN_SPEARBOOMERANG); + if (skill_lv > 0) skill->attack(BF_WEAPON, src, src, target, KN_SPEARBOOMERANG, skill_lv, tick, skl->flag); - } else + } else { skill->attack(BF_WEAPON, src, src, target, KN_SPEARBOOMERANG, 1, tick, skl->flag); + } break; case CH_PALMSTRIKE: { @@ -5014,7 +5021,7 @@ int skill_castend_id(int tid, int64 tick, int id, intptr_t data) { } if (ud->skill_id >= SL_SKE && ud->skill_id <= SL_SKA && target->type == BL_MOB) { - if (((struct mob_data *)target)->class_ == MOBID_EMPELIUM) + if (BL_UCCAST(BL_MOB, target)->class_ == MOBID_EMPELIUM) break; } else if (inf && battle->check_target(src, target, inf) <= 0) { if (sd) clif->skill_fail(sd,ud->skill_id,USESKILL_FAIL_LEVEL,0); @@ -5597,8 +5604,8 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin if (ud->target) target_id = ud->target; else switch (src->type) { - case BL_MOB: target_id = ((struct mob_data *)src)->target_id; break; - case BL_PET: target_id = ((struct pet_data *)src)->target_id; break; + case BL_MOB: target_id = BL_UCAST(BL_MOB, src)->target_id; break; + case BL_PET: target_id = BL_UCAST(BL_PET, src)->target_id; break; } if (!target_id) break; @@ -5832,7 +5839,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin if( sd ) skill->blockpc_start(sd, skill_id, skill->get_time(skill_id, skill_lv)); else if( bl->type == BL_MER ) - skill->blockmerc_start((struct mercenary_data *)bl, skill_id, skill->get_time(skill_id, skill_lv)); + skill->blockmerc_start(BL_UCAST(BL_MER, bl), skill_id, skill->get_time(skill_id, skill_lv)); break; case TK_JUMPKICK: @@ -7516,10 +7523,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin break; case HT_SPRINGTRAP: clif->skill_nodamage(src,bl,skill_id,skill_lv,1); - { - struct skill_unit *su=NULL; - if (bl->type==BL_SKILL && (su=(struct skill_unit *)bl) != NULL && su->group != NULL) { - switch(su->group->unit_id){ + if (bl->type == BL_SKILL) { + struct skill_unit *su = BL_UCAST(BL_SKILL, bl); + if (su->group != NULL) { + switch (su->group->unit_id) { case UNT_ANKLESNARE: if (su->group->val2 != 0) // if it is already trapping something don't spring it, @@ -9017,8 +9024,8 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin if( flag&1 ) { if( is_boss(bl) ) break; if( sc_start2(src,bl, type, 100, skill_lv, src->id, skill->get_time(skill_id, skill_lv))) { - if( bl->type == BL_MOB ) - mob->unlocktarget((struct mob_data *)bl, timer->gettick()); + if (bl->type == BL_MOB) + mob->unlocktarget(BL_UCAST(BL_MOB, bl), timer->gettick()); unit->stop_attack(bl); clif->bladestop(src, bl->id, 1); map->freeblock_unlock(); @@ -9283,11 +9290,13 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin unit->skilluse_id(src, bl->id, improv_skill_id, improv_skill_lv); } else { int target_id = 0; - if (ud->target) + if (ud->target) { target_id = ud->target; - else switch (src->type) { - case BL_MOB: target_id = ((struct mob_data *)src)->target_id; break; - case BL_PET: target_id = ((struct pet_data *)src)->target_id; break; + } else { + switch (src->type) { + case BL_MOB: target_id = BL_UCAST(BL_MOB, src)->target_id; break; + case BL_PET: target_id = BL_UCAST(BL_PET, src)->target_id; break; + } } if (!target_id) break; @@ -11694,11 +11703,9 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl, int64 tick case UNT_WARP_WAITING: { int working = sg->val1&0xffff; - if(bl->type==BL_PC && !working){ - struct map_session_data *sd = (struct map_session_data *)bl; - if((!sd->chatID || battle_config.chat_warpportal) - && sd->ud.to_x == src->bl.x && sd->ud.to_y == src->bl.y) - { + if (bl->type == BL_PC && !working) { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + if ((!sd->chatID || battle_config.chat_warpportal) && sd->ud.to_x == src->bl.x && sd->ud.to_y == src->bl.y) { int x = sg->val2>>16; int y = sg->val2&0xffff; int count = sg->val1>>16; @@ -12587,7 +12594,7 @@ int skill_unit_onplace_timer(struct skill_unit *src, struct block_list *bl, int6 } if (bl->type == BL_MOB && ss != bl) - mob->skill_event((struct mob_data *)bl, ss, tick, MSC_SKILLUSED|(skill_id<<16)); + mob->skill_event(BL_UCAST(BL_MOB, bl), ss, tick, MSC_SKILLUSED|(skill_id<<16)); return skill_id; } @@ -17677,9 +17684,10 @@ void skill_toggle_magicpower(struct block_list *bl, uint16 skill_id) { sc->data[SC_MAGICPOWER]->val4 = 1; status_calc_bl(bl, status->sc2scb_flag(SC_MAGICPOWER)); #ifndef RENEWAL - if(bl->type == BL_PC){// update current display. - clif->updatestatus((struct map_session_data *)bl, SP_MATK1); - clif->updatestatus((struct map_session_data *)bl, SP_MATK2); + if (bl->type == BL_PC) {// update current display. + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + clif->updatestatus(sd, SP_MATK1); + clif->updatestatus(sd, SP_MATK2); } #endif } diff --git a/src/map/status.c b/src/map/status.c index 03167d058..a4cb85d66 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -1310,7 +1310,7 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp, } if (target->type == BL_SKILL) - return skill->unit_ondamaged((struct skill_unit *)target, src, hp, timer->gettick()); + return skill->unit_ondamaged(BL_UCAST(BL_SKILL, target), src, hp, timer->gettick()); st = status->get_status_data(target); if( st == &status->dummy ) @@ -1416,14 +1416,14 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp, } switch (target->type) { - case BL_PC: pc->damage((struct map_session_data *)target, src, hp, sp); break; - case BL_MOB: mob->damage((struct mob_data *)target, src, hp); break; - case BL_HOM: homun->damaged((struct homun_data *)target); break; - case BL_MER: mercenary->heal((struct mercenary_data *)target, hp, sp); break; - case BL_ELEM: elemental->heal((struct elemental_data *)target, hp, sp); break; + case BL_PC: pc->damage(BL_UCAST(BL_PC, target), src, hp, sp); break; + case BL_MOB: mob->damage(BL_UCAST(BL_MOB, target), src, hp); break; + case BL_HOM: homun->damaged(BL_UCAST(BL_HOM, target)); break; + case BL_MER: mercenary->heal(BL_UCAST(BL_MER, target), hp, sp); break; + case BL_ELEM: elemental->heal(BL_UCAST(BL_ELEM, target), hp, sp); break; } - if (src != NULL && target->type == BL_PC && ((struct map_session_data *)target)->disguise > 0) { + if (src != NULL && target->type == BL_PC && BL_UCAST(BL_PC, target)->disguise > 0) { // stop walking when attacked in disguise to prevent walk-delay bug unit->stop_walking(target, STOPWALKING_FLAG_FIXPOS); } @@ -1442,11 +1442,11 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp, //&2: Also remove object from map. //&4: Also delete object from memory. switch (target->type) { - case BL_PC: flag = pc->dead((struct map_session_data *)target, src); break; - case BL_MOB: flag = mob->dead((struct mob_data *)target, src, (flag&4) ? 3 : 0); break; - case BL_HOM: flag = homun->dead((struct homun_data *)target); break; - case BL_MER: flag = mercenary->dead((struct mercenary_data *)target); break; - case BL_ELEM: flag = elemental->dead((struct elemental_data *)target); break; + case BL_PC: flag = pc->dead(BL_UCAST(BL_PC, target), src); break; + case BL_MOB: flag = mob->dead(BL_UCAST(BL_MOB, target), src, (flag&4) ? 3 : 0); break; + case BL_HOM: flag = homun->dead(BL_UCAST(BL_HOM, target)); break; + case BL_MER: flag = mercenary->dead(BL_UCAST(BL_MER, target)); break; + case BL_ELEM: flag = elemental->dead(BL_UCAST(BL_ELEM, target)); break; default: //Unhandled case, do nothing to object. flag = 0; break; @@ -1486,18 +1486,21 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp, sc_start(target,target,status->skill2sc(PR_KYRIE),100,10,time); if( target->type == BL_MOB ) - ((struct mob_data *)target)->state.rebirth = 1; + BL_UCAST(BL_MOB, target)->state.rebirth = 1; return (int)(hp+sp); } - if (target->type == BL_MOB && sc && sc->data[SC_REBIRTH] && !((struct mob_data *) target)->state.rebirth) { - // Ensure the monster has not already rebirthed before doing so. - status->revive(target, sc->data[SC_REBIRTH]->val2, 0); - status->change_clear(target,0); - ((struct mob_data *)target)->state.rebirth = 1; + if (target->type == BL_MOB && sc != NULL && sc->data[SC_REBIRTH] != NULL) { + struct mob_data *t_md = BL_UCAST(BL_MOB, target); + if (!t_md->state.rebirth) { + // Ensure the monster has not already reborn before doing so. + status->revive(target, sc->data[SC_REBIRTH]->val2, 0); + status->change_clear(target,0); + t_md->state.rebirth = 1; - return (int)(hp+sp); + return (int)(hp+sp); + } } status->change_clear(target,0); @@ -1582,11 +1585,11 @@ int status_heal(struct block_list *bl,int64 in_hp,int64 in_sp, int flag) { // send hp update to client switch(bl->type) { - case BL_PC: pc->heal((struct map_session_data *)bl,hp,sp,(flag&2) ? 1 : 0); break; - case BL_MOB: mob->heal((struct mob_data *)bl,hp); break; - case BL_HOM: homun->healed((struct homun_data *)bl); break; - case BL_MER: mercenary->heal((struct mercenary_data *)bl,hp,sp); break; - case BL_ELEM: elemental->heal((struct elemental_data *)bl,hp,sp); break; + case BL_PC: pc->heal(BL_UCAST(BL_PC, bl), hp, sp, (flag&2) ? 1 : 0); break; + case BL_MOB: mob->heal(BL_UCAST(BL_MOB, bl), hp); break; + case BL_HOM: homun->healed(BL_UCAST(BL_HOM, bl)); break; + case BL_MER: mercenary->heal(BL_UCAST(BL_MER, bl), hp, sp); break; + case BL_ELEM: elemental->heal(BL_UCAST(BL_ELEM, bl), hp, sp); break; } return (int)(hp+sp); @@ -1679,9 +1682,9 @@ int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per clif->resurrection(bl, 1); switch (bl->type) { - case BL_PC: pc->revive((struct map_session_data *)bl, hp, sp); break; - case BL_MOB: mob->revive((struct mob_data *)bl, hp); break; - case BL_HOM: homun->revive((struct homun_data *)bl, hp, sp); break; + case BL_PC: pc->revive(BL_UCAST(BL_PC, bl), hp, sp); break; + case BL_MOB: mob->revive(BL_UCAST(BL_MOB, bl), hp); break; + case BL_HOM: homun->revive(BL_UCAST(BL_HOM, bl), hp, sp); break; } return 1; } @@ -1714,9 +1717,9 @@ int status_fixed_revive(struct block_list *bl, unsigned int per_hp, unsigned int if (bl->prev) //Animation only if character is already on a map. clif->resurrection(bl, 1); switch (bl->type) { - case BL_PC: pc->revive((struct map_session_data *)bl, hp, sp); break; - case BL_MOB: mob->revive((struct mob_data *)bl, hp); break; - case BL_HOM: homun->revive((struct homun_data *)bl, hp, sp); break; + case BL_PC: pc->revive(BL_UCAST(BL_PC, bl), hp, sp); break; + case BL_MOB: mob->revive(BL_UCAST(BL_MOB, bl), hp); break; + case BL_HOM: homun->revive(BL_UCAST(BL_HOM, bl), hp, sp); break; } return 1; } @@ -1972,15 +1975,15 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin switch( target->type ) { case BL_PC: { - struct map_session_data *sd = (struct map_session_data *)target; + const struct map_session_data *tsd = BL_UCCAST(BL_PC, target); bool is_boss = (st->mode&MD_BOSS); bool is_detect = ((st->mode&MD_DETECTOR)?true:false);//god-knows-why gcc doesn't shut up until this happens - if (pc_isinvisible(sd)) + if (pc_isinvisible(tsd)) return 0; if (tsc != NULL) { if (tsc->option&hide_flag && !is_boss - && ((sd->special_state.perfect_hiding || !is_detect) + && ((tsd->special_state.perfect_hiding || !is_detect) || (tsc->data[SC_CLOAKINGEXCEED] != NULL && is_detect) )) return 0; @@ -2084,7 +2087,7 @@ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) { //Max HP setting from Summon Flora/marine Sphere struct unit_data *ud = unit->bl2ud(mbl); //Remove special AI when this is used by regular mobs. - if (mbl->type == BL_MOB && ((struct mob_data *)mbl)->special_state.ai == AI_NONE) + if (mbl->type == BL_MOB && BL_UCAST(BL_MOB, mbl)->special_state.ai == AI_NONE) md->special_state.ai = AI_NONE; if (ud) { // different levels of HP according to skill level @@ -3436,8 +3439,8 @@ void status_calc_regen(struct block_list *bl, struct status_data *st, struct reg sregen->sp = cap_value(val, 0, SHRT_MAX); } - if( bl->type == BL_HOM ) { - struct homun_data *hd = (struct homun_data *)bl; + if (bl->type == BL_HOM) { + struct homun_data *hd = BL_UCAST(BL_HOM, bl); if( (skill_lv = homun->checkskill(hd,HAMI_SKIN)) > 0 ) { val = regen->hp*(100+5*skill_lv)/100; regen->hp = cap_value(val, 1, SHRT_MAX); @@ -3506,7 +3509,7 @@ void status_calc_regen_rate(struct block_list *bl, struct regen_data *regen, str || sc->data[SC_OBLIVIONCURSE] != NULL || sc->data[SC_MAXIMIZEPOWER] != NULL || sc->data[SC_REBOUND] != NULL - || (bl->type == BL_PC && (((struct map_session_data *)bl)->class_&MAPID_UPPERMASK) == MAPID_MONK + || (bl->type == BL_PC && (BL_UCAST(BL_PC, bl)->class_&MAPID_UPPERMASK) == MAPID_MONK && (sc->data[SC_EXTREMITYFIST] != NULL || (sc->data[SC_EXPLOSIONSPIRITS] != NULL && (sc->data[SC_SOULLINK] == NULL || sc->data[SC_SOULLINK]->val2 != SL_MONK) @@ -3769,8 +3772,11 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) { if( bl->type&BL_PC && !(sd && sd->state.permanent_speed) && st->speed < battle_config.max_walk_speed ) st->speed = battle_config.max_walk_speed; - if (bl->type&BL_HOM && battle_config.hom_setting&0x8 && ((struct homun_data *)bl)->master != NULL) - st->speed = status->get_speed(&((struct homun_data *)bl)->master->bl); + if (bl->type&BL_HOM && battle_config.hom_setting&0x8) { + struct homun_data *hd = BL_UCAST(BL_HOM, bl); + if (hd->master != NULL) + st->speed = status->get_speed(&hd->master->bl); + } } if(flag&SCB_CRI && bst->cri) { @@ -3779,7 +3785,7 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) { else st->cri = status->calc_critical(bl, sc, bst->cri + 3*(st->luk - bst->luk), true); } - if (battle_config.show_katar_crit_bonus && bl->type == BL_PC && ((struct map_session_data *)bl)->status.weapon == W_KATAR) + if (battle_config.show_katar_crit_bonus && bl->type == BL_PC && BL_UCAST(BL_PC, bl)->status.weapon == W_KATAR) st->cri <<= 1; if(flag&SCB_FLEE2 && bst->flee2) { @@ -3944,16 +3950,20 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) { /// Also sends updates to the client wherever applicable. /// @param flag bitfield of values from enum scb_flag /// @param first if true, will cause status_calc_* functions to run their base status initialization code -void status_calc_bl_(struct block_list *bl, enum scb_flag flag, enum e_status_calc_opt opt) { +void status_calc_bl_(struct block_list *bl, enum scb_flag flag, enum e_status_calc_opt opt) +{ struct status_data bst; // previous battle status struct status_data *st; // pointer to current battle status - if (bl->type == BL_PC && ((struct map_session_data *)bl)->delayed_damage != 0) { - if (opt&SCO_FORCE) { - ((struct map_session_data *)bl)->state.hold_recalc = 0;/* clear and move on */ - } else { - ((struct map_session_data *)bl)->state.hold_recalc = 1;/* flag and stop */ - return; + if (bl->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + if (sd->delayed_damage != 0) { + if (opt&SCO_FORCE) { + sd->state.hold_recalc = 0;/* clear and move on */ + } else { + sd->state.hold_recalc = 1;/* flag and stop */ + return; + } } } @@ -4129,10 +4139,10 @@ int status_check_visibility(struct block_list *src, struct block_list *target) { switch ( src->type ) { case BL_MOB: - view_range = ((struct mob_data *)src)->min_chase; + view_range = BL_UCCAST(BL_MOB, src)->min_chase; break; case BL_PET: - view_range = ((struct pet_data *)src)->db->range2; + view_range = BL_UCCAST(BL_PET, src)->db->range2; break; default: view_range = AREA_SIZE; @@ -4157,7 +4167,7 @@ int status_check_visibility(struct block_list *src, struct block_list *target) { || tsc->data[SC_CAMOUFLAGE] != NULL ) && !(st->mode&MD_BOSS) - && (((struct map_session_data *)target)->special_state.perfect_hiding || !(st->mode&MD_DETECTOR))) + && (BL_UCCAST(BL_PC, target)->special_state.perfect_hiding || !(st->mode&MD_DETECTOR))) return 0; break; default: @@ -4223,8 +4233,8 @@ unsigned short status_base_atk(const struct block_list *bl, const struct status_ if ( !(bl->type&battle_config.enable_baseatk) ) return 0; - if ( bl->type == BL_PC ) - switch (((struct map_session_data *)bl)->status.weapon) { + if (bl->type == BL_PC) { + switch (BL_UCCAST(BL_PC, bl)->status.weapon) { case W_BOW: case W_MUSICAL: case W_WHIP: @@ -4234,20 +4244,18 @@ unsigned short status_base_atk(const struct block_list *bl, const struct status_ case W_SHOTGUN: case W_GRENADE: flag = 1; + } } if ( flag ) { -#ifdef RENEWAL - dstr = -#endif - str = st->dex; + str = st->dex; dex = st->str; } else { -#ifdef RENEWAL - dstr = -#endif - str = st->str; + str = st->str; dex = st->dex; } +#ifdef RENEWAL + dstr = str; +#endif //Normally only players have base-atk, but homunc have a different batk // equation, hinting that perhaps non-players should use this for batk. // [Skotlex] @@ -4260,12 +4268,15 @@ unsigned short status_base_atk(const struct block_list *bl, const struct status_ dstr = str / 10; str += dstr*dstr; #endif - if ( bl->type == BL_PC ) #ifdef RENEWAL - str = (int)(dstr + (float)dex / 5 + (float)st->luk / 3 + (float)((struct map_session_data *)bl)->status.base_level / 4); - else if ( bl->type == BL_MOB || bl->type == BL_MER ) - str = dstr + ((struct mob_data *)bl)->level; + if (bl->type == BL_PC) + str = (int)(dstr + (float)dex / 5 + (float)st->luk / 3 + (float)BL_UCCAST(BL_PC, bl)->status.base_level / 4); + else if (bl->type == BL_MOB) + str = dstr + BL_UCCAST(BL_MOB, bl)->level; + //else if (bl->type == BL_MER) // FIXME: What should go here? + // str = dstr + BL_UCCAST(BL_MER, bl)->level; #else + if (bl->type == BL_PC) str += dex / 5 + st->luk / 5; #endif return cap_value(str, 0, USHRT_MAX); @@ -4870,7 +4881,7 @@ unsigned short status_calc_watk(struct block_list *bl, struct status_change *sc, if (bl->type != BL_PC) { watk += sc->data[SC_NIBELUNGEN]->val2; } else { - struct map_session_data *sd = (struct map_session_data *)bl; + const struct map_session_data *sd = BL_UCCAST(BL_PC, bl); int index = sd->equip_index[sd->state.lr_flag?EQI_HAND_L:EQI_HAND_R]; if(index >= 0 && sd->inventory_data[index] && sd->inventory_data[index]->wlv == 4) watk += sc->data[SC_NIBELUNGEN]->val2; @@ -5732,10 +5743,10 @@ short status_calc_aspd(struct block_list *bl, struct status_change *sc, short fl } if (sc->data[SC_ASSNCROS] && bonus < sc->data[SC_ASSNCROS]->val2) { - if (bl->type!=BL_PC) + if (bl->type != BL_PC) { bonus = sc->data[SC_ASSNCROS]->val2; - else { - switch (((struct map_session_data *)bl)->status.weapon) { + } else { + switch (BL_UCCAST(BL_PC, bl)->status.weapon) { case W_BOW: case W_REVOLVER: case W_RIFLE: @@ -5831,11 +5842,10 @@ short status_calc_fix_aspd(struct block_list *bl, struct status_change *sc, int if (!sc || !sc->count) return cap_value(aspd, 0, 2000); - if ((sc->data[SC_GUST_OPTION] || sc->data[SC_BLAST_OPTION] - || sc->data[SC_WILD_STORM_OPTION])) + if (sc->data[SC_GUST_OPTION] != NULL || sc->data[SC_BLAST_OPTION] != NULL || sc->data[SC_WILD_STORM_OPTION] != NULL) aspd -= 50; // +5 ASPD - if (sc->data[SC_FIGHTINGSPIRIT] && sc->data[SC_FIGHTINGSPIRIT]->val2) - aspd -= (bl->type == BL_PC ? pc->checkskill((struct map_session_data *)bl, RK_RUNEMASTERY) : 10) / 10 * 40; + if (sc->data[SC_FIGHTINGSPIRIT] != NULL && sc->data[SC_FIGHTINGSPIRIT]->val2 != 0) + aspd -= (bl->type == BL_PC ? pc->checkskill(BL_UCAST(BL_PC, bl), RK_RUNEMASTERY) : 10) / 10 * 40; if (sc->data[SC_MTF_ASPD]) aspd -= sc->data[SC_MTF_ASPD]->val1; @@ -5891,10 +5901,10 @@ short status_calc_aspd_rate(struct block_list *bl, struct status_change *sc, int max = sc->data[SC_HLIF_FLEET]->val2; if (sc->data[SC_ASSNCROS] && max < sc->data[SC_ASSNCROS]->val2) { - if (bl->type!=BL_PC) { + if (bl->type != BL_PC) { max = sc->data[SC_ASSNCROS]->val2; } else { - switch (((struct map_session_data *)bl)->status.weapon) { + switch (BL_UCCAST(BL_PC, bl)->status.weapon) { case W_BOW: case W_REVOLVER: case W_RIFLE: @@ -5988,9 +5998,10 @@ short status_calc_aspd_rate(struct block_list *bl, struct status_change *sc, int return (short)cap_value(aspd_rate,0,SHRT_MAX); } -unsigned short status_calc_dmotion(struct block_list *bl, struct status_change *sc, int dmotion) { +unsigned short status_calc_dmotion(struct block_list *bl, struct status_change *sc, int dmotion) +{ // It has been confirmed on official servers that MvP mobs have no dmotion even without endure - 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; if( !sc || !sc->count || map_flag_gvg2(bl->m) || map->list[bl->m].flag.battleground ) @@ -6214,14 +6225,21 @@ unsigned short status_calc_mode(struct block_list *bl, struct status_change *sc, return cap_value(mode,0,USHRT_MAX); } -const char* status_get_name(struct block_list *bl) { +const char *status_get_name(struct block_list *bl) +{ nullpo_ret(bl); switch (bl->type) { - case BL_PC: return ((struct map_session_data *)bl)->fakename[0] != '\0' ? ((struct map_session_data *)bl)->fakename : ((struct map_session_data *)bl)->status.name; - case BL_MOB: return ((struct mob_data *)bl)->name; - case BL_PET: return ((struct pet_data *)bl)->pet.name; - case BL_HOM: return ((struct homun_data *)bl)->homunculus.name; - case BL_NPC: return ((struct npc_data *)bl)->name; + case BL_PC: + { + const struct map_session_data *sd = BL_UCCAST(BL_PC, bl); + if (sd->fakename[0] != '\0') + return sd->fakename; + return sd->status.name; + } + case BL_MOB: return BL_UCCAST(BL_MOB, bl)->name; + case BL_PET: return BL_UCCAST(BL_PET, bl)->pet.name; + case BL_HOM: return BL_UCCAST(BL_HOM, bl)->homunculus.name; + case BL_NPC: return BL_UCCAST(BL_NPC, bl)->name; } return "Unknown"; } @@ -6232,16 +6250,17 @@ const char* status_get_name(struct block_list *bl) { * 0 = fail * class_id = success *------------------------------------------*/ -int status_get_class(struct block_list *bl) { +int status_get_class(struct block_list *bl) +{ nullpo_ret(bl); - switch( bl->type ) { - case BL_PC: return ((struct map_session_data *)bl)->status.class_; - case BL_MOB: return ((struct mob_data *)bl)->vd->class_; //Class used on all code should be the view class of the mob. - case BL_PET: return ((struct pet_data *)bl)->pet.class_; - case BL_HOM: return ((struct homun_data *)bl)->homunculus.class_; - case BL_MER: return ((struct mercenary_data *)bl)->mercenary.class_; - case BL_NPC: return ((struct npc_data *)bl)->class_; - case BL_ELEM: return ((struct elemental_data *)bl)->elemental.class_; + switch (bl->type) { + case BL_PC: return BL_UCCAST(BL_PC, bl)->status.class_; + case BL_MOB: return BL_UCCAST(BL_MOB, bl)->vd->class_; //Class used on all code should be the view class of the mob. + case BL_PET: return BL_UCCAST(BL_PET, bl)->pet.class_; + case BL_HOM: return BL_UCCAST(BL_HOM, bl)->homunculus.class_; + case BL_MER: return BL_UCCAST(BL_MER, bl)->mercenary.class_; + case BL_NPC: return BL_UCCAST(BL_NPC, bl)->class_; + case BL_ELEM: return BL_UCCAST(BL_ELEM, bl)->elemental.class_; } return 0; } @@ -6251,16 +6270,17 @@ int status_get_class(struct block_list *bl) { * 1 = fail * level = success *------------------------------------------*/ -int status_get_lv(struct block_list *bl) { +int status_get_lv(struct block_list *bl) +{ nullpo_ret(bl); switch (bl->type) { - case BL_PC: return ((struct map_session_data *)bl)->status.base_level; - case BL_MOB: return ((struct mob_data *)bl)->level; - case BL_PET: return ((struct pet_data *)bl)->pet.level; - case BL_HOM: return ((struct homun_data *)bl)->homunculus.level; - case BL_MER: return ((struct mercenary_data *)bl)->db->lv; - case BL_ELEM: return ((struct elemental_data *)bl)->db->lv; - case BL_NPC: return ((struct npc_data *)bl)->level; + case BL_PC: return BL_UCCAST(BL_PC, bl)->status.base_level; + case BL_MOB: return BL_UCCAST(BL_MOB, bl)->level; + case BL_PET: return BL_UCCAST(BL_PET, bl)->pet.level; + case BL_HOM: return BL_UCCAST(BL_HOM, bl)->homunculus.level; + case BL_MER: return BL_UCCAST(BL_MER, bl)->db->lv; + case BL_ELEM: return BL_UCCAST(BL_ELEM, bl)->db->lv; + case BL_NPC: return BL_UCCAST(BL_NPC, bl)->level; } return 1; } @@ -6269,10 +6289,10 @@ struct regen_data *status_get_regen_data(struct block_list *bl) { nullpo_retr(NULL, bl); switch (bl->type) { - case BL_PC: return &((struct map_session_data *)bl)->regen; - case BL_HOM: return &((struct homun_data *)bl)->regen; - case BL_MER: return &((struct mercenary_data *)bl)->regen; - case BL_ELEM: return &((struct elemental_data *)bl)->regen; + case BL_PC: return &BL_UCAST(BL_PC, bl)->regen; + case BL_HOM: return &BL_UCAST(BL_HOM, bl)->regen; + case BL_MER: return &BL_UCAST(BL_MER, bl)->regen; + case BL_ELEM: return &BL_UCAST(BL_ELEM, bl)->regen; default: return NULL; } @@ -6283,13 +6303,17 @@ struct status_data *status_get_status_data(struct block_list *bl) nullpo_retr(&status->dummy, bl); switch (bl->type) { - case BL_PC: return &((struct map_session_data *)bl)->battle_status; - case BL_MOB: return &((struct mob_data *)bl)->status; - case BL_PET: return &((struct pet_data *)bl)->status; - case BL_HOM: return &((struct homun_data *)bl)->battle_status; - case BL_MER: return &((struct mercenary_data *)bl)->battle_status; - case BL_ELEM: return &((struct elemental_data *)bl)->battle_status; - case BL_NPC: return mob->db_checkid(((struct npc_data *)bl)->class_) == 0 ? &((struct npc_data *)bl)->status : &status->dummy; + case BL_PC: return &BL_UCAST(BL_PC, bl)->battle_status; + case BL_MOB: return &BL_UCAST(BL_MOB, bl)->status; + case BL_PET: return &BL_UCAST(BL_PET, bl)->status; + case BL_HOM: return &BL_UCAST(BL_HOM, bl)->battle_status; + case BL_MER: return &BL_UCAST(BL_MER, bl)->battle_status; + case BL_ELEM: return &BL_UCAST(BL_ELEM, bl)->battle_status; + case BL_NPC: + { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + return mob->db_checkid(nd->class_) == 0 ? &nd->status : &status->dummy; + } default: return &status->dummy; } @@ -6299,13 +6323,21 @@ struct status_data *status_get_base_status(struct block_list *bl) { nullpo_retr(NULL, bl); switch (bl->type) { - case BL_PC: return &((struct map_session_data *)bl)->base_status; - case BL_MOB: return ((struct mob_data *)bl)->base_status ? ((struct mob_data *)bl)->base_status : &((struct mob_data *)bl)->db->status; - case BL_PET: return &((struct pet_data *)bl)->db->status; - case BL_HOM: return &((struct homun_data *)bl)->base_status; - case BL_MER: return &((struct mercenary_data *)bl)->base_status; - case BL_ELEM: return &((struct elemental_data *)bl)->base_status; - case BL_NPC: return mob->db_checkid(((struct npc_data *)bl)->class_) == 0 ? &((struct npc_data *)bl)->status : NULL; + case BL_PC: return &BL_UCAST(BL_PC, bl)->base_status; + case BL_MOB: + { + struct mob_data *md = BL_UCAST(BL_MOB, bl); + return md->base_status ? md->base_status : &md->db->status; + } + case BL_PET: return &BL_UCAST(BL_PET, bl)->db->status; + case BL_HOM: return &BL_UCAST(BL_HOM, bl)->base_status; + case BL_MER: return &BL_UCAST(BL_MER, bl)->base_status; + case BL_ELEM: return &BL_UCAST(BL_ELEM, bl)->base_status; + case BL_NPC: + { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + return mob->db_checkid(nd->class_) == 0 ? &nd->status : NULL; + } default: return NULL; } @@ -6321,9 +6353,10 @@ defType status_get_def(struct block_list *bl) { return cap_value(def, DEFTYPE_MIN, DEFTYPE_MAX); } -unsigned short status_get_speed(struct block_list *bl) { - if(bl->type==BL_NPC)//Only BL with speed data but no status_data [Skotlex] - return ((struct npc_data *)bl)->speed; +unsigned short status_get_speed(struct block_list *bl) +{ + if (bl->type == BL_NPC) //Only BL with speed data but no status_data [Skotlex] + return BL_UCCAST(BL_NPC, bl)->speed; return status->get_status_data(bl)->speed; } @@ -6331,16 +6364,19 @@ int status_get_party_id(struct block_list *bl) { nullpo_ret(bl); switch (bl->type) { case BL_PC: - return ((struct map_session_data *)bl)->status.party_id; + return BL_UCCAST(BL_PC, bl)->status.party_id; case BL_PET: - if (((struct pet_data *)bl)->msd != NULL) - return ((struct pet_data *)bl)->msd->status.party_id; + { + const struct pet_data *pd = BL_UCCAST(BL_PET, bl); + if (pd->msd != NULL) + return pd->msd->status.party_id; + } break; case BL_MOB: { - struct mob_data *md = (struct mob_data *)bl; + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); if (md->master_id > 0) { - struct map_session_data *msd; + const struct map_session_data *msd = NULL; if (md->special_state.ai != AI_NONE && (msd = map->id2sd(md->master_id)) != NULL) return msd->status.party_id; return -md->master_id; @@ -6348,65 +6384,98 @@ int status_get_party_id(struct block_list *bl) { } break; case BL_HOM: - if (((struct homun_data *)bl)->master != NULL) - return ((struct homun_data *)bl)->master->status.party_id; + { + const struct homun_data *hd = BL_UCCAST(BL_HOM, bl); + if (hd->master != NULL) + return hd->master->status.party_id; + } break; case BL_MER: - if (((struct mercenary_data *)bl)->master != NULL) - return ((struct mercenary_data *)bl)->master->status.party_id; + { + const struct mercenary_data *mc = BL_UCCAST(BL_MER, bl); + if (mc->master != NULL) + return mc->master->status.party_id; + } break; case BL_SKILL: - if (((struct skill_unit *)bl)->group != NULL) - return ((struct skill_unit *)bl)->group->party_id; + { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, bl); + if (su->group != NULL) + return su->group->party_id; + } break; case BL_ELEM: - if (((struct elemental_data *)bl)->master != NULL) - return ((struct elemental_data *)bl)->master->status.party_id; + { + const struct elemental_data *ed = BL_UCCAST(BL_ELEM, bl); + if (ed->master != NULL) + return ed->master->status.party_id; + } break; } return 0; } -int status_get_guild_id(struct block_list *bl) { +int status_get_guild_id(struct block_list *bl) +{ nullpo_ret(bl); switch (bl->type) { case BL_PC: - return ((struct map_session_data *)bl)->status.guild_id; + return BL_UCCAST(BL_PC, bl)->status.guild_id; case BL_PET: - if (((struct pet_data *)bl)->msd != NULL) - return ((struct pet_data *)bl)->msd->status.guild_id; + { + const struct pet_data *pd = BL_UCCAST(BL_PET, bl); + if (pd->msd != NULL) + return pd->msd->status.guild_id; + } break; case BL_MOB: { - struct map_session_data *msd; - struct mob_data *md = (struct mob_data *)bl; - if( md->guardian_data ) { //Guardian's guild [Skotlex] + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); + const struct map_session_data *msd = NULL; + if (md->guardian_data != NULL) { //Guardian's guild [Skotlex] // Guardian guild data may not been available yet, castle data is always set - return (md->guardian_data->g)?md->guardian_data->g->guild_id:md->guardian_data->castle->guild_id; + if (md->guardian_data->g != NULL) + return md->guardian_data->g->guild_id; + return md->guardian_data->castle->guild_id; } if (md->special_state.ai != AI_NONE && (msd = map->id2sd(md->master_id)) != NULL) return msd->status.guild_id; //Alchemist's mobs [Skotlex] break; } case BL_HOM: - if (((struct homun_data *)bl)->master != NULL) - return ((struct homun_data *)bl)->master->status.guild_id; + { + const struct homun_data *hd = BL_UCCAST(BL_HOM, bl); + if (hd->master != NULL) + return hd->master->status.guild_id; + } break; case BL_MER: - if (((struct mercenary_data *)bl)->master != NULL) - return ((struct mercenary_data *)bl)->master->status.guild_id; + { + const struct mercenary_data *mc = BL_UCCAST(BL_MER, bl); + if (mc->master != NULL) + return mc->master->status.guild_id; + } break; case BL_NPC: - if (((struct npc_data *)bl)->subtype == SCRIPT) - return ((struct npc_data *)bl)->u.scr.guild_id; + { + const struct npc_data *nd = BL_UCCAST(BL_NPC, bl); + if (nd->subtype == SCRIPT) + return nd->u.scr.guild_id; + } break; case BL_SKILL: - if (((struct skill_unit *)bl)->group != NULL) - return ((struct skill_unit *)bl)->group->guild_id; + { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, bl); + if (su->group != NULL) + return su->group->guild_id; + } break; case BL_ELEM: - if (((struct elemental_data *)bl)->master != NULL) - return ((struct elemental_data *)bl)->master->status.guild_id; + { + const struct elemental_data *ed = BL_UCCAST(BL_ELEM, bl); + if (ed->master != NULL) + return ed->master->status.guild_id; + } break; } return 0; @@ -6416,39 +6485,58 @@ int status_get_emblem_id(struct block_list *bl) { nullpo_ret(bl); switch (bl->type) { case BL_PC: - return ((struct map_session_data *)bl)->guild_emblem_id; + return BL_UCCAST(BL_PC, bl)->guild_emblem_id; case BL_PET: - if (((struct pet_data *)bl)->msd != NULL) - return ((struct pet_data *)bl)->msd->guild_emblem_id; + { + const struct pet_data *pd = BL_UCCAST(BL_PET, bl); + if (pd->msd != NULL) + return pd->msd->guild_emblem_id; + } break; case BL_MOB: { - struct map_session_data *msd; - struct mob_data *md = (struct mob_data *)bl; - if (md->guardian_data) //Guardian's guild [Skotlex] - return (md->guardian_data->g) ? md->guardian_data->g->emblem_id:0; + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); + const struct map_session_data *msd = NULL; + if (md->guardian_data != NULL) { + //Guardian's guild [Skotlex] + if (md->guardian_data->g != NULL) + return md->guardian_data->g->emblem_id; + return 0; + } if (md->special_state.ai != AI_NONE && (msd = map->id2sd(md->master_id)) != NULL) return msd->guild_emblem_id; //Alchemist's mobs [Skotlex] } break; case BL_HOM: - if (((struct homun_data *)bl)->master) - return ((struct homun_data *)bl)->master->guild_emblem_id; + { + const struct homun_data *hd = BL_UCCAST(BL_HOM, bl); + if (hd->master) + return hd->master->guild_emblem_id; + } break; case BL_MER: - if (((struct mercenary_data *)bl)->master) - return ((struct mercenary_data *)bl)->master->guild_emblem_id; + { + const struct mercenary_data *mc = BL_UCCAST(BL_MER, bl); + if (mc->master) + return mc->master->guild_emblem_id; + } break; case BL_NPC: - if (((struct npc_data *)bl)->subtype == SCRIPT && ((struct npc_data *)bl)->u.scr.guild_id > 0) { - struct guild *g = guild->search(((struct npc_data *)bl)->u.scr.guild_id); + { + const struct npc_data *nd = BL_UCCAST(BL_NPC, bl); + if (nd->subtype == SCRIPT && nd->u.scr.guild_id > 0) { + struct guild *g = guild->search(nd->u.scr.guild_id); if (g != NULL) return g->emblem_id; } + } break; case BL_ELEM: - if (((struct elemental_data *)bl)->master) - return ((struct elemental_data *)bl)->master->guild_emblem_id; + { + const struct elemental_data *ed = BL_UCCAST(BL_ELEM, bl); + if (ed->master) + return ed->master->guild_emblem_id; + } break; } return 0; @@ -6457,19 +6545,20 @@ int status_get_emblem_id(struct block_list *bl) { int status_get_mexp(struct block_list *bl) { nullpo_ret(bl); - if(bl->type==BL_MOB) - return ((struct mob_data *)bl)->db->mexp; - if(bl->type==BL_PET) - return ((struct pet_data *)bl)->db->mexp; + if (bl->type == BL_MOB) + return BL_UCCAST(BL_MOB, bl)->db->mexp; + if (bl->type == BL_PET) + return BL_UCCAST(BL_PET, bl)->db->mexp; return 0; } + int status_get_race2(struct block_list *bl) { nullpo_ret(bl); - if(bl->type == BL_MOB) - return ((struct mob_data *)bl)->db->race2; - if(bl->type==BL_PET) - return ((struct pet_data *)bl)->db->race2; + if (bl->type == BL_MOB) + return BL_UCCAST(BL_MOB, bl)->db->race2; + if (bl->type == BL_PET) + return BL_UCCAST(BL_PET, bl)->db->race2; return 0; } @@ -6478,27 +6567,34 @@ int status_isdead(struct block_list *bl) { return status->get_status_data(bl)->hp == 0; } -int status_isimmune(struct block_list *bl) { - struct status_change *sc = status->get_sc(bl); - if (sc && sc->data[SC_HERMODE]) +int status_isimmune(struct block_list *bl) +{ + struct status_change *sc = NULL; + nullpo_ret(bl); + sc = status->get_sc(bl); + + if (sc != NULL && sc->data[SC_HERMODE] != NULL) return 100; - if (bl->type == BL_PC && ((struct map_session_data *)bl)->special_state.no_magic_damage >= battle_config.gtb_sc_immunity) - return ((struct map_session_data *)bl)->special_state.no_magic_damage; + if (bl->type == BL_PC) { + const struct map_session_data *sd = BL_UCCAST(BL_PC, bl); + if (sd->special_state.no_magic_damage >= battle_config.gtb_sc_immunity) + return sd->special_state.no_magic_damage; + } return 0; } -struct view_data* status_get_viewdata(struct block_list *bl) +struct view_data *status_get_viewdata(struct block_list *bl) { nullpo_retr(NULL, bl); switch (bl->type) { - case BL_PC: return &((struct map_session_data *)bl)->vd; - case BL_MOB: return ((struct mob_data *)bl)->vd; - case BL_PET: return &((struct pet_data *)bl)->vd; - case BL_NPC: return ((struct npc_data *)bl)->vd; - case BL_HOM: return ((struct homun_data *)bl)->vd; - case BL_MER: return ((struct mercenary_data *)bl)->vd; - case BL_ELEM: return ((struct elemental_data *)bl)->vd; + case BL_PC: return &BL_UCAST(BL_PC, bl)->vd; + case BL_MOB: return BL_UCAST(BL_MOB, bl)->vd; + case BL_PET: return &BL_UCAST(BL_PET, bl)->vd; + case BL_NPC: return BL_UCAST(BL_NPC, bl)->vd; + case BL_HOM: return BL_UCAST(BL_HOM, bl)->vd; + case BL_MER: return BL_UCAST(BL_MER, bl)->vd; + case BL_ELEM: return BL_UCAST(BL_ELEM, bl)->vd; } return NULL; } @@ -6523,7 +6619,7 @@ void status_set_viewdata(struct block_list *bl, int class_) 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); if (pc->db_checkid(class_)) { if (pc_isridingpeco(sd)) { switch (class_) { @@ -6588,7 +6684,7 @@ void status_set_viewdata(struct block_list *bl, int class_) break; case BL_MOB: { - struct mob_data *md = (struct mob_data *)bl; + struct mob_data *md = BL_UCAST(BL_MOB, bl); if (vd != NULL) md->vd = vd; else @@ -6597,7 +6693,7 @@ void status_set_viewdata(struct block_list *bl, int class_) break; case BL_PET: { - struct pet_data *pd = (struct pet_data *)bl; + struct pet_data *pd = BL_UCAST(BL_PET, bl); if (vd != NULL) { memcpy(&pd->vd, vd, sizeof(struct view_data)); if (!pc->db_checkid(vd->class_)) { @@ -6615,7 +6711,7 @@ void status_set_viewdata(struct block_list *bl, int class_) break; case BL_NPC: { - struct npc_data *nd = (struct npc_data *)bl; + struct npc_data *nd = BL_UCAST(BL_NPC, bl); if (vd != NULL) nd->vd = vd; else @@ -6624,7 +6720,7 @@ void status_set_viewdata(struct block_list *bl, int class_) break; case BL_HOM: //[blackhole89] { - struct homun_data *hd = (struct homun_data *)bl; + struct homun_data *hd = BL_UCAST(BL_HOM, bl); if (vd != NULL) hd->vd = vd; else @@ -6633,7 +6729,7 @@ void status_set_viewdata(struct block_list *bl, int class_) break; case BL_MER: { - struct mercenary_data *md = (struct mercenary_data *)bl; + struct mercenary_data *md = BL_UCAST(BL_MER, bl); if (vd != NULL) md->vd = vd; else @@ -6642,7 +6738,7 @@ void status_set_viewdata(struct block_list *bl, int class_) break; case BL_ELEM: { - struct elemental_data *ed = (struct elemental_data*)bl; + struct elemental_data *ed = BL_UCAST(BL_ELEM, bl); if (vd != NULL) ed->vd = vd; else @@ -6653,15 +6749,16 @@ void status_set_viewdata(struct block_list *bl, int class_) } /// Returns the status_change data of bl or NULL if it doesn't exist. -struct status_change *status_get_sc(struct block_list *bl) { - if( bl ) { +struct status_change *status_get_sc(struct block_list *bl) +{ + if (bl != NULL) { switch (bl->type) { - case BL_PC: return &((struct map_session_data *)bl)->sc; - case BL_MOB: return &((struct mob_data *)bl)->sc; + case BL_PC: return &BL_UCAST(BL_PC, bl)->sc; + case BL_MOB: return &BL_UCAST(BL_MOB, bl)->sc; case BL_NPC: return NULL; - case BL_HOM: return &((struct homun_data *)bl)->sc; - case BL_MER: return &((struct mercenary_data *)bl)->sc; - case BL_ELEM: return &((struct elemental_data *)bl)->sc; + case BL_HOM: return &BL_UCAST(BL_HOM, bl)->sc; + case BL_MER: return &BL_UCAST(BL_MER, bl)->sc; + case BL_ELEM: return &BL_UCAST(BL_ELEM, bl)->sc; } } return NULL; @@ -6912,13 +7009,13 @@ int status_get_sc_def(struct block_list *src, struct block_list *bl, enum sc_typ sc_def = (st->vit + st->luk)*20; break; case SC_SIREN: - tick_def2 = status->get_lv(bl) * 100 + (bl->type == BL_PC ? ((struct map_session_data *)bl)->status.job_level : 0); + tick_def2 = status->get_lv(bl) * 100 + (bl->type == BL_PC ? BL_UCCAST(BL_PC, bl)->status.job_level : 0); break; case SC_NEEDLE_OF_PARALYZE: tick_def2 = (st->vit + st->luk) * 50; break; case SC_NETHERWORLD: - tick_def2 = 1000 * ((bl->type == BL_PC ? ((struct map_session_data *)bl)->status.job_level : 0) / 10 + status->get_lv(bl) / 50); + tick_def2 = 1000 * ((bl->type == BL_PC ? BL_UCCAST(BL_PC, bl)->status.job_level : 0) / 10 + status->get_lv(bl) / 50); break; default: //Effect that cannot be reduced? Likely a buff. @@ -7930,8 +8027,11 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t if (sd->devotion[i] && (tsd = map->id2sd(sd->devotion[i])) != NULL) status->change_start(bl, &tsd->bl, type, 10000, val1, val2, val3, val4, tick, SCFLAG_ALL); } - } else if (bl->type == BL_MER && ((struct mercenary_data *)bl)->devotion_flag && (tsd = ((struct mercenary_data *)bl)->master) != NULL) { - status->change_start(bl, &tsd->bl, type, 10000, val1, val2, val3, val4, tick, SCFLAG_ALL); + } else if (bl->type == BL_MER) { + struct mercenary_data *mc = BL_UCAST(BL_MER, bl); + if (mc->devotion_flag && (tsd = mc->master) != NULL) { + status->change_start(bl, &tsd->bl, type, 10000, val1, val2, val3, val4, tick, SCFLAG_ALL); + } } } //val4 signals infinite endure (if val4 == 2 it is infinite endure from Berserk) @@ -8030,8 +8130,11 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t if (sd->devotion[i] && (tsd = map->id2sd(sd->devotion[i])) != NULL) status->change_start(bl, &tsd->bl, type, 10000, val1, val2, 0, 0, tick, SCFLAG_ALL); } - } else if (bl->type == BL_MER && ((struct mercenary_data *)bl)->devotion_flag && (tsd = ((struct mercenary_data *)bl)->master) != NULL) { - status->change_start(bl, &tsd->bl, type, 10000, val1, val2, 0, 0, tick, SCFLAG_ALL); + } else if (bl->type == BL_MER) { + struct mercenary_data *mc = BL_UCAST(BL_MER, bl); + if (mc->devotion_flag && (tsd = mc->master) != NULL) { + status->change_start(bl, &tsd->bl, type, 10000, val1, val2, 0, 0, tick, SCFLAG_ALL); + } } } break; @@ -8173,7 +8276,7 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t if( val2 && bl->type == BL_MOB ) { struct block_list* src2 = map->id2bl(val2); if( src2 ) - mob->log_damage((struct mob_data *)bl, src2, diff); + mob->log_damage(BL_UCAST(BL_MOB, bl), src2, diff); } status_zap(bl, diff, 0); } @@ -8247,7 +8350,7 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t //val4&1 signals the presence of a wall. //val4&2 makes cloak not end on normal attacks [Skotlex] //val4&4 makes cloak not end on using skills - if (bl->type == BL_PC || (bl->type == BL_MOB && ((struct mob_data *)bl)->special_state.clone)) //Standard cloaking. + if (bl->type == BL_PC || (bl->type == BL_MOB && BL_UCCAST(BL_MOB, bl)->special_state.clone)) //Standard cloaking. val4 |= battle_config.pc_cloak_check_type&7; else val4 |= battle_config.monster_cloak_check_type&7; @@ -8291,8 +8394,11 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t if (sd->devotion[i] && (tsd = map->id2sd(sd->devotion[i])) != NULL) status->change_start(bl, &tsd->bl, type, 10000, val1, val2, 0, 0, tick, SCFLAG_ALL); } - } else if (bl->type == BL_MER && ((struct mercenary_data *)bl)->devotion_flag && (tsd = ((struct mercenary_data *)bl)->master) != NULL) { - status->change_start(bl, &tsd->bl, type, 10000, val1, val2, 0, 0, tick, SCFLAG_ALL); + } else if (bl->type == BL_MER) { + struct mercenary_data *mc = BL_UCAST(BL_MER, bl); + if (mc->devotion_flag && (tsd = mc->master) != NULL) { + status->change_start(bl, &tsd->bl, type, 10000, val1, val2, 0, 0, tick, SCFLAG_ALL); + } } } } @@ -8467,7 +8573,7 @@ int status_change_start(struct block_list *src, struct block_list *bl, enum sc_t if( val3 && bl->type == BL_MOB ) { struct block_list* src2 = map->id2bl(val3); if( src2 ) - mob->log_damage((struct mob_data *)bl,src2,st->hp - 1); + mob->log_damage(BL_UCAST(BL_MOB, bl), src2, st->hp - 1); } status_zap(bl, st->hp-1, val2 ? 0 : st->sp); return 1; @@ -10240,11 +10346,14 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const if (sd->devotion[i] && (tsd = map->id2sd(sd->devotion[i])) != NULL && tsd->sc.data[type]) status_change_end(&tsd->bl, type, INVALID_TIMER); } - } else if (bl->type == BL_MER && ((struct mercenary_data *)bl)->devotion_flag) { - // Clear Status from Master - tsd = ((struct mercenary_data *)bl)->master; - if (tsd != NULL && tsd->sc.data[type] != NULL) - status_change_end(&tsd->bl, type, INVALID_TIMER); + } else if (bl->type == BL_MER) { + struct mercenary_data *mc = BL_UCAST(BL_MER, bl); + if (mc->devotion_flag) { + // Clear Status from Master + tsd = mc->master; + if (tsd != NULL && tsd->sc.data[type] != NULL) + status_change_end(&tsd->bl, type, INVALID_TIMER); + } } } break; @@ -10252,10 +10361,10 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const { struct block_list *d_bl = map->id2bl(sce->val1); if( d_bl ) { - if( d_bl->type == BL_PC ) - ((struct map_session_data*)d_bl)->devotion[sce->val2] = 0; - else if( d_bl->type == BL_MER ) - ((struct mercenary_data *)d_bl)->devotion_flag = 0; + if (d_bl->type == BL_PC) + BL_UCAST(BL_PC, d_bl)->devotion[sce->val2] = 0; + else if (d_bl->type == BL_MER) + BL_UCAST(BL_MER, d_bl)->devotion_flag = 0; clif->devotion(d_bl, NULL); } @@ -11011,7 +11120,7 @@ int status_change_timer(int tid, int64 tick, int id, intptr_t data) { if( sce->val2 && bl->type == BL_MOB ) { struct block_list* src = map->id2bl(sce->val2); if (src != NULL) - mob->log_damage((struct mob_data *)bl,src,sce->val4); + mob->log_damage(BL_UCAST(BL_MOB, bl), src, sce->val4); } map->freeblock_lock(); status_zap(bl, sce->val4, 0); @@ -11050,7 +11159,7 @@ int status_change_timer(int tid, int64 tick, int id, intptr_t data) { int hp = rnd()%600 + 200; struct block_list* src = map->id2bl(sce->val2); if( src && bl && bl->type == BL_MOB ) { - mob->log_damage((struct mob_data *)bl, src, sd != NULL || hp < st->hp ? hp : st->hp-1); + mob->log_damage(BL_UCAST(BL_MOB, bl), src, sd != NULL || hp < st->hp ? hp : st->hp-1); } map->freeblock_lock(); status_fix_damage(src, bl, sd||hp<st->hp?hp:st->hp-1, 1); @@ -11866,7 +11975,7 @@ int status_get_weapon_atk(struct block_list *bl, struct weapon_atk *watk, int fl } if ( bl->type == BL_PC && !(flag & 2) ) { - struct map_session_data *sd = (struct map_session_data *)bl; + const struct map_session_data *sd = BL_UCCAST(BL_PC, bl); short index = sd->equip_index[EQI_HAND_R], refine; if ( index >= 0 && sd->inventory_data[index] && sd->inventory_data[index]->type == IT_WEAPON && (refine = sd->status.inventory[index].refine) < 16 && refine ) { @@ -11937,12 +12046,18 @@ void status_get_matk_sub(struct block_list *bl, int flag, unsigned short *matk_m } break; case BL_MER: - *matk_min += 70 * ((struct mercenary_data *)bl)->battle_status.rhw.atk2 / 100; - *matk_max += 130 * ((struct mercenary_data *)bl)->battle_status.rhw.atk2 / 100; + { + const struct mercenary_data *mc = BL_UCCAST(BL_MER, bl); + *matk_min += 70 * mc->battle_status.rhw.atk2 / 100; + *matk_max += 130 * mc->battle_status.rhw.atk2 / 100; + } break; case BL_MOB: - *matk_min += 70 * ((struct mob_data *)bl)->status.rhw.atk2 / 100; - *matk_max += 130 * ((struct mob_data *)bl)->status.rhw.atk2 / 100; + { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); + *matk_min += 70 * md->status.rhw.atk2 / 100; + *matk_max += 130 * md->status.rhw.atk2 / 100; + } break; case BL_HOM: { 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); |