diff options
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 1403 |
1 files changed, 729 insertions, 674 deletions
diff --git a/src/map/script.c b/src/map/script.c index 591bca68f..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); @@ -7253,7 +7255,7 @@ BUILDIN(getitem2) if (item_data == NULL) return -1; if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR) { - if(ref > MAX_REFINE) ref = MAX_REFINE; + ref = cap_value(ref, 0, MAX_REFINE); } else if(item_data->type==IT_PETEGG) { iden = 1; @@ -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; - if(drop->item_data.nameid==item) - (*amount)+=drop->item_data.amount; + 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; 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); + + nullpo_ret(bl); + Assert_ret(bl->type == BL_PC); + sd = BL_UCAST(BL_PC, bl); - clif->soundeffect((TBL_PC *)bl, bl, name, type); + 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; @@ -14109,6 +14088,7 @@ BUILDIN(getlook) case LOOK_SHIELD: val = sd->status.shield; break; //8 case LOOK_SHOES: break; //9 case LOOK_ROBE: val = sd->status.robe; break; //12 + case LOOK_BODY2: val=sd->status.body; break; //13 } script_pushint(st,val); @@ -14121,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; @@ -14164,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; @@ -14363,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; @@ -14377,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); @@ -14425,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; @@ -14477,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; @@ -14555,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; @@ -14594,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; @@ -14621,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); @@ -14636,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); @@ -14687,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); @@ -14981,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"); @@ -15040,7 +15017,7 @@ BUILDIN(implode) const char *name; uint32 array_size, id; - TBL_PC* sd = NULL; + struct map_session_data *sd = NULL; char *output; @@ -15735,11 +15712,81 @@ BUILDIN(md5) return true; } +BUILDIN(swap) +{ + struct map_session_data *sd = NULL; + struct script_data *data1, *data2; + const char *varname1, *varname2; + int64 uid1, uid2; + + data1 = script_getdata(st,2); + data2 = script_getdata(st,3); + + if (!data_isreference(data1) || !data_isreference(data2) || reference_toconstant(data1) || reference_toconstant(data2)) { + st->state = END; + return true; // avoid print error message twice + } + + if (reference_toparam(data1) || reference_toparam(data2)) { + ShowError("script:swap: detected parameter type constant.\n"); + if (reference_toparam(data1)) + script->reportdata(data1); + if (reference_toparam(data2)) + script->reportdata(data2); + st->state = END; + return false; + } + + varname1 = reference_getname(data1); + varname2 = reference_getname(data2); + + if ((is_string_variable(varname1) && !is_string_variable(varname2)) || (!is_string_variable(varname1) && is_string_variable(varname2))) { + ShowError("script:swap: both sides must be same integer or string type.\n"); + script->reportdata(data1); + script->reportdata(data2); + st->state = END; + return false; + } + + if (not_server_variable(*varname1) || not_server_variable(*varname2)) { + sd = script->rid2sd(st); + if (sd == NULL) + return true; // avoid print error message twice + } + + uid1 = reference_getuid(data1); + uid2 = reference_getuid(data2); + + if (is_string_variable(varname1)) { + const char *value1, *value2; + + value1 = script_getstr(st,2); + value2 = script_getstr(st,3); + + if (strcmpi(value1, value2)) { + script->set_reg(st, sd, uid1, varname1, (void*)(value2), script_getref(st,3)); + script->set_reg(st, sd, uid2, varname2, (void*)(value1), script_getref(st,2)); + } + } + else { + int value1, value2; + + value1 = script_getnum(st,2); + value2 = script_getnum(st,3); + + if (value1 != value2) { + script->set_reg(st, sd, uid1, varname1, (void*)h64BPTRSIZE(value2), script_getref(st,3)); + script->set_reg(st, sd, uid2, varname2, (void*)h64BPTRSIZE(value1), script_getref(st,2)); + } + } + return true; +} + // [zBuffer] List of dynamic var commands ---> BUILDIN(setd) { - TBL_PC *sd=NULL; + struct map_session_data *sd = NULL; char varname[100]; const char *buffer; int elem; @@ -15770,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; @@ -15897,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 @@ -15927,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; @@ -16071,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; @@ -16282,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)); @@ -16299,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)); @@ -16315,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)); @@ -16341,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; } @@ -16393,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,""); @@ -16418,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); @@ -16434,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); @@ -16455,7 +16503,7 @@ BUILDIN(pcfollow) { BUILDIN(pcstopfollow) { int id; - TBL_PC *sd = NULL; + struct map_session_data *sd = NULL; id = script_getnum(st,2); @@ -16515,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); @@ -16569,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); @@ -16598,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 { @@ -16618,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); @@ -16647,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; @@ -16717,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); @@ -16751,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); @@ -16837,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; @@ -16952,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); @@ -16965,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); @@ -17407,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; @@ -17451,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; } @@ -17512,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 ) @@ -17575,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); @@ -17965,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; @@ -18140,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); @@ -18152,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; @@ -18349,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); @@ -18363,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); @@ -18382,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); @@ -18644,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; @@ -18663,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); } } @@ -18843,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 ); @@ -18929,8 +18987,6 @@ BUILDIN(montransform) { if (tick != 0) { struct map_session_data *sd = script->id2sd(st, bl->id); - struct mob_db *monster = mob->db(mob_id); - char msg[CHAT_SIZE_MAX]; if (sd == NULL) return true; @@ -18945,8 +19001,6 @@ BUILDIN(montransform) { return true; } - sprintf(msg, msg_sd(sd,1485), monster->name); // Traaaansformation-!! %s form!! - clif->ShowScript(&sd->bl, msg); status_change_end(bl, SC_MONSTER_TRANSFORM, INVALID_TIMER); // Clear previous sc_start2(NULL, bl, SC_MONSTER_TRANSFORM, 100, mob_id, type, tick); @@ -19517,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; @@ -19553,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; @@ -20492,6 +20546,7 @@ void script_parse_builtin(void) { BUILDIN_DEF(min, "i*"), BUILDIN_DEF(max, "i*"), BUILDIN_DEF(md5,"s"), + BUILDIN_DEF(swap,"rr"), // [zBuffer] List of dynamic var commands ---> BUILDIN_DEF(getd,"s"), BUILDIN_DEF(setd,"sv"), |