Author Topic: FF7: ATB Formula  (Read 17543 times)

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
FF7: ATB Formula
« on: 2008-08-25 03:48:57 »
I've looked through a substantial amount documentation (though I could've missed something) and I've been unable to find any clear definition of how Dexterity *exactly* affects the speed of the ATB.

Does anyone here know the exact mechanics behind it? I would try get ahold of TFergusson, as he's written quite a lot of documentation on mechanics for FF7, but he's fallen off the map somewhat.

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #1 on: 2008-08-25 19:34:21 »
Maybe I'll reverse this soon. though I still went through initialization of player units.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #2 on: 2008-08-26 01:15:38 »
Well if it comes to it I could derive the equation by testing dexterity at 1 and at 255 then assuming a linear equation (which it is, most likely). But then there are other factors like if each character recieves slightly different benefit from dexterity, and how that changes in each level bracket, which wouldn't surprise me as this kind of mechanic is extremely typical of how a lot of things in FF7 are calculated. If you have any insight in the form of an equation, or table, or the time/interest to derive it, I would greatly appreciate it.

Lets just say that I need it for a 'very exciting project'. :wink:

Maybe I've said too much.
« Last Edit: 2008-08-26 01:19:43 by Vanit »

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #3 on: 2008-09-09 17:50:48 »
Start unit timer value completly random. It can be modified depending on type of battle. For example in preemptive battle player has 0xfffe value and enemy are 0x0. In some type of battles (where you surround enemy) enemies random value divided by 8. I post full list later.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #4 on: 2008-09-10 11:00:01 »
I've been wondering about that. Looking forward to seeing the full thing and thanks again for following it up. :D

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #5 on: 2008-09-11 13:14:27 »
Action timer are value 0 - 0xffff. 0xffff - means unit can act.

There are 6 types of battle formation.
0,5 - normal
1,3 - player advantage
2,4 - enemy advantage

Start value of action timer for normal battle calculated as "[random 0-0xffff] + 0xe0000 - max_random".
Max random are maximum random value among all units.
Start value of action timer for player advantage battle are 0xfffe for player and "[random 0-0xffff] / 8" for enemy.
Start value of action timer for enemy advantage battle are 0x0 for player and "[random 0-0xffff] + 0xf000" for enemy.
There is some additional check (I think this is for sephiroth battle) that set player action timer to 0xfffe and set enemy timer to 0.

Action timer increase by unit speed aproximately 30 times per second.

Unit speed calculated as "battle_speed * dexterity / party_dexterity". This uses final dexterity with all bonuses and we add 0x32 to dexterity for player units.
Party dexterity calculated as sum of dexterity from all party units divided by number of party members plus 0x32. Real formula looks like this "((total_dexterity - 1 + number_of_party) / number_of_party + 0x32)"
Battle speed calculated as "0x8000 / (config_battle_speed * 0x3c0 / 0x100 + 0x78)"
It's speed for slow status. It is multiplied by 2 for normal and by 4 for haste.

Final formula cooks like this:
(0x8000 / (config_battle_speed * 0x3c0 / 0x100 + 0x78)) * [1-slow|2-normal|4-haste] * dexterity_with_bonuses / (((dexterity_1 + dexterity_2 + dexterity_3 - 1 + number_of_party) / number_of_party + 32))
« Last Edit: 2008-09-11 13:19:14 by Akari »

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #6 on: 2008-09-12 11:51:31 »
So let me get this straight (just bouncing it back paraphrased/elaborated to make sure I get it right):

The action bar is a percentage representation of a scale between 0 and 65535. In a normal battle, the start position is calculated as: [random 0-65535] + 917504 - [the maximum random component out of all the party members]  <- somewhat confused by this, because if it is +0xe0000 then the value is going to be way over the maximum value of the action bar, unless you meant 0xe000, which would be more inline with the value I was assuming.

In a player advantage battle, the player starts at 65534/65535 (basically full), and the enemy starts at [random 0-65535]/8.

In an enemy advantage battle, the player starts at 0 and the enemy is [random 0-65535] + 61440 (nearly always full).

Action bar is incrementally increased 30 times per second, with the equation:

(32768 / (config_battle_speed * 960 / 256 + 120)) * [1-slow|2-normal|4-haste] * dexterity_with_bonuses / (((dexterity_1 + dexterity_2 + dexterity_3 - 1 + number_of_party) / number_of_party + 50))

And config battle speed is the speed indicated by you in the menu right? Do you know the range of values for this? I do know that the relationship is inversely proportional between config battle speed and the amount per increment (higher the cbs, lower the increment is).

In anycase thank you SO much. This equation will be put to very good use. ~_^
« Last Edit: 2008-09-12 12:15:38 by Vanit »

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #7 on: 2008-09-12 13:12:57 »
Not 0xe0000... sorry. 0xE000 of course.

Config speed value between 0x0 and 0xff. Higher value - slower the battle speed in the end.

The main reason for all those calculation are make real battle speed less dependent on dexterity. So if all units has dex 1 and all units has dex 255 - battle speed will be the same, only difference has meaning. And it depends only on players dex cause this is visible in battle.

And note that unit battle speed stored as 2 bytes value so all higher bits will be ignored. So I don't see difference between  [random 0-65535] + 61440 and [random 0-65535].

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #8 on: 2008-09-12 22:02:14 »
[random 0-65535] + 61440 is basically just another way of writing [random 61440-65535] really, but its left expanded so when [max_random] is substracted, it can still be a value from 0-65535.

I have another request for you as there is another equation I need that is completely undocumented. It would be great if you could work out the equation that powers the limit bar (ie the one that decides how much your limit bar should go up depending on how hard you're hit).
« Last Edit: 2008-09-12 22:16:34 by Vanit »

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #9 on: 2008-09-22 01:31:15 »
I don't know if you're actually working on the limit equation since you gave no confirmation, but I found that TFergusson actually had the equation burried at the very end of his party mechanics guide:

Quote
Units gained = [[300 * HP Lost / Max HP] * 256 * Status Factor / LNum]

In the above formula, Status Factor is equal to 2.0 while in 'Fury' Status,
0.5 in 'Sadness' Status, and 1.0 otherwise.

LNum is derived from a table that I'm not attaching, but can be found here.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #10 on: 2009-05-09 09:50:31 »
I'm necro'ing this thread as I finally got up to the stage where I needed the ATB formula. Until now it was just sitting in a text file under the assumption it was correct, but after some inspection I've found it to be completely wrong. I've PM'd Akari, but they haven't posted in 2 months so I'm unsure how active they are.

Here's my math:

battle speed = (0x8000 / (config_battle_speed * 0x3c0 / 0x100 + 0x78)) *[1-slow, 2-normal, 4-haste]
config_battle_speed = 127
therefore, battle speed = 109.9

dexterity = 50

party_dexterty = ((total_dexterity - 1 + number_of_party) / number_of_party + 0x32)
=(150-1+3)/3+50
=100

therefore, 1 itteration = 109.9*50/100
=54.95

It was stated there are 30 itterations per second, which means UPS (units per second), is 1648.5 - meaning it would take that character just under 40 seconds for their ATB to hit full. Obviously there's something wrong with this algorithm. I've tried messing around with it to see if theres any small mistakes I could fix or if there were parts I intepretted wrong, but I've been unable to reach anything close to accurate with what speeds I get in the actual game.

Is there anyone else who would be able to find the ATB formula for me? Would be greatly appreciated. :)

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #11 on: 2009-05-11 15:38:12 »
Don't forget that all player units has 0x32 added to their dexterity.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #12 on: 2009-05-12 00:02:20 »
All that does is increase party dexterity, which actually just makes UPS even lower, which doesn't fix the equation at all. I'm 99% sure the one you've listed is incorrect, I've put it in a spreadsheet if you want to see for yourself.

As I've said, I've tried messing around with the equation and nothing I've done makes it seem close to accurate. Regardless of the value of Party Dexterity, the Dexterity of the character being calculated for has WAY too much weight on UPS. I've been able to come up with my own approximation of what the real ATB Formula should be (see below, also have a spreadsheet for it), but I'd like to be using the actual one.

UPS/30 = BattleSpeed + Dexterty * 5

Dexterity = 50
Config Battle Speed = 127.
Battlespeed = 32768/(Config Battle Speed* 960/256 + 120) * 3 * [1-Slow, 2-Normal, 4-Haste] = 329.7

therefore, UPS/30 = 329.7 + 50 *5 = 579.7
Time to Full = 65535/(579.7*30) = 3.8s

This equation is within +/- 0.5s of the real equation for all valid values of Dexterity, Config Battle Speed and the Slow/Normal/Haste modifer in any combination. Still would be nice to have the real one though.
« Last Edit: 2009-05-12 00:33:03 by Vanit »

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #13 on: 2009-05-12 04:25:05 »
Well... little addition. When you calculate party dexterity - data used directly from savemap. But when you calculate number of time units you wish to add each tact you add 0x32 to player dexterity. Only to player!

So final result of time will be twice less.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #14 on: 2009-05-12 08:06:10 »
Would you be able to do a calculation and show me exactly what you mean? ^^;

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #15 on: 2009-05-13 03:12:15 »
Quote
therefore, 1 itteration = 109.9*50/100
=54.95

It was stated there are 30 itterations per second, which means UPS (units per second), is 1648.5 - meaning it would take that character just under 40 seconds for their ATB to hit full.

therefore, 1 itteration = 109.9*(50+50/100
=109.9

It was stated there are 30 itterations per second, which means UPS (units per second), is 3297 - meaning it would take that character just under 20 seconds for their ATB to hit full.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #16 on: 2009-05-13 07:53:29 »
But 20 seconds is not what you see in application, how do you explain that? There must be something up with this algorithm if the output ingame is different.

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #17 on: 2009-05-13 18:49:59 »
But 20 seconds is not what you see in application, how do you explain that? There must be something up with this algorithm if the output ingame is different.

I debugged a little, so some results. Battle speed is from 0x36 to 0x111, where 0x5b - with config value 0x80.
Incrementation called 4 times per frame (I don't know why, but it looks this way), so it will be 120 times per second
And it takes from 3 to 12 seconds per turn, where 7 - with config value 0x80.

ps: checked at the beginning of the game.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #18 on: 2009-05-13 22:43:33 »
Thanks for looking into it. Could you write out the entire algorithm with an explaination of all the variables again? I wasn't able to reproduce your last numbers so I must still have something wrong, and it would be nice to have a full clarification. :)

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #19 on: 2009-05-14 02:55:29 »
Thanks for looking into it. Could you write out the entire algorithm with an explaination of all the variables again? I wasn't able to reproduce your last numbers so I must still have something wrong, and it would be nice to have a full clarification. :)

Ooops. Looks like I shifted value one more time =) You need to use 0x1e0 instead of 0x3c0
Exact formula looks like this
battle speed = 0x10000 / (((config_speed * 0x1e0 / 0x100) + 0x78) * 2)
next you multiply in by 1,2 or 4 if character is slow normal or haste and calculate final value.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #20 on: 2009-05-14 08:53:30 »
Sweet, this seems to check out. Thanks so much for working with me to get to the bottom of this. :D

Also for enemies, is the ATB equation the same - but without the +50 bonus to the character's dexterity and the overall party dexterity? And if this equation does apply to enemies - what constitutes a party for them? Is it the entire field or is it every row?

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #21 on: 2009-05-14 15:44:54 »
Sweet, this seems to check out. Thanks so much for working with me to get to the bottom of this. :D

Also for enemies, is the ATB equation the same - but without the +50 bonus to the character's dexterity and the overall party dexterity? And if this equation does apply to enemies - what constitutes a party for them? Is it the entire field or is it every row?

Party members are only player. No matter you calculate enemies or not. Speed of battle always depends on player. That's why visually speed of battle always the same.
In case of enemies you just don't add 0x32 to final dexterity.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #22 on: 2009-05-14 16:23:10 »
So are you saying the equation for enemies looks like this:

UPS/120 = Battle Speed * [1-slow, 2-normal, 4-haste] * enemy_dex / player_party_dex

Akari

  • *
  • Posts: 766
    • View Profile
Re: FF7: ATB Formula
« Reply #23 on: 2009-05-14 18:11:59 »
So are you saying the equation for enemies looks like this:

UPS/120 = Battle Speed * [1-slow, 2-normal, 4-haste] * enemy_dex / player_party_dex

Yup.

Vanit

  • *
  • Posts: 73
    • View Profile
    • http://vanitstudios.burn.at
Re: FF7: ATB Formula
« Reply #24 on: 2009-05-14 23:01:51 »
Sweet. Would you be interested in looking into another algorithm for me?

I'm interested in the algorithm that defines a "time unit" - the "flow of time" when in battle. This affects the duration of the spells and their intensity per second. For example under a quick flow of time, Regen restores health quickly, but has a short duration.

I'm guessing the equation to determine how many seconds a time unit is, looks something like this:

1 time unit = unknown_variable/[1-slow, 2-normal, 4-haste] * battlespeed.
« Last Edit: 2009-05-15 01:53:38 by Vanit »