summaryrefslogtreecommitdiff
path: root/src/map/pc.c
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-05-18 16:55:07 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-05-18 16:55:07 +0000
commit3c0bb6cec420f251ffbc45eaf9196e11fc72dfa1 (patch)
treeffcce8e25146fc45cf14d9ba9257b10834e57744 /src/map/pc.c
parent1f82fb3ed60e57b7fecc18cd871747af3dca461b (diff)
downloadhercules-3c0bb6cec420f251ffbc45eaf9196e11fc72dfa1.tar.gz
hercules-3c0bb6cec420f251ffbc45eaf9196e11fc72dfa1.tar.bz2
hercules-3c0bb6cec420f251ffbc45eaf9196e11fc72dfa1.tar.xz
hercules-3c0bb6cec420f251ffbc45eaf9196e11fc72dfa1.zip
- Rewrote/cleaned up several functions in storage.c
- Optimized pc_additem comparisons to account for items with more than four slots. - Updated clif.c to enable retrieval of items from cart/storage while trading. Exception is retrieving items from the cart while vending. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6642 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/pc.c')
-rw-r--r--src/map/pc.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/src/map/pc.c b/src/map/pc.c
index 1a3a88486..1797bb36b 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -2384,30 +2384,30 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount)
{
struct item_data *data;
int i;
- long w;
+ int w;
nullpo_retr(1, sd);
nullpo_retr(1, item_data);
if(item_data->nameid <= 0 || amount <= 0)
return 1;
+ if(amount > MAX_AMOUNT)
+ return 5;
+
data = itemdb_search(item_data->nameid);
w = data->weight*amount;
- if(w + (long)sd->weight > (long)sd->max_weight || w + (long)sd->weight < 0) //Weight overflow check?
+ if(w > sd->max_weight - sd->weight)
return 2;
i = MAX_INVENTORY;
- if (!itemdb_isequip2(data)){
- // 装 備品ではないので、既所有品なら個数のみ変化させる
+ if (!itemdb_isequip2(data)){ //Stackable
for (i = 0; i < MAX_INVENTORY; i++)
if(sd->status.inventory[i].nameid == item_data->nameid &&
- sd->status.inventory[i].card[0] == item_data->card[0] &&
- sd->status.inventory[i].card[1] == item_data->card[1] &&
- sd->status.inventory[i].card[2] == item_data->card[2] &&
- sd->status.inventory[i].card[3] == item_data->card[3])
+ memcmp(&sd->status.inventory[i].card,&item_data->card,
+ sizeof(item_data->card))==0)
{
- if (amount < 0 || amount > MAX_AMOUNT || sd->status.inventory[i].amount + amount > MAX_AMOUNT)
+ if (amount > MAX_AMOUNT - sd->status.inventory[i].amount)
return 5;
sd->status.inventory[i].amount += amount;
clif_additem(sd,i,amount,0);
@@ -2415,22 +2415,18 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount)
}
}
if (i >= MAX_INVENTORY){
- // 装 備品か未所有品だったので空き欄へ追加
i = pc_search_inventory(sd,0);
- if(i >= 0) {
- // clear equips field first, just in case
- if (item_data->equip != 0)
- item_data->equip = 0;
- memcpy(&sd->status.inventory[i], item_data, sizeof(sd->status.inventory[0]));
- sd->status.inventory[i].amount = amount;
- sd->inventory_data[i] = data;
- clif_additem(sd,i,amount,0);
- }
- else return 4;
- }
- sd->weight += (int)w;
+ if(i<0) return 4;
+ // clear equips field first, just in case
+ if (item_data->equip)
+ item_data->equip = 0;
+ memcpy(&sd->status.inventory[i], item_data, sizeof(item_data));
+ sd->status.inventory[i].amount = amount;
+ sd->inventory_data[i] = data;
+ clif_additem(sd,i,amount,0);
+ }
+ sd->weight += w;
clif_updatestatus(sd,SP_WEIGHT);
-
return 0;
}
@@ -2857,7 +2853,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->amount<amount || sd->vender_id )
+ if(item_data->nameid==0 || amount < 1 || item_data->amount<amount || sd->vender_id )
return 1;
if((flag = pc_additem(sd,item_data,amount)) == 0)
return pc_cart_delitem(sd,idx,amount,0);