Browse Source

* 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://svn.code.sf.net/p/rathena/svn/trunk@11355 54d463be-8e91-2dee-dedb-b68131a5f0ec
ultramage 17 years ago
parent
commit
95024b89d1
2 changed files with 24 additions and 7 deletions
  1. 2 0
      Changelog-Trunk.txt
  2. 22 7
      src/map/vending.c

+ 2 - 0
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

+ 22 - 7
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 )
 	{