# User File #27870229146523304

#### #27870229146523304 - Advance Wars: Dual Strike (USA) RNG Lua

AWDS simple RNG.lua
Uploaded 12/30/2015 3:01 AM by ALAKTORN (see all 34)
``````local function Multiply(int1, int2)
local High1 = math.floor(int1 / 32768)
local Low1 = math.floor(int1 % 32768)
local High2 = math.floor(int2 / 32768)
local Low2 = math.floor(int2 % 32768)

local NewHigh = (High1 * Low2 + High2 * Low1) % 32768;
local NewLow = Low1 * Low2

return (NewHigh * 32768 + NewLow) % 1073741824;
end

function RNGStep(i)
local i4 = (i * 4 + 1) % 1073741824
return Multiply(i4, i + 1)
end

local function RNGSteps(iRNG, iTimes)
while iTimes > 0 do
iRNG = RNGStep(iRNG)
iTimes = iTimes - 1
end
return iRNG
end

local function getNumSteps(oldRNG, newRNG)
if oldRNG == newRNG then
return 0
end
for i = 1, 200 do
oldRNG = RNGStep(oldRNG)
if oldRNG == newRNG then
return i
end
end
return -1;
end

local x = GameTime + RNGStep(iRNG)
local newRNG = RNGStep(x)
newRNG = newRNG + (math.floor(newRNG / 2) % 2)
return newRNG
end

for i = 1, 80 do
iRNG = RNGStep(iRNG)
iRNG = iRNG + (math.floor(iRNG / 2) % 2)
end
return iRNG
end

MapTimer = -1
MapTimerFrame = -1
if MapTimer == newMapTime then
MapTimerFrame = MapTimerFrame + 1
else
MapTimer = newMapTime
MapTimerFrame = 1
-- Player map timer increased? Then AI Day is certainly over
AIDayActive = false
end
end

GameTimer = -1
GameTimerFrame = -1
if GameTimer == newGameTime then
GameTimerFrame = GameTimerFrame + 1
else
GameTimer = newGameTime
GameTimerFrame = 1
end
end

RNG = -1
TotalNumSteps = 0
if RNG ~= newRNG then
printText = ''
if RNG ~= -1 then
local numSteps = getNumSteps(RNG, newRNG)
if numSteps ~= -1 then
TotalNumSteps = TotalNumSteps + numSteps
printText = newRNG .. ' (' .. numSteps .. ')' .. ' Total: ' .. TotalNumSteps .. ' at ' .. GameTimer
else
TotalNumSteps = 0
if newRNG == RNGFrameAdv(RNG, GameTimer) then
printText = newRNG .. ' (Frame ' .. GameTimer .. ')'
AIDayActive = true
else
for i = 1, 10 do
printText = newRNG .. ' (Menu * ' .. i .. ' at ' .. GameTimer .. ')'
AIDayActive = false
end
end
end
end
end
if printChanges then
if printText ~= '' then
print(printText)
else
print(newRNG)
end
end
RNG = newRNG
end
end

function main()