share/hedgewars/Data/Scripts/OfficialChallenges.lua
author spudpiggy <facetakers@gmail.com>
Fri, 05 Apr 2024 13:10:55 +0100
changeset 16006 1f9f971adec4
parent 14231 74bf2d906097
permissions -rw-r--r--
sndCover now falls back to sndWatchThis OR sndFire. sndDrat and sndBugger now fall back to each other.

HedgewarsScriptLoad("/Scripts/OfficialChallengeHashes.lua")

-- 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
        local mapString = hashDigest() .. "," .. LandDigest

        if band(GameFlags, gfBorder) ~= 0 then
            mapString = "Border," .. mapString
        end

        WriteLnToConsole("OfficialChallenges: Hash: "..mapString)
        local map = official_racer_maps[mapString]
        if map ~= nil then
            WriteLnToConsole("OfficialChallenges: Detected official challenge: "..map)
        end
        return map
    end
end