Author Topic: Whose turn is it?  (Read 3296 times)

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Whose turn is it?
« on: October 30, 2013, 09:55:27 AM »
Does anybody have any insight into how the game determines when a character's turn comes up in battle?
I imagine it makes calculations based on the Relative Speed values, but based on the fact that there will be times in battle when nobody is doing anything, it can't just be a turn queue (like in FFX or FFT).

So I imagine there must be timers counting down to each character's turn... anybody know where in RAM those are? Or have an idea about how to start looking for them?

Or maybe I'm totally off base and turns are determined some other way?

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Whose turn is it?
« Reply #1 on: October 30, 2013, 11:33:15 AM »
An interesting idea Chillyfeez, I suspect that it is an invisible ATB gauge that counts up until that person's turn is reached. I'll see if I can't find anything more concrete...

Hmm, well just by simple mathematic I think that Yousei must have been off on his relative speed dealings.

Cecil's Agility x 32 / Character's Agility x 0A if it is Cecil's case it should Always Equal 03, but the value that seems to be consistent is that it is 5 no matter what.

But if it is reading another character, then it might make sense...

A level 1 Rydia with 4 Agility who is in a party with a 99 Agility Cecil has EF01 as her Relative Speed.

99 x 32 = 3168 / 4 x 10 = 40. 3168 /40 should only be 79. But EF+(255x1)01 is 495.

She'll get one turn to Cecil's 20 it seems.

This is definitely worthy of further exploration.


chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Whose turn is it?
« Reply #2 on: October 30, 2013, 01:36:34 PM »
What I'm trying to be able to do is force (or delay) a single turn, without affecting the character/monster's speed otherwise. The end result would be a new attempt at making a Mime command (I can't just let this die) by using the Charging status from Yang's Charge ability, which sets a next action and a status that executes that action next turn. If I could force that next turn in the same command...
Well, that's the idea, anyway. The method's all worked out in my head, except I can't force the turn.
Of course the possibilities of what we could do with this wouldn't end there... wasn't there a Charge command in FFV that made all party members attack? We could do something like that, too. Maybe even an X-Magic...

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Whose turn is it?
« Reply #3 on: November 01, 2013, 11:58:03 AM »
Aha!
Found the hidden ATB gauge.

Turns out the Bab-il docs are wrong, or at least incomplete. They say that the data at 2A04-2A2A is "status duration data for each slot," and that 2A2B-???? is "poison data."
Well, some of this might be true, but here is what I've found out for sure...
Beginning at 2A05, there are 15 (hex)-byte records for each battle participant (beginning with the five party slots, then on to monsters). Byte 02 of this record counts down until it is time for the character/monster to do something. This counts for when he/she/it is ready to take a turn, or if casting, when he/she is ready to cast the spell. Everybody's timer counts down at the same rate, and the beginning number is higher depending on relative speed (or, presumably, casting duration of the spell).

More research and testing is needed before I can say that I can use this info in custom commands to force or delay an individual's turn, but it is definitely possible to do so by hand with Geiger's.

Also, byte 04 has something to do with what the character is doing during that wait. 80 is "waiting for command." 00 is either "defend," or simply "waiting for next turn." It seems having bit 0 set freezes the timer altogether, thus making the character unable to take a turn (which does not freeze the game, but appears to be permanent through the end of the battle.

Interesting stuff...

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Whose turn is it?
« Reply #4 on: November 01, 2013, 04:07:58 PM »
Wow! Great work there Chillyfeez! I'll have to scrounge around that area a bit and see if I can't help with figuring this out.

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Whose turn is it?
« Reply #5 on: November 01, 2013, 05:25:58 PM »
I'm not able to mess with it too much today, but my guess is that the timer isn't set until after the command takes place, so changing the value it starts at probably will require affecting the factors that determine that number instead of something as simple as setting the number within the instructions of a command (if that makes any sense).

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Whose turn is it?
« Reply #6 on: November 04, 2013, 11:08:09 AM »
Made some exciting strides on this one!

Remember that byte 04 I was talking about? Well, if it's set to 08, then when the timer reaches zero, the character will do whatever action is in their "next [or most recent] action" byte.
You can test this out to see. Load your game in Geiger's and get into a battle. View RAM at 7E2A04. You'll see the counters. You'll have to perform an action with a character first. After that, their "charging status" byte will turn to 00 (it's the second byte after the timer). Change it manually to 08. When the timer reaches zero, the character will automatically perform that same action again.
Notice that both Jump and Charge/Boost/(whatever) contain these three commands in succession:
Code: [Select]
20 C8 85  JSR $85C8
A9 08     LDA #$08
9D 06 2A  STA $2A06,x
Well, subroutine 03/85C8 identifies which character to address in the duration table. Then the next two commands put 08, or "automatically perform 'next action,'" in the appropriate byte for that character.

Also, there is a table in ROM at A0189 that contains one-byte-per-command references to the duration set to perform each command. Most of them are 00, which is immediate. 01 is not one second, though. These are pointers. I haven't tested all 256 options (and probably won't) but the following are used:
00: (most commands) immediate
01: (Charge) 5 seconds
02: (Dark Wave, a few others) 2 seconds
04: (Salve, Aim) 1 second
FE: (not used, but I tested it to see if it would crash the game - it doesn't) several hundred seconds

I am nearly positive that with this knowledge, I have enough to make my Mime command! Might take a few days to get it working...
« Last Edit: November 04, 2013, 11:14:32 AM by chillyfeez »

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Whose turn is it?
« Reply #7 on: November 04, 2013, 12:22:51 PM »
That is Awesome! Incredible work there Chillyfeez! Finally now we can add wait timers to some commands that should have them to begin with, I was looking for the elusive "timer" bytes, but I expected them to be in the command routines themselves, not in a completely separate part of ROM.

Again, well done! That would make a very neat little addition to the editor.

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Whose turn is it?
« Reply #8 on: November 06, 2013, 12:10:56 AM »
Hmm... seems I'm still missing a key portion of the Jump and Charge routines that causes the 08 timer status to stick after they return. Think I'm gonna have to test Charge command-by-command til I find it. Ah, well. I'll get there eventually. Really hope I can find the time sooner rather than later.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Whose turn is it?
« Reply #9 on: November 06, 2013, 12:30:34 AM »
Hmm...

http://slickproductions.org/forum/index.php?topic=1883.msg19350#msg19350

Is this of any help in that? Charge and Jump's second portion does make it go through the Fight Routine which would likely reset the timer all on its own.

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Whose turn is it?
« Reply #10 on: November 06, 2013, 08:10:18 AM »
I've been referring heavily to your disassemblies for this process. I actually haven't tried changing Charge's 1F to see if it works with other commands. I'm kind of afraid to find out...

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Whose turn is it?
« Reply #11 on: November 06, 2013, 11:24:31 AM »
Charge and Jump's secondary command can be changed (Though Jump's might be a bit finnicky because of the "coming back down" animation that is used in that. Charge I've tested pretty extensively the only problem with it is that the Charging Status never goes away because it is the 1F command that removes it, itself. There are benefits and downsides to having Charge status though. Mainly Charge has an innate x2 damage with the status but has Defense and Magic Defense cut in half. This, in my opinion, more fits Berserk, than it does Charging which never should have had those restrictions placed on it in the first place.

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Whose turn is it?
« Reply #12 on: November 06, 2013, 12:02:21 PM »
Do you happen to know the purpose of INC $390A?
Jump and charge both use that, too, but the RAM map in the Bab-il docs does not identify 7E390A. I have a day off tomorrow so I've resolved to figure it out then.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Whose turn is it?
« Reply #13 on: November 06, 2013, 12:18:31 PM »
Not only Jump and Charge, but Regen uses it as well. The information around 390A is mostly stuff dealing with stats.
3901      Caster's Critical Hit Bonus
3902      Caster's Attack Power

3904      Target's Magical Defense Rate
3905      Target's Physical Defense Rate

I've never given it much thought, but it may be more important than it seems.

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Whose turn is it?
« Reply #14 on: November 06, 2013, 05:21:17 PM »
Regen, too... as in, another command that sets an automatic next command? I bet that's part of the puzzle! Thanks for the info!