Attempt to implement hash for special points to detect tech racer maps
authorunC0Rr
Fri, 12 Feb 2016 17:03:42 +0300
changeset 11542 64a5ab2c4f00
parent 11541 34a0181d5be5
child 11543 3617c611406b
Attempt to implement hash for special points to detect tech racer maps
share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua
share/hedgewars/Data/Scripts/OfficialChallenges.lua
--- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Tue Feb 09 15:27:55 2016 -0500
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Fri Feb 12 17:03:42 2016 +0300
@@ -551,6 +551,9 @@
 end
 
 function onSpecialPoint(x,y,flag)
+    addHashData(x)
+    addHashData(y)
+    addHashData(flag)
     specialPointsX[specialPointsCount] = x
     specialPointsY[specialPointsCount] = y
     specialPointsCount = specialPointsCount + 1
--- a/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Tue Feb 09 15:27:55 2016 -0500
+++ b/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Fri Feb 12 17:03:42 2016 +0300
@@ -724,6 +724,9 @@
 end
 
 function onSpecialPoint(x,y,flag)
+    addHashData(x)
+    addHashData(y)
+    addHashData(flag)
     specialPointsX[specialPointsCount] = x
     specialPointsY[specialPointsCount] = y
 	specialPointsFlag[specialPointsCount] = flag
@@ -1270,7 +1273,7 @@
         raceType = "mixed race"
     end
 
-    map = detectMap()
+    map = detectMapWithDigest()
 
     for i = 0, (numTeams-1) do
         if teamScore[i] < 100000 then
--- a/share/hedgewars/Data/Scripts/OfficialChallenges.lua	Tue Feb 09 15:27:55 2016 -0500
+++ b/share/hedgewars/Data/Scripts/OfficialChallenges.lua	Fri Feb 12 17:03:42 2016 +0300
@@ -45,3 +45,26 @@
         end
     end
 end
+
+-- modified Adler hash
+local hashA = 0
+local hashB = 0
+local hashModule = 299993
+
+function resetHash()
+    hashA = 0
+    hashB = 0
+end
+
+function addHashData(i)
+    hashA = (hashA + i + 65536) % hashModule
+    hashB = (hashB + hashA) % hashModule
+end
+
+function hashDigest()
+    return(hashB * hashModule + hashA)
+end
+
+function detectMapWithDigest()
+    return("map " .. hashDigest())
+end