summaryrefslogtreecommitdiff
path: root/src/map/vending.c
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-10-04 20:44:46 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-10-04 20:44:46 +0000
commit72f668162425f86e6253d571708f9a54a776c923 (patch)
treed1b46a204ccadde1e37b5969cc1c030445c89900 /src/map/vending.c
parentb4a305c08f2e6aaf2f1179462958af0f0b184fd2 (diff)
downloadhercules-72f668162425f86e6253d571708f9a54a776c923.tar.gz
hercules-72f668162425f86e6253d571708f9a54a776c923.tar.bz2
hercules-72f668162425f86e6253d571708f9a54a776c923.tar.xz
hercules-72f668162425f86e6253d571708f9a54a776c923.zip
* Added code that compacts the vending list after a purchase; fixes the problem with empty positions appearing in the list (bugreport:168)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11355 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/vending.c')
-rw-r--r--src/map/vending.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/map/vending.c b/src/map/vending.c
index 7ac83b69c..9017eab96 100644
--- a/src/map/vending.c
+++ b/src/map/vending.c
@@ -57,10 +57,8 @@ void vending_vendinglistreq(struct map_session_data* sd, int id)
*------------------------------------------*/
void vending_purchasereq(struct map_session_data* sd, int id, const uint8* data, int count)
{
- int i, j, w, new_ = 0, blank, vend_list[MAX_VENDING];
+ int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING];
double z;
- unsigned short amount;
- short idx;
struct s_vending vending[MAX_VENDING]; // against duplicate packets
struct map_session_data* vsd = map_id2sd(id);
@@ -83,8 +81,8 @@ void vending_purchasereq(struct map_session_data* sd, int id, const uint8* data,
w = 0; // weight counter
for( i = 0; i < count; i++ )
{
- amount = *(uint16*)(data + 4*i + 0);
- idx = *(uint16*)(data + 4*i + 2);
+ unsigned short amount = *(uint16*)(data + 4*i + 0);
+ short idx = *(uint16*)(data + 4*i + 2);
idx -= 2;
if( amount <= 0 )
@@ -152,8 +150,8 @@ void vending_purchasereq(struct map_session_data* sd, int id, const uint8* data,
for( i = 0; i < count; i++ )
{
- amount = *(uint16*)(data + 4*i + 0);
- idx = *(uint16*)(data + 4*i + 2);
+ unsigned short amount = *(uint16*)(data + 4*i + 0);
+ short idx = *(uint16*)(data + 4*i + 2);
idx -= 2;
//Logs sold (V)ending items [Lupus]
@@ -177,6 +175,23 @@ void vending_purchasereq(struct map_session_data* sd, int id, const uint8* data,
}
}
+ // compact the vending list
+ for( i = 0, cursor = 0; i < vsd->vend_num; i++ )
+ {
+ if( vsd->vending[i].amount == 0 )
+ continue;
+
+ if( cursor != i ) // speedup
+ {
+ vsd->vending[cursor].index = vsd->vending[i].index;
+ vsd->vending[cursor].amount = vsd->vending[i].amount;
+ vsd->vending[cursor].value = vsd->vending[i].value;
+ }
+
+ cursor++;
+ }
+ vsd->vend_num = cursor;
+
//Always save BOTH: buyer and customer
if( save_settings&2 )
{