Damage and Knockback Routine (Dash, tackle, throw stone)

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search

Calculate XA * 1..Y damage, and then have a chance for knockback.

Chance for knockback is random (meaning the chance itself):

0..(atkr.Br - 1) / target.Br

The actual chance should be the probability of:

0..(atkr.Br - 1) >= 0..(target.Br - 1)

which is roughly

atkr.Br / (atkr.Br + target.Br)


Code:

                                             Alternative notes Damage_and_Knockback_Routine_(alternative)
0018691c: 27bdffe8 addiu r29,r29,0xffe8     ~
00186920: afbf0010 sw r31,0x0010(r29)       ~
00186924: 0c063ba8 jal 0x 0018eea0          r2 = 0..7FFFh
00186928: 00000000 nop                      ~
0018692c: 3c038019 lui r3,0x8019            r3 = ability param Y
00186930: 906338fa lbu r3,0x38fa(r3)        ^
00186934: 00000000 nop                      ~
00186938: 00430018 mult r2,r3               r2 = 0..(Y-1)
0018693c: 00001012 mflo r2                  ^
00186940: 04410002 bgez r2,0x 0018694c      if r2 < 0:          //force positive
00186944: 00000000 nop                      ~
00186948: 24427fff addiu r2,r2,0x7fff           r2 += 7FFFh     
0018694c: 000213c3 sra r2,r2,0x0f           r2 /= 8000h         // r2 = 0..(Y-1)
00186950: 3c038019 lui r3,0x8019            load XA
00186954: 946338ce lhu r3,0x38ce(r3)        ^
00186958: 24420001 addiu r2,r2,0x0001       r2 += 1             // r2 = 1..Y
0018695c: 00430018 mult r2,r3               // see 00186978
00186960: 3c048019 lui r4,0x8019            r4 = target action data pointer
00186964: 8c842d90 lw r4,0x2d90(r4)         ^
00186968: 34020080 ori r2,r0,0x0080         target_action_data->25h = 80h  //?
0018696c: a0820025 sb r2,0x0025(r4)         ^
00186970: 3c038019 lui r3,0x8019            r3 = is-prediction
00186974: 8c63f5fc lw r3,-0x0a04(r3)        ^
00186978: 00001012 mflo r2                  r2 = XA * 1..Y
0018697c: 14600017 bne r3,r0,0x 001869dc    v HP damage = XA * 1..Y
00186980: a4820004 sh r2,0x0004(r4)         ^ if not just predicting:   //try knockback
00186984: 0c063ba8 jal 0x 0018eea0              r2 = 0..7FFFh
00186988: 00000000 nop                         
0018698c: 3c038019 lui r3,0x8019                r3 = attacker data pointer
00186990: 8c632d94 lw r3,0x2d94(r3)             ^
00186994: 00000000 nop                          
00186998: 90630024 lbu r3,0x0024(r3)            r3 = attacker.Brave
0018699c: 00000000 nop                      
001869a0: 00430018 mult r2,r3                   r5 = atkr.Br * 0..7FFFh = 0..(atkr.Br-1)
001869a4: 00002812 mflo r5                      ^
001869a8: 04a10002 bgez r5,0x 001869b4          if r5 < 0:      //force positive
001869ac: 00000000 nop                      
001869b0: 24a57fff addiu r5,r5,0x7fff               r5 += 7FFFh
001869b4: 3c028019 lui r2,0x8019                r2 = target data pointer
001869b8: 8c422d98 lw r2,0x2d98(r2)             ^
001869bc: 00000000 nop                      
001869c0: 90440024 lbu r4,0x0024(r2)            r4 = target.Brave
001869c4: 0c017833 jal 0x0005e0cc               if roll_success(
001869c8: 00052bc3 sra r5,r5,0x0f                   chance := 0..(atkr.Br-1) / target.Br
001869cc: 14400003 bne r2,r0,0x 001869dc            // Yes, two rolls are involved.
001869d0: 00000000 nop                          ):
001869d4: 0c0610fb jal 0x 001843ec              Knockback Calculation
001869d8: 00000000 nop                          
001869dc: 8fbf0010 lw r31,0x0010(r29)       return
001869e0: 27bd0018 addiu r29,r29,0x 0018    ^
001869e4: 03e00008 jr r31                   ^
001869e8: 00000000 nop

Return location

Battle.bin
00189fbc: 37_Dmg_(Rdm(1…Y)*PA)