diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-06 17:36:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-06 17:36:33 +0300 |
commit | d5199cee806fb9f18987dea0c3a20a2d381927ca (patch) | |
tree | 135f15dadc1c7964b3078fd8223771f94d1ed0e6 | |
parent | 756be9835054a3b2b8ebace388546fa15ffd4a92 (diff) | |
parent | e3eac134b1607cfe78331e298aaa20b260662571 (diff) | |
download | hercules-d5199cee806fb9f18987dea0c3a20a2d381927ca.tar.gz hercules-d5199cee806fb9f18987dea0c3a20a2d381927ca.tar.bz2 hercules-d5199cee806fb9f18987dea0c3a20a2d381927ca.tar.xz hercules-d5199cee806fb9f18987dea0c3a20a2d381927ca.zip |
Merge pull request #1034 from HerculesWS/bl_cast
Changed all TBL_* to the appropriate structs
-rw-r--r-- | src/map/atcommand.c | 126 | ||||
-rw-r--r-- | src/map/battle.c | 490 | ||||
-rw-r--r-- | src/map/battleground.c | 39 | ||||
-rw-r--r-- | src/map/chat.c | 30 | ||||
-rw-r--r-- | src/map/chrif.c | 16 | ||||
-rw-r--r-- | src/map/chrif.h | 6 | ||||
-rw-r--r-- | src/map/clif.c | 555 | ||||
-rw-r--r-- | src/map/duel.c | 2 | ||||
-rw-r--r-- | src/map/elemental.c | 3 | ||||
-rw-r--r-- | src/map/guild.c | 26 | ||||
-rw-r--r-- | src/map/guild.h | 6 | ||||
-rw-r--r-- | src/map/homunculus.c | 5 | ||||
-rw-r--r-- | src/map/instance.c | 28 | ||||
-rw-r--r-- | src/map/intif.c | 12 | ||||
-rw-r--r-- | src/map/itemdb.c | 2 | ||||
-rw-r--r-- | src/map/map.c | 311 | ||||
-rw-r--r-- | src/map/map.h | 101 | ||||
-rw-r--r-- | src/map/mercenary.c | 3 | ||||
-rw-r--r-- | src/map/mob.c | 160 | ||||
-rw-r--r-- | src/map/npc.c | 98 | ||||
-rw-r--r-- | src/map/npc_chat.c | 35 | ||||
-rw-r--r-- | src/map/party.c | 30 | ||||
-rw-r--r-- | src/map/party.h | 5 | ||||
-rw-r--r-- | src/map/pc.c | 110 | ||||
-rw-r--r-- | src/map/pc_groups.c | 2 | ||||
-rw-r--r-- | src/map/pet.c | 30 | ||||
-rw-r--r-- | src/map/quest.c | 32 | ||||
-rw-r--r-- | src/map/quest.h | 19 | ||||
-rw-r--r-- | src/map/script.c | 1325 | ||||
-rw-r--r-- | src/map/script.h | 10 | ||||
-rw-r--r-- | src/map/skill.c | 563 | ||||
-rw-r--r-- | src/map/status.c | 1037 | ||||
-rw-r--r-- | src/map/status.h | 7 | ||||
-rw-r--r-- | src/map/unit.c | 132 |
34 files changed, 2988 insertions, 2368 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index ffd09caeb..9d03dd057 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -609,7 +609,7 @@ ACMD(jump) * various info. *------------------------------------------*/ ACMD(who) { - struct map_session_data *pl_sd = NULL; + const struct map_session_data *pl_sd = NULL; struct s_mapiterator *iter = NULL; char player_name[NAME_LENGTH] = ""; int count = 0; @@ -640,7 +640,7 @@ ACMD(who) { StrBuf->Init(&buf); iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) { + for (pl_sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCCAST(BL_PC, mapit->next(iter))) { if (!((pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) || pc_isinvisible(pl_sd)) && pc_get_group_level(pl_sd) > level)) { // you can look only lower or same level if (stristr(pl_sd->status.name, player_name) == NULL // search with no case sensitive || (map_id >= 0 && pl_sd->bl.m != map_id)) @@ -709,7 +709,7 @@ ACMD(who) { *------------------------------------------*/ ACMD(whogm) { - struct map_session_data* pl_sd; + const struct map_session_data *pl_sd; struct s_mapiterator* iter; int j, count; int level; @@ -731,7 +731,7 @@ ACMD(whogm) level = pc_get_group_level(sd); iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) { + for (pl_sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCCAST(BL_PC, mapit->next(iter))) { int pl_level = pc_get_group_level(pl_sd); if (!pl_level) continue; @@ -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) { - TBL_PC* sd = (TBL_PC*)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) { - TBL_PC* sd = (TBL_PC*)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! @@ -2959,10 +2967,8 @@ ACMD(doom) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) - { - if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) - { + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) { + if (pl_sd->fd != fd && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { status_kill(&pl_sd->bl); clif->specialeffect(&pl_sd->bl,450,AREA); clif->message(pl_sd->fd, msg_fd(fd,61)); // The holy messenger has given judgment. @@ -2984,10 +2990,8 @@ ACMD(doommap) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) - { - if (pl_sd->fd != fd && sd->bl.m == pl_sd->bl.m && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) - { + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) { + if (pl_sd->fd != fd && sd->bl.m == pl_sd->bl.m && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { status_kill(&pl_sd->bl); clif->specialeffect(&pl_sd->bl,450,AREA); clif->message(pl_sd->fd, msg_fd(fd,61)); // The holy messenger has given judgment. @@ -3021,7 +3025,7 @@ ACMD(raise) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) if( pc_isdead(pl_sd) ) atcommand->raise_sub(pl_sd); mapit->free(iter); @@ -3040,7 +3044,7 @@ ACMD(raisemap) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) if (sd->bl.m == pl_sd->bl.m && pc_isdead(pl_sd) ) atcommand->raise_sub(pl_sd); mapit->free(iter); @@ -3089,8 +3093,7 @@ ACMD(kickall) struct s_mapiterator* iter; iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) - { + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) { if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kick only lower or same gm level if (sd->status.account_id != pl_sd->status.account_id) clif->GM_kick(NULL, pl_sd); @@ -3424,7 +3427,7 @@ ACMD(recallall) count = 0; iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) { + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) { if (sd->status.account_id != pl_sd->status.account_id && pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { if (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y) continue; // Don't waste time warping the character to the same place. @@ -3484,8 +3487,7 @@ ACMD(guildrecall) count = 0; iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) - { + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) { if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.guild_id == g->guild_id) { if (pc_get_group_level(pl_sd) > pc_get_group_level(sd) || (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y)) continue; // Skip GMs greater than you... or chars already on the cell @@ -3541,7 +3543,7 @@ ACMD(partyrecall) count = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) { if (sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party.party_id) { if (pc_get_group_level(pl_sd) > pc_get_group_level(sd) || (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y)) continue; // Skip GMs greater than you... or chars already on the cell @@ -3704,7 +3706,7 @@ ACMD(reloadscript) { //atcommand_broadcast( fd, sd, "@broadcast", "You will feel a bit of lag at this point !" ); iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) { + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) { if (pl_sd->npc_id || pl_sd->npc_shopid) { if (pl_sd->state.using_fake_npc) { clif->clearunit_single(pl_sd->npc_id, CLR_OUTSIGHT, pl_sd->fd); @@ -3742,10 +3744,11 @@ ACMD(reloadscript) { * 3 = Shows the chats in that map TODO# add the missing mapflags e.g. adjust_skill_damage to display *------------------------------------------*/ -ACMD(mapinfo) { - struct map_session_data* pl_sd; +ACMD(mapinfo) +{ + const struct map_session_data *pl_sd; struct s_mapiterator* iter; - struct chat_data *cd = NULL; + const struct chat_data *cd = NULL; char direction[12]; int i, m_id, chat_num = 0, list = 0, vend_num = 0; unsigned short m_index; @@ -3780,11 +3783,11 @@ ACMD(mapinfo) { // count chats (for initial message) chat_num = 0; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) { + for (pl_sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCCAST(BL_PC, mapit->next(iter))) { if( pl_sd->mapindex == m_index ) { if( pl_sd->state.vending ) vend_num++; - else if( (cd = (struct chat_data*)map->id2bl(pl_sd->chatID)) != NULL && cd->usersd[0] == pl_sd ) + else if ((cd = map->id2cd(pl_sd->chatID)) != NULL && cd->usersd[0] == pl_sd) chat_num++; } } @@ -3925,8 +3928,7 @@ ACMD(mapinfo) { case 1: clif->message(fd, msg_fd(fd,1098)); // ----- Players in Map ----- iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) - { + for (pl_sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCCAST(BL_PC, mapit->next(iter))) { if (pl_sd->mapindex == m_index) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1099), // Player '%s' (session #%d) | Location: %d,%d pl_sd->status.name, pl_sd->fd, pl_sd->bl.x, pl_sd->bl.y); @@ -3963,12 +3965,8 @@ ACMD(mapinfo) { case 3: clif->message(fd, msg_fd(fd,1113)); // ----- Chats in Map ----- iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) - { - if ((cd = (struct chat_data*)map->id2bl(pl_sd->chatID)) != NULL && - pl_sd->mapindex == m_index && - cd->usersd[0] == pl_sd) - { + for (pl_sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCCAST(BL_PC, mapit->next(iter))) { + if ((cd = map->id2cd(pl_sd->chatID)) != NULL && pl_sd->mapindex == m_index && cd->usersd[0] == pl_sd) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1114), // Chat: %s | Player: %s | Location: %d %d cd->title, pl_sd->status.name, cd->bl.x, cd->bl.y); clif->message(fd, atcmd_output); @@ -4749,7 +4747,7 @@ ACMD(disguiseall) } iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) pc->disguise(pl_sd, mob_id); mapit->free(iter); @@ -4829,7 +4827,7 @@ ACMD(undisguiseall) { struct s_mapiterator* iter; iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) if( pl_sd->disguise != -1 ) pc->disguise(pl_sd, -1); mapit->free(iter); @@ -6065,7 +6063,8 @@ ACMD(mobsearch) char mob_name[100]; int mob_id; int number = 0; - struct s_mapiterator* it; + struct s_mapiterator *it; + const struct mob_data *md = NULL; if (!*message || sscanf(message, "%99[^\n]", mob_name) < 1) { clif->message(fd, msg_fd(fd,1218)); // Please enter a monster name (usage: @mobsearch <monster name>). @@ -6087,12 +6086,7 @@ ACMD(mobsearch) clif->message(fd, atcmd_output); it = mapit_geteachmob(); - for(;;) - { - TBL_MOB* md = (TBL_MOB*)mapit->next(it); - if( md == NULL ) - break;// no more mobs - + for (md = BL_UCCAST(BL_MOB, mapit->first(it)); mapit->exists(it); md = BL_UCCAST(BL_MOB, mapit->next(it))) { if( md->bl.m != sd->bl.m ) continue; if( mob_id != -1 && md->class_ != mob_id ) @@ -6250,24 +6244,22 @@ ACMD(users) char buf[CHAT_SIZE_MAX]; int users[MAX_MAPINDEX]; int users_all; - struct s_mapiterator* iter; + struct s_mapiterator *iter; + const struct map_session_data *pl_sd = NULL; memset(users, 0, sizeof(users)); users_all = 0; // count users on each map iter = mapit_getallusers(); - for(;;) - { - struct map_session_data* sd2 = (struct map_session_data*)mapit->next(iter); - if( sd2 == NULL ) - break;// no more users - - if( sd2->mapindex >= MAX_MAPINDEX ) + for (pl_sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCCAST(BL_PC, mapit->next(iter))) { + if (pl_sd->mapindex >= MAX_MAPINDEX) continue;// invalid mapindex - if( users[sd2->mapindex] < INT_MAX ) ++users[sd2->mapindex]; - if( users_all < INT_MAX ) ++users_all; + if (users[pl_sd->mapindex] < INT_MAX) + ++users[pl_sd->mapindex]; + if (users_all < INT_MAX) + ++users_all; } mapit->free(iter); @@ -6536,7 +6528,7 @@ ACMD(refreshall) struct s_mapiterator* iter; iter = mapit_getallusers(); - for (iter_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); iter_sd = (TBL_PC*)mapit->next(iter)) + for (iter_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); iter_sd = BL_UCAST(BL_PC, mapit->next(iter))) clif->refresh(iter_sd); mapit->free(iter); return true; @@ -6744,7 +6736,8 @@ ACMD(showmobs) char mob_name[100]; int mob_id; int number = 0; - struct s_mapiterator* it; + struct s_mapiterator *it; + const struct mob_data *md = NULL; if (sscanf(message, "%99[^\n]", mob_name) < 0) { clif->message(fd, msg_fd(fd,546)); // Please enter a mob name/id (usage: @showmobs <mob name/id>) @@ -6781,12 +6774,7 @@ ACMD(showmobs) clif->message(fd, atcmd_output); it = mapit_geteachmob(); - for(;;) - { - TBL_MOB* md = (TBL_MOB*)mapit->next(it); - if( md == NULL ) - break;// no more mobs - + for (md = BL_UCCAST(BL_MOB, mapit->first(it)); mapit->next(it); md = BL_UCCAST(BL_MOB, mapit->next(it))) { if( md->bl.m != sd->bl.m ) continue; if( mob_id != -1 && md->class_ != mob_id ) @@ -6808,7 +6796,7 @@ ACMD(showmobs) * homunculus level up [orn] *------------------------------------------*/ ACMD(homlevel) { - TBL_HOM * hd; + struct homun_data *hd; int level = 0; enum homun_type htype; @@ -7303,7 +7291,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; @@ -7419,7 +7407,7 @@ ACMD(sizeall) size = cap_value(size,0,2); iter = mapit_getallusers(); - for (pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter)) { + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) { if (pl_sd->state.size != size) { if (pl_sd->state.size) { pl_sd->state.size = SZ_SMALL; @@ -9822,7 +9810,7 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa //Reconstructed message char atcmd_msg[CHAT_SIZE_MAX]; - TBL_PC * ssd = NULL; //sd for target + struct map_session_data *ssd = NULL; //sd for target AtCommandInfo * info; nullpo_retr(false, sd); diff --git a/src/map/battle.c b/src/map/battle.c index 201cd6a00..3b3ea2047 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -61,18 +61,30 @@ struct Battle_Config battle_config; struct battle_interface battle_s; struct battle_interface *battle; -int battle_getcurrentskill(struct block_list *bl) { //Returns the current/last skill in use by this bl. - struct unit_data *ud; +/** + * Returns the current/last skill in use by this bl. + * + * @param bl The bl to check. + * @return The current/last skill ID. + */ +int battle_getcurrentskill(struct block_list *bl) +{ + const struct unit_data *ud; nullpo_ret(bl); if (bl->type == BL_SKILL) { - struct skill_unit * su = (struct skill_unit*)bl; - return su->group?su->group->skill_id:0; + const struct skill_unit *su = BL_UCCAST(BL_SKILL, bl); + if (su->group == NULL) + return 0; + return su->group->skill_id; } ud = unit->bl2ud(bl); - return ud?ud->skill_id:0; + if (ud == NULL) + return 0; + + return ud->skill_id; } /*========================================== @@ -125,12 +137,12 @@ int battle_gettarget(struct block_list* bl) { nullpo_ret(bl); switch (bl->type) { - case BL_PC: return ((struct map_session_data*)bl)->ud.target; - case BL_MOB: return ((struct mob_data*)bl)->target_id; - case BL_PET: return ((struct pet_data*)bl)->target_id; - case BL_HOM: return ((struct homun_data*)bl)->ud.target; - case BL_MER: return ((struct mercenary_data*)bl)->ud.target; - case BL_ELEM: return ((struct elemental_data*)bl)->ud.target; + case BL_PC: return BL_UCCAST(BL_PC, bl)->ud.target; + case BL_MOB: return BL_UCCAST(BL_MOB, bl)->target_id; + case BL_PET: return BL_UCCAST(BL_PET, bl)->target_id; + case BL_HOM: return BL_UCCAST(BL_HOM, bl)->ud.target; + case BL_MER: return BL_UCCAST(BL_MER, bl)->ud.target; + case BL_ELEM: return BL_UCCAST(BL_ELEM, bl)->ud.target; } return 0; @@ -230,47 +242,37 @@ int battle_delay_damage_sub(int tid, int64 tick, int id, intptr_t data) { struct delay_damage *dat = (struct delay_damage *)data; if ( dat ) { - struct block_list* src = NULL; - struct block_list* target = map->id2bl(dat->target_id); - - if( !target || status->isdead(target) ) {/* nothing we can do */ - if( dat->src_type == BL_PC && (src = map->id2bl(dat->src_id)) != NULL && --((TBL_PC*)src)->delayed_damage == 0 && ((TBL_PC*)src)->state.hold_recalc ) { - ((TBL_PC*)src)->state.hold_recalc = 0; - status_calc_pc(((TBL_PC*)src),SCO_FORCE); + struct block_list *src = map->id2bl(dat->src_id); + struct map_session_data *sd = BL_CAST(BL_PC, src); + struct block_list *target = map->id2bl(dat->target_id); + + if (target != NULL && !status->isdead(target)) { + //Check to see if you haven't teleported. [Skotlex] + if (src != NULL && ( + battle_config.fix_warp_hit_delay_abuse ? + (dat->skill_id == MO_EXTREMITYFIST || target->m != src->m || check_distance_bl(src, target, dat->distance)) + : + ((target->type != BL_PC || BL_UCAST(BL_PC, target)->invincible_timer == INVALID_TIMER) + && (dat->skill_id == MO_EXTREMITYFIST || (target->m == src->m && check_distance_bl(src, target, dat->distance)))) + )) { + map->freeblock_lock(); + status_fix_damage(src, target, dat->damage, dat->delay); + if (dat->attack_type && !status->isdead(target) && dat->additional_effects) + skill->additional_effect(src,target,dat->skill_id,dat->skill_lv,dat->attack_type,dat->dmg_lv,tick); + if (dat->dmg_lv > ATK_BLOCK && dat->attack_type) + skill->counter_additional_effect(src,target,dat->skill_id,dat->skill_lv,dat->attack_type,tick); + map->freeblock_unlock(); + } else if (src == NULL && dat->skill_id == CR_REFLECTSHIELD) { + // it was monster reflected damage, and the monster died, we pass the damage to the character as expected + map->freeblock_lock(); + status_fix_damage(target, target, dat->damage, dat->delay); + map->freeblock_unlock(); } - ers_free(battle->delay_damage_ers, dat); - return 0; - } - - src = map->id2bl(dat->src_id); - - //Check to see if you haven't teleported. [Skotlex] - if (src && ( - battle_config.fix_warp_hit_delay_abuse ? - (dat->skill_id == MO_EXTREMITYFIST || target->m != src->m || check_distance_bl(src, target, dat->distance)) - : - ((target->type != BL_PC || ((TBL_PC*)target)->invincible_timer == INVALID_TIMER) - && (dat->skill_id == MO_EXTREMITYFIST || (target->m == src->m && check_distance_bl(src, target, dat->distance)))) - )) { - map->freeblock_lock(); - status_fix_damage(src, target, dat->damage, dat->delay); - if( dat->attack_type && !status->isdead(target) && dat->additional_effects ) - skill->additional_effect(src,target,dat->skill_id,dat->skill_lv,dat->attack_type,dat->dmg_lv,tick); - if( dat->dmg_lv > ATK_BLOCK && dat->attack_type ) - skill->counter_additional_effect(src,target,dat->skill_id,dat->skill_lv,dat->attack_type,tick); - map->freeblock_unlock(); - } else if( !src && dat->skill_id == CR_REFLECTSHIELD ) { - /** - * it was monster reflected damage, and the monster died, we pass the damage to the character as expected - **/ - map->freeblock_lock(); - status_fix_damage(target, target, dat->damage, dat->delay); - map->freeblock_unlock(); } - if( src && src->type == BL_PC && --((TBL_PC*)src)->delayed_damage == 0 && ((TBL_PC*)src)->state.hold_recalc ) { - ((TBL_PC*)src)->state.hold_recalc = 0; - status_calc_pc(((TBL_PC*)src),SCO_FORCE); + if (sd != NULL && --sd->delayed_damage == 0 && sd->state.hold_recalc) { + sd->state.hold_recalc = 0; + status_calc_pc(sd, SCO_FORCE); } } ers_free(battle->delay_damage_ers, dat); @@ -317,8 +319,8 @@ int battle_delay_damage(int64 tick, int amotion, struct block_list *src, struct if (src->type != BL_PC && amotion > 1000) amotion = 1000; //Aegis places a damage-delay cap of 1 sec to non player attacks. [Skotlex] - if( src->type == BL_PC ) { - ((TBL_PC*)src)->delayed_damage++; + if (src->type == BL_PC) { + BL_UCAST(BL_PC, src)->delayed_damage++; } timer->add(tick+amotion, battle->delay_damage_sub, 0, (intptr_t)dat); @@ -371,7 +373,7 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d } if( target && target->type == BL_SKILL ) { if( atk_elem == ELE_FIRE && battle->get_current_skill(target) == GN_WALLOFTHORN ) { - struct skill_unit *su = (struct skill_unit*)target; + struct skill_unit *su = BL_UCAST(BL_SKILL, target); struct skill_unit_group *sg; struct block_list *sgsrc; @@ -526,17 +528,20 @@ int64 battle_calc_base_damage(struct block_list *src, struct block_list *bl, uin int64 damage; struct status_data *st = status->get_status_data(src); struct status_change *sc = status->get_sc(src); - + const struct map_session_data *sd = NULL; nullpo_retr(0, src); + + sd = BL_CCAST(BL_PC, src); + if ( !skill_id ) { s_ele = st->rhw.ele; s_ele_ = st->lhw.ele; - if ( src->type == BL_PC ) { - if ( ((TBL_PC*)src)->charm_type != CHARM_TYPE_NONE && ((TBL_PC*)src)->charm_count >= MAX_SPIRITCHARM ) { - s_ele = s_ele_ = ((TBL_PC*)src)->charm_type; + if (sd != NULL) { + if (sd->charm_type != CHARM_TYPE_NONE && sd->charm_count >= MAX_SPIRITCHARM) { + s_ele = s_ele_ = sd->charm_type; } - if ( flag & 2 && ((TBL_PC*)src)->bonus.arrow_ele ) - s_ele = ((TBL_PC*)src)->bonus.arrow_ele; + if (flag&2 && sd->bonus.arrow_ele != 0) + s_ele = sd->bonus.arrow_ele; } } if (src->type == BL_PC) { @@ -550,8 +555,7 @@ int64 battle_calc_base_damage(struct block_list *src, struct block_list *bl, uin damage = batk + 3 * battle->calc_weapon_damage(src, bl, skill_id, skill_lv, &st->lhw, nk, n_ele, s_ele, s_ele_, status_get_size(bl), type, flag, flag2) / 4; else damage = (batk << 1) + battle->calc_weapon_damage(src, bl, skill_id, skill_lv, &st->rhw, nk, n_ele, s_ele, s_ele_, status_get_size(bl), type, flag, flag2); - } - else{ + } else { damage = st->batk + battle->calc_weapon_damage(src, bl, skill_id, skill_lv, &st->rhw, nk, n_ele, s_ele, s_ele_, status_get_size(bl), type, flag, flag2); } @@ -2720,6 +2724,8 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam nullpo_ret(bl); nullpo_ret(d); + + sd = BL_CAST(BL_PC, bl); div_ = d->div_; flag = d->flag; @@ -2729,8 +2735,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam return 0; if( battle_config.ksprotection && mob->ksprotected(src, bl) ) return 0; - if (bl->type == BL_PC) { - sd=(struct map_session_data *)bl; + if (sd != NULL) { //Special no damage states if(flag&BF_WEAPON && sd->special_state.no_weapon_damage) damage -= damage * sd->special_state.no_weapon_damage / 100; @@ -2861,9 +2866,11 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam // If the target is too far away from the devotion caster, autoguard has no effect // Autoguard will be disabled later on struct block_list *d_bl = map->id2bl(sce_d->val1); - if (d_bl && check_distance_bl(bl, d_bl, sce_d->val3) - && ((d_bl->type == BL_MER && ((TBL_MER*)d_bl)->master && ((TBL_MER*)d_bl)->master->bl.id == bl->id) - || (d_bl->type == BL_PC && ((TBL_PC*)d_bl)->devotion[sce_d->val2] == bl->id)) + struct mercenary_data *d_md = BL_CAST(BL_MER, d_bl); + struct map_session_data *d_sd = BL_CAST(BL_PC, d_bl); + if (d_bl != NULL && check_distance_bl(bl, d_bl, sce_d->val3) + && ((d_bl->type == BL_MER && d_md->master != NULL && d_md->master->bl.id == bl->id) + || (d_bl->type == BL_PC && d_sd->devotion[sce_d->val2] == bl->id)) ) { // if player is target of devotion, show guard effect on the devotion caster rather than the target clif->skill_nodamage(d_bl, d_bl, CR_AUTOGUARD, sce->val1, 1); @@ -3059,10 +3066,11 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam // Compressed code, fixed by map.h [Epoque] if (src->type == BL_MOB) { + const struct mob_data *md = BL_UCCAST(BL_MOB, src); int i; if (sc->data[SC_MANU_DEF] != NULL) { for (i = 0; i < ARRAYLENGTH(mob->manuk); i++) { - if (mob->manuk[i] == ((TBL_MOB*)src)->class_) { + if (mob->manuk[i] == md->class_) { damage -= damage * sc->data[SC_MANU_DEF]->val1 / 100; break; } @@ -3070,7 +3078,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam } if (sc->data[SC_SPL_DEF] != NULL) { for (i = 0; i < ARRAYLENGTH(mob->splendide); i++) { - if (mob->splendide[i] == ((TBL_MOB*)src)->class_) { + if (mob->splendide[i] == md->class_) { damage -= damage * sc->data[SC_SPL_DEF]->val1 / 100; break; } @@ -3078,7 +3086,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam } if (sc->data[SC_MORA_BUFF] != NULL) { for (i = 0; i < ARRAYLENGTH(mob->mora); i++) { - if (mob->mora[i] == ((TBL_MOB*)src)->class_) { + if (mob->mora[i] == md->class_) { damage -= damage * sc->data[SC_MORA_BUFF]->val1 / 100; break; } @@ -3123,7 +3131,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam if( (sce = sc->data[SC_STONEHARDSKIN]) && flag&(BF_SHORT|BF_WEAPON) && damage > 0 ) { sce->val2 -= (int)cap_value(damage,INT_MIN,INT_MAX); if( src->type == BL_PC ) { - TBL_PC *ssd = BL_CAST(BL_PC, src); + struct map_session_data *ssd = BL_CAST(BL_PC, src); if (ssd && ssd->status.weapon != W_BOW) skill->break_equip(src, EQP_WEAPON, 3000, BCT_SELF); } else @@ -3194,7 +3202,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam clif->millenniumshield(bl, sc->fv_counter++); if (sc->data[SC_STYLE_CHANGE] && rnd()%2) { - TBL_HOM *hd = BL_CAST(BL_HOM,bl); + struct homun_data *hd = BL_CAST(BL_HOM,bl); if (hd) homun->addspiritball(hd, 10); //add a sphere } @@ -3213,24 +3221,25 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam damage += damage * 75 / 100; // [Epoque] if (bl->type == BL_MOB) { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); int i; - if ( ((sce=tsc->data[SC_MANU_ATK]) && (flag&BF_WEAPON)) || - ((sce=tsc->data[SC_MANU_MATK]) && (flag&BF_MAGIC)) - ) - for (i=0;ARRAYLENGTH(mob->manuk)>i;i++) - if (((TBL_MOB*)bl)->class_==mob->manuk[i]) { + if (((sce=tsc->data[SC_MANU_ATK]) != NULL && (flag&BF_WEAPON)) + || ((sce=tsc->data[SC_MANU_MATK]) != NULL && (flag&BF_MAGIC))) { + for (i = 0; i < ARRAYLENGTH(mob->manuk); i++) + if (md->class_ == mob->manuk[i]) { damage += damage * sce->val1 / 100; break; } - if ( ((sce=tsc->data[SC_SPL_ATK]) && (flag&BF_WEAPON)) || - ((sce=tsc->data[SC_SPL_MATK]) && (flag&BF_MAGIC)) - ) - for (i=0;ARRAYLENGTH(mob->splendide)>i;i++) - if (((TBL_MOB*)bl)->class_==mob->splendide[i]) { + } + if (((sce=tsc->data[SC_SPL_ATK]) != NULL && (flag&BF_WEAPON)) + || ((sce=tsc->data[SC_SPL_MATK]) != NULL && (flag&BF_MAGIC))) { + for (i = 0; i < ARRAYLENGTH(mob->splendide); i++) + if (md->class_ == mob->splendide[i]) { damage += damage * sce->val1 / 100; break; } + } } if( tsc->data[SC_POISONINGWEAPON] ) { struct status_data *tstatus = status->get_status_data(bl); @@ -3246,12 +3255,12 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam if (tsc->data[SC_SHIELDSPELL_REF] && tsc->data[SC_SHIELDSPELL_REF]->val1 == 1 && damage > 0) skill->break_equip(bl,EQP_ARMOR,10000,BCT_ENEMY ); if (tsc->data[SC_STYLE_CHANGE] && rnd()%2) { - TBL_HOM *hd = BL_CAST(BL_HOM,bl); + struct homun_data *hd = BL_CAST(BL_HOM,bl); if (hd) homun->addspiritball(hd, 10); } if (src->type == BL_PC && damage > 0 && (sce = tsc->data[SC_GENTLETOUCH_ENERGYGAIN]) != NULL) { - struct map_session_data *tsd = (struct map_session_data *)src; - if ( tsd && rnd() % 100 < sce->val2 ) + struct map_session_data *tsd = BL_UCAST(BL_PC, src); + if (tsd != NULL && rnd() % 100 < sce->val2) pc->addspiritball(tsd, skill->get_time(MO_CALLSPIRITS, 1), pc->getmaxspiritball(tsd, 0)); } } @@ -3292,18 +3301,20 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam } if( bl->type == BL_MOB && !status->isdead(bl) && src != bl) { - if ( damage > 0 ) - mob->skill_event((TBL_MOB*)bl,src,timer->gettick(),flag); + struct mob_data *md = BL_UCAST(BL_MOB, bl); + if (damage > 0) + mob->skill_event(md, src, timer->gettick(), flag); if (skill_id) - mob->skill_event((TBL_MOB*)bl,src,timer->gettick(),MSC_SKILLUSED|(skill_id<<16)); + mob->skill_event(md, src, timer->gettick(), MSC_SKILLUSED|(skill_id<<16)); } if (sd && pc_ismadogear(sd) && rnd()%100 < 50) { int element = -1; if (!skill_id || (element = skill->get_ele(skill_id, skill_lv)) == -1) { // Take weapon's element struct status_data *sstatus = NULL; - if (src->type == BL_PC && ((TBL_PC*)src)->bonus.arrow_ele) { - element = ((TBL_PC*)src)->bonus.arrow_ele; + struct map_session_data *ssd = BL_CAST(BL_PC, src); + if (src->type == BL_PC && ssd->bonus.arrow_ele != 0) { + element = ssd->bonus.arrow_ele; } else if ((sstatus = status->get_status_data(src)) != NULL) { element = sstatus->rhw.ele; } @@ -3371,7 +3382,13 @@ int64 battle_calc_gvg_damage(struct block_list *src,struct block_list *bl,int64 } } if(src->type != BL_MOB) { - struct guild *g = src->type == BL_PC ? ((TBL_PC *)src)->guild : guild->search(status->get_guild_id(src)); + struct guild *g = NULL; + if (src->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, src); + g = sd->guild; + } else { + g = guild->search(status->get_guild_id(src)); + } if (class_ == MOBID_EMPELIUM && (!g || guild->checkskill(g,GD_APPROVAL) <= 0)) return 0; @@ -3420,7 +3437,8 @@ int battle_calc_drain(int64 damage, int rate, int per) { /*========================================== * Consumes ammo for the given skill. *------------------------------------------*/ -void battle_consume_ammo(TBL_PC*sd, int skill_id, int lv) { +void battle_consume_ammo(struct map_session_data *sd, int skill_id, int lv) +{ int qty=1; nullpo_retv(sd); @@ -3499,7 +3517,7 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list short s_ele = 0; unsigned int skillratio = 100; //Skill dmg modifiers. - TBL_PC *sd; + struct map_session_data *sd = NULL; struct status_change *sc; struct Damage ad; struct status_data *sstatus = status->get_status_data(src); @@ -3562,8 +3580,11 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list //Skill Range Criteria ad.flag |= battle->range_type(src, target, skill_id, skill_lv); flag.infdef = (tstatus->mode&MD_PLANT) ? 1 : 0; - if( !flag.infdef && target->type == BL_SKILL && ((TBL_SKILL*)target)->group->unit_id == UNT_REVERBERATION ) - flag.infdef = 1; // Reverberation takes 1 damage + if (!flag.infdef && target->type == BL_SKILL) { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, target); + if (su->group->unit_id == UNT_REVERBERATION) + flag.infdef = 1; // Reverberation takes 1 damage + } switch(skill_id) { case MG_FIREWALL: @@ -3691,10 +3712,11 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list if (skill_id) { for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { - if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { - if( (((TBL_MOB*)target)->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS) ) + if (target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE) { + const struct mob_data *md = BL_UCCAST(BL_MOB, target); + if ((md->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) continue; - if( ((TBL_MOB*)target)->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE) ) + if (md->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) continue; } if( ad.damage > map->list[target->m].zone->capped_skills[i]->cap ) @@ -4165,10 +4187,11 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * if (skill_id) { for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { - if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { - if( (((TBL_MOB*)target)->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS) ) + if (target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE) { + const struct mob_data *t_md = BL_UCCAST(BL_MOB, target); + if ((t_md->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) continue; - if( ((TBL_MOB*)target)->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE) ) + if (t_md->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) continue; } if( md.damage > map->list[target->m].zone->capped_skills[i]->cap ) @@ -4294,13 +4317,16 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list //Initial flag flag.rh=1; flag.weapon=1; - flag.infdef=(tstatus->mode&MD_PLANT && skill_id != RA_CLUSTERBOMB + flag.infdef = (tstatus->mode&MD_PLANT && skill_id != RA_CLUSTERBOMB?1:0); #ifdef RENEWAL - && skill_id != HT_FREEZINGTRAP + if (skill_id == HT_FREEZINGTRAP) + flag.infdef = 0; #endif - ?1:0); - if( !flag.infdef && target->type == BL_SKILL && ((TBL_SKILL*)target)->group->unit_id == UNT_REVERBERATION ) - flag.infdef = 1; // Reverberation takes 1 damage + if (!flag.infdef && target->type == BL_SKILL) { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, target); + if (su->group->unit_id == UNT_REVERBERATION) + flag.infdef = 1; // Reverberation takes 1 damage + } //Initial Values wd.type = BDT_NORMAL; @@ -4846,10 +4872,12 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list ATK_ADD(sstatus->rhw.atk2); //Else use Atk2 break; case HFLI_SBR44: //[orn] - if(src->type == BL_HOM) { - wd.damage = ((TBL_HOM*)src)->homunculus.intimacy ; + if (src->type == BL_HOM) { + const struct homun_data *hd = BL_UCCAST(BL_HOM, src); + wd.damage = hd->homunculus.intimacy; break; } + break; default: { i = (flag.cri @@ -5153,8 +5181,9 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list } #endif if(sc->data[SC_STYLE_CHANGE]){ - TBL_HOM *hd = BL_CAST(BL_HOM,src); - if (hd) ATK_ADD(hd->homunculus.spiritball * 3); + struct homun_data *hd = BL_CAST(BL_HOM, src); + if (hd != NULL) + ATK_ADD(hd->homunculus.spiritball * 3); } } @@ -5384,10 +5413,11 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list if (skill_id) { for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { - if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { - if( (((TBL_MOB*)target)->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS) ) + if (target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE) { + const struct mob_data *md = BL_UCCAST(BL_MOB, target); + if ((md->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) continue; - if( ((TBL_MOB*)target)->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE) ) + if (md->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) continue; } if( wd.damage > map->list[target->m].zone->capped_skills[i]->cap ) @@ -5596,14 +5626,10 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list } } //Reject Sword bugreport:4493 by Daegaladh - if(wd.damage && tsc && tsc->data[SC_SWORDREJECT] && - (src->type!=BL_PC || ( - ((TBL_PC *)src)->weapontype1 == W_DAGGER || - ((TBL_PC *)src)->weapontype1 == W_1HSWORD || - ((TBL_PC *)src)->status.weapon == W_2HSWORD - )) && - rnd()%100 < tsc->data[SC_SWORDREJECT]->val2 - ) { + if (wd.damage != 0 && tsc != NULL && tsc->data[SC_SWORDREJECT] != NULL + && (sd == NULL || sd->weapontype1 == W_DAGGER || sd->weapontype1 == W_1HSWORD || sd->status.weapon == W_2HSWORD) + && rnd()%100 < tsc->data[SC_SWORDREJECT]->val2 + ) { ATK_RATER(50); status_fix_damage(target,src,wd.damage,clif->damage(target,src,0,0,wd.damage,0,BDT_NORMAL,0)); clif->skill_nodamage(target,target,ST_REJECTSWORD,tsc->data[SC_SWORDREJECT]->val1,1); @@ -5644,10 +5670,11 @@ struct Damage battle_calc_attack(int attack_type,struct block_list *bl,struct bl int i; for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { - if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { - if( (((TBL_MOB*)target)->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS) ) + if (target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE) { + const struct mob_data *md = BL_UCCAST(BL_MOB, target); + if ((md->status.mode&MD_BOSS) && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_BOSS)) continue; - if( ((TBL_MOB*)target)->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE) ) + if (md->special_state.clone && !(map->list[target->m].zone->disabled_skills[i]->subtype&MZS_CLONE)) continue; } if( d.damage > map->list[target->m].zone->capped_skills[i]->cap ) @@ -5893,7 +5920,7 @@ void battle_reflect_damage(struct block_list *target, struct block_list *src, st #undef NORMALIZE_RDAMAGE } -void battle_drain(TBL_PC *sd, struct block_list *tbl, int64 rdamage, int64 ldamage, int race, int boss) +void battle_drain(struct map_session_data *sd, struct block_list *tbl, int64 rdamage, int64 ldamage, int race, int boss) { struct weapon_data *wd; int type, thp = 0, tsp = 0, rhp = 0, rsp = 0, hp, sp, i; @@ -5964,19 +5991,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 && ((TBL_MOB*)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((TBL_PC*)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 && ((TBL_PC*)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(); } @@ -6171,9 +6202,9 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t if (sd && sd->bonus.splash_range > 0 && damage > 0) skill->castend_damage_id(src, target, 0, 1, tick, 0); - if ( target->type == BL_SKILL && damage > 0 ){ - TBL_SKILL *su = (TBL_SKILL*)target; - if( su->group && su->group->skill_id == HT_BLASTMINE) + if (target->type == BL_SKILL && damage > 0) { + struct skill_unit *su = BL_UCAST(BL_SKILL, target); + if (su->group && su->group->skill_id == HT_BLASTMINE) skill->blown(src, target, 3, -1, 0); } map->freeblock_lock(); @@ -6189,20 +6220,23 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t if( tsc->data[SC_DEVOTION] ) { struct status_change_entry *sce = tsc->data[SC_DEVOTION]; struct block_list *d_bl = map->id2bl(sce->val1); - - if( d_bl && ( - (d_bl->type == BL_MER && ((TBL_MER*)d_bl)->master && ((TBL_MER*)d_bl)->master->bl.id == target->id) || - (d_bl->type == BL_PC && ((TBL_PC*)d_bl)->devotion[sce->val2] == target->id) - ) && check_distance_bl(target, d_bl, sce->val3) ) - { + struct mercenary_data *d_md = BL_CAST(BL_MER, d_bl); + struct map_session_data *d_sd = BL_CAST(BL_PC, d_bl); + + if (d_bl != NULL + && ((d_bl->type == BL_MER && d_md->master != NULL && d_md->master->bl.id == target->id) + || (d_bl->type == BL_PC && d_sd->devotion[sce->val2] == target->id) + ) + && check_distance_bl(target, d_bl, sce->val3) + ) { clif->damage(d_bl, d_bl, 0, 0, damage, 0, BDT_NORMAL, 0); status_fix_damage(NULL, d_bl, damage, 0); - } - else + } else { status_change_end(target, SC_DEVOTION, INVALID_TIMER); + } } else if( tsc->data[SC_CIRCLE_OF_FIRE_OPTION] && (wd.flag&BF_SHORT) && target->type == BL_PC ) { - struct elemental_data *ed = ((TBL_PC*)target)->ed; - if( ed ) { + struct elemental_data *ed = BL_UCAST(BL_PC, target)->ed; + if (ed != NULL) { clif->skill_damage(&ed->bl, target, tick, status_get_amotion(src), 0, -30000, 1, EL_CIRCLE_OF_FIRE, tsc->data[SC_CIRCLE_OF_FIRE_OPTION]->val1, BDT_SKILL); skill->attack(BF_MAGIC,&ed->bl,&ed->bl,src,EL_CIRCLE_OF_FIRE,tsc->data[SC_CIRCLE_OF_FIRE_OPTION]->val1,tick,wd.flag); } @@ -6366,35 +6400,54 @@ bool battle_check_undead(int race,int element) } //Returns the upmost level master starting with the given object -struct block_list* battle_get_master(struct block_list *src) { - struct block_list *prev; //Used for infinite loop check (master of yourself?) +struct block_list *battle_get_master(struct block_list *src) +{ + struct block_list *prev = NULL; //Used for infinite loop check (master of yourself?) nullpo_retr(NULL, src); do { prev = src; switch (src->type) { case BL_PET: - if (((TBL_PET*)src)->msd) - src = (struct block_list*)((TBL_PET*)src)->msd; + { + struct pet_data *pd = BL_UCAST(BL_PET, src); + if (pd->msd != NULL) + src = &pd->msd->bl; + } break; case BL_MOB: - if (((TBL_MOB*)src)->master_id) - src = map->id2bl(((TBL_MOB*)src)->master_id); + { + struct mob_data *md = BL_UCAST(BL_MOB, src); + if (md->master_id != 0) + src = map->id2bl(md->master_id); + } break; case BL_HOM: - if (((TBL_HOM*)src)->master) - src = (struct block_list*)((TBL_HOM*)src)->master; + { + struct homun_data *hd = BL_UCAST(BL_HOM, src); + if (hd->master != NULL) + src = &hd->master->bl; + } break; case BL_MER: - if (((TBL_MER*)src)->master) - src = (struct block_list*)((TBL_MER*)src)->master; + { + struct mercenary_data *md = BL_UCAST(BL_MER, src); + if (md->master != NULL) + src = &md->master->bl; + } break; case BL_ELEM: - if (((TBL_ELEM*)src)->master) - src = (struct block_list*)((TBL_ELEM*)src)->master; + { + struct elemental_data *ed = BL_UCAST(BL_ELEM, src); + if (ed->master != NULL) + src = &ed->master->bl; + } break; case BL_SKILL: - if (((TBL_SKILL*)src)->group && ((TBL_SKILL*)src)->group->src_id) - src = map->id2bl(((TBL_SKILL*)src)->group->src_id); + { + struct skill_unit *su = BL_UCAST(BL_SKILL, src); + if (su->group != NULL && su->group->src_id != 0) + src = map->id2bl(su->group->src_id); + } break; } } while (src && src != prev); @@ -6435,14 +6488,15 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f if( (s_bl = battle->get_master(src)) == NULL ) s_bl = src; - if ( s_bl->type == BL_PC ) { - switch( t_bl->type ) { + if (s_bl->type == BL_PC) { + const struct map_session_data *s_sd = BL_UCCAST(BL_PC, s_bl); + switch (t_bl->type) { case BL_MOB: // Source => PC, Target => MOB - if (pc_has_permission((TBL_PC*)s_bl, PC_PERM_DISABLE_PVM) ) + if (pc_has_permission(s_sd, PC_PERM_DISABLE_PVM)) return 0; break; case BL_PC: - if (pc_has_permission((TBL_PC*)s_bl, PC_PERM_DISABLE_PVP)) + if (pc_has_permission(s_sd, PC_PERM_DISABLE_PVP)) return 0; break; default:/* anything else goes */ @@ -6451,29 +6505,31 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f } switch( target->type ) { // Checks on actual target - case BL_PC: { - struct status_change* sc = status->get_sc(src); - if( ((TBL_PC*)target)->invincible_timer != INVALID_TIMER ) { - switch( battle->get_current_skill(src) ) { - /* TODO a proper distinction should be established bugreport:8397 */ - case PR_SANCTUARY: - case PR_MAGNIFICAT: - break; - default: - return -1; - } - } - if ( pc_isinvisible((TBL_PC*)target) ) - return -1; //Cannot be targeted yet. - if( sc && sc->count ) { - if( sc->data[SC_SIREN] && sc->data[SC_SIREN]->val2 == target->id ) + case BL_PC: + { + const struct status_change *sc = status->get_sc(src); + const struct map_session_data *t_sd = BL_UCCAST(BL_PC, target); + if (t_sd->invincible_timer != INVALID_TIMER) { + switch( battle->get_current_skill(src) ) { + /* TODO a proper distinction should be established bugreport:8397 */ + case PR_SANCTUARY: + case PR_MAGNIFICAT: + break; + default: return -1; } } + if (pc_isinvisible(t_sd)) + return -1; //Cannot be targeted yet. + if (sc && sc->count) { + if (sc->data[SC_SIREN] && sc->data[SC_SIREN]->val2 == target->id) + return -1; + } + } break; case BL_MOB: { - TBL_MOB *md = BL_CAST(BL_MOB, target); + const struct mob_data *md = BL_UCCAST(BL_MOB, target); if(( (md->special_state.ai == AI_SPHERE || (md->special_state.ai == AI_FLORA && battle_config.summon_flora&1)) && s_bl->type == BL_PC && src->type != BL_MOB @@ -6488,7 +6544,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f } case BL_SKILL: { - TBL_SKILL *su = (TBL_SKILL*)target; + const struct skill_unit *su = BL_UCCAST(BL_SKILL, target); if( !su->group ) return 0; if( skill->get_inf2(su->group->skill_id)&INF2_TRAP && @@ -6559,13 +6615,13 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f switch( t_bl->type ) { //Checks on target master case BL_PC: { - struct map_session_data *sd; - if( t_bl == s_bl ) break; - sd = BL_CAST(BL_PC, t_bl); + const struct map_session_data *sd = BL_UCCAST(BL_PC, t_bl); + if (t_bl == s_bl) + break; if( sd->state.monster_ignore && flag&BCT_ENEMY ) return 0; // Global immunity only to Attacks - if( sd->status.karma && s_bl->type == BL_PC && ((TBL_PC*)s_bl)->status.karma ) + if (sd->status.karma && s_bl->type == BL_PC && BL_UCCAST(BL_PC, s_bl)->status.karma) state |= BCT_ENEMY; // Characters with bad karma may fight amongst them if( sd->state.killable ) { state |= BCT_ENEMY; // Everything can kill it @@ -6575,7 +6631,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f } case BL_MOB: { - struct mob_data *md = BL_CAST(BL_MOB, t_bl); + const struct mob_data *md = BL_UCCAST(BL_MOB, t_bl); if( !((map->agit_flag || map->agit2_flag) && map->list[m].flag.gvg_castle) && md->guardian_data && (md->guardian_data->g || md->guardian_data->castle->guild_id) ) @@ -6589,31 +6645,32 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f case BL_PET: if (t_bl->type != BL_MOB && flag&BCT_ENEMY) return 0; //Pet may not attack non-mobs. - if (t_bl->type == BL_MOB && ((TBL_MOB*)t_bl)->guardian_data && flag&BCT_ENEMY) + if (t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->guardian_data && flag&BCT_ENEMY) return 0; //pet may not attack Guardians/Emperium break; - case BL_SKILL: { - struct skill_unit *su = (struct skill_unit *)src; - struct status_change* sc = status->get_sc(target); - if (!su->group) - return 0; + case BL_SKILL: + { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, src); + const struct status_change *sc = status->get_sc(target); + if (su->group == NULL) + return 0; - if (su->group->src_id == target->id) { - int inf2 = skill->get_inf2(su->group->skill_id); - if (inf2&INF2_NO_TARGET_SELF) - return -1; - if (inf2&INF2_TARGET_SELF) - return 1; - } - //Status changes that prevent traps from triggering - if (sc && sc->count && skill->get_inf2(su->group->skill_id)&INF2_TRAP) { - if( sc->data[SC_WZ_SIGHTBLASTER] && sc->data[SC_WZ_SIGHTBLASTER]->val2 > 0 && sc->data[SC_WZ_SIGHTBLASTER]->val4%2 == 0) - return -1; - } + if (su->group->src_id == target->id) { + int inf2 = skill->get_inf2(su->group->skill_id); + if (inf2&INF2_NO_TARGET_SELF) + return -1; + if (inf2&INF2_TARGET_SELF) + return 1; } + //Status changes that prevent traps from triggering + if (sc != NULL && sc->count != 0 && skill->get_inf2(su->group->skill_id)&INF2_TRAP) { + if (sc->data[SC_WZ_SIGHTBLASTER] != NULL && sc->data[SC_WZ_SIGHTBLASTER]->val2 > 0 && sc->data[SC_WZ_SIGHTBLASTER]->val4%2 == 0) + return -1; + } + } break; case BL_MER: - if (t_bl->type == BL_MOB && ((TBL_MOB*)t_bl)->class_ == MOBID_EMPELIUM && flag&BCT_ENEMY) + if (t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->class_ == MOBID_EMPELIUM && flag&BCT_ENEMY) return 0; //mercenary may not attack Emperium break; } //end switch actual src @@ -6621,7 +6678,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f switch( s_bl->type ) { //Checks on source master case BL_PC: { - struct map_session_data *sd = BL_CAST(BL_PC, s_bl); + const struct map_session_data *sd = BL_UCCAST(BL_PC, s_bl); if( s_bl != t_bl ) { if( sd->state.killer ) { state |= BCT_ENEMY; // Can kill anything @@ -6629,13 +6686,13 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f } else if( sd->duel_group && !((!battle_config.duel_allow_pvp && map->list[m].flag.pvp) || (!battle_config.duel_allow_gvg && map_flag_gvg(m))) ) { - if( t_bl->type == BL_PC && (sd->duel_group == ((TBL_PC*)t_bl)->duel_group) ) + if (t_bl->type == BL_PC && sd->duel_group == BL_UCCAST(BL_PC, t_bl)->duel_group) return (BCT_ENEMY&flag)?1:-1; // Duel targets can ONLY be your enemy, nothing else. else if (src->type != BL_SKILL || (flag&BCT_ALL) != BCT_ALL) return 0; } } - if (map_flag_gvg(m) && !sd->status.guild_id && t_bl->type == BL_MOB && ((TBL_MOB*)t_bl)->class_ == MOBID_EMPELIUM) + if (map_flag_gvg(m) && !sd->status.guild_id && t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->class_ == MOBID_EMPELIUM) return 0; //If you don't belong to a guild, can't target emperium. if( t_bl->type != BL_PC ) state |= BCT_ENEMY; //Natural enemy. @@ -6643,21 +6700,21 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f } case BL_MOB: { - struct mob_data *md = BL_CAST(BL_MOB, s_bl); + const struct mob_data *md = BL_UCCAST(BL_MOB, s_bl); if( !((map->agit_flag || map->agit2_flag) && map->list[m].flag.gvg_castle) && md->guardian_data && (md->guardian_data->g || md->guardian_data->castle->guild_id) ) return 0; // Disable guardians/emperium owned by Guilds on non-woe times. if (md->special_state.ai == AI_NONE) { //Normal mobs - struct mob_data *target_md = BL_CAST(BL_MOB, target); - if( (target_md && t_bl->type == BL_PC && target_md->special_state.ai != AI_ZANZOU && target_md->special_state.ai != AI_ATTACK) - || (t_bl->type == BL_MOB && !((TBL_MOB*)t_bl)->special_state.ai) ) + const struct mob_data *target_md = BL_CCAST(BL_MOB, target); + if ((target_md != NULL && t_bl->type == BL_PC && target_md->special_state.ai != AI_ZANZOU && target_md->special_state.ai != AI_ATTACK) + || (t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->special_state.ai == AI_NONE)) state |= BCT_PARTY; //Normal mobs with no ai are friends. else state |= BCT_ENEMY; //However, all else are enemies. } else { - if (t_bl->type == BL_MOB && ((TBL_MOB*)t_bl)->special_state.ai == AI_NONE) + if (t_bl->type == BL_MOB && BL_UCCAST(BL_MOB, t_bl)->special_state.ai == AI_NONE) state |= BCT_ENEMY; //Natural enemy for AI mobs are normal mobs. } break; @@ -6720,15 +6777,16 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f if( state&BCT_ENEMY && map->list[m].flag.battleground && sbg_id && sbg_id == tbg_id ) state &= ~BCT_ENEMY; - if( state&BCT_ENEMY && battle_config.pk_mode && !map_flag_gvg(m) && s_bl->type == BL_PC && t_bl->type == BL_PC ) - { // Prevent novice engagement on pk_mode (feature by Valaris) - TBL_PC *sd = (TBL_PC*)s_bl, *sd2 = (TBL_PC*)t_bl; + if (state&BCT_ENEMY && battle_config.pk_mode && !map_flag_gvg(m) && s_bl->type == BL_PC && t_bl->type == BL_PC) { + // Prevent novice engagement on pk_mode (feature by Valaris) + const struct map_session_data *s_sd = BL_UCCAST(BL_PC, s_bl); + const struct map_session_data *t_sd = BL_UCCAST(BL_PC, t_bl); if ( - (sd->class_&MAPID_UPPERMASK) == MAPID_NOVICE || - (sd2->class_&MAPID_UPPERMASK) == MAPID_NOVICE || - (int)sd->status.base_level < battle_config.pk_min_level || - (int)sd2->status.base_level < battle_config.pk_min_level || - (battle_config.pk_level_range && abs((int)sd->status.base_level - (int)sd2->status.base_level) > battle_config.pk_level_range) + (s_sd->class_&MAPID_UPPERMASK) == MAPID_NOVICE || + (t_sd->class_&MAPID_UPPERMASK) == MAPID_NOVICE || + (int)s_sd->status.base_level < battle_config.pk_min_level || + (int)t_sd->status.base_level < battle_config.pk_min_level || + (battle_config.pk_level_range && abs((int)s_sd->status.base_level - (int)t_sd->status.base_level) > battle_config.pk_level_range) ) state &= ~BCT_ENEMY; } diff --git a/src/map/battleground.c b/src/map/battleground.c index b2d6f0faf..e3fedbf34 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -220,29 +220,46 @@ int bg_team_get_id(struct block_list *bl) { nullpo_ret(bl); switch( bl->type ) { case BL_PC: - return ((TBL_PC*)bl)->bg_id; + { + const struct map_session_data *sd = BL_UCCAST(BL_PC, bl); + return sd->bg_id; + } case BL_PET: - if( ((TBL_PET*)bl)->msd ) - return ((TBL_PET*)bl)->msd->bg_id; + { + const struct pet_data *pd = BL_UCCAST(BL_PET, bl); + if (pd->msd != NULL) + return pd->msd->bg_id; + } break; case BL_MOB: { - struct map_session_data *msd; - struct mob_data *md = (TBL_MOB*)bl; + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); + const struct map_session_data *msd; if (md->special_state.ai != AI_NONE && (msd = map->id2sd(md->master_id)) != NULL) return msd->bg_id; return md->bg_id; } case BL_HOM: - if( ((TBL_HOM*)bl)->master ) - return ((TBL_HOM*)bl)->master->bg_id; + { + const struct homun_data *hd = BL_UCCAST(BL_HOM, bl); + if (hd->master != NULL) + return hd->master->bg_id; + } break; case BL_MER: - if( ((TBL_MER*)bl)->master ) - return ((TBL_MER*)bl)->master->bg_id; + { + const struct mercenary_data *md = BL_UCCAST(BL_MER, bl); + if (md->master != NULL) + return md->master->bg_id; + } break; case BL_SKILL: - return ((TBL_SKILL*)bl)->group->bg_id; + { + const struct skill_unit *su = BL_UCCAST(BL_SKILL, bl); + if (su->group != NULL) + return su->group->bg_id; + } + break; } return 0; @@ -655,7 +672,7 @@ int bg_afk_timer(int tid, int64 tick, int id, intptr_t data) { int count = 0; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( !sd->bg_queue.arena || !sd->bg_id ) continue; if( DIFF_TICK(sockt->last_tick, sd->idletime) > bg->mafksec ) diff --git a/src/map/chat.c b/src/map/chat.c index 45d4ea0cc..d60b9bece 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -53,7 +53,7 @@ struct chat_data* chat_createchat(struct block_list* bl, const char* title, cons nullpo_retr(NULL, ev); /* Given the overhead and the numerous instances (npc allocated or otherwise) wouldn't it be beneficial to have it use ERS? [Ind] */ - cd = (struct chat_data *) aMalloc(sizeof(struct chat_data)); + CREATE(cd, struct chat_data, 1); safestrncpy(cd->title, title, sizeof(cd->title)); safestrncpy(cd->pass, pass, sizeof(cd->pass)); @@ -140,7 +140,7 @@ bool chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) { nullpo_ret(sd); nullpo_ret(pass); - cd = (struct chat_data*)map->id2bl(chatid); + cd = map->id2cd(chatid); if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || ((cd->owner->type == BL_NPC) ? cd->users+1 : cd->users) >= cd->limit ) { @@ -204,7 +204,7 @@ int chat_leavechat(struct map_session_data* sd, bool kicked) { nullpo_retr(0, sd); - cd = (struct chat_data*)map->id2bl(sd->chatID); + cd = map->id2cd(sd->chatID); if( cd == NULL ) { pc_setchatid(sd, 0); return 0; @@ -247,14 +247,14 @@ int chat_leavechat(struct map_session_data* sd, bool kicked) { if( leavechar == 0 && cd->owner->type == BL_PC ) { // Set and announce new owner - cd->owner = (struct block_list*) cd->usersd[0]; + cd->owner = &cd->usersd[0]->bl; clif->changechatowner(cd, cd->usersd[0]); clif->clearchat(cd, 0); //Adjust Chat location after owner has been changed. map->delblock( &cd->bl ); - cd->bl.x=cd->usersd[0]->bl.x; - cd->bl.y=cd->usersd[0]->bl.y; + cd->bl.x = cd->owner->x; + cd->bl.y = cd->owner->y; map->addblock( &cd->bl ); clif->dispchat(cd,0); @@ -279,8 +279,8 @@ bool chat_changechatowner(struct map_session_data* sd, const char* nextownername nullpo_ret(sd); nullpo_ret(nextownername); - cd = (struct chat_data*)map->id2bl(sd->chatID); - if( cd == NULL || (struct block_list*) sd != cd->owner ) + cd = map->id2cd(sd->chatID); + if (cd == NULL || &sd->bl != cd->owner) return false; ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 ); @@ -291,7 +291,7 @@ bool chat_changechatowner(struct map_session_data* sd, const char* nextownername clif->clearchat(cd,0); // set new owner - cd->owner = (struct block_list*) cd->usersd[i]; + cd->owner = &cd->usersd[i]->bl; clif->changechatowner(cd,cd->usersd[i]); // swap the old and new owners' positions @@ -324,8 +324,8 @@ bool chat_changechatstatus(struct map_session_data* sd, const char* title, const nullpo_ret(title); nullpo_ret(pass); - cd = (struct chat_data*)map->id2bl(sd->chatID); - if( cd==NULL || (struct block_list *)sd != cd->owner ) + cd = map->id2cd(sd->chatID); + if (cd == NULL || &sd->bl != cd->owner) return false; safestrncpy(cd->title, title, CHATROOM_TITLE_SIZE); @@ -352,9 +352,9 @@ bool chat_kickchat(struct map_session_data* sd, const char* kickusername) { nullpo_ret(sd); nullpo_ret(kickusername); - cd = (struct chat_data *)map->id2bl(sd->chatID); + cd = map->id2cd(sd->chatID); - if( cd==NULL || (struct block_list *)sd != cd->owner ) + if (cd == NULL || &sd->bl != cd->owner) return false; ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 ); @@ -409,8 +409,8 @@ bool chat_deletenpcchat(struct npc_data* nd) { struct chat_data *cd; nullpo_ret(nd); - cd = (struct chat_data*)map->id2bl(nd->chat_id); - if( cd == NULL ) + cd = map->id2cd(nd->chat_id); + if (cd == NULL) return false; chat->npc_kick_all(cd); diff --git a/src/map/chrif.c b/src/map/chrif.c index e9227db73..1f7fbe96e 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -163,7 +163,8 @@ bool chrif_auth_delete(int account_id, int char_id, enum sd_state state) { } //Moves the sd character to the auth_db structure. -bool chrif_sd_to_auth(TBL_PC* sd, enum sd_state state) { +bool chrif_sd_to_auth(struct map_session_data *sd, enum sd_state state) +{ struct auth_node *node; nullpo_retr(false, sd); @@ -191,7 +192,7 @@ bool chrif_sd_to_auth(TBL_PC* sd, enum sd_state state) { return true; } -bool chrif_auth_logout(TBL_PC* sd, enum sd_state state) +bool chrif_auth_logout(struct map_session_data *sd, enum sd_state state) { nullpo_retr(false, sd); if(sd->fd && state == ST_LOGOUT) { //Disassociate player, and free it after saving ack returns. [Skotlex] @@ -204,7 +205,8 @@ bool chrif_auth_logout(TBL_PC* sd, enum sd_state state) return chrif->sd_to_auth(sd, state); } -bool chrif_auth_finished(TBL_PC* sd) { +bool chrif_auth_finished(struct map_session_data *sd) +{ struct auth_node *node; nullpo_retr(false, sd); @@ -593,7 +595,7 @@ void chrif_authok(int fd) { struct mmo_charstatus* charstatus; struct auth_node *node; bool changing_mapservers; - TBL_PC* sd; + struct map_session_data *sd = NULL; //Check if both servers agree on the struct's size if( RFIFOW(fd,2) - 25 != sizeof(struct mmo_charstatus) ) { @@ -1476,8 +1478,8 @@ int send_usercount_tochar(int tid, int64 tick, int id, intptr_t data) { *------------------------------------------*/ bool send_users_tochar(void) { int users = 0, i = 0; - struct map_session_data* sd; - struct s_mapiterator* iter; + const struct map_session_data *sd; + struct s_mapiterator *iter; chrif_check(false); @@ -1487,7 +1489,7 @@ bool send_users_tochar(void) { WFIFOW(chrif->fd,0) = 0x2aff; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { + for (sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCCAST(BL_PC, mapit->next(iter))) { WFIFOL(chrif->fd,6+8*i) = sd->status.account_id; WFIFOL(chrif->fd,6+8*i+4) = sd->status.char_id; i++; diff --git a/src/map/chrif.h b/src/map/chrif.h index d57d4d42c..6a5ec36b6 100644 --- a/src/map/chrif.h +++ b/src/map/chrif.h @@ -21,9 +21,9 @@ #ifndef MAP_CHRIF_H #define MAP_CHRIF_H -#include "map/map.h" //TBL_PC #include "common/hercules.h" #include "common/db.h" +#include "common/mmo.h" struct eri; struct map_session_data; @@ -129,9 +129,9 @@ struct chrif_interface { bool (*flush) (void); void (*skillid2idx) (int fd); - bool (*sd_to_auth) (TBL_PC* sd, enum sd_state state); + bool (*sd_to_auth) (struct map_session_data *sd, enum sd_state state); int (*check_connect_char_server) (int tid, int64 tick, int id, intptr_t data); - bool (*auth_logout) (TBL_PC* sd, enum sd_state state); + bool (*auth_logout) (struct map_session_data *sd, enum sd_state state); void (*save_ack) (int fd); int (*reconnect) (DBKey key, DBData *data, va_list ap); int (*auth_db_cleanup_sub) (DBKey key, DBData *data, va_list ap); diff --git a/src/map/clif.c b/src/map/clif.c index 053017a4a..827f57c45 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -190,8 +190,12 @@ static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, s #endif // 0 //To identify disguised characters. -static inline bool disguised(struct block_list* bl) { - return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise != -1 ); +static inline bool disguised(struct block_list* bl) +{ + struct map_session_data *sd = BL_CAST(BL_PC, bl); + if (sd == NULL || sd->disguise == -1) + return false; + return true; } //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex] @@ -313,7 +317,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. @@ -334,15 +339,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; @@ -404,7 +408,7 @@ bool clif_send(const void* buf, int len, struct block_list* bl, enum send_target case ALL_CLIENT: //All player clients. iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { + while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); WFIFOSET(tsd->fd,len); @@ -414,7 +418,7 @@ bool clif_send(const void* buf, int len, struct block_list* bl, enum send_target case ALL_SAMEMAP: //All players on the same map iter = mapit_getallusers(); - while ((tsd = (TBL_PC*)mapit->next(iter)) != NULL) { + while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) { if (bl && bl->m == tsd->bl.m) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); @@ -445,12 +449,12 @@ bool clif_send(const void* buf, int len, struct block_list* bl, enum send_target case CHAT_WOS: nullpo_retr(true, bl); { - struct chat_data *cd; - if (sd) { - cd = (struct chat_data*)map->id2bl(sd->chatID); - } else if (bl->type == BL_CHAT) { - cd = (struct chat_data*)bl; - } else break; + const struct chat_data *cd = NULL; + if (sd != NULL) { + cd = map->id2cd(sd->chatID); + } else { + cd = BL_CCAST(BL_CHAT, bl); + } if (cd == NULL) break; for(i = 0; i < cd->users; i++) { @@ -505,7 +509,7 @@ bool clif_send(const void* buf, int len, struct block_list* bl, enum send_target break; iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { + while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) { if( tsd->partyspy == p->party.party_id ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); @@ -521,7 +525,7 @@ bool clif_send(const void* buf, int len, struct block_list* bl, enum send_target if (!sd || !sd->duel_group) break; //Invalid usage. iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { + while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) { if( type == DUEL_WOS && bl->id == tsd->bl.id ) continue; if( sd->duel_group == tsd->duel_group ) { @@ -584,7 +588,7 @@ bool clif_send(const void* buf, int len, struct block_list* bl, enum send_target break; iter = mapit_getallusers(); - while( (tsd = (TBL_PC*)mapit->next(iter)) != NULL ) { + while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) { if( tsd->guildspy == g->guild_id ) { WFIFOHEAD(tsd->fd, len); memcpy(WFIFOP(tsd->fd,0), buf, len); @@ -946,7 +950,7 @@ void clif_set_unit_idle2(struct block_list* bl, struct map_session_data *tsd, en p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0; + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.job = vd->class_; p.head = vd->hair_style; p.weapon = vd->weapon; @@ -1013,7 +1017,7 @@ void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enu p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0; + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.job = vd->class_; p.head = vd->hair_style; p.weapon = vd->weapon; @@ -1049,9 +1053,10 @@ void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enu #endif #if PACKETVER >= 20120221 if (battle_config.show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); p.maxHP = status_get_max_hp(bl); p.HP = status_get_hp(bl); - p.isBoss = ( ((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss ) ? 1 : 0; + p.isBoss = (md->spawn != NULL && md->spawn->state.boss) ? 1 : 0; } else { p.maxHP = -1; p.HP = -1; @@ -1095,7 +1100,7 @@ void clif_spawn_unit2(struct block_list* bl, enum send_target target) { p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0; + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.head = vd->hair_style; p.weapon = vd->weapon; p.accessory = vd->head_bottom; @@ -1153,7 +1158,7 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) { p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0; + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.job = vd->class_; p.head = vd->hair_style; p.weapon = vd->weapon; @@ -1188,9 +1193,10 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) { #endif #if PACKETVER >= 20120221 if (battle_config.show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); p.maxHP = status_get_max_hp(bl); p.HP = status_get_hp(bl); - p.isBoss = ( ((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss ) ? 1 : 0; + p.isBoss = (md->spawn != NULL && md->spawn->state.boss) ? 1 : 0; } else { p.maxHP = -1; p.HP = -1; @@ -1247,7 +1253,7 @@ void clif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd, p.speed = status->get_speed(bl); p.bodyState = (sc) ? sc->opt1 : 0; p.healthState = (sc) ? sc->opt2 : 0; - p.effectState = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0; + p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); p.job = vd->class_; p.head = vd->hair_style; p.weapon = vd->weapon; @@ -1278,9 +1284,10 @@ void clif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd, #endif #if PACKETVER >= 20120221 if (battle_config.show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); p.maxHP = status_get_max_hp(bl); p.HP = status_get_hp(bl); - p.isBoss = ( ((TBL_MOB*)bl)->spawn && ((TBL_MOB*)bl)->spawn->state.boss ) ? 1 : 0; + p.isBoss = (md->spawn != NULL && md->spawn->state.boss) ? 1 : 0; } else { p.maxHP = -1; p.HP = -1; @@ -1387,8 +1394,7 @@ void clif_weather(int16 m) struct map_session_data *sd=NULL; iter = mapit_getallusers(); - for( sd = (struct map_session_data*)mapit->first(iter); mapit->exists(iter); sd = (struct map_session_data*)mapit->next(iter) ) - { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( sd->bl.m == m ) clif->weather_check(sd); } @@ -1406,13 +1412,15 @@ bool clif_spawn(struct block_list *bl) if( !vd ) return false; - if( ( bl->type == BL_NPC - && !((TBL_NPC*)bl)->chat_id - && (((TBL_NPC*)bl)->option&OPTION_INVISIBLE) ) // Hide NPC from maya purple card. - || ( vd->class_ == INVISIBLE_CLASS ) - ) + if (vd->class_ == INVISIBLE_CLASS) return true; // Doesn't need to be spawned, so everything is alright + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->chat_id == 0 && (nd->option&OPTION_INVISIBLE)) // Hide NPC from maya purple card. + return true; // Doesn't need to be spawned, so everything is alright + } + clif->spawn_unit(bl,AREA_WOS); if (vd->cloth_color) @@ -1422,47 +1430,47 @@ bool clif_spawn(struct block_list *bl) switch (bl->type) { case BL_PC: - { - TBL_PC *sd = ((TBL_PC*)bl); - int i; - if (sd->spiritball > 0) - clif->spiritball(&sd->bl); - if(sd->state.size==SZ_BIG) // tiny/big players [Valaris] - clif->specialeffect(bl,423,AREA); - else if(sd->state.size==SZ_MEDIUM) - clif->specialeffect(bl,421,AREA); - if( sd->bg_id && map->list[sd->bl.m].flag.battleground ) - clif->sendbgemblem_area(sd); - for( i = 0; i < sd->sc_display_count; i++ ) { - clif->sc_load(&sd->bl, sd->bl.id,AREA,status->dbs->IconChangeTable[sd->sc_display[i]->type],sd->sc_display[i]->val1,sd->sc_display[i]->val2,sd->sc_display[i]->val3); - } - if (sd->charm_type != CHARM_TYPE_NONE && sd->charm_count > 0) - clif->spiritcharm(sd); - if (sd->status.robe) - clif->refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA); + { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + int i; + if (sd->spiritball > 0) + clif->spiritball(&sd->bl); + if (sd->state.size == SZ_BIG) // tiny/big players [Valaris] + clif->specialeffect(bl,423,AREA); + else if (sd->state.size == SZ_MEDIUM) + clif->specialeffect(bl,421,AREA); + if (sd->bg_id != 0 && map->list[sd->bl.m].flag.battleground) + clif->sendbgemblem_area(sd); + for (i = 0; i < sd->sc_display_count; i++) { + clif->sc_load(&sd->bl, sd->bl.id,AREA,status->dbs->IconChangeTable[sd->sc_display[i]->type],sd->sc_display[i]->val1,sd->sc_display[i]->val2,sd->sc_display[i]->val3); } + if (sd->charm_type != CHARM_TYPE_NONE && sd->charm_count > 0) + clif->spiritcharm(sd); + if (sd->status.robe) + clif->refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA); + } break; case BL_MOB: - { - TBL_MOB *md = ((TBL_MOB*)bl); - if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris] - clif->specialeffect(&md->bl,423,AREA); - else if(md->special_state.size==SZ_MEDIUM) - clif->specialeffect(&md->bl,421,AREA); - } + { + struct mob_data *md = BL_UCAST(BL_MOB, bl); + if (md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris] + clif->specialeffect(&md->bl,423,AREA); + else if (md->special_state.size==SZ_MEDIUM) + clif->specialeffect(&md->bl,421,AREA); + } break; case BL_NPC: - { - TBL_NPC *nd = ((TBL_NPC*)bl); - if( nd->size == SZ_BIG ) - clif->specialeffect(&nd->bl,423,AREA); - else if( nd->size == SZ_MEDIUM ) - clif->specialeffect(&nd->bl,421,AREA); - } + { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->size == SZ_BIG) + clif->specialeffect(&nd->bl,423,AREA); + else if (nd->size == SZ_MEDIUM) + clif->specialeffect(&nd->bl,421,AREA); + } break; case BL_PET: if (vd->head_bottom) - clif->send_petdata(NULL, (TBL_PET*)bl, 3, vd->head_bottom); // needed to display pet equip properly + clif->send_petdata(NULL, BL_UCAST(BL_PET, bl), 3, vd->head_bottom); // needed to display pet equip properly break; } return true; @@ -1688,27 +1696,27 @@ void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *u switch(bl->type) { case BL_PC: - { - TBL_PC *sd = ((TBL_PC*)bl); - //clif_movepc(sd); - if(sd->state.size==SZ_BIG) // tiny/big players [Valaris] - clif->specialeffect(&sd->bl,423,AREA); - else if(sd->state.size==SZ_MEDIUM) - clif->specialeffect(&sd->bl,421,AREA); - } + { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + //clif_movepc(sd); + if(sd->state.size==SZ_BIG) // tiny/big players [Valaris] + clif->specialeffect(&sd->bl,423,AREA); + else if(sd->state.size==SZ_MEDIUM) + clif->specialeffect(&sd->bl,421,AREA); + } break; case BL_MOB: - { - TBL_MOB *md = ((TBL_MOB*)bl); - if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris] - clif->specialeffect(&md->bl,423,AREA); - else if(md->special_state.size==SZ_MEDIUM) - clif->specialeffect(&md->bl,421,AREA); - } + { + struct mob_data *md = BL_UCAST(BL_MOB, bl); + if (md->special_state.size == SZ_BIG) // tiny/big mobs [Valaris] + clif->specialeffect(&md->bl,423,AREA); + else if (md->special_state.size == SZ_MEDIUM) + clif->specialeffect(&md->bl,421,AREA); + } break; case BL_PET: if( vd->head_bottom ) // needed to display pet equip properly - clif->send_petdata(NULL, (TBL_PET*)bl, 3, vd->head_bottom); + clif->send_petdata(NULL, BL_UCAST(BL_PET, bl), 3, vd->head_bottom); break; } #ifdef ANTI_MAYAP_CHEAT @@ -1735,11 +1743,12 @@ void clif_move(struct unit_data *ud) if (!vd || vd->class_ == INVISIBLE_CLASS) return; //This performance check is needed to keep GM-hidden objects from being notified to bots. - /** - * Hide NPC from maya purple card. - **/ - if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->option&OPTION_INVISIBLE)) - return; + if (bl->type == BL_NPC) { + // Hide NPC from maya purple card. + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->chat_id == 0 && (nd->option&OPTION_INVISIBLE)) + return; + } if (ud->state.speed_changed) { // Since we don't know how to update the speed of other objects, @@ -2765,16 +2774,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 = (TBL_PC *)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); @@ -3491,7 +3499,7 @@ void clif_changeoption(struct block_list* bl) WBUFL(buf,2) = bl->id; WBUFW(buf,6) = (sc) ? sc->opt1 : 0; WBUFW(buf,8) = (sc) ? sc->opt2 : 0; - WBUFL(buf,10) = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0; + WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); WBUFB(buf,14) = (sd)? sd->status.karma : 0; if(disguised(bl)) { clif->send(buf,packet_len(0x229),bl,AREA_WOS); @@ -3507,7 +3515,7 @@ void clif_changeoption(struct block_list* bl) WBUFL(buf,2) = bl->id; WBUFW(buf,6) = (sc) ? sc->opt1 : 0; WBUFW(buf,8) = (sc) ? sc->opt2 : 0; - WBUFL(buf,10) = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0; + WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); WBUFB(buf,12) = (sd)? sd->status.karma : 0; if(disguised(bl)) { clif->send(buf,packet_len(0x119),bl,AREA_WOS); @@ -3532,7 +3540,7 @@ void clif_changeoption2(struct block_list* bl) { WBUFW(buf,0) = 0x28a; WBUFL(buf,2) = bl->id; - WBUFL(buf,6) = (sc) ? sc->option : bl->type == BL_NPC ? ((TBL_NPC*)bl)->option : 0; + WBUFL(buf,6) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0); WBUFL(buf,10) = clif_setlevel(bl); WBUFL(buf,14) = (sc) ? sc->opt3 : 0; if(disguised(bl)) { @@ -3742,10 +3750,11 @@ void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd) WFIFOW(fd, 2) = 8 + (28*(cd->users+t)); WFIFOL(fd, 4) = cd->bl.id; - if(cd->owner->type == BL_NPC){ + if(cd->owner->type == BL_NPC) { + const struct npc_data *nd = BL_UCCAST(BL_NPC, cd->owner); WFIFOL(fd, 30) = 1; WFIFOL(fd, 8) = 0; - memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH); + memcpy(WFIFOP(fd, 12), nd->name, NAME_LENGTH); for (i = 0; i < cd->users; i++) { WFIFOL(fd, 8+(i+1)*28) = 1; memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH); @@ -4120,8 +4129,8 @@ void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* ds nullpo_retv(sd); nullpo_retv(dstsd); if( dstsd->chatID ) { - struct chat_data *cd = NULL; - if( (cd = (struct chat_data*)map->id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd) + struct chat_data *cd = map->id2cd(dstsd->chatID); + if (cd != NULL && cd->usersd[0] == dstsd) clif->dispchat(cd,sd->fd); } else if( dstsd->state.vending ) clif->showvendingboard(&dstsd->bl,dstsd->message,sd->fd); @@ -4164,11 +4173,12 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) { if (!vd || vd->class_ == INVISIBLE_CLASS) return; - /** - * Hide NPC from maya purple card. - **/ - if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->option&OPTION_INVISIBLE)) - return; + if (bl->type == BL_NPC) { + // Hide NPC from maya purple card. + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->chat_id == 0 && (nd->option&OPTION_INVISIBLE)) + return; + } if ( ( ud = unit->bl2ud(bl) ) && ud->walktimer != INVALID_TIMER ) clif->set_unit_walking(bl,sd,ud,SELF); @@ -4182,57 +4192,60 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) { switch (bl->type) { case BL_PC: - { - TBL_PC* tsd = (TBL_PC*)bl; - clif->getareachar_pc(sd, tsd); - if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris] - clif->specialeffect_single(bl,423,sd->fd); - else if(tsd->state.size==SZ_MEDIUM) - clif->specialeffect_single(bl,421,sd->fd); - if( tsd->bg_id && map->list[tsd->bl.m].flag.battleground ) - clif->sendbgemblem_single(sd->fd,tsd); - if ( tsd->status.robe ) - clif->refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF); - } + { + struct map_session_data *tsd = BL_UCAST(BL_PC, bl); + clif->getareachar_pc(sd, tsd); + if (tsd->state.size == SZ_BIG) // tiny/big players [Valaris] + clif->specialeffect_single(bl,423,sd->fd); + else if (tsd->state.size == SZ_MEDIUM) + clif->specialeffect_single(bl,421,sd->fd); + if (tsd->bg_id != 0 && map->list[tsd->bl.m].flag.battleground) + clif->sendbgemblem_single(sd->fd,tsd); + if (tsd->status.robe) + clif->refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF); + } break; case BL_MER: // Devotion Effects - if( ((TBL_MER*)bl)->devotion_flag ) + { + struct mercenary_data *md = BL_UCAST(BL_MER, bl); + if (md->devotion_flag) clif->devotion(bl, sd); + } break; case BL_NPC: - { - TBL_NPC* nd = (TBL_NPC*)bl; - if( nd->chat_id ) - clif->dispchat((struct chat_data*)map->id2bl(nd->chat_id),sd->fd); - if( nd->size == SZ_BIG ) - clif->specialeffect_single(bl,423,sd->fd); - else if( nd->size == SZ_MEDIUM ) - clif->specialeffect_single(bl,421,sd->fd); - } + { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->chat_id != 0) + clif->dispchat(map->id2cd(nd->chat_id), sd->fd); + if (nd->size == SZ_BIG) + clif->specialeffect_single(bl,423,sd->fd); + else if (nd->size == SZ_MEDIUM) + clif->specialeffect_single(bl,421,sd->fd); + } break; case BL_MOB: - { - TBL_MOB* md = (TBL_MOB*)bl; - if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris] - clif->specialeffect_single(bl,423,sd->fd); - else if(md->special_state.size==SZ_MEDIUM) - clif->specialeffect_single(bl,421,sd->fd); + { + struct mob_data *md = BL_UCAST(BL_MOB, bl); + if (md->special_state.size == SZ_BIG) // tiny/big mobs [Valaris] + clif->specialeffect_single(bl,423,sd->fd); + else if (md->special_state.size == SZ_MEDIUM) + clif->specialeffect_single(bl,421,sd->fd); #if (PACKETVER >= 20120404 && PACKETVER < 20131223) - if (battle_config.show_monster_hp_bar && !(md->status.mode&MD_BOSS)) { - int i; - for(i = 0; i < DAMAGELOG_SIZE; i++) {// must show hp bar to all char who already hit the mob. - if (md->dmglog[i].id == sd->status.char_id) { - clif->monster_hp_bar(md, sd); - break; - } + if (battle_config.show_monster_hp_bar && !(md->status.mode&MD_BOSS)) { + int i; + for (i = 0; i < DAMAGELOG_SIZE; i++) {// must show hp bar to all char who already hit the mob. + if (md->dmglog[i].id == sd->status.char_id) { + clif->monster_hp_bar(md, sd); + break; } } -#endif } +#endif + } break; case BL_PET: if (vd->head_bottom) - clif->send_petdata(NULL, (TBL_PET*)bl, 3, vd->head_bottom); // needed to display pet equip properly + clif->send_petdata(NULL, BL_UCAST(BL_PET, bl), 3, vd->head_bottom); // needed to display pet equip properly break; } } @@ -4522,8 +4535,10 @@ void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *su, en clif->send(&p,sizeof(p),bl,target); - if(su->group->skill_id == WZ_ICEWALL) - clif->changemapcell(bl->type == BL_PC ? ((TBL_PC*)bl)->fd : 0,su->bl.m,su->bl.x,su->bl.y,5,SELF); + if (su->group->skill_id == WZ_ICEWALL) { + struct map_session_data *sd = BL_CAST(BL_PC, bl); + clif->changemapcell(sd != NULL ? sd->fd : 0, su->bl.m, su->bl.x, su->bl.y, 5, SELF); + } } /*========================================== @@ -4582,10 +4597,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,(TBL_SKILL*)bl,SELF); + clif->getareachar_skillunit(&sd->bl, BL_UCAST(BL_SKILL, bl), SELF); break; default: if(&sd->bl == bl) @@ -4603,7 +4618,7 @@ int clif_outsight(struct block_list *bl,va_list ap) { struct block_list *tbl; struct view_data *vd; - TBL_PC *sd, *tsd; + struct map_session_data *sd, *tsd; tbl=va_arg(ap,struct block_list*); if(bl == tbl) return 0; // bl can be null pointer? and after if BL_PC, sd will be null pointer too @@ -4616,9 +4631,8 @@ int clif_outsight(struct block_list *bl,va_list ap) case BL_PC: if (sd->vd.class_ != INVISIBLE_CLASS) clif->clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd); - if(sd->chatID){ - struct chat_data *cd; - cd=(struct chat_data*)map->id2bl(sd->chatID); + if (sd->chatID) { + struct chat_data *cd = map->id2cd(sd->chatID); if(cd->usersd[0]==sd) clif->dispchat(cd,tsd->fd); } @@ -4628,13 +4642,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( !(((TBL_NPC*)bl)->option&OPTION_INVISIBLE) ) + if (!(BL_UCAST(BL_NPC, bl)->option&OPTION_INVISIBLE)) clif->clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd); break; default: @@ -4645,10 +4659,10 @@ 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); - else if (((vd=status->get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) && - !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->option&OPTION_INVISIBLE))) + if (tbl->type == BL_SKILL) //Trap knocked out of sight + 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 && (BL_UCAST(BL_NPC, tbl)->option&OPTION_INVISIBLE))) clif->clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd); } return 0; @@ -4660,7 +4674,7 @@ int clif_outsight(struct block_list *bl,va_list ap) int clif_insight(struct block_list *bl,va_list ap) { struct block_list *tbl; - TBL_PC *sd, *tsd; + struct map_session_data *sd, *tsd; tbl=va_arg(ap,struct block_list*); if (bl == tbl) return 0; @@ -4672,10 +4686,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,(TBL_SKILL*)bl,SELF); + clif->getareachar_skillunit(&tsd->bl, BL_UCAST(BL_SKILL, bl), SELF); break; default: clif->getareachar_unit(tsd,bl); @@ -5669,11 +5683,13 @@ void clif_resurrection(struct block_list *bl,int type) clif->send(buf,packet_len(0x148),bl, type == 1 ? AREA : AREA_WOS); if (disguised(bl)) { - if( ((TBL_PC*)bl)->fontcolor ) { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + if (sd->fontcolor) { WBUFL(buf,2)=-bl->id; clif->send(buf,packet_len(0x148),bl, SELF); - } else + } else { clif->spawn(bl); + } } } @@ -7013,8 +7029,8 @@ void clif_devotion(struct block_list *src, struct map_session_data *tsd) *------------------------------------------*/ void clif_spiritball(struct block_list *bl) { unsigned char buf[16]; - TBL_PC *sd = BL_CAST(BL_PC,bl); - TBL_HOM *hd = BL_CAST(BL_HOM,bl); + struct map_session_data *sd = BL_CAST(BL_PC,bl); + struct homun_data *hd = BL_CAST(BL_HOM,bl); nullpo_retv(bl); @@ -8353,114 +8369,110 @@ void clif_charnameack (int fd, struct block_list *bl) switch( bl->type ) { case BL_PC: - { - struct map_session_data *ssd = (struct map_session_data *)bl; - struct party_data *p = NULL; - struct guild *g = NULL; - int ps = -1; - - //Requesting your own "shadow" name. [Skotlex] - if (ssd->fd == fd && ssd->disguise != -1) - WBUFL(buf,2) = -bl->id; - - if( ssd->fakename[0] ) { - WBUFW(buf, 0) = cmd = 0x195; - memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH); - WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0; - break; - } - memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH); + { + const struct map_session_data *ssd = BL_UCCAST(BL_PC, bl); + const struct party_data *p = NULL; + const struct guild *g = NULL; + int ps = -1; - if( ssd->status.party_id ) { - p = party->search(ssd->status.party_id); - } - if( ssd->status.guild_id ) { - if ((g = ssd->guild ) != NULL) { - int i; - ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id); - if( i < g->max_member ) ps = g->member[i].position; - } - } + //Requesting your own "shadow" name. [Skotlex] + if (ssd->fd == fd && ssd->disguise != -1) + WBUFL(buf,2) = -bl->id; + + if (ssd->fakename[0] != '\0') { + WBUFW(buf, 0) = cmd = 0x195; + memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH); + WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0; + break; + } + memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH); - if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild - p = NULL; + if (ssd->status.party_id != 0) { + p = party->search(ssd->status.party_id); + } + if (ssd->status.guild_id != 0) { + if ((g = ssd->guild) != NULL) { + int i; + ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id); + if (i < g->max_member) + ps = g->member[i].position; } + } - if (p == NULL && g == NULL) - break; + if (!battle_config.display_party_name && g == NULL) { + // do not display party unless the player is also in a guild + p = NULL; + } - WBUFW(buf, 0) = cmd = 0x195; - if (p) - memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH); - else - WBUFB(buf,30) = 0; + if (p == NULL && g == NULL) + break; - if (g && ps >= 0 && ps < MAX_GUILDPOSITION) - { - memcpy(WBUFP(buf,54), g->name,NAME_LENGTH); - memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH); - } else { //Assume no guild. - WBUFB(buf,54) = 0; - WBUFB(buf,78) = 0; - } + WBUFW(buf, 0) = cmd = 0x195; + if (p != NULL) + memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH); + else + WBUFB(buf,30) = 0; + + if (g != NULL && ps >= 0 && ps < MAX_GUILDPOSITION) { + memcpy(WBUFP(buf,54), g->name,NAME_LENGTH); + memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH); + } else { //Assume no guild. + WBUFB(buf,54) = 0; + WBUFB(buf,78) = 0; } + } break; //[blackhole89] case BL_HOM: - memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_HOM, bl)->homunculus.name, NAME_LENGTH); break; case BL_MER: - memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_MER, bl)->db->name, NAME_LENGTH); break; case BL_PET: - memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_PET, bl)->pet.name, NAME_LENGTH); break; case BL_NPC: - memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_NPC, bl)->name, NAME_LENGTH); break; case BL_MOB: - { - struct mob_data *md = (struct mob_data *)bl; - nullpo_retv(md); - - memcpy(WBUFP(buf,6), md->name, NAME_LENGTH); - if( md->guardian_data && md->guardian_data->g ) - { - WBUFW(buf, 0) = cmd = 0x195; - WBUFB(buf,30) = 0; - memcpy(WBUFP(buf,54), md->guardian_data->g->name, NAME_LENGTH); - memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH); - } - else if( battle_config.show_mob_info ) - { - char mobhp[50], *str_p = mobhp; - WBUFW(buf, 0) = cmd = 0x195; - if( battle_config.show_mob_info&4 ) - str_p += sprintf(str_p, "Lv. %d | ", md->level); - if( battle_config.show_mob_info&1 ) - str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp); - if( battle_config.show_mob_info&2 ) - str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp)); - //Even thought mobhp ain't a name, we send it as one so the client - //can parse it. [Skotlex] - if( str_p != mobhp ) - { - *(str_p-3) = '\0'; //Remove trailing space + pipe. - memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH); - WBUFB(buf,54) = 0; - WBUFB(buf,78) = 0; - } + { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); + + memcpy(WBUFP(buf,6), md->name, NAME_LENGTH); + if (md->guardian_data && md->guardian_data->g) { + WBUFW(buf, 0) = cmd = 0x195; + WBUFB(buf,30) = 0; + memcpy(WBUFP(buf,54), md->guardian_data->g->name, NAME_LENGTH); + memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH); + } else if (battle_config.show_mob_info) { + char mobhp[50], *str_p = mobhp; + WBUFW(buf, 0) = cmd = 0x195; + if (battle_config.show_mob_info&4) + str_p += sprintf(str_p, "Lv. %d | ", md->level); + if (battle_config.show_mob_info&1) + str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp); + if (battle_config.show_mob_info&2) + str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp)); + //Even thought mobhp ain't a name, we send it as one so the client + //can parse it. [Skotlex] + if (str_p != mobhp) { + *(str_p-3) = '\0'; //Remove trailing space + pipe. + memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH); + WBUFB(buf,54) = 0; + WBUFB(buf,78) = 0; } } + } break; case BL_CHAT: #if 0 //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex] - memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_CHAT, bl)->title, NAME_LENGTH); break; #endif return; case BL_ELEM: - memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH); + memcpy(WBUFP(buf,6), BL_UCCAST(BL_ELEM, bl)->db->name, NAME_LENGTH); break; default: ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id); @@ -8468,9 +8480,9 @@ void clif_charnameack (int fd, struct block_list *bl) } // if no recipient specified just update nearby clients - if (fd == 0) + if (fd == 0) { clif->send(buf, packet_len(cmd), bl, AREA); - else { + } else { WFIFOHEAD(fd, packet_len(cmd)); memcpy(WFIFOP(fd, 0), buf, packet_len(cmd)); WFIFOSET(fd, packet_len(cmd)); @@ -9087,7 +9099,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data* sd) { return; } - CREATE(sd, TBL_PC, 1); + CREATE(sd, struct map_session_data, 1); sd->fd = fd; sd->cryptKey = (( ((( clif->cryptKey[0] * clif->cryptKey[1] ) + clif->cryptKey[2]) & 0xFFFFFFFF) @@ -9890,7 +9902,7 @@ void clif_changed_dir(struct block_list *bl, enum send_target target) nullpo_retv(bl); WBUFW(buf,0) = 0x9c; WBUFL(buf,2) = bl->id; - WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0; + WBUFW(buf,6) = bl->type == BL_PC ? BL_UCCAST(BL_PC, bl)->head_dir : 0; WBUFB(buf,8) = unit->getdir(bl); clif->send(buf, packet_len(0x9c), bl, target); @@ -9973,9 +9985,8 @@ void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) { clif->user_count(sd, map->getusers()); } -void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, int64 tick) { - struct block_list *target = NULL; - +void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, int64 tick) +{ nullpo_retv(sd); if (pc_isdead(sd)) { clif->clearunit_area(&sd->bl, CLR_DEAD); @@ -10002,8 +10013,10 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, switch(action_type) { case 0x00: // once attack case 0x07: // continuous attack - if( (target = map->id2bl(target_id)) && target->type == BL_NPC ) { - npc->click(sd,(TBL_NPC*)target); + { + struct npc_data *nd = map->id2nd(target_id); + if (nd != NULL) { + npc->click(sd, nd); return; } @@ -10023,6 +10036,7 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, pc->delinvincibletimer(sd); pc->update_idle_time(sd, BCIDLE_ATTACK); unit->attack(&sd->bl, target_id, action_type != 0); + } break; case 0x02: // sitdown if (battle_config.basic_skill_check && pc->checkskill(sd, NV_BASIC) < 3) { @@ -10280,13 +10294,10 @@ void clif_parse_TakeItem(int fd, struct map_session_data *sd) __attribute__((non /// 009f <id>.L (CZ_ITEM_PICKUP) /// 0362 <id>.L (CZ_ITEM_PICKUP2) /// There are various variants of this packet, some of them have padding between fields. -void clif_parse_TakeItem(int fd, struct map_session_data *sd) { - struct flooritem_data *fitem; - int map_object_id; - - map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); - - fitem = (struct flooritem_data*)map->id2bl(map_object_id); +void clif_parse_TakeItem(int fd, struct map_session_data *sd) +{ + int map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); + struct flooritem_data *fitem = map->id2fi(map_object_id); do { if (pc_isdead(sd)) { @@ -10294,7 +10305,7 @@ void clif_parse_TakeItem(int fd, struct map_session_data *sd) { break; } - if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m) + if (fitem == NULL || fitem->bl.m != sd->bl.m) break; if( sd->sc.count && ( @@ -10490,7 +10501,7 @@ void clif_parse_NpcClicked(int fd,struct map_session_data *sd) break; } if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt) - npc->click(sd,(TBL_NPC*)bl); + npc->click(sd, BL_UCAST(BL_NPC, bl)); break; } } @@ -11370,7 +11381,7 @@ void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd) #ifdef SECURE_NPCTIMEOUT if( sd->npc_idle_timer != INVALID_TIMER ) { #endif - TBL_NPC* nd = map->id2nd(npc_id); + struct npc_data *nd = map->id2nd(npc_id); ShowWarning("Invalid menu selection on npc %d:'%s' - got %d, valid range is [%d..%d] (player AID:%d, CID:%d, name:'%s')!\n", npc_id, (nd)?nd->name:"invalid npc id", select, 1, sd->npc_menu, sd->bl.id, sd->status.char_id, sd->status.name); clif->GM_kick(NULL,sd); #ifdef SECURE_NPCTIMEOUT @@ -13220,7 +13231,7 @@ void clif_parse_GMKick(int fd, struct map_session_data *sd) { case BL_NPC: { - struct npc_data* nd = (struct npc_data *)target; + struct npc_data *nd = BL_UCAST(BL_NPC, target); if( !pc->can_use_command(sd, "@unloadnpc")) { clif->GM_kickack(sd, 0); return; @@ -17604,7 +17615,7 @@ void clif_status_change_end(struct block_list *bl, int tid, enum send_target tar nullpo_retv(bl); - if( bl->type == BL_PC && !((TBL_PC*)bl)->state.active ) + if (bl->type == BL_PC && !BL_UCAST(BL_PC, bl)->state.active) return; p.PacketType = status_change_endType; @@ -18638,7 +18649,7 @@ unsigned short clif_parse_cmd_optional( int fd, struct map_session_data *sd ) { *------------------------------------------*/ int clif_parse(int fd) { int cmd, packet_len; - TBL_PC* sd; + struct map_session_data *sd; int pnum; //TODO apply delays or disconnect based on packet throughput [FlavioJS] @@ -18648,7 +18659,7 @@ int clif_parse(int fd) { unsigned short (*parse_cmd_func)(int fd, struct map_session_data *sd); // begin main client packet processing loop - sd = (TBL_PC *)sockt->session[fd]->session_data; + sd = sockt->session[fd]->session_data; if (sockt->session[fd]->flag.eof) { if (sd) { diff --git a/src/map/duel.c b/src/map/duel.c index 8f309abe4..c658ea3e3 100644 --- a/src/map/duel.c +++ b/src/map/duel.c @@ -134,7 +134,7 @@ void duel_invite(const unsigned int did, struct map_session_data* sd, struct map // "Blue -- Player %s invites you to PVP duel (@accept/@reject) --" sprintf(output, msg_sd(target_sd,374), sd->status.name); - clif->broadcast((struct block_list *)target_sd, output, strlen(output)+1, BC_BLUE, SELF); + clif->broadcast(&target_sd->bl, output, strlen(output)+1, BC_BLUE, SELF); } static int duel_leave_sub(struct map_session_data* sd, va_list va) diff --git a/src/map/elemental.c b/src/map/elemental.c index a6fe94ab2..a87deb7d7 100644 --- a/src/map/elemental.c +++ b/src/map/elemental.c @@ -273,9 +273,10 @@ int elemental_data_received(struct s_elemental *ele, bool flag) { db = &elemental->db[i]; if( !sd->ed ) { // Initialize it after first summon. - sd->ed = ed = (struct elemental_data*)aCalloc(1,sizeof(struct elemental_data)); + CREATE(ed, struct elemental_data, 1); ed->bl.type = BL_ELEM; ed->bl.id = npc->get_new_npc_id(); + sd->ed = ed; ed->master = sd; ed->db = db; memcpy(&ed->elemental, ele, sizeof(struct s_elemental)); diff --git a/src/map/guild.c b/src/map/guild.c index 10511067a..cba05638f 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -57,8 +57,9 @@ struct guild_interface *guild; /*========================================== * Retrieves and validates the sd pointer for this guild member [Skotlex] *------------------------------------------*/ -TBL_PC* guild_sd_check(int guild_id, int account_id, int char_id) { - TBL_PC* sd = map->id2sd(account_id); +struct map_session_data *guild_sd_check(int guild_id, int account_id, int char_id) +{ + struct map_session_data *sd = map->id2sd(account_id); if (!(sd && sd->status.char_id == char_id)) return NULL; @@ -441,8 +442,7 @@ int guild_check_member(struct guild *g) nullpo_ret(g); iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) - { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( sd->status.guild_id != g->guild_id ) continue; @@ -465,7 +465,7 @@ int guild_recv_noinfo(int guild_id) struct s_mapiterator* iter; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( sd->status.guild_id == guild_id ) sd->status.guild_id = 0; // erase guild } @@ -505,7 +505,7 @@ int guild_recv_info(struct guild *sg) { tg[i] = guild->search(sg->alliance[i].guild_id); } - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if (!sd->status.guild_id) continue; // Not interested in guildless users @@ -939,14 +939,14 @@ int guild_member_withdraw(int guild_id, int account_id, int char_id, int flag, c void guild_retrieveitembound(int char_id,int aid,int guild_id) { #ifdef GP_BOUND_ITEMS - TBL_PC *sd = map->charid2sd(char_id); - if(sd){ //Character is online + struct map_session_data *sd = map->charid2sd(char_id); + if (sd != NULL) { //Character is online pc->bound_clear(sd,IBT_GUILD); } else { //Character is offline, ask char server to do the job struct guild_storage *gstor = idb_get(gstorage->db,guild_id); if(gstor && gstor->storage_status == 1) { //Someone is in guild storage, close them struct s_mapiterator* iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if(sd->status.guild_id == guild_id && sd->state.storage_flag == STORAGE_FLAG_GUILD) { gstorage->close(sd); break; @@ -1229,7 +1229,7 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) continue; // update permanent guardians for( i = 0; i < ARRAYLENGTH(gc->guardian); ++i ) { - TBL_MOB* md = (gc->guardian[i].id ? map->id2md(gc->guardian[i].id) : NULL); + struct mob_data *md = gc->guardian[i].id ? map->id2md(gc->guardian[i].id) : NULL; if( md == NULL || md->guardian_data == NULL ) continue; @@ -1237,7 +1237,7 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) } // update temporary guardians for( i = 0; i < gc->temp_guardians_max; ++i ) { - TBL_MOB* md = (gc->temp_guardians[i] ? map->id2md(gc->temp_guardians[i]) : NULL); + struct mob_data *md = gc->temp_guardians[i] ? map->id2md(gc->temp_guardians[i]) : NULL; if( md == NULL || md->guardian_data == NULL ) continue; @@ -1328,7 +1328,7 @@ int guild_getexp(struct map_session_data *sd,int exp) /*==================================================== * Ask to increase guildskill skill_id *---------------------------------------------------*/ -int guild_skillup(TBL_PC* sd, uint16 skill_id) +int guild_skillup(struct map_session_data *sd, uint16 skill_id) { struct guild* g; int idx = skill_id - GD_SKILLBASE; @@ -2208,7 +2208,7 @@ void guild_flag_remove(struct npc_data *nd) { continue; if( cursor != i ) { - memmove(&guild->flags[cursor], &guild->flags[i], sizeof(struct npc_data*)); + memmove(&guild->flags[cursor], &guild->flags[i], sizeof(guild->flags[0])); } cursor++; } diff --git a/src/map/guild.h b/src/map/guild.h index 4b6e860d8..10749f8ad 100644 --- a/src/map/guild.h +++ b/src/map/guild.h @@ -21,11 +21,13 @@ #ifndef MAP_GUILD_H #define MAP_GUILD_H -#include "map/map.h" // EVENT_NAME_LENGTH, TBL_PC +#include "map/map.h" // EVENT_NAME_LENGTH #include "common/hercules.h" #include "common/db.h" #include "common/mmo.h" +struct map_session_data; + /** * Defines **/ @@ -161,7 +163,7 @@ struct guild_interface { void (*retrieveitembound) (int char_id,int aid,int guild_id); /* */ int (*payexp_timer) (int tid, int64 tick, int id, intptr_t data); - TBL_PC* (*sd_check) (int guild_id, int account_id, int char_id); + struct map_session_data *(*sd_check) (int guild_id, int account_id, int char_id); bool (*read_guildskill_tree_db) (char* split[], int columns, int current); bool (*read_castledb) (char* str[], int columns, int current); int (*payexp_timer_sub) (DBKey key, DBData *data, va_list ap); diff --git a/src/map/homunculus.c b/src/map/homunculus.c index d81eeb2da..b642c197f 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -580,7 +580,7 @@ void homunculus_healed (struct homun_data *hd) { void homunculus_save(struct homun_data *hd) { // copy data that must be saved in homunculus struct ( hp / sp ) - TBL_PC * sd; + struct map_session_data *sd = NULL; //Do not check for max_hp/max_sp caps as current could be higher to max due //to status changes/skills (they will be capped as needed upon stat //calculation on login) @@ -786,9 +786,10 @@ bool homunculus_create(struct map_session_data *sd, struct s_homunculus *hom) { intif->homunculus_requestdelete(hom->hom_id); return false; } - sd->hd = hd = (struct homun_data*)aCalloc(1,sizeof(struct homun_data)); + CREATE(hd, struct homun_data, 1); hd->bl.type = BL_HOM; hd->bl.id = npc->get_new_npc_id(); + sd->hd = hd; hd->master = sd; hd->homunculusDB = &homun->dbs->db[i]; diff --git a/src/map/instance.c b/src/map/instance.c index ff6f8bdab..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; } @@ -724,7 +734,7 @@ void do_reload_instance(void) { } iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if(sd && map->list[sd->bl.m].instance_id >= 0) { pc->setpos(sd,instance->list[map->list[sd->bl.m].instance_id].respawn.map,instance->list[map->list[sd->bl.m].instance_id].respawn.x,instance->list[map->list[sd->bl.m].instance_id].respawn.y,CLR_TELEPORT); } diff --git a/src/map/intif.c b/src/map/intif.c index 016b4f7d3..1968ebe67 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -995,7 +995,7 @@ void intif_parse_WisEnd(int fd) { if (battle_config.etc_log) ShowInfo("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd,2), RFIFOB(fd,26)); // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target - sd = (struct map_session_data *)map->nick2sd((char *) RFIFOP(fd,2)); + sd = map->nick2sd((char *)RFIFOP(fd,2)); if (sd != NULL) clif->wis_end(sd->fd, RFIFOB(fd,26)); @@ -1496,7 +1496,8 @@ QUESTLOG SYSTEM FUNCTIONS * * @param sd Character's data */ -void intif_request_questlog(TBL_PC *sd) { +void intif_request_questlog(struct map_session_data *sd) +{ nullpo_retv(sd); WFIFOHEAD(inter_fd,6); WFIFOW(inter_fd,0) = 0x3060; @@ -1513,7 +1514,7 @@ void intif_request_questlog(TBL_PC *sd) { */ void intif_parse_QuestLog(int fd) { int char_id = RFIFOL(fd, 4), num_received = (RFIFOW(fd, 2)-8)/sizeof(struct quest); - TBL_PC *sd = map->charid2sd(char_id); + struct map_session_data *sd = map->charid2sd(char_id); if (!sd) // User not online anymore return; @@ -1568,7 +1569,7 @@ void intif_parse_QuestLog(int fd) { */ void intif_parse_QuestSave(int fd) { int cid = RFIFOL(fd, 2); - TBL_PC *sd = map->id2sd(cid); + struct map_session_data *sd = map->id2sd(cid); if( !RFIFOB(fd, 6) ) ShowError("intif_parse_QuestSave: Failed to save quest(s) for character %d!\n", cid); @@ -1582,7 +1583,8 @@ void intif_parse_QuestSave(int fd) { * @param sd Character's data * @return 0 in case of success, nonzero otherwise */ -int intif_quest_save(TBL_PC *sd) { +int intif_quest_save(struct map_session_data *sd) +{ int len = sizeof(struct quest)*sd->num_quests + 8; if(intif->CheckForCharServer()) diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 2894463de..048efd636 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -2123,7 +2123,7 @@ void itemdb_reload(void) { // readjust itemdb pointer cache for each player iter = mapit_geteachpc(); - for( sd = (struct map_session_data*)mapit->first(iter); mapit->exists(iter); sd = (struct map_session_data*)mapit->next(iter) ) { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { memset(sd->item_delay, 0, sizeof(sd->item_delay)); // reset item delays pc->setinventorydata(sd); if( battle_config.item_check ) diff --git a/src/map/map.c b/src/map/map.c index dcbc3f6f5..ed171f4bd 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -332,8 +332,9 @@ int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) { if (sc && sc->data[SC_PROPERTYWALK] && sc->data[SC_PROPERTYWALK]->val3 >= skill->get_maxcount(sc->data[SC_PROPERTYWALK]->val1,sc->data[SC_PROPERTYWALK]->val2) ) status_change_end(bl,SC_PROPERTYWALK,INVALID_TIMER); - } else if (bl->type == BL_NPC) - npc->unsetcells((TBL_NPC*)bl); + } else if (bl->type == BL_NPC) { + npc->unsetcells(BL_UCAST(BL_NPC, bl)); + } if (moveblock) map->delblock(bl); #ifdef CELL_NOSTACK @@ -347,15 +348,17 @@ int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) { #endif if (bl->type&BL_CHAR) { + struct map_session_data *sd = BL_CAST(BL_PC, bl); skill->unit_move(bl,tick,3); - if( bl->type == BL_PC && ((TBL_PC*)bl)->shadowform_id ) {//Shadow Form Target Moving + if (sd != NULL && sd->shadowform_id != 0) { + //Shadow Form Target Moving struct block_list *d_bl; - if( (d_bl = map->id2bl(((TBL_PC*)bl)->shadowform_id)) == NULL || !check_distance_bl(bl,d_bl,10) ) { + if ((d_bl = map->id2bl(sd->shadowform_id)) == NULL || !check_distance_bl(bl,d_bl,10)) { if( d_bl ) status_change_end(d_bl,SC__SHADOWFORM,INVALID_TIMER); - ((TBL_PC*)bl)->shadowform_id = 0; + sd->shadowform_id = 0; } } @@ -391,7 +394,7 @@ int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) { } } /* Guild Aura Moving */ - if( bl->type == BL_PC && ((TBL_PC*)bl)->state.gmaster_flag ) { + if (sd != NULL && sd->state.gmaster_flag) { if (sc->data[SC_LEADERSHIP]) skill->unit_move_unit_group(skill->id2group(sc->data[SC_LEADERSHIP]->val4), bl->m, x1-x0, y1-y0); if (sc->data[SC_GLORYWOUNDS]) @@ -402,8 +405,9 @@ int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) { skill->unit_move_unit_group(skill->id2group(sc->data[SC_HAWKEYES]->val4), bl->m, x1-x0, y1-y0); } } - } else if (bl->type == BL_NPC) - npc->setcells((TBL_NPC*)bl); + } else if (bl->type == BL_NPC) { + npc->setcells(BL_UCAST(BL_NPC, bl)); + } return 0; } @@ -484,7 +488,7 @@ struct skill_unit* map_find_skill_unit_oncell(struct block_list* target,int16 x, if (bl->x != x || bl->y != y || bl->type != BL_SKILL) continue; - su = (struct skill_unit *) bl; + su = BL_UCAST(BL_SKILL, bl); if( su == out_unit || !su->alive || !su->group || su->group->skill_id != skill_id ) continue; if( !(flag&1) || battle->check_target(&su->bl,target,su->group->target_flag) > 0 ) @@ -1370,10 +1374,12 @@ int map_get_new_object_id(void) * Timered function to clear the floor (remove remaining item) * Called each flooritem_lifetime ms *------------------------------------------*/ -int map_clearflooritem_timer(int tid, int64 tick, int id, intptr_t data) { - struct flooritem_data* fitem = (struct flooritem_data*)idb_get(map->id_db, id); +int map_clearflooritem_timer(int tid, int64 tick, int id, intptr_t data) +{ + struct block_list *bl = idb_get(map->id_db, id); + struct flooritem_data *fitem = BL_CAST(BL_ITEM, bl); - if (fitem == NULL || fitem->bl.type != BL_ITEM || (fitem->cleartimer != tid)) { + if (fitem == NULL || fitem->cleartimer != tid) { ShowError("map_clearflooritem_timer : error\n"); return 1; } @@ -1391,8 +1397,11 @@ int map_clearflooritem_timer(int tid, int64 tick, int id, intptr_t data) { /* * clears a single bl item out of the bazooonga. */ -void map_clearflooritem(struct block_list *bl) { - struct flooritem_data* fitem = (struct flooritem_data*)bl; +void map_clearflooritem(struct block_list *bl) +{ + struct flooritem_data *fitem = BL_CAST(BL_ITEM, bl); + + nullpo_retv(fitem); if( fitem->cleartimer != INVALID_TIMER ) timer->delete(fitem->cleartimer,map->clearflooritem_timer); @@ -1738,15 +1747,12 @@ void map_addiddb(struct block_list *bl) { nullpo_retv(bl); - if( bl->type == BL_PC ) - { - TBL_PC* sd = (TBL_PC*)bl; + if (bl->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); idb_put(map->pc_db,sd->bl.id,sd); idb_put(map->charid_db,sd->status.char_id,sd); - } - else if( bl->type == BL_MOB ) - { - TBL_MOB* md = (TBL_MOB*)bl; + } else if (bl->type == BL_MOB) { + struct mob_data *md = BL_UCAST(BL_MOB, bl); idb_put(map->mobid_db,bl->id,bl); if( md->state.boss ) @@ -1766,14 +1772,11 @@ void map_deliddb(struct block_list *bl) { nullpo_retv(bl); - if( bl->type == BL_PC ) - { - TBL_PC* sd = (TBL_PC*)bl; + if (bl->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); idb_remove(map->pc_db,sd->bl.id); idb_remove(map->charid_db,sd->status.char_id); - } - else if( bl->type == BL_MOB ) - { + } else if (bl->type == BL_MOB) { idb_remove(map->mobid_db,bl->id); idb_remove(map->bossid_db,bl->id); } @@ -1901,42 +1904,185 @@ int map_quit(struct map_session_data *sd) { return 0; } -/*========================================== - * Lookup, id to session (player,mob,npc,homon,merc..) - *------------------------------------------*/ -struct map_session_data *map_id2sd(int id) { - if (id <= 0) return NULL; - return (struct map_session_data*)idb_get(map->pc_db,id); -} +/** + * Looks up a session data by ID. + * + * The search is performed using the pc_db. + * + * @param id The bl ID to search. + * @return The searched map_session_data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to a player unit. + */ +struct map_session_data *map_id2sd(int id) +{ + struct block_list *bl = NULL; + if (id <= 0) + return NULL; + + bl = idb_get(map->pc_db,id); -struct mob_data *map_id2md(int id) { - if (id <= 0) return NULL; - return (struct mob_data*)idb_get(map->mobid_db,id); + Assert_retr(NULL, bl->type == BL_PC); + return BL_UCAST(BL_PC, bl); } -struct npc_data *map_id2nd(int id) { +/** + * Looks up a NPC data by ID. + * + * @param id The bl ID to search. + * @return The searched npc_data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to a NPC. + */ +struct npc_data *map_id2nd(int id) +{ // just a id2bl lookup because there's no npc_db struct block_list* bl = map->id2bl(id); return BL_CAST(BL_NPC, bl); } -struct homun_data *map_id2hd(int id) { +/** + * Looks up a mob data by ID. + * + * The search is performed using the mobid_db. + * + * @param id The bl ID to search. + * @return The searched mob_data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to a mob unit. + */ +struct mob_data *map_id2md(int id) +{ + struct block_list *bl = NULL; + if (id <= 0) + return NULL; + + bl = idb_get(map->mobid_db,id); + + Assert_retr(NULL, bl->type == BL_MOB); + return BL_UCAST(BL_MOB, bl); +} + +/** + * Looks up a floor item data by ID. + * + * @param id The bl ID to search. + * @return The searched flooritem_data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to a floor item. + */ +struct flooritem_data *map_id2fi(int id) +{ + struct block_list* bl = map->id2bl(id); + + return BL_CAST(BL_ITEM, bl); +} + +/** + * Looks up a chat data by ID. + * + * @param id The bl ID to search. + * @return The searched chat_data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to a chat. + */ +struct chat_data *map_id2cd(int id) +{ + struct block_list* bl = map->id2bl(id); + + return BL_CAST(BL_CHAT, bl); +} + +/** + * Looks up a skill unit data by ID. + * + * @param id The bl ID to search. + * @return The searched skill_unit data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to a skill unit. + */ +struct skill_unit *map_id2su(int id) +{ + struct block_list* bl = map->id2bl(id); + + return BL_CAST(BL_SKILL, bl); +} + +/** + * Looks up a pet data by ID. + * + * @param id The bl ID to search. + * @return The searched pet_data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to a pet. + */ +struct pet_data *map_id2pd(int id) +{ + struct block_list* bl = map->id2bl(id); + + return BL_CAST(BL_PET, bl); +} + +/** + * Looks up a homunculus data by ID. + * + * @param id The bl ID to search. + * @return The searched homun_data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to a homunculus. + */ +struct homun_data *map_id2hd(int id) +{ struct block_list* bl = map->id2bl(id); return BL_CAST(BL_HOM, bl); } -struct mercenary_data *map_id2mc(int id) { +/** + * Looks up a mercenary data by ID. + * + * @param id The bl ID to search. + * @return The searched mercenary_data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to a mercenary. + */ +struct mercenary_data *map_id2mc(int id) +{ struct block_list* bl = map->id2bl(id); return BL_CAST(BL_MER, bl); } -struct chat_data *map_id2cd(int id) { +/** + * Looks up an elemental data by ID. + * + * @param id The bl ID to search. + * @return The searched elemental_data, if it exists. + * @retval NULL if the ID is invalid or doesn't belong to an elemental. + */ +struct elemental_data *map_id2ed(int id) +{ struct block_list* bl = map->id2bl(id); - return BL_CAST(BL_CHAT, bl); + return BL_CAST(BL_ELEM, bl); +} + +/** + * Looks up a block_list by ID. + * + * The search is performed using the id_db. + * + * @param id The bl ID to search. + * @return The searched block_list, if it exists. + * @retval NULL if the ID is invalid. + */ +struct block_list *map_id2bl(int id) +{ + return idb_get(map->id_db, id); +} + +/** + * Verifies whether a block list ID is valid. + * + * @param id The bl ID to search. + * @retval true if the ID exists and is valid. + * @retval false otherwise. + */ +bool map_blid_exists(int id) +{ + return (idb_exists(map->id_db,id)); } /// Returns the nick of the target charid or NULL if unknown (requests the nick to the char server). @@ -1959,7 +2105,9 @@ const char *map_charid2nick(int charid) { /// Returns the struct map_session_data of the charid or NULL if the char is not online. struct map_session_data* map_charid2sd(int charid) { - return (struct map_session_data*)idb_get(map->charid_db, charid); + struct block_list *bl = idb_get(map->charid_db, charid); + Assert_retr(NULL, bl->type == BL_PC); + return BL_UCAST(BL_PC, bl); } /*========================================== @@ -1982,8 +2130,7 @@ struct map_session_data * map_nick2sd(const char *nick) iter = mapit_getallusers(); found_sd = NULL; - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) - { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( battle_config.partial_name_scan ) {// partial name search if( strnicmp(sd->status.name, nick, nicklen) == 0 ) @@ -2014,20 +2161,6 @@ struct map_session_data * map_nick2sd(const char *nick) } /*========================================== - * Looksup id_db DBMap and returns BL pointer of 'id' or NULL if not found - *------------------------------------------*/ -struct block_list * map_id2bl(int id) { - return (struct block_list*)idb_get(map->id_db,id); -} - -/** - * Same as map->id2bl except it only checks for its existence - **/ -bool map_blid_exists( int id ) { - return (idb_exists(map->id_db,id)); -} - -/*========================================== * Convext Mirror *------------------------------------------*/ struct mob_data * map_getmob_boss(int16 m) @@ -2037,10 +2170,8 @@ struct mob_data * map_getmob_boss(int16 m) bool found = false; iter = db_iterator(map->bossid_db); - for( md = (struct mob_data*)dbi_first(iter); dbi_exists(iter); md = (struct mob_data*)dbi_next(iter) ) - { - if( md->bl.m == m ) - { + for (md = dbi_first(iter); dbi_exists(iter); md = dbi_next(iter)) { + if (md->bl.m == m) { found = true; break; } @@ -2050,10 +2181,14 @@ struct mob_data * map_getmob_boss(int16 m) return (found)? md : NULL; } -struct mob_data * map_id2boss(int id) +struct mob_data *map_id2boss(int id) { - if (id <= 0) return NULL; - return (struct mob_data*)idb_get(map->bossid_db,id); + struct block_list *bl = NULL; + if (id <= 0) + return NULL; + bl = idb_get(map->bossid_db,id); + Assert_retr(NULL, bl->type == BL_MOB); + return BL_UCAST(BL_MOB, bl); } /** @@ -2128,7 +2263,7 @@ void map_vforeachmob(int (*func)(struct mob_data* md, va_list args), va_list arg struct mob_data* md; iter = db_iterator(map->mobid_db); - for( md = (struct mob_data*)dbi_first(iter); dbi_exists(iter); md = (struct mob_data*)dbi_next(iter) ) { + for (md = dbi_first(iter); dbi_exists(iter); md = dbi_next(iter)) { va_list argscopy; int ret; @@ -2159,9 +2294,9 @@ void map_vforeachnpc(int (*func)(struct npc_data* nd, va_list args), va_list arg struct block_list* bl; iter = db_iterator(map->id_db); - for( bl = (struct block_list*)dbi_first(iter); dbi_exists(iter); bl = (struct block_list*)dbi_next(iter) ) { - if( bl->type == BL_NPC ) { - struct npc_data* nd = (struct npc_data*)bl; + for (bl = dbi_first(iter); dbi_exists(iter); bl = dbi_next(iter)) { + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); va_list argscopy; int ret; @@ -2193,7 +2328,7 @@ void map_vforeachregen(int (*func)(struct block_list* bl, va_list args), va_list struct block_list* bl; iter = db_iterator(map->regen_db); - for( bl = (struct block_list*)dbi_first(iter); dbi_exists(iter); bl = (struct block_list*)dbi_next(iter) ) { + for (bl = dbi_first(iter); dbi_exists(iter); bl = dbi_next(iter)) { va_list argscopy; int ret; @@ -2224,7 +2359,7 @@ void map_vforeachiddb(int (*func)(struct block_list* bl, va_list args), va_list struct block_list* bl; iter = db_iterator(map->id_db); - for( bl = (struct block_list*)dbi_first(iter); dbi_exists(iter); bl = (struct block_list*)dbi_next(iter) ) { + for (bl = dbi_first(iter); dbi_exists(iter); bl = dbi_next(iter)) { va_list argscopy; int ret; @@ -2305,7 +2440,7 @@ struct block_list* mapit_first(struct s_mapiterator* iter) { nullpo_retr(NULL,iter); - for( bl = (struct block_list*)dbi_first(iter->dbi); bl != NULL; bl = (struct block_list*)dbi_next(iter->dbi) ) { + for (bl = dbi_first(iter->dbi); bl != NULL; bl = dbi_next(iter->dbi) ) { if( MAPIT_MATCHES(iter,bl) ) break;// found match } @@ -2322,7 +2457,7 @@ struct block_list* mapit_last(struct s_mapiterator* iter) { nullpo_retr(NULL,iter); - for( bl = (struct block_list*)dbi_last(iter->dbi); bl != NULL; bl = (struct block_list*)dbi_prev(iter->dbi) ) { + for (bl = dbi_last(iter->dbi); bl != NULL; bl = dbi_prev(iter->dbi)) { if( MAPIT_MATCHES(iter,bl) ) break;// found match } @@ -2340,7 +2475,7 @@ struct block_list* mapit_next(struct s_mapiterator* iter) { nullpo_retr(NULL,iter); for( ; ; ) { - bl = (struct block_list*)dbi_next(iter->dbi); + bl = dbi_next(iter->dbi); if( bl == NULL ) break;// end if( MAPIT_MATCHES(iter,bl) ) @@ -2361,7 +2496,7 @@ struct block_list* mapit_prev(struct s_mapiterator* iter) { nullpo_retr(NULL,iter); for( ; ; ) { - bl = (struct block_list*)dbi_prev(iter->dbi); + bl = dbi_prev(iter->dbi); if( bl == NULL ) break;// end if( MAPIT_MATCHES(iter,bl) ) @@ -2437,8 +2572,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 @@ -5338,10 +5475,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); @@ -5353,7 +5490,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; } @@ -5384,7 +5521,7 @@ int do_final(void) { //Ladies and babies first. iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) map->quit(sd); mapit->free(iter); @@ -5528,7 +5665,7 @@ void do_shutdown(void) { struct map_session_data* sd; struct s_mapiterator* iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) clif->GM_kick(NULL, sd); mapit->free(iter); sockt->flush_fifos(); @@ -6163,11 +6300,15 @@ void map_defaults(void) { map->foreachininstance = map_foreachininstance; map->id2sd = map_id2sd; - map->id2md = map_id2md; map->id2nd = map_id2nd; + map->id2md = map_id2md; + map->id2fi = map_id2fi; + map->id2cd = map_id2cd; + map->id2su = map_id2su; + map->id2pd = map_id2pd; map->id2hd = map_id2hd; map->id2mc = map_id2mc; - map->id2cd = map_id2cd; + map->id2ed = map_id2ed; map->id2bl = map_id2bl; map->blid_exists = map_blid_exists; map->mapindex2mapid = map_mapindex2mapid; diff --git a/src/map/map.h b/src/map/map.h index 7047feab6..4c74d352c 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -828,8 +828,89 @@ typedef struct homun_data TBL_HOM; typedef struct mercenary_data TBL_MER; typedef struct elemental_data TBL_ELEM; +/** + * Casts a block list to a specific type. + * + * @remark + * The `bl` argument may be evaluated more than once. + * + * @param type_ The block list type (using symbols from enum bl_type). + * @param bl The source block list to cast. + * @return The block list, cast to the correct type. + * @retval NULL if bl is the wrong type or NULL. + */ #define BL_CAST(type_, bl) \ - ( ((bl) == (struct block_list*)NULL || (bl)->type != (type_)) ? (T ## type_ *)NULL : (T ## type_ *)(bl) ) + ( ((bl) == (struct block_list *)NULL || (bl)->type != (type_)) ? (T ## type_ *)NULL : (T ## type_ *)(bl) ) + +/** + * Casts a const block list to a specific type. + * + * @remark + * The `bl` argument may be evaluated more than once. + * + * @param type_ The block list type (using symbols from enum bl_type). + * @param bl The source block list to cast. + * @return The block list, cast to the correct type. + * @retval NULL if bl is the wrong type or NULL. + */ +#define BL_CCAST(type_, bl) \ + ( ((bl) == (const struct block_list *)NULL || (bl)->type != (type_)) ? (const T ## type_ *)NULL : (const T ## type_ *)(bl) ) + +/** + * Helper function for `BL_UCAST`. + * + * @warning + * This function shouldn't be called on it own. + * + * The purpose of this function is to produce a compile-timer error if a non-bl + * object is passed to BL_UCAST. It's declared as static inline to let the + * compiler optimize out the function call overhead. + */ +static inline struct block_list *BL_UCAST_(struct block_list *bl) +{ + return bl; +} + +/** + * Casts a block list to a specific type, without performing any type checks. + * + * @remark + * The `bl` argument is guaranteed to be evaluated once and only once. + * + * @param type_ The block list type (using symbols from enum bl_type). + * @param bl The source block list to cast. + * @return The block list, cast to the correct type. + */ +#define BL_UCAST(type_, bl) \ + ((T ## type_ *)BL_UCAST_(bl)) + +/** + * Helper function for `BL_UCCAST`. + * + * @warning + * This function shouldn't be called on it own. + * + * The purpose of this function is to produce a compile-timer error if a non-bl + * object is passed to BL_UCAST. It's declared as static inline to let the + * compiler optimize out the function call overhead. + */ +static inline const struct block_list *BL_UCCAST_(const struct block_list *bl) +{ + return bl; +} + +/** + * Casts a const block list to a specific type, without performing any type checks. + * + * @remark + * The `bl` argument is guaranteed to be evaluated once and only once. + * + * @param type_ The block list type (using symbols from enum bl_type). + * @param bl The source block list to cast. + * @return The block list, cast to the correct type. + */ +#define BL_UCCAST(type_, bl) \ + ((const T ## type_ *)BL_UCCAST_(bl)) struct charid_request { struct charid_request* next; @@ -1029,13 +1110,17 @@ END_ZEROED_BLOCK; int (*vforeachininstance)(int (*func)(struct block_list*,va_list), int16 instance_id, int type, va_list ap); int (*foreachininstance)(int (*func)(struct block_list*,va_list), int16 instance_id, int type,...); - struct map_session_data * (*id2sd) (int id); - struct mob_data * (*id2md) (int id); - struct npc_data * (*id2nd) (int id); - struct homun_data* (*id2hd) (int id); - struct mercenary_data* (*id2mc) (int id); - struct chat_data* (*id2cd) (int id); - struct block_list * (*id2bl) (int id); + struct map_session_data *(*id2sd) (int id); + struct npc_data *(*id2nd) (int id); + struct mob_data *(*id2md) (int id); + struct flooritem_data *(*id2fi) (int id); + struct chat_data *(*id2cd) (int id); + struct skill_unit *(*id2su) (int id); + struct pet_data *(*id2pd) (int id); + struct homun_data *(*id2hd) (int id); + struct mercenary_data *(*id2mc) (int id); + struct elemental_data *(*id2ed) (int id); + struct block_list *(*id2bl) (int id); bool (*blid_exists) (int id); int16 (*mapindex2mapid) (unsigned short map_index); int16 (*mapname2mapid) (const char* name); diff --git a/src/map/mercenary.c b/src/map/mercenary.c index fb801a8da..e6c911ef6 100644 --- a/src/map/mercenary.c +++ b/src/map/mercenary.c @@ -317,10 +317,11 @@ int merc_data_received(struct s_mercenary *merc, bool flag) { db = &mercenary->db[i]; if( !sd->md ) { - sd->md = md = (struct mercenary_data*)aCalloc(1,sizeof(struct mercenary_data)); + CREATE(md, struct mercenary_data, 1); md->bl.type = BL_MER; md->bl.id = npc->get_new_npc_id(); md->devotion_flag = 0; + sd->md = md; md->master = sd; md->db = db; diff --git a/src/map/mob.c b/src/map/mob.c index 16b5417b9..37da81a15 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -274,7 +274,8 @@ int mob_parse_dataset(struct spawn_data *data) * Generates the basic mob data using the spawn_data provided. *------------------------------------------*/ struct mob_data* mob_spawn_dataset(struct spawn_data *data) { - struct mob_data *md = (struct mob_data*)aCalloc(1, sizeof(struct mob_data)); + struct mob_data *md = NULL; + CREATE(md, struct mob_data, 1); md->bl.id= npc->get_new_npc_id(); md->bl.type = BL_MOB; md->bl.m = data->m; @@ -591,12 +592,9 @@ int mob_spawn_guardian_sub(int tid, int64 tick, int id, intptr_t data) { if( bl == NULL ) //It is possible mob was already removed from map when the castle has no owner. [Skotlex] return 0; - if( bl->type != BL_MOB ) { - ShowError("mob_spawn_guardian_sub: Block error!\n"); - return 0; - } + Assert_ret(bl->type == BL_MOB); + md = BL_UCAST(BL_MOB, bl); - md = (struct mob_data*)bl; nullpo_ret(md->guardian_data); g = guild->search((int)data); @@ -684,11 +682,9 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam if( has_index && gc->guardian[guardian].id ) { //Check if guardian already exists, refuse to spawn if so. - struct mob_data *md2 = (TBL_MOB*)map->id2bl(gc->guardian[guardian].id); - if (md2 && md2->bl.type == BL_MOB - && md2->guardian_data - && md2->guardian_data->number == guardian - ) { + struct block_list *bl2 = map->id2bl(gc->guardian[guardian].id); // TODO: Why does this not use map->id2md? + struct mob_data *md2 = BL_CAST(BL_MOB, bl2); + if (md2 != NULL && md2->guardian_data != NULL && md2->guardian_data->number == guardian) { ShowError("mob_spawn_guardian: Attempted to spawn guardian in position %d which already has a guardian (castle map %s)\n", guardian, map->list[m].name); return 0; } @@ -794,17 +790,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) @@ -825,7 +820,7 @@ int mob_linksearch(struct block_list *bl,va_list ap) { * mob spawn with delay (timer function) *------------------------------------------*/ int mob_delayspawn(int tid, int64 tick, int id, intptr_t data) { - struct block_list* bl = map->id2bl(id); + struct block_list* bl = map->id2bl(id); // TODO: Why does this not use map->bl2md? struct mob_data* md = BL_CAST(BL_MOB, bl); if( md ) @@ -889,7 +884,7 @@ int mob_count_sub(struct block_list *bl, va_list ap) { int mobid[10] = { 0 }, i; ARR_FIND(0, 10, i, (mobid[i] = va_arg(ap, int)) == 0); //fetch till 0 if (mobid[0]) { //if there one let's check it otherwise go backward - TBL_MOB *md = BL_CAST(BL_MOB, bl); + struct mob_data *md = BL_CAST(BL_MOB, bl); nullpo_ret(md); ARR_FIND(0, 10, i, md->class_ == mobid[i]); return (i < 10) ? 1 : 0; @@ -1073,8 +1068,7 @@ int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap) switch (bl->type) { case BL_PC: - if (((TBL_PC*)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 +1168,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 = (TBL_NPC*) 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 @@ -1440,14 +1432,13 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { if (md->target_id) { //Check validity of current target. [Skotlex] + struct map_session_data *tsd = NULL; tbl = map->id2bl(md->target_id); - if (!tbl || tbl->m != md->bl.m + tsd = BL_CAST(BL_PC, tbl); + if (tbl == NULL || tbl->m != md->bl.m || (md->ud.attacktimer == INVALID_TIMER && !status->check_skilluse(&md->bl, tbl, 0, 0)) || (md->ud.walktimer != INVALID_TIMER && !(battle_config.mob_ai&0x1) && !check_distance_bl(&md->bl, tbl, md->min_chase)) - || ( tbl->type == BL_PC - && ((((TBL_PC*)tbl)->state.gangsterparadise && !(mode&MD_BOSS)) - || ((TBL_PC*)tbl)->invincible_timer != INVALID_TIMER) - ) + || (tsd != NULL && ((tsd->state.gangsterparadise && !(mode&MD_BOSS)) || tsd->invincible_timer != INVALID_TIMER)) ) { //No valid target if (mob->warpchase(md, tbl)) @@ -1580,7 +1571,7 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { //Target exists, attack or loot as applicable. if (tbl->type == BL_ITEM) { //Loot time. - struct flooritem_data *fitem; + struct flooritem_data *fitem = BL_UCAST(BL_ITEM, tbl); if (md->ud.target == tbl->id && md->ud.walktimer != INVALID_TIMER) return true; //Already locked. if (md->lootitem == NULL) { @@ -1606,7 +1597,6 @@ bool mob_ai_sub_hard(struct mob_data *md, int64 tick) { if (md->ud.attacktimer != INVALID_TIMER) return true; //Busy attacking? - fitem = (struct flooritem_data *)tbl; //Logs items, taken by (L)ooter Mobs [Lupus] logs->pick_mob(md, LOG_TYPE_LOOT, fitem->item_data.amount, &fitem->item_data, NULL); @@ -1687,9 +1677,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) @@ -1847,7 +1843,7 @@ int mob_delay_item_drop(int tid, int64 tick, int id, intptr_t data) { *------------------------------------------*/ void mob_item_drop(struct mob_data *md, struct item_drop_list *dlist, struct item_drop *ditem, int loot, int drop_rate, unsigned short flag) { - TBL_PC* sd; + struct map_session_data *sd = NULL; //Logs items, dropped by mobs [Lupus] logs->pick_mob(md, loot?LOG_TYPE_LOOT:LOG_TYPE_PICKDROP_MONSTER, -ditem->item_data.amount, &ditem->item_data, NULL); @@ -1878,7 +1874,7 @@ void mob_item_drop(struct mob_data *md, struct item_drop_list *dlist, struct ite } int mob_timer_delete(int tid, int64 tick, int id, intptr_t data) { - struct block_list* bl = map->id2bl(id); + struct block_list* bl = map->id2bl(id); // TODO: Why does this not use map->id2md? struct mob_data* md = BL_CAST(BL_MOB, bl); if( md ) @@ -1900,13 +1896,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; @@ -1945,7 +1941,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) { case BL_PC: { - struct map_session_data *sd = (TBL_PC*)src; + const struct map_session_data *sd = BL_UCCAST(BL_PC, src); char_id = sd->status.char_id; if( damage ) md->attacked_id = src->id; @@ -1953,7 +1949,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_HOM: { - struct homun_data *hd = (TBL_HOM*)src; + const struct homun_data *hd = BL_UCCAST(BL_HOM, src); flag = MDLF_HOMUN; if( hd->master ) char_id = hd->master->status.char_id; @@ -1963,7 +1959,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_MER: { - struct mercenary_data *mer = (TBL_MER*)src; + const struct mercenary_data *mer = BL_UCCAST(BL_MER, src); if( mer->master ) char_id = mer->master->status.char_id; if( damage ) @@ -1972,7 +1968,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_PET: { - struct pet_data *pd = (TBL_PET*)src; + const struct pet_data *pd = BL_UCCAST(BL_PET, src); flag = MDLF_PET; if( pd->msd ) { @@ -1984,7 +1980,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_MOB: { - struct mob_data* md2 = (TBL_MOB*)src; + const struct mob_data *md2 = BL_UCCAST(BL_MOB, src); if (md2->special_state.ai != AI_NONE && md2->master_id) { struct map_session_data* msd = map->id2sd(md2->master_id); if( msd ) @@ -2001,7 +1997,7 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage) } case BL_ELEM: { - struct elemental_data *ele = (TBL_ELEM*)src; + const struct elemental_data *ele = BL_UCCAST(BL_ELEM, src); if( ele->master ) char_id = ele->master->status.char_id; if( damage ) @@ -2098,14 +2094,15 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) { *------------------------------------------*/ int mob_dead(struct mob_data *md, struct block_list *src, int type) { struct status_data *mstatus; - struct map_session_data *sd = NULL, *tmpsd[DAMAGELOG_SIZE]; - struct map_session_data *mvp_sd = NULL, *second_sd = NULL, *third_sd = NULL; + struct map_session_data *sd = BL_CAST(BL_PC, src); + struct map_session_data *tmpsd[DAMAGELOG_SIZE] = { NULL }; + struct map_session_data *mvp_sd = sd, *second_sd = NULL, *third_sd = NULL; struct { struct party_data *p; int id,zeny; unsigned int base_exp,job_exp; - } pt[DAMAGELOG_SIZE]; + } pt[DAMAGELOG_SIZE] = { { 0 } }; int i, temp, count, m = md->bl.m; int dmgbltypes = 0; // bitfield of all bl types, that caused damage to the mob and are eligible for exp distribution unsigned int mvp_damage; @@ -2114,12 +2111,6 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) { mstatus = &md->status; - if( src && src->type == BL_PC ) - { - sd = (struct map_session_data *)src; - mvp_sd = sd; - } - if( md->guardian_data && md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS ) guild->castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0); @@ -2131,13 +2122,10 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) { map->freeblock_lock(); - memset(pt,0,sizeof(pt)); - - if(src && src->type == BL_MOB) - mob->unlocktarget((struct mob_data *)src,tick); + if (src != NULL && src->type == BL_MOB) + mob->unlocktarget(BL_UCAST(BL_MOB, src), tick); // filter out entries not eligible for exp distribution - memset(tmpsd,0,sizeof(tmpsd)); for(i = 0, count = 0, mvp_damage = 0; i < DAMAGELOG_SIZE && md->dmglog[i].id; i++) { struct map_session_data* tsd = map->charid2sd(md->dmglog[i].id); @@ -2582,10 +2570,10 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) { md->status.hp = 0; //So that npc_event invoked functions KNOW that mob is dead if( src ) { switch( src->type ) { - case BL_PET: sd = ((TBL_PET*)src)->msd; break; - case BL_HOM: sd = ((TBL_HOM*)src)->master; break; - case BL_MER: sd = ((TBL_MER*)src)->master; break; - case BL_ELEM: sd = ((TBL_ELEM*)src)->master; break; + case BL_PET: sd = BL_UCAST(BL_PET, src)->msd; break; + case BL_HOM: sd = BL_UCAST(BL_HOM, src)->master; break; + case BL_MER: sd = BL_UCAST(BL_MER, src)->master; break; + case BL_ELEM: sd = BL_UCAST(BL_ELEM, src)->master; break; } } @@ -2843,13 +2831,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 +2866,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 +3059,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 a7d4cdab0..411e52c29 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,9 +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) - { - TBL_PC *sd = (TBL_PC*)bl; + + if (bl->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); if (nd->option&OPTION_INVISIBLE) return 1; @@ -272,9 +277,9 @@ int npc_enable(const char* name, int flag) /*========================================== * NPC lookup (get npc_data through npcname) *------------------------------------------*/ -struct npc_data* npc_name2id(const char* name) +struct npc_data *npc_name2id(const char *name) { - return (struct npc_data *) strdb_get(npc->name_db, name); + return strdb_get(npc->name_db, name); } /** * For the Secure NPC Timeout option (check config/Secure.h) [RR] @@ -566,10 +571,11 @@ struct timer_event_data { /*========================================== * triger 'OnTimerXXXX' events *------------------------------------------*/ -int npc_timerevent(int tid, int64 tick, int id, intptr_t data) { +int npc_timerevent(int tid, int64 tick, int id, intptr_t data) +{ int old_rid, old_timer; int64 old_tick; - struct npc_data* nd=(struct npc_data *)map->id2bl(id); + struct npc_data *nd = map->id2nd(id); struct npc_timerevent_list *te; struct timer_event_data *ted = (struct timer_event_data*)data; struct map_session_data *sd=NULL; @@ -736,14 +742,13 @@ void npc_timerevent_quit(struct map_session_data* sd) } // Delete timer - nd = (struct npc_data *)map->id2bl(td->id); + nd = map->id2nd(td->id); ted = (struct timer_event_data*)td->data; timer->delete(sd->npc_timer_id, npc->timerevent); sd->npc_timer_id = INVALID_TIMER; // Execute OnTimerQuit - if( nd && nd->bl.type == BL_NPC ) - { + if (nd != NULL) { char buf[EVENT_NAME_LENGTH]; struct event_data *ev; @@ -1027,15 +1032,14 @@ int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y) *------------------------------------------*/ int npc_untouch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y) { - struct npc_data *nd; + struct npc_data *nd = NULL; nullpo_retr(1, sd); if (!sd->areanpc_id) return 0; - nd = (struct npc_data *) map->id2bl(sd->areanpc_id); - if (!nd) - { + nd = map->id2nd(sd->areanpc_id); + if (nd == NULL) { sd->areanpc_id = 0; return 1; } @@ -1166,13 +1170,13 @@ int npc_check_areanpc(int flag, int16 m, int16 x, int16 y, int16 range) { *------------------------------------------*/ struct npc_data* npc_checknear(struct map_session_data* sd, struct block_list* bl) { - struct npc_data *nd; + struct npc_data *nd = BL_CAST(BL_NPC, bl); int distance = AREA_SIZE + 1; nullpo_retr(NULL, sd); - if (bl == NULL) return NULL; - if (bl->type != BL_NPC) return NULL; - nd = (TBL_NPC*)bl; + + if (nd == NULL) + return NULL; if (sd->npc_id == bl->id) return nd; @@ -1297,8 +1301,8 @@ int npc_scriptcont(struct map_session_data* sd, int id, bool closing) { nullpo_retr(1, sd); if( id != sd->npc_id ){ - TBL_NPC* nd_sd=(TBL_NPC*)map->id2bl(sd->npc_id); - TBL_NPC* nd = BL_CAST(BL_NPC, target); + struct npc_data *nd_sd = map->id2nd(sd->npc_id); + struct npc_data *nd = BL_CAST(BL_NPC, target); ShowDebug("npc_scriptcont: %s (sd->npc_id=%d) is not %s (id=%d).\n", nd_sd?(char*)nd_sd->name:"'Unknown NPC'", (int)sd->npc_id, nd?(char*)nd->name:"'Unknown NPC'", (int)id); @@ -1397,7 +1401,8 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, uns if( points < 0 ) return ERROR_TYPE_MONEY; - if( !(nd = (struct npc_data *)map->id2bl(sd->npc_shopid)) ) + nd = map->id2nd(sd->npc_shopid); + if (nd == NULL) return ERROR_TYPE_NPC; if( nd->subtype != CASHSHOP ) { @@ -1631,11 +1636,10 @@ void npc_trader_update(int master) { CREATE(master_nd->u.scr.shop,struct npc_shop_data,1); iter = db_iterator(map->id_db); - for( bl = (struct block_list*)dbi_first(iter); dbi_exists(iter); bl = (struct block_list*)dbi_next(iter) ) { - if( bl->type == BL_NPC ) { - struct npc_data* nd = (struct npc_data*)bl; - - if( nd->src_id == master ) { + for (bl = dbi_first(iter); dbi_exists(iter); bl = dbi_next(iter)) { + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->src_id == master) { nd->u.scr.shop = master_nd->u.scr.shop; } } @@ -1720,7 +1724,8 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po if( sd->state.trading ) return ERROR_TYPE_EXCHANGE; - if( !(nd = (struct npc_data *)map->id2bl(sd->npc_shopid)) ) + nd = map->id2nd(sd->npc_shopid); + if (nd == NULL) return ERROR_TYPE_NPC; if( (item = itemdb->exists(nameid)) == NULL ) @@ -2283,11 +2288,12 @@ int npc_unload(struct npc_data* nd, bool single) if( single && nd->bl.m != -1 ) map->remove_questinfo(nd->bl.m,nd); - if( nd->src_id == 0 && ( nd->subtype == SHOP || nd->subtype == CASHSHOP ) ) //src check for duplicate shops [Orcao] + if (nd->src_id == 0 && ( nd->subtype == SHOP || nd->subtype == CASHSHOP)) { + //src check for duplicate shops [Orcao] aFree(nd->u.shop.shop_item); - else if( nd->subtype == SCRIPT ) { - struct s_mapiterator* iter; - struct block_list* bl; + } else if (nd->subtype == SCRIPT) { + struct s_mapiterator *iter; + struct map_session_data *sd = NULL; if( single ) { npc->ev_db->foreach(npc->ev_db,npc->unload_ev,nd->exname); //Clean up all events related @@ -2295,9 +2301,8 @@ int npc_unload(struct npc_data* nd, bool single) } iter = mapit_geteachpc(); - for( bl = (struct block_list*)mapit->first(iter); mapit->exists(iter); bl = (struct block_list*)mapit->next(iter) ) { - struct map_session_data *sd = ((TBL_PC*)bl); - if( sd && sd->npc_timer_id != INVALID_TIMER ) { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { + if (sd->npc_timer_id != INVALID_TIMER ) { const struct TimerData *td = timer->get(sd->npc_timer_id); if( td && td->id != nd->bl.id ) @@ -3430,10 +3435,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; } @@ -4663,11 +4675,11 @@ int npc_reload(void) { //Remove all npcs/mobs. [Skotlex] iter = mapit_geteachiddb(); - for( bl = (struct block_list*)mapit->first(iter); mapit->exists(iter); bl = (struct block_list*)mapit->next(iter) ) { + for (bl = mapit->first(iter); mapit->exists(iter); bl = mapit->next(iter)) { switch(bl->type) { case BL_NPC: if( bl->id != npc->fake_nd->bl.id )// don't remove fake_nd - npc->unload((struct npc_data *)bl, false); + npc->unload(BL_UCAST(BL_NPC, bl), false); break; case BL_MOB: unit->free(bl,CLR_OUTSIGHT); @@ -4878,7 +4890,7 @@ int do_init_npc(bool minimal) { } // Init dummy NPC - npc->fake_nd = (struct npc_data *)aCalloc(1,sizeof(struct npc_data)); + CREATE(npc->fake_nd, struct npc_data, 1); npc->fake_nd->bl.m = -1; npc->fake_nd->bl.id = npc->get_new_npc_id(); npc->fake_nd->class_ = FAKE_NPC; diff --git a/src/map/npc_chat.c b/src/map/npc_chat.c index 8950df1ee..fef3ba99b 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; @@ -395,38 +400,46 @@ int npc_chat_sub(struct block_list* bl, va_list ap) } // Various script built-ins used to support these functions -BUILDIN(defpattern) { +BUILDIN(defpattern) +{ int setid = script_getnum(st,2); const char* pattern = script_getstr(st,3); const char* label = script_getstr(st,4); - struct npc_data* nd = (struct npc_data *)map->id2bl(st->oid); + struct npc_data *nd = map->id2nd(st->oid); + nullpo_retr(false, nd); npc_chat->def_pattern(nd, setid, pattern, label); return true; } -BUILDIN(activatepset) { +BUILDIN(activatepset) +{ int setid = script_getnum(st,2); - struct npc_data* nd = (struct npc_data *)map->id2bl(st->oid); + struct npc_data *nd = map->id2nd(st->oid); + nullpo_retr(false, nd); npc_chat->activate_pcreset(nd, setid); return true; } -BUILDIN(deactivatepset) { +BUILDIN(deactivatepset) +{ int setid = script_getnum(st,2); - struct npc_data* nd = (struct npc_data *)map->id2bl(st->oid); + struct npc_data *nd = map->id2nd(st->oid); + nullpo_retr(false, nd); npc_chat->deactivate_pcreset(nd, setid); return true; } -BUILDIN(deletepset) { +BUILDIN(deletepset) +{ int setid = script_getnum(st,2); - struct npc_data* nd = (struct npc_data *)map->id2bl(st->oid); + struct npc_data *nd = map->id2nd(st->oid); + nullpo_retr(false, nd); npc_chat->delete_pcreset(nd, setid); diff --git a/src/map/party.c b/src/map/party.c index 1b5989f41..a3e59c281 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -96,8 +96,9 @@ struct map_session_data* party_getavailablesd(struct party_data *p) /*========================================== * Retrieves and validates the sd pointer for this party member [Skotlex] *------------------------------------------*/ -TBL_PC* party_sd_check(int party_id, int account_id, int char_id) { - TBL_PC* sd = map->id2sd(account_id); +struct map_session_data *party_sd_check(int party_id, int account_id, int char_id) +{ + struct map_session_data *sd = map->id2sd(account_id); if (!(sd && sd->status.char_id == char_id)) return NULL; @@ -954,8 +955,8 @@ int party_exp_share(struct party_data* p, struct block_list* src, unsigned int b for (i = 0; i < c; i++) { #ifdef RENEWAL_EXP - if( !(src && src->type == BL_MOB && ((TBL_MOB*)src)->db->mexp) ){ - struct mob_data *md = (TBL_MOB*)src; + struct mob_data *md = BL_CAST(BL_MOB, src); + if (md != NULL && md->db->mexp == 0) { int rate = pc->level_penalty_mod(md->level - (sd[i])->status.base_level, md->status.race, md->status.mode, 1); base_exp = (unsigned int)cap_value(base_exp_bonus * rate / 100, 1, UINT_MAX); @@ -973,16 +974,16 @@ int party_exp_share(struct party_data* p, struct block_list* src, unsigned int b //Does party loot. first_charid holds the charid of the player who has time priority to take the item. int party_share_loot(struct party_data* p, struct map_session_data* sd, struct item* item_data, int first_charid) { - TBL_PC* target = NULL; + struct map_session_data *target = NULL; int i; if (p && p->party.item&2 && (first_charid || !(battle_config.party_share_type&1))) { //item distribution to party members. if (battle_config.party_share_type&2) { //Round Robin - TBL_PC* psd; i = p->itemc; do { + struct map_session_data *psd; i++; if (i >= MAX_PARTY) i = 0; // reset counter to 1st person in party so it'll stop when it reaches "itemc" @@ -1000,7 +1001,7 @@ int party_share_loot(struct party_data* p, struct map_session_data* sd, struct i } while (i != p->itemc); } else { //Random pick - TBL_PC* psd[MAX_PARTY]; + struct map_session_data *psd[MAX_PARTY]; int count = 0; //Collect pick candidates for (i = 0; i < MAX_PARTY; i++) { @@ -1048,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 = (TBL_PC *)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; @@ -1109,8 +1114,13 @@ 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 = (TBL_PC *)bl; +int party_sub_count_chorus(struct block_list *bl, va_list ap) +{ + 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/party.h b/src/map/party.h index eb3442b92..828916b88 100644 --- a/src/map/party.h +++ b/src/map/party.h @@ -21,7 +21,6 @@ #ifndef MAP_PARTY_H #define MAP_PARTY_H -#include "map/map.h" // TBL_PC #include "common/hercules.h" #include "common/db.h" #include "common/mmo.h" // struct party @@ -31,7 +30,9 @@ #define PARTY_BOOKING_JOBS 6 #define PARTY_BOOKING_RESULTS 10 +struct block_list; struct hplugin_data_store; +struct map_session_data; struct party_member_data { struct map_session_data *sd; @@ -141,7 +142,7 @@ struct party_interface { int (*foreachsamemap) (int (*func)(struct block_list *,va_list),struct map_session_data *sd,int range,...); int (*send_xy_timer) (int tid, int64 tick, int id, intptr_t data); void (*fill_member) (struct party_member* member, struct map_session_data* sd, unsigned int leader); - TBL_PC* (*sd_check) (int party_id, int account_id, int char_id); + struct map_session_data *(*sd_check) (int party_id, int account_id, int char_id); void (*check_state) (struct party_data *p); struct party_booking_ad_info* (*create_booking_data) (void); int (*db_final) (DBKey key, DBData *data, va_list ap); diff --git a/src/map/pc.c b/src/map/pc.c index b6b6787e9..2dfd9519b 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -123,10 +123,11 @@ bool pc_should_log_commands(struct map_session_data *sd) return pcg->should_log_commands(sd->group); } -int pc_invincible_timer(int tid, int64 tick, int id, intptr_t data) { - struct map_session_data *sd; +int pc_invincible_timer(int tid, int64 tick, int id, intptr_t data) +{ + struct map_session_data *sd = map->id2sd(id); - if( (sd=(struct map_session_data *)map->id2sd(id)) == NULL || sd->bl.type!=BL_PC ) + if (sd == NULL) return 1; if(sd->invincible_timer != tid){ @@ -162,10 +163,10 @@ void pc_delinvincibletimer(struct map_session_data* sd) } int pc_spiritball_timer(int tid, int64 tick, int id, intptr_t data) { - struct map_session_data *sd; + struct map_session_data *sd = map->id2sd(id); int i; - if( (sd=(struct map_session_data *)map->id2sd(id)) == NULL || sd->bl.type!=BL_PC ) + if (sd == NULL) return 1; if( sd->spiritball <= 0 ) @@ -286,14 +287,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 *); @@ -1858,9 +1862,9 @@ int pc_disguise(struct map_session_data *sd, int class_) { clif->updatestatus(sd,SP_CARTINFO); } if (sd->chatID) { - struct chat_data* cd; + struct chat_data *cd = map->id2cd(sd->chatID); - if( (cd = (struct chat_data*)map->id2bl(sd->chatID)) ) + if (cd != NULL) clif->dispchat(cd,0); } } @@ -3976,7 +3980,7 @@ int pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type4 * Grants a player a given skill. * Flag values: @see enum pc_skill_flag *------------------------------------------*/ -int pc_skill(TBL_PC* sd, int id, int level, int flag) +int pc_skill(struct map_session_data *sd, int id, int level, int flag) { uint16 index = 0; nullpo_ret(sd); @@ -5224,7 +5228,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 +5237,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; } @@ -5252,15 +5261,13 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil int i,itemid,flag; double rate; struct status_data *sd_status, *md_status; - struct mob_data *md; + struct mob_data *md = BL_CAST(BL_MOB, bl); struct item tmp_item; struct item_data *data = NULL; - if(!sd || !bl || bl->type!=BL_MOB) + if (sd == NULL || md == NULL) return 0; - md = (TBL_MOB *)bl; - if(md->state.steal_flag == UCHAR_MAX || ( md->sc.opt1 && md->sc.opt1 != OPT1_BURNING && md->sc.opt1 != OPT1_CRYSTALIZE ) ) //already stolen from / status change check return 0; @@ -5332,12 +5339,11 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil **/ int pc_steal_coin(struct map_session_data *sd, struct block_list *target) { int rate, skill_lv; - struct mob_data *md; + struct mob_data *md = BL_CAST(BL_MOB, target); - if (!sd || !target || target->type != BL_MOB) + if (sd == NULL || md == NULL) return 0; - md = (TBL_MOB*)target; if (md->state.steal_coin_flag || md->sc.data[SC_STONE] || md->sc.data[SC_FREEZE] || md->status.mode&MD_BOSS) return 0; @@ -7597,11 +7603,11 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) { if (sd->charm_type != CHARM_TYPE_NONE && sd->charm_count > 0) pc->del_charm(sd, sd->charm_count, sd->charm_type); - if (src) { + if (src != NULL) { switch (src->type) { case BL_MOB: { - struct mob_data *md=(struct mob_data *)src; + struct mob_data *md = BL_UCAST(BL_MOB, src); if (md->target_id==sd->bl.id) mob->unlocktarget(md,tick); if (battle_config.mobs_level_up && md->status.hp @@ -7623,19 +7629,19 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) { } break; case BL_PET: //Pass on to master... - src = &((TBL_PET*)src)->msd->bl; + src = &BL_UCAST(BL_PET, src)->msd->bl; break; case BL_HOM: - src = &((TBL_HOM*)src)->master->bl; + src = &BL_UCAST(BL_HOM, src)->master->bl; break; case BL_MER: - src = &((TBL_MER*)src)->master->bl; + src = &BL_UCAST(BL_MER, src)->master->bl; break; } } - if (src && src->type == BL_PC) { - struct map_session_data *ssd = (struct map_session_data *)src; + if (src != NULL && src->type == BL_PC) { + struct map_session_data *ssd = BL_UCAST(BL_PC, src); pc->setparam(ssd, SP_KILLEDRID, sd->bl.id); npc->script_event(ssd, NPCE_KILLPC); @@ -7821,9 +7827,8 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) { if( map->list[sd->bl.m].flag.pvp && !battle_config.pk_mode && !map->list[sd->bl.m].flag.pvp_nocalcrank ) { sd->pvp_point -= 5; sd->pvp_lost++; - if( src && src->type == BL_PC ) - { - struct map_session_data *ssd = (struct map_session_data *)src; + if (src != NULL && src->type == BL_PC) { + struct map_session_data *ssd = BL_UCAST(BL_PC, src); ssd->pvp_point++; ssd->pvp_won++; } @@ -8323,11 +8328,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); @@ -8778,7 +8784,7 @@ int pc_setcart(struct map_session_data *sd,int type) { * @param sd Target player. * @param flag New state. **/ -void pc_setfalcon(TBL_PC* sd, bool flag) +void pc_setfalcon(struct map_session_data *sd, bool flag) { if (flag) { if (pc->checkskill(sd,HT_FALCON) > 0) // add falcon if he have the skill @@ -8796,7 +8802,7 @@ void pc_setfalcon(TBL_PC* sd, bool flag) * @param sd Target player. * @param flag New state. **/ -void pc_setridingpeco(TBL_PC* sd, bool flag) +void pc_setridingpeco(struct map_session_data *sd, bool flag) { if (flag) { if (pc->checkskill(sd, KN_RIDING)) @@ -8832,7 +8838,7 @@ void pc_setmadogear(struct map_session_data *sd, bool flag) * @param sd Target player. * @param type New state. This must be a valid OPTION_DRAGON* or 0. **/ -void pc_setridingdragon(TBL_PC* sd, unsigned int type) +void pc_setridingdragon(struct map_session_data *sd, unsigned int type) { if (type&OPTION_DRAGON) { // Ensure only one dragon is set at a time. @@ -8864,7 +8870,7 @@ void pc_setridingdragon(TBL_PC* sd, unsigned int type) * @param sd Target player. * @param flag New state. **/ -void pc_setridingwug(TBL_PC* sd, bool flag) +void pc_setridingwug(struct map_session_data *sd, bool flag) { if (flag) { if (pc->checkskill(sd, RA_WUGRIDER) > 0) @@ -9999,12 +10005,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 @@ -10259,8 +10268,7 @@ int pc_autosave(int tid, int64 tick, int id, intptr_t data) { save_flag = 1; //Noone was saved, so save first found char. iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) - { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if(sd->bl.id == last_save_id && save_flag != 1) { save_flag = 1; continue; @@ -10403,10 +10411,10 @@ bool pc_can_use_command(struct map_session_data *sd, const char *command) { */ int pc_charm_timer(int tid, int64 tick, int id, intptr_t data) { - struct map_session_data *sd; + struct map_session_data *sd = map->id2sd(id); int i; - if( (sd=(struct map_session_data *)map->id2sd(id)) == NULL || sd->bl.type!=BL_PC ) + if (sd == NULL) return 1; if (sd->charm_count <= 0) { @@ -10814,7 +10822,7 @@ void pc_read_skill_tree(void) /* lets update all players skill tree */ iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) clif->skillinfoblock(sd); mapit->free(iter); } @@ -11197,7 +11205,7 @@ int pc_global_expiration_timer(int tid, int64 tick, int id, intptr_t data) { struct map_session_data* sd; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( sd->expiration_time ) pc->expire_check(sd); } @@ -11243,7 +11251,7 @@ void pc_autotrade_load(void) SQL->GetData(map->mysql_handle, 2, &data, NULL); sex = atoi(data); SQL->GetData(map->mysql_handle, 3, &data, NULL); safestrncpy(title, data, sizeof(title)); - CREATE(sd, TBL_PC, 1); + CREATE(sd, struct map_session_data, 1); pc->setnewpc(sd, account_id, char_id, 0, 0, sex, 0); @@ -11389,7 +11397,7 @@ void pc_autotrade_prepare(struct map_session_data *sd) { map->quit(sd); chrif->auth_delete(account_id, char_id, ST_LOGOUT); - CREATE(sd, TBL_PC, 1); + CREATE(sd, struct map_session_data, 1); pc->setnewpc(sd, account_id, char_id, 0, 0, sex, 0); diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c index 675a8b62e..bd46b9616 100644 --- a/src/map/pc_groups.c +++ b/src/map/pc_groups.c @@ -508,7 +508,7 @@ void pc_groups_reload(void) { /* refresh online users permissions */ iter = mapit_getallusers(); - for (sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter)) { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if (pc->set_group(sd, sd->group_id) != 0) { ShowWarning("pc_groups_reload: %s (AID:%d) has unknown group id (%d)! kicking...\n", sd->status.name, sd->status.account_id, pc_get_group_id(sd)); diff --git a/src/map/pet.c b/src/map/pet.c index 18a5ba915..db8d0d1f1 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -359,9 +359,10 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo) sd->status.pet_id = 0; return 1; } - sd->pd = pd = (struct pet_data *)aCalloc(1,sizeof(struct pet_data)); + CREATE(pd, struct pet_data, 1); pd->bl.type = BL_PET; pd->bl.id = npc->get_new_npc_id(); + sd->pd = pd; pd->msd = sd; pd->petDB = &pet->db[i]; @@ -505,13 +506,15 @@ int pet_catch_process1(struct map_session_data *sd,int target_class) } int pet_catch_process2(struct map_session_data* sd, int target_id) { - struct mob_data* md; + struct mob_data *md = NULL; + struct block_list *bl = NULL; int i = 0, pet_catch_rate = 0; nullpo_retr(1, sd); - md = (struct mob_data*)map->id2bl(target_id); - if(!md || md->bl.type != BL_MOB || md->bl.prev == NULL) { + bl = map->id2bl(target_id); // TODO: Why does this not use map->id2md? + md = BL_CAST(BL_MOB, bl); + if (md == NULL || md->bl.prev == NULL) { // Invalid inputs/state, abort capture. clif->pet_roulette(sd,0); sd->catch_target_class = -1; @@ -937,7 +940,7 @@ int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, int64 tick pet->unlocktarget(pd); return 0; } else{ - struct flooritem_data *fitem = (struct flooritem_data *)target; + struct flooritem_data *fitem = BL_UCAST(BL_ITEM, target); if(pd->loot->count < pd->loot->max){ memcpy(&pd->loot->item[pd->loot->count++],&fitem->item_data,sizeof(pd->loot->item[0])); pd->loot->weight += itemdb_weight(fitem->item_data.nameid)*fitem->item_data.amount; @@ -964,15 +967,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 9a6200138..0dbea56f8 100644 --- a/src/map/quest.c +++ b/src/map/quest.c @@ -75,7 +75,7 @@ struct quest_db *quest_db(int quest_id) { * @param sd Player's data * @return 0 in case of success, nonzero otherwise (i.e. the player has no quests) */ -int quest_pc_login(TBL_PC *sd) +int quest_pc_login(struct map_session_data *sd) { #if PACKETVER < 20141022 int i; @@ -106,7 +106,8 @@ int quest_pc_login(TBL_PC *sd) * @param quest_id ID of the quest to add. * @return 0 in case of success, nonzero otherwise */ -int quest_add(TBL_PC *sd, int quest_id) { +int quest_add(struct map_session_data *sd, int quest_id) +{ int n; struct quest_db *qi = quest->db(quest_id); @@ -157,7 +158,8 @@ int quest_add(TBL_PC *sd, int quest_id) { * @param qid2 New quest to add * @return 0 in case of success, nonzero otherwise */ -int quest_change(TBL_PC *sd, int qid1, int qid2) { +int quest_change(struct map_session_data *sd, int qid1, int qid2) +{ int i; struct quest_db *qi = quest->db(qid2); @@ -207,7 +209,8 @@ int quest_change(TBL_PC *sd, int qid1, int qid2) { * @param quest_id ID of the quest to remove * @return 0 in case of success, nonzero otherwise */ -int quest_delete(TBL_PC *sd, int quest_id) { +int quest_delete(struct map_session_data *sd, int quest_id) +{ int i; //Search for quest @@ -249,15 +252,15 @@ int quest_delete(TBL_PC *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; @@ -276,7 +279,7 @@ int quest_update_objective_sub(struct block_list *bl, va_list ap) { * @param sd Character's data * @param mob_id Monster ID */ -void quest_update_objective(TBL_PC *sd, int mob_id) +void quest_update_objective(struct map_session_data *sd, int mob_id) { int i,j; @@ -331,7 +334,8 @@ void quest_update_objective(TBL_PC *sd, int mob_id) * @param qs New quest state * @return 0 in case of success, nonzero otherwise */ -int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state qs) { +int quest_update_status(struct map_session_data *sd, int quest_id, enum quest_state qs) +{ int i; ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id); @@ -380,7 +384,7 @@ int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state qs) { * 1 if the quest's timeout has expired * 0 otherwise */ -int quest_check(TBL_PC *sd, int quest_id, enum quest_check_type type) +int quest_check(struct map_session_data *sd, int quest_id, enum quest_check_type type) { int i; diff --git a/src/map/quest.h b/src/map/quest.h index 567f0692a..8e2cb4e23 100644 --- a/src/map/quest.h +++ b/src/map/quest.h @@ -21,9 +21,12 @@ #ifndef MAP_QUEST_H #define MAP_QUEST_H -#include "map/map.h" // TBL_PC #include "common/hercules.h" #include "common/conf.h" +#include "common/mmo.h" // enum quest_state + +struct block_list; +struct map_session_data; #define MAX_QUEST_DB (60355+1) // Highest quest ID + 1 @@ -64,14 +67,14 @@ struct quest_interface { void (*reload) (void); /* */ struct quest_db *(*db) (int quest_id); - int (*pc_login) (TBL_PC *sd); - int (*add) (TBL_PC *sd, int quest_id); - int (*change) (TBL_PC *sd, int qid1, int qid2); - int (*delete) (TBL_PC *sd, int quest_id); + int (*pc_login) (struct map_session_data *sd); + int (*add) (struct map_session_data *sd, int quest_id); + int (*change) (struct map_session_data *sd, int qid1, int qid2); + int (*delete) (struct map_session_data *sd, int quest_id); int (*update_objective_sub) (struct block_list *bl, va_list ap); - void (*update_objective) (TBL_PC *sd, int mob_id); - int (*update_status) (TBL_PC *sd, int quest_id, enum quest_state qs); - int (*check) (TBL_PC *sd, int quest_id, enum quest_check_type type); + void (*update_objective) (struct map_session_data *sd, int mob_id); + int (*update_status) (struct map_session_data *sd, int quest_id, enum quest_state qs); + int (*check) (struct map_session_data *sd, int quest_id, enum quest_check_type type); void (*clear) (void); int (*read_db) (void); struct quest_db *(*read_db_sub) (config_setting_t *cs, int n, const char *source); diff --git a/src/map/script.c b/src/map/script.c index 1e19cb85b..befb85304 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -226,10 +226,13 @@ void script_reportsrc(struct script_state *st) { switch( bl->type ) { case BL_NPC: - if( bl->m >= 0 ) - ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map->list[bl->m].name, bl->x, bl->y); + { + const struct npc_data *nd = BL_UCCAST(BL_NPC, bl); + if (bl->m >= 0) + ShowDebug("Source (NPC): %s at %s (%d,%d)\n", nd->name, map->list[bl->m].name, bl->x, bl->y); else - ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name); + ShowDebug("Source (NPC): %s (invisible/not on a map)\n", nd->name); + } break; default: if( bl->m >= 0 ) @@ -2633,8 +2636,9 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o /// Returns the player attached to this script, identified by the rid. /// If there is no player attached, the script is terminated. -TBL_PC *script_rid2sd(struct script_state *st) { - TBL_PC *sd; +struct map_session_data *script_rid2sd(struct script_state *st) +{ + struct map_session_data *sd; if( !( sd = map->id2sd(st->rid) ) ) { ShowError("script_rid2sd: fatal error ! player not attached!\n"); script->reportfunc(st); @@ -2644,8 +2648,9 @@ TBL_PC *script_rid2sd(struct script_state *st) { return sd; } -TBL_PC *script_id2sd(struct script_state *st, int account_id) { - TBL_PC *sd; +struct map_session_data *script_id2sd(struct script_state *st, int account_id) +{ + struct map_session_data *sd; if ((sd = map->id2sd(account_id)) == NULL) { ShowWarning("script_id2sd: Player with account ID '%d' not found!\n", account_id); script->reportfunc(st); @@ -2654,8 +2659,9 @@ TBL_PC *script_id2sd(struct script_state *st, int account_id) { return sd; } -TBL_PC *script_charid2sd(struct script_state *st, int char_id) { - TBL_PC *sd; +struct map_session_data *script_charid2sd(struct script_state *st, int char_id) +{ + struct map_session_data *sd; if ((sd = map->charid2sd(char_id)) == NULL) { ShowWarning("script_charid2sd: Player with char ID '%d' not found!\n", char_id); script->reportfunc(st); @@ -2664,8 +2670,9 @@ TBL_PC *script_charid2sd(struct script_state *st, int char_id) { return sd; } -TBL_PC *script_nick2sd(struct script_state *st, const char *name) { - TBL_PC *sd; +struct map_session_data *script_nick2sd(struct script_state *st, const char *name) +{ + struct map_session_data *sd; if ((sd = map->nick2sd(name)) == NULL) { ShowWarning("script_nick2sd: Player name '%s' not found!\n", name); script->reportfunc(st); @@ -2717,7 +2724,7 @@ struct script_data *get_val(struct script_state* st, struct script_data* data) { const char* name; char prefix; char postfix; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; if( !data_isreference(data) ) return data;// not a variable/constant @@ -3146,7 +3153,8 @@ void set_reg_instance_num(struct script_state* st, int64 num, const char* name, * * TODO: return values are screwed up, have been for some time (reaad: years), e.g. some functions return 1 failure and success. *------------------------------------------*/ -int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, const void* value, struct reg_db *ref) { +int set_reg(struct script_state *st, struct map_session_data *sd, int64 num, const char *name, const void *value, struct reg_db *ref) +{ char prefix = name[0]; if (strlen(name) > SCRIPT_VARNAME_LENGTH) { @@ -3231,11 +3239,13 @@ int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, co } } -int set_var(TBL_PC* sd, char* name, void* val) { +int set_var(struct map_session_data *sd, char *name, void *val) +{ return script->set_reg(NULL, sd, reference_uid(script->add_str(name),0), name, val, NULL); } -void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct reg_db *ref) { +void setd_sub(struct script_state *st, struct map_session_data *sd, const char *varname, int elem, void *value, struct reg_db *ref) +{ script->set_reg(st, sd, reference_uid(script->add_str(varname),elem), varname, value, ref); } @@ -4156,7 +4166,7 @@ void script_stop_instances(struct script_code *code) { int run_script_timer(int tid, int64 tick, int id, intptr_t data) { struct script_state *st = idb_get(script->st_db,(int)data); if( st ) { - TBL_PC *sd = map->id2sd(st->rid); + struct map_session_data *sd = map->id2sd(st->rid); if((sd && sd->status.char_id != id) || (st->rid && !sd)) { //Character mismatch. Cancel execution. st->rid = 0; @@ -4241,7 +4251,7 @@ void script_attach_state(struct script_state* st) { void run_script_main(struct script_state *st) { int cmdcount = script->config.check_cmdcount; int gotocount = script->config.check_gotocount; - TBL_PC *sd; + struct map_session_data *sd; struct script_stack *stack = st->stack; struct npc_data *nd; @@ -5158,8 +5168,9 @@ const char *script_getfuncname(struct script_state *st) { /// If a dialog doesn't exist yet, one is created. /// /// mes "<message>"; -BUILDIN(mes) { - TBL_PC* sd = script->rid2sd(st); +BUILDIN(mes) +{ + struct map_session_data *sd = script->rid2sd(st); if( sd == NULL ) return true; @@ -5183,10 +5194,8 @@ BUILDIN(mes) { /// next; BUILDIN(next) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; #ifdef SECURE_NPCTIMEOUT sd->npc_idle_type = NPCT_WAIT; @@ -5200,11 +5209,10 @@ BUILDIN(next) /// The dialog is closed when the button is pressed. /// /// close; -BUILDIN(close) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) +BUILDIN(close) +{ + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; st->state = sd->state.dialog == 1 ? CLOSE : END; @@ -5216,11 +5224,10 @@ BUILDIN(close) { /// The dialog is closed and the script continues when the button is pressed. /// /// close2; -BUILDIN(close2) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) +BUILDIN(close2) +{ + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; if( sd->state.dialog == 1 ) @@ -5290,10 +5297,8 @@ BUILDIN(menu) { int i; const char* text; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; #ifdef SECURE_NPCTIMEOUT @@ -5414,10 +5419,8 @@ BUILDIN(select) { int i; const char* text; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; #ifdef SECURE_NPCTIMEOUT @@ -5491,10 +5494,8 @@ BUILDIN(prompt) { int i; const char *text; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; #ifdef SECURE_NPCTIMEOUT @@ -5821,10 +5822,8 @@ BUILDIN(warp) int x,y; int warp_clean = 1; const char* str; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; str = script_getstr(st,2); @@ -5853,10 +5852,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); @@ -5864,9 +5868,9 @@ int buildin_areawarp_sub(struct block_list *bl,va_list ap) x3 = va_arg(ap,int); y3 = va_arg(ap,int); - if(index == 0) - pc->randomwarp((TBL_PC *)bl,CLR_TELEPORT); - else if(x3 && y3) { + if (index == 0) { + pc->randomwarp(sd, CLR_TELEPORT); + } else if (x3 != 0 && y3 != 0) { int max, tx, ty, j = 0; // choose a suitable max number of attempts @@ -5880,10 +5884,10 @@ 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((TBL_PC *)bl,index,tx,ty,CLR_OUTSIGHT); + pc->setpos(sd, index, tx, ty, CLR_OUTSIGHT); + } else { + pc->setpos(sd, index, x2, y2, CLR_OUTSIGHT); } - else - pc->setpos((TBL_PC *)bl,index,x2,y2,CLR_OUTSIGHT); return 0; } BUILDIN(areawarp) @@ -5928,14 +5932,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((TBL_PC *)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; @@ -5965,7 +5975,7 @@ BUILDIN(areapercentheal) { BUILDIN(warpchar) { int x,y,a; const char *str; - TBL_PC *sd; + struct map_session_data *sd; str=script_getstr(st,2); x=script_getnum(st,3); @@ -5993,8 +6003,8 @@ BUILDIN(warpchar) { *------------------------------------------*/ BUILDIN(warpparty) { - TBL_PC *sd = NULL; - TBL_PC *pl_sd; + struct map_session_data *sd = NULL; + struct map_session_data *pl_sd; struct party_data* p; int type; int map_index; @@ -6082,8 +6092,8 @@ BUILDIN(warpparty) *------------------------------------------*/ BUILDIN(warpguild) { - TBL_PC *sd = NULL; - TBL_PC *pl_sd; + struct map_session_data *sd = NULL; + struct map_session_data *pl_sd; struct guild* g; struct s_mapiterator* iter; int type; @@ -6108,8 +6118,7 @@ BUILDIN(warpguild) } iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) - { + for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( pl_sd->status.guild_id != gid ) continue; @@ -6140,12 +6149,12 @@ BUILDIN(warpguild) /*========================================== * Force Heal a player (hp and sp) *------------------------------------------*/ -BUILDIN(heal) { - TBL_PC *sd; +BUILDIN(heal) +{ int hp,sp; - - sd = script->rid2sd(st); - if (!sd) return true; + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) + return true; hp=script_getnum(st,2); sp=script_getnum(st,3); @@ -6157,7 +6166,7 @@ BUILDIN(heal) { *------------------------------------------*/ BUILDIN(itemheal) { - TBL_PC *sd; + struct map_session_data *sd; int hp,sp; hp=script_getnum(st,2); @@ -6180,7 +6189,7 @@ BUILDIN(itemheal) BUILDIN(percentheal) { int hp,sp; - TBL_PC* sd; + struct map_session_data *sd; hp=script_getnum(st,2); sp=script_getnum(st,3); @@ -6213,12 +6222,9 @@ BUILDIN(jobchange) if( script_hasdata(st,3) ) upper=script_getnum(st,3); - if (pc->db_checkid(job)) - { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + if (pc->db_checkid(job)) { + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; pc->jobchange(sd, job, upper); @@ -6246,15 +6252,13 @@ BUILDIN(jobname) /// input(<var>{,<min>{,<max>}}) -> <int> BUILDIN(input) { - TBL_PC* sd; struct script_data* data; int64 uid; const char* name; int min; int max; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; data = script_getdata(st,2); @@ -6308,8 +6312,9 @@ BUILDIN(copyarray); /// The value is converted to the type of the variable. /// /// set(<variable>,<value>) -> <variable> -BUILDIN(__setr) { - TBL_PC* sd = NULL; +BUILDIN(__setr) +{ + struct map_session_data *sd = NULL; struct script_data* data; //struct script_data* datavalue; int64 num; @@ -6402,7 +6407,7 @@ BUILDIN(setarray) uint32 end; int32 id; int32 i; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; data = script_getdata(st, 2); if( !data_isreference(data) || reference_toconstant(data) ) @@ -6453,7 +6458,7 @@ BUILDIN(cleararray) uint32 end; int32 id; void* v; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; data = script_getdata(st, 2); if( !data_isreference(data) ) @@ -6506,7 +6511,7 @@ BUILDIN(copyarray) void* v; int32 i; uint32 count; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; data1 = script_getdata(st, 2); data2 = script_getdata(st, 3); @@ -6608,7 +6613,7 @@ BUILDIN(deletearray) const char* name; unsigned int start, end, i; int id; - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; struct script_array *sa = NULL; struct reg_db *src = NULL; void *value; @@ -6757,7 +6762,7 @@ BUILDIN(getelementofarray) BUILDIN(setlook) { int type,val; - TBL_PC* sd; + struct map_session_data *sd; type=script_getnum(st,2); val=script_getnum(st,3); @@ -6774,7 +6779,7 @@ BUILDIN(setlook) BUILDIN(changelook) { // As setlook but only client side int type,val; - TBL_PC* sd; + struct map_session_data *sd; type=script_getnum(st,2); val=script_getnum(st,3); @@ -6793,10 +6798,8 @@ BUILDIN(changelook) *------------------------------------------*/ BUILDIN(cutin) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; clif->cutin(sd,script_getstr(st,2),script_getnum(st,3)); @@ -6809,7 +6812,7 @@ BUILDIN(cutin) BUILDIN(viewpoint) { int type,x,y,id,color; - TBL_PC* sd; + struct map_session_data *sd; type=script_getnum(st,2); x=script_getnum(st,3); @@ -6834,8 +6837,8 @@ BUILDIN(countitem) { int count = 0; struct item_data* id = NULL; - TBL_PC* sd = script->rid2sd(st); - if( !sd ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; if( script_isstringtype(st, 2) ) { @@ -6872,8 +6875,8 @@ BUILDIN(countitem2) { int i; struct item_data* id = NULL; - TBL_PC* sd = script->rid2sd(st); - if( !sd ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; if( script_isstringtype(st, 2) ) { @@ -7017,8 +7020,7 @@ BUILDIN(checkweight2) int32 idx_it, idx_nb; int nb_it, nb_nb; //array size - TBL_PC *sd = script->rid2sd(st); - + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -7110,7 +7112,7 @@ BUILDIN(checkweight2) BUILDIN(getitem) { int nameid,amount,get_count,i,flag = 0, offset = 0; struct item it; - TBL_PC *sd; + struct map_session_data *sd; struct item_data *item_data; if( script_isstringtype(st, 2) ) { @@ -7196,7 +7198,7 @@ BUILDIN(getitem2) { int nameid,amount,flag = 0, offset = 0; int iden,ref,attr,c1,c2,c3,c4, bound = 0; - TBL_PC *sd; + struct map_session_data *sd; if( !strcmp(script->getfuncname(st),"getitembound2") ) { bound = script_getnum(st,11); @@ -7353,7 +7355,7 @@ BUILDIN(rentitem) { BUILDIN(getnameditem) { int nameid; struct item item_tmp; - TBL_PC *sd, *tsd; + struct map_session_data *sd, *tsd; sd = script->rid2sd(st); if (sd == NULL) // Player not attached! @@ -7466,9 +7468,9 @@ BUILDIN(makeitem) y = script_getnum(st,6); if(strcmp(mapname,"this")==0) { - TBL_PC *sd; - sd = script->rid2sd(st); - if (!sd) return true; //Failed... + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) + return true; //Failed... m=sd->bl.m; } else m=map->mapname2mapid(mapname); @@ -7621,8 +7623,9 @@ bool buildin_delitem_search(struct map_session_data* sd, struct item* it, bool e /// /// delitem <item id>,<amount>{,<account id>} /// delitem "<item name>",<amount>{,<account id>} -BUILDIN(delitem) { - TBL_PC *sd; +BUILDIN(delitem) +{ + struct map_session_data *sd; struct item it; if (script_hasdata(st,4)) { @@ -7677,8 +7680,9 @@ BUILDIN(delitem) { /// /// delitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>} /// delitem2 "<Item name>",<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>} -BUILDIN(delitem2) { - TBL_PC *sd; +BUILDIN(delitem2) +{ + struct map_session_data *sd; struct item it; if (script_hasdata(st,11)) { @@ -7741,18 +7745,16 @@ BUILDIN(delitem2) { *------------------------------------------*/ BUILDIN(enableitemuse) { - TBL_PC *sd; - sd=script->rid2sd(st); - if (sd) + struct map_session_data *sd = script->rid2sd(st); + if (sd != NULL) st->npc_item_flag = sd->npc_item_flag = 1; return true; } BUILDIN(disableitemuse) { - TBL_PC *sd; - sd=script->rid2sd(st); - if (sd) + struct map_session_data *sd = script->rid2sd(st); + if (sd != NULL) st->npc_item_flag = sd->npc_item_flag = 0; return true; } @@ -7763,7 +7765,7 @@ BUILDIN(disableitemuse) *------------------------------------------*/ BUILDIN(readparam) { int type; - TBL_PC *sd; + struct map_session_data *sd; type=script_getnum(st,2); if (script_hasdata(st,3)) @@ -7792,7 +7794,7 @@ BUILDIN(readparam) { *------------------------------------------*/ BUILDIN(getcharid) { int num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); if( script_hasdata(st,3) ) @@ -8066,13 +8068,11 @@ BUILDIN(getguildmember) *------------------------------------------*/ BUILDIN(strcharinfo) { - TBL_PC *sd; int num; struct guild* g; struct party_data* p; - - sd=script->rid2sd(st); - if (!sd) //Avoid crashing.... + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) //Avoid crashing.... return true; num=script_getnum(st,2); @@ -8115,13 +8115,12 @@ BUILDIN(strcharinfo) * 3 : ::str * 4 : map name *------------------------------------------*/ -BUILDIN(strnpcinfo) { - TBL_NPC* nd; +BUILDIN(strnpcinfo) +{ int num; char *buf,*name=NULL; - - nd = map->id2nd(st->oid); - if (!nd) { + struct npc_data *nd = map->id2nd(st->oid); + if (nd == NULL) { script_pushconststr(st, ""); return true; } @@ -8166,7 +8165,7 @@ BUILDIN(strnpcinfo) { BUILDIN(charid2rid) { int cid = script_getnum(st, 2); - TBL_PC *sd = map->charid2sd(cid); + struct map_session_data *sd = map->charid2sd(cid); if (sd == NULL) { script_pushint(st, 0); @@ -8183,11 +8182,9 @@ BUILDIN(charid2rid) BUILDIN(getequipid) { int i, num; - TBL_PC* sd; struct item_data* item; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; num = script_getnum(st,2) - 1; @@ -8221,11 +8218,9 @@ BUILDIN(getequipid) BUILDIN(getequipname) { int i, num; - TBL_PC* sd; struct item_data* item; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; num = script_getnum(st,2) - 1; @@ -8258,10 +8253,8 @@ BUILDIN(getequipname) BUILDIN(getbrokenid) { int i,num,id=0,brokencounter=0; - TBL_PC *sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; num=script_getnum(st,2); @@ -8286,10 +8279,7 @@ BUILDIN(getbrokenid) BUILDIN(getbrokencount) { int i, counter = 0; - TBL_PC *sd; - - sd = script->rid2sd(st); - + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -8310,10 +8300,8 @@ BUILDIN(repair) { int i,num; int repaircounter=0; - TBL_PC *sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; num=script_getnum(st,2); @@ -8339,10 +8327,8 @@ BUILDIN(repair) BUILDIN(repairall) { int i, repaircounter = 0; - TBL_PC *sd; - - sd = script->rid2sd(st); - if(sd == NULL) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; for(i = 0; i < MAX_INVENTORY; i++) @@ -8370,7 +8356,7 @@ BUILDIN(repairall) BUILDIN(getequipisequiped) { int i = -1,num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -8397,7 +8383,7 @@ BUILDIN(getequipisequiped) BUILDIN(getequipisenableref) { int i = -1,num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -8423,7 +8409,7 @@ BUILDIN(getequipisenableref) BUILDIN(getequipisidentify) { int i = -1,num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -8449,7 +8435,7 @@ BUILDIN(getequipisidentify) BUILDIN(getequiprefinerycnt) { int i = -1,num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -8476,7 +8462,7 @@ BUILDIN(getequiprefinerycnt) BUILDIN(getequipweaponlv) { int i = -1,num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -8501,7 +8487,7 @@ BUILDIN(getequipweaponlv) *------------------------------------------*/ BUILDIN(getequippercentrefinery) { int i = -1,num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -8524,7 +8510,7 @@ BUILDIN(getequippercentrefinery) { BUILDIN(successrefitem) { int i = -1 , num, up = 1; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -8585,7 +8571,7 @@ BUILDIN(successrefitem) BUILDIN(failedrefitem) { int i=-1,num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -8613,7 +8599,7 @@ BUILDIN(failedrefitem) BUILDIN(downrefitem) { int i = -1, num, down = 1; - TBL_PC *sd; + struct map_session_data *sd; sd = script->rid2sd(st); if (sd == NULL) @@ -8654,7 +8640,7 @@ BUILDIN(downrefitem) BUILDIN(delequip) { int i=-1,num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -8681,7 +8667,7 @@ BUILDIN(delequip) *------------------------------------------*/ BUILDIN(statusup) { int type; - TBL_PC *sd; + struct map_session_data *sd; type=script_getnum(st,2); sd = script->rid2sd(st); @@ -8698,7 +8684,7 @@ BUILDIN(statusup) { BUILDIN(statusup2) { int type,val; - TBL_PC *sd; + struct map_session_data *sd; type=script_getnum(st,2); val=script_getnum(st,3); @@ -8725,10 +8711,8 @@ BUILDIN(bonus) { int val3 = 0; int val4 = 0; int val5 = 0; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; // no player attached type = script_getnum(st,2); @@ -8806,11 +8790,9 @@ BUILDIN(autobonus) { unsigned int dur; short rate; short atk_type = 0; - TBL_PC* sd; const char *bonus_script, *other_script = NULL; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; // no player attached if( sd->state.autobonus&sd->status.inventory[status->current_equip_item_index].equip ) @@ -8842,11 +8824,9 @@ BUILDIN(autobonus2) { unsigned int dur; short rate; short atk_type = 0; - TBL_PC* sd; const char *bonus_script, *other_script = NULL; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; // no player attached if( sd->state.autobonus&sd->status.inventory[status->current_equip_item_index].equip ) @@ -8877,11 +8857,9 @@ BUILDIN(autobonus2) { BUILDIN(autobonus3) { unsigned int dur; short rate,atk_type; - TBL_PC* sd; const char *bonus_script, *other_script = NULL; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; // no player attached if( sd->state.autobonus&sd->status.inventory[status->current_equip_item_index].equip ) @@ -8922,10 +8900,8 @@ BUILDIN(skill) { int id; int level; int flag = SKILL_GRANT_TEMPORARY; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source id = ( script_isstringtype(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); @@ -8950,10 +8926,8 @@ BUILDIN(addtoskill) { int id; int level; int flag = SKILL_GRANT_TEMPSTACK; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source id = ( script_isstringtype(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); @@ -8973,11 +8947,9 @@ BUILDIN(guildskill) { int skill_id, id, max_points; int level; - TBL_PC* sd; struct guild *gd; struct guild_skill gd_skill; - - sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; // no player attached, report source @@ -9007,12 +8979,11 @@ BUILDIN(guildskill) { /// /// getskilllv(<skill id>) -> <level> /// getskilllv("<skill name>") -> <level> -BUILDIN(getskilllv) { +BUILDIN(getskilllv) +{ int id; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source id = ( script_isstringtype(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); @@ -9057,10 +9028,8 @@ BUILDIN(basicskillcheck) /// getgmlevel() -> <level> BUILDIN(getgmlevel) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source script_pushint(st, pc_get_group_level(sd)); @@ -9097,9 +9066,7 @@ BUILDIN(setgroupid) { /// getgroupid() -> <int> BUILDIN(getgroupid) { - TBL_PC* sd; - - sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; // no player attached, report source script_pushint(st, pc_get_group_id(sd)); @@ -9133,10 +9100,8 @@ BUILDIN(end) { BUILDIN(checkoption) { int option; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source option = script_getnum(st,2); @@ -9154,10 +9119,8 @@ BUILDIN(checkoption) BUILDIN(checkoption1) { int opt1; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source opt1 = script_getnum(st,2); @@ -9175,10 +9138,8 @@ BUILDIN(checkoption1) BUILDIN(checkoption2) { int opt2; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source opt2 = script_getnum(st,2); @@ -9201,10 +9162,8 @@ BUILDIN(setoption) { int option; int flag = 1; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source option = script_getnum(st,2); @@ -9234,10 +9193,8 @@ BUILDIN(setoption) /// @author Valaris BUILDIN(checkcart) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source if( pc_iscarton(sd) ) @@ -9262,10 +9219,8 @@ BUILDIN(checkcart) BUILDIN(setcart) { int type = 1; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source if( script_hasdata(st,2) ) @@ -9282,9 +9237,7 @@ BUILDIN(setcart) /// @author Valaris BUILDIN(checkfalcon) { - TBL_PC* sd; - - sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true;// no player attached, report source @@ -9304,9 +9257,7 @@ BUILDIN(checkfalcon) BUILDIN(setfalcon) { bool flag = true; - TBL_PC* sd; - - sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true;// no player attached, report source @@ -9342,9 +9293,7 @@ enum setmount_type { */ BUILDIN(checkmount) { - TBL_PC* sd; - - sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; // no player attached, report source @@ -9388,9 +9337,7 @@ BUILDIN(checkmount) BUILDIN(setmount) { int flag = SETMOUNT_TYPE_AUTODETECT; - TBL_PC* sd; - - sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true;// no player attached, report source @@ -9454,10 +9401,8 @@ BUILDIN(setmount) /// BUILDIN(checkwug) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true;// no player attached, report source if( pc_iswug(sd) || pc_isridingwug(sd) ) @@ -9477,9 +9422,7 @@ BUILDIN(savepoint) { int y; short mapid; const char* str; - TBL_PC* sd; - - sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; // no player attached, report source @@ -9595,23 +9538,21 @@ BUILDIN(gettimestr) /*========================================== * Open player storage *------------------------------------------*/ -BUILDIN(openstorage) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) +BUILDIN(openstorage) +{ + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; storage->open(sd); return true; } -BUILDIN(guildopenstorage) { - TBL_PC* sd; +BUILDIN(guildopenstorage) +{ int ret; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; ret = gstorage->open(sd); @@ -9624,13 +9565,12 @@ BUILDIN(guildopenstorage) { *------------------------------------------*/ /// itemskill <skill id>,<level>{,flag /// itemskill "<skill name>",<level>{,flag -BUILDIN(itemskill) { +BUILDIN(itemskill) +{ int id; int lv; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL || sd->ud.skilltimer != INVALID_TIMER ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || sd->ud.skilltimer != INVALID_TIMER) return true; id = ( script_isstringtype(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); @@ -9653,10 +9593,8 @@ BUILDIN(itemskill) { BUILDIN(produce) { int trigger; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; trigger=script_getnum(st,2); @@ -9669,10 +9607,8 @@ BUILDIN(produce) BUILDIN(cooking) { int trigger; - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; trigger=script_getnum(st,2); @@ -9684,7 +9620,7 @@ BUILDIN(cooking) *------------------------------------------*/ BUILDIN(makepet) { - TBL_PC* sd; + struct map_session_data *sd; int id,pet_id; id=script_getnum(st,2); @@ -9711,12 +9647,10 @@ BUILDIN(makepet) *------------------------------------------*/ BUILDIN(getexp) { - TBL_PC* sd; int base=0,job=0; double bonus; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; base=script_getnum(st,2); @@ -9739,11 +9673,9 @@ BUILDIN(getexp) *------------------------------------------*/ BUILDIN(guildgetexp) { - TBL_PC* sd; int exp; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; exp = script_getnum(st,2); @@ -9758,8 +9690,9 @@ BUILDIN(guildgetexp) /*========================================== * Changes the guild master of a guild [Skotlex] *------------------------------------------*/ -BUILDIN(guildchangegm) { - TBL_PC *sd; +BUILDIN(guildchangegm) +{ + struct map_session_data *sd; int guild_id; const char *name; @@ -9953,11 +9886,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) -{ //same fix but with killmonster instead - stripping events from mobs. - TBL_MOB* md = (TBL_MOB*)bl; - char *event=va_arg(ap,char *); - int allflag=va_arg(ap,int); +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 = 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; @@ -9971,11 +9909,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) { - TBL_MOB* md = (TBL_MOB*)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) @@ -10058,7 +10000,7 @@ BUILDIN(killmonsterall) { * clone map, x, y, event, char_id, master_id, mode, flag, duration *------------------------------------------*/ BUILDIN(clone) { - TBL_PC *sd, *msd=NULL; + struct map_session_data *sd, *msd = NULL; int char_id,master_id=0,x,y, mode = 0, flag = 0, m; unsigned int duration = 0; const char *mapname, *event; @@ -10139,7 +10081,7 @@ BUILDIN(addtimer) { int tick = script_getnum(st,2); const char* event = script_getstr(st, 3); - TBL_PC* sd; + struct map_session_data *sd; script->check_event(st, event); sd = script->rid2sd(st); @@ -10157,7 +10099,7 @@ BUILDIN(addtimer) BUILDIN(deltimer) { const char *event; - TBL_PC* sd; + struct map_session_data *sd; event=script_getstr(st, 2); sd = script->rid2sd(st); @@ -10174,7 +10116,7 @@ BUILDIN(addtimercount) { const char *event; int tick; - TBL_PC* sd; + struct map_session_data *sd; event=script_getstr(st, 2); tick=script_getnum(st,3); @@ -10203,25 +10145,26 @@ BUILDIN(initnpctimer) struct script_data *data; data = script_getdata(st,2); script->get_val(st,data); // dereference if it's a variable - if( data_isstring(data) ) //NPC name + if (data_isstring(data)) { + //NPC name nd = npc->name2id(script->conv_str(st, data)); - else if( data_isint(data) ) { + } else if (data_isint(data)) { //Flag - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); flag = script->conv_num(st,data); } else { ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n"); return false; } - } else - nd = (struct npc_data *)map->id2bl(st->oid); + } else { + nd = map->id2nd(st->oid); + } if( !nd ) return true; - if( flag ) //Attach - { - TBL_PC* sd = script->rid2sd(st); - if( sd == NULL ) + if (flag) { //Attach + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; nd->u.scr.rid = sd->bl.id; } @@ -10247,25 +10190,26 @@ BUILDIN(startnpctimer) struct script_data *data; data = script_getdata(st,2); script->get_val(st,data); // dereference if it's a variable - if( data_isstring(data) ) //NPC name + if (data_isstring(data)) { + //NPC name nd = npc->name2id(script->conv_str(st, data)); - else if( data_isint(data) ) { + } else if (data_isint(data)) { //Flag - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); flag = script->conv_num(st,data); } else { ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n"); return false; } - } else - nd=(struct npc_data *)map->id2bl(st->oid); + } else { + nd = map->id2nd(st->oid); + } if( !nd ) return true; - if( flag ) //Attach - { - TBL_PC* sd = script->rid2sd(st); - if( sd == NULL ) + if (flag) { //Attach + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; nd->u.scr.rid = sd->bl.id; } @@ -10288,18 +10232,20 @@ BUILDIN(stopnpctimer) { struct script_data *data; data = script_getdata(st,2); script->get_val(st,data); // Dereference if it's a variable - if( data_isstring(data) ) //NPC name + if (data_isstring(data)) { + //NPC name nd = npc->name2id(script->conv_str(st, data)); - else if( data_isint(data) ) { + } else if (data_isint(data)) { //Flag - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); flag = script->conv_num(st,data); } else { ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n"); return false; } - } else - nd=(struct npc_data *)map->id2bl(st->oid); + } else { + nd = map->id2nd(st->oid); + } if( !nd ) return true; @@ -10311,19 +10257,19 @@ BUILDIN(stopnpctimer) { } /*========================================== *------------------------------------------*/ -BUILDIN(getnpctimer) { +BUILDIN(getnpctimer) +{ struct npc_data *nd; - TBL_PC *sd; + struct map_session_data *sd; int type = script_getnum(st,2); int val = 0; if( script_hasdata(st,3) ) nd = npc->name2id(script_getstr(st,3)); else - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); - if( !nd || nd->bl.type != BL_NPC ) - { + if (nd == NULL) { script_pushint(st,0); ShowError("getnpctimer: Invalid NPC.\n"); return false; @@ -10358,9 +10304,9 @@ BUILDIN(setnpctimer) if( script_hasdata(st,3) ) nd = npc->name2id(script_getstr(st,3)); else - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); - if( !nd || nd->bl.type != BL_NPC ) { + if (nd == NULL) { script_pushint(st,1); ShowError("setnpctimer: Invalid NPC.\n"); return false; @@ -10374,12 +10320,12 @@ BUILDIN(setnpctimer) /*========================================== * attaches the player rid to the timer [Celest] *------------------------------------------*/ -BUILDIN(attachnpctimer) { - TBL_PC *sd; - struct npc_data *nd = (struct npc_data *)map->id2bl(st->oid); +BUILDIN(attachnpctimer) +{ + struct map_session_data *sd; + struct npc_data *nd = map->id2nd(st->oid); - if( !nd || nd->bl.type != BL_NPC ) - { + if (nd == NULL) { script_pushint(st,1); ShowError("setnpctimer: Invalid NPC.\n"); return false; @@ -10409,10 +10355,9 @@ BUILDIN(detachnpctimer) { if( script_hasdata(st,2) ) nd = npc->name2id(script_getstr(st,2)); else - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); - if( !nd || nd->bl.type != BL_NPC ) - { + if (nd == NULL) { script_pushint(st,1); ShowError("detachnpctimer: Invalid NPC.\n"); return false; @@ -10450,7 +10395,15 @@ BUILDIN(announce) { if( flag&(BC_TARGET_MASK|BC_SOURCE_MASK) ) { // Broadcast source or broadcast region defined send_target target; - struct block_list *bl = (flag&BC_NPC) ? map->id2bl(st->oid) : (struct block_list *)script->rid2sd(st); // If bc_npc flag is set, use NPC as broadcast source + struct block_list *bl = NULL; + if (flag&BC_NPC) { + // If bc_npc flag is set, use NPC as broadcast source + bl = map->id2bl(st->oid); + } else { + struct map_session_data *sd = script->rid2sd(st); + if (sd != NULL) + bl = &sd->bl; + } if (bl == NULL) return true; @@ -10494,17 +10447,16 @@ int buildin_announce_sub(struct block_list *bl, va_list ap) /* Runs item effect on attached character. * itemeffect <item id>; * itemeffect "<item name>"; */ -BUILDIN(itemeffect) { - TBL_NPC *nd; - TBL_PC *sd; +BUILDIN(itemeffect) +{ + struct npc_data *nd; struct item_data *item_data; - - sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; - nd = (TBL_NPC *)map->id2bl(sd->npc_id); - if( nd == NULL ) + nd = map->id2nd(sd->npc_id); + if (nd == NULL) return false; if( script_isstringtype(st, 2) ) { @@ -10611,7 +10563,8 @@ BUILDIN(getusers) { *------------------------------------------*/ BUILDIN(getusersname) { - TBL_PC *sd, *pl_sd; + struct map_session_data *sd; + const struct map_session_data *pl_sd; int /*disp_num=1,*/ group_level = 0; struct s_mapiterator* iter; @@ -10620,8 +10573,7 @@ BUILDIN(getusersname) group_level = pc_get_group_level(sd); iter = mapit_getallusers(); - for( pl_sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); pl_sd = (TBL_PC*)mapit->next(iter) ) - { + for (pl_sd = BL_UCCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCCAST(BL_PC, mapit->next(iter))) { if (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > group_level) continue; // skip hidden sessions @@ -10700,7 +10652,7 @@ BUILDIN(getareausers) } idx = 3; } else { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) { script_pushint(st, -1); return true; @@ -10746,17 +10698,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; @@ -10832,8 +10789,9 @@ BUILDIN(hideonnpc) * sc_start4 <effect_id>,<duration>,<val1>,<val2>,<val3>,<val4>{,<rate,<flag>,{<unit_id>}}; * <flag>: @see enum scstart_flag */ -BUILDIN(sc_start) { - TBL_NPC * nd = map->id2nd(st->oid); +BUILDIN(sc_start) +{ + struct npc_data *nd = map->id2nd(st->oid); struct block_list* bl; enum sc_type type; int tick, val1, val2, val3, val4=0, rate, flag; @@ -11029,7 +10987,7 @@ BUILDIN(debugmes) BUILDIN(catchpet) { int pet_id; - TBL_PC *sd; + struct map_session_data *sd; pet_id= script_getnum(st,2); sd=script->rid2sd(st); @@ -11045,10 +11003,8 @@ BUILDIN(catchpet) *------------------------------------------*/ BUILDIN(homunculus_evolution) { - TBL_PC *sd; - - sd=script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; if(homun_alive(sd->hd)) { @@ -11067,11 +11023,9 @@ BUILDIN(homunculus_evolution) *------------------------------------------*/ BUILDIN(homunculus_mutate) { - TBL_PC *sd; bool success = false; - - sd = script->rid2sd(st); - if( sd == NULL || sd->hd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || sd->hd == NULL) return true; if (sd->hd->homunculus.vaporize == HOM_ST_MORPH) { @@ -11110,11 +11064,9 @@ BUILDIN(homunculus_mutate) *------------------------------------------*/ BUILDIN(homunculus_morphembryo) { - TBL_PC *sd; bool success = false; - - sd = script->rid2sd(st); - if( sd == NULL || sd->hd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || sd->hd == NULL) return true; if (homun_alive(sd->hd)) { @@ -11153,10 +11105,10 @@ BUILDIN(homunculus_morphembryo) * 1 = Homunculus is vaporized (rest) * 2 = Homunculus is in morph state *------------------------------------------*/ -BUILDIN(homunculus_checkcall) { - TBL_PC *sd = script->rid2sd(st); - - if( sd == NULL || !sd->hd ) +BUILDIN(homunculus_checkcall) +{ + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || sd->hd == NULL) script_pushint(st, -1); else script_pushint(st, sd->hd->homunculus.vaporize); @@ -11165,11 +11117,10 @@ BUILDIN(homunculus_checkcall) { } // [Zephyrus] -BUILDIN(homunculus_shuffle) { - TBL_PC *sd; - - sd=script->rid2sd(st); - if( sd == NULL ) +BUILDIN(homunculus_shuffle) +{ + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; if(homun_alive(sd->hd)) @@ -11182,12 +11133,11 @@ BUILDIN(homunculus_shuffle) { BUILDIN(eaclass) { int class_; - if( script_hasdata(st,2) ) + if (script_hasdata(st,2)) { class_ = script_getnum(st,2); - else { - TBL_PC *sd; - sd=script->rid2sd(st); - if( !sd ) + } else { + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; class_ = sd->status.class_; } @@ -11199,10 +11149,10 @@ BUILDIN(roclass) { int class_ =script_getnum(st,2); int sex; - if( script_hasdata(st,3) ) + if (script_hasdata(st,3)) { sex = script_getnum(st,3); - else { - TBL_PC *sd; + } else { + struct map_session_data *sd; if (st->rid && (sd=script->rid2sd(st)) != NULL) sex = sd->status.sex; else @@ -11217,9 +11167,8 @@ BUILDIN(roclass) *------------------------------------------*/ BUILDIN(birthpet) { - TBL_PC *sd; - sd=script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; if( sd->status.pet_id ) @@ -11241,12 +11190,9 @@ BUILDIN(birthpet) *------------------------------------------*/ BUILDIN(resetlvl) { - TBL_PC *sd; - int type=script_getnum(st,2); - - sd=script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; pc->resetlvl(sd,type); @@ -11257,7 +11203,7 @@ BUILDIN(resetlvl) *------------------------------------------*/ BUILDIN(resetstatus) { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; pc->resetstate(sd); @@ -11269,7 +11215,7 @@ BUILDIN(resetstatus) *------------------------------------------*/ BUILDIN(resetskill) { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; pc->resetskill(sd, PCRESETSKILL_RESYNC); @@ -11281,7 +11227,7 @@ BUILDIN(resetskill) *------------------------------------------*/ BUILDIN(skillpointcount) { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; script_pushint(st,sd->status.skill_point + pc->resetskill(sd, PCRESETSKILL_RECOUNT)); @@ -11291,8 +11237,9 @@ BUILDIN(skillpointcount) /*========================================== * *------------------------------------------*/ -BUILDIN(changebase) { - TBL_PC *sd=NULL; +BUILDIN(changebase) +{ + struct map_session_data *sd = NULL; int vclass; if (script_hasdata(st,3)) @@ -11318,10 +11265,10 @@ BUILDIN(changebase) { return true; } -static TBL_PC *prepareChangeSex(struct script_state* st) +static struct map_session_data *prepareChangeSex(struct script_state *st) { int i; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return NULL; @@ -11338,7 +11285,7 @@ static TBL_PC *prepareChangeSex(struct script_state* st) *------------------------------------------*/ BUILDIN(changesex) { - TBL_PC *sd = prepareChangeSex(st); + struct map_session_data *sd = prepareChangeSex(st); if (sd == NULL) return true; chrif->changesex(sd, true); @@ -11350,7 +11297,7 @@ BUILDIN(changesex) *------------------------------------------*/ BUILDIN(changecharsex) { - TBL_PC *sd = prepareChangeSex(st); + struct map_session_data *sd = prepareChangeSex(st); if (sd == NULL) return true; chrif->changesex(sd, false); @@ -11360,9 +11307,8 @@ BUILDIN(changecharsex) /*========================================== * Works like 'announce' but outputs in the common chat window *------------------------------------------*/ -BUILDIN(globalmes) { - struct block_list *bl = map->id2bl(st->oid); - struct npc_data *nd = (struct npc_data *)bl; +BUILDIN(globalmes) +{ const char *name=NULL,*mes; mes=script_getstr(st,2); @@ -11372,7 +11318,9 @@ BUILDIN(globalmes) { // npc name to display name=script_getstr(st,3); } else { - name=nd->name; //use current npc name + const struct npc_data *nd = map->id2nd(st->oid); + nullpo_retr(false, nd); + name = nd->name; //use current npc name } npc->globalmessage(name,mes); // broadcast to all players connected @@ -11398,7 +11346,7 @@ BUILDIN(waitingroom) int minLvl = script_hasdata(st,7) ? script_getnum(st,7) : 1; int maxLvl = script_hasdata(st,8) ? script_getnum(st,8) : MAX_LEVEL; - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); if (nd != NULL) { int pub = 1; chat->create_npc_chat(nd, title, limit, pub, trigger, ev, zeny, minLvl, maxLvl); @@ -11416,8 +11364,8 @@ BUILDIN(delwaitingroom) { if( script_hasdata(st,2) ) nd = npc->name2id(script_getstr(st, 2)); else - nd = (struct npc_data *)map->id2bl(st->oid); - if( nd != NULL ) + nd = map->id2nd(st->oid); + if (nd != NULL) chat->delete_npc_chat(nd); return true; } @@ -11433,9 +11381,9 @@ BUILDIN(waitingroomkickall) { if( script_hasdata(st,2) ) nd = npc->name2id(script_getstr(st,2)); else - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); - if( nd != NULL && (cd=(struct chat_data *)map->id2bl(nd->chat_id)) != NULL ) + if (nd != NULL && (cd=map->id2cd(nd->chat_id)) != NULL) chat->npc_kick_all(cd); return true; } @@ -11451,9 +11399,9 @@ BUILDIN(enablewaitingroomevent) { if( script_hasdata(st,2) ) nd = npc->name2id(script_getstr(st, 2)); else - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); - if( nd != NULL && (cd=(struct chat_data *)map->id2bl(nd->chat_id)) != NULL ) + if (nd != NULL && (cd=map->id2cd(nd->chat_id)) != NULL) chat->enable_event(cd); return true; } @@ -11469,9 +11417,9 @@ BUILDIN(disablewaitingroomevent) { if( script_hasdata(st,2) ) nd = npc->name2id(script_getstr(st, 2)); else - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); - if( nd != NULL && (cd=(struct chat_data *)map->id2bl(nd->chat_id)) != NULL ) + if (nd != NULL && (cd=map->id2cd(nd->chat_id)) != NULL) chat->disable_event(cd); return true; } @@ -11494,9 +11442,10 @@ BUILDIN(disablewaitingroomevent) { /// /// getwaitingroomstate(<type>,"<npc_name>") -> <info> /// getwaitingroomstate(<type>) -> <info> -BUILDIN(getwaitingroomstate) { - struct npc_data *nd; - struct chat_data *cd; +BUILDIN(getwaitingroomstate) +{ + const struct npc_data *nd; + const struct chat_data *cd; int type; int i; @@ -11504,9 +11453,9 @@ BUILDIN(getwaitingroomstate) { if( script_hasdata(st,3) ) nd = npc->name2id(script_getstr(st, 3)); else - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); - if( nd == NULL || (cd=(struct chat_data *)map->id2bl(nd->chat_id)) == NULL ) { + if (nd == NULL || (cd=map->id2cd(nd->chat_id)) == NULL) { script_pushint(st, -1); return true; } @@ -11555,8 +11504,8 @@ BUILDIN(warpwaitingpc) struct npc_data* nd; struct chat_data* cd; - nd = (struct npc_data *)map->id2bl(st->oid); - if( nd == NULL || (cd=(struct chat_data *)map->id2bl(nd->chat_id)) == NULL ) + nd = map->id2nd(st->oid); + if (nd == NULL || (cd=map->id2cd(nd->chat_id)) == NULL) return true; map_name = script_getstr(st,2); @@ -11568,7 +11517,7 @@ BUILDIN(warpwaitingpc) n = script_getnum(st,5); for (i = 0; i < n && cd->users > 0; i++) { - TBL_PC* sd = cd->usersd[0]; + struct map_session_data *sd = cd->usersd[0]; if (strcmp(map_name,"SavePoint") == 0 && map->list[sd->bl.m].flag.noteleport) { // can't teleport on this map @@ -11638,10 +11587,11 @@ BUILDIN(detachrid) /*========================================== * Chk if account connected, (and charid from account if specified) *------------------------------------------*/ -BUILDIN(isloggedin) { - TBL_PC* sd = map->id2sd(script_getnum(st,2)); - if (script_hasdata(st,3) && sd && - sd->status.char_id != script_getnum(st,3)) +BUILDIN(isloggedin) +{ + struct map_session_data *sd = map->id2sd(script_getnum(st,2)); + if (script_hasdata(st,3) && sd != NULL + && sd->status.char_id != script_getnum(st,3)) sd = NULL; script->push_val(st->stack,C_INT,sd!=NULL,NULL); return true; @@ -11741,8 +11691,14 @@ BUILDIN(getmapflag) return true; } /* pvp timer handling */ -int script_mapflag_pvp_sub(struct block_list *bl,va_list ap) { - TBL_PC* sd = (TBL_PC*)bl; +int script_mapflag_pvp_sub(struct block_list *bl, va_list ap) +{ + 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; @@ -11755,6 +11711,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; @@ -11945,10 +11902,11 @@ BUILDIN(removemapflag) { return true; } -BUILDIN(pvpon) { +BUILDIN(pvpon) +{ int16 m; const char *str; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; struct s_mapiterator* iter; struct block_list bl; @@ -11973,8 +11931,7 @@ BUILDIN(pvpon) { return true; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) - { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if( sd->bl.m != m || sd->pvp_timer != INVALID_TIMER ) continue; // not applicable @@ -11990,9 +11947,14 @@ BUILDIN(pvpon) { return true; } -int buildin_pvpoff_sub(struct block_list *bl,va_list ap) +int buildin_pvpoff_sub(struct block_list *bl, va_list ap) { - TBL_PC* sd = (TBL_PC*)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); @@ -12084,7 +12046,7 @@ BUILDIN(emotion) { player=script_getnum(st,3); if (player != 0) { - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; if (script_hasdata(st,4)) sd = script->nick2sd(st, script_getstr(st,4)); else @@ -12092,11 +12054,12 @@ BUILDIN(emotion) { if (sd != NULL) clif->emotion(&sd->bl,type); } else if( script_hasdata(st,4) ) { - TBL_NPC *nd = npc->name2id(script_getstr(st,4)); - if(nd) + struct npc_data *nd = npc->name2id(script_getstr(st,4)); + if (nd == NULL) clif->emotion(&nd->bl,type); - } else + } else { clif->emotion(map->id2bl(st->oid),type); + } return true; } @@ -12117,9 +12080,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); @@ -12191,13 +12158,14 @@ BUILDIN(agitcheck2) { /// Sets the guild_id of this npc. /// /// flagemblem <guild_id>; -BUILDIN(flagemblem) { - TBL_NPC* nd; +BUILDIN(flagemblem) +{ + struct npc_data *nd; int g_id = script_getnum(st,2); if(g_id < 0) return true; - nd = (TBL_NPC*)map->id2nd(st->oid); + nd = map->id2nd(st->oid); if( nd == NULL ) { ShowError("script:flagemblem: npc %d not found\n", st->oid); } else if( nd->subtype != SCRIPT ) { @@ -12310,7 +12278,7 @@ BUILDIN(requestguildinfo) BUILDIN(getequipcardcnt) { int i=-1,j,num; - TBL_PC *sd; + struct map_session_data *sd; int count; num=script_getnum(st,2); @@ -12349,7 +12317,7 @@ BUILDIN(successremovecards) { int i=-1,c,cardflag=0; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); int num = script_getnum(st,2); if (sd == NULL) @@ -12420,7 +12388,7 @@ BUILDIN(failedremovecards) { int i=-1,c,cardflag=0; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); int num = script_getnum(st,2); int typefail = script_getnum(st,3); @@ -12550,9 +12518,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; @@ -12594,8 +12568,8 @@ BUILDIN(mobcount) { BUILDIN(marriage) { const char *partner=script_getstr(st,2); - TBL_PC *sd=script->rid2sd(st); - TBL_PC *p_sd = script->nick2sd(st, partner); + struct map_session_data *sd = script->rid2sd(st); + struct map_session_data *p_sd = script->nick2sd(st, partner); if (sd == NULL || p_sd == NULL || pc->marriage(sd,p_sd) < 0) { script_pushint(st,0); @@ -12604,8 +12578,9 @@ BUILDIN(marriage) { script_pushint(st,1); return true; } -BUILDIN(wedding_effect) { - TBL_PC *sd = script->rid2sd(st); +BUILDIN(wedding_effect) +{ + struct map_session_data *sd = script->rid2sd(st); struct block_list *bl; if (sd == NULL) @@ -12617,8 +12592,8 @@ BUILDIN(wedding_effect) { } BUILDIN(divorce) { - TBL_PC *sd=script->rid2sd(st); - if(sd==NULL || pc->divorce(sd) < 0) { + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || pc->divorce(sd) < 0) { script_pushint(st,0); return true; } @@ -12627,7 +12602,7 @@ BUILDIN(divorce) } BUILDIN(ispartneron) { - TBL_PC *sd=script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd==NULL || !pc->ismarried(sd) || map->charid2sd(sd->status.partner_id) == NULL) { @@ -12641,7 +12616,7 @@ BUILDIN(ispartneron) { BUILDIN(getpartnerid) { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -12651,7 +12626,7 @@ BUILDIN(getpartnerid) BUILDIN(getchildid) { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -12661,7 +12636,7 @@ BUILDIN(getchildid) BUILDIN(getmotherid) { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -12670,8 +12645,8 @@ BUILDIN(getmotherid) } BUILDIN(getfatherid) { - TBL_PC *sd=script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; script_pushint(st,sd->status.father); @@ -12683,8 +12658,8 @@ BUILDIN(warppartner) int x,y; unsigned short map_index; const char *str; - TBL_PC *sd=script->rid2sd(st); - TBL_PC *p_sd=NULL; + struct map_session_data *sd = script->rid2sd(st); + struct map_session_data *p_sd = NULL; if (sd == NULL || !pc->ismarried(sd) || (p_sd = script->charid2sd(st, sd->status.partner_id)) == NULL) { @@ -12992,7 +12967,7 @@ BUILDIN(setiteminfo) BUILDIN(getequipcardid) { int i=-1,num,slot; - TBL_PC *sd; + struct map_session_data *sd; num=script_getnum(st,2); slot=script_getnum(st,3); @@ -13018,9 +12993,9 @@ BUILDIN(petskillbonus) { struct pet_data *pd; - TBL_PC *sd=script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); - if(sd==NULL || sd->pd==NULL) + if (sd == NULL || sd->pd == NULL) return true; pd=sd->pd; @@ -13055,9 +13030,9 @@ BUILDIN(petloot) { int max; struct pet_data *pd; - TBL_PC *sd=script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); - if(sd==NULL || sd->pd==NULL) + if (sd == NULL || sd->pd == NULL) return true; max=script_getnum(st,2); @@ -13091,8 +13066,9 @@ BUILDIN(petloot) * @inventorylist_card(0..3), @inventorylist_expire * @inventorylist_count = scalar *------------------------------------------*/ -BUILDIN(getinventorylist){ - TBL_PC *sd=script->rid2sd(st); +BUILDIN(getinventorylist) +{ + struct map_session_data *sd = script->rid2sd(st); char card_var[NAME_LENGTH]; int i,j=0,k; @@ -13123,8 +13099,9 @@ BUILDIN(getinventorylist){ return true; } -BUILDIN(getcartinventorylist){ - TBL_PC *sd=script->rid2sd(st); +BUILDIN(getcartinventorylist) +{ + struct map_session_data *sd = script->rid2sd(st); char card_var[26]; int i,j=0,k; @@ -13153,9 +13130,10 @@ BUILDIN(getcartinventorylist){ BUILDIN(getskilllist) { - TBL_PC *sd=script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); int i,j=0; - if(!sd) return true; + if (sd == NULL) + return true; for(i=0;i<MAX_SKILL;i++) { if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0) { pc->setreg(sd,reference_uid(script->add_str("@skilllist_id"), j),sd->status.skill[i].id); @@ -13170,9 +13148,10 @@ BUILDIN(getskilllist) BUILDIN(clearitem) { - TBL_PC *sd=script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); int i; - if(sd==NULL) return true; + if (sd == NULL) + return true; for (i=0; i<MAX_INVENTORY; i++) { if (sd->status.inventory[i].amount) { pc->delitem(sd, i, sd->status.inventory[i].amount, 0, DELITEM_NORMAL, LOG_TYPE_SCRIPT); @@ -13187,8 +13166,9 @@ BUILDIN(clearitem) BUILDIN(disguise) { int id; - TBL_PC* sd = script->rid2sd(st); - if (sd == NULL) return true; + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) + return true; id = script_getnum(st,2); @@ -13206,8 +13186,9 @@ BUILDIN(disguise) *------------------------------------------*/ BUILDIN(undisguise) { - TBL_PC* sd = script->rid2sd(st); - if (sd == NULL) return true; + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) + return true; if (sd->disguise != -1) { pc->disguise(sd, -1); @@ -13247,8 +13228,8 @@ BUILDIN(misceffect) if (bl) clif->specialeffect(bl,type,AREA); } else { - TBL_PC *sd=script->rid2sd(st); - if(sd) + struct map_session_data *sd = script->rid2sd(st); + if (sd != NULL) clif->specialeffect(&sd->bl,type,AREA); } return true; @@ -13333,23 +13314,27 @@ BUILDIN(playbgmall) { *------------------------------------------*/ BUILDIN(soundeffect) { - TBL_PC* sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); const char* name = script_getstr(st,2); int type = script_getnum(st,3); - if(sd) - { + if (sd != NULL) { clif->soundeffect(sd,&sd->bl,name,type); } 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((TBL_PC *)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; } @@ -13412,9 +13397,9 @@ BUILDIN(soundeffectall) { BUILDIN(petrecovery) { struct pet_data *pd; - TBL_PC *sd=script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); - if(sd==NULL || sd->pd==NULL) + if (sd == NULL || sd->pd == NULL) return true; pd=sd->pd; @@ -13438,9 +13423,10 @@ BUILDIN(petrecovery) *------------------------------------------*/ /// petskillattack <skill id>,<level>,<div>,<rate>,<bonusrate> /// petskillattack "<skill name>",<level>,<div>,<rate>,<bonusrate> -BUILDIN(petskillattack) { +BUILDIN(petskillattack) +{ struct pet_data *pd; - TBL_PC *sd=script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd==NULL || sd->pd==NULL) return true; @@ -13463,11 +13449,12 @@ BUILDIN(petskillattack) { *------------------------------------------*/ /// petskillsupport <skill id>,<level>,<delay>,<hp>,<sp> /// petskillsupport "<skill name>",<level>,<delay>,<hp>,<sp> -BUILDIN(petskillsupport) { +BUILDIN(petskillsupport) +{ struct pet_data *pd; - TBL_PC *sd=script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); - if(sd==NULL || sd->pd==NULL) + if (sd == NULL || sd->pd == NULL) return true; pd=sd->pd; @@ -13501,8 +13488,9 @@ BUILDIN(petskillsupport) { *------------------------------------------*/ /// skilleffect <skill id>,<level> /// skilleffect "<skill name>",<level> -BUILDIN(skilleffect) { - TBL_PC *sd; +BUILDIN(skilleffect) +{ + struct map_session_data *sd; uint16 skill_id=( script_isstringtype(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); uint16 skill_lv=script_getnum(st,3); @@ -13553,17 +13541,14 @@ BUILDIN(specialeffect) { if(bl==NULL) return true; - if( script_hasdata(st,4) ) - { - TBL_NPC *nd = npc->name2id(script_getstr(st,4)); - if(nd) + if (script_hasdata(st,4)) { + struct npc_data *nd = npc->name2id(script_getstr(st,4)); + if (nd != NULL) clif->specialeffect(&nd->bl, type, target); - } - else - { + } else { if (target == SELF) { - TBL_PC *sd=script->rid2sd(st); - if (sd) + struct map_session_data *sd = script->rid2sd(st); + if (sd != NULL) clif->specialeffect_single(bl,type,sd->fd); } else { clif->specialeffect(bl, type, target); @@ -13574,7 +13559,7 @@ BUILDIN(specialeffect) { } BUILDIN(specialeffect2) { - TBL_PC *sd; + struct map_session_data *sd; int type = script_getnum(st,2); enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA; @@ -13594,10 +13579,10 @@ BUILDIN(specialeffect2) { *------------------------------------------*/ BUILDIN(nude) { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); int i, calcflag = 0; - if( sd == NULL ) + if (sd == NULL) return true; for( i = 0 ; i < EQI_MAX; i++ ) { @@ -13617,8 +13602,9 @@ BUILDIN(nude) /*========================================== * gmcommand [MouseJstr] *------------------------------------------*/ -BUILDIN(atcommand) { - TBL_PC *sd, *dummy_sd = NULL; +BUILDIN(atcommand) +{ + struct map_session_data *sd, *dummy_sd = NULL; int fd; const char* cmd; bool ret = true; @@ -13638,7 +13624,7 @@ BUILDIN(atcommand) { struct block_list* bl = map->id2bl(st->oid); memcpy(&sd->bl, bl, sizeof(struct block_list)); if (bl->type == BL_NPC) - safestrncpy(sd->status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); + safestrncpy(sd->status.name, BL_UCAST(BL_NPC, bl)->name, NAME_LENGTH); } } @@ -13660,7 +13646,7 @@ BUILDIN(atcommand) { */ BUILDIN(dispbottom) { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); const char *message = script_getstr(st,2); if (sd == NULL) @@ -13682,12 +13668,11 @@ BUILDIN(dispbottom) *------------------------------------------*/ BUILDIN(recovery) { - TBL_PC* sd; + struct map_session_data *sd; struct s_mapiterator* iter; iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) - { + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if(pc_isdead(sd)) status->revive(&sd->bl, 100, 100); else @@ -13704,11 +13689,11 @@ BUILDIN(recovery) *------------------------------------------*/ BUILDIN(getpetinfo) { - TBL_PC *sd=script->rid2sd(st); - TBL_PET *pd; + struct map_session_data *sd = script->rid2sd(st); + struct pet_data *pd; int type=script_getnum(st,2); - if(!sd || !sd->pd) { + if (sd == NULL || sd->pd == NULL) { if (type == 2) script_pushconststr(st,"null"); else @@ -13738,10 +13723,10 @@ BUILDIN(getpetinfo) *------------------------------------------*/ BUILDIN(gethominfo) { - TBL_PC *sd=script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); int type = script_getnum(st,2); - if(!sd || !sd->hd) { + if (sd == NULL || sd->hd == NULL) { if (type == 2) script_pushconststr(st,"null"); else @@ -13820,7 +13805,7 @@ BUILDIN(getmercinfo) BUILDIN(checkequipedcard) { int n,i,c=0; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -13866,8 +13851,9 @@ BUILDIN(__jump_zero) /*========================================== * movenpc [MouseJstr] *------------------------------------------*/ -BUILDIN(movenpc) { - TBL_NPC *nd = NULL; +BUILDIN(movenpc) +{ + struct npc_data *nd = NULL; const char *npc_name; int x,y; @@ -13890,7 +13876,7 @@ BUILDIN(movenpc) { BUILDIN(message) { const char *message; - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; if (script_isstringtype(st,2)) sd = script->nick2sd(st, script_getstr(st,2)); @@ -13917,12 +13903,11 @@ BUILDIN(npctalk) if (script_hasdata(st, 3)) { nd = npc->name2id(script_getstr(st, 3)); - } - else { - nd = (struct npc_data *)map->id2bl(st->oid); + } else { + nd = map->id2nd(st->oid); } - if (nd) { + if (nd != NULL) { char name[NAME_LENGTH], message[256]; safestrncpy(name, nd->name, sizeof(name)); strtok(name, "#"); // discard extra name identifier if present @@ -13939,9 +13924,9 @@ BUILDIN(npcspeed) { int speed; speed = script_getnum(st,2); - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); - if( nd ) { + if (nd != NULL) { unit->bl2ud2(&nd->bl); // ensure nd->ud is safe to edit nd->speed = speed; nd->ud->state.speed_changed = 1; @@ -13950,14 +13935,15 @@ BUILDIN(npcspeed) { return true; } // make an npc walk to a position [Valaris] -BUILDIN(npcwalkto) { - struct npc_data *nd=(struct npc_data *)map->id2bl(st->oid); +BUILDIN(npcwalkto) +{ + struct npc_data *nd = map->id2nd(st->oid); int x=0,y=0; x=script_getnum(st,2); y=script_getnum(st,3); - if( nd ) { + if (nd != NULL) { unit->bl2ud2(&nd->bl); // ensure nd->ud is safe to edit if (!nd->status.hp) { status_calc_npc(nd, SCO_FIRST); @@ -13970,10 +13956,11 @@ BUILDIN(npcwalkto) { return true; } // stop an npc's movement [Valaris] -BUILDIN(npcstop) { - struct npc_data *nd = (struct npc_data *)map->id2bl(st->oid); +BUILDIN(npcstop) +{ + struct npc_data *nd = map->id2nd(st->oid); - if( nd ) { + if (nd != NULL) { unit->bl2ud2(&nd->bl); // ensure nd->ud is safe to edit unit->stop_walking(&nd->bl, STOPWALKING_FLAG_FIXPOS|STOPWALKING_FLAG_NEXTCELL); } @@ -13982,9 +13969,10 @@ BUILDIN(npcstop) { } // set click npc distance [4144] -BUILDIN(setnpcdistance) { - struct npc_data *nd = (struct npc_data *) map->id2bl (st->oid); - if (!nd) +BUILDIN(setnpcdistance) +{ + struct npc_data *nd = map->id2nd(st->oid); + if (nd == NULL) return false; nd->area_size = script_getnum(st, 2); @@ -13995,23 +13983,20 @@ BUILDIN(setnpcdistance) { // return current npc direction [4144] BUILDIN(getnpcdir) { - struct npc_data *nd = 0; + const struct npc_data *nd = NULL; - if (script_hasdata(st, 2)) - { - nd = npc->name2id (script_getstr(st, 2)); + if (script_hasdata(st, 2)) { + nd = npc->name2id(script_getstr(st, 2)); } - if (!nd && !st->oid) - { + if (nd == NULL && !st->oid) { script_pushint(st, -1); return true; } - if (!nd) - nd = (struct npc_data *) map->id2bl (st->oid); + if (nd == NULL) + nd = map->id2nd(st->oid); - if (!nd) - { + if (nd == NULL) { script_pushint(st, -1); return true; } @@ -14025,22 +14010,19 @@ BUILDIN(getnpcdir) BUILDIN(setnpcdir) { int newdir; - struct npc_data *nd = 0; + struct npc_data *nd = NULL; - if (script_hasdata(st, 3)) - { - nd = npc->name2id (script_getstr(st, 2)); + if (script_hasdata(st, 3)) { + nd = npc->name2id(script_getstr(st, 2)); newdir = script_getnum(st, 3); - } - else if (script_hasdata(st, 2)) - { + } else if (script_hasdata(st, 2)) { if (!st->oid) return false; - nd = (struct npc_data *) map->id2bl (st->oid); + nd = map->id2nd(st->oid); newdir = script_getnum(st, 2); } - if (!nd) + if (nd == NULL) return false; if (newdir < 0) @@ -14061,23 +14043,20 @@ BUILDIN(setnpcdir) // return npc class [4144] BUILDIN(getnpcclass) { - struct npc_data *nd = 0; + const struct npc_data *nd = NULL; - if (script_hasdata(st, 2)) - { - nd = npc->name2id (script_getstr(st, 2)); + if (script_hasdata(st, 2)) { + nd = npc->name2id(script_getstr(st, 2)); } - if (!nd && !st->oid) - { + if (nd == NULL && !st->oid) { script_pushint(st, -1); return false; } - if (!nd) - nd = (struct npc_data *) map->id2bl(st->oid); + if (nd == NULL) + nd = map->id2nd(st->oid); - if (!nd) - { + if (nd == NULL) { script_pushint(st, -1); return false; } @@ -14093,7 +14072,7 @@ BUILDIN(getnpcclass) BUILDIN(getlook) { int type,val = -1; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -14122,7 +14101,7 @@ BUILDIN(getlook) BUILDIN(getsavepoint) { int type; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -14165,7 +14144,7 @@ BUILDIN(getsavepoint) BUILDIN(getmapxy) { struct block_list *bl = NULL; - TBL_PC *sd=NULL; + struct map_session_data *sd = NULL; int64 num; const char *name; @@ -14364,7 +14343,7 @@ BUILDIN(getmapxy) BUILDIN(logmes) { const char *str; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -14378,12 +14357,11 @@ BUILDIN(summon) { int class_, timeout=0; const char *str,*event=""; - TBL_PC *sd; struct mob_data *md; int64 tick = timer->gettick(); - - sd=script->rid2sd(st); - if (!sd) return true; + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) + return true; str = script_getstr(st,2); class_ = script_getnum(st,3); @@ -14426,7 +14404,7 @@ BUILDIN(isequippedcnt) { int i, j, k, id = 1; int ret = 0; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -14478,7 +14456,7 @@ BUILDIN(isequipped) int ret = -1; //Original hash to reverse it when full check fails. unsigned int setitem_hash = 0, setitem_hash2 = 0; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -14556,7 +14534,7 @@ BUILDIN(cardscnt) int i, k, id = 1; int ret = 0; int index; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -14595,7 +14573,7 @@ BUILDIN(cardscnt) *-------------------------------------------------------*/ BUILDIN(getrefine) { - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -14622,7 +14600,7 @@ BUILDIN(day) { BUILDIN(unequip) { size_t num; - TBL_PC *sd; + struct map_session_data *sd; num = script_getnum(st,2); sd = script->rid2sd(st); @@ -14637,11 +14615,9 @@ BUILDIN(unequip) BUILDIN(equip) { int nameid=0,i; - TBL_PC *sd; struct item_data *item_data; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return false; nameid=script_getnum(st,2); @@ -14688,7 +14664,7 @@ BUILDIN(equip2) { int i,nameid,ref,attr,c0,c1,c2,c3; struct item_data *item_data; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) { script_pushint(st,0); @@ -14982,7 +14958,7 @@ BUILDIN(explode) char *temp = NULL; const char *name; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; if (!data_isreference(data)) { ShowError("script:explode: not a variable\n"); @@ -15041,7 +15017,7 @@ BUILDIN(implode) const char *name; uint32 array_size, id; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; char *output; @@ -15810,7 +15786,7 @@ BUILDIN(swap) BUILDIN(setd) { - TBL_PC *sd=NULL; + struct map_session_data *sd = NULL; char varname[100]; const char *buffer; int elem; @@ -15841,7 +15817,7 @@ BUILDIN(setd) int buildin_query_sql_sub(struct script_state* st, Sql* handle) { int i, j; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; const char* query; struct script_data* data; const char* name; @@ -15968,11 +15944,10 @@ BUILDIN(getd) { // Pet stat [Lance] BUILDIN(petstat) { - TBL_PC *sd = NULL; struct pet_data *pd; int flag = script_getnum(st,2); - sd = script->rid2sd(st); - if(!sd || !sd->status.pet_id || !sd->pd) { + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL || sd->status.pet_id == 0 || sd->pd == NULL) { if(flag == 2) script_pushconststr(st, ""); else @@ -15998,7 +15973,7 @@ BUILDIN(callshop) struct npc_data *nd; const char *shopname; int flag = 0; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -16142,7 +16117,7 @@ BUILDIN(npcshopattach) { } if (flag) - nd->master_nd = ((struct npc_data *)map->id2bl(st->oid)); + nd->master_nd = map->id2nd(st->oid); else nd->master_nd = NULL; @@ -16353,7 +16328,7 @@ BUILDIN(getmonsterinfo) BUILDIN(checkvending) // check vending [Nab4] { - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; if (script_hasdata(st,2)) sd = script->nick2sd(st, script_getstr(st,2)); @@ -16370,7 +16345,7 @@ BUILDIN(checkvending) // check vending [Nab4] // check chatting [Marka] BUILDIN(checkchatting) { - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; if (script_hasdata(st,2)) sd = script->nick2sd(st, script_getstr(st,2)); @@ -16386,7 +16361,7 @@ BUILDIN(checkchatting) { } BUILDIN(checkidle) { - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; if (script_hasdata(st, 2)) sd = script->nick2sd(st, script_getstr(st, 2)); @@ -16412,11 +16387,11 @@ BUILDIN(searchitem) int32 start; int32 id; int32 i; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; - if ((items[0] = itemdb->exists(atoi(itemname)))) + if ((items[0] = itemdb->exists(atoi(itemname)))) { count = 1; - else { + } else { count = itemdb->search_name_array(items, ARRAYLENGTH(items), itemname, 0); if (count > MAX_SEARCH) count = MAX_SEARCH; } @@ -16464,17 +16439,18 @@ BUILDIN(searchitem) } // [zBuffer] List of player cont commands ---> -BUILDIN(rid2name) { +BUILDIN(rid2name) +{ struct block_list *bl = NULL; int rid = script_getnum(st,2); if((bl = map->id2bl(rid))) { switch(bl->type) { - case BL_MOB: script_pushstrcopy(st,((TBL_MOB*)bl)->name); break; - case BL_PC: script_pushstrcopy(st,((TBL_PC*)bl)->status.name); break; - case BL_NPC: script_pushstrcopy(st,((TBL_NPC*)bl)->exname); break; - case BL_PET: script_pushstrcopy(st,((TBL_PET*)bl)->pet.name); break; - case BL_HOM: script_pushstrcopy(st,((TBL_HOM*)bl)->homunculus.name); break; - case BL_MER: script_pushstrcopy(st,((TBL_MER*)bl)->db->name); break; + case BL_MOB: script_pushstrcopy(st, BL_UCCAST(BL_MOB, bl)->name); break; + case BL_PC: script_pushstrcopy(st, BL_UCCAST(BL_PC, bl)->status.name); break; + case BL_NPC: script_pushstrcopy(st, BL_UCCAST(BL_NPC, bl)->exname); break; + case BL_PET: script_pushstrcopy(st, BL_UCCAST(BL_PET, bl)->pet.name); break; + case BL_HOM: script_pushstrcopy(st, BL_UCCAST(BL_HOM, bl)->homunculus.name); break; + case BL_MER: script_pushstrcopy(st, BL_UCCAST(BL_MER, bl)->db->name); break; default: ShowError("buildin_rid2name: BL type unknown.\n"); script_pushconststr(st,""); @@ -16489,7 +16465,7 @@ BUILDIN(rid2name) { BUILDIN(pcblockmove) { int id, flag; - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; id = script_getnum(st,2); flag = script_getnum(st,3); @@ -16505,9 +16481,10 @@ BUILDIN(pcblockmove) { return true; } -BUILDIN(pcfollow) { +BUILDIN(pcfollow) +{ int id, targetid; - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; id = script_getnum(st,2); targetid = script_getnum(st,3); @@ -16526,7 +16503,7 @@ BUILDIN(pcfollow) { BUILDIN(pcstopfollow) { int id; - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; id = script_getnum(st,2); @@ -16586,7 +16563,7 @@ BUILDIN(unitwalk) { } if( bl->type == BL_NPC ) { - unit->bl2ud2(bl); // ensure the ((TBL_NPC*)bl)->ud is safe to edit + unit->bl2ud2(bl); // ensure the ((struct npc_data*)bl)->ud is safe to edit } if( script_hasdata(st,4) ) { int x = script_getnum(st,3); @@ -16640,7 +16617,7 @@ BUILDIN(unitwarp) { mapid = map->mapname2mapid(mapname); if( mapid >= 0 && bl != NULL ) { - unit->bl2ud2(bl); // ensure ((TBL_NPC*)bl)->ud is safe to edit + unit->bl2ud2(bl); // ensure ((struct npc_data *)bl)->ud is safe to edit script_pushint(st, unit->warp(bl,mapid,x,y,CLR_OUTSIGHT)); } else { script_pushint(st, 0); @@ -16669,7 +16646,7 @@ BUILDIN(unitattack) { } if (script_isstringtype(st, 3)) { - TBL_PC* sd = script->nick2sd(st, script_getstr(st, 3)); + struct map_session_data *sd = script->nick2sd(st, script_getstr(st, 3)); if (sd != NULL) target_bl = &sd->bl; } else { @@ -16689,14 +16666,14 @@ BUILDIN(unitattack) { switch( unit_bl->type ) { case BL_PC: - clif->pActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, timer->gettick()); + clif->pActionRequest_sub(BL_UCAST(BL_PC, unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, timer->gettick()); script_pushint(st, 1); return true; case BL_MOB: - ((TBL_MOB *)unit_bl)->target_id = target_bl->id; + BL_UCAST(BL_MOB, unit_bl)->target_id = target_bl->id; break; case BL_PET: - ((TBL_PET *)unit_bl)->target_id = target_bl->id; + BL_UCAST(BL_PET, unit_bl)->target_id = target_bl->id; break; default: ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type); @@ -16718,11 +16695,11 @@ BUILDIN(unitstop) { bl = map->id2bl(unit_id); if( bl != NULL ) { - unit->bl2ud2(bl); // ensure ((TBL_NPC*)bl)->ud is safe to edit + unit->bl2ud2(bl); // ensure ((struct npc_data *)bl)->ud is safe to edit unit->stop_attack(bl); unit->stop_walking(bl, STOPWALKING_FLAG_NEXTCELL); if( bl->type == BL_MOB ) - ((TBL_MOB*)bl)->target_id = 0; + BL_UCAST(BL_MOB, bl)->target_id = 0; } return true; @@ -16788,12 +16765,13 @@ BUILDIN(unitskilluseid) { bl = map->id2bl(unit_id); - if( bl != NULL ) { - if( bl->type == BL_NPC ) { - if (!((TBL_NPC*)bl)->status.hp) { - status_calc_npc(((TBL_NPC*)bl), SCO_FIRST); + if (bl != NULL) { + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->status.hp == 0) { + status_calc_npc(nd, SCO_FIRST); } else { - status_calc_npc(((TBL_NPC*)bl), SCO_NONE); + status_calc_npc(nd, SCO_NONE); } } unit->skilluse_id(bl, target_id, skill_id, skill_lv); @@ -16822,12 +16800,13 @@ BUILDIN(unitskillusepos) { bl = map->id2bl(unit_id); - if( bl != NULL ) { - if( bl->type == BL_NPC ) { - if (!((TBL_NPC*)bl)->status.hp) { - status_calc_npc(((TBL_NPC*)bl), SCO_FIRST); + if (bl != NULL) { + if (bl->type == BL_NPC) { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (nd->status.hp == 0) { + status_calc_npc(nd, SCO_FIRST); } else { - status_calc_npc(((TBL_NPC*)bl), SCO_NONE); + status_calc_npc(nd, SCO_NONE); } } unit->skilluse_pos(bl, skill_x, skill_y, skill_id, skill_lv); @@ -16908,7 +16887,7 @@ BUILDIN(awake) { for( tst = dbi_first(iter); dbi_exists(iter); tst = dbi_next(iter) ) { if( tst->oid == nd->bl.id ) { - TBL_PC* sd = map->id2sd(tst->rid); + struct map_session_data *sd = map->id2sd(tst->rid); if( tst->sleep.timer == INVALID_TIMER ) {// already awake ??? continue; @@ -17023,10 +17002,8 @@ BUILDIN(warpportal) { BUILDIN(openmail) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; mail->openmail(sd); @@ -17036,10 +17013,8 @@ BUILDIN(openmail) BUILDIN(openauction) { - TBL_PC* sd; - - sd = script->rid2sd(st); - if( sd == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; clif->auction_openwindow(sd); @@ -17478,8 +17453,9 @@ BUILDIN(questprogress) return true; } -BUILDIN(showevent) { - TBL_PC *sd = script->rid2sd(st); +BUILDIN(showevent) +{ + struct map_session_data *sd = script->rid2sd(st); struct npc_data *nd = map->id2nd(st->oid); int icon, color = 0; @@ -17522,9 +17498,9 @@ BUILDIN(waitingroom2bg) { if( script_hasdata(st,7) ) nd = npc->name2id(script_getstr(st,7)); else - nd = (struct npc_data *)map->id2bl(st->oid); + nd = map->id2nd(st->oid); - if( nd == NULL || (cd = (struct chat_data *)map->id2bl(nd->chat_id)) == NULL ) { + if (nd == NULL || (cd = map->id2cd(nd->chat_id)) == NULL) { script_pushint(st,0); return true; } @@ -17583,7 +17559,7 @@ BUILDIN(waitingroom2bg_single) { y = script_getnum(st,5); nd = npc->name2id(script_getstr(st,6)); - if( nd == NULL || (cd = (struct chat_data *)map->id2bl(nd->chat_id)) == NULL || cd->users <= 0 ) + if (nd == NULL || (cd = map->id2cd(nd->chat_id)) == NULL || cd->users <= 0) return true; if( (sd = cd->usersd[0]) == NULL ) @@ -17646,15 +17622,15 @@ BUILDIN(bg_monster) return true; } -BUILDIN(bg_monster_set_team) { - struct mob_data *md; - struct block_list *mbl; +BUILDIN(bg_monster_set_team) +{ int id = script_getnum(st,2), bg_id = script_getnum(st,3); + struct block_list *mbl = map->id2bl(id); // TODO: Why does this not use map->id2md? + struct mob_data *md = BL_CAST(BL_MOB, mbl); - if( (mbl = map->id2bl(id)) == NULL || mbl->type != BL_MOB ) + if (md == NULL) return true; - md = (TBL_MOB *)mbl; md->bg_id = bg_id; mob_stop_attack(md); @@ -18036,12 +18012,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) { - struct map_session_data *sd = ((TBL_PC*)bl); + +int buildin_instance_warpall_sub(struct block_list *bl, va_list ap) +{ + 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; @@ -18211,9 +18193,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) { - TBL_MOB* md = (TBL_MOB*)bl; + struct mob_data *md = NULL; struct block_list *tbl; int mobid = va_arg(ap,int); uint16 skill_id = va_arg(ap,int); @@ -18223,6 +18205,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; @@ -18420,9 +18406,10 @@ BUILDIN(showdigit) /** * Rune Knight **/ -BUILDIN(makerune) { - TBL_PC* sd; - if( (sd = script->rid2sd(st)) == NULL ) +BUILDIN(makerune) +{ + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; clif->skill_produce_mix_list(sd,RK_RUNEMASTERY,24); sd->itemid = script_getnum(st,2); @@ -18434,8 +18421,8 @@ BUILDIN(makerune) { **/ BUILDIN(hascashmount) { - TBL_PC* sd; - if( (sd = script->rid2sd(st)) == NULL ) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; if( sd->sc.data[SC_ALL_RIDING] ) script_pushint(st,1); @@ -18453,8 +18440,8 @@ BUILDIN(hascashmount) **/ BUILDIN(setcashmount) { - TBL_PC* sd; - if ((sd = script->rid2sd(st)) == NULL) + struct map_session_data *sd = script->rid2sd(st); + if (sd == NULL) return true; if (pc_hasmount(sd)) { clif->msgtable(sd, MSG_REINS_CANT_USE_MOUNTED); @@ -18715,7 +18702,7 @@ BUILDIN(unbindatcmd) { } BUILDIN(useatcmd) { - TBL_PC *sd, *dummy_sd = NULL; + struct map_session_data *sd, *dummy_sd = NULL; int fd; const char* cmd; @@ -18734,8 +18721,8 @@ BUILDIN(useatcmd) { if( st->oid ) { struct block_list* bl = map->id2bl(st->oid); memcpy(&sd->bl, bl, sizeof(struct block_list)); - if( bl->type == BL_NPC ) - safestrncpy(sd->status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); + if (bl->type == BL_NPC) + safestrncpy(sd->status.name, BL_UCAST(BL_NPC, bl)->name, NAME_LENGTH); } } @@ -18914,7 +18901,7 @@ BUILDIN(npcskill) if (sd == NULL) return true; - nd = (struct npc_data *)map->id2bl(sd->npc_id); + nd = map->id2nd(sd->npc_id); if (stat_point > battle_config.max_third_parameter) { ShowError("npcskill: stat point exceeded maximum of %d.\n",battle_config.max_third_parameter ); @@ -19584,7 +19571,7 @@ BUILDIN(bg_join_team) { BUILDIN(countbound) { int i, type, j=0, k=0; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; @@ -19620,7 +19607,7 @@ BUILDIN(checkbound) { int i, nameid = script_getnum(st,2); int bound_type = 0; - TBL_PC *sd = script->rid2sd(st); + struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; diff --git a/src/map/script.h b/src/map/script.h index b3e16b1b4..5f71662c6 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -647,10 +647,10 @@ struct script_interface { bool (*addScript) (char *name, char *args, bool (*func)(struct script_state *st), bool isDeprecated); int (*conv_num) (struct script_state *st,struct script_data *data); const char* (*conv_str) (struct script_state *st,struct script_data *data); - TBL_PC *(*rid2sd) (struct script_state *st); - TBL_PC *(*id2sd) (struct script_state *st, int account_id); - TBL_PC *(*charid2sd) (struct script_state *st, int char_id); - TBL_PC *(*nick2sd) (struct script_state *st, const char *name); + struct map_session_data *(*rid2sd) (struct script_state *st); + struct map_session_data *(*id2sd) (struct script_state *st, int account_id); + struct map_session_data *(*charid2sd) (struct script_state *st, int char_id); + struct map_session_data *(*nick2sd) (struct script_state *st, const char *name); void (*detach_rid) (struct script_state* st); struct script_data* (*push_val)(struct script_stack* stack, enum c_op type, int64 val, struct reg_db *ref); struct script_data *(*get_val) (struct script_state* st, struct script_data* data); @@ -728,7 +728,7 @@ struct script_interface { void (*read_constdb) (void); const char* (*print_line) (StringBuf *buf, const char *p, const char *mark, int line); void (*errorwarning_sub) (StringBuf *buf, const char *src, const char *file, int start_line, const char *error_msg, const char *error_pos); - int (*set_reg) (struct script_state *st, TBL_PC *sd, int64 num, const char *name, const void *value, struct reg_db *ref); + int (*set_reg) (struct script_state *st, struct map_session_data *sd, int64 num, const char *name, const void *value, struct reg_db *ref); void (*set_reg_ref_str) (struct script_state* st, struct reg_db *n, int64 num, const char* name, const char *str); void (*set_reg_scope_str) (struct script_state* st, struct reg_db *n, int64 num, const char* name, const char *str); void (*set_reg_npc_str) (struct script_state* st, struct reg_db *n, int64 num, const char* name, const char *str); diff --git a/src/map/skill.c b/src/map/skill.c index 5462340db..8414ac638 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -260,6 +260,7 @@ int skill_get_casttype2 (uint16 index) { //Returns actual skill range taking into account attack range and AC_OWL [Skotlex] int skill_get_range2 (struct block_list *bl, uint16 skill_id, uint16 skill_lv) { int range; + struct map_session_data *sd = BL_CAST(BL_PC, bl); if( bl->type == BL_MOB && battle_config.mob_ai&0x400 ) return 9; //Mobs have a range of 9 regardless of skill used. @@ -288,8 +289,8 @@ int skill_get_range2 (struct block_list *bl, uint16 skill_id, uint16 skill_lv) { case RA_ARROWSTORM: case RA_AIMEDBOLT: case RA_WUGBITE: - if( bl->type == BL_PC ) - range += pc->checkskill((TBL_PC*)bl, AC_VULTURE); + if (sd != NULL) + range += pc->checkskill(sd, AC_VULTURE); else range += 10; //Assume level 10? break; @@ -299,14 +300,14 @@ int skill_get_range2 (struct block_list *bl, uint16 skill_id, uint16 skill_lv) { case GS_FULLBUSTER: case GS_SPREADATTACK: case GS_GROUNDDRIFT: - if (bl->type == BL_PC) - range += pc->checkskill((TBL_PC*)bl, GS_SNAKEEYE); + if (sd != NULL) + range += pc->checkskill(sd, GS_SNAKEEYE); else range += 10; //Assume level 10? break; case NJ_KIRIKAGE: - if (bl->type == BL_PC) - range = skill->get_range(NJ_SHADOWJUMP,pc->checkskill((TBL_PC*)bl,NJ_SHADOWJUMP)); + if (sd != NULL) + range = skill->get_range(NJ_SHADOWJUMP, pc->checkskill(sd, NJ_SHADOWJUMP)); break; /** * Warlock @@ -323,9 +324,9 @@ int skill_get_range2 (struct block_list *bl, uint16 skill_id, uint16 skill_lv) { case WL_TETRAVORTEX: case WL_EARTHSTRAIN: case WL_RELEASE: - if( bl->type == BL_PC ) - range += pc->checkskill((TBL_PC*)bl, WL_RADIUS); - break; + if (sd != NULL) + range += pc->checkskill(sd, WL_RADIUS); + break; /** * Ranger Bonus **/ @@ -336,8 +337,8 @@ int skill_get_range2 (struct block_list *bl, uint16 skill_id, uint16 skill_lv) { case RA_CLUSTERBOMB: case RA_FIRINGTRAP: case RA_ICEBOUNDTRAP: - if( bl->type == BL_PC ) - range += (1 + pc->checkskill((TBL_PC*)bl, RA_RESEARCHTRAP))/2; + if (sd != NULL) + range += (1 + pc->checkskill(sd, RA_RESEARCHTRAP))/2; } if( !range && bl->type != BL_PC ) @@ -383,7 +384,7 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk #endif // RENEWAL if (sd && (skill2_lv = pc->checkskill(sd, HP_MEDITATIO)) > 0) hp += hp * skill2_lv * 2 / 100; - else if( src->type == BL_HOM && (skill2_lv = homun->checkskill(((TBL_HOM*)src), HLIF_BRAIN)) > 0 ) + else if (src->type == BL_HOM && (skill2_lv = homun->checkskill(BL_UCAST(BL_HOM, src), HLIF_BRAIN)) > 0) hp += hp * skill2_lv * 2 / 100; break; } @@ -1765,8 +1766,8 @@ int skill_counter_additional_effect(struct block_list* src, struct block_list *b break; case HFLI_SBR44: // [orn] case HVAN_EXPLOSION: - if(src->type == BL_HOM){ - TBL_HOM *hd = (TBL_HOM*)src; + if (src->type == BL_HOM) { + struct homun_data *hd = BL_UCAST(BL_HOM, src); hd->homunculus.intimacy = 200; if (hd->master) clif->send_homdata(hd->master,SP_INTIMATE,hd->homunculus.intimacy/100); @@ -1957,8 +1958,7 @@ int skill_break_equip (struct block_list *bl, unsigned short where, int rate, in const enum sc_type scdef[4] = {SC_PROTECTWEAPON, SC_PROTECTARMOR, SC_PROTECTSHIELD, SC_PROTECTHELM}; struct status_change *sc = status->get_sc(bl); int i; - TBL_PC *sd; - sd = BL_CAST(BL_PC, bl); + struct map_session_data *sd = BL_CAST(BL_PC, bl); if (sc && !sc->count) sc = NULL; @@ -2074,9 +2074,9 @@ int skill_strip_equip(struct block_list *bl, unsigned short where, int rate, int - if 'flag&0x1', position update packets must not be sent. - if 'flag&0x2', skill blown ignores players' special_state.no_knockback -------------------------------------------------------------------------*/ -int skill_blown(struct block_list* src, struct block_list* target, int count, int8 dir, int flag) { +int skill_blown(struct block_list* src, struct block_list* target, int count, int8 dir, int flag) +{ int dx = 0, dy = 0; - struct skill_unit* su = NULL; nullpo_ret(src); @@ -2086,26 +2086,30 @@ int skill_blown(struct block_list* src, struct block_list* target, int count, in return 0; // Actual knockback distance is 0. switch (target->type) { - case BL_MOB: { - struct mob_data* md = BL_CAST(BL_MOB, target); - if (md->class_ == MOBID_EMPELIUM) - return 0; - if(src != target && is_boss(target)) // Bosses can't be knocked-back - return 0; - } + case BL_MOB: + { + const struct mob_data *md = BL_UCCAST(BL_MOB, target); + if (md->class_ == MOBID_EMPELIUM) + return 0; + if (src != target && is_boss(target)) // Bosses can't be knocked-back + return 0; + } break; - case BL_PC: { - struct map_session_data *sd = BL_CAST(BL_PC, target); - if( sd->sc.data[SC_BASILICA] && sd->sc.data[SC_BASILICA]->val4 == sd->bl.id && !is_boss(src)) - return 0; // Basilica caster can't be knocked-back by normal monsters. - if( !(flag&0x2) && src != target && sd->special_state.no_knockback ) - return 0; - } + case BL_PC: + { + struct map_session_data *sd = BL_UCAST(BL_PC, target); + if (sd->sc.data[SC_BASILICA] && sd->sc.data[SC_BASILICA]->val4 == sd->bl.id && !is_boss(src)) + return 0; // Basilica caster can't be knocked-back by normal monsters. + if (!(flag&0x2) && src != target && sd->special_state.no_knockback) + return 0; + } break; case BL_SKILL: - su = (struct skill_unit *)target; - if( su->group && (su->group->unit_id == UNT_ANKLESNARE || su->group->unit_id == UNT_REVERBERATION)) + { + struct skill_unit *su = BL_UCAST(BL_SKILL, target); + if (su->group && (su->group->unit_id == UNT_ANKLESNARE || su->group->unit_id == UNT_REVERBERATION)) return 0; // ankle snare cannot be knocked back + } break; } @@ -2232,8 +2236,8 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr dmg = battle->calc_attack(attack_type,src,bl,skill_id,skill_lv,flag&0xFFF); //Skotlex: Adjusted to the new system - if( src->type == BL_PET ) { // [Valaris] - struct pet_data *pd = (TBL_PET*)src; + if (src->type == BL_PET) { // [Valaris] + struct pet_data *pd = BL_UCAST(BL_PET, src); if (pd->a_skill && pd->a_skill->div_ && pd->a_skill->id == skill_id) { int element = skill->get_ele(skill_id, skill_lv); /*if (skill_id == -1) Does it ever worked? @@ -2770,12 +2774,13 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr if( sc && sc->data[SC_DEVOTION] && skill_id != PA_PRESSURE ) { struct status_change_entry *sce = sc->data[SC_DEVOTION]; struct block_list *d_bl = map->id2bl(sce->val1); + struct mercenary_data *d_md = BL_CAST(BL_MER, d_bl); + struct map_session_data *d_sd = BL_CAST(BL_PC, d_bl); - if( d_bl && ( - (d_bl->type == BL_MER && ((TBL_MER*)d_bl)->master && ((TBL_MER*)d_bl)->master->bl.id == bl->id) || - (d_bl->type == BL_PC && ((TBL_PC*)d_bl)->devotion[sce->val2] == bl->id) - ) && check_distance_bl(bl, d_bl, sce->val3) ) - { + if (d_bl != NULL + && ((d_md != NULL && d_md->master && d_md->master->bl.id == bl->id) || (d_sd != NULL && d_sd->devotion[sce->val2] == bl->id)) + && check_distance_bl(bl, d_bl, sce->val3) + ) { if(!rmdamage){ clif->damage(d_bl,d_bl, 0, 0, damage, 0, BDT_NORMAL, 0); status_fix_damage(NULL,d_bl, damage, 0); @@ -2876,8 +2881,8 @@ void skill_attack_combo2_unknown(int *attack_type, struct block_list* src, struc void skill_attack_display_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage) { if (*flag & SD_ANIMATION && dmg->div_ < 2) //Disabling skill animation doesn't works on multi-hit. *type = BDT_SPLASH; - if (bl->type == BL_SKILL ) { - TBL_SKILL *su = (TBL_SKILL*)bl; + if (bl->type == BL_SKILL) { + struct skill_unit *su = BL_UCAST(BL_SKILL, bl); if (su->group && skill->get_inf2(su->group->skill_id) & INF2_TRAP) // show damage on trap targets clif->skill_damage(src, bl, *tick, dmg->amotion, dmg->dmotion, *damage, dmg->div_, *skill_id, (*flag & SD_LEVEL) ? -1 : *skill_lv, BDT_SPLASH); } @@ -2895,7 +2900,7 @@ int skill_attack_dir_unknown(int *attack_type, struct block_list* src, struct bl void skill_attack_blow_unknown(int *attack_type, struct block_list* src, struct block_list *dsrc, struct block_list *bl, uint16 *skill_id, uint16 *skill_lv, int64 *tick, int *flag, int *type, struct Damage *dmg, int64 *damage, int8 *dir) { skill->blown(dsrc, bl, dmg->blewcount, *dir, 0x0); if (!dmg->blewcount && bl->type == BL_SKILL && *damage > 0){ - TBL_SKILL *su = (TBL_SKILL*)bl; + struct skill_unit *su = BL_UCAST(BL_SKILL, bl); if (su->group && su->group->skill_id == HT_BLASTMINE) skill->blown(src, bl, 3, -1, 0); } @@ -2938,15 +2943,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 +3040,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 && ((TBL_MOB*)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; } @@ -3092,8 +3100,8 @@ int skill_check_condition_mercenary(struct block_list *bl, int skill_id, int lv, nullpo_ret(bl); switch( bl->type ) { - case BL_HOM: sd = ((TBL_HOM*)bl)->master; break; - case BL_MER: sd = ((TBL_MER*)bl)->master; break; + case BL_HOM: sd = BL_UCAST(BL_HOM, bl)->master; break; + case BL_MER: sd = BL_UCAST(BL_MER, bl)->master; break; } st = status->get_status_data(bl); @@ -3323,9 +3331,9 @@ int skill_timerskill(int tid, int64 tick, int id, intptr_t data) { break; case LG_MOONSLASHER: case SR_WINDMILL: - if( target->type == BL_PC ) { - struct map_session_data *tsd = NULL; - if( (tsd = ((TBL_PC*)target)) && !pc_issit(tsd) ) { + if (target->type == BL_PC) { + struct map_session_data *tsd = BL_UCAST(BL_PC, target); + if (!pc_issit(tsd)) { pc_setsit(tsd); skill->sit(tsd,1); clif->sitting(&tsd->bl); @@ -3344,11 +3352,12 @@ int skill_timerskill(int tid, int64 tick, int id, intptr_t data) { case SR_FALLENEMPIRE: case SR_TIGERCANNON: case SR_SKYNETBLOW: - if( src->type == BL_PC ) { + if (src->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, src); if( distance_xy(src->x, src->y, target->x, target->y) >= 3 ) break; - skill->castend_damage_id(src, target, skl->skill_id, pc->checkskill(((TBL_PC*)src), skl->skill_id), tick, 0); + skill->castend_damage_id(src, target, skl->skill_id, pc->checkskill(sd, skl->skill_id), tick, 0); } break; case SC_ESCAPE: @@ -3359,12 +3368,14 @@ int skill_timerskill(int tid, int64 tick, int id, intptr_t data) { } break; case RK_HUNDREDSPEAR: - if(src->type == BL_PC) { - int skill_lv = pc->checkskill((TBL_PC *)src, KN_SPEARBOOMERANG); - if(skill_lv > 0) + if (src->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, src); + int skill_lv = pc->checkskill(sd, KN_SPEARBOOMERANG); + if (skill_lv > 0) skill->attack(BF_WEAPON, src, src, target, KN_SPEARBOOMERANG, skill_lv, tick, skl->flag); - } else + } else { skill->attack(BF_WEAPON, src, src, target, KN_SPEARBOOMERANG, 1, tick, skl->flag); + } break; case CH_PALMSTRIKE: { @@ -3506,11 +3517,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 = (TBL_SKILL*)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 +3537,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) { - TBL_SKILL *su = (TBL_SKILL*)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); @@ -5000,7 +5022,7 @@ int skill_castend_id(int tid, int64 tick, int id, intptr_t data) { } if (ud->skill_id >= SL_SKE && ud->skill_id <= SL_SKA && target->type == BL_MOB) { - if (((TBL_MOB*)target)->class_ == MOBID_EMPELIUM) + if (BL_UCCAST(BL_MOB, target)->class_ == MOBID_EMPELIUM) break; } else if (inf && battle->check_target(src, target, inf) <= 0) { if (sd) clif->skill_fail(sd,ud->skill_id,USESKILL_FAIL_LEVEL,0); @@ -5560,30 +5582,31 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin abra_skill_lv = min(skill_lv, skill->get_max(abra_skill_id)); clif->skill_nodamage (src, bl, skill_id, skill_lv, 1); - if( sd ) - {// player-casted + if (sd) { + // player-casted sd->state.abra_flag = 1; sd->skillitem = abra_skill_id; sd->skillitemlv = abra_skill_lv; clif->item_skill(sd, abra_skill_id, abra_skill_lv); - } - else - {// mob-casted + } else { + // mob-casted struct unit_data *ud = unit->bl2ud(src); int inf = skill->get_inf(abra_skill_id); - if (!ud) break; + if (ud == NULL) + break; if (inf&INF_SELF_SKILL || inf&INF_SUPPORT_SKILL) { - if (src->type == BL_PET) - bl = (struct block_list*)((TBL_PET*)src)->msd; - if (!bl) bl = src; - unit->skilluse_id(src, bl->id, abra_skill_id, abra_skill_lv); + int id = src->id; + struct pet_data *pd = BL_CAST(BL_PET, src); + if (pd != NULL && pd->msd != NULL) + id = pd->msd->bl.id; + unit->skilluse_id(src, id, abra_skill_id, abra_skill_lv); } else { //Assume offensive skills int target_id = 0; if (ud->target) target_id = ud->target; else switch (src->type) { - case BL_MOB: target_id = ((TBL_MOB*)src)->target_id; break; - case BL_PET: target_id = ((TBL_PET*)src)->target_id; break; + case BL_MOB: target_id = BL_UCAST(BL_MOB, src)->target_id; break; + case BL_PET: target_id = BL_UCAST(BL_PET, src)->target_id; break; } if (!target_id) break; @@ -5817,7 +5840,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin if( sd ) skill->blockpc_start(sd, skill_id, skill->get_time(skill_id, skill_lv)); else if( bl->type == BL_MER ) - skill->blockmerc_start((TBL_MER*)bl, skill_id, skill->get_time(skill_id, skill_lv)); + skill->blockmerc_start(BL_UCAST(BL_MER, bl), skill_id, skill->get_time(skill_id, skill_lv)); break; case TK_JUMPKICK: @@ -7501,10 +7524,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin break; case HT_SPRINGTRAP: clif->skill_nodamage(src,bl,skill_id,skill_lv,1); - { - struct skill_unit *su=NULL; - if (bl->type==BL_SKILL && (su=(struct skill_unit *)bl) != NULL && su->group != NULL) { - switch(su->group->unit_id){ + if (bl->type == BL_SKILL) { + struct skill_unit *su = BL_UCAST(BL_SKILL, bl); + if (su->group != NULL) { + switch (su->group->unit_id) { case UNT_ANKLESNARE: if (su->group->val2 != 0) // if it is already trapping something don't spring it, @@ -9002,8 +9025,8 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin if( flag&1 ) { if( is_boss(bl) ) break; if( sc_start2(src,bl, type, 100, skill_lv, src->id, skill->get_time(skill_id, skill_lv))) { - if( bl->type == BL_MOB ) - mob->unlocktarget((TBL_MOB*)bl,timer->gettick()); + if (bl->type == BL_MOB) + mob->unlocktarget(BL_UCAST(BL_MOB, bl), timer->gettick()); unit->stop_attack(bl); clif->bladestop(src, bl->id, 1); map->freeblock_unlock(); @@ -9251,7 +9274,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin improv_skill_lv = 4 + skill_lv; clif->skill_nodamage (src, bl, skill_id, skill_lv, 1); - if( sd ) { + if (sd == NULL) { sd->state.abra_flag = 2; sd->skillitem = improv_skill_id; sd->skillitemlv = improv_skill_lv; @@ -9259,19 +9282,23 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, uin } else { struct unit_data *ud = unit->bl2ud(src); int inf = skill->get_inf(improv_skill_id); - if (!ud) break; + if (ud == NULL) + break; if (inf&INF_SELF_SKILL || inf&INF_SUPPORT_SKILL) { - if (src->type == BL_PET) - bl = (struct block_list*)((TBL_PET*)src)->msd; - if (!bl) bl = src; - unit->skilluse_id(src, bl->id, improv_skill_id, improv_skill_lv); + int id = src->id; + struct pet_data *pd = BL_CAST(BL_PET, src); + if (pd != NULL && pd->msd != NULL) + id = pd->msd->bl.id; + unit->skilluse_id(src, id, improv_skill_id, improv_skill_lv); } else { int target_id = 0; - if (ud->target) + if (ud->target) { target_id = ud->target; - else switch (src->type) { - case BL_MOB: target_id = ((TBL_MOB*)src)->target_id; break; - case BL_PET: target_id = ((TBL_PET*)src)->target_id; break; + } else { + switch (src->type) { + case BL_MOB: target_id = BL_UCAST(BL_MOB, src)->target_id; break; + case BL_PET: target_id = BL_UCAST(BL_PET, src)->target_id; break; + } } if (!target_id) break; @@ -10049,10 +10076,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) { - TBL_NPC* nd = (TBL_NPC*)bl; - if( nd->option&(OPTION_HIDE|OPTION_INVISIBLE) || nd->class_ != 45 ) +static int check_npc_chaospanic(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) || nd->class_ != WARP_CLASS) return 0; return 1; @@ -10648,9 +10681,10 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0); } else { int mob_id = skill_lv < 2 ? MOBID_BLACK_MUSHROOM + rnd()%2 : MOBID_RED_PLANT + rnd()%6; - TBL_MOB* md = mob->once_spawn_sub(src, src->m, x, y, "--ja--", mob_id, "", SZ_SMALL, AI_NONE); + struct mob_data *md = mob->once_spawn_sub(src, src->m, x, y, "--ja--", mob_id, "", SZ_SMALL, AI_NONE); int i; - if (!md) break; + if (md == NULL) + break; if ((i = skill->get_time(skill_id, skill_lv)) > 0) { if( md->deletetimer != INVALID_TIMER ) @@ -10968,11 +11002,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)) @@ -11133,10 +11172,13 @@ struct skill_unit_group* skill_unitsetting(struct block_list *src, uint16 skill_ limit=2000; } else { // previous implementation (not used anymore) //Warp Portal morphing to active mode, extract relevant data from src. [Skotlex] - if( src->type != BL_SKILL ) return NULL; - group = ((TBL_SKILL*)src)->group; + struct skill_unit *su = BL_CAST(BL_SKILL, src); + if (su == NULL) + return NULL; + group = su->group; src = map->id2bl(group->src_id); - if( !src ) return NULL; + if (src == NULL) + return NULL; val2 = group->val2; //Copy the (x,y) position you warp to val3 = group->val3; //as well as the mapindex to warp to. } @@ -11666,11 +11708,9 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl, int64 tick case UNT_WARP_WAITING: { int working = sg->val1&0xffff; - if(bl->type==BL_PC && !working){ - struct map_session_data *sd = (struct map_session_data *)bl; - if((!sd->chatID || battle_config.chat_warpportal) - && sd->ud.to_x == src->bl.x && sd->ud.to_y == src->bl.y) - { + if (bl->type == BL_PC && !working) { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + if ((!sd->chatID || battle_config.chat_warpportal) && sd->ud.to_x == src->bl.x && sd->ud.to_y == src->bl.y) { int x = sg->val2>>16; int y = sg->val2&0xffff; int count = sg->val1>>16; @@ -11827,7 +11867,7 @@ void skill_unit_onplace_unknown(struct skill_unit *src, struct block_list *bl, i int skill_unit_onplace_timer(struct skill_unit *src, struct block_list *bl, int64 tick) { struct skill_unit_group *sg; struct block_list *ss; - TBL_PC* tsd; + struct map_session_data *tsd; struct status_data *tstatus, *bst; struct status_change *tsc, *ssc; struct skill_unit_group_tickset *ts; @@ -12416,7 +12456,7 @@ int skill_unit_onplace_timer(struct skill_unit *src, struct block_list *bl, int6 break; case UNT_DEMONIC_FIRE: { - TBL_PC* sd = BL_CAST(BL_PC, ss); + struct map_session_data *sd = BL_CAST(BL_PC, ss); switch( sg->val2 ) { case 1: case 2: @@ -12559,7 +12599,7 @@ int skill_unit_onplace_timer(struct skill_unit *src, struct block_list *bl, int6 } if (bl->type == BL_MOB && ss != bl) - mob->skill_event((TBL_MOB*)bl, ss, tick, MSC_SKILLUSED|(skill_id<<16)); + mob->skill_event(BL_UCAST(BL_MOB, bl), ss, tick, MSC_SKILLUSED|(skill_id<<16)); return skill_id; } @@ -12816,21 +12856,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] @@ -12958,15 +12998,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. @@ -15309,10 +15352,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; @@ -15326,11 +15373,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; @@ -15347,10 +15397,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) { @@ -15401,7 +15456,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; @@ -15417,9 +15473,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) @@ -15551,15 +15607,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); @@ -15567,30 +15623,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(((TBL_PC*)src), ((TBL_ITEM*)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; @@ -15630,16 +15691,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! */ @@ -15723,38 +15789,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); @@ -15807,21 +15879,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: @@ -15837,6 +15912,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; @@ -15918,8 +15994,9 @@ bool skill_can_cloak(struct map_session_data *sd) { * Verifies if an user can still be cloaked (AS_CLOAKING) * Is called via map->foreachinrange when any kind of wall disapears **/ -int skill_check_cloaking_end(struct block_list *bl, va_list ap) { - TBL_PC *sd = BL_CAST(BL_PC, bl); +int skill_check_cloaking_end(struct block_list *bl, va_list ap) +{ + struct map_session_data *sd = BL_CAST(BL_PC, bl); if (sd && sd->sc.data[SC_CLOAKING] && !skill->can_cloak(sd)) status_change_end(bl, SC_CLOAKING, INVALID_TIMER); @@ -15964,6 +16041,7 @@ bool skill_check_shadowform(struct block_list *bl, int64 damage, int hit) if (sc && sc->data[SC__SHADOWFORM] && damage) { struct block_list *src = map->id2bl(sc->data[SC__SHADOWFORM]->val2); + struct map_session_data *sd = BL_CAST(BL_PC, src); if( !src || src->m != bl->m ) { status_change_end(bl, SC__SHADOWFORM, INVALID_TIMER); @@ -15971,8 +16049,8 @@ bool skill_check_shadowform(struct block_list *bl, int64 damage, int hit) } if( src && (status->isdead(src) || !battle->check_target(bl,src,BCT_ENEMY)) ){ - if( src->type == BL_PC ) - ((TBL_PC*)src)->shadowform_id = 0; + if (sd != NULL) + sd->shadowform_id = 0; status_change_end(bl, SC__SHADOWFORM, INVALID_TIMER); return false; } @@ -15982,8 +16060,8 @@ bool skill_check_shadowform(struct block_list *bl, int64 damage, int hit) /* because damage can cancel it */ if( sc->data[SC__SHADOWFORM] && (--sc->data[SC__SHADOWFORM]->val3) <= 0 ) { status_change_end(bl, SC__SHADOWFORM, INVALID_TIMER); - if( src->type == BL_PC ) - ((TBL_PC*)src)->shadowform_id = 0; + if (sd != NULL) + sd->shadowform_id = 0; } return true; } @@ -16180,7 +16258,7 @@ struct skill_unit_group* skill_initunitgroup (struct block_list* src, int count, group->guild_id = status->get_guild_id(src); group->bg_id = bg->team_get_id(src); group->group_id = skill->get_new_group_id(); - group->unit.data = (struct skill_unit *)aCalloc(count,sizeof(struct skill_unit)); + CREATE(group->unit.data, struct skill_unit, 1); group->unit.count = count; group->alive_count = 0; group->val1 = 0; @@ -16207,24 +16285,27 @@ struct skill_unit_group* skill_initunitgroup (struct block_list* src, int count, /*========================================== * *------------------------------------------*/ -int skill_delunitgroup(struct skill_unit_group *group, const char* file, int line, const char* func) { +int skill_delunitgroup(struct skill_unit_group *group, const char *file, int line, const char *func) +{ struct block_list* src; struct unit_data *ud; int i,j; + struct map_session_data *sd = NULL; if( group == NULL ) { ShowDebug("skill_delunitgroup: group is NULL (source=%s:%d, %s)! Please report this! (#3504)\n", file, line, func); return 0; } - src=map->id2bl(group->src_id); + src = map->id2bl(group->src_id); ud = unit->bl2ud(src); - if(!src || !ud) { + sd = BL_CAST(BL_PC, src); + if (src == NULL || ud == NULL) { ShowError("skill_delunitgroup: Group's source not found! (src_id: %d skill_id: %d)\n", group->src_id, group->skill_id); return 0; } - if( src->type == BL_PC && !status->isdead(src) && ((TBL_PC*)src)->state.warping && !((TBL_PC*)src)->state.changemap ) { + if (sd != NULL && !status->isdead(src) && sd->state.warping && !sd->state.changemap) { switch( group->skill_id ) { case BA_DISSONANCE: case BA_POEMBRAGI: @@ -16236,7 +16317,7 @@ int skill_delunitgroup(struct skill_unit_group *group, const char* file, int lin case DC_DONTFORGETME: case DC_FORTUNEKISS: case DC_SERVICEFORYOU: - skill->usave_add(((TBL_PC*)src), group->skill_id, group->skill_lv); + skill->usave_add(sd, group->skill_id, group->skill_lv); break; } } @@ -16301,8 +16382,8 @@ int skill_delunitgroup(struct skill_unit_group *group, const char* file, int lin break; } - if (src->type==BL_PC && group->state.ammo_consume) - battle->consume_ammo((TBL_PC*)src, group->skill_id, group->skill_lv); + if (sd != NULL && group->state.ammo_consume) + battle->consume_ammo(sd, group->skill_id, group->skill_lv); group->alive_count=0; @@ -16646,9 +16727,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); @@ -16658,6 +16740,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 ) @@ -17607,9 +17693,10 @@ void skill_toggle_magicpower(struct block_list *bl, uint16 skill_id) { sc->data[SC_MAGICPOWER]->val4 = 1; status_calc_bl(bl, status->sc2scb_flag(SC_MAGICPOWER)); #ifndef RENEWAL - if(bl->type == BL_PC){// update current display. - clif->updatestatus(((TBL_PC *)bl),SP_MATK1); - clif->updatestatus(((TBL_PC *)bl),SP_MATK2); + if (bl->type == BL_PC) {// update current display. + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + clif->updatestatus(sd, SP_MATK1); + clif->updatestatus(sd, SP_MATK2); } #endif } @@ -17857,13 +17944,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 ) { @@ -18025,11 +18114,14 @@ int skill_blockpc_start_(struct map_session_data *sd, uint16 skill_id, int tick) return 0; } -int skill_blockhomun_end(int tid, int64 tick, int id, intptr_t data) { // [orn] - struct homun_data *hd = (TBL_HOM*)map->id2bl(id); +// [orn] +int skill_blockhomun_end(int tid, int64 tick, int id, intptr_t data) +{ + struct homun_data *hd = map->id2hd(id); if (data <= 0 || data >= MAX_SKILL) return 0; - if (hd) hd->blockskill[data] = 0; + if (hd != NULL) + hd->blockskill[data] = 0; return 1; } @@ -18049,11 +18141,14 @@ int skill_blockhomun_start(struct homun_data *hd, uint16 skill_id, int tick) { / return timer->add(timer->gettick() + tick, skill->blockhomun_end, hd->bl.id, idx); } -int skill_blockmerc_end(int tid, int64 tick, int id, intptr_t data) {// [orn] - struct mercenary_data *md = (TBL_MER*)map->id2bl(id); - if( data <= 0 || data >= MAX_SKILL ) +// [orn] +int skill_blockmerc_end(int tid, int64 tick, int id, intptr_t data) +{ + struct mercenary_data *md = map->id2mc(id); + if (data <= 0 || data >= MAX_SKILL) return 0; - if( md ) md->blockskill[data] = 0; + if (md != NULL) + md->blockskill[data] = 0; return 1; } @@ -19106,7 +19201,7 @@ void skill_reload(void) chrif->skillid2idx(0); /* lets update all players skill tree : so that if any skill modes were changed they're properly updated */ iter = mapit_getallusers(); - for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) ) + for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) clif->skillinfoblock(sd); mapit->free(iter); diff --git a/src/map/status.c b/src/map/status.c index e96b881dd..c755d8eb0 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 ) @@ -1350,9 +1350,14 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp, #ifdef DEVOTION_REFLECT_DAMAGE if (src && (sce = sc->data[SC_DEVOTION]) != NULL) { struct block_list *d_bl = map->id2bl(sce->val1); + struct mercenary_data *d_md = BL_CAST(BL_MER, d_bl); + struct map_session_data *d_sd = BL_CAST(BL_PC, d_bl); - if(d_bl &&((d_bl->type == BL_MER && ((TBL_MER *)d_bl)->master && ((TBL_MER *)d_bl)->master->bl.id == target->id) - || (d_bl->type == BL_PC && ((TBL_PC *)d_bl)->devotion[sce->val2] == target->id)) && check_distance_bl(target, d_bl, sce->val3)) { + if (d_bl != NULL + && ((d_md != NULL && d_md->master != NULL && d_md->master->bl.id == target->id) + || (d_sd != NULL && d_sd->devotion[sce->val2] == target->id)) + && check_distance_bl(target, d_bl, sce->val3) + ) { clif->damage(d_bl, d_bl, 0, 0, hp, 0, BDT_NORMAL, 0); status_fix_damage(NULL, d_bl, hp, 0); return 0; @@ -1412,14 +1417,15 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp, } switch (target->type) { - case BL_PC: pc->damage((TBL_PC*)target,src,hp,sp); break; - case BL_MOB: mob->damage((TBL_MOB*)target, src, hp); break; - case BL_HOM: homun->damaged((TBL_HOM*)target); break; - case BL_MER: mercenary->heal((TBL_MER*)target,hp,sp); break; - case BL_ELEM: elemental->heal((TBL_ELEM*)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 && target->type == BL_PC && (((TBL_PC*)target)->disguise) > 0 ) {// stop walking when attacked in disguise to prevent walk-delay bug + 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); } @@ -1437,11 +1443,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((TBL_PC*)target,src); break; - case BL_MOB: flag = mob->dead((TBL_MOB*)target, src, (flag&4) ? 3 : 0); break; - case BL_HOM: flag = homun->dead((TBL_HOM*)target); break; - case BL_MER: flag = mercenary->dead((TBL_MER*)target); break; - case BL_ELEM: flag = elemental->dead((TBL_ELEM*)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; @@ -1481,18 +1487,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 ) - ((TBL_MOB*)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] && !((TBL_MOB*) 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); - ((TBL_MOB*)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); @@ -1577,11 +1586,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((TBL_PC*)bl,hp,sp,(flag&2) ? 1 : 0); break; - case BL_MOB: mob->heal((TBL_MOB*)bl,hp); break; - case BL_HOM: homun->healed((TBL_HOM*)bl); break; - case BL_MER: mercenary->heal((TBL_MER*)bl,hp,sp); break; - case BL_ELEM: elemental->heal((TBL_ELEM*)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); @@ -1674,9 +1683,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((TBL_PC*)bl, hp, sp); break; - case BL_MOB: mob->revive((TBL_MOB*)bl, hp); break; - case BL_HOM: homun->revive((TBL_HOM*)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; } @@ -1709,9 +1718,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((TBL_PC*)bl, hp, sp); break; - case BL_MOB: mob->revive((TBL_MOB*)bl, hp); break; - case BL_HOM: homun->revive((TBL_HOM*)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; } @@ -1731,10 +1740,11 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin struct status_data *st; struct status_change *sc=NULL, *tsc; int hide_flag; + struct map_session_data *sd = BL_CAST(BL_PC, src); st = src ? status->get_status_data(src) : &status->dummy; - if (src && src->type != BL_PC && status->isdead(src)) + if (src != NULL && src->type != BL_PC && status->isdead(src)) return 0; if (!skill_id) { //Normal attack checks. @@ -1749,14 +1759,14 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin } if( skill_id ) { - - if( src && !(src->type == BL_PC && ((TBL_PC*)src)->skillitem)) { // Items that cast skills using 'itemskill' will not be handled by map_zone_db. + if (src != NULL && (sd == NULL || sd->skillitem == 0)) { + // Items that cast skills using 'itemskill' will not be handled by map_zone_db. int i; for(i = 0; i < map->list[src->m].zone->disabled_skills_count; i++) { if( skill_id == map->list[src->m].zone->disabled_skills[i]->nameid && (map->list[src->m].zone->disabled_skills[i]->type&src->type) ) { if (src->type == BL_PC) { - clif->msgtable((TBL_PC*)src, MSG_SKILL_CANT_USE_AREA); // This skill cannot be used within this area + clif->msgtable(sd, MSG_SKILL_CANT_USE_AREA); // This skill cannot be used within this area } else if (src->type == BL_MOB && map->list[src->m].zone->disabled_skills[i]->subtype != MZS_NONE) { if( st->mode&MD_BOSS ) { /* is boss */ if( !( map->list[src->m].zone->disabled_skills[i]->subtype&MZS_BOSS ) ) @@ -1786,9 +1796,10 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin break; case AL_TELEPORT: //Should fail when used on top of Land Protector [Skotlex] - if (src && map->getcell(src->m, src, src->x, src->y, CELL_CHKLANDPROTECTOR) - && !(st->mode&MD_BOSS) - && (src->type != BL_PC || ((TBL_PC*)src)->skillitem != skill_id)) + if (src != NULL + && map->getcell(src->m, src, src->x, src->y, CELL_CHKLANDPROTECTOR) + && !(st->mode&MD_BOSS) + && (src->type != BL_PC || sd->skillitem != skill_id)) return 0; break; default: @@ -1818,7 +1829,7 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin struct block_list *winkcharm_target = map->id2bl(sc->data[SC_DC_WINKCHARM]->val2); if (winkcharm_target != NULL) { if (unit->bl2ud(src) && (unit->bl2ud(src))->walktimer == INVALID_TIMER) - unit->walktobl(src, map->id2bl(sc->data[SC_DC_WINKCHARM]->val2), 3, 1); + unit->walktobl(src, winkcharm_target, 3, 1); clif->emotion(src, E_LV); return 0; } else { @@ -1838,9 +1849,9 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin } if (sc->data[SC_DANCING] && flag!=2) { - if( src->type == BL_PC && skill_id >= WA_SWING_DANCE && skill_id <= WM_UNLIMITED_HUMMING_VOICE ) - { // Lvl 5 Lesson or higher allow you use 3rd job skills while dancing.v - if( pc->checkskill((TBL_PC*)src,WM_LESSON) < 5 ) + if (src->type == BL_PC && skill_id >= WA_SWING_DANCE && skill_id <= WM_UNLIMITED_HUMMING_VOICE) { + // Lvl 5 Lesson or higher allow you use 3rd job skills while dancing.v + if (pc->checkskill(sd, WM_LESSON) < 5) return 0; } else if(sc->data[SC_LONGING]) { //Allow everything except dancing/re-dancing. [Skotlex] if (skill_id == BD_ENCORE || @@ -1862,48 +1873,45 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin return 0; //Can't amp out of Wand of Hermode :/ [Skotlex] } - if (skill_id && //Do not block item-casted skills. - (src->type != BL_PC || ((TBL_PC*)src)->skillitem != skill_id) - ) { + if (skill_id != 0 /* Do not block item-casted skills.*/ && (src->type != BL_PC || sd->skillitem != skill_id)) { //Skills blocked through status changes... - if (!flag && ( //Blocked only from using the skill (stuff like autospell may still go through - sc->data[SC_SILENCE] || - sc->data[SC_STEELBODY] || - sc->data[SC_BERSERK] || - sc->data[SC_OBLIVIONCURSE] || - sc->data[SC_WHITEIMPRISON] || - sc->data[SC__INVISIBILITY] || - (sc->data[SC_COLD] && src->type != BL_MOB) || - sc->data[SC__IGNORANCE] || - sc->data[SC_DEEP_SLEEP] || - sc->data[SC_SATURDAY_NIGHT_FEVER] || - sc->data[SC_CURSEDCIRCLE_TARGET] || - (sc->data[SC_MARIONETTE_MASTER] && skill_id != CG_MARIONETTE) || //Only skill you can use is marionette again to cancel it - (sc->data[SC_MARIONETTE] && skill_id == CG_MARIONETTE) || //Cannot use marionette if you are being buffed by another - (sc->data[SC_STASIS] && skill->block_check(src, SC_STASIS, skill_id)) || - (sc->data[SC_KG_KAGEHUMI] && skill->block_check(src, SC_KG_KAGEHUMI, skill_id)) - )) - return 0; + if (!flag && ( //Blocked only from using the skill (stuff like autospell may still go through + sc->data[SC_SILENCE] || + sc->data[SC_STEELBODY] || + sc->data[SC_BERSERK] || + sc->data[SC_OBLIVIONCURSE] || + sc->data[SC_WHITEIMPRISON] || + sc->data[SC__INVISIBILITY] || + (sc->data[SC_COLD] && src->type != BL_MOB) || + sc->data[SC__IGNORANCE] || + sc->data[SC_DEEP_SLEEP] || + sc->data[SC_SATURDAY_NIGHT_FEVER] || + sc->data[SC_CURSEDCIRCLE_TARGET] || + (sc->data[SC_MARIONETTE_MASTER] && skill_id != CG_MARIONETTE) || //Only skill you can use is marionette again to cancel it + (sc->data[SC_MARIONETTE] && skill_id == CG_MARIONETTE) || //Cannot use marionette if you are being buffed by another + (sc->data[SC_STASIS] && skill->block_check(src, SC_STASIS, skill_id)) || + (sc->data[SC_KG_KAGEHUMI] && skill->block_check(src, SC_KG_KAGEHUMI, skill_id)) + )) + return 0; - //Skill blocking. - if ( - (sc->data[SC_VOLCANO] && skill_id == WZ_ICEWALL) || - (sc->data[SC_ROKISWEIL] && skill_id != BD_ADAPTATION) || - (sc->data[SC_HERMODE] && skill->get_inf(skill_id) & INF_SUPPORT_SKILL) || - pc_ismuted(sc, MANNER_NOSKILL) - ) - return 0; + //Skill blocking. + if ( + (sc->data[SC_VOLCANO] && skill_id == WZ_ICEWALL) || + (sc->data[SC_ROKISWEIL] && skill_id != BD_ADAPTATION) || + (sc->data[SC_HERMODE] && skill->get_inf(skill_id) & INF_SUPPORT_SKILL) || + pc_ismuted(sc, MANNER_NOSKILL) + ) + return 0; - if( sc->data[SC__MANHOLE] || ((tsc = status->get_sc(target)) && tsc->data[SC__MANHOLE]) ) { - switch(skill_id) {//##TODO## make this a flag in skill_db? - // Skills that can be used even under Man Hole effects. - case SC_SHADOWFORM: - break; - default: - return 0; - } + if( sc->data[SC__MANHOLE] || ((tsc = status->get_sc(target)) && tsc->data[SC__MANHOLE]) ) { + switch(skill_id) {//##TODO## make this a flag in skill_db? + // Skills that can be used even under Man Hole effects. + case SC_SHADOWFORM: + break; + default: + return 0; } - + } } } @@ -1963,23 +1971,26 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin hide_flag &= ~OPTION_HIDE; switch( target->type ) { - case BL_PC: { - struct map_session_data *sd = (TBL_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)) + case BL_PC: + { + 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(tsd)) + return 0; + if (tsc != NULL) { + if (tsc->option&hide_flag + && !is_boss + && ((tsd->special_state.perfect_hiding || !is_detect) + || (tsc->data[SC_CLOAKINGEXCEED] != NULL && is_detect) + )) + return 0; + if (tsc->data[SC_CAMOUFLAGE] && !(is_boss || is_detect) && (!skill_id || (flag == 0 && src && src->type != BL_PC))) + return 0; + if (tsc->data[SC_STEALTHFIELD] && !is_boss) return 0; - if( tsc ) { - if (tsc->option&hide_flag && !is_boss && - ((sd->special_state.perfect_hiding || !is_detect) || - (tsc->data[SC_CLOAKINGEXCEED] && is_detect))) - return 0; - if( tsc->data[SC_CAMOUFLAGE] && !(is_boss || is_detect) && (!skill_id || (flag == 0 && src && src->type != BL_PC)) ) - return 0; - if( tsc->data[SC_STEALTHFIELD] && !is_boss ) - return 0; - } } + } break; case BL_ITEM: //Allow targeting of items to pick'em up (or in the case of mobs, to loot them). @@ -2052,7 +2063,7 @@ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) { return 0; } if (!md->base_status) - md->base_status = (struct status_data*)aCalloc(1, sizeof(struct status_data)); + CREATE(md->base_status, struct status_data, 1); mstatus = md->base_status; memcpy(mstatus, &md->db->status, sizeof(struct status_data)); @@ -2074,7 +2085,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 && ((TBL_MOB*)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 @@ -3426,8 +3437,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 = (TBL_HOM*)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); @@ -3492,10 +3503,17 @@ void status_calc_regen_rate(struct block_list *bl, struct regen_data *regen, str ) regen->flag = 0; //No regen - if ( sc->data[SC_DANCING] || sc->data[SC_OBLIVIONCURSE] || sc->data[SC_MAXIMIZEPOWER] || sc->data[SC_REBOUND] - || ( bl->type == BL_PC && (((TBL_PC*)bl)->class_&MAPID_UPPERMASK) == MAPID_MONK - && (sc->data[SC_EXTREMITYFIST] || (sc->data[SC_EXPLOSIONSPIRITS] && (!sc->data[SC_SOULLINK] || sc->data[SC_SOULLINK]->val2 != SL_MONK))) + if (sc->data[SC_DANCING] != NULL + || sc->data[SC_OBLIVIONCURSE] != NULL + || sc->data[SC_MAXIMIZEPOWER] != NULL + || sc->data[SC_REBOUND] != NULL + || (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) ) + ) + ) ) { regen->flag &=~RGN_SP; //No natural SP regen } @@ -3542,13 +3560,21 @@ void status_calc_regen_rate(struct block_list *bl, struct regen_data *regen, str regen->rate.sp += regen->rate.sp * sc->data[SC_BUCHEDENOEL]->val2 / 100; } } + +#define status_get_homstr(st, hd) ((st)->str + (hd)->homunculus.str_value) +#define status_get_homagi(st, hd) ((st)->agi + (hd)->homunculus.agi_value) +#define status_get_homvit(st, hd) ((st)->vit + (hd)->homunculus.vit_value) +#define status_get_homint(st, hd) ((st)->int_ + (hd)->homunculus.int_value) +#define status_get_homdex(st, hd) ((st)->dex + (hd)->homunculus.dex_value) +#define status_get_homluk(st, hd) ((st)->luk + (hd)->homunculus.luk_value) + /// Recalculates parts of an object's battle status according to the specified flags. /// @param flag bitfield of values from enum scb_flag void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) { const struct status_data *bst = status->get_base_status(bl); struct status_data *st = status->get_status_data(bl); struct status_change *sc = status->get_sc(bl); - TBL_PC *sd = BL_CAST(BL_PC,bl); + struct map_session_data *sd = BL_CAST(BL_PC,bl); int temp; if (!bst || !st) @@ -3744,8 +3770,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 && ((TBL_HOM*)bl)->master) - st->speed = status->get_speed(&((TBL_HOM*)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) { @@ -3754,7 +3783,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 && ((TBL_PC*)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) { @@ -3860,12 +3889,13 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) { if(flag&SCB_ASPD) { int amotion; if ( bl->type&BL_HOM ) { + const struct homun_data *hd = BL_UCCAST(BL_HOM, bl); #ifdef RENEWAL - amotion = ((TBL_HOM*)bl)->homunculusDB->baseASPD; - amotion = amotion - amotion * status_get_homdex(bl) / 1000 - status_get_homagi(bl) * amotion / 250; + amotion = hd->homunculusDB->baseASPD; + amotion = amotion - amotion * status_get_homdex(st, hd) / 1000 - status_get_homagi(st, hd) * amotion / 250; amotion = (amotion * status->calc_aspd(bl, sc, 1) + status->calc_aspd(bl, sc, 2)) / -100 + amotion; #else - amotion = (1000 - 4 * st->agi - st->dex) * ((TBL_HOM*)bl)->homunculusDB->baseASPD / 1000; + amotion = (1000 - 4 * st->agi - st->dex) * hd->homunculusDB->baseASPD / 1000; amotion = status->calc_aspd_rate(bl, sc, amotion); @@ -3918,16 +3948,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 && ((TBL_PC*)bl)->delayed_damage != 0 ) { - if( opt&SCO_FORCE ) - ((TBL_PC*)bl)->state.hold_recalc = 0;/* clear and move on */ - else { - ((TBL_PC*)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; + } } } @@ -3964,7 +3998,7 @@ void status_calc_bl_(struct block_list *bl, enum scb_flag flag, enum e_status_ca // compare against new values and send client updates if( bl->type == BL_PC ) { - TBL_PC* sd = BL_CAST(BL_PC, bl); + struct map_session_data *sd = BL_CAST(BL_PC, bl); if(bst.str != st->str) clif->updatestatus(sd,SP_STR); if(bst.agi != st->agi) @@ -4055,11 +4089,11 @@ void status_calc_bl_(struct block_list *bl, enum scb_flag flag, enum e_status_ca clif->updatestatus(sd,SP_ATK2); #endif } else if( bl->type == BL_HOM ) { - TBL_HOM* hd = BL_CAST(BL_HOM, bl); - if( hd->master && memcmp(&bst, st, sizeof(struct status_data)) != 0 ) + struct homun_data *hd = BL_CAST(BL_HOM, bl); + if (hd->master != NULL && memcmp(&bst, st, sizeof(struct status_data)) != 0) clif->hominfo(hd->master,hd,0); } else if( bl->type == BL_MER ) { - TBL_MER* md = BL_CAST(BL_MER, bl); + struct mercenary_data *md = BL_CAST(BL_MER, bl); if( bst.rhw.atk != st->rhw.atk || bst.rhw.atk2 != st->rhw.atk2 ) clif->mercenary_updatestatus(md->master, SP_ATK1); if( bst.matk_max != st->matk_max ) @@ -4085,7 +4119,7 @@ void status_calc_bl_(struct block_list *bl, enum scb_flag flag, enum e_status_ca if( bst.sp != st->sp ) clif->mercenary_updatestatus(md->master, SP_SP); } else if( bl->type == BL_ELEM ) { - TBL_ELEM* ed = BL_CAST(BL_ELEM, bl); + struct elemental_data *ed = BL_CAST(BL_ELEM, bl); if( bst.max_hp != st->max_hp ) clif->elemental_updatestatus(ed->master, SP_MAXHP); if( bst.max_sp != st->max_sp ) @@ -4103,10 +4137,10 @@ int status_check_visibility(struct block_list *src, struct block_list *target) { switch ( src->type ) { case BL_MOB: - view_range = ((TBL_MOB*)src)->min_chase; + view_range = BL_UCCAST(BL_MOB, src)->min_chase; break; case BL_PET: - view_range = ((TBL_PET*)src)->db->range2; + view_range = BL_UCCAST(BL_PET, src)->db->range2; break; default: view_range = AREA_SIZE; @@ -4125,8 +4159,13 @@ int status_check_visibility(struct block_list *src, struct block_list *target) { case BL_PC: if ( tsc->data[SC_CLOAKINGEXCEED] && !(st->mode&MD_BOSS) ) return 0; - if ( (tsc->option&(OPTION_HIDE | OPTION_CLOAK | OPTION_CHASEWALK) || tsc->data[SC_STEALTHFIELD] || tsc->data[SC__INVISIBILITY] || tsc->data[SC_CAMOUFLAGE]) && !(st->mode&MD_BOSS) && - (((TBL_PC*)target)->special_state.perfect_hiding || !(st->mode&MD_DETECTOR)) ) + if ((tsc->option&(OPTION_HIDE | OPTION_CLOAK | OPTION_CHASEWALK) + || tsc->data[SC_STEALTHFIELD] != NULL + || tsc->data[SC__INVISIBILITY] != NULL + || tsc->data[SC_CAMOUFLAGE] != NULL + ) + && !(st->mode&MD_BOSS) + && (BL_UCCAST(BL_PC, target)->special_state.perfect_hiding || !(st->mode&MD_DETECTOR))) return 0; break; default: @@ -4192,8 +4231,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 ( ((TBL_PC*)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: @@ -4203,36 +4242,39 @@ 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] #ifdef RENEWAL - if ( bl->type == BL_HOM ) - str = 2 * (((TBL_HOM*)bl)->homunculus.level + status_get_homstr(bl)); + if (bl->type == BL_HOM) { + const struct homun_data *hd = BL_UCCAST(BL_HOM, bl); + str = 2 * (hd->homunculus.level + status_get_homstr(st, hd)); + } #else 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)((TBL_PC*)bl)->status.base_level / 4); - else if ( bl->type == BL_MOB || bl->type == BL_MER ) - str = dstr + ((TBL_MOB*)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); @@ -4249,7 +4291,7 @@ unsigned short status_base_matk(struct block_list *bl, const struct status_data case BL_MOB: return st->int_ + level; case BL_HOM: - return status_get_homint(bl) + level; + return status_get_homint(st, BL_UCCAST(BL_HOM, bl)) + level; case BL_MER: return st->int_ + st->int_ / 5 * st->int_ / 5; case BL_PC: @@ -4272,14 +4314,15 @@ void status_calc_misc(struct block_list *bl, struct status_data *st, int level) #ifdef RENEWAL // renewal formulas if ( bl->type == BL_HOM ) { - st->def2 = status_get_homvit(bl) + status_get_homagi(bl) / 2; - st->mdef2 = (status_get_homvit(bl) + status_get_homint(bl)) / 2; - st->def += status_get_homvit(bl) + level / 2; // Increase. Already initialized in status_calc_homunculus_ - st->mdef = (int)(((float)status_get_homvit(bl) + level) / 4 + (float)status_get_homint(bl) / 2); + const struct homun_data *hd = BL_UCCAST(BL_HOM, bl); + st->def2 = status_get_homvit(st, hd) + status_get_homagi(st, hd) / 2; + st->mdef2 = (status_get_homvit(st, hd) + status_get_homint(st, hd)) / 2; + st->def += status_get_homvit(st, hd) + level / 2; // Increase. Already initialized in status_calc_homunculus_ + st->mdef = (int)(((float)status_get_homvit(st, hd) + level) / 4 + (float)status_get_homint(st, hd) / 2); st->hit = level + st->dex + 150; - st->flee = level + status_get_homagi(bl); - st->rhw.atk = (status_get_homstr(bl) + status_get_homdex(bl)) / 5; - st->rhw.atk2 = (status_get_homluk(bl) + status_get_homstr(bl) + status_get_homdex(bl)) / 3; + st->flee = level + status_get_homagi(st, hd); + st->rhw.atk = (status_get_homstr(st, hd) + status_get_homdex(st, hd)) / 5; + st->rhw.atk2 = (status_get_homluk(st, hd) + status_get_homstr(st, hd) + status_get_homdex(st, hd)) / 3; } else { st->hit += level + st->dex + (bl->type == BL_PC ? st->luk / 3 + 175 : 150); //base level + ( every 1 dex = +1 hit ) + (every 3 luk = +1 hit) + 175 st->flee += level + st->agi + (bl->type == BL_MER ? 0: (bl->type == BL_PC ? st->luk / 5 : 0) + 100); //base level + ( every 1 agi = +1 flee ) + (every 5 luk = +1 flee) + 100 @@ -4833,10 +4876,10 @@ unsigned short status_calc_watk(struct block_list *bl, struct status_change *sc, #ifndef RENEWAL if(sc->data[SC_NIBELUNGEN]) { - if (bl->type != BL_PC) + if (bl->type != BL_PC) { watk += sc->data[SC_NIBELUNGEN]->val2; - else { - TBL_PC *sd = (TBL_PC*)bl; + } else { + 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; @@ -5469,7 +5512,7 @@ signed short status_calc_mdef2(struct block_list *bl, struct status_change *sc, unsigned short status_calc_speed(struct block_list *bl, struct status_change *sc, int speed) { - TBL_PC* sd = BL_CAST(BL_PC, bl); + struct map_session_data *sd = BL_CAST(BL_PC, bl); int speed_rate; if( sc == NULL || ( sd && sd->state.permanent_speed ) ) @@ -5698,11 +5741,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 (((TBL_PC*)bl)->status.weapon) - { + } else { + switch (BL_UCCAST(BL_PC, bl)->status.weapon) { case W_BOW: case W_REVOLVER: case W_RIFLE: @@ -5798,11 +5840,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((TBL_PC *)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; @@ -5857,14 +5898,11 @@ short status_calc_aspd_rate(struct block_list *bl, struct status_change *sc, int max < sc->data[SC_HLIF_FLEET]->val2) max = sc->data[SC_HLIF_FLEET]->val2; - if(sc->data[SC_ASSNCROS] && - max < sc->data[SC_ASSNCROS]->val2) - { - if (bl->type!=BL_PC) + if (sc->data[SC_ASSNCROS] && max < sc->data[SC_ASSNCROS]->val2) { + if (bl->type != BL_PC) { max = sc->data[SC_ASSNCROS]->val2; - else - switch(((TBL_PC*)bl)->status.weapon) - { + } else { + switch (BL_UCCAST(BL_PC, bl)->status.weapon) { case W_BOW: case W_REVOLVER: case W_RIFLE: @@ -5874,6 +5912,7 @@ short status_calc_aspd_rate(struct block_list *bl, struct status_change *sc, int break; default: max = sc->data[SC_ASSNCROS]->val2; + } } } @@ -5957,9 +5996,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 && (((TBL_MOB*)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 ) @@ -6183,14 +6223,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 ((TBL_PC *)bl)->fakename[0] != '\0' ? ((TBL_PC*)bl)->fakename : ((TBL_PC*)bl)->status.name; - case BL_MOB: return ((TBL_MOB*)bl)->name; - case BL_PET: return ((TBL_PET*)bl)->pet.name; - case BL_HOM: return ((TBL_HOM*)bl)->homunculus.name; - case BL_NPC: return ((TBL_NPC*)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"; } @@ -6201,16 +6248,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 ((TBL_PC*)bl)->status.class_; - case BL_MOB: return ((TBL_MOB*)bl)->vd->class_; //Class used on all code should be the view class of the mob. - case BL_PET: return ((TBL_PET*)bl)->pet.class_; - case BL_HOM: return ((TBL_HOM*)bl)->homunculus.class_; - case BL_MER: return ((TBL_MER*)bl)->mercenary.class_; - case BL_NPC: return ((TBL_NPC*)bl)->class_; - case BL_ELEM: return ((TBL_ELEM*)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; } @@ -6220,16 +6268,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 ((TBL_PC*)bl)->status.base_level; - case BL_MOB: return ((TBL_MOB*)bl)->level; - case BL_PET: return ((TBL_PET*)bl)->pet.level; - case BL_HOM: return ((TBL_HOM*)bl)->homunculus.level; - case BL_MER: return ((TBL_MER*)bl)->db->lv; - case BL_ELEM: return ((TBL_ELEM*)bl)->db->lv; - case BL_NPC: return ((TBL_NPC*)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; } @@ -6238,10 +6287,10 @@ struct regen_data *status_get_regen_data(struct block_list *bl) { nullpo_retr(NULL, bl); switch (bl->type) { - case BL_PC: return &((TBL_PC*)bl)->regen; - case BL_HOM: return &((TBL_HOM*)bl)->regen; - case BL_MER: return &((TBL_MER*)bl)->regen; - case BL_ELEM: return &((TBL_ELEM*)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; } @@ -6252,13 +6301,17 @@ struct status_data *status_get_status_data(struct block_list *bl) nullpo_retr(&status->dummy, bl); switch (bl->type) { - case BL_PC: return &((TBL_PC*)bl)->battle_status; - case BL_MOB: return &((TBL_MOB*)bl)->status; - case BL_PET: return &((TBL_PET*)bl)->status; - case BL_HOM: return &((TBL_HOM*)bl)->battle_status; - case BL_MER: return &((TBL_MER*)bl)->battle_status; - case BL_ELEM: return &((TBL_ELEM*)bl)->battle_status; - case BL_NPC: return ((mob->db_checkid(((TBL_NPC*)bl)->class_) == 0) ? &((TBL_NPC*)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; } @@ -6268,13 +6321,21 @@ struct status_data *status_get_base_status(struct block_list *bl) { nullpo_retr(NULL, bl); switch (bl->type) { - case BL_PC: return &((TBL_PC*)bl)->base_status; - case BL_MOB: return ((TBL_MOB*)bl)->base_status ? ((TBL_MOB*)bl)->base_status : &((TBL_MOB*)bl)->db->status; - case BL_PET: return &((TBL_PET*)bl)->db->status; - case BL_HOM: return &((TBL_HOM*)bl)->base_status; - case BL_MER: return &((TBL_MER*)bl)->base_status; - case BL_ELEM: return &((TBL_ELEM*)bl)->base_status; - case BL_NPC: return ((mob->db_checkid(((TBL_NPC*)bl)->class_) == 0) ? &((TBL_NPC*)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; } @@ -6290,9 +6351,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; } @@ -6300,81 +6362,118 @@ int status_get_party_id(struct block_list *bl) { nullpo_ret(bl); switch (bl->type) { case BL_PC: - return ((TBL_PC*)bl)->status.party_id; + return BL_UCCAST(BL_PC, bl)->status.party_id; case BL_PET: - if (((TBL_PET*)bl)->msd) - return ((TBL_PET*)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=(TBL_MOB*)bl; - if( md->master_id > 0 ) { - struct map_session_data *msd; + case BL_MOB: + { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); + if (md->master_id > 0) { + 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; } - } - break; + } + break; case BL_HOM: - if (((TBL_HOM*)bl)->master) - return ((TBL_HOM*)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 (((TBL_MER*)bl)->master) - return ((TBL_MER*)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 (((TBL_SKILL*)bl)->group) - return ((TBL_SKILL*)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 (((TBL_ELEM*)bl)->master) - return ((TBL_ELEM*)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 ((TBL_PC*)bl)->status.guild_id; + return BL_UCCAST(BL_PC, bl)->status.guild_id; case BL_PET: - if (((TBL_PET*)bl)->msd) - return ((TBL_PET*)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 (((TBL_HOM*)bl)->master) - return ((TBL_HOM*)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 (((TBL_MER*)bl)->master) - return ((TBL_MER*)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 (((TBL_NPC*)bl)->subtype == SCRIPT) - return ((TBL_NPC*)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 (((TBL_SKILL*)bl)->group) - return ((TBL_SKILL*)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 (((TBL_ELEM*)bl)->master) - return ((TBL_ELEM*)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; @@ -6384,38 +6483,58 @@ int status_get_emblem_id(struct block_list *bl) { nullpo_ret(bl); switch (bl->type) { case BL_PC: - return ((TBL_PC*)bl)->guild_emblem_id; + return BL_UCCAST(BL_PC, bl)->guild_emblem_id; case BL_PET: - if (((TBL_PET*)bl)->msd) - return ((TBL_PET*)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; + case BL_MOB: + { + 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; + } + break; case BL_HOM: - if (((TBL_HOM*)bl)->master) - return ((TBL_HOM*)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 (((TBL_MER*)bl)->master) - return ((TBL_MER*)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 (((TBL_NPC*)bl)->subtype == SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) { - struct guild *g = guild->search(((TBL_NPC*)bl)->u.scr.guild_id); - if (g) + { + 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 (((TBL_ELEM*)bl)->master) - return ((TBL_ELEM*)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; @@ -6424,19 +6543,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; } @@ -6445,28 +6565,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 && - ((TBL_PC*)bl)->special_state.no_magic_damage >= battle_config.gtb_sc_immunity) - return ((TBL_PC*)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 &((TBL_PC*)bl)->vd; - case BL_MOB: return ((TBL_MOB*)bl)->vd; - case BL_PET: return &((TBL_PET*)bl)->vd; - case BL_NPC: return ((TBL_NPC*)bl)->vd; - case BL_HOM: return ((TBL_HOM*)bl)->vd; - case BL_MER: return ((TBL_MER*)bl)->vd; - case BL_ELEM: return ((TBL_ELEM*)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; } @@ -6490,142 +6616,147 @@ void status_set_viewdata(struct block_list *bl, int class_) switch (bl->type) { case BL_PC: - { - TBL_PC* sd = (TBL_PC*)bl; - if (pc->db_checkid(class_)) { - if (pc_isridingpeco(sd)) { - switch (class_) { - //Adapt class to a Mounted one. - case JOB_KNIGHT: - class_ = JOB_KNIGHT2; - break; - case JOB_CRUSADER: - class_ = JOB_CRUSADER2; - break; - case JOB_LORD_KNIGHT: - class_ = JOB_LORD_KNIGHT2; - break; - case JOB_PALADIN: - class_ = JOB_PALADIN2; - break; - case JOB_BABY_KNIGHT: - class_ = JOB_BABY_KNIGHT2; - break; - case JOB_BABY_CRUSADER: - class_ = JOB_BABY_CRUSADER2; - break; - } - } - sd->vd.class_ = class_; - clif->get_weapon_view(sd, &sd->vd.weapon, &sd->vd.shield); - sd->vd.head_top = sd->status.head_top; - sd->vd.head_mid = sd->status.head_mid; - sd->vd.head_bottom = sd->status.head_bottom; - sd->vd.hair_style = cap_value(sd->status.hair,0,battle_config.max_hair_style); - sd->vd.hair_color = cap_value(sd->status.hair_color,0,battle_config.max_hair_color); - sd->vd.cloth_color = cap_value(sd->status.clothes_color,0,battle_config.max_cloth_color); - sd->vd.robe = sd->status.robe; - sd->vd.body_style = sd->status.body; - sd->vd.sex = sd->status.sex; - - if ( sd->vd.cloth_color ) { - if( sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette ) - sd->vd.cloth_color = 0; - if( sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette ) - sd->vd.cloth_color = 0; - if( sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette ) - sd->vd.cloth_color = 0; - if( sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette ) - sd->vd.cloth_color = 0; - if( sd->sc.option&OPTION_OKTOBERFEST /* TODO: config? */ ) - sd->vd.cloth_color = 0; + { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + if (pc->db_checkid(class_)) { + if (pc_isridingpeco(sd)) { + switch (class_) { + //Adapt class to a Mounted one. + case JOB_KNIGHT: + class_ = JOB_KNIGHT2; + break; + case JOB_CRUSADER: + class_ = JOB_CRUSADER2; + break; + case JOB_LORD_KNIGHT: + class_ = JOB_LORD_KNIGHT2; + break; + case JOB_PALADIN: + class_ = JOB_PALADIN2; + break; + case JOB_BABY_KNIGHT: + class_ = JOB_BABY_KNIGHT2; + break; + case JOB_BABY_CRUSADER: + class_ = JOB_BABY_CRUSADER2; + break; } - if ( sd->vd.body_style && ( - sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS || - sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK || - sd->sc.option&OPTION_OKTOBERFEST)) - sd->vd.body_style = 0; - } else if (vd) - memcpy(&sd->vd, vd, sizeof(struct view_data)); - else - ShowError("status_set_viewdata (PC): No view data for class %d\n", class_); + } + sd->vd.class_ = class_; + clif->get_weapon_view(sd, &sd->vd.weapon, &sd->vd.shield); + sd->vd.head_top = sd->status.head_top; + sd->vd.head_mid = sd->status.head_mid; + sd->vd.head_bottom = sd->status.head_bottom; + sd->vd.hair_style = cap_value(sd->status.hair,0,battle_config.max_hair_style); + sd->vd.hair_color = cap_value(sd->status.hair_color,0,battle_config.max_hair_color); + sd->vd.cloth_color = cap_value(sd->status.clothes_color,0,battle_config.max_cloth_color); + sd->vd.robe = sd->status.robe; + sd->vd.body_style = sd->status.body; + sd->vd.sex = sd->status.sex; + + if (sd->vd.cloth_color) { + if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette) + sd->vd.cloth_color = 0; + if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette) + sd->vd.cloth_color = 0; + if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette) + sd->vd.cloth_color = 0; + if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette) + sd->vd.cloth_color = 0; + if (sd->sc.option&OPTION_OKTOBERFEST /* TODO: config? */) + sd->vd.cloth_color = 0; + } + if (sd->vd.body_style + && (sd->sc.option&OPTION_WEDDING + || sd->sc.option&OPTION_XMAS + || sd->sc.option&OPTION_SUMMER + || sd->sc.option&OPTION_HANBOK + || sd->sc.option&OPTION_OKTOBERFEST)) + sd->vd.body_style = 0; + } else if (vd != NULL) { + memcpy(&sd->vd, vd, sizeof(struct view_data)); + } else { + ShowError("status_set_viewdata (PC): No view data for class %d\n", class_); } + } break; case BL_MOB: - { - TBL_MOB* md = (TBL_MOB*)bl; - if (vd) - md->vd = vd; - else - ShowError("status_set_viewdata (MOB): No view data for class %d\n", class_); - } + { + struct mob_data *md = BL_UCAST(BL_MOB, bl); + if (vd != NULL) + md->vd = vd; + else + ShowError("status_set_viewdata (MOB): No view data for class %d\n", class_); + } break; case BL_PET: - { - TBL_PET* pd = (TBL_PET*)bl; - if (vd) { - memcpy(&pd->vd, vd, sizeof(struct view_data)); - if (!pc->db_checkid(vd->class_)) { - pd->vd.hair_style = battle_config.pet_hair_style; - if(pd->pet.equip) { - pd->vd.head_bottom = itemdb_viewid(pd->pet.equip); - if (!pd->vd.head_bottom) - pd->vd.head_bottom = pd->pet.equip; - } + { + 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_)) { + pd->vd.hair_style = battle_config.pet_hair_style; + if(pd->pet.equip) { + pd->vd.head_bottom = itemdb_viewid(pd->pet.equip); + if (!pd->vd.head_bottom) + pd->vd.head_bottom = pd->pet.equip; } - } else - ShowError("status_set_viewdata (PET): No view data for class %d\n", class_); + } + } else { + ShowError("status_set_viewdata (PET): No view data for class %d\n", class_); } + } break; case BL_NPC: - { - TBL_NPC* nd = (TBL_NPC*)bl; - if (vd) - nd->vd = vd; - else - ShowError("status_set_viewdata (NPC): No view data for class %d (name=%s)\n", class_, nd->name); - } + { + struct npc_data *nd = BL_UCAST(BL_NPC, bl); + if (vd != NULL) + nd->vd = vd; + else + ShowError("status_set_viewdata (NPC): No view data for class %d (name=%s)\n", class_, nd->name); + } break; case BL_HOM: //[blackhole89] - { - struct homun_data *hd = (struct homun_data*)bl; - if (vd) - hd->vd = vd; - else - ShowError("status_set_viewdata (HOMUNCULUS): No view data for class %d\n", class_); - } + { + struct homun_data *hd = BL_UCAST(BL_HOM, bl); + if (vd != NULL) + hd->vd = vd; + else + ShowError("status_set_viewdata (HOMUNCULUS): No view data for class %d\n", class_); + } break; case BL_MER: - { - struct mercenary_data *md = (struct mercenary_data*)bl; - if (vd) - md->vd = vd; - else - ShowError("status_set_viewdata (MERCENARY): No view data for class %d\n", class_); - } + { + struct mercenary_data *md = BL_UCAST(BL_MER, bl); + if (vd != NULL) + md->vd = vd; + else + ShowError("status_set_viewdata (MERCENARY): No view data for class %d\n", class_); + } break; case BL_ELEM: - { - struct elemental_data *ed = (struct elemental_data*)bl; - if (vd) - ed->vd = vd; - else - ShowError("status_set_viewdata (ELEMENTAL): No view data for class %d\n", class_); - } + { + struct elemental_data *ed = BL_UCAST(BL_ELEM, bl); + if (vd != NULL) + ed->vd = vd; + else + ShowError("status_set_viewdata (ELEMENTAL): No view data for class %d\n", class_); + } break; } } /// 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 &((TBL_PC*)bl)->sc; - case BL_MOB: return &((TBL_MOB*)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 &((TBL_HOM*)bl)->sc; - case BL_MER: return &((TBL_MER*)bl)->sc; - case BL_ELEM: return &((TBL_ELEM*)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; @@ -6876,13 +7007,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)?((TBL_PC*)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) ? ((TBL_PC*)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. @@ -7894,8 +8025,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 && ((TBL_MER*)bl)->devotion_flag && (tsd = ((TBL_MER*)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) @@ -7994,8 +8128,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 && ((TBL_MER*)bl)->devotion_flag && (tsd = ((TBL_MER*)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; @@ -8137,7 +8274,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((TBL_MOB*)bl,src2,diff); + mob->log_damage(BL_UCAST(BL_MOB, bl), src2, diff); } status_zap(bl, diff, 0); } @@ -8211,7 +8348,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 && ((TBL_MOB*)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; @@ -8255,9 +8392,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 && ((TBL_MER*)bl)->devotion_flag && (tsd = ((TBL_MER*)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); + } } } } @@ -8432,7 +8571,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((TBL_MOB*)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; @@ -10205,11 +10344,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 && ((TBL_MER*)bl)->devotion_flag ) { - // Clear Status from Master - tsd = ((TBL_MER*)bl)->master; - if( tsd && tsd->sc.data[type] ) - 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; @@ -10217,10 +10359,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 ) - ((TBL_PC*)d_bl)->devotion[sce->val2] = 0; - else if( d_bl->type == BL_MER ) - ((TBL_MER*)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); } @@ -10975,8 +11117,8 @@ int status_change_timer(int tid, int64 tick, int id, intptr_t data) { if (!sc->data[SC_SLOWPOISON]) { if( sce->val2 && bl->type == BL_MOB ) { struct block_list* src = map->id2bl(sce->val2); - if( src ) - mob->log_damage((TBL_MOB*)bl,src,sce->val4); + if (src != NULL) + mob->log_damage(BL_UCAST(BL_MOB, bl), src, sce->val4); } map->freeblock_lock(); status_zap(bl, sce->val4, 0); @@ -11015,7 +11157,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((TBL_MOB*)bl,src,sd||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); @@ -11760,9 +11902,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 @@ -11828,7 +11973,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 ) { @@ -11899,16 +12044,25 @@ void status_get_matk_sub(struct block_list *bl, int flag, unsigned short *matk_m } break; case BL_MER: - *matk_min += 70 * ((TBL_MER*)bl)->battle_status.rhw.atk2 / 100; - *matk_max += 130 * ((TBL_MER*)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 * ((TBL_MOB*)bl)->status.rhw.atk2 / 100; - *matk_max += 130 * ((TBL_MOB*)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: - *matk_min += (status_get_homint(bl) + status_get_homdex(bl)) / 5; - *matk_max += (status_get_homluk(bl) + status_get_homint(bl) + status_get_homdex(bl)) / 3; + { + const struct homun_data *hd = BL_UCCAST(BL_HOM, bl); + *matk_min += (status_get_homint(st, hd) + status_get_homdex(st, hd)) / 5; + *matk_max += (status_get_homluk(st, hd) + status_get_homint(st, hd) + status_get_homdex(st, hd)) / 3; + } break; } @@ -11944,6 +12098,13 @@ void status_get_matk_sub(struct block_list *bl, int flag, unsigned short *matk_m return; } +#undef status_get_homstr +#undef status_get_homagi +#undef status_get_homvit +#undef status_get_homint +#undef status_get_homdex +#undef status_get_homluk + /** * Gets a random matk value depending on min matk and max matk **/ diff --git a/src/map/status.h b/src/map/status.h index 55df4cdab..51ca1e78b 100644 --- a/src/map/status.h +++ b/src/map/status.h @@ -2123,13 +2123,6 @@ struct status_change { #define status_get_size(bl) (status->get_status_data(bl)->size) #define status_get_mode(bl) (status->get_status_data(bl)->mode) -#define status_get_homstr(bl) (st->str + ((TBL_HOM*)bl)->homunculus.str_value) -#define status_get_homagi(bl) (st->agi + ((TBL_HOM*)bl)->homunculus.agi_value) -#define status_get_homvit(bl) (st->vit + ((TBL_HOM*)bl)->homunculus.vit_value) -#define status_get_homint(bl) (st->int_ + ((TBL_HOM*)bl)->homunculus.int_value) -#define status_get_homdex(bl) (st->dex + ((TBL_HOM*)bl)->homunculus.dex_value) -#define status_get_homluk(bl) (st->luk + ((TBL_HOM*)bl)->homunculus.luk_value) - //Short version, receives rate in 1->100 range, and does not uses a flag setting. #define sc_start(src, bl, type, rate, val1, tick) (status->change_start((src),(bl),(type),100*(rate),(val1),0,0,0,(tick),SCFLAG_NONE)) #define sc_start2(src, bl, type, rate, val1, val2, tick) (status->change_start((src),(bl),(type),100*(rate),(val1),(val2),0,0,(tick),SCFLAG_NONE)) diff --git a/src/map/unit.c b/src/map/unit.c index 4c5254373..03334f7f3 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -73,15 +73,16 @@ struct unit_interface *unit; * @param bl block_list to process * @return a pointer to the given object's unit_data **/ -struct unit_data* unit_bl2ud(struct block_list *bl) { - if( bl == NULL) return NULL; - if( bl->type == BL_PC) return &((struct map_session_data*)bl)->ud; - if( bl->type == BL_MOB) return &((struct mob_data*)bl)->ud; - if( bl->type == BL_PET) return &((struct pet_data*)bl)->ud; - if( bl->type == BL_NPC) return ((struct npc_data*)bl)->ud; - if( bl->type == BL_HOM) return &((struct homun_data*)bl)->ud; - if( bl->type == BL_MER) return &((struct mercenary_data*)bl)->ud; - if( bl->type == BL_ELEM) return &((struct elemental_data*)bl)->ud; +struct unit_data* unit_bl2ud(struct block_list *bl) +{ + if (bl == NULL) return NULL; + if (bl->type == BL_PC) return &BL_UCAST(BL_PC, bl)->ud; + if (bl->type == BL_MOB) return &BL_UCAST(BL_MOB, bl)->ud; + if (bl->type == BL_PET) return &BL_UCAST(BL_PET, bl)->ud; + if (bl->type == BL_NPC) return BL_UCAST(BL_NPC, bl)->ud; + if (bl->type == BL_HOM) return &BL_UCAST(BL_HOM, bl)->ud; + if (bl->type == BL_MER) return &BL_UCAST(BL_MER, bl)->ud; + if (bl->type == BL_ELEM) return &BL_UCAST(BL_ELEM, bl)->ud; return NULL; } @@ -92,9 +93,10 @@ struct unit_data* unit_bl2ud(struct block_list *bl) { * @param bl block_list to process * @return a pointer to the given object's unit_data */ -struct unit_data* unit_bl2ud2(struct block_list *bl) { - if( bl && bl->type == BL_NPC && ((struct npc_data*)bl)->ud == &npc->base_ud ) { - struct npc_data *nd = (struct npc_data *)bl; +struct unit_data *unit_bl2ud2(struct block_list *bl) +{ + struct npc_data *nd = BL_CAST(BL_NPC, bl); + if (nd != NULL && nd->ud == &npc->base_ud) { nd->ud = NULL; CREATE(nd->ud, struct unit_data, 1); unit->dataset(&nd->bl); @@ -148,8 +150,9 @@ int unit_walktoxy_sub(struct block_list *bl) ud->state.change_walk_target=0; if (bl->type == BL_PC) { - ((TBL_PC *)bl)->head_dir = 0; - clif->walkok((TBL_PC*)bl); + struct map_session_data *sd = BL_UCAST(BL_PC, bl); + sd->head_dir = 0; + clif->walkok(sd); } clif->move(ud); @@ -448,7 +451,7 @@ int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) { //Cancel chase. ud->to_x = bl->x; ud->to_y = bl->y; - if (tbl && bl->type == BL_MOB && mob->warpchase((TBL_MOB*)bl, tbl) ) + if (tbl && bl->type == BL_MOB && mob->warpchase(BL_UCAST(BL_MOB, bl), tbl)) return 0; ud->target_to = 0; return 0; @@ -813,7 +816,7 @@ int unit_setdir(struct block_list *bl,unsigned char dir) if (!ud) return 0; ud->dir = dir; if (bl->type == BL_PC) - ((TBL_PC *)bl)->head_dir = 0; + BL_UCAST(BL_PC, bl)->head_dir = 0; clif->changed_dir(bl, AREA); return 0; } @@ -823,7 +826,7 @@ uint8 unit_getdir(struct block_list *bl) { nullpo_ret(bl); if( bl->type == BL_NPC ) - return ((TBL_NPC*)bl)->dir; + return BL_UCCAST(BL_NPC, bl)->dir; ud = unit->bl2ud(bl); if (!ud) return 0; return ud->dir; @@ -917,10 +920,13 @@ int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type) switch (bl->type) { case BL_MOB: - if (map->list[bl->m].flag.monster_noteleport && ((TBL_MOB*)bl)->master_id == 0) + { + const struct mob_data *md = BL_UCCAST(BL_MOB, bl); + if (map->list[bl->m].flag.monster_noteleport && md->master_id == 0) return 1; - if (m != bl->m && map->list[m].flag.nobranch && battle_config.mob_warp&4 && !(((TBL_MOB *)bl)->master_id)) + if (m != bl->m && map->list[m].flag.nobranch && battle_config.mob_warp&4 && md->master_id == 0) return 1; + } break; case BL_PC: if (map->list[bl->m].flag.noteleport) @@ -947,7 +953,7 @@ int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type) } if (bl->type == BL_PC) //Use pc_setpos - return pc->setpos((TBL_PC*)bl, map_id2index(m), x, y, type); + return pc->setpos(BL_UCAST(BL_PC, bl), map_id2index(m), x, y, type); if (!unit->remove_map(bl, type, ALC_MARK)) return 3; @@ -1137,7 +1143,7 @@ int unit_can_move(struct block_list *bl) { int unit_resume_running(int tid, int64 tick, int id, intptr_t data) { struct unit_data *ud = (struct unit_data *)data; - TBL_PC * sd = map->id2sd(id); + struct map_session_data *sd = map->id2sd(id); if(sd && pc_isridingwug(sd)) clif->skill_nodamage(ud->bl,ud->bl,RA_WUGDASH,ud->skill_lv, @@ -1164,7 +1170,7 @@ int unit_set_walkdelay(struct block_list *bl, int64 tick, int delay, int type) { if (type) { //Bosses can ignore skill induced walkdelay (but not damage induced) - if(bl->type == BL_MOB && (((TBL_MOB*)bl)->status.mode&MD_BOSS)) + if (bl->type == BL_MOB && (BL_UCCAST(BL_MOB, bl)->status.mode&MD_BOSS)) return 0; //Make sure walk delay is not decreased if (DIFF_TICK(ud->canmove_tick, tick+delay) > 0) @@ -1256,13 +1262,17 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui break; case WE_MALE: case WE_FEMALE: + { + struct map_session_data *p_sd = NULL; if (!sd->status.partner_id) return 0; - target = (struct block_list*)map->charid2sd(sd->status.partner_id); - if (!target) { + p_sd = map->charid2sd(sd->status.partner_id); + if (p_sd == NULL) { clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0); return 0; } + target = &p_sd->bl; + } break; case GC_WEAPONCRUSH: if( sc && sc->data[SC_COMBOATTACK] && sc->data[SC_COMBOATTACK]->val1 == GC_WEAPONBLOCKING ) { @@ -1381,14 +1391,16 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui return 0; } - if( src->type == BL_MOB ) - switch( skill_id ) { + if (src->type == BL_MOB) { + const struct mob_data *src_md = BL_UCCAST(BL_MOB, src); + switch (skill_id) { case NPC_SUMMONSLAVE: case NPC_SUMMONMONSTER: case AL_TELEPORT: - if (((TBL_MOB*)src)->master_id && ((TBL_MOB*)src)->special_state.ai != AI_NONE) + if (src_md->master_id != 0 && src_md->special_state.ai != AI_NONE) return 0; } + } if (src->type == BL_NPC) // NPC-objects can override cast distance range = AREA_SIZE; // Maximum visible distance before NPC goes out of sight @@ -1564,9 +1576,8 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui clif->skillcasting(src, src->id, target_id, 0,0, skill_id, skill->get_ele(skill_id, skill_lv), casttime); if( casttime > 0 || temp ) { - if (sd && target->type == BL_MOB) - { - TBL_MOB *md = (TBL_MOB*)target; + if (sd != NULL && target->type == BL_MOB) { + struct mob_data *md = BL_UCAST(BL_MOB, target); mob->skill_event(md, src, tick, -1); //Cast targeted skill event. if (tstatus->mode&(MD_CASTSENSOR_IDLE|MD_CASTSENSOR_CHASE) && battle->check_target(target, src, BCT_ENEMY) > 0) @@ -1848,10 +1859,10 @@ int unit_unattackable(struct block_list *bl) unit->set_target(ud, 0); } - if(bl->type == BL_MOB) - mob->unlocktarget((struct mob_data*)bl, timer->gettick()) ; - else if(bl->type == BL_PET) - pet->unlocktarget((struct pet_data*)bl); + if (bl->type == BL_MOB) + mob->unlocktarget(BL_UCAST(BL_MOB, bl), timer->gettick()); + else if (bl->type == BL_PET) + pet->unlocktarget(BL_UCAST(BL_PET, bl)); return 0; } @@ -1872,10 +1883,10 @@ int unit_attack(struct block_list *src,int target_id,int continuous) { return 1; } - if( src->type == BL_PC ) { - TBL_PC* sd = (TBL_PC*)src; + if (src->type == BL_PC) { + struct map_session_data *sd = BL_UCAST(BL_PC, src); if( target->type == BL_NPC ) { // monster npcs [Valaris] - npc->click(sd,(TBL_NPC*)target); // submitted by leinsirk10 [Celest] + npc->click(sd, BL_UCAST(BL_NPC, target)); // submitted by leinsirk10 [Celest] return 0; } if( pc_is90overweight(sd) || pc_isridingwug(sd) ) { // overweight or mounted on warg - stop attacking @@ -2086,9 +2097,8 @@ int unit_attack_timer_sub(struct block_list* src, int tid, int64 tick) { ) return 0; // can't attack under these conditions - if( src->m != target->m ) - { - if( src->type == BL_MOB && mob->warpchase((TBL_MOB*)src, target) ) + if (src->m != target->m) { + if (src->type == BL_MOB && mob->warpchase(BL_UCAST(BL_MOB, src), target)) return 1; // Follow up. return 0; } @@ -2161,7 +2171,7 @@ int unit_attack_timer_sub(struct block_list* src, int tid, int64 tick) { map->foreachinrange(mob->linksearch, src, md->db->range2, BL_MOB, md->class_, target, tick); } } - if(src->type == BL_PET && pet->attackskill((TBL_PET*)src, target->id)) + if (src->type == BL_PET && pet->attackskill(BL_UCAST(BL_PET, src), target->id)) return 1; map->freeblock_lock(); @@ -2256,7 +2266,8 @@ int unit_skillcastcancel(struct block_list *bl,int type) } } - if(bl->type==BL_MOB) ((TBL_MOB*)bl)->skill_idx = -1; + if (bl->type == BL_MOB) + BL_UCAST(BL_MOB, bl)->skill_idx = -1; clif->skillcastcancel(bl); return 1; @@ -2311,9 +2322,9 @@ int unit_changeviewsize(struct block_list *bl,short size) size=(size<0)?-1:(size>0)?1:0; if(bl->type == BL_PC) { - ((TBL_PC*)bl)->state.size=size; + BL_UCAST(BL_PC, bl)->state.size = size; } else if(bl->type == BL_MOB) { - ((TBL_MOB*)bl)->special_state.size=size; + BL_UCAST(BL_MOB, bl)->special_state.size = size; } else return 0; if(size!=0) @@ -2398,8 +2409,9 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i } switch( bl->type ) { - case BL_PC: { - struct map_session_data *sd = (struct map_session_data*)bl; + case BL_PC: + { + struct map_session_data *sd = BL_UCAST(BL_PC, bl); if(sd->shadowform_id) { struct block_list *d_bl = map->id2bl(sd->shadowform_id); @@ -2494,8 +2506,9 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } - case BL_MOB: { - struct mob_data *md = (struct mob_data*)bl; + case BL_MOB: + { + struct mob_data *md = BL_UCAST(BL_MOB, bl); // Drop previous target mob_slave_keep_target: no. if (!battle_config.mob_slave_keep_target) md->target_id=0; @@ -2505,8 +2518,9 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } - case BL_PET: { - struct pet_data *pd = (struct pet_data*)bl; + case BL_PET: + { + struct pet_data *pd = BL_UCAST(BL_PET, bl); if( pd->pet.intimate <= 0 && !(pd->msd && !pd->msd->state.active) ) { //If logging out, this is deleted on unit->free clif->clearunit_area(bl,clrtype); @@ -2519,7 +2533,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } case BL_HOM: { - struct homun_data *hd = (struct homun_data *)bl; + struct homun_data *hd = BL_UCAST(BL_HOM, bl); if( !hd->homunculus.intimacy && !(hd->master && !hd->master->state.active) ) { //If logging out, this is deleted on unit->free clif->emotion(bl, E_SOB); @@ -2532,7 +2546,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } case BL_MER: { - struct mercenary_data *md = (struct mercenary_data *)bl; + struct mercenary_data *md = BL_UCAST(BL_MER, bl); ud->canact_tick = ud->canmove_tick; if( mercenary->get_lifetime(md) <= 0 && !(md->master && !md->master->state.active) ) { clif->clearunit_area(bl,clrtype); @@ -2544,7 +2558,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i break; } case BL_ELEM: { - struct elemental_data *ed = (struct elemental_data *)bl; + struct elemental_data *ed = BL_UCAST(BL_ELEM, bl); ud->canact_tick = ud->canmove_tick; if( elemental->get_lifetime(ed) <= 0 && !(ed->master && !ed->master->state.active) ) { clif->clearunit_area(bl,clrtype); @@ -2608,7 +2622,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { switch( bl->type ) { case BL_PC: { - struct map_session_data *sd = (struct map_session_data*)bl; + struct map_session_data *sd = BL_UCAST(BL_PC, bl); sd->state.loggingout = 1; @@ -2672,7 +2686,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { } case BL_PET: { - struct pet_data *pd = (struct pet_data*)bl; + struct pet_data *pd = BL_UCAST(BL_PET, bl); struct map_session_data *sd = pd->msd; pet->hungry_timer_delete(pd); if( pd->a_skill ) @@ -2723,7 +2737,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { } case BL_MOB: { - struct mob_data *md = (struct mob_data*)bl; + struct mob_data *md = BL_UCAST(BL_MOB, bl); if( md->spawn_timer != INVALID_TIMER ) { timer->delete(md->spawn_timer,mob->delayspawn); @@ -2783,7 +2797,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { } case BL_HOM: { - struct homun_data *hd = (TBL_HOM*)bl; + struct homun_data *hd = BL_UCAST(BL_HOM, bl); struct map_session_data *sd = hd->master; homun->hunger_timer_delete(hd); if( hd->homunculus.intimacy > 0 ) @@ -2799,7 +2813,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { } case BL_MER: { - struct mercenary_data *md = (TBL_MER*)bl; + struct mercenary_data *md = BL_UCAST(BL_MER, bl); struct map_session_data *sd = md->master; if( mercenary->get_lifetime(md) > 0 ) mercenary->save(md); @@ -2816,7 +2830,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) { break; } case BL_ELEM: { - struct elemental_data *ed = (TBL_ELEM*)bl; + struct elemental_data *ed = BL_UCAST(BL_ELEM, bl); struct map_session_data *sd = ed->master; if( elemental->get_lifetime(ed) > 0 ) elemental->save(ed); |