Update racer scripts 0.9.22
authorunc0rr
Mon, 01 May 2017 13:59:24 +0300
branch0.9.22
changeset 12401 7342f5020691
parent 12400 c7d73e5840c8
child 14361 21d556cddf93
Update racer scripts
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 05 11:32:23 2016 +0300
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Mon May 01 13:59:24 2017 +0300
@@ -94,7 +94,7 @@
 local fastY = {}
 local fastCount = 0
 local fastIndex = 0
-local fastColour
+local fastColour = 0xffffffff
 
 local currX = {}
 local currY = {}
@@ -540,7 +540,7 @@
             wpY[wpCount] = y
             wpCol[wpCount] = 0xffffffff
             wpCirc[wpCount] = AddVisualGear(wpX[wpCount],wpY[wpCount],vgtCircle,0,true)
-                                                                                                                                            
+
             SetVisualGearValues(wpCirc[wpCount], wpX[wpCount], wpY[wpCount], 20, 100, 1, 10, 0, wpRad, 5, wpCol[wpCount])
 
             wpCount = wpCount + 1
@@ -551,9 +551,18 @@
 end
 
 function onSpecialPoint(x,y,flag)
-    specialPointsX[specialPointsCount] = x
-    specialPointsY[specialPointsCount] = y
-    specialPointsCount = specialPointsCount + 1
+    if flag == 99 then
+        fastX[fastCount] = x
+        fastY[fastCount] = y
+        fastCount = fastCount + 1
+    else
+        addHashData(x)
+        addHashData(y)
+        addHashData(flag)
+        specialPointsX[specialPointsCount] = x
+        specialPointsY[specialPointsCount] = y
+        specialPointsCount = specialPointsCount + 1
+    end
 end
 
 function onNewTurn()
@@ -743,17 +752,18 @@
 
 function onAttack()
     at = GetCurAmmoType()
-    
+
     usedWeapons[at] = 0
 end
 
 function onAchievementsDeclaration()
     usedWeapons[amSkip] = nil
-    
+    usedWeapons[amExtraTime] = nil
+
     usedRope = usedWeapons[amRope] ~= nil
     usedPortal = usedWeapons[amPortalGun] ~= nil
     usedSaucer = usedWeapons[amJetpack] ~= nil
-    
+
     usedWeapons[amNothing] = nil
     usedWeapons[amRope] = nil
     usedWeapons[amPortalGun] = nil
@@ -775,8 +785,8 @@
         raceType = "mixed race"
     end
 
-    map = detectMap()
-    
+    map = detectMapWithDigest()
+
     for i = 0, (numTeams-1) do
         if teamScore[i] < 100000 then
             DeclareAchievement(raceType, teamNameArr[i], map, teamScore[i])
--- a/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Fri Feb 05 11:32:23 2016 +0300
+++ b/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Mon May 01 13:59:24 2017 +0300
@@ -173,7 +173,7 @@
 local fastY = {}
 local fastCount = 0
 local fastIndex = 0
-local fastColour
+local fastColour = 0xffffffff
 
 local currX = {}
 local currY = {}
@@ -246,7 +246,7 @@
                 teamNameArr[i] = " " -- = i
                 teamSize[i] = 0
                 teamIndex[i] = 0
-                teamScore[i] = 100000
+                teamScore[i] = 1000000
         end
         numTeams = 0
 
@@ -350,7 +350,7 @@
 function AdjustScores()
 
         if bestTime == nil then
-                bestTime = 100000
+                bestTime = 1000000
                 bestClan = 10
                 bestTimeComment = "N/A"
         end
@@ -380,7 +380,7 @@
                 end
         end
 
-        if bestTime ~= 100000 then
+        if bestTime ~= 1000000 then
                 bestTimeComment = (bestTime/1000) ..loc("s")
         end
 
@@ -690,10 +690,11 @@
 end
 
 function onGameInit()
+    if mapID == nil then
+        mapID = 2 + GetRandom(7)
+    end
 
-		if mapID == nil then
-			mapID = 2 + GetRandom(7)
-		end
+    addHashData(mapID)
 
 		Theme = "Cave"
 
@@ -724,10 +725,22 @@
 end
 
 function onSpecialPoint(x,y,flag)
-    specialPointsX[specialPointsCount] = x
-    specialPointsY[specialPointsCount] = y
-	specialPointsFlag[specialPointsCount] = flag
-    specialPointsCount = specialPointsCount + 1
+    if flag == 99 then
+        fastX[fastCount] = x
+        fastY[fastCount] = y
+        fastCount = fastCount + 1
+    elseif flag == 0 then
+        techX[techCount], techY[techCount] = x, y
+        techCount = techCount + 1
+    else
+        addHashData(x)
+        addHashData(y)
+        addHashData(flag)
+        specialPointsX[specialPointsCount] = x
+        specialPointsY[specialPointsCount] = y
+        specialPointsFlag[specialPointsCount] = flag
+        specialPointsCount = specialPointsCount + 1
+    end
 end
 
 function InterpretPoints()
@@ -1245,6 +1258,7 @@
 
 function onAchievementsDeclaration()
     usedWeapons[amSkip] = nil
+    usedWeapons[amExtraTime] = nil
 
     usedRope = usedWeapons[amRope] ~= nil
     usedPortal = usedWeapons[amPortalGun] ~= nil
@@ -1270,10 +1284,10 @@
         raceType = "mixed race"
     end
 
-    map = detectMap()
+    map = detectMapWithDigest()
 
     for i = 0, (numTeams-1) do
-        if teamScore[i] < 100000 then
+        if teamScore[i] < 1000000 then
             DeclareAchievement(raceType, teamNameArr[i], map, teamScore[i])
         end
     end
--- a/share/hedgewars/Data/Scripts/OfficialChallenges.lua	Fri Feb 05 11:32:23 2016 +0300
+++ b/share/hedgewars/Data/Scripts/OfficialChallenges.lua	Mon May 01 13:59:24 2017 +0300
@@ -1,47 +1,63 @@
-function detectMap()
+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"
+    , ["60715683005,M-281312897Scripts/Multiplayer/Racer.lua"] = "Racer Challenge #20"
+-- tech racer
+    , ["Border,19661006772,M-975391975Scripts/Multiplayer/TechRacer.lua"] = "Tech Racer #1"
+    , ["Border,19661306766,M-975391975Scripts/Multiplayer/TechRacer.lua"] = "Tech Racer #2"
+    , ["Border,19661606760,M-975391975Scripts/Multiplayer/TechRacer.lua"] = "Tech Racer #3"
+    , ["Border,19661906754,M-975391975Scripts/Multiplayer/TechRacer.lua"] = "Tech Racer #4"
+    , ["Border,19662206748,M-975391975Scripts/Multiplayer/TechRacer.lua"] = "Tech Racer #5"
+    , ["Border,19662506742,M-975391975Scripts/Multiplayer/TechRacer.lua"] = "Tech Racer #6"
+    , ["Border,19662806736,M-975391975Scripts/Multiplayer/TechRacer.lua"] = "Tech Racer #7"
+    , ["Border,19663106730,M-975391975Scripts/Multiplayer/TechRacer.lua"] = "Tech Racer #8"
+    }
+
+-- 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()
     if RopePercent == 100 and MinesNum == 0 then
--- challenges with border
+        mapString = hashDigest() .. "," .. LandDigest
+
         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")
+            mapString = "Border," .. mapString
         end
+
+        --WriteLnToConsole(mapString)
+        return(maps[mapString])
     end
 end