summaryrefslogtreecommitdiff
path: root/src/map/status.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-12-28 15:13:02 +0100
committerHaru <haru@dotalux.com>2016-01-06 15:17:44 +0100
commit0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be (patch)
treea10d3acba71b7dfd643c3bfcd626fb2f592c2335 /src/map/status.c
parent5db8be91c0e1b256a3c9d615ede2957218e69d3a (diff)
downloadhercules-0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be.tar.gz
hercules-0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be.tar.bz2
hercules-0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be.tar.xz
hercules-0e05c1ed742707e0eb5923b562b2f6b8c6c5a3be.zip
Replaced some explicit casts with BL_UCAST
- Replaced safe casts (bl type already checked) Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/status.c')
-rw-r--r--src/map/status.c571
1 files changed, 343 insertions, 228 deletions
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:
{