Randomly Transfer Data

From Final Fantasy Hacktics Wiki
Revision as of 20:02, 22 June 2024 by Orkney (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
BATTLE.BIN :  - Randomly_Transfer_Data
Test Saved Action Outcomes. Begin by better score, simulate Hit% and store the first action that do not miss at AI 0x17fc
------------------------------------------------------------------------------------------
Parameter : Nothing
Return : r2 = 0x01 if an action has been selected
         r2 = 0x00 if No Action passed the test
------------------------------------------------------------------------------------------
001970bc: 27bdffd0 addiu r29,r29,-0x0030     |
001970c0: afb3001c sw r19,0x001c(r29)        |
001970c4: 00009821 addu r19,r0,r0            |Initialize Valid action flag
001970c8: afb00010 sw r16,0x0010(r29)        |
001970cc: 00008021 addu r16,r0,r0            |Initialize Action counter
001970d0: afb60028 sw r22,0x0028(r29)        |
001970d4: 3c1651eb lui r22,0x51eb            |
001970d8: 36d6851f ori r22,r22,0x851f        |0,32*2^32
001970dc: afb40020 sw r20,0x0020(r29)        |
001970e0: 3c14801a lui r20,0x801a            |
001970e4: 2694f3c4 addiu r20,r20,-0x0c3c     |0x8019f3c4
001970e8: afb20018 sw r18,0x0018(r29)        |
001970ec: 02809021 addu r18,r20,r0           |0x8019f3c4 - Used as pointer to Saved Action data (AI 0x54 -> AI 0x154)
001970f0: afbf002c sw r31,0x002c(r29)        |
001970f4: afb50024 sw r21,0x0024(r29)        |
001970f8: afb10014 sw r17,0x0014(r29)        |

=== TEST all stored action hit% - Transfer the first that succeed ===
                                            @LOOP - Test Action average Hit% vs Rdm
001970fc: 92510071 lbu r17,0x0071(r18)           |This Action Average Hit %
00197100: 00000000 nop                           |
00197104: 12200002 beq r17,r0,0x00197110         #If Average Hit% > 0
00197108: 0010a940 sll r21,r16,0x05              |Counter * 0x20
0019710c: 34130001 ori r19,r0,0x0001                 |Enable valid action flag
00197110: 0c0088c3 jal 0x0002230c                |-->Random_Number_Generator return rdm {0…0x7fff}
00197114: 00000000 nop                           |
00197118: 00560018 mult r2,r22                   |Rdm * 0,32 * 2^32
0019711c: 00021fc3 sra r3,r2,0x1f                |
00197120: 00002010 mfhi r4                       |Rdm * 0,32
00197124: 00042143 sra r4,r4,0x05                |Rdm/100
00197128: 00832023 subu r4,r4,r3                 |
0019712c: 00041840 sll r3,r4,0x01                |2*Rdm%
00197130: 00641821 addu r3,r3,r4                 |3*Rdm%
00197134: 000318c0 sll r3,r3,0x03                |24*Rdm%
00197138: 00641821 addu r3,r3,r4                 |25*Rdm%
0019713c: 00031880 sll r3,r3,0x02                |100*Rdm%
00197140: 00431023 subu r2,r2,r3                 |Rdm{0…99             Since Rdm/100 do not have decimals
00197144: 0051102a slt r2,r2,r17                 |0x1 if Rdm < Average Hit%
00197148: 14400008 bne r2,r0,0x0019716c          #If Rdm < Hit% Select this action
0019714c: 26100001 addiu r16,r16,0x0001          |Action counter +1
00197150: 2a020008 slti r2,r16,0x0008            |
00197154: 1440ffe9 bne r2,r0,0x001970fc      #loop 8 times or RNG breaks out
00197158: 26520020 addiu r18,r18,0x0020          |AI Action Outcome offset (+0x20 each iteration)

=== No valid action in list  ===
0019715c: 1260000a beq r19,r0,0x00197188     #If there was no action with hit > 0% Exit Return 0x00

=== There is some valid action but they all failed the test : Force AI 0x54 ===
00197160: 268417fc addiu r4,r20,0x17fc       |Destination pointer 
00197164: 08065c5e j 0x00197178              >>If there was an Action with Hit > 0% but all rdm test fails Tranfer best score data
00197168: 26850054 addiu r5,r20,0x0054       |Force origin pointer to best-scoring action (AI 0x54)

=== Select the first action to pass the test ===
0019716c: 268417fc addiu r4,r20,0x17fc       |Destination pointer
00197170: 26a50054 addiu r5,r21,0x0054       |Action counter offset (0x20) + 0x54 (start of action data)
00197174: 02852821 addu r5,r20,r5            |Pointer to 0x8019f3c4 + 0x54 + selected action offset

=== Transfer data to AI 0x17fc ===
00197178: 0c066ac2 jal 0x0019ab08            |-->Transfer_Halfword_Values Transfer selected action data to AI 0x17fc
0019717c: 34060020 ori r6,r0,0x0020          |Transfer 0x20 bytes
00197180: 08065c63 j 0x0019718c              |Exit  return 0x01
00197184: 34020001 ori r2,r0,0x0001          |
00197188: 00001021 addu r2,r0,r0
0019718c: 8fbf002c lw r31,0x002c(r29)
00197190: 8fb60028 lw r22,0x0028(r29)
00197194: 8fb50024 lw r21,0x0024(r29)
00197198: 8fb40020 lw r20,0x0020(r29)
0019719c: 8fb3001c lw r19,0x001c(r29)
001971a0: 8fb20018 lw r18,0x0018(r29)
001971a4: 8fb10014 lw r17,0x0014(r29)
001971a8: 8fb00010 lw r16,0x0010(r29)
001971ac: 27bd0030 addiu r29,r29,0x0030
001971b0: 03e00008 jr r31
001971b4: 00000000 nop

Return locations

BATTLE.BIN
 00196278: Non-Specific_AI_AutoBattle_(Enemies)
 0019825c: Fight_for_Life_-_Auto_Battle_(00197ff4)
 001982a8: Fight_for_Life_-_Auto_Battle_(00197ff4)
 00198764: Protect_Allies_-_Auto_Battle_(001984ec)
 001987a4: Protect_Allies_-_Auto_Battle_(001984ec)
 001987dc: Protect_Allies_-_Auto_Battle_(001984ec)
 00198f3c: AI_Critical_or_Run_Like_Rabbit
 00199024: AI_Critical_or_Run_Like_Rabbit