Skip to content

Commit

Permalink
Merge pull request #1034 from HerculesWS/bl_cast
Browse files Browse the repository at this point in the history
Changed all TBL_* to the appropriate structs
  • Loading branch information
4144 committed Jan 6, 2016
2 parents 756be98 + e3eac13 commit d5199ce
Show file tree
Hide file tree
Showing 34 changed files with 2,988 additions and 2,368 deletions.
126 changes: 57 additions & 69 deletions src/map/atcommand.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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!

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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>).
Expand All @@ -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 )
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>)
Expand Down Expand Up @@ -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 )
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d5199ce

Please sign in to comment.