øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=2188.msg27026e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index3eb6.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=2188.75e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index3eb6.html.zx" FFV Damage Calculator

Author Topic: FFV Damage Calculator  (Read 9849 times)

Squall

  • Dark Dragon
  • *
  • Posts: 486
    • View Profile
Re: FFV Damage Calculator
« Reply #75 on: February 08, 2017, 03:50:13 AM »
Quote
the bottom 2 bits of a weapon's Targeting byte ($4085 or $4091) are used as an index into a table to load 0, 10, 20, or 30.  this is done for each hand, with the values being added together.  the result is modified based on possessed Haste or Slow, then stored in some ATB variable.
If by bottom you mean bit 0 & 1, they are undefined in Jorgur's document

However your observation may shed a light on 2):
Code: [Select]
6.11) ATB CALCULATION
---------------------
1) Everyone's ATB is a measure between 0 and 255.
2) Initial values at the start of battle = ??
3) Eveyone's ATB increases at a constant rate (unlike FF6-9).
4) Once someone's ATB reaches 255, they can perform an action.
5) After performing an action, their ATB gets "reset" and is calculated as follows:

Quote
when does the game ever use $408E or $409A , Parameter 1 for the weapon Action?  i see no evidence of this in Bank C2.  it'll load Attack Formula, and Parameters 2 and 3.
Param1 usually contain the chance a wepon to proc Action, while 2 & 3 contain the params for the action

Squall

  • Dark Dragon
  • *
  • Posts: 486
    • View Profile
Re: FFV Damage Calculator
« Reply #76 on: February 09, 2017, 04:35:14 AM »
Quote
Param1 usually contain the chance a weapon to proc Action, while 2 & 3 contain the params for the action
Sorry my mistake. It seems Param1 is used as usual in the DF for the weapon. Param 2&3 are used for the Action.
Param2 - is % chance for FX
Param3 - is the FX action to perform.

So to answer your question the code that handle the FX uses only param 2 and 3.
Param 1 is used before executing the FX code and is connected to the weapon. For example:
- Venom Axe uses param 1 for hit% chance
- Air Blade (katana) - uses param 1 for crit % chance
- Dragon Whip - uses param 1 for 'Strong VS' (Dragon type)

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: FFV Damage Calculator
« Reply #77 on: February 09, 2017, 12:29:41 PM »
thanks..

you confirming that prompted me to look at the variable chain backwards, and i found the $4085 variables being copied to $79FC variables in C2/09DD.  this after seeing that $7A05 (with offset $39 varying by hand used?) later gets put in Var $57 in C2/653A.

also, i wonder whether parts of C2/09DD were written by robots or monkeys.

the most blatant:
Code: [Select]
C2/0A06: D0 03        BNE $0A0B
C2/0A08: 4C 3C 0A     JMP $0A3C
C2/0A0B: 20 23 99     JSR $9923

[...]

C2/0A41: D0 03        BNE $0A46
C2/0A43: 4C 79 0A     JMP $0A79
C2/0A46: 20 23 99     JSR $9923

then we have:
Code: [Select]
C2/0A22: A6 0E        LDX $0E
C2/0A24: BD 8D 40     LDA $408D,X
C2/0A27: 48           PHA
C2/0A28: AD FA 79     LDA $79FA
C2/0A2B: AA           TAX
C2/0A2C: 68           PLA
C2/0A2D: 9D 2D 7B     STA $7B2D,X
C2/0A30: 9E 1C 7B     STZ $7B1C,X
C2/0A33: 9E CC 7A     STZ $7ACC,X

admittedly a pain in the ass situation (if you have one index register available), so they use the stack to work around it.  lower down, they try a different approach for the same thing:
Code: [Select]
C2/0A5D: A6 0E        LDX $0E
C2/0A5F: AD FA 79     LDA $79FA
C2/0A62: A8           TAY
C2/0A63: BD 99 40     LDA $4099,X
C2/0A66: 99 2D 7B     STA $7B2D,Y
C2/0A69: AD FA 79     LDA $79FA
C2/0A6C: AA           TAX
C2/0A6D: 9E 1C 7B     STZ $7B1C,X
C2/0A70: 9E CC 7A     STZ $7ACC,X

...but this way is even 2 bytes bigger.  the amazing thing is once they go with Y, an elegant solution of "TYX" is staring them right in the face, and they reload from Var $79FA anyway!  or they could "LDY $0E" instead, do all writes with an X index ("TAX" at C2/0A62), and drop the "TYX" as well.

that's 4 bytes smaller than second snippet, 2 bytes than the first.  and then putting the large chunks of "LDY $0E" thru "JSR $98E3" into its own function would save 17 bytes more.

Squall

  • Dark Dragon
  • *
  • Posts: 486
    • View Profile
Re: FFV Damage Calculator
« Reply #78 on: February 10, 2017, 08:25:31 AM »
Quote
also, i wonder whether parts of C2/09DD were written by robots or monkeys.
Hehe I like that.

Probably around a year ago I made similar comment. My guess is that part of the code was written in a higher level language (non asm) and then compiled. Such asm code pretty much resemble compilation of "if xxx then ..." statements (or multi if - "case"). But definitely part of the code was written in pure asm.

Thats normal way of developing any huge by its scope application/system. You write the main logic with something that is easy to change/easy to read and then you optimize some tough spots (bottlenecks).

P.S. assassin, I'm very interested in your observations on bottom bits of Targeting byte. I checked all the weapons but it seems they use 00 there. Then I checked all the Actions (they use similar structure as weapons) nothing. So either  its left code from previous FFs or  ... there is a separate place that adds lower 2 bits ...

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: FFV Damage Calculator
« Reply #79 on: February 10, 2017, 09:47:19 AM »
yeah, they really need to go back and replace all their JSR $01C0 / $01BF / $01B7 / $01B6 calls, for instance.

argh, was hoping i'd found something of use.  so it's a dummied feature, or like you said, the bits get added in later.  maybe try putting a breakpoint on D0/ECEF , D0/ECF0 , and D0/ECF1 starting just before battle, and see whether they're accessed from that C2/1Bnn function, with a variety of weapons in hands.

can you check Usable Items for the bottom two Targeting bits?  they're another thing that function's code checks.

Squall

  • Dark Dragon
  • *
  • Posts: 486
    • View Profile
Re: FFV Damage Calculator
« Reply #80 on: February 13, 2017, 02:44:16 AM »
Quote
can you check Usable Items for the bottom two Targeting bits?  they're another thing that function's code checks.
Sure I forgot about them.

Checked - same here, no item is using lower 2 bits ...

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: FFV Damage Calculator
« Reply #81 on: April 03, 2018, 08:58:42 PM »
(another edition of my annual Ask About Variable $63)

does anybody know of abilities, script commands, or any circumstances that can cause an attack's damage to be redirected to the attacker?

i ask because i think that's what this variable involves, based on the following understanding of the $7Bnn variables:

Code: [Select]
$7B69 = HP or MP damage and/or healing, working copy

-----

$7B6B = attacker HP damage
$7B6D = target HP damage

$7B6F = attacker HP healing
$7B71 = target HP healing

-----

$7B73 = attacker MP healing
$7B75 = target MP healing

$7B77 = attacker MP damage
$7B79 = target MP damage

(gar, those were already covered at: http://erick.guillen.com.mx/Codes/SNES%20Final%20Fantasy%20V.txt)

also, i believe target elemental absorption (Variable $62) will preempt this.

however, knowing jack squat about the game in general, nothing's jumping out at me as a candidate for setting Variable $63 when i scroll through the Algorithms FAQ.  but it might be obvious to somebody who knows something about FF5.

Squall

  • Dark Dragon
  • *
  • Posts: 486
    • View Profile
Re: FFV Damage Calculator
« Reply #82 on: April 04, 2018, 02:24:58 AM »
I remember your interest in $63 from before. Unfortunately I know nothing about it, neither I recall being used in battle mechanics  :blush:

Quote
does anybody know of abilities, script commands, or any circumstances that can cause an attack's damage to be redirected to the attacker?
The only thing that comes to my mind is Reflect. There is no implemented mechanics that does deflect/redirect of damage, the way its done in some contemporary RPG (if thats what you have in mind).

Quote
i ask because i think that's what this variable involves, based on the following understanding of the $7Bnn variables:
Well that is a standard 'way' of calculating damage, since Healing is also considered a damage (with revert sign). That mechanics is used in pretty much all FF 1-6 (can't recall about 7).

x0_000

  • Siren
  • *
  • Posts: 72
    • View Profile
Re: FFV Damage Calculator
« Reply #83 on: April 11, 2018, 12:20:43 AM »
!Guard also redirects physical attacks (although self damage probably can't occur from various coding.)

Edit: I did a quick memory hack of FFVA and made it so confused player characters can cover their own attacks, so it's very technically possible.
« Last Edit: April 11, 2018, 01:11:01 AM by x0_000 »

Squall

  • Dark Dragon
  • *
  • Posts: 486
    • View Profile
Re: FFV Damage Calculator
« Reply #84 on: April 11, 2018, 01:43:46 AM »
!Guard also redirects physical attacks (although self damage probably can't occur from various coding.)
No Guard reduce physical damage but doesn't redirect it :)

x0_000

  • Siren
  • *
  • Posts: 72
    • View Profile
Re: FFV Damage Calculator
« Reply #85 on: April 11, 2018, 03:22:36 AM »
Whoops, meant the Cover skill.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: FFV Damage Calculator
« Reply #86 on: April 20, 2018, 07:38:44 AM »
thanks both for the replies.

x0_000: based on your post, i investigated Cover.  the function at C2/964D handles it, and seems to reroute the target there.  i see no $63 references in the function, and it seems unlikely that Cover would need to use the variable later.

Squall: based on your post, i tried to investigate Reflection, but there's jack squat documented in the Bank C2 disassembly.  so having no clue how it's implemented, i'm also less likely to rule it out as a $63 candidate.