Skip to content

Logic for random checks

Henri Asseily edited this page Feb 4, 2022 · 4 revisions

Preamble

Deathlord uses a random number generator routine at 0x4AE0 during the game that outputs a random 8-bit integer. It also has a routine I call "CMPRNG100" which takes as input a number between 0 and 100, and does a check against a random number. This routine needs to transform the 0-100 % into a 0-255 to compare against the RNG. The way it does it is by adding together a left shift and a right shift of the number, basically multiplying it by 2.5. So it turns into a 0-250 range to compare against 0-255. Close and good enough for the 6502 processor.

RNG quirks

The RNG routine is at 0x6780 during the "pre-game" (character generation, menu stuff...), and at 0x4AE0 during the game.

There is a table of 256 random numbers (for example, at 0x6500 during character generation) that the routine updates.

During character creation, the routine runs continuously while waiting for keyboard input. When coding the automatic re-roll system for attributes, I had to randomize every once in a while the table in order to "re-seed" the RNG. Otherwise we could get into an infinite loop of not getting the needed attributes because the numbers would roll over.

Lockpicking

Lockpicking is always maxed at 97 before hitting the CMPRNG100 routine. So you'll get an effective lockpick max of around 95%.

Non-thief classes:

4 + MAX(0, (DEX - 12) * 3)

Thief class:

If level 33 or above, set to 97

Otherwise:

(level*3) + MAX(0, (DEX - 12) * 3)

A thief class is thief, assassin, ninja, monk. If a pure thief, add 8 to the score.

Smashing Doors

Simply adds STR and SIZ and sends that to the CMPRNG100 routine.

So a troll with 21 STR and 21 SIZ will have a score of 42 and about 40% chance to smash a door.

Searching

By far the most evil "feature" of Deathlord is that searching for hidden doors and traps does not always succeed. "Not always" is a misnomer for "good luck". So you think that having a thief in the party would help, no? Nope. Because Deathlord.

In fact, search success is purely driven by race. Yes, race. The game does a RNG check against the below table, and succeeds when under this:

  • Human 0x58 (88) --> 35%
  • Toshi 0x96 (150) --> 59%
  • Nintoshi 0x80 (128) --> 50%
  • Kobito 0xAF (175) --> 68%
  • Gnome 0xAF (175) --> 68%
  • Obake 0x64 (100) --> 39%
  • Troll 0x4B (75) --> 29%
  • Ogre 0x4B (75) --> 29%

So get yourself a dwarf or a gnome, or use Deathlord Relorded where search always succeeds. Because anything else is too evil.