From fd625485b8ab08aa9df7115d630076cb2ca6d9af Mon Sep 17 00:00:00 2001 From: ai4rei Date: Sun, 27 Mar 2011 18:43:31 +0000 Subject: * Added separate character state for vending (like for buyingstore), instead of vender_id != 0 (follow up to r14682, related r14713). git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14762 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 6 +++--- src/map/buyingstore.c | 2 +- src/map/chat.c | 4 ++-- src/map/clif.c | 10 +++++----- src/map/mail.c | 2 +- src/map/pc.c | 8 ++++---- src/map/pc.h | 7 ++++--- src/map/script.c | 2 +- src/map/searchstore.c | 2 +- src/map/trade.c | 4 ++-- src/map/unit.c | 5 ++--- src/map/vending.c | 23 +++++++++++------------ 12 files changed, 37 insertions(+), 38 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index b6304349e..090bc0e6e 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -1150,7 +1150,7 @@ ACMD_FUNC(storage) { nullpo_retr(-1, sd); - if (sd->npc_id || sd->vender_id || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag) + if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading || sd->state.storage_flag) return -1; if (storage_storageopen(sd) == 1) @@ -1177,7 +1177,7 @@ ACMD_FUNC(guildstorage) return -1; } - if (sd->npc_id || sd->vender_id || sd->state.buyingstore || sd->state.trading) + if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.trading) return -1; if (sd->state.storage_flag == 1) { @@ -5945,7 +5945,7 @@ ACMD_FUNC(autotrade) return -1; } - if( !sd->vender_id && !sd->state.buyingstore ) { //check if player is vending or buying + if( !sd->state.vending && !sd->state.buyingstore ) { //check if player is vending or buying clif_displaymessage(fd, msg_txt(549)); // "You should have a shop open to use @autotrade." return -1; } diff --git a/src/map/buyingstore.c b/src/map/buyingstore.c index 8f158cd29..5b9734819 100644 --- a/src/map/buyingstore.c +++ b/src/map/buyingstore.c @@ -46,7 +46,7 @@ static unsigned int buyingstore_getuid(void) bool buyingstore_setup(struct map_session_data* sd, unsigned char slots) { - if( !battle_config.feature_buying_store || sd->vender_id || sd->state.buyingstore || sd->state.trading || slots == 0 ) + if( !battle_config.feature_buying_store || sd->state.vending || sd->state.buyingstore || sd->state.trading || slots == 0 ) { return false; } diff --git a/src/map/chat.c b/src/map/chat.c index 4ba784b2e..4c2a001ec 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -69,7 +69,7 @@ int chat_createpcchat(struct map_session_data* sd, const char* title, const char if( sd->chatID ) return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex] - if( sd->vender_id || sd->state.buyingstore ) + if( sd->state.vending || sd->state.buyingstore ) {// not chat, when you already have a store open return 0; } @@ -113,7 +113,7 @@ int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) nullpo_ret(sd); cd = (struct chat_data*)map_id2bl(chatid); - if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->vender_id || sd->state.buyingstore || sd->chatID || cd->users >= cd->limit ) + if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || cd->users >= cd->limit ) { clif_joinchatfail(sd,0); return 0; diff --git a/src/map/clif.c b/src/map/clif.c index 1233c41af..496100c65 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -3645,7 +3645,7 @@ static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_d clif_dispchat(cd,sd->fd); } - if(dstsd->vender_id) + if( dstsd->state.vending ) clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd); if( dstsd->state.buyingstore ) @@ -4077,7 +4077,7 @@ int clif_outsight(struct block_list *bl,va_list ap) if(cd->usersd[0]==sd) clif_dispchat(cd,tsd->fd); } - if(sd->vender_id) + if( sd->state.vending ) clif_closevendingboard(bl,tsd->fd); if( sd->state.buyingstore ) clif_buyingstore_disappear_entry_single(tsd, sd); @@ -10428,7 +10428,7 @@ void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) *------------------------------------------*/ void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) { - if(sd->vender_id) + if( sd->state.vending ) return; if (!pc_iscarton(sd)) return; @@ -10445,7 +10445,7 @@ void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) *------------------------------------------*/ void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) { - if (sd->vender_id) + if( sd->state.vending ) return; if (!pc_iscarton(sd)) return; @@ -12860,7 +12860,7 @@ void clif_Auction_openwindow(struct map_session_data *sd) { int fd = sd->fd; - if( sd->state.storage_flag || sd->vender_id || sd->state.buyingstore || sd->state.trading ) + if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading ) return; WFIFOHEAD(fd,12); diff --git a/src/map/mail.c b/src/map/mail.c index c866bfb60..59afa0421 100644 --- a/src/map/mail.c +++ b/src/map/mail.c @@ -162,7 +162,7 @@ int mail_openmail(struct map_session_data *sd) { nullpo_ret(sd); - if( sd->state.storage_flag || sd->vender_id || sd->state.buyingstore || sd->state.trading ) + if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading ) return 0; clif_Mail_window(sd->fd, 0); diff --git a/src/map/pc.c b/src/map/pc.c index 396eb0ae5..aac8b45ec 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -3435,7 +3435,7 @@ int pc_dropitem(struct map_session_data *sd,int n,int amount) if(sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0 || sd->status.inventory[n].amount < amount || - sd->state.trading || sd->vender_id != 0 || + sd->state.trading || sd->state.vending || !sd->inventory_data[n] //pc_delitem would fail on this case. ) return 0; @@ -3870,7 +3870,7 @@ int pc_putitemtocart(struct map_session_data *sd,int idx,int amount) item_data = &sd->status.inventory[idx]; - if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->vender_id ) + if( item_data->nameid == 0 || amount < 1 || item_data->amount < amount || sd->state.vending ) return 1; if( pc_cart_additem(sd,item_data,amount) == 0 ) @@ -3910,7 +3910,7 @@ int pc_getitemfromcart(struct map_session_data *sd,int idx,int amount) item_data=&sd->status.cart[idx]; - if(item_data->nameid==0 || amount < 1 || item_data->amountvender_id ) + if(item_data->nameid==0 || amount < 1 || item_data->amountstate.vending ) return 1; if((flag = pc_additem(sd,item_data,amount)) == 0) return pc_cart_delitem(sd,idx,amount,0); @@ -7313,7 +7313,7 @@ int pc_checkitem(struct map_session_data *sd) nullpo_ret(sd); - if( sd->vender_id ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam) + if( sd->state.vending ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam) return 0; if( battle_config.item_check ) diff --git a/src/map/pc.h b/src/map/pc.h index 4b9765d7f..28ed28da8 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -131,6 +131,7 @@ struct map_session_data { unsigned debug_remove_map : 1; // temporary state to track double remove_map's [FlavioJS] unsigned buyingstore : 1; unsigned lesseffect : 1; + unsigned vending : 1; unsigned short autoloot; unsigned short autolootid; // [Zephyrus] unsigned noks : 3; // [Zeph Kill Steal Protection] @@ -523,9 +524,9 @@ extern int duel_count; #define pc_setsit(sd) ( (sd)->state.dead_sit = (sd)->vd.dead_sit = 2 ) #define pc_isdead(sd) ( (sd)->state.dead_sit == 1 ) #define pc_issit(sd) ( (sd)->vd.dead_sit == 2 ) -#define pc_isidle(sd) ( (sd)->chatID || (sd)->vender_id || (sd)->state.buyingstore || DIFF_TICK(last_tick, (sd)->idletime) >= battle_config.idle_no_share ) -#define pc_istrading(sd) ( (sd)->npc_id || (sd)->vender_id || (sd)->state.buyingstore || (sd)->state.trading ) -#define pc_cant_act(sd) ( (sd)->npc_id || (sd)->vender_id || (sd)->state.buyingstore || (sd)->chatID || (sd)->sc.opt1 || (sd)->state.trading || (sd)->state.storage_flag ) +#define pc_isidle(sd) ( (sd)->chatID || (sd)->state.vending || (sd)->state.buyingstore || DIFF_TICK(last_tick, (sd)->idletime) >= battle_config.idle_no_share ) +#define pc_istrading(sd) ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->state.trading ) +#define pc_cant_act(sd) ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->chatID || (sd)->sc.opt1 || (sd)->state.trading || (sd)->state.storage_flag ) #define pc_setdir(sd,b,h) ( (sd)->ud.dir = (b) ,(sd)->head_dir = (h) ) #define pc_setchatid(sd,n) ( (sd)->chatID = n ) #define pc_ishiding(sd) ( (sd)->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_CHASEWALK) ) diff --git a/src/map/script.c b/src/map/script.c index dec4a3f89..3cb469ac5 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -13111,7 +13111,7 @@ BUILDIN_FUNC(checkvending) // check vending [Nab4] sd = script_rid2sd(st); if(sd) - script_pushint(st,(sd->vender_id != 0)); + script_pushint(st,sd->state.vending); else script_pushint(st,0); diff --git a/src/map/searchstore.c b/src/map/searchstore.c index d7378ab36..76f0d4e2e 100644 --- a/src/map/searchstore.c +++ b/src/map/searchstore.c @@ -71,7 +71,7 @@ static bool searchstore_hasstore(struct map_session_data* sd, unsigned char type { switch( type ) { - case SEARCHTYPE_VENDING: return (bool)( sd->vender_id != 0 ); + case SEARCHTYPE_VENDING: return sd->state.vending; case SEARCHTYPE_BUYING_STORE: return sd->state.buyingstore; } return false; diff --git a/src/map/trade.c b/src/map/trade.c index bedbb9451..fb9fecbac 100644 --- a/src/map/trade.c +++ b/src/map/trade.c @@ -138,8 +138,8 @@ void trade_tradeack(struct map_session_data *sd, int type) } //Check if you can start trade. - if (sd->npc_id || sd->vender_id || sd->state.buyingstore || sd->state.storage_flag || - tsd->npc_id || tsd->vender_id || tsd->state.buyingstore || tsd->state.storage_flag) + if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.storage_flag || + tsd->npc_id || tsd->state.vending || tsd->state.buyingstore || tsd->state.storage_flag) { //Fail clif_tradestart(sd, 2); clif_tradestart(tsd, 2); diff --git a/src/map/unit.c b/src/map/unit.c index 2467baf86..da1ce1c14 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -802,7 +802,7 @@ int unit_can_move(struct block_list *bl) if (sd && ( pc_issit(sd) || - sd->vender_id || + sd->state.vending || sd->state.buyingstore || sd->state.blockedmove )) @@ -1871,8 +1871,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file, chat_leavechat(sd,0); if(sd->trade_partner) trade_tradecancel(sd); - if(sd->vender_id) - vending_closevending(sd); + vending_closevending(sd); buyingstore_close(sd); searchstore_close(sd); if(sd->state.storage_flag == 1) diff --git a/src/map/vending.c b/src/map/vending.c index 08e15d733..c5ead6513 100644 --- a/src/map/vending.c +++ b/src/map/vending.c @@ -19,16 +19,11 @@ #include #include -static int vending_nextid = 1; +static int vending_nextid = 0; /// Returns an unique vending shop id. static int vending_getuid(void) { - if(!vending_nextid) - {// wrapped around, 0 is reserved for "not vending" state on eathena - vending_nextid = 1; - } - return vending_nextid++; } @@ -39,8 +34,11 @@ void vending_closevending(struct map_session_data* sd) { nullpo_retv(sd); - sd->vender_id = 0; - clif_closevendingboard(&sd->bl,0); + if( sd->state.vending ) + { + sd->state.vending = false; + clif_closevendingboard(&sd->bl, 0); + } } /*========================================== @@ -53,7 +51,7 @@ void vending_vendinglistreq(struct map_session_data* sd, int id) if( (vsd = map_id2sd(id)) == NULL ) return; - if( vsd->vender_id == 0 ) + if( !vsd->state.vending ) return; // not vending if ( !pc_can_give_items(pc_isGM(sd)) || !pc_can_give_items(pc_isGM(vsd)) ) //check if both GMs are allowed to trade @@ -78,7 +76,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui struct map_session_data* vsd = map_id2sd(aid); nullpo_retv(sd); - if( vsd == NULL || vsd->vender_id == 0 || vsd->bl.id == sd->bl.id ) + if( vsd == NULL || !vsd->state.vending || vsd->bl.id == sd->bl.id ) return; // invalid shop if( vsd->vender_id != uid ) @@ -309,6 +307,7 @@ void vending_openvending(struct map_session_data* sd, const char* message, bool return; } + sd->state.vending = true; sd->vender_id = vending_getuid(); sd->vend_num = i; safestrncpy(sd->message, message, MESSAGE_SIZE); @@ -324,7 +323,7 @@ bool vending_search(struct map_session_data* sd, unsigned short nameid) { int i; - if( !sd->vender_id ) + if( !sd->state.vending ) {// not vending return false; } @@ -347,7 +346,7 @@ bool vending_searchall(struct map_session_data* sd, const struct s_search_store_ unsigned int idx, cidx; struct item* it; - if( !sd->vender_id ) + if( !sd->state.vending ) {// not vending return true; } -- cgit v1.2.3-70-g09d2