I used
Cheat Engine on SQ3 in DOSBox to find out how the RNG sequence works for this game. The sequence is given by:
x←31821*x mod 65536
Like AGI, 0 is a special case that seeds the RNG with some value (may depend on system clock). That's all I know so far.
The SCI
random function is called whenever there is a game over (to select the game over music). This is a good way to check where the address is in JPC-rr.
Edit: OK, I figured out how the
random method works (other than how it seeds the RNG value when the address has value 0). It works like this:
- The RNG sequence is determined by: x ← 31821*x mod 65536.
- The method, random(int min, int max), returns a value from min to max as follows, given the previous RNG value of x:
-- Calculate a ← 31821*x.
-- Calculate b ← floor(a/256) mod 65536 (in hexadecimal this is the central 4 digits of the 8-digit representation of a)
-- Calculate c ← b*(max-min+1)
-- Calculate d ← floor(c/65536) (in hexadecimal this is the number c dropping the rightmost 4 digits)
-- Calculate res ← d + min
- Then random(int min, int max) returns res.
Example: Arnoid's appearance on the pod screen is given by:
(switch global110
(1
(if (== (Random 1 2) 2)
((= gNewAct (Act new:)) posn: 1000 1000 init:)
(= gSeconds (Random 2 10))
)
(following numbers are in hexadecimal)
If the RNG value before entering the pod screen is 0001, then:
0001*7C4D=00
007C4D, 007C*(1-0+1)=
000F8, res=0+1=1
Since res is 1 instead of 2, Arnoid does not appear at all.
If the RNG value before entering the pod screen is AAAA, then:
AAAA*7C4D=52
DDAD22, DDAD*(1-0+1)=
1BB5A, res=1+1=2
Since res is 2, Arnoid appears.
The current RNG value is now AD22 and the number of gSeconds is then given by:
AD22*7C4D=54
108B3A, 108B*(10-2+1)=
094E3, res=0+2=2.
So gSeconds before Arnoid appears is 2, the shortest possible time.