-add enum for return value of pc_additem

-revert r17142 sd.guild assignment

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@17248 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
glighta 2013-04-11 13:28:30 +00:00
parent 7d46012f3d
commit b43102152f
10 changed files with 67 additions and 64 deletions

View File

@ -331,7 +331,7 @@ void buyingstore_trade(struct map_session_data* sd, int account_id, unsigned int
return; return;
} }
if( pc_checkadditem(pl_sd, nameid, amount) == ADDITEM_OVERAMOUNT ) if( pc_checkadditem(pl_sd, nameid, amount) == CHKADDITEM_OVERAMOUNT )
{// buyer does not have enough space for this item {// buyer does not have enough space for this item
clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid); clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
return; return;

View File

@ -78,7 +78,7 @@ static void cashshop_read_db_txt( void ){
if( !cashshop_parse_dbrow( str, path, lines ) ) if( !cashshop_parse_dbrow( str, path, lines ) )
continue; continue;
count++; count++;
} }
@ -91,7 +91,7 @@ static void cashshop_read_db_txt( void ){
static int cashshop_read_db_sql( void ){ static int cashshop_read_db_sql( void ){
const char* cash_db_name[] = { item_cash_db_db, item_cash_db2_db }; const char* cash_db_name[] = { item_cash_db_db, item_cash_db2_db };
int fi; int fi;
for( fi = 0; fi < ARRAYLENGTH( cash_db_name ); ++fi ){ for( fi = 0; fi < ARRAYLENGTH( cash_db_name ); ++fi ){
uint32 lines = 0, count = 0; uint32 lines = 0, count = 0;
@ -211,14 +211,14 @@ void cashshop_buylist( struct map_session_data* sd, uint32 kafrapoints, int n, u
} }
switch( pc_checkadditem( sd, nameid, quantity ) ){ switch( pc_checkadditem( sd, nameid, quantity ) ){
case ADDITEM_EXIST: case CHKADDITEM_EXIST:
break; break;
case ADDITEM_NEW: case CHKADDITEM_NEW:
new_++; new_++;
break; break;
case ADDITEM_OVERAMOUNT: case CHKADDITEM_OVERAMOUNT:
clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_OVER_PRODUCT_TOTAL_CNT ); clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_OVER_PRODUCT_TOTAL_CNT );
return; return;
} }
@ -254,16 +254,16 @@ void cashshop_buylist( struct map_session_data* sd, uint32 kafrapoints, int n, u
item_tmp.identify = 1; item_tmp.identify = 1;
switch( pc_additem( sd, &item_tmp, quantity, LOG_TYPE_CASH ) ){ switch( pc_additem( sd, &item_tmp, quantity, LOG_TYPE_CASH ) ){
case 2: case ADDITEM_OVERWEIGHT:
clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_INVENTORY_WEIGHT ); clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_INVENTORY_WEIGHT );
return; return;
case 4: case ADDITEM_OVERITEM:
clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_INVENTORY_ITEMCNT ); clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_INVENTORY_ITEMCNT );
return; return;
case 5: case ADDITEM_OVERAMOUNT:
clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_OVER_PRODUCT_TOTAL_CNT ); clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_OVER_PRODUCT_TOTAL_CNT );
return; return;
case 7: case ADDITEM_STACKLIMIT:
clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_RUNE_OVERCOUNT ); clif_cashshop_result( sd, nameid, CASHSHOP_RESULT_ERROR_RUNE_OVERCOUNT );
return; return;
} }

View File

@ -14025,10 +14025,10 @@ void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
return; return;
switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) { switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
case ADDITEM_NEW: case CHKADDITEM_NEW:
fail = ( pc_inventoryblank(sd) == 0 ); fail = ( pc_inventoryblank(sd) == 0 );
break; break;
case ADDITEM_OVERAMOUNT: case CHKADDITEM_OVERAMOUNT:
fail = true; fail = true;
} }
@ -16584,7 +16584,7 @@ void clif_cashshop_result( struct map_session_data *sd, uint16 item_id, uint16 r
WFIFOW( sd->fd, 6 ) = result; WFIFOW( sd->fd, 6 ) = result;
WFIFOL( sd->fd, 8 ) = sd->cashPoints; WFIFOL( sd->fd, 8 ) = sd->cashPoints;
WFIFOL( sd->fd, 12 ) = sd->kafraPoints; WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
WFIFOSET( sd->fd, 16 ); WFIFOSET( sd->fd, 16 );
} }
/*========================================== /*==========================================

View File

@ -406,17 +406,11 @@ int guild_created(int account_id,int guild_id)
if(sd==NULL) if(sd==NULL)
return 0; return 0;
if(!guild_id) { if(!guild_id) {
clif_guild_created(sd, 2); // Creation failure (presence of the same name Guild) clif_guild_created(sd, 2); // Creation failure (presence of the same name Guild)
return 0; return 0;
} }
guild = guild_search( guild_id );
if( !guild ){ //guild not found
return -1;
}
sd->status.guild_id = guild_id; sd->status.guild_id = guild_id;
sd->guild = guild;
clif_guild_created(sd,0); clif_guild_created(sd,0);
if(battle_config.guild_emperium_check) if(battle_config.guild_emperium_check)
pc_delitem(sd,pc_search_inventory(sd,ITEMID_EMPERIUM),1,0,0,LOG_TYPE_CONSUME); //emperium consumption pc_delitem(sd,pc_search_inventory(sd,ITEMID_EMPERIUM),1,0,0,LOG_TYPE_CONSUME); //emperium consumption
@ -471,6 +465,7 @@ int guild_check_member(struct guild *g)
i = guild_getindex(g,sd->status.account_id,sd->status.char_id); i = guild_getindex(g,sd->status.account_id,sd->status.char_id);
if (i < 0) { if (i < 0) {
sd->guild = NULL;
sd->status.guild_id=0; sd->status.guild_id=0;
sd->guild_emblem_id=0; sd->guild_emblem_id=0;
ShowWarning("guild: check_member %d[%s] is not member\n",sd->status.account_id,sd->status.name); ShowWarning("guild: check_member %d[%s] is not member\n",sd->status.account_id,sd->status.name);
@ -611,7 +606,7 @@ int guild_recv_info(struct guild *sg)
} }
} }
//Occurrence of an event //Occurrence of an event
if (guild_infoevent_db->remove(guild_infoevent_db, db_i2key(sg->guild_id), &data)) { if (guild_infoevent_db->remove(guild_infoevent_db, db_i2key(sg->guild_id), &data)) {
struct eventlist *ev = db_data2ptr(&data), *ev2; struct eventlist *ev = db_data2ptr(&data), *ev2;
while(ev) { while(ev) {

View File

@ -1335,10 +1335,10 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, uns
switch( pc_checkadditem(sd,nameid,amount) ) switch( pc_checkadditem(sd,nameid,amount) )
{ {
case ADDITEM_NEW: case CHKADDITEM_NEW:
new_++; new_++;
break; break;
case ADDITEM_OVERAMOUNT: case CHKADDITEM_OVERAMOUNT:
return 3; return 3;
} }
@ -1443,11 +1443,11 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po
switch( pc_checkadditem(sd, nameid, amount) ) switch( pc_checkadditem(sd, nameid, amount) )
{ {
case ADDITEM_NEW: case CHKADDITEM_NEW:
if( pc_inventoryblank(sd) == 0 ) if( pc_inventoryblank(sd) == 0 )
return 3; return 3;
break; break;
case ADDITEM_OVERAMOUNT: case CHKADDITEM_OVERAMOUNT:
return 3; return 3;
} }
@ -1542,14 +1542,14 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list)
switch( pc_checkadditem(sd,nameid,amount) ) switch( pc_checkadditem(sd,nameid,amount) )
{ {
case ADDITEM_EXIST: case CHKADDITEM_EXIST:
break; break;
case ADDITEM_NEW: case CHKADDITEM_NEW:
new_++; new_++;
break; break;
case ADDITEM_OVERAMOUNT: case CHKADDITEM_OVERAMOUNT:
return 2; return 2;
} }

View File

@ -3586,26 +3586,26 @@ int pc_checkadditem(struct map_session_data *sd,int nameid,int amount)
nullpo_ret(sd); nullpo_ret(sd);
if(amount > MAX_AMOUNT) if(amount > MAX_AMOUNT)
return ADDITEM_OVERAMOUNT; return CHKADDITEM_OVERAMOUNT;
data = itemdb_search(nameid); data = itemdb_search(nameid);
if(!itemdb_isstackable2(data)) if(!itemdb_isstackable2(data))
return ADDITEM_NEW; return CHKADDITEM_NEW;
if( data->stack.inventory && amount > data->stack.amount ) if( data->stack.inventory && amount > data->stack.amount )
return ADDITEM_OVERAMOUNT; return CHKADDITEM_OVERAMOUNT;
for(i=0;i<MAX_INVENTORY;i++){ for(i=0;i<MAX_INVENTORY;i++){
// FIXME: This does not consider the checked item's cards, thus could check a wrong slot for stackability. // FIXME: This does not consider the checked item's cards, thus could check a wrong slot for stackability.
if(sd->status.inventory[i].nameid==nameid){ if(sd->status.inventory[i].nameid==nameid){
if( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->status.inventory[i].amount ) ) if( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->status.inventory[i].amount ) )
return ADDITEM_OVERAMOUNT; return CHKADDITEM_OVERAMOUNT;
return ADDITEM_EXIST; return CHKADDITEM_EXIST;
} }
} }
return ADDITEM_NEW; return CHKADDITEM_NEW;
} }
/*========================================== /*==========================================
@ -3810,14 +3810,14 @@ int pc_search_inventory(struct map_session_data *sd,int item_id)
/*========================================== /*==========================================
* Attempt to add a new item to inventory. * Attempt to add a new item to inventory.
* Return: * Return:
0 = success 0 = success
1 = invalid itemid not found or negative amount 1 = invalid itemid not found or negative amount
2 = overweight 2 = overweight
3 = ? 3 = ?
4 = no free place found 4 = no free place found
5 = max amount reached 5 = max amount reached
6 = ? 6 = ?
7 = stack limitation 7 = stack limitation
*------------------------------------------*/ *------------------------------------------*/
int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_log_pick_type log_type) int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_log_pick_type log_type)
{ {
@ -3829,20 +3829,20 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l
nullpo_retr(1, item_data); nullpo_retr(1, item_data);
if( item_data->nameid <= 0 || amount <= 0 ) if( item_data->nameid <= 0 || amount <= 0 )
return 1; return ADDITEM_INVALID;
if( amount > MAX_AMOUNT ) if( amount > MAX_AMOUNT )
return 5; return ADDITEM_OVERAMOUNT;
data = itemdb_search(item_data->nameid); data = itemdb_search(item_data->nameid);
if( data->stack.inventory && amount > data->stack.amount ) if( data->stack.inventory && amount > data->stack.amount )
{// item stack limitation {// item stack limitation
return 7; return ADDITEM_STACKLIMIT;
} }
w = data->weight*amount; w = data->weight*amount;
if(sd->weight + w > sd->max_weight) if(sd->weight + w > sd->max_weight)
return 2; return ADDITEM_OVERWEIGHT;
i = MAX_INVENTORY; i = MAX_INVENTORY;
@ -3865,7 +3865,7 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l
{ {
i = pc_search_inventory(sd,0); i = pc_search_inventory(sd,0);
if( i < 0 ) if( i < 0 )
return 4; return ADDITEM_OVERITEM;
memcpy(&sd->status.inventory[i], item_data, sizeof(sd->status.inventory[0])); memcpy(&sd->status.inventory[i], item_data, sizeof(sd->status.inventory[0]));
// clear equips field first, just in case // clear equips field first, just in case
@ -3900,7 +3900,7 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l
} }
} }
return 0; return ADDITEM_SUCCESS;
} }
/*========================================== /*==========================================

View File

@ -914,7 +914,15 @@ int pc_readdb(void);
int do_init_pc(void); int do_init_pc(void);
void do_final_pc(void); void do_final_pc(void);
enum {ADDITEM_EXIST,ADDITEM_NEW,ADDITEM_OVERAMOUNT}; enum {CHKADDITEM_EXIST,CHKADDITEM_NEW,CHKADDITEM_OVERAMOUNT};
enum {
ADDITEM_SUCCESS,
ADDITEM_INVALID,
ADDITEM_OVERWEIGHT,
ADDITEM_OVERITEM=4,
ADDITEM_OVERAMOUNT,
ADDITEM_STACKLIMIT=7
};
// timer for night.day // timer for night.day
extern int day_timer_tid; extern int day_timer_tid;

View File

@ -6162,10 +6162,10 @@ BUILDIN_FUNC(checkweight)
switch( pc_checkadditem(sd, nameid, amount) ) switch( pc_checkadditem(sd, nameid, amount) )
{ {
case ADDITEM_EXIST: case CHKADDITEM_EXIST:
// item is already in inventory, but there is still space for the requested amount // item is already in inventory, but there is still space for the requested amount
break; break;
case ADDITEM_NEW: case CHKADDITEM_NEW:
if( itemdb_isstackable(nameid) ) {// stackable if( itemdb_isstackable(nameid) ) {// stackable
amount2++; amount2++;
if( slots < amount2 ) { if( slots < amount2 ) {
@ -6181,7 +6181,7 @@ BUILDIN_FUNC(checkweight)
} }
} }
break; break;
case ADDITEM_OVERAMOUNT: case CHKADDITEM_OVERAMOUNT:
script_pushint(st,0); script_pushint(st,0);
return 0; return 0;
} }
@ -6267,10 +6267,10 @@ BUILDIN_FUNC(checkweight2)
continue; continue;
} }
switch( pc_checkadditem(sd, nameid, amount) ) { switch( pc_checkadditem(sd, nameid, amount) ) {
case ADDITEM_EXIST: case CHKADDITEM_EXIST:
// item is already in inventory, but there is still space for the requested amount // item is already in inventory, but there is still space for the requested amount
break; break;
case ADDITEM_NEW: case CHKADDITEM_NEW:
if( itemdb_isstackable(nameid) ){// stackable if( itemdb_isstackable(nameid) ){// stackable
amount2++; amount2++;
if( slots < amount2 ) if( slots < amount2 )
@ -6283,7 +6283,7 @@ BUILDIN_FUNC(checkweight2)
} }
} }
break; break;
case ADDITEM_OVERAMOUNT: case CHKADDITEM_OVERAMOUNT:
fail = 1; fail = 1;
} //end switch } //end switch
} //end loop DO NOT break it prematurly we need to depop all stack } //end loop DO NOT break it prematurly we need to depop all stack

View File

@ -16059,7 +16059,7 @@ int skill_can_produce_mix (struct map_session_data *sd, int nameid, int trigger,
if( i >= MAX_SKILL_PRODUCE_DB ) if( i >= MAX_SKILL_PRODUCE_DB )
return 0; return 0;
if( pc_checkadditem(sd, nameid, qty) == ADDITEM_OVERAMOUNT ) if( pc_checkadditem(sd, nameid, qty) == CHKADDITEM_OVERAMOUNT )
{// cannot carry the produced stuff {// cannot carry the produced stuff
return 0; return 0;
} }

View File

@ -59,7 +59,7 @@ void vending_vendinglistreq(struct map_session_data* sd, int id)
{ // GM is not allowed to trade { // GM is not allowed to trade
clif_displaymessage(sd->fd, msg_txt(246)); clif_displaymessage(sd->fd, msg_txt(246));
return; return;
} }
sd->vended_id = vsd->vender_id; // register vending uid sd->vended_id = vsd->vender_id; // register vending uid
@ -139,11 +139,11 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
clif_buyvending(sd, idx, amount, 2); // you can not buy, because overweight clif_buyvending(sd, idx, amount, 2); // you can not buy, because overweight
return; return;
} }
//Check to see if cart/vend info is in sync. //Check to see if cart/vend info is in sync.
if( vending[j].amount > vsd->status.cart[idx].amount ) if( vending[j].amount > vsd->status.cart[idx].amount )
vending[j].amount = vsd->status.cart[idx].amount; vending[j].amount = vsd->status.cart[idx].amount;
// if they try to add packets (example: get twice or more 2 apples if marchand has only 3 apples). // if they try to add packets (example: get twice or more 2 apples if marchand has only 3 apples).
// here, we check cumulative amounts // here, we check cumulative amounts
if( vending[j].amount < amount ) if( vending[j].amount < amount )
@ -152,18 +152,18 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
clif_buyvending(sd, idx, vsd->vending[j].amount, 4); // not enough quantity clif_buyvending(sd, idx, vsd->vending[j].amount, 4); // not enough quantity
return; return;
} }
vending[j].amount -= amount; vending[j].amount -= amount;
switch( pc_checkadditem(sd, vsd->status.cart[idx].nameid, amount) ) { switch( pc_checkadditem(sd, vsd->status.cart[idx].nameid, amount) ) {
case ADDITEM_EXIST: case CHKADDITEM_EXIST:
break; //We'd add this item to the existing one (in buyers inventory) break; //We'd add this item to the existing one (in buyers inventory)
case ADDITEM_NEW: case CHKADDITEM_NEW:
new_++; new_++;
if (new_ > blank) if (new_ > blank)
return; //Buyer has no space in his inventory return; //Buyer has no space in his inventory
break; break;
case ADDITEM_OVERAMOUNT: case CHKADDITEM_OVERAMOUNT:
return; //too many items return; //too many items
} }
} }
@ -199,7 +199,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
{ {
if( vsd->vending[i].amount == 0 ) if( vsd->vending[i].amount == 0 )
continue; continue;
if( cursor != i ) // speedup if( cursor != i ) // speedup
{ {
vsd->vending[cursor].index = vsd->vending[i].index; vsd->vending[cursor].index = vsd->vending[i].index;