User Tools

Site Tools


fusion:technical:rng

RNG Doc

Random elements on Fusion are determined on a per-enemy basis. Each enemy/sprite has an RNG value between 0-15 (0-F) that changes every frame. This is the primary value used for most randomness in the game.

Random elements include:
Enemy spawns
X-parasite refills
Eyedoor open/shoot
Eyedoor opening delay
Zazabi wasted jumps
Zazabi crawl duration
Serris pattern
Yakuza rounds

Maybe random:
Arachnus
Mega-X
Nettori shots

There are two frame counters involved in the calculation. One is a 16-bit counter at 0x3000002 (unsigned, 2 bytes) and the other is an 8-bit counter at 0x3000BE5 (unsigned, 1 byte). The 8-bit counter seems unnecessary, since the 8-bit portion of the 16-bit counter is always the same, but the reason for this is irrelevant. Both counters start running the moment the game starts and they never stop.

Getting the RNG value is a two part process. First, an index value is calculated. Then, the index value is used to get the RNG value from an array of fixed values. The first part is shown below:

index = (EnemySlot + EnemyX + EnemyY + Frame1 + Frame2) % 32

EnemySlot: There are 24 slots for enemies/sprites in the current room. Each slot is 56 (0x38) in length. This is simply a value from 0-23.
EnemyX: The x position of the enemy, located at 0x3000144 + EnemySlot*56 (unsigned, 2 bytes)
EnemyY: The y position of the enemy, located at 0x3000142 + EnemySlot*56 (unsigned, 2 bytes)
Frame1: 8-bit frame counter at 0x3000BE5
Frame2: 16-bit frame counter at 0x3000002 divided by 16

This formula will provide a value between 0-31. This serves as the index value for the following array:

RNs = {13, 2, 6, 8, 7, 9, 14, 10, 2, 4, 14, 4, 12, 15, 13, 12, 11, 1, 3, 15, 0, 6, 7, 8, 11, 5, 0, 3, 5, 1, 9, 10}

The array contains two of every value from 0-15. Most random elements are determined the frame before it happens, so this is when the value is read.
Red X:
if (RN % 4)*256 + [0x3000BE5] >= 1024 - RedX, then a red x will spawn
RedX = [82E4D58 + EnemyID*14]
note: this is based on where the X spawns, which is not always the same as the enemy's location.

Eyedoor open/shoot:
if RN ⇐ 6, then the eyedoor will be vulnerable
else, it will shoot

Eyedoor opening delay:
frames = 60 + RN*4

Core-X drops:
if RN ⇐ 4, then a green x will spawn
else, a yellow x will spawn

Zazabi wasted jumps:
jumps = (CurrRound-1) + RN/4, where CurrRound = [1-3]

Zazabi crawl delay:
frames = 60 + RN*8

Serris:
TODO

Yakuza rounds:
rounds = 1 + RN/4

Thanks to biospark for providing this information

fusion/technical/rng.txt · Last modified: 2018/01/27 18:26 by oneof99