Selaa lähdekoodia

Checkweight

-Fix bugreport:8503 (chkweight uint16 limitation on weight thx to
AnnieRuru)
-Add this testcase on npc_test_checkweight.txt and move it to npec/tests
folder.
lighta 11 vuotta sitten
vanhempi
commit
8115dc048a
3 muutettua tiedostoa jossa 37 lisäystä ja 12 poistoa
  1. 6 0
      npc/scripts_test.conf
  2. 29 11
      npc/test/npc_test_checkweight.txt
  3. 2 1
      src/map/script.c

+ 6 - 0
npc/scripts_test.conf

@@ -1 +1,7 @@
+// --------------------------------------------------------------
+// -                        Tests Scripts                        -
+// --------------------------------------------------------------
+// Thoses scripts are meant for regression test purposes
+
 npc: npc/test/OnInterInit.txt
+npc: npc/test/npc_test_checkweight.txt

+ 29 - 11
doc/sample/npc_test_checkweight.txt → npc/test/npc_test_checkweight.txt

@@ -88,54 +88,72 @@ L_TEST3: //update using array tests
 	.@succes = 0;
 
 	setarray .@item[0], 512,513,514,515;
-        setarray .@count[0], 1,5,9,12;
+	setarray .@count[0], 1,5,9,12;
 	.@ret = checkweight2(.@item,.@count);
 	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be sucess
+	
 	cleararray .@item[0], 0, 4;
 	cleararray .@count[0], 0, 4;
 	setarray .@item[0], 512,513,514,515;
-        setarray .@count[0], 1,5,-1,12;
+	setarray .@count[0], 1,5,-1,12;
 	.@ret = checkweight2(.@item,.@count);
 	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, invalide amout
+	
 	cleararray .@item[0], 0, 4;
 	cleararray .@count[0], 0, 4;
 	setarray .@item[0], 512,513,514,-1;
-        setarray .@count[0], 1,5,15,12;
+	setarray .@count[0], 1,5,15,12;
 	.@ret = checkweight2(.@item,.@count);
 	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, invalide id
+	
 	cleararray .@item[0], 0, 4;
 	cleararray .@count[0], 0, 4;
 	setarray .@item[0], 717,715,716,714;
-        setarray .@count[0], 300,300,300,300;
+	setarray .@count[0], 300,300,300,300;
 	.@ret = checkweight2(.@item,.@count);
 	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, total by weight
+	
 	cleararray .@item[0], 0, 4;
 	cleararray .@count[0], 0, 4;
 	setarray .@item[0], 6320,6320;
-        setarray .@count[0], 31000,2000;
+	setarray .@count[0], 31000,2000;
 	.@ret = checkweight2(.@item,.@count);
 	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, total by weight
+	
 	cleararray .@item[0], 0, 2;
 	cleararray .@count[0], 0, 2;
 	setarray .@item[0], 2794,2795;
-        setarray .@count[0], 95,5;
+	setarray .@count[0], 95,5;
 	.@ret = checkweight2(.@item,.@count);
 	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success
-        setarray .@count[0], 95,10;
+	
+	setarray .@count[0], 95,10;
 	.@ret = checkweight2(.@item,.@count);
 	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure overamount item
+	
 	cleararray .@item[0], 0, 2;
 	cleararray .@count[0], 0, 2;
 	setarray .@item[0], 6320,6320,512;
-        setarray .@count[0], 1,3;
+	setarray .@count[0], 1,3;
 	.@ret = checkweight2(.@item,.@count);
 	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, size mistmatch
+	
 	cleararray .@item[0], 0, 3;
 	cleararray .@count[0], 0, 2;
-	setarray .@item[0], 6320,6320;
-        setarray .@count[0], 1,3,5;
+	setarray .@item[0], 6320,6321;
+	setarray .@count[0], 1,3,5;
+	.@ret = checkweight2(.@item,.@count);
+	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, size mistmatch
+	
+	set .@weight_limit, MaxWeight;
+	set MaxWeight, 4294967296 - 1; //currently maxweight is stored as uint32 (2^32-1)
+	cleararray .@item[0], 0, 2;
+	cleararray .@count[0], 0, 3;
+	setarray .@item[0], 714;
+	setarray .@count[0], 300;
 	.@ret = checkweight2(.@item,.@count);
-	set .@succes,.@succes+ChkResult(.@testid++,0,.@ret); //should be failure, size mistmatch		
+	set MaxWeight, .@weight_limit;
+	set .@succes,.@succes+ChkResult(.@testid++,1,.@ret); //should be success, (test weight over 65k)
 
 
 	debugmes "End update by array tests";

+ 2 - 1
src/map/script.c

@@ -6151,7 +6151,8 @@ int checkweight_sub(TBL_PC *sd,int nbargs,int32 *eitemid,int32 *eamount)
 {
 	struct item_data* id = NULL;
 	int nameid,amount;
-	uint16 amount2=0,slots,weight=0,i;
+	uint32 weight=0;
+	uint16 amount2=0,slots,i;
 
 	slots = pc_inventoryblank(sd); //nb of empty slot