summaryrefslogtreecommitdiff
path: root/src/map/pc.c
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-12-14 01:20:44 +0300
committerAndrei Karas <akaras@inbox.ru>2018-12-14 23:52:47 +0300
commitbc682624496b854607b8e1bd976bb317eb8b0d4f (patch)
tree57cb030d5c5d0f2865c05ea641041634f7855258 /src/map/pc.c
parent1a26402c3bd986d0bba0435bfbd62e32abf07302 (diff)
downloadhercules-bc682624496b854607b8e1bd976bb317eb8b0d4f.tar.gz
hercules-bc682624496b854607b8e1bd976bb317eb8b0d4f.tar.bz2
hercules-bc682624496b854607b8e1bd976bb317eb8b0d4f.tar.xz
hercules-bc682624496b854607b8e1bd976bb317eb8b0d4f.zip
Add inventory size field into db and using it in server.
Diffstat (limited to 'src/map/pc.c')
-rw-r--r--src/map/pc.c82
1 files changed, 40 insertions, 42 deletions
diff --git a/src/map/pc.c b/src/map/pc.c
index 39358adf4..ad8cf2a94 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -568,7 +568,7 @@ static void pc_rental_expire(struct map_session_data *sd, int i)
int nameid;
nullpo_retv(sd);
- Assert_retv(i >= 0 && i < MAX_INVENTORY);
+ Assert_retv(i >= 0 && i < sd->status.inventorySize);
nameid = sd->status.inventory[i].nameid;
/* Soon to be dropped, we got plans to integrate it with item db */
@@ -637,11 +637,11 @@ static void pc_rental_expire(struct map_session_data *sd, int i)
}
static void pc_inventory_rentals(struct map_session_data *sd)
{
- int i, c = 0;
+ int c = 0;
int64 expire_tick, next_tick = INT64_MAX;
nullpo_retv(sd);
- for( i = 0; i < MAX_INVENTORY; i++ )
+ for (int i = 0; i < sd->status.inventorySize; i++ )
{ // Check for Rentals on Inventory
if( sd->status.inventory[i].nameid == 0 )
continue; // Nothing here
@@ -773,7 +773,6 @@ static int pc_setnewpc(struct map_session_data *sd, int account_id, int char_id,
sd->battle_status.speed = sd->base_status.speed = DEFAULT_WALK_SPEED;
sd->state.warp_clean = 1;
sd->catch_target_class = -1;
- sd->inventorySize = 100;
return 0;
}
@@ -783,7 +782,7 @@ static int pc_equippoint(struct map_session_data *sd, int n)
int ep = 0;
nullpo_ret(sd);
- Assert_ret(n >= 0 && n < MAX_INVENTORY);
+ Assert_ret(n >= 0 && n < sd->status.inventorySize);
if(!sd->inventory_data[n])
return 0;
@@ -839,11 +838,9 @@ static int pc_item_equippoint(struct map_session_data *sd, struct item_data *id)
static int pc_setinventorydata(struct map_session_data *sd)
{
- int i;
-
nullpo_ret(sd);
- for (i = 0; i < MAX_INVENTORY; i++) {
+ for (int i = 0; i < sd->status.inventorySize; i++) {
int id = sd->status.inventory[i].nameid;
sd->inventory_data[i] = id?itemdb->search(id):NULL;
}
@@ -903,7 +900,7 @@ static int pc_setequipindex(struct map_session_data *sd)
for(i=0;i<EQI_MAX;i++)
sd->equip_index[i] = -1;
- for(i=0;i<MAX_INVENTORY;i++) {
+ for (i = 0; i < sd->status.inventorySize; i++) {
if(sd->status.inventory[i].nameid <= 0)
continue;
if(sd->status.inventory[i].equip) {
@@ -1074,7 +1071,7 @@ static int pc_isequip(struct map_session_data *sd, int n)
struct item_data *item;
nullpo_ret(sd);
- Assert_ret(n >= 0 && n < MAX_INVENTORY);
+ Assert_ret(n >= 0 && n < sd->status.inventorySize);
item = sd->inventory_data[n];
@@ -4311,7 +4308,7 @@ static bool pc_can_insert_card_into(struct map_session_data *sd, int idx_card, i
nullpo_ret(sd);
- if (idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL)
+ if (idx_equip < 0 || idx_equip >= sd->status.inventorySize || sd->inventory_data[idx_equip] == NULL)
return false; //Invalid item index.
if (sd->status.inventory[idx_equip].nameid <= 0 || sd->status.inventory[idx_equip].amount < 1)
return false; // target item missing
@@ -4345,7 +4342,7 @@ static bool pc_can_insert_card(struct map_session_data *sd, int idx_card)
{
nullpo_ret(sd);
- if (idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL)
+ if (idx_card < 0 || idx_card >= sd->status.inventorySize || sd->inventory_data[idx_card] == NULL)
return false; //Invalid card index.
if (sd->status.inventory[idx_card].nameid <= 0 || sd->status.inventory[idx_card].amount < 1)
return false; // target card missing
@@ -4441,7 +4438,6 @@ static int pc_modifysellvalue(struct map_session_data *sd, int orig_value)
*------------------------------------------*/
static int pc_checkadditem(struct map_session_data *sd, int nameid, int amount)
{
- int i;
struct item_data* data;
nullpo_ret(sd);
@@ -4457,7 +4453,7 @@ static int pc_checkadditem(struct map_session_data *sd, int nameid, int amount)
if( data->stack.inventory && amount > data->stack.amount )
return ADDITEM_OVERAMOUNT;
- for(i=0;i<MAX_INVENTORY;i++){
+ for(int i = 0; i < sd->status.inventorySize; i++) {
// 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( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->status.inventory[i].amount ) )
@@ -4475,11 +4471,10 @@ static int pc_checkadditem(struct map_session_data *sd, int nameid, int amount)
*------------------------------------------*/
static int pc_inventoryblank(struct map_session_data *sd)
{
- int i,b;
-
nullpo_ret(sd);
+ int b = 0;
- for(i=0,b=0;i<MAX_INVENTORY;i++){
+ for (int i = 0; i < sd->status.inventorySize; i++) {
if(sd->status.inventory[i].nameid==0)
b++;
}
@@ -4676,8 +4671,8 @@ static int pc_search_inventory(struct map_session_data *sd, int item_id)
int i;
nullpo_retr(INDEX_NOT_FOUND, sd);
- ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == item_id && (sd->status.inventory[i].amount > 0 || item_id == 0) );
- return ( i < MAX_INVENTORY ) ? i : INDEX_NOT_FOUND;
+ ARR_FIND(0, sd->status.inventorySize, i, sd->status.inventory[i].nameid == item_id && (sd->status.inventory[i].amount > 0 || item_id == 0));
+ return (i < sd->status.inventorySize) ? i : INDEX_NOT_FOUND;
}
/*==========================================
@@ -4739,11 +4734,11 @@ static int pc_additem(struct map_session_data *sd, const struct item *item_data,
}
}
- i = MAX_INVENTORY;
+ i = sd->status.inventorySize;
// Stackable | Non Rental
if( itemdb->isstackable2(data) && item_data->expire_time == 0 ) {
- for( i = 0; i < MAX_INVENTORY; i++ ) {
+ for (i = 0; i < sd->status.inventorySize; i++) {
if( sd->status.inventory[i].nameid == item_data->nameid &&
sd->status.inventory[i].bound == item_data->bound &&
sd->status.inventory[i].expire_time == 0 &&
@@ -4758,7 +4753,7 @@ static int pc_additem(struct map_session_data *sd, const struct item *item_data,
}
}
- if ( i >= MAX_INVENTORY ) {
+ if (i >= sd->status.inventorySize) {
i = pc->search_inventory(sd,0);
if (i == INDEX_NOT_FOUND)
return 4;
@@ -4818,7 +4813,7 @@ static int pc_additem(struct map_session_data *sd, const struct item *item_data,
static int pc_delitem(struct map_session_data *sd, int n, int amount, int type, short reason, e_log_pick_type log_type)
{
nullpo_retr(1, sd);
- Assert_retr(1, n >= 0 && n < MAX_INVENTORY);
+ Assert_retr(1, n >= 0 && n < sd->status.inventorySize);
if(sd->status.inventory[n].nameid==0 || amount <= 0 || sd->status.inventory[n].amount<amount || sd->inventory_data[n] == NULL)
return 1;
@@ -4852,7 +4847,7 @@ static int pc_dropitem(struct map_session_data *sd, int n, int amount)
{
nullpo_retr(1, sd);
- if(n < 0 || n >= MAX_INVENTORY)
+ if(n < 0 || n >= sd->status.inventorySize)
return 0;
if(amount <= 0)
@@ -4963,7 +4958,7 @@ static int pc_isUseitem(struct map_session_data *sd, int n)
int nameid;
nullpo_ret(sd);
- Assert_ret(n >= 0 && n < MAX_INVENTORY);
+ Assert_ret(n >= 0 && n < sd->status.inventorySize);
item = sd->inventory_data[n];
nameid = sd->status.inventory[n].nameid;
@@ -5199,7 +5194,7 @@ static int pc_useitem(struct map_session_data *sd, int n)
bool removeItem = false;
nullpo_ret(sd);
- Assert_ret(n >= 0 && n < MAX_INVENTORY);
+ Assert_ret(n >= 0 && n < sd->status.inventorySize);
if (sd->npc_id || sd->state.workinprogress & 1) {
#if PACKETVER >= 20110308
@@ -5436,7 +5431,7 @@ static int pc_cart_delitem(struct map_session_data *sd, int n, int amount, int t
{
struct item_data * data;
nullpo_retr(1, sd);
- Assert_retr(1, n >= 0 && n < MAX_INVENTORY);
+ Assert_retr(1, n >= 0 && n < MAX_CART);
if( sd->status.cart[n].nameid == 0 || sd->status.cart[n].amount < amount || !(data = itemdb->exists(sd->status.cart[n].nameid)) )
return 1;
@@ -5470,7 +5465,7 @@ static int pc_putitemtocart(struct map_session_data *sd, int idx, int amount)
nullpo_ret(sd);
- if (idx < 0 || idx >= MAX_INVENTORY) //Invalid index check [Skotlex]
+ if (idx < 0 || idx >= sd->status.inventorySize) //Invalid index check [Skotlex]
return 1;
item_data = &sd->status.inventory[idx];
@@ -5540,7 +5535,7 @@ static void pc_bound_clear(struct map_session_data *sd, enum e_item_bound_type t
/* both restricted to inventory */
case IBT_PARTY:
case IBT_CHARACTER:
- for( i = 0; i < MAX_INVENTORY; i++ ){
+ for (i = 0; i < sd->status.inventorySize; i++ ) {
if( sd->status.inventory[i].bound == type ) {
pc->delitem(sd, i, sd->status.inventory[i].amount, 0, DELITEM_SKILLUSE, LOG_TYPE_OTHER); // FIXME: is this the correct reason flag?
}
@@ -5552,7 +5547,7 @@ static void pc_bound_clear(struct map_session_data *sd, enum e_item_bound_type t
case IBT_GUILD: {
struct guild_storage *gstor = idb_get(gstorage->db,sd->status.guild_id);
- for( i = 0; i < MAX_INVENTORY; i++ ){
+ for (i = 0; i < sd->status.inventorySize; i++ ) {
if(sd->status.inventory[i].bound == type) {
if( gstor )
gstorage->additem(sd,gstor,&sd->status.inventory[i],sd->status.inventory[i].amount);
@@ -8293,15 +8288,15 @@ static int pc_dead(struct map_session_data *sd, struct block_list *src)
if(id == 0)
continue;
if(id == -1){
- int eq_num=0,eq_n[MAX_INVENTORY],k;
+ int eq_num = 0, eq_n[MAX_INVENTORY], k;
memset(eq_n,0,sizeof(eq_n));
- for(i=0;i<MAX_INVENTORY;i++){
+ for(i = 0; i < sd->status.inventorySize; i++) {
if( (type == 1 && !sd->status.inventory[i].equip)
|| (type == 2 && sd->status.inventory[i].equip)
|| type == 3)
{
- ARR_FIND( 0, MAX_INVENTORY, k, eq_n[k] <= 0 );
- if( k < MAX_INVENTORY )
+ ARR_FIND(0, sd->status.inventorySize, k, eq_n[k] <= 0);
+ if (k < sd->status.inventorySize)
eq_n[k] = i;
eq_num++;
@@ -8317,7 +8312,7 @@ static int pc_dead(struct map_session_data *sd, struct block_list *src)
}
}
else if(id > 0){
- for(i=0;i<MAX_INVENTORY;i++){
+ for( i = 0; i < sd->status.inventorySize; i++) {
if(sd->status.inventory[i].nameid == id
&& rnd()%10000 < per
&& ((type == 1 && !sd->status.inventory[i].equip)
@@ -10148,7 +10143,7 @@ static int pc_equipitem(struct map_session_data *sd, int n, int req_pos)
nullpo_ret(sd);
- if( n < 0 || n >= MAX_INVENTORY ) {
+ if (n < 0 || n >= sd->status.inventorySize) {
clif->equipitemack(sd,0,0,EIA_FAIL);
return 0;
}
@@ -10356,7 +10351,7 @@ static int pc_unequipitem(struct map_session_data *sd, int n, int flag)
nullpo_ret(sd);
- if (n < 0 || n >= MAX_INVENTORY) {
+ if (n < 0 || n >= sd->status.inventorySize) {
clif->unequipitemack(sd, 0, 0, UIA_FAIL);
return 0;
}
@@ -10508,7 +10503,7 @@ static int pc_checkitem(struct map_session_data *sd)
int id = 0;
if (sd->itemcheck & PCCHECKITEM_INVENTORY) {
- for (i = 0; i < MAX_INVENTORY; i++) {
+ for (i = 0; i < sd->status.inventorySize; i++) {
if ((id = sd->status.inventory[i].nameid) == 0)
continue;
@@ -10588,7 +10583,7 @@ static int pc_checkitem(struct map_session_data *sd)
}
}
- for (i = 0; i < MAX_INVENTORY; i++) {
+ for (i = 0; i < sd->status.inventorySize; i++) {
if (sd->status.inventory[i].nameid == 0)
continue;
@@ -10762,11 +10757,14 @@ static int pc_divorce(struct map_session_data *sd)
// Both players online, lets do the divorce manually
sd->status.partner_id = 0;
p_sd->status.partner_id = 0;
- for( i = 0; i < MAX_INVENTORY; i++ )
+ for (i = 0; i < sd->status.inventorySize; i++)
{
- if( sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F )
+ if (sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F)
pc->delitem(sd, i, 1, 0, DELITEM_NORMAL, LOG_TYPE_DIVORCE);
- if( p_sd->status.inventory[i].nameid == WEDDING_RING_M || p_sd->status.inventory[i].nameid == WEDDING_RING_F )
+ }
+ for (i = 0; i < p_sd->status.inventorySize; i++)
+ {
+ if (p_sd->status.inventory[i].nameid == WEDDING_RING_M || p_sd->status.inventory[i].nameid == WEDDING_RING_F)
pc->delitem(p_sd, i, 1, 0, DELITEM_NORMAL, LOG_TYPE_DIVORCE);
}