summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/map/atcommand.c18
-rw-r--r--src/map/battle.c12
-rw-r--r--src/map/clif.c47
-rw-r--r--src/map/instance.c26
-rw-r--r--src/map/map.c12
-rw-r--r--src/map/mob.c82
-rw-r--r--src/map/npc.c27
-rw-r--r--src/map/npc_chat.c11
-rw-r--r--src/map/party.c12
-rw-r--r--src/map/pc.c40
-rw-r--r--src/map/pet.c17
-rw-r--r--src/map/quest.c14
-rw-r--r--src/map/script.c135
-rw-r--r--src/map/skill.c287
-rw-r--r--src/map/status.c9
15 files changed, 475 insertions, 274 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 635a7a220..ef569afa1 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -1563,8 +1563,11 @@ int atcommand_stopattack(struct block_list *bl,va_list ap)
*------------------------------------------*/
int atcommand_pvpoff_sub(struct block_list *bl,va_list ap)
{
- struct map_session_data *sd = (struct map_session_data *)bl;
+ struct map_session_data *sd = NULL;
nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
+
clif->pvpset(sd, 0, 0, 2);
if (sd->pvp_timer != INVALID_TIMER) {
timer->delete(sd->pvp_timer, pc->calc_pvprank_timer);
@@ -1598,8 +1601,11 @@ ACMD(pvpoff)
*------------------------------------------*/
int atcommand_pvpon_sub(struct block_list *bl,va_list ap)
{
- struct map_session_data *sd = (struct map_session_data *)bl;
+ struct map_session_data *sd = NULL;
nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
+
if (sd->pvp_timer == INVALID_TIMER) {
sd->pvp_timer = timer->add(timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0);
sd->pvp_rank = 0;
@@ -2041,10 +2047,12 @@ ACMD(monster)
*------------------------------------------*/
int atkillmonster_sub(struct block_list *bl, va_list ap)
{
- struct mob_data *md = (struct mob_data *)bl;
+ struct mob_data *md = NULL;
int flag = va_arg(ap, int);
-
nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
+
if (md->guardian_data)
return 0; //Do not touch WoE mobs!
@@ -7285,7 +7293,7 @@ int atcommand_mutearea_sub(struct block_list *bl, va_list ap)
{ // As it is being used [ACMD(mutearea)] there's no need to be a bool, but if there's need to reuse it, it's better to be this way
int time, id;
- struct map_session_data *pl_sd = (struct map_session_data *)bl;
+ struct map_session_data *pl_sd = BL_CAST(BL_PC, bl);
if (pl_sd == NULL)
return 0;
diff --git a/src/map/battle.c b/src/map/battle.c
index d6328c951..06f41856c 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -5979,19 +5979,23 @@ int battle_damage_area(struct block_list *bl, va_list ap) {
amotion=va_arg(ap,int);
dmotion=va_arg(ap,int);
damage=va_arg(ap,int);
- if (bl->type == BL_MOB && ((struct mob_data *)bl)->class_ == MOBID_EMPELIUM)
+ if (bl->type == BL_MOB && BL_UCCAST(BL_MOB, bl)->class_ == MOBID_EMPELIUM)
return 0;
if( bl != src && battle->check_target(src,bl,BCT_ENEMY) > 0 ) {
+ struct map_session_data *sd = NULL;
nullpo_ret(src);
+
map->freeblock_lock();
- if( src->type == BL_PC )
- battle->drain((struct map_session_data *)src, bl, damage, damage, status_get_race(bl), is_boss(bl));
+ sd = BL_CAST(BL_PC, src);
+
+ if (src->type == BL_PC)
+ battle->drain(sd, bl, damage, damage, status_get_race(bl), is_boss(bl));
if( amotion )
battle->delay_damage(tick, amotion,src,bl,0,CR_REFLECTSHIELD,0,damage,ATK_DEF,0,true);
else
status_fix_damage(src,bl,damage,0);
clif->damage(bl,bl,amotion,dmotion,damage,1,BDT_ENDURE,0);
- if (!(src->type == BL_PC && ((struct map_session_data *)src)->state.autocast))
+ if (src->type != BL_PC || !sd->state.autocast)
skill->additional_effect(src, bl, CR_REFLECTSHIELD, 1, BF_WEAPON|BF_SHORT|BF_NORMAL,ATK_DEF,tick);
map->freeblock_unlock();
}
diff --git a/src/map/clif.c b/src/map/clif.c
index 898a97c95..5419e6cd5 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -314,7 +314,8 @@ int clif_send_sub(struct block_list *bl, va_list ap) {
int len, type, fd;
nullpo_ret(bl);
- nullpo_ret(sd = (struct map_session_data *)bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
fd = sd->fd;
if (!fd || sockt->session[fd] == NULL) //Don't send to disconnected clients.
@@ -335,15 +336,14 @@ int clif_send_sub(struct block_list *bl, va_list ap) {
return 0;
break;
case AREA_WOSC: {
- if(src_bl->type == BL_PC){
- struct map_session_data *ssd = (struct map_session_data *)src_bl;
- if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
- return 0;
- }
- else if(src_bl->type == BL_NPC) {
- struct npc_data *nd = (struct npc_data *)src_bl;
- if (nd && sd->chatID && (sd->chatID == nd->chat_id))
- return 0;
+ if (src_bl->type == BL_PC) {
+ const struct map_session_data *ssd = BL_UCCAST(BL_PC, src_bl);
+ if (ssd != NULL && sd->chatID != 0 && (sd->chatID == ssd->chatID))
+ return 0;
+ } else if (src_bl->type == BL_NPC) {
+ const struct npc_data *nd = BL_UCCAST(BL_NPC, src_bl);
+ if (nd != NULL && sd->chatID != 0 && (sd->chatID == nd->chat_id))
+ return 0;
}
}
break;
@@ -2765,16 +2765,15 @@ void clif_guild_xy_remove(struct map_session_data *sd)
/*==========================================
*
*------------------------------------------*/
-int clif_hpmeter_sub(struct block_list *bl, va_list ap) {
- struct map_session_data *sd, *tsd;
+int clif_hpmeter_sub(struct block_list *bl, va_list ap)
+{
#if PACKETVER < 20100126
const int cmd = 0x106;
#else
const int cmd = 0x80e;
#endif
-
- sd = va_arg(ap, struct map_session_data *);
- tsd = (struct map_session_data *)bl;
+ struct map_session_data *sd = va_arg(ap, struct map_session_data *);
+ struct map_session_data *tsd = BL_CAST(BL_PC, bl);
nullpo_ret(sd);
nullpo_ret(tsd);
@@ -4582,10 +4581,10 @@ int clif_getareachar(struct block_list* bl,va_list ap) {
switch(bl->type){
case BL_ITEM:
- clif->getareachar_item(sd,(struct flooritem_data*) bl);
+ clif->getareachar_item(sd, BL_UCAST(BL_ITEM, bl));
break;
case BL_SKILL:
- clif->getareachar_skillunit(&sd->bl, (struct skill_unit *)bl, SELF);
+ clif->getareachar_skillunit(&sd->bl, BL_UCAST(BL_SKILL, bl), SELF);
break;
default:
if(&sd->bl == bl)
@@ -4628,13 +4627,13 @@ int clif_outsight(struct block_list *bl,va_list ap)
clif->buyingstore_disappear_entry_single(tsd, sd);
break;
case BL_ITEM:
- clif->clearflooritem((struct flooritem_data*)bl,tsd->fd);
+ clif->clearflooritem(BL_UCAST(BL_ITEM, bl), tsd->fd);
break;
case BL_SKILL:
- clif->clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
+ clif->clearchar_skillunit(BL_UCAST(BL_SKILL, bl), tsd->fd);
break;
case BL_NPC:
- if (!(((struct npc_data *)bl)->option&OPTION_INVISIBLE))
+ if (!(BL_UCAST(BL_NPC, bl)->option&OPTION_INVISIBLE))
clif->clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
break;
default:
@@ -4646,9 +4645,9 @@ int clif_outsight(struct block_list *bl,va_list ap)
if (sd && sd->fd) { //sd is watching tbl go out of view.
nullpo_ret(tbl);
if (tbl->type == BL_SKILL) //Trap knocked out of sight
- clif->clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
+ clif->clearchar_skillunit(BL_UCAST(BL_SKILL, tbl), sd->fd);
else if ((vd = status->get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS
- && !(tbl->type == BL_NPC && (((struct npc_data *)tbl)->option&OPTION_INVISIBLE)))
+ && !(tbl->type == BL_NPC && (BL_UCAST(BL_NPC, tbl)->option&OPTION_INVISIBLE)))
clif->clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
}
return 0;
@@ -4672,10 +4671,10 @@ int clif_insight(struct block_list *bl,va_list ap)
nullpo_ret(bl);
switch(bl->type) {
case BL_ITEM:
- clif->getareachar_item(tsd,(struct flooritem_data*)bl);
+ clif->getareachar_item(tsd, BL_UCAST(BL_ITEM, bl));
break;
case BL_SKILL:
- clif->getareachar_skillunit(&tsd->bl, (struct skill_unit *)bl, SELF);
+ clif->getareachar_skillunit(&tsd->bl, BL_UCAST(BL_SKILL, bl), SELF);
break;
default:
clif->getareachar_unit(tsd,bl);
diff --git a/src/map/instance.c b/src/map/instance.c
index e9ef602f7..5e8256c88 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -369,21 +369,31 @@ int instance_mapid2imapid(int16 m, int instance_id) {
/*--------------------------------------
* Used on Init instance. Duplicates each script on source map
*--------------------------------------*/
-int instance_map_npcsub(struct block_list* bl, va_list args) {
- struct npc_data* nd = (struct npc_data*)bl;
+int instance_map_npcsub(struct block_list* bl, va_list args)
+{
+ struct npc_data *nd = NULL;
int16 m = va_arg(args, int); // Destination Map
- if ( npc->duplicate4instance(nd, m) )
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_NPC);
+ nd = BL_UCAST(BL_NPC, bl);
+
+ if (npc->duplicate4instance(nd, m))
ShowDebug("instance_map_npcsub:npc_duplicate4instance failed (%s/%d)\n",nd->name,m);
return 1;
}
-int instance_init_npc(struct block_list* bl, va_list args) {
- struct npc_data *nd = (struct npc_data*)bl;
+int instance_init_npc(struct block_list* bl, va_list args)
+{
+ struct npc_data *nd = NULL;
struct event_data *ev;
char evname[EVENT_NAME_LENGTH];
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_NPC);
+ nd = BL_UCAST(BL_NPC, bl);
+
snprintf(evname, EVENT_NAME_LENGTH, "%s::OnInstanceInit", nd->exname);
if( ( ev = strdb_get(npc->ev_db, evname) ) )
@@ -430,10 +440,10 @@ int instance_cleanup_sub(struct block_list *bl, va_list ap) {
switch(bl->type) {
case BL_PC:
- map->quit((struct map_session_data *) bl);
+ map->quit(BL_UCAST(BL_PC, bl));
break;
case BL_NPC:
- npc->unload((struct npc_data *)bl,true);
+ npc->unload(BL_UCAST(BL_NPC, bl), true);
break;
case BL_MOB:
unit->free(bl,CLR_OUTSIGHT);
@@ -445,7 +455,7 @@ int instance_cleanup_sub(struct block_list *bl, va_list ap) {
map->clearflooritem(bl);
break;
case BL_SKILL:
- skill->delunit((struct skill_unit *) bl);
+ skill->delunit(BL_UCAST(BL_SKILL, bl));
break;
}
diff --git a/src/map/map.c b/src/map/map.c
index e3054fb30..0a0a09fcb 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -2431,8 +2431,10 @@ void map_spawnmobs(int16 m) {
int map_removemobs_sub(struct block_list *bl, va_list ap)
{
- struct mob_data *md = (struct mob_data *)bl;
- nullpo_ret(md);
+ struct mob_data *md = NULL;
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
//When not to remove mob:
// doesn't respawn and is not a slave
@@ -5332,10 +5334,10 @@ int cleanup_sub(struct block_list *bl, va_list ap) {
switch(bl->type) {
case BL_PC:
- map->quit((struct map_session_data *) bl);
+ map->quit(BL_UCAST(BL_PC, bl));
break;
case BL_NPC:
- npc->unload((struct npc_data *)bl,false);
+ npc->unload(BL_UCAST(BL_NPC, bl), false);
break;
case BL_MOB:
unit->free(bl,CLR_OUTSIGHT);
@@ -5347,7 +5349,7 @@ int cleanup_sub(struct block_list *bl, va_list ap) {
map->clearflooritem(bl);
break;
case BL_SKILL:
- skill->delunit((struct skill_unit *) bl);
+ skill->delunit(BL_UCAST(BL_SKILL, bl));
break;
}
diff --git a/src/map/mob.c b/src/map/mob.c
index f52918d23..074dc13bc 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -794,17 +794,16 @@ int mob_can_reach(struct mob_data *md,struct block_list *bl,int range, int state
/*==========================================
* Links nearby mobs (supportive mobs)
*------------------------------------------*/
-int mob_linksearch(struct block_list *bl,va_list ap) {
- struct mob_data *md;
- int class_;
- struct block_list *target;
- int64 tick;
+int mob_linksearch(struct block_list *bl,va_list ap)
+{
+ struct mob_data *md = NULL;
+ int class_ = va_arg(ap, int);
+ struct block_list *target = va_arg(ap, struct block_list *);
+ int64 tick = va_arg(ap, int64);
nullpo_ret(bl);
- md=(struct mob_data *)bl;
- class_ = va_arg(ap, int);
- target = va_arg(ap, struct block_list *);
- tick = va_arg(ap, int64);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
if (md->class_ == class_ && DIFF_TICK(md->last_linktime, tick) < MIN_MOBLINKTIME
&& !md->target_id)
@@ -1073,8 +1072,7 @@ int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap)
switch (bl->type) {
case BL_PC:
- if (((struct map_session_data *)bl)->state.gangsterparadise
- && !(status_get_mode(&md->bl)&MD_BOSS))
+ if (BL_UCCAST(BL_PC, bl)->state.gangsterparadise && !(status_get_mode(&md->bl)&MD_BOSS))
return 0; //Gangster paradise protection.
default:
if (battle_config.hom_setting&0x4 &&
@@ -1174,17 +1172,15 @@ int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
}
int mob_warpchase_sub(struct block_list *bl,va_list ap) {
- struct block_list *target;
- struct npc_data **target_nd;
- struct npc_data *nd;
- int *min_distance;
int cur_distance;
+ struct block_list *target = va_arg(ap, struct block_list *);
+ struct npc_data **target_nd = va_arg(ap, struct npc_data **);
+ int *min_distance = va_arg(ap, int *);
+ struct npc_data *nd = NULL;
- target= va_arg(ap, struct block_list*);
- target_nd= va_arg(ap, struct npc_data**);
- min_distance= va_arg(ap, int*);
-
- nd = (struct npc_data *)bl;
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_NPC);
+ nd = BL_UCAST(BL_NPC, bl);
if(nd->subtype != WARP)
return 0; //Not a warp
@@ -1687,9 +1683,15 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) {
return true;
}
-int mob_ai_sub_hard_timer(struct block_list *bl, va_list ap) {
- struct mob_data *md = (struct mob_data*)bl;
+int mob_ai_sub_hard_timer(struct block_list *bl, va_list ap)
+{
+ struct mob_data *md = NULL;
int64 tick = va_arg(ap, int64);
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
+
if (mob->ai_sub_hard(md, tick)) {
//Hard AI triggered.
if(!md->state.spotted)
@@ -1900,13 +1902,13 @@ int mob_timer_delete(int tid, int64 tick, int id, intptr_t data) {
*------------------------------------------*/
int mob_deleteslave_sub(struct block_list *bl,va_list ap)
{
- struct mob_data *md;
- int id;
+ struct mob_data *md = NULL;
+ int id = va_arg(ap, int);
nullpo_ret(bl);
- nullpo_ret(md = (struct mob_data *)bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
- id=va_arg(ap,int);
if(md->master_id > 0 && md->master_id == id )
status_kill(bl);
return 0;
@@ -2843,13 +2845,18 @@ void mob_heal(struct mob_data *md, unsigned int heal)
/*==========================================
* Added by RoVeRT
*------------------------------------------*/
-int mob_warpslave_sub(struct block_list *bl,va_list ap) {
- struct mob_data *md=(struct mob_data *)bl;
+int mob_warpslave_sub(struct block_list *bl, va_list ap)
+{
+ struct mob_data *md = NULL;
struct block_list *master;
short x,y,range=0;
master = va_arg(ap, struct block_list*);
range = va_arg(ap, int);
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
+
if(md->master_id!=master->id)
return 0;
@@ -2873,14 +2880,16 @@ int mob_warpslave(struct block_list *bl, int range) {
/*==========================================
* Counts slave sub, currently checking if mob master is the given ID.
*------------------------------------------*/
-int mob_countslave_sub(struct block_list *bl,va_list ap)
+int mob_countslave_sub(struct block_list *bl, va_list ap)
{
- int id;
- struct mob_data *md;
- id=va_arg(ap,int);
+ int id = va_arg(ap, int);
+ struct mob_data *md = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
- md = (struct mob_data *)bl;
- if( md->master_id==id )
+ if (md->master_id == id)
return 1;
return 0;
}
@@ -3064,11 +3073,12 @@ struct block_list *mob_getmasterhpltmaxrate(struct mob_data *md,int rate) {
int mob_getfriendstatus_sub(struct block_list *bl,va_list ap)
{
int cond1,cond2;
- struct mob_data **fr, *md, *mmd;
+ struct mob_data **fr = NULL, *md = NULL, *mmd = NULL;
int flag=0;
nullpo_ret(bl);
- nullpo_ret(md=(struct mob_data *)bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
nullpo_ret(mmd=va_arg(ap,struct mob_data *));
if( mmd->bl.id == bl->id && !(battle_config.mob_ai&0x10) )
diff --git a/src/map/npc.c b/src/map/npc.c
index fc4abb5fa..56fc8cc8a 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -147,8 +147,13 @@ int npc_get_new_npc_id(void) {
}
}
-int npc_isnear_sub(struct block_list* bl, va_list args) {
- struct npc_data *nd = (struct npc_data*)bl;
+int npc_isnear_sub(struct block_list *bl, va_list args)
+{
+ const struct npc_data *nd = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_NPC);
+ nd = BL_UCCAST(BL_NPC, bl);
if( nd->option & (OPTION_HIDE|OPTION_INVISIBLE) )
return 0;
@@ -212,8 +217,9 @@ int npc_enable_sub(struct block_list *bl, va_list ap)
nullpo_ret(bl);
nullpo_ret(nd=va_arg(ap,struct npc_data *));
+
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);
if (nd->option&OPTION_INVISIBLE)
return 1;
@@ -3428,10 +3434,17 @@ void npc_setcells(struct npc_data* nd) {
}
}
-int npc_unsetcells_sub(struct block_list* bl, va_list ap) {
- struct npc_data *nd = (struct npc_data*)bl;
- int id = va_arg(ap,int);
- if (nd->bl.id == id) return 0;
+int npc_unsetcells_sub(struct block_list *bl, va_list ap)
+{
+ struct npc_data *nd = NULL;
+ int id = va_arg(ap, int);
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_NPC);
+ nd = BL_UCAST(BL_NPC, bl);
+
+ if (nd->bl.id == id)
+ return 0;
npc->setcells(nd);
return 1;
}
diff --git a/src/map/npc_chat.c b/src/map/npc_chat.c
index 8950df1ee..db300e362 100644
--- a/src/map/npc_chat.c
+++ b/src/map/npc_chat.c
@@ -339,15 +339,20 @@ void npc_chat_finalize(struct npc_data* nd)
*/
int npc_chat_sub(struct block_list* bl, va_list ap)
{
- struct npc_data *nd = (struct npc_data *) bl;
- struct npc_parse *npcParse = nd->chatdb;
- char* msg;
+ struct npc_data *nd = NULL;
+ struct npc_parse *npcParse = NULL;
+ char *msg;
int len, i;
struct map_session_data* sd;
struct npc_label_list* lst;
struct pcrematch_set* pcreset;
struct pcrematch_entry* e;
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_NPC);
+ nd = BL_UCAST(BL_NPC, bl);
+ npcParse = nd->chatdb;
+
// Not interested in anything you might have to say...
if (npcParse == NULL || npcParse->active == NULL)
return 0;
diff --git a/src/map/party.c b/src/map/party.c
index 7d44a61c5..320370c33 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -1049,7 +1049,11 @@ int party_send_dot_remove(struct map_session_data *sd)
// party_foreachsamemap(party->sub_count, sd, 0, &c);
int party_sub_count(struct block_list *bl, va_list ap)
{
- struct map_session_data *sd = (struct map_session_data *)bl;
+ const struct map_session_data *sd = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCCAST(BL_PC, bl);
if (sd->state.autotrade)
return 0;
@@ -1112,7 +1116,11 @@ int party_vforeachsamemap(int (*func)(struct block_list*,va_list), struct map_se
// Special check for Minstrel's and Wanderer's chorus skills.
int party_sub_count_chorus(struct block_list *bl, va_list ap)
{
- struct map_session_data *sd = (struct map_session_data *)bl;
+ const struct map_session_data *sd = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCCAST(BL_PC, bl);
if (sd->state.autotrade)
return 0;
diff --git a/src/map/pc.c b/src/map/pc.c
index 7fc67d668..cf7bc6dcb 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -286,14 +286,17 @@ int pc_delspiritball(struct map_session_data *sd,int count,int type)
}
return 0;
}
-int pc_check_banding( struct block_list *bl, va_list ap ) {
+int pc_check_banding(struct block_list *bl, va_list ap)
+{
int *c, *b_sd;
struct block_list *src;
- struct map_session_data *tsd;
+ const struct map_session_data *tsd;
struct status_change *sc;
nullpo_ret(bl);
- nullpo_ret(tsd = (struct map_session_data*)bl);
+ Assert_ret(bl->type == BL_PC);
+ tsd = BL_UCCAST(BL_PC, bl);
+
nullpo_ret(src = va_arg(ap,struct block_list *));
c = va_arg(ap,int *);
b_sd = va_arg(ap, int *);
@@ -5224,7 +5227,7 @@ void pc_bound_clear(struct map_session_data *sd, enum e_item_bound_type type) {
*------------------------------------------*/
int pc_show_steal(struct block_list *bl,va_list ap)
{
- struct map_session_data *sd;
+ struct map_session_data *sd = NULL, *tsd = NULL;
int itemid;
struct item_data *item=NULL;
@@ -5233,11 +5236,16 @@ int pc_show_steal(struct block_list *bl,va_list ap)
sd=va_arg(ap,struct map_session_data *);
itemid=va_arg(ap,int);
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ tsd = BL_UCAST(BL_PC, bl);
+ nullpo_ret(sd);
+
if((item=itemdb->exists(itemid))==NULL)
sprintf(output,"%s stole an Unknown Item (id: %i).",sd->status.name, itemid);
else
sprintf(output,"%s stole %s.",sd->status.name,item->jname);
- clif->message( ((struct map_session_data *)bl)->fd, output);
+ clif->message(tsd->fd, output);
return 0;
}
@@ -8323,11 +8331,12 @@ int pc_percentheal(struct map_session_data *sd,int hp,int sp)
int jobchange_killclone(struct block_list *bl, va_list ap)
{
- struct mob_data *md;
- int flag;
- md = (struct mob_data *)bl;
- nullpo_ret(md);
- flag = va_arg(ap, int);
+ struct mob_data *md = NULL;
+ int flag = va_arg(ap, int);
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
if (md->master_id && md->special_state.clone && md->master_id == flag)
status_kill(&md->bl);
@@ -9999,12 +10008,15 @@ int pc_checkitem(struct map_session_data *sd)
/*==========================================
* Update PVP rank for sd1 in cmp to sd2
*------------------------------------------*/
-int pc_calc_pvprank_sub(struct block_list *bl,va_list ap)
+int pc_calc_pvprank_sub(struct block_list *bl, va_list ap)
{
- struct map_session_data *sd1,*sd2;
+ struct map_session_data *sd1 = NULL;
+ struct map_session_data *sd2 = va_arg(ap,struct map_session_data *);
- sd1=(struct map_session_data *)bl;
- sd2=va_arg(ap,struct map_session_data *);
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd1 = BL_UCAST(BL_PC, bl);
+ nullpo_ret(sd2);
if (pc_isinvisible(sd1) ||pc_isinvisible(sd2)) {
// cannot register pvp rank for hidden GMs
diff --git a/src/map/pet.c b/src/map/pet.c
index 18a5ba915..8726b611b 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -964,15 +964,16 @@ int pet_ai_hard(int tid, int64 tick, int id, intptr_t data) {
return 0;
}
-int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
+int pet_ai_sub_hard_lootsearch(struct block_list *bl, va_list ap)
{
- struct pet_data* pd;
- struct flooritem_data *fitem = (struct flooritem_data *)bl;
- struct block_list **target;
- int sd_charid =0;
-
- pd=va_arg(ap,struct pet_data *);
- target=va_arg(ap,struct block_list**);
+ struct pet_data *pd = va_arg(ap,struct pet_data *);
+ struct block_list **target = va_arg(ap,struct block_list**);
+ struct flooritem_data *fitem = NULL;
+ int sd_charid = 0;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_ITEM);
+ fitem = BL_UCAST(BL_ITEM, bl);
sd_charid = fitem->first_get_charid;
diff --git a/src/map/quest.c b/src/map/quest.c
index bec358187..0dbea56f8 100644
--- a/src/map/quest.c
+++ b/src/map/quest.c
@@ -252,15 +252,15 @@ int quest_delete(struct map_session_data *sd, int quest_id)
* int Party ID
* int Mob ID
*/
-int quest_update_objective_sub(struct block_list *bl, va_list ap) {
- struct map_session_data *sd;
- int mob_id, party_id;
+int quest_update_objective_sub(struct block_list *bl, va_list ap)
+{
+ struct map_session_data *sd = NULL;
+ int party_id = va_arg(ap, int);
+ int mob_id = va_arg(ap, int);
nullpo_ret(bl);
- nullpo_ret(sd = (struct map_session_data *)bl);
-
- party_id = va_arg(ap,int);
- mob_id = va_arg(ap,int);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
if( !sd->avail_quests )
return 0;
diff --git a/src/map/script.c b/src/map/script.c
index 800b58428..214cb4914 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -5849,10 +5849,15 @@ BUILDIN(warp)
/*==========================================
* Warp a specified area
*------------------------------------------*/
-int buildin_areawarp_sub(struct block_list *bl,va_list ap)
+int buildin_areawarp_sub(struct block_list *bl, va_list ap)
{
int x2,y2,x3,y3;
unsigned int index;
+ struct map_session_data *sd = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
index = va_arg(ap,unsigned int);
x2 = va_arg(ap,int);
@@ -5861,7 +5866,7 @@ int buildin_areawarp_sub(struct block_list *bl,va_list ap)
y3 = va_arg(ap,int);
if (index == 0) {
- pc->randomwarp((struct map_session_data *)bl, CLR_TELEPORT);
+ pc->randomwarp(sd, CLR_TELEPORT);
} else if (x3 != 0 && y3 != 0) {
int max, tx, ty, j = 0;
@@ -5876,9 +5881,9 @@ int buildin_areawarp_sub(struct block_list *bl,va_list ap)
j++;
} while (map->getcell(index, bl, tx, ty, CELL_CHKNOPASS) && j < max);
- pc->setpos((struct map_session_data *)bl, index, tx, ty, CLR_OUTSIGHT);
+ pc->setpos(sd, index, tx, ty, CLR_OUTSIGHT);
} else {
- pc->setpos((struct map_session_data *)bl,index,x2,y2,CLR_OUTSIGHT);
+ pc->setpos(sd, index, x2, y2, CLR_OUTSIGHT);
}
return 0;
}
@@ -5924,14 +5929,20 @@ BUILDIN(areawarp)
/*==========================================
* areapercentheal <map>,<x1>,<y1>,<x2>,<y2>,<hp>,<sp>
*------------------------------------------*/
-int buildin_areapercentheal_sub(struct block_list *bl,va_list ap)
+int buildin_areapercentheal_sub(struct block_list *bl, va_list ap)
{
- int hp, sp;
- hp = va_arg(ap, int);
- sp = va_arg(ap, int);
- pc->percentheal((struct map_session_data *)bl, hp, sp);
+ int hp = va_arg(ap, int);
+ int sp = va_arg(ap, int);
+ struct map_session_data *sd = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
+
+ pc->percentheal(sd, hp, sp);
return 0;
}
+
BUILDIN(areapercentheal) {
int hp,sp,m;
const char *mapname;
@@ -9872,12 +9883,16 @@ BUILDIN(areamonster) {
/*==========================================
* KillMonster subcheck, verify if mob to kill ain't got an even to handle, could be force kill by allflag
*------------------------------------------*/
-int buildin_killmonster_sub_strip(struct block_list *bl,va_list ap)
+int buildin_killmonster_sub_strip(struct block_list *bl, va_list ap)
{
//same fix but with killmonster instead - stripping events from mobs.
- struct mob_data *md = (struct mob_data *)bl;
- char *event=va_arg(ap,char *);
- int allflag=va_arg(ap,int);
+ struct mob_data *md = NULL;
+ char *event = va_arg(ap,char *);
+ int allflag = va_arg(ap,int);
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
md->state.npc_killmonster = 1;
@@ -9891,11 +9906,15 @@ int buildin_killmonster_sub_strip(struct block_list *bl,va_list ap)
md->state.npc_killmonster = 0;
return 0;
}
-int buildin_killmonster_sub(struct block_list *bl,va_list ap)
+int buildin_killmonster_sub(struct block_list *bl, va_list ap)
{
- struct mob_data *md = (struct mob_data *)bl;
- char *event=va_arg(ap,char *);
- int allflag=va_arg(ap,int);
+ struct mob_data *md = NULL;
+ char *event = va_arg(ap,char *);
+ int allflag = va_arg(ap,int);
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
if(!allflag) {
if(strcmp(event,md->npc_event)==0)
@@ -10665,17 +10684,22 @@ BUILDIN(getareausers)
/*==========================================
*------------------------------------------*/
-int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
+int buildin_getareadropitem_sub(struct block_list *bl, va_list ap)
{
- int item=va_arg(ap,int);
- int *amount=va_arg(ap,int *);
- struct flooritem_data *drop=(struct flooritem_data *)bl;
+ int item = va_arg(ap, int);
+ int *amount = va_arg(ap, int *);
+ const struct flooritem_data *drop = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_ITEM);
+ drop = BL_UCCAST(BL_ITEM, bl);
- if(drop->item_data.nameid==item)
- (*amount)+=drop->item_data.amount;
+ if (drop->item_data.nameid == item)
+ (*amount) += drop->item_data.amount;
return 0;
}
+
BUILDIN(getareadropitem) {
const char *str;
int16 m,x0,y0,x1,y1;
@@ -11653,7 +11677,12 @@ BUILDIN(getmapflag)
/* pvp timer handling */
int script_mapflag_pvp_sub(struct block_list *bl, va_list ap)
{
- struct map_session_data *sd = (struct map_session_data *)bl;
+ struct map_session_data *sd = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
+
if (sd->pvp_timer == INVALID_TIMER) {
sd->pvp_timer = timer->add(timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0);
sd->pvp_rank = 0;
@@ -11666,6 +11695,7 @@ int script_mapflag_pvp_sub(struct block_list *bl, va_list ap)
clif->maptypeproperty2(&sd->bl,SELF);
return 0;
}
+
BUILDIN(setmapflag) {
int16 m,i;
const char *str, *val2 = NULL;
@@ -11903,7 +11933,12 @@ BUILDIN(pvpon)
int buildin_pvpoff_sub(struct block_list *bl, va_list ap)
{
- struct map_session_data *sd = (struct map_session_data *)bl;
+ struct map_session_data *sd = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
+
clif->pvpset(sd, 0, 0, 2);
if (sd->pvp_timer != INVALID_TIMER) {
timer->delete(sd->pvp_timer, pc->calc_pvprank_timer);
@@ -12029,9 +12064,13 @@ int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list ap)
return 1;
}
-int buildin_maprespawnguildid_sub_mob(struct block_list *bl,va_list ap)
+int buildin_maprespawnguildid_sub_mob(struct block_list *bl, va_list ap)
{
- struct mob_data *md=(struct mob_data *)bl;
+ struct mob_data *md = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
if (md->guardian_data == NULL && md->class_ != MOBID_EMPELIUM)
status_kill(bl);
@@ -12463,9 +12502,15 @@ BUILDIN(mapwarp) {
}
// Added by RoVeRT
-int buildin_mobcount_sub(struct block_list *bl,va_list ap) {
- char *event=va_arg(ap,char *);
- struct mob_data *md = ((struct mob_data *)bl);
+int buildin_mobcount_sub(struct block_list *bl, va_list ap)
+{
+ char *event = va_arg(ap,char *);
+ const struct mob_data *md = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCCAST(BL_MOB, bl);
+
if( md->status.hp > 0 && (!event || strcmp(event,md->npc_event) == 0) )
return 1;
return 0;
@@ -13263,12 +13308,17 @@ BUILDIN(soundeffect)
return true;
}
-int soundeffect_sub(struct block_list* bl,va_list ap)
+int soundeffect_sub(struct block_list *bl, va_list ap)
{
- char* name = va_arg(ap,char*);
- int type = va_arg(ap,int);
+ struct map_session_data *sd = NULL;
+ char *name = va_arg(ap, char *);
+ int type = va_arg(ap, int);
- clif->soundeffect((struct map_session_data *)bl, bl, name, type);
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
+
+ clif->soundeffect(sd, bl, name, type);
return true;
}
@@ -17950,13 +18000,18 @@ BUILDIN(has_instance) {
script_pushconststr(st, map->list[m].name);
return true;
}
-int buildin_instance_warpall_sub(struct block_list *bl,va_list ap)
+
+int buildin_instance_warpall_sub(struct block_list *bl, va_list ap)
{
- struct map_session_data *sd = (struct map_session_data*)bl;
+ struct map_session_data *sd = NULL;
int map_index = va_arg(ap,int);
int x = va_arg(ap,int);
int y = va_arg(ap,int);
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
+
pc->setpos(sd,map_index,x,y,CLR_TELEPORT);
return 0;
@@ -18126,9 +18181,9 @@ BUILDIN(setfont)
return true;
}
-int buildin_mobuseskill_sub(struct block_list *bl,va_list ap)
+int buildin_mobuseskill_sub(struct block_list *bl, va_list ap)
{
- struct mob_data *md = (struct mob_data *)bl;
+ struct mob_data *md = NULL;
struct block_list *tbl;
int mobid = va_arg(ap,int);
uint16 skill_id = va_arg(ap,int);
@@ -18138,6 +18193,10 @@ int buildin_mobuseskill_sub(struct block_list *bl,va_list ap)
int emotion = va_arg(ap,int);
int target = va_arg(ap,int);
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCAST(BL_MOB, bl);
+
if( md->class_ != mobid )
return 0;
diff --git a/src/map/skill.c b/src/map/skill.c
index b82e3864b..1656ddeb0 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -2938,15 +2938,18 @@ int skill_area_sub(struct block_list *bl, va_list ap) {
return 0;
}
-int skill_check_unit_range_sub (struct block_list *bl, va_list ap) {
- struct skill_unit *su;
+int skill_check_unit_range_sub(struct block_list *bl, va_list ap)
+{
+ const struct skill_unit *su = NULL;
uint16 skill_id,g_skill_id;
- su = (struct skill_unit *)bl;
+ nullpo_ret(bl);
- if(bl->prev == NULL || bl->type != BL_SKILL)
+ if (bl->type != BL_SKILL || bl->prev == NULL)
return 0;
+ su = BL_UCCAST(BL_SKILL, bl);
+
if(!su->alive)
return 0;
@@ -3032,7 +3035,7 @@ int skill_check_unit_range2_sub (struct block_list *bl, va_list ap) {
if( skill_id == HP_BASILICA && bl->type == BL_PC )
return 0;
- if (skill_id == AM_DEMONSTRATION && bl->type == BL_MOB && ((struct mob_data *)bl)->class_ == MOBID_EMPELIUM)
+ if (skill_id == AM_DEMONSTRATION && bl->type == BL_MOB && BL_UCCAST(BL_MOB, bl)->class_ == MOBID_EMPELIUM)
return 0; //Allow casting Bomb/Demonstration Right under emperium [Skotlex]
return 1;
}
@@ -3506,11 +3509,16 @@ bool skill_cleartimerskill_exception(int skill_id)
return false;
}
-int skill_activate_reverberation(struct block_list *bl, va_list ap) {
- struct skill_unit *su = (struct skill_unit *)bl;
- struct skill_unit_group *sg;
- if( bl->type != BL_SKILL )
+int skill_activate_reverberation(struct block_list *bl, va_list ap)
+{
+ struct skill_unit *su = NULL;
+ struct skill_unit_group *sg = NULL;
+
+ nullpo_ret(bl);
+ if (bl->type != BL_SKILL)
return 0;
+ su = BL_UCAST(BL_SKILL, bl);
+
if( su->alive && (sg = su->group) != NULL && sg->skill_id == WM_REVERBERATION && sg->unit_id == UNT_REVERBERATION ) {
int64 tick = timer->gettick();
clif->changetraplook(bl,UNT_USED_TRAPS);
@@ -3521,8 +3529,14 @@ int skill_activate_reverberation(struct block_list *bl, va_list ap) {
return 0;
}
-int skill_reveal_trap (struct block_list *bl, va_list ap) {
- struct skill_unit *su = (struct skill_unit *)bl;
+int skill_reveal_trap(struct block_list *bl, va_list ap)
+{
+ struct skill_unit *su = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_SKILL);
+ su = BL_UCAST(BL_SKILL, bl);
+
if (su->alive && su->group && skill->get_inf2(su->group->skill_id)&INF2_TRAP) { //Reveal trap.
//Change look is not good enough, the client ignores it as an actual trap still. [Skotlex]
//clif->changetraplook(bl, su->group->unit_id);
@@ -10051,11 +10065,16 @@ int skill_castend_pos(int tid, int64 tick, int id, intptr_t data)
return 0;
}
+
static int check_npc_chaospanic(struct block_list *bl, va_list args)
{
- struct npc_data *nd = (struct npc_data *)bl;
+ const struct npc_data *nd = NULL;
- if( nd->option&(OPTION_HIDE|OPTION_INVISIBLE) || nd->class_ != 45 )
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_NPC);
+ nd = BL_UCCAST(BL_NPC, bl);
+
+ if (nd->option&(OPTION_HIDE|OPTION_INVISIBLE) || nd->class_ != WARP_CLASS)
return 0;
return 1;
@@ -10972,11 +10991,16 @@ bool skill_castend_pos2_unknown(struct block_list* src, int *x, int *y, uint16 *
}
/// transforms 'target' skill unit into dissonance (if conditions are met)
-int skill_dance_overlap_sub(struct block_list* bl, va_list ap) {
- struct skill_unit* target = (struct skill_unit*)bl;
- struct skill_unit* src = va_arg(ap, struct skill_unit*);
+int skill_dance_overlap_sub(struct block_list *bl, va_list ap)
+{
+ struct skill_unit *target = NULL;
+ struct skill_unit *src = va_arg(ap, struct skill_unit*);
int flag = va_arg(ap, int);
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_SKILL);
+ target = BL_UCAST(BL_SKILL, bl);
+
if (src == target)
return 0;
if (!target->group || !(target->group->state.song_dance&0x1))
@@ -12820,21 +12844,21 @@ int skill_unit_ondamaged(struct skill_unit *src, struct block_list *bl, int64 da
/*==========================================
*
*------------------------------------------*/
-int skill_check_condition_char_sub (struct block_list *bl, va_list ap) {
- int *c, skill_id;
- struct block_list *src;
- struct map_session_data *sd;
- struct map_session_data *tsd;
- int *p_sd; //Contains the list of characters found.
+int skill_check_condition_char_sub (struct block_list *bl, va_list ap)
+{
+ struct map_session_data *tsd = NULL;
+ struct block_list *src = va_arg(ap, struct block_list *);
+ struct map_session_data *sd = NULL;
+ int *c = va_arg(ap, int *);
+ int *p_sd = va_arg(ap, int *); //Contains the list of characters found.
+ int skill_id = va_arg(ap, int);
nullpo_ret(bl);
- nullpo_ret(tsd=(struct map_session_data*)bl);
- nullpo_ret(src=va_arg(ap,struct block_list *));
- nullpo_ret(sd=(struct map_session_data*)src);
-
- c=va_arg(ap,int *);
- p_sd = va_arg(ap, int *);
- skill_id = va_arg(ap,int);
+ nullpo_ret(src);
+ Assert_ret(bl->type == BL_PC);
+ Assert_ret(src->type == BL_PC);
+ tsd = BL_UCAST(BL_PC, bl);
+ sd = BL_UCAST(BL_PC, src);
if ( ((skill_id != PR_BENEDICTIO && *c >=1) || *c >=2) && !(skill->get_inf2(skill_id)&INF2_CHORUS_SKILL) )
return 0; //Partner found for ensembles, or the two companions for Benedictio. [Skotlex]
@@ -12962,15 +12986,18 @@ int skill_check_pc_partner (struct map_session_data *sd, uint16 skill_id, uint16
/*==========================================
*
*------------------------------------------*/
-int skill_check_condition_mob_master_sub (struct block_list *bl, va_list ap) {
- int *c,src_id,mob_class,skill_id;
- struct mob_data *md;
+int skill_check_condition_mob_master_sub (struct block_list *bl, va_list ap)
+{
+ const struct mob_data *md = NULL;
+ int src_id = va_arg(ap, int);
+ int mob_class = va_arg(ap, int);
+ int skill_id = va_arg(ap, int);
+ int *c = va_arg(ap, int *);
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_MOB);
+ md = BL_UCCAST(BL_MOB, bl);
- md=(struct mob_data*)bl;
- src_id=va_arg(ap,int);
- mob_class=va_arg(ap,int);
- skill_id=va_arg(ap,int);
- c=va_arg(ap,int *);
if( md->master_id != src_id
|| md->special_state.ai != (skill_id == AM_SPHEREMINE?AI_SPHERE:skill_id == KO_ZANZOU?AI_ZANZOU:skill_id == MH_SUMMON_LEGION?AI_ATTACK:AI_FLORA) )
return 0; //Non alchemist summoned mobs have nothing to do here.
@@ -15313,10 +15340,14 @@ int skill_autospell (struct map_session_data *sd, uint16 skill_id)
/*==========================================
* Sitting skills functions.
*------------------------------------------*/
-int skill_sit_count (struct block_list *bl, va_list ap) {
- struct map_session_data *sd;
- int type =va_arg(ap,int);
- sd=(struct map_session_data*)bl;
+int skill_sit_count(struct block_list *bl, va_list ap)
+{
+ int type = va_arg(ap, int);
+ struct map_session_data *sd = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
if(!pc_issit(sd))
return 0;
@@ -15330,11 +15361,14 @@ int skill_sit_count (struct block_list *bl, va_list ap) {
return 0;
}
-int skill_sit_in (struct block_list *bl, va_list ap) {
- struct map_session_data *sd;
- int type =va_arg(ap,int);
+int skill_sit_in(struct block_list *bl, va_list ap)
+{
+ int type = va_arg(ap, int);
+ struct map_session_data *sd = NULL;
- sd=(struct map_session_data*)bl;
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
if(!pc_issit(sd))
return 0;
@@ -15351,10 +15385,15 @@ int skill_sit_in (struct block_list *bl, va_list ap) {
return 0;
}
-int skill_sit_out (struct block_list *bl, va_list ap) {
- struct map_session_data *sd;
- int type =va_arg(ap,int);
- sd=(struct map_session_data*)bl;
+int skill_sit_out(struct block_list *bl, va_list ap)
+{
+ int type = va_arg(ap, int);
+ struct map_session_data *sd = NULL;
+
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_PC);
+ sd = BL_UCAST(BL_PC, bl);
+
if(sd->state.gangsterparadise && type&1)
sd->state.gangsterparadise=0;
if(sd->state.rest && type&2) {
@@ -15405,7 +15444,8 @@ int skill_sit (struct map_session_data *sd, int type)
/*==========================================
*
*------------------------------------------*/
-int skill_frostjoke_scream(struct block_list *bl, va_list ap) {
+int skill_frostjoke_scream(struct block_list *bl, va_list ap)
+{
struct block_list *src;
uint16 skill_id,skill_lv;
int64 tick;
@@ -15421,9 +15461,9 @@ int skill_frostjoke_scream(struct block_list *bl, va_list ap) {
if (src == bl || status->isdead(bl))
return 0;
if (bl->type == BL_PC) {
- struct map_session_data *sd = (struct map_session_data *)bl;
- if (sd && (pc_isinvisible(sd) || pc_ismadogear(sd)))
- return 0;//Frost Joke / Scream cannot target invisible or MADO Gear characters [Ind]
+ const struct map_session_data *sd = BL_UCCAST(BL_PC, bl);
+ if (pc_isinvisible(sd) || pc_ismadogear(sd))
+ return 0; //Frost Joke / Scream cannot target invisible or MADO Gear characters [Ind]
}
//It has been reported that Scream/Joke works the same regardless of woe-setting. [Skotlex]
if(battle->check_target(src,bl,BCT_ENEMY) > 0)
@@ -15555,15 +15595,15 @@ struct skill_unit_group *skill_locate_element_field(struct block_list *bl) {
}
// for graffiti cleaner [Valaris]
-int skill_graffitiremover (struct block_list *bl, va_list ap) {
- struct skill_unit *su=NULL;
+int skill_graffitiremover(struct block_list *bl, va_list ap)
+{
+ struct skill_unit *su = NULL;
nullpo_ret(bl);
- if(bl->type != BL_SKILL)
+ if (bl->type != BL_SKILL)
return 0;
-
- su = ((struct skill_unit *)bl);
+ su = BL_UCAST(BL_SKILL, bl);
if((su->group) && (su->group->unit_id == UNT_GRAFFITI))
skill->delunit(su);
@@ -15571,30 +15611,35 @@ int skill_graffitiremover (struct block_list *bl, va_list ap) {
return 0;
}
-int skill_greed (struct block_list *bl, va_list ap) {
- struct block_list *src;
+int skill_greed(struct block_list *bl, va_list ap)
+{
+ struct block_list *src = va_arg(ap, struct block_list *);
nullpo_ret(bl);
- nullpo_ret(src = va_arg(ap, struct block_list *));
+ nullpo_ret(src);
- if(src->type == BL_PC && bl->type==BL_ITEM )
- pc->takeitem((struct map_session_data *)src, (struct flooritem_data *)bl);
+ if (src->type == BL_PC && bl->type == BL_ITEM) {
+ struct map_session_data *sd = BL_UCAST(BL_PC, src);
+ struct flooritem_data *fitem = BL_UCAST(BL_ITEM, bl);
+ pc->takeitem(sd, fitem);
+ }
return 0;
}
+
//For Ranger's Detonator [Jobbie/3CeAM]
-int skill_detonator(struct block_list *bl, va_list ap) {
- struct skill_unit *su=NULL;
- struct block_list *src;
+int skill_detonator(struct block_list *bl, va_list ap)
+{
+ struct skill_unit *su = NULL;
+ struct block_list *src = va_arg(ap,struct block_list *);
int unit_id;
nullpo_ret(bl);
- src = va_arg(ap,struct block_list *);
+ nullpo_ret(src);
- if( bl->type != BL_SKILL )
+ if (bl->type != BL_SKILL)
return 0;
-
- su = (struct skill_unit *)bl;
+ su = BL_UCAST(BL_SKILL, bl);
if( !su->group || su->group->src_id != src->id )
return 0;
@@ -15634,16 +15679,21 @@ int skill_detonator(struct block_list *bl, va_list ap) {
/*==========================================
*
*------------------------------------------*/
-int skill_cell_overlap(struct block_list *bl, va_list ap) {
+int skill_cell_overlap(struct block_list *bl, va_list ap)
+{
uint16 skill_id;
int *alive;
- struct skill_unit *su;
+ struct skill_unit *su = NULL;
skill_id = va_arg(ap,int);
alive = va_arg(ap,int *);
- su = (struct skill_unit *)bl;
- if( su == NULL || su->group == NULL || (*alive) == 0 )
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_SKILL);
+ nullpo_ret(alive);
+ su = BL_UCAST(BL_SKILL, bl);
+
+ if (bl->type != BL_SKILL || su->group == NULL || (*alive) == 0)
return 0;
if( su->group->state.guildaura ) /* guild auras are not canceled! */
@@ -15727,38 +15777,44 @@ int skill_cell_overlap(struct block_list *bl, va_list ap) {
/*==========================================
*
*------------------------------------------*/
-int skill_chastle_mob_changetarget(struct block_list *bl,va_list ap)
+int skill_chastle_mob_changetarget(struct block_list *bl, va_list ap)
{
- struct mob_data* md;
- struct unit_data*ud = unit->bl2ud(bl);
- struct block_list *from_bl;
- struct block_list *to_bl;
- md = (struct mob_data*)bl;
- from_bl = va_arg(ap,struct block_list *);
- to_bl = va_arg(ap,struct block_list *);
-
- if(ud && ud->target == from_bl->id)
+ struct unit_data *ud = unit->bl2ud(bl);
+ struct block_list *from_bl = va_arg(ap, struct block_list *);
+ struct block_list *to_bl = va_arg(ap, struct block_list *);
+
+ nullpo_ret(bl);
+ nullpo_ret(from_bl);
+ nullpo_ret(to_bl);
+
+ if (ud != NULL && ud->target == from_bl->id)
ud->target = to_bl->id;
- if(md->bl.type == BL_MOB && md->target_id == from_bl->id)
- md->target_id = to_bl->id;
+ if (bl->type == BL_MOB) {
+ struct mob_data *md = BL_UCAST(BL_MOB, bl);
+ if (md->target_id == from_bl->id)
+ md->target_id = to_bl->id;
+ }
return 0;
}
/*==========================================
*
*------------------------------------------*/
-int skill_trap_splash(struct block_list *bl, va_list ap) {
- struct block_list *src;
- int64 tick;
- struct skill_unit *src_su;
+int skill_trap_splash(struct block_list *bl, va_list ap)
+{
+ struct block_list *src = va_arg(ap, struct block_list *);
+ int64 tick = va_arg(ap, int64);
+ struct skill_unit *src_su = NULL;
struct skill_unit_group *sg;
struct block_list *ss;
- src = va_arg(ap,struct block_list *);
- src_su = (struct skill_unit *)src;
- tick = va_arg(ap,int64);
- if( !src_su->alive || bl->prev == NULL )
+ nullpo_ret(bl);
+ nullpo_ret(src);
+ Assert_ret(src->type == BL_SKILL);
+ src_su = BL_UCAST(BL_SKILL, src);
+
+ if (!src_su->alive || bl->prev == NULL)
return 0;
nullpo_ret(sg = src_su->group);
@@ -15811,21 +15867,24 @@ int skill_trap_splash(struct block_list *bl, va_list ap) {
break;
case UNT_FIRINGTRAP:
case UNT_ICEBOUNDTRAP:
- if( src->id == bl->id ) break;
- if( bl->type == BL_SKILL ){
- struct skill_unit *su = (struct skill_unit *)bl;
- if( su->group->unit_id == UNT_USED_TRAPS )
+ if (src->id == bl->id)
+ break;
+ if (bl->type == BL_SKILL) {
+ struct skill_unit *su = BL_UCAST(BL_SKILL, bl);
+ if (su->group->unit_id == UNT_USED_TRAPS)
break;
}
+ /* Fall through */
case UNT_CLUSTERBOMB:
if( ss != bl )
skill->attack(BF_MISC,ss,src,bl,sg->skill_id,sg->skill_lv,tick,sg->val1|SD_LEVEL);
break;
case UNT_CLAYMORETRAP:
- if( src->id == bl->id ) break;
- if( bl->type == BL_SKILL ){
- struct skill_unit *su = (struct skill_unit *)bl;
- switch( su->group->unit_id ){
+ if (src->id == bl->id)
+ break;
+ if (bl->type == BL_SKILL) {
+ struct skill_unit *su = BL_UCAST(BL_SKILL, bl);
+ switch (su->group->unit_id) {
case UNT_CLAYMORETRAP:
case UNT_LANDMINE:
case UNT_BLASTMINE:
@@ -15841,6 +15900,7 @@ int skill_trap_splash(struct block_list *bl, va_list ap) {
}
break;
}
+ /* Fall through */
default:
skill->attack(skill->get_type(sg->skill_id),ss,src,bl,sg->skill_id,sg->skill_lv,tick,0);
break;
@@ -16651,9 +16711,10 @@ int skill_unit_timer(int tid, int64 tick, int id, intptr_t data) {
/*==========================================
*
*------------------------------------------*/
-int skill_unit_move_sub(struct block_list* bl, va_list ap) {
- struct skill_unit* su = (struct skill_unit *)bl;
- struct skill_unit_group* group = su->group;
+int skill_unit_move_sub(struct block_list* bl, va_list ap)
+{
+ struct skill_unit *su = NULL;
+ struct skill_unit_group *group = NULL;
struct block_list* target = va_arg(ap,struct block_list*);
int64 tick = va_arg(ap,int64);
@@ -16663,6 +16724,10 @@ int skill_unit_move_sub(struct block_list* bl, va_list ap) {
uint16 skill_id;
int i;
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_SKILL);
+ su = BL_UCAST(BL_SKILL, bl);
+ group = su->group;
nullpo_ret(group);
if( !su->alive || target->prev == NULL )
@@ -17862,13 +17927,15 @@ int skill_changematerial(struct map_session_data *sd, int n, unsigned short *ite
/**
* for Royal Guard's LG_TRAMPLE
**/
-int skill_destroy_trap(struct block_list *bl, va_list ap) {
- struct skill_unit *su = (struct skill_unit *)bl;
+int skill_destroy_trap(struct block_list *bl, va_list ap)
+{
+ struct skill_unit *su = NULL;
struct skill_unit_group *sg;
- int64 tick;
+ int64 tick = va_arg(ap, int64);
- nullpo_ret(su);
- tick = va_arg(ap, int64);
+ nullpo_ret(bl);
+ Assert_ret(bl->type == BL_SKILL);
+ su = BL_UCAST(BL_SKILL, bl);
if (su->alive && (sg = su->group) != NULL && skill->get_inf2(sg->skill_id)&INF2_TRAP) {
switch( sg->unit_id ) {
diff --git a/src/map/status.c b/src/map/status.c
index e29e27236..cfae64536 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -11783,9 +11783,12 @@ int status_change_timer_sub(struct block_list* bl, va_list ap) {
if (battle->check_target( src, bl, BCT_ENEMY ) > 0
&& status->check_skilluse(src, bl, WZ_SIGHTBLASTER, 2)
) {
- struct skill_unit *su = (struct skill_unit *)bl;
- if (sce && skill->attack(BF_MAGIC,src,src,bl,WZ_SIGHTBLASTER,sce->val1,tick,0x4000)
- && (!su || !su->group || !(skill->get_inf2(su->group->skill_id)&INF2_TRAP))) { // The hit is not counted if it's against a trap
+ const struct skill_unit *su = BL_CCAST(BL_SKILL, bl);
+ if (sce != NULL
+ && skill->attack(BF_MAGIC,src,src,bl,WZ_SIGHTBLASTER,sce->val1,tick,0x4000)
+ && (su == NULL || su->group == NULL || !(skill->get_inf2(su->group->skill_id)&INF2_TRAP))
+ ) {
+ // The hit is not counted if it's against a trap
sce->val2 = 0; // This signals it to end.
} else if ((bl->type&BL_SKILL) && sce && sce->val4%2 == 0) {
//Remove trap immunity temporarily so it triggers if you still stand on it