detectMap() rewrite with more sane approach, also check waypoints placement to avoid cheating
authorunc0rr
Sat, 13 Feb 2016 00:36:38 +0300
changeset 11545 86528b0cd491
parent 11543 3617c611406b
child 11546 59bf29b4f523
detectMap() rewrite with more sane approach, also check waypoints placement to avoid cheating
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	Fri Feb 12 14:27:20 2016 -0500
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Sat Feb 13 00:36:38 2016 +0300
@@ -778,7 +778,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/Multiplayer/TechRacer.lua	Fri Feb 12 14:27:20 2016 -0500
+++ b/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Sat Feb 13 00:36:38 2016 +0300
@@ -690,10 +690,10 @@
 end
 
 function onGameInit()
-
-		if mapID == nil then
-			mapID = 2 + GetRandom(7)
-		end
+    if mapID == nil then
+        mapID = 2 + GetRandom(7)
+        addHashData(mapID)
+    end
 
 		Theme = "Cave"
 
--- a/share/hedgewars/Data/Scripts/OfficialChallenges.lua	Fri Feb 12 14:27:20 2016 -0500
+++ b/share/hedgewars/Data/Scripts/OfficialChallenges.lua	Sat Feb 13 00:36:38 2016 +0300
@@ -1,50 +1,24 @@
-function detectMap()
-    if RopePercent == 100 and MinesNum == 0 then
--- challenges with border
-        if band(GameFlags, gfBorder) ~= 0 then
-            if LandDigest == "M838018718Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #1")
-            elseif LandDigest == "M-490229244Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #2")
-            elseif LandDigest == "M806689586Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #3")
-            elseif LandDigest == "M1770509913Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #7")
-            elseif LandDigest == "M1902370941Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #8")
-            elseif LandDigest == "M185940363Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #9")
-            elseif LandDigest == "M751885839Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #10")
-            elseif LandDigest == "M178845011Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #11")
-            elseif LandDigest == "M706743197Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #12")
-            elseif LandDigest == "M157242054Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #13")
-            elseif LandDigest == "M-1585582638Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #14")
-            elseif LandDigest == "M-528106034Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #16")
-            elseif LandDigest == "M-534640804Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #18")
-            elseif LandDigest == "M-1839546856Scripts/Multiplayer/Racer.lua" then
-                return("Racer Challenge #19")
-            end
--- challenges without border
-        elseif LandDigest == "M-134869715Scripts/Multiplayer/Racer.lua" then
-            return("Racer Challenge #4")
-        elseif LandDigest == "M-661895109Scripts/Multiplayer/Racer.lua" then
-            return("Racer Challenge #5")
-        elseif LandDigest == "M479034891Scripts/Multiplayer/Racer.lua" then
-            return("Racer Challenge #6")
-        elseif LandDigest == "M256715557Scripts/Multiplayer/Racer.lua" then
-            return("Racer Challenge #15")
-        elseif LandDigest == "M-1389184823Scripts/Multiplayer/Racer.lua" then
-            return("Racer Challenge #17")
-        end
-    end
-end
+local maps = {
+    ["Border,60526986531,M838018718Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #1"
+    , ["Border,71022545335,M-490229244Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #2"
+    , ["Border,40469748943,M806689586Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #3"
+    , ["85940488650,M-134869715Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #4"
+    , ["62080348735,M-661895109Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #5"
+    , ["56818170733,M479034891Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #6"
+    , ["Border,25372705797,M1770509913Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #7"
+    , ["Border,10917540013,M1902370941Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #8"
+    , ["Border,43890274319,M185940363Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #9"
+    , ["Border,27870148394,M751885839Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #10"
+    , ["Border,22647869226,M178845011Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #11"
+    , ["Border,46954401793,M706743197Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #12"
+    , ["Border,60760377667,M157242054Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #13"
+    , ["Border,51825989393,M-1585582638Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #14"
+    , ["81841189250,M256715557Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #15"
+    , ["Border,44246064625,M-528106034Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #16"
+    , ["60906776802,M-1389184823Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #17"
+    , ["Border,70774747774,M-534640804Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #18"
+    , ["Border,50512019610,M-1839546856Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #19"
+    }
 
 -- modified Adler hash
 local hashA = 0
@@ -66,5 +40,14 @@
 end
 
 function detectMapWithDigest()
-    return("map " .. hashDigest())
+    if RopePercent == 100 and MinesNum == 0 then
+        mapString = hashDigest() .. "," .. LandDigest
+
+        if band(GameFlags, gfBorder) ~= 0 then
+            mapString = "Border," .. mapString
+        end
+
+        --WriteLnToConsole(mapString)
+        return(maps[mapString])
+    end
 end