User:Blaziken257/Telefang RNG

From Wikifang, a definitive guide to Telefang, Dino Device and Bugsite
Revision as of 12:28, 21 October 2011 by Blaziken257 (talk | contribs) (Created page with "In Telefang 1, random events rely on a random number generator. It is generated using the following variables: * The frame counter, located at <tt>0x3C30</tt> in RAM. This i...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In Telefang 1, random events rely on a random number generator. It is generated using the following variables:

  • The frame counter, located at 0x3C30 in RAM. This is an 8-bit number, and it increments by 1 for every frame that passes (1 frame = 1/60 second). However, it temporarily freezes in certain situations, mainly when the game has to load screens. The frame counter makes random actions frame dependent.
  • Seed 1, located at 0xC41F in RAM. This value is also an 8-bit number, and it changes every time a random event occurs, and its value depends on the current value of the frame counter, as well as the current values of both seeds.
  • Seed 2, located at 0xC420 in RAM. This 8-bit value functions similarly to Seed 1, although it influences the randomly generated number more than Seed 1.
  • Seed sum, the 8-bit sum of the two seeds, located at 0xC400 in RAM. This is the randomly generated number, most directly used to determine random events.

Seed calculation

Note: Original thread here: http://s15.zetaboards.com/Tulunk_Village/topic/6967791/1/

First, the game takes the current value of the frame counter and uses a formula to calculate a new 16-bit number, which is later added to the seeds.

F = (Frame counter * 256) + ((int(((Swap nibbles(Frame counter) + 1) mod 256) / 2) + 135) mod 256)

Next, the game calculates a number based on the current value of the two seeds. This formula is simpler:

S = Seed 1 * 256 + Seed 2

To obtain seed 1:

Seed 1new = ((F+S) mod 256)

To obtain seed 2:

Seed 2new = (int(((F+S) mod 65536)/256)) xor ((F+S) mod 256)

The seeds are then added together (reduced to 8 bits), and this is the randomly generated number.

Random events

Wild Denjuu

Species

For more information, see one of these pages.

Random number range Probability Denjuu Group
0-24 10% Denjuu 4
25-75 20% Denjuu 3
76-152 30% Denjuu 2
153-255 40% Denjuu 1

Level

Random number range Probability Level offset
0-63 25% +1
64-127 25% -1
128-255 50% 0

Personality

Random number range Probability Personality
0-19, 240-255* 14% 0
20-39 8% 1
40-59 8% 2
60-79 8% 3
80-99 8% 4
100-119 8% 5
120-139 8% 6
140-159 8% 7
160-179 8% 8
180-199 8% 9
200-219 8% 10
220-239 8% 11

Battle events

Move accuracy

Critical hits

Damage calculation

Personality flaws

AI

Target selection

Move selection

Escaping

More research needed!

When 0xD504 <= 0xD546 (note: these addresses' behavior are unknown, although both seem to always be 0 before battling):

Random number range Probability Level offset
0-199 78% Unable to escape
200-255 22% Able to escape

When 0xD504 > 0xD546 (note: these addresses' behavior are unknown, although both seem to always be 0 before battling):

Random number range Probability Level offset
0-84 33% Unable to escape
85-255 67% Able to escape

Denjuu giving out number