Select Random Tile For Random Fire Abilities

From Final Fantasy Hacktics Wiki
(Redirected from 0017d708 - 0017d84c)
Jump to navigation Jump to search
0017d708 - 0017d84c

This routine select a random tile among Tiles which have their "green panel" flag at byte [0x05] 
Rq : the 1st loop is a bit odd, using the targetable panels 0x01 byte to host Tile ID value (not matching the panel ID)
-------------------------------------------------------------------------------------------------------------------------------
0017d708: 27bdffe0 addiu r29,r29,-0x0020    |
0017d70c: afb00010 sw r16,0x0010(r29)       |
0017d710: 00008021 addu r16,r0,r0           |r16 = 0x00 green panel counter
0017d714: 00002821 addu r5,r0,r0            |r5 = 0x00
0017d718: 34090100 ori r9,r0,0x0100         |r9 = 0x100
0017d71c: 3c088019 lui r8,0x8019            |r8 = 0x80190000
0017d720: 25082dd8 addiu r8,r8,0x2dd8       |r8 = Targetable grid data pointer  0x80192dd8
0017d724: 3c068019 lui r6,0x8019            |r6 = 0x8019
0017d728: 24c6f8cc addiu r6,r6,-0x0734      |r6 = Tile data pointer  0x8018f8cc
0017d72c: 00003821 addu r7,r0,r0            |r7 = 0x00 (Targetable panel data counter)
0017d730: afbf0018 sw r31,0x0018(r29)       |
0017d734: afb10014 sw r17,0x0014(r29)       |
0017d738: 14a90002 bne r5,r9,0x0017d744     @ LOOP #If This iteration Tile is 0x100 Loop though all tiles
0017d73c: 00000000 nop                               | 
0017d740: 02008821 addu r17,r16,r0                   |r17 = green panel counter, low elevation tiles only
0017d744: 90c40005 lbu r4,0x0005(r6)             |r4 = This iteration Tile [0x05]
0017d748: 00000000 nop                           |
0017d74c: 30820080 andi r2,r4,0x0080             |r2 = 0x80 if this Tile has "green panel" flag ON
0017d750: 10400006 beq r2,r0,0x0017d76c          #If This Tile has green panel
0017d754: 00e81821 addu r3,r7,r8                 |r3 = Targetable panel data pointer
0017d758: 24e70005 addiu r7,r7,0x0005                |r7 = Targetable panel counter + 0x05 (size of panel data) not every iteration panel and tile do not match !! It's using panels 0x01 as a stack pointer
0017d75c: 26100001 addiu r16,r16,0x0001              |r16 = green panel counter + 1
0017d760: 3082007f andi r2,r4,0x007f                 |r2 = r4 without "green panel" flag
0017d764: a0c20005 sb r2,0x0005(r6)                  |Update this Tile [0x05] without "green panel" flag
0017d768: a0650001 sb r5,0x0001(r3)                  |Store loop counter (TIle ID) on Panel [0x01] byte 
0017d76c: 24a50001 addiu r5,r5,0x0001            |r5 = loop counter + 1
0017d770: 28a20200 slti r2,r5,0x0200             |r2 = 0x01 if counter < 0x200
0017d774: 1440fff0 bne r2,r0,0x0017d738     Λ loop while counter < 0x200
0017d778: 24c60008 addiu r6,r6,0x0008            |r6 = Tile data pointer + 0x08
0017d77c: 0c0088c3 jal 0x0002230c           |-->Random_Number_Generator return r2 = random halfword (0 to 0x7fff)
0017d780: 00000000 nop                      |
0017d784: 00500018 mult r2,r16              |Random * green panel counter
0017d788: 00001812 mflo r3                  |r3 = Random * green panel counter
0017d78c: 04610002 bgez r3,0x0017d798       #If r3 < 0x00 (random number was < 0x00) never true
0017d790: 00000000 nop                      |
0017d794: 24637fff addiu r3,r3,0x7fff            |r3 = random positive (security ?)
0017d798: 00031bc3 sra r3,r3,0x0f           |r3 =  random from 0x00 to green panel counter = random panel 
0017d79c: 00031080 sll r2,r3,0x02           |r2 = random panel * 4
0017d7a0: 00431021 addu r2,r2,r3            |r2 = random panel * 5 (panel offset)
0017d7a4: 3c018019 lui r1,0x8019            |r1 = 0x80190000
0017d7a8: 00220821 addu r1,r1,r2            |r1 = 0x80190000 + random panel offset
0017d7ac: 90242dd9 lbu r4,0x2dd9(r1)        |r4 = Random panel [0x01] byte (hold loop counter value which is tile ID)  0x80192dd8 + 0x01
0017d7b0: 0071182a slt r3,r3,r17            |r3 = 0x01 if random panel is low elevation
0017d7b4: 14600003 bne r3,r0,0x0017d7c4     #If random panel is on high elevation
0017d7b8: 000410c0 sll r2,r4,0x03           |r2 = Random Tile ID * 8
0017d7bc: 24840100 addiu r4,r4,0x0100            |r4 = Random Tile ID + higher elevation offset
0017d7c0: 000410c0 sll r2,r4,0x03                |r2 = Random Higher Tile ID * 8
0017d7c4: 3c018019 lui r1,0x8019            |r1 = 0x80190000
0017d7c8: 00220821 addu r1,r1,r2            |r1 = 0x80190000 + Random tile offset
0017d7cc: 9023f8d1 lbu r3,-0x072f(r1)       |r3 = Random Tile byte  [0x05] value 0x8018f8cc + 0x05
0017d7d0: 00000000 nop                      |
0017d7d4: 34630080 ori r3,r3,0x0080         |r3 = Random Tile [0x05] + green panel flag
0017d7d8: 3c018019 lui r1,0x8019            |r1 = 0x80190000
0017d7dc: 00220821 addu r1,r1,r2            |r1 = 0x80190000 + Random tile offset
0017d7e0: a023f8d1 sb r3,-0x072f(r1)        |Store random tile [0x05] byte updated with green panel flag (0x80)
0017d7e4: 34020001 ori r2,r0,0x0001         |r2 = 0x01
0017d7e8: 3c018019 lui r1,0x8019            |r1 = 0x80190000
0017d7ec: a022390f sb r2,0x390f(r1)         |Store 0x01 at 0x8019390f  8019390f
0017d7f0: 04810002 bgez r4,0x0017d7fc       #If random Tile ID  <0x00 ???
0017d7f4: 00802821 addu r5,r4,r0            |r5 = random tile ID
0017d7f8: 248500ff addiu r5,r4,0x00ff            |r5 = random tile ID + 0x00ff
0017d7fc: 3c03800e lui r3,0x800e            |r3 = 0x800e
0017d800: 90634e9c lbu r3,0x4e9c(r3)        |r3 = Map Max X
0017d804: 308200ff andi r2,r4,0x00ff        |r2 = low elevation Tile ID
0017d808: 0043001a div r2,r3                |low elevation ID / map Max X
0017d80c: 00001012 mflo r2                  |r2 = Random Tile Y coord
0017d810: 00002010 mfhi r4                  |r4 = Random Tile X coord (division reminder - Tile ID is X + Y*MaxX)
0017d814: 00051a03 sra r3,r5,0x08           |r3 = Random Tile / 0x100 = 0x01 if Random Tile is high elevation (ID >= 0x100)
0017d818: 3c018019 lui r1,0x8019            |
0017d81c: a02338cc sb r3,0x38cc(r1)         |Store Random Tile elevation to Target New elevation (0x801938cc)  801938cc 
0017d820: 3c018019 lui r1,0x8019            |
0017d824: a02238cb sb r2,0x38cb(r1)         |Store Random Tile Y  to Target New Y (0x801938cb)  801938cb 
0017d828: 3c018019 lui r1,0x8019            |
0017d82c: a02438ca sb r4,0x38ca(r1)         |Store Random Tile X to Target New X (0x801938ca)  801938ca 
0017d830: 0c05e500 jal 0x00179400           |-->Null_some_Tile_Data_(192dd9) Nullify all targetable panels 0x01 byte
0017d834: 00000000 nop                      
0017d838: 8fbf0018 lw r31,0x0018(r29)       
0017d83c: 8fb10014 lw r17,0x0014(r29)       
0017d840: 8fb00010 lw r16,0x0010(r29)       
0017d844: 27bd0020 addiu r29,r29,0x0020     
0017d848: 03e00008 jr r31                   
0017d84c: 00000000 nop

Returns location

Battle.bin
 0017ce28: Map_calculations_for_attack