From 72f668162425f86e6253d571708f9a54a776c923 Mon Sep 17 00:00:00 2001 From: ultramage Date: Thu, 4 Oct 2007 20:44:46 +0000 Subject: * 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 --- Changelog-Trunk.txt | 2 ++ src/map/vending.c | 29 ++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index ce4fbc3d3..58ff37140 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -4,6 +4,8 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. 2007/10/04 + * Added code that compacts the vending list after a purchase; fixes + the problem with empty positions appearing in the list (bugreport:168) * Corrected Icewall skill to be closer to official behavior - now works on occupied squares (previously it disappeared) - now you can walk out of an icewall square (removed code that blocked 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 ) { -- cgit v1.2.3-60-g2f50