Author Topic: How is the order of FF7 encounters (battle formations) picked?  (Read 4819 times)

BrutalAl

  • *
  • Posts: 17
    • View Profile
I'm trying to figure out exactly how the game picks the order of different battle formations. I know some about it atm but not enough yet to figure it out.
If anyone happens to know all this already feel free to enlighten me :)

What I know (in short)
I know that from a hard reset the order of the enemy formations you encounter (in random field battles) will always be the same.

E.g. if you encounter EnemyA, EnemyB, EnemyC, in that order (in three separate battles) you will again if you hard reset the system (turn the PSX power off/on) then load a file and fight in the same area.
If you from a hard reset fight only one battle (against EnemyA), then soft reset and load a file and fight another battle in the same area this battle will be against EnemyB, and if you soft reset again and fight another battle yet again this one will be against EnemyC. In other words, the order is kept/remembered as long as the system isn't powered off.

I know that the RNG-list that is used for deciding when to give you an encounter is also the RNG-list that is used to decide what encounter (battle formation) that will be (and I have a somewhat good idea of how the actuall values in the RING-list are used to decide the formation).

I have located a counter that keeps track of how many battles you have fought since latest hard reset, however its behaviour is somewhat random (it's increased by 1-3 per battle) but if it is reset back to 0 (by unnatural means) you will reset the order (i.e. the next Fight will be against EnemyA, then B then C). What decides how this counter behaves is still unknown to me though.

I'm currently not at my work station so I don't have the memory addresses for all the values involved, as soon as I get back I'll add them to this thread, but until then the above information will have to do.
« Last Edit: 2009-04-20 13:24:20 by BrutalAl »

LJH

  • *
  • Posts: 132
    • View Profile
You forgot to state which game you're talking about here... I would assume either FF7 or FF8, since FF7 is most commonly talked about here and I've heard of stuff like this happening with FF8...

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
FF7 has a psudo-random number generator. It's a list of 256 numbers, numbered 1-256 that has been scrambled. The pointer for what number is "current" is saved. This is why you hit the same fight after a load. After the random function is used, the pointer advances one.

BrutalAl

  • *
  • Posts: 17
    • View Profile
Sorry, FF7

Yes. I know about the RNG-list and pseudo randomness, but it isn't simply picking the first number for the first battle and then moving on to the next number for the next battle.

More Data
In the memory the RNG list can be found at address 000E0638 to 000E0737 (PSX NTSC US version).
The value that is increased by 1, 2, or 3 (I've only observed those three increments) at each battle can be found at address 00071C20 (PSX NTSC US version).

If we stay at the rather small field (ID#461, 01CDh) that resides in between the 'Mt. Corel Reactor' field and the 'Roller Coaster Section' field and play 20(23) Battles it will all line out like this;

Battle Formation # (1st Encounter to the left):
#4,#2,#1,#4,#3,#2,#4,#3,#4,#2,#4,#2,#1,#3,#2,#4,#2,#4,#3,#2,(#4,#4,#4,...)
#1 = 1x Bomb, Chance 18/64
#2 = 2x Bomb, Chance 17/64
#3 = 1x Cocatolis, 2x Boatfloat, Chance 15/64
#4 = 2x Cocatolis, Chance 14/64

Counter That is Incremented at Encounter (and remembered between soft resets, is 0 at start):
2,4,6,8,11,13,15,17,20,22,24,26,28,30,33,36,38,40,43,46,(48,51,54,...)
Note: It will be 0 before your first encounter but turn to 2 the instance you get that first encounter. I.e. It is incremented AT encounter and not after.
Also Note: Fighting one or more battles at any other field Could alter this pattern, but will not necessarily do so. Because of this I believe the encounter itself has something to do with this value's behavior.

First 20(23) values in the RNG list:
decimal: 177,202,238,108,90,113,46,85,214,0,204,153,144,107,125,235,79,160,7,172,(223,138,86,...)
hex: B1,CA,EE,6C,5A,71,2E,55,D6,00,CC,99,90,6B,7D,EB,4F,A0,07,AC,(DF,8A,56,...)


What I think I know
For the first encounter the 3rd value in the RNG list will be used (the one in slot 02 if you count the first one as being in slot 00), namely 238.
And the game does the following:

x = 238
r = 'Battle Formation #1 Chance' * 64  //18
s = 'Battle Formation #2 Chance' * 64  //17
t = 'Battle Formation #3 Chance' * 64  //15
u = 'Battle Formation #4 Chance' * 64  //14

If x<r*4 {Give Battle #1}
Else If x<(r+s)*4 {Give Battle #2}
Else If x<(r+s+t)*4 {Give Battle #3}
Else {Give Battle #4}  //(r+s+t+u)*4 will always be 256 in a set of 4 battles

For the 2nd encounter the 5th value in the RNG list will be used, the one in Slot 04, namely 90. A similar check to the one above is made BUT for some reason the 6th value in the List (Slot 05) has something to do with the outcome. If the 6th value is set to 00h the game will pick the battle # just like it did for the first encounter but if set to 80h it wont, i do not know why.


This is pretty much what I got so far, I will probably try some more in a very near future but for now this is it. Anyone up for the challenge is more than welcome to help out or solve this before I do :)

EDIT:
Been looking at it some more and did managed to figure most of it out. Was still somewhat puzzled as to why it used RNG x+1 instead of x sometimes though, but fortunately Terance's "Enemy Mechanics" actually hand an explanation for that specific behavior and with that all the remaining blanks could be filled. So yeah, problem kinda solved.
« Last Edit: 2009-04-25 00:22:48 by BrutalAl »