diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-01-14 08:54:54 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-01-14 08:54:54 +0000 |
commit | c59ea57a893908f54d2960a1e18d2473a1bb8196 (patch) | |
tree | ffd267754c4bc8b70d559e9e416f326c82757ecb /src | |
parent | dde2e2fa9619a504765b676caa3ac0b05b67cfbc (diff) | |
download | hercules-c59ea57a893908f54d2960a1e18d2473a1bb8196.tar.gz hercules-c59ea57a893908f54d2960a1e18d2473a1bb8196.tar.bz2 hercules-c59ea57a893908f54d2960a1e18d2473a1bb8196.tar.xz hercules-c59ea57a893908f54d2960a1e18d2473a1bb8196.zip |
Simplified the BL_CAST macro (see topic:166795)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12072 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/map/battle.c | 18 | ||||
-rw-r--r-- | src/map/clif.c | 16 | ||||
-rw-r--r-- | src/map/map.h | 4 | ||||
-rw-r--r-- | src/map/skill.c | 62 | ||||
-rw-r--r-- | src/map/status.c | 18 | ||||
-rw-r--r-- | src/map/unit.c | 45 |
6 files changed, 77 insertions, 86 deletions
diff --git a/src/map/battle.c b/src/map/battle.c index 9d3bfe31c..e0d21f4ec 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -878,8 +878,8 @@ static struct Damage battle_calc_weapon_attack(struct block_list *src,struct blo if (tsc && !tsc->count) tsc = NULL; //Skip checking as there are no status changes active. - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_PC, target, tsd); + sd = BL_CAST(BL_PC, src); + tsd = BL_CAST(BL_PC, target); if(sd) wd.blewcount += battle_blewcount_bonus(sd, skill_num); @@ -2111,8 +2111,8 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list nk = skill_get_nk(skill_num); flag.imdef = nk&NK_IGNORE_DEF?1:0; - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_PC, target, tsd); + sd = BL_CAST(BL_PC, src); + tsd = BL_CAST(BL_PC, target); //Initialize variables that will be used afterwards s_ele = skill_get_ele(skill_num, skill_lv); @@ -2442,8 +2442,8 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * nk = skill_get_nk(skill_num); - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_PC, target, tsd); + sd = BL_CAST(BL_PC, src); + tsd = BL_CAST(BL_PC, target); if(sd) { sd->state.arrow_atk = 0; @@ -2664,7 +2664,7 @@ int battle_calc_return_damage(struct block_list* bl, int damage, int flag) struct map_session_data* sd = NULL; int rdamage = 0; - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); //Bounces back part of the damage. if (flag & BF_SHORT) { @@ -2753,8 +2753,8 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t if (src->prev == NULL || target->prev == NULL) return 0; - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_PC, target, tsd); + sd = BL_CAST(BL_PC, src); + tsd = BL_CAST(BL_PC, target); sstatus = status_get_status_data(src); tstatus = status_get_status_data(target); diff --git a/src/map/clif.c b/src/map/clif.c index 002210485..4cbfbd198 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -279,7 +279,7 @@ int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target if( type != ALL_CLIENT && type != CHAT_MAINCHAT ) nullpo_retr(0, bl); - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); switch(type) { case ALL_CLIENT: //All player clients. @@ -758,7 +758,7 @@ static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool #if PACKETVER >= 7 unsigned short offset = 0; #endif - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); if(type) WBUFW(buf,0) = spawn?0x7c:0x78; @@ -869,7 +869,7 @@ static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, un unsigned short offset = 0; #endif - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); #if PACKETVER < 4 WBUFW(buf, 0) = 0x7b; @@ -2388,7 +2388,7 @@ void clif_changelook(struct block_list *bl,int type,int val) struct view_data* vd; nullpo_retv(bl); - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); vd = status_get_viewdata(bl); //nullpo_ret(vd); if( vd ) //temp hack to let Warp Portal change appearance @@ -3787,8 +3787,8 @@ int clif_outsight(struct block_list *bl,va_list ap) TBL_PC *sd, *tsd; tbl=va_arg(ap,struct block_list*); if(bl == tbl) return 0; - BL_CAST(BL_PC, bl, sd); - BL_CAST(BL_PC, tbl, tsd); + sd = BL_CAST(BL_PC, bl); + tsd = BL_CAST(BL_PC, tbl); if (tsd && tsd->fd) { //tsd has lost sight of the bl object. @@ -3836,8 +3836,8 @@ int clif_insight(struct block_list *bl,va_list ap) if (bl == tbl) return 0; - BL_CAST(BL_PC, bl, sd); - BL_CAST(BL_PC, tbl, tsd); + sd = BL_CAST(BL_PC, bl); + tsd = BL_CAST(BL_PC, tbl); if (tsd && tsd->fd) { //Tell tsd that bl entered into his view diff --git a/src/map/map.h b/src/map/map.h index 266572680..e73d82c87 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -1362,8 +1362,8 @@ typedef struct skill_unit TBL_SKILL; typedef struct pet_data TBL_PET; typedef struct homun_data TBL_HOM; -#define BL_CAST(type_, bl , dest) \ - (((bl) == NULL || (bl)->type != type_) ? ((dest) = NULL, 0) : ((dest) = (T ## type_ *)(bl), 1)) +#define BL_CAST(type_, bl) \ + ( ((bl) == (struct block_list*)NULL || (bl)->type != (type_)) ? (T ## type_ *)NULL : (T ## type_ *)(bl) ) extern int lowest_gm_level; diff --git a/src/map/skill.c b/src/map/skill.c index 9c17cf6c0..1377748e0 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -418,10 +418,10 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, int if(skillid < 0) return 0; if(skillid > 0 && skilllv <= 0) return 0; // don't forget auto attacks! - celest - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_MOB, src, md); - BL_CAST(BL_PC, bl, dstsd); - BL_CAST(BL_MOB, bl, dstmd); + sd = BL_CAST(BL_PC, src); + md = BL_CAST(BL_MOB, src); + dstsd = BL_CAST(BL_PC, bl); + dstmd = BL_CAST(BL_MOB, bl); sc = status_get_sc(src); tsc = status_get_sc(bl); @@ -952,8 +952,8 @@ int skill_counter_additional_effect (struct block_list* src, struct block_list * if (tsc && !tsc->count) tsc = NULL; - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_PC, bl, dstsd); + sd = BL_CAST(BL_PC, src); + dstsd = BL_CAST(BL_PC, bl); switch(skillid){ case 0: //Normal Attack @@ -1106,7 +1106,7 @@ int skill_break_equip (struct block_list *bl, unsigned short where, int rate, in struct status_change *sc = status_get_sc(bl); int i,j; TBL_PC *sd; - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); if (sc && !sc->count) sc = NULL; @@ -1293,7 +1293,7 @@ static int skill_magic_reflect(struct block_list *bl, int type) { struct status_change *sc = status_get_sc(bl); struct map_session_data *sd; - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); if(sd && sd->magic_damage_return && type && rand()%100 < sd->magic_damage_return) return 1; @@ -1353,8 +1353,8 @@ int skill_attack (int attack_type, struct block_list* src, struct block_list *ds return 0; } - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_PC, bl, tsd); + sd = BL_CAST(BL_PC, src); + tsd = BL_CAST(BL_PC, bl); sstatus = status_get_status_data(src); tstatus = status_get_status_data(bl); @@ -1396,8 +1396,8 @@ int skill_attack (int attack_type, struct block_list* src, struct block_list *ds struct block_list *tbl = bl; bl = src; src = tbl; - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_PC, bl, tsd); + sd = BL_CAST(BL_PC, src); + tsd = BL_CAST(BL_PC, bl); sc = status_get_sc(bl); if (sc && !sc->count) sc = NULL; //Don't need it. @@ -2169,8 +2169,8 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, int if (bl->prev == NULL) return 1; - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_PC, bl, tsd); + sd = BL_CAST(BL_PC, src); + tsd = BL_CAST(BL_PC, bl); if (status_isdead(bl)) return 1; @@ -2807,12 +2807,12 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in if (src->m != bl->m) return 1; - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_HOM, src, hd); - BL_CAST(BL_MOB, src, md); + sd = BL_CAST(BL_PC, src); + hd = BL_CAST(BL_HOM, src); + md = BL_CAST(BL_MOB, src); - BL_CAST(BL_PC, bl, dstsd); - BL_CAST(BL_MOB, bl, dstmd); + dstsd = BL_CAST(BL_PC, bl); + dstmd = BL_CAST(BL_MOB, bl); if(bl->prev == NULL) return 1; @@ -4562,7 +4562,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in { struct skill_unit* su; struct skill_unit_group* sg; - BL_CAST(BL_SKILL, bl, su); + su = BL_CAST(BL_SKILL, bl); if( (su) && (sg = su->group) @@ -5166,9 +5166,9 @@ int skill_castend_id (int tid, unsigned int tick, int id, int data) nullpo_retr(0, ud); - BL_CAST( BL_PC, src, sd); - BL_CAST( BL_HOM, src, hd); //[orn] - BL_CAST( BL_MOB, src, md); + sd = BL_CAST(BL_PC, src); + hd = BL_CAST(BL_HOM, src); + md = BL_CAST(BL_MOB, src); if( src->prev == NULL ) { ud->skilltimer = -1; @@ -5391,9 +5391,9 @@ int skill_castend_pos (int tid, unsigned int tick, int id, int data) nullpo_retr(0, ud); - BL_CAST( BL_PC , src, sd); - BL_CAST( BL_HOM, src, hd); //[orn] - BL_CAST( BL_MOB, src, md); + sd = BL_CAST(BL_PC , src); + hd = BL_CAST(BL_HOM, src); + md = BL_CAST(BL_MOB, src); if( src->prev == NULL ) { ud->skilltimer = -1; @@ -5518,7 +5518,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk if(status_isdead(src)) return 0; - BL_CAST(BL_PC, src, sd); + sd = BL_CAST(BL_PC, src); sc = status_get_sc(src); type = SkillStatusChangeTable(skillid); @@ -6134,7 +6134,7 @@ struct skill_unit_group* skill_unitsetting (struct block_list *src, short skilli unit_flag = skill_get_unit_flag(skillid); layout = skill_get_unit_layout(skillid,skilllv,src,x,y); - BL_CAST(BL_PC, src, sd); + sd = BL_CAST(BL_PC, src); status = status_get_status_data(src); sc = status_get_sc(src); // for traps, firewall and fogwall - celest @@ -6650,8 +6650,8 @@ int skill_unit_onplace_timer (struct skill_unit *src, struct block_list *bl, uns nullpo_retr(0, sg=src->group); nullpo_retr(0, ss=map_id2bl(sg->src_id)); - BL_CAST(BL_PC, ss, sd); - BL_CAST(BL_PC, bl, tsd); + sd = BL_CAST(BL_PC, ss); + tsd = BL_CAST(BL_PC, bl); tsc = status_get_sc(bl); tstatus = status_get_status_data(bl); if (sg->state.magic_power) //For magic power. @@ -8194,7 +8194,7 @@ int skill_castfix (struct block_list *bl, int skill_id, int skill_lv) struct map_session_data *sd; nullpo_retr(0, bl); - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); // calculate base cast time (reduced by dex) if (!(skill_get_castnodex(skill_id, skill_lv)&1)) { diff --git a/src/map/status.c b/src/map/status.c index 655944555..1176bd219 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -2520,7 +2520,7 @@ void status_calc_regen(struct block_list *bl, struct status_data *status, struct if (!(bl->type&BL_REGEN) || !regen) return; - BL_CAST(BL_PC,bl,sd); + sd = BL_CAST(BL_PC,bl); val = 1 + (status->vit/5) + (status->max_hp/200); @@ -2957,7 +2957,7 @@ void status_calc_bl(struct block_list *bl, unsigned long flag) if (!b_status || !status) return; - BL_CAST(BL_PC,bl,sd); + sd = BL_CAST(BL_PC,bl); if(sd && flag&SCB_PC) { //Recalc everything. @@ -4446,7 +4446,7 @@ int status_get_sc_def(struct block_list *bl, enum sc_type type, int rate, int ti return 0; } - BL_CAST(BL_PC,bl,sd); + sd = BL_CAST(BL_PC,bl); status = status_get_status_data(bl); switch (type) { @@ -4612,7 +4612,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val return 0; //Emperium can't be afflicted by status changes } - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); if(sd && sd->state.waitingdisconnect) return 0; //Character logging out, all his SC were wiped already! @@ -6220,7 +6220,7 @@ int status_change_end(struct block_list* bl, enum sc_type type, int tid) if(type < 0 || type >= SC_MAX || !sc || !(sce = sc->data[type])) return 0; - BL_CAST(BL_PC,bl,sd); + sd = BL_CAST(BL_PC,bl); if (sce->timer != tid && tid != -1) return 0; @@ -6696,7 +6696,7 @@ int status_change_timer(int tid, unsigned int tick, int id, int data) return 0; } - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); // set the next timer of the sce (don't assume the status still exists) #define sc_timer_next(t,f,i,d) \ @@ -7020,8 +7020,8 @@ int status_change_timer_sub(struct block_list* bl, va_list ap) tsc = status_get_sc(bl); - BL_CAST(BL_PC, src, sd); - BL_CAST(BL_PC, bl, tsd); + sd = BL_CAST(BL_PC, src); + tsd = BL_CAST(BL_PC, bl); switch( type ) { @@ -7172,7 +7172,7 @@ static int status_natural_heal(DBKey key,void * data,va_list ap) sc = status_get_sc(bl); if (sc && !sc->count) sc = NULL; - BL_CAST(BL_PC,bl,sd); + sd = BL_CAST(BL_PC,bl); flag = regen->flag; if (flag&RGN_HP && (status->hp >= status->max_hp || regen->state.block&1)) diff --git a/src/map/unit.c b/src/map/unit.c index bdb2935f5..287feddad 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -107,19 +107,16 @@ static int unit_walktoxy_timer(int tid,unsigned int tick,int id,int data) int x,y,dx,dy; uint8 dir; struct block_list *bl; - struct map_session_data *sd = NULL; - struct mob_data *md = NULL; - struct unit_data *ud = NULL; + struct map_session_data *sd; + struct mob_data *md; + struct unit_data *ud; - bl=map_id2bl(id); + bl = map_id2bl(id); if(bl == NULL) return 0; - if( BL_CAST( BL_PC, bl, sd ) ) { - ud = &sd->ud; - } else if( BL_CAST( BL_MOB, bl, md ) ) { - ud = &md->ud; - } else - ud = unit_bl2ud(bl); + sd = BL_CAST(BL_PC, bl); + md = BL_CAST(BL_MOB, bl); + ud = unit_bl2ud(bl); if(ud == NULL) return 0; @@ -473,11 +470,9 @@ int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool struct map_session_data *sd = NULL; nullpo_retr(0, bl); - if( BL_CAST( BL_PC, bl, sd ) ) { - ud = &sd->ud; - } else - ud = unit_bl2ud(bl); - + sd = BL_CAST(BL_PC, bl); + ud = unit_bl2ud(bl); + if( ud == NULL) return 0; unit_stop_walking(bl,1); @@ -696,7 +691,7 @@ int unit_can_move(struct block_list *bl) nullpo_retr(0, bl); ud = unit_bl2ud(bl); sc = status_get_sc(bl); - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); if (!ud) return 0; @@ -793,10 +788,8 @@ int unit_skilluse_id2(struct block_list *src, int target_id, short skill_num, sh if(status_isdead(src)) return 0; // 死んでいないか - if( BL_CAST( BL_PC, src, sd ) ) - ud = &sd->ud; - else - ud = unit_bl2ud(src); + sd = BL_CAST(BL_PC, src); + ud = unit_bl2ud(src); if(ud == NULL) return 0; sc = status_get_sc(src); @@ -1074,10 +1067,8 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, sh if(!src->prev) return 0; // map 上に存在するか if(status_isdead(src)) return 0; - if( BL_CAST( BL_PC, src, sd ) ) { - ud = &sd->ud; - } else - ud = unit_bl2ud(src); + sd = BL_CAST(BL_PC, src); + ud = unit_bl2ud(src); if(ud == NULL) return 0; if(ud->skilltimer != -1) //Normally not needed since clif.c checks for it, but at/char/script commands don't! [Skotlex] @@ -1338,8 +1329,8 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t ShowError("unit_attack_timer %d != %d\n",ud->attacktimer,tid); return 0; } - BL_CAST( BL_PC , src, sd); - BL_CAST( BL_MOB, src, md); + sd = BL_CAST(BL_PC, src); + md = BL_CAST(BL_MOB, src); ud->attacktimer=-1; target=map_id2bl(ud->target); @@ -1465,7 +1456,7 @@ int unit_skillcastcancel(struct block_list *bl,int type) if (!ud || ud->skilltimer==-1) return 0; //Nothing to cancel. - BL_CAST(BL_PC, bl, sd); + sd = BL_CAST(BL_PC, bl); if (type&2) { //See if it can be cancelled. |