summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Friis <peavey@placid.dk>2008-10-30 06:03:52 +0000
committerDennis Friis <peavey@placid.dk>2008-10-30 06:03:52 +0000
commit2e8a19a2c2651b1eb371b8c1abfb8f615fc23f70 (patch)
treea84d379175c230fe4713ed32972a0b63e46c3d83
parentadf0d0506d653340849f0caf6cb4ec85dea2fd56 (diff)
downloadtmwa-2e8a19a2c2651b1eb371b8c1abfb8f615fc23f70.tar.gz
tmwa-2e8a19a2c2651b1eb371b8c1abfb8f615fc23f70.tar.bz2
tmwa-2e8a19a2c2651b1eb371b8c1abfb8f615fc23f70.tar.xz
tmwa-2e8a19a2c2651b1eb371b8c1abfb8f615fc23f70.zip
part 2 of fix for mantis #455; free slots takes into account that you can stack onto existing items which are stackable.
-rw-r--r--src/map/trade.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/map/trade.c b/src/map/trade.c
index 5208292..3fef59a 100644
--- a/src/map/trade.c
+++ b/src/map/trade.c
@@ -87,9 +87,12 @@ void trade_tradeack(struct map_session_data *sd,int type)
void trade_tradeadditem(struct map_session_data *sd,int index,int amount)
{
struct map_session_data *target_sd;
+ struct item_data *id;
int trade_i;
int trade_weight=0;
+ int free = 0;
int c;
+ int i;
nullpo_retv(sd);
@@ -100,18 +103,27 @@ void trade_tradeadditem(struct map_session_data *sd,int index,int amount)
clif_tradeadditem(sd,target_sd,0,amount);
}
}else if(amount <= sd->status.inventory[index-2].amount && amount > 0){
+ // determine free slots of receiver
+ for(i=0;i<MAX_INVENTORY;i++){
+ if(target_sd->status.inventory[i].nameid==0 && target_sd->inventory_data[i] == NULL)
+ free++;
+ }
for(trade_i=0; trade_i<10;trade_i++){
if(sd->deal_item_amount[trade_i] == 0){
// calculate trade weight
trade_weight+=sd->inventory_data[index-2]->weight*amount;
- // determine free slots of receiver
- int i, free = 0;
+ // determine if item is a stackable already in receivers inventory, and up free count
for(i=0;i<MAX_INVENTORY;i++){
- if(target_sd->status.inventory[i].nameid==0 && target_sd->inventory_data[i] == NULL)
- free++;
+ if (target_sd->status.inventory[i].nameid==sd->status.inventory[index-2].nameid && target_sd->inventory_data[i] != NULL){
+ id = target_sd->inventory_data[i];
+ if (id->type != 4 && id->type != 5 && id->type != 7 && id->type != 8){
+ free++;
+ break;
+ }
+ }
}
- free -= trade_i;
+
if(target_sd->weight + trade_weight > target_sd->max_weight){
clif_tradeitemok(sd,index,0,1); //fail to add item -- the player was over weighted.
amount = 0; // [MouseJstr]
@@ -136,8 +148,21 @@ void trade_tradeadditem(struct map_session_data *sd,int index,int amount)
}
break;
}else{
+ // calculate weight for stored deal
trade_weight+=sd->inventory_data[sd->deal_item_index[trade_i]-2]->weight*sd->deal_item_amount[trade_i];
+ // count free stackables in stored deal
+ for(i=0;i<MAX_INVENTORY;i++){
+ if (target_sd->status.inventory[i].nameid==sd->status.inventory[sd->deal_item_index[trade_i]-2].nameid && target_sd->inventory_data[i] != NULL){
+ id = target_sd->inventory_data[i];
+ if (id->type != 4 && id->type != 5 && id->type != 7 && id->type != 8){
+ free++;
+ break;
+ }
+ }
+ }
}
+ // used a slot, but might be cancelled out by stackable checks above
+ free--;
}
}
}