Magic Gun Ability Decision

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
No Parameters - Returns Nothing

Uses The Gun Element to determine which spell type will be cast.
Only one element is taken into account. The others will be ignored : First Fire, then Thunder, finally Ice.   
(Note that Ice is default, everything not fire/thunder will end to cast an ice spell)

The tier of the cast spell is randomly chosen :
  - 10% of chances to cast tier 3
  - 30% of chances to cast tier 2
  - 60% of chances to cast tier 1

Magic gun ability ID is hardcoded. 
Magic gun ability data will be stored in current ability section (0x801938f0 to 0x801938fd) 
------------------------------------------------------------------------------------------------------
00187730: 27bdffe8 addiu r29,r29,-0x0018    |
00187734: afb00010 sw r16,0x0010(r29)       |
00187738: 3c108019 lui r16,0x8019           |
0018773c: 92103904 lbu r16,0x3904(r16)      |r16 = Current Ability Weapon's Element   0x80193904 / 80193904
00187740: afbf0014 sw r31,0x0014(r29)       |
00187744: 0c063ba8 jal 0x0018eea0           |-->Random Process  Returns r2 between 0x00 and 0x7fff
00187748: 00000000 nop                      |
0018774c: 00021840 sll r3,r2,0x01           |Random * 2
00187750: 00621821 addu r3,r3,r2            |Random * 3
00187754: 000318c0 sll r3,r3,0x03           |Random * 24
00187758: 00621821 addu r3,r3,r2            |Random * 25
0018775c: 00031880 sll r3,r3,0x02           |Random * 100
00187760: 04610002 bgez r3,0x0018776c       #If Random < 0x00
00187764: 32020080 andi r2,r16,0x0080       |r2 <> 0x00 if Weapon Element is Fire
00187768: 24637fff addiu r3,r3,0x7fff           |Make random positive
0018776c: 1040000b beq r2,r0,0x0018779c     #If Weapon Element has Fire
00187770: 00031bc2 srl r3,r3,0x0f               |r3 = Random between 0 and 99  (100 x Random / [Max possible random + 1])
00187774: 306400ff andi r4,r3,0x00ff            |r4 = Random number in a byte (useless if everything is ok)
00187778: 2c82000a sltiu r2,r4,0x000a           |r2 = 0x01 if Random < 10
0018777c: 10400003 beq r2,r0,0x0018778c         #If Random < 10
00187780: 2c820028 sltiu r2,r4,0x0028           |r2 = 0x01 if Random < 40
00187784: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Fire 3)
00187788: 34030012 ori r3,r0,0x0012                 |r3 = 0x12 (Fire 3)
0018778c: 10400017 beq r2,r0,0x001877ec         #If Random < 40 /Else Branch to Store Ability data with Fire
00187790: 34030010 ori r3,r0,0x0010             |r3 = 0x10 (Fire)
00187794: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Fire 2)
00187798: 34030011 ori r3,r0,0x0011                 |r3 = 0x11 (Fire 2)
0018779c: 32020040 andi r2,r16,0x0040       |r2 <> 0x00 if Weapon Element is Lightning
001877a0: 1040000a beq r2,r0,0x001877cc     #If Weapon Element has Lightning
001877a4: 306400ff andi r4,r3,0x00ff            |r4 = Random number in a byte (useless if everything is ok)
001877a8: 2c82000a sltiu r2,r4,0x000a           |r2 = 0x01 if Random < 10
001877ac: 10400003 beq r2,r0,0x001877bc         #If Random < 10
001877b0: 2c820028 sltiu r2,r4,0x0028           |r2 = 0x01 if Random < 40
001877b4: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Bolt 3)
001877b8: 34030016 ori r3,r0,0x0016                 |r3 = 0x16 (Bolt 3)
001877bc: 1040000b beq r2,r0,0x001877ec         #If Random < 40 /Else Branch to Store Ability data with Bolt
001877c0: 34030014 ori r3,r0,0x0014             |r3 = 14 (Bolt)
001877c4: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Bolt 2)
001877c8: 34030015 ori r3,r0,0x0015                 |r3 = 0x15 (Bolt 2)
                                            #If Weapon Element is Ice  (In fact it could be every other element - or even no elements)
001877cc: 2c82000a sltiu r2,r4,0x000a           |r2 = 0x01 if Random < 10
001877d0: 10400003 beq r2,r0,0x001877e0         #If Random < 10
001877d4: 2c820028 sltiu r2,r4,0x0028           |r2 = 0x01 if Random < 40
001877d8: 08061dfb j 0x001877ec                     >>jump to Store Ability data (Bolt 3)
001877dc: 3403001a ori r3,r0,0x001a                 |r3 = 0x1a (Ice 3)
001877e0: 10400002 beq r2,r0,0x001877ec         #If Random < 40 /Else Branch to Store Ability data with Ice
001877e4: 34030018 ori r3,r0,0x0018             |r3 = 18 (Ice)
001877e8: 34030019 ori r3,r0,0x0019                 |r3 = 19 (Ice 2)

--- Store Magic gun Ability data section ---
001877ec: 3c058019 lui r5,0x8019                    
001877f0: 24a538d6 addiu r5,r5,0x38d6       |r5 = Current Ability used ability ID pointer  0x801938d6 / 801938d6
001877f4: 000320c0 sll r4,r3,0x03           |Magic Gun Ability ID * 8
001877f8: 00832023 subu r4,r4,r3            |Magic Gun Ability ID * 7
001877fc: 00042040 sll r4,r4,0x01           |r4 = Magic Gun Ability ID * 14
00187800: a4a30000 sh r3,0x0000(r5)         |Store Magic Gun Ability ID as Current Ability Used Ability ID
00187804: 24a5001a addiu r5,r5,0x001a       |r5 = Current Ability : Start of Ability data pointer  0x801938f0 / 801938f0
00187808: 3c028019 lui r2,0x8019            |
0018780c: 8c422d94 lw r2,0x2d94(r2)         |r2 =  Attacker's Data Pointer
00187810: 3406000e ori r6,r0,0x000e         |r6 = 0x0e
00187814: a4430170 sh r3,0x0170(r2)         |Store Last Attack? = Ability ID
00187818: 3c028006 lui r2,0x8006            |
0018781c: 2442fbf0 addiu r2,r2,-0x0410      |r2 = 0x8005fbf0 (Start of Ability Data 2 Table)
00187820: 0c017895 jal 0x0005e254           |-->Store_X_Byte_into_Y  Store Magic Gun Ability Data (Range to MP cost) in Current Ability data (0x801938f0 to 0x801938fd)
00187824: 00822021 addu r4,r4,r2            |r4 = Magic Gun Ability Data Pointer
00187828: 8fbf0014 lw r31,0x0014(r29)       
0018782c: 8fb00010 lw r16,0x0010(r29)       
00187830: 27bd0018 addiu r29,r29,0x0018     
00187834: 03e00008 jr r31                   
00187838: 00000000 nop                      

Hard coded mechanics

Ability ID of Fire 1/2/3 Ice 1/2/3 Lightning 1/2/3 are hardcoded here.
Setting another spell in place of one of those ones will make it cast by the magic gun (provided that there's no further checks)

Return Locations

Battle.bin
00188c34: 04 Magic Gun