diff options
-rw-r--r-- | Changelog-Trunk.txt | 2 | ||||
-rw-r--r-- | 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 ) { |