Check for good units to target (based on distance,status,coordinate)
(Redirected from 0019971c - 001998c4)
Jump to navigation
Jump to search
BATTLE.BIN - Check for good units to target (based on distance,status,coordinate) Should probably be : Set Enemies proximity score ------------------------------------------------------------------------------------------------------------------------------------- Parameters : Nothing Returns : r2 = 0x00 if 0x19b7 = 0x00 and Unit has moved / can't move r2 = 0x00 if Unit Can move but has berserk or confuse r2 = -0x01 if 0001dba8 returns r2 > 0x1b8 (?) First fill targetable ennemies list ( 0x8019f3c4 + 0xc8d ) Then fill Table 0x0174 with some proximity score for each Tile of the map. the higher the score, the more ennemies surround the tile. ------------------------------------------------------------------------------------------------- 0019971c: 27bdffc8 addiu r29,r29,-0x0038 | 00199720: afb20028 sw r18,0x0028(r29) | 00199724: 3c12801a lui r18,0x801a | 00199728: 2652f3c4 addiu r18,r18,-0x0c3c |AI data pointer ( 8019f3c4 ) 0019972c: afb00020 sw r16,0x0020(r29) | 00199730: 00008021 addu r16,r0,r0 |Initialize loop counter 00199734: afb3002c sw r19,0x002c(r29) | 00199738: 34130001 ori r19,r0,0x0001 |Prepare flag value 0019973c: afbf0030 sw r31,0x0030(r29) | 00199740: afb10024 sw r17,0x0024(r29) | 00199744: 02508821 addu r17,r18,r16 |AI data pointer + Unit offset @LOOP - though all units 00199748: a2200c8d sb r0,0x0c8d(r17) |Initialize Unit flag in targetable list 0019974c: 0c065b23 jal 0x00196c8c |-->Check target type Returns r2 = 0x00 if This iteration unit is targetable 00199750: 02002021 addu r4,r16,r0 |This iteration Unit ID 00199754: 14400006 bne r2,r0,0x00199770 #If This unit is targetable / Else branch to Next Unit 00199758: 00000000 nop | 0019975c: 0c066632 jal 0x001998c8 |-->AI Check Options - Stop/Don't Act/Sleep/Chicken/Charm Returns 0x00 if enemy Unit could suffer any of these (= is worth to be considered) 00199760: 02002021 addu r4,r16,r0 | 00199764: 14400002 bne r2,r0,0x00199770 #If Unit is an ennemy worth to be considered / Else branch to Next Unit 00199768: 00000000 nop | 0019976c: a2330c8d sb r19,0x0c8d(r17) |Unit Targetable = True 00199770: 26100001 addiu r16,r16,0x0001 |Unit counter + 1 00199774: 2a020015 slti r2,r16,0x0015 |Check limit 00199778: 1440fff3 bne r2,r0,0x00199748 Λ Loop 0x15 Times 0019977c: 02508821 addu r17,r18,r16 |Ai data offset (+1 each iteration) 00199780: 00007021 addu r14,r0,r0 |Initialize elevation loop counter 00199784: 3c118019 lui r17,0x8019 | 00199788: 263108cc addiu r17,r17,0x08cc |Start of Battle stats data pointer 0019978c: 340f000a ori r15,r0,0x000a |r15 = 10 (used to set the proximity score) 00199790: 02406821 addu r13,r18,r0 |AI data pointer ( 8019f3c4 ) 00199794: 02406021 addu r12,r18,r0 |AI data pointer ( 8019f3c4 ) 00199798: 92420e3b lbu r2,0x0e3b(r18) |Load map max Y 0019979c: 00000000 nop | 001997a0: 1840003c blez r2,0x00199894 #If Map max Y is invalid : Branch to next iteration 001997a4: 00004021 addu r8,r0,r0 |Initialize Y counter 001997a8: 25ab0174 addiu r11,r13,0x0174 |This elevation iteration of Tile's target proximity data Table + 0x120 for high elevation 001997ac: 258a0a74 addiu r10,r12,0x0a74 |This elevation iteration ? + 0x24 for high elevation 001997b0: 95490000 lhu r9,0x0000(r10) |Load Y coordinates Halfword (0x10 reachable tiles flags) 001997b4: 00000000 nop | 001997b8: 11200030 beq r9,r0,0x0019987c #If there is somereachable tile in this row 001997bc: 00000000 nop | 001997c0: 92420e3a lbu r2,0x0e3a(r18) |Load map max X 001997c4: 00000000 nop | 001997c8: 1840002c blez r2,0x0019987c #If Map max X is invalid : Branch to next iteration 001997cc: 00002821 addu r5,r0,r0 |Initialize X counter 001997d0: 01603021 addu r6,r11,r0 |Pointer to 8019f3c4 - 0x174 data +0x10 each Yrow iteration @LOOP - through all X tiles (in Y row) 001997d4: 00a91004 sllv r2,r9,r5 |Shift Row flag (this iteration X tile flag will be the highest in the halfword) 001997d8: 30428000 andi r2,r2,0x8000 |Bitmask on this iteration Tile's flag (is reachable by AI unit) 001997dc: 10400022 beq r2,r0,0x00199868 #If This Tile is reachable 001997e0: 00000000 nop | 001997e4: a0c00000 sb r0,0x0000(r6) |Initialize this Tile byte in 0x174 data 001997e8: 00008021 addu r16,r0,r0 |Initialize Unit counter 001997ec: 00c03821 addu r7,r6,r0 |This tile 0x174 data pointer 001997f0: 02202021 addu r4,r17,r0 |Start of Battle stats data pointer @LOOP - through all units 001997f4: 02501021 addu r2,r18,r16 |This iteration unit AI data pointer 001997f8: 90420c8d lbu r2,0x0c8d(r2) |Load this unit targetable flag (in targetable list) 001997fc: 00000000 nop | 00199800: 10400015 beq r2,r0,0x00199858 #If this unit is a Targetable foe / Worth to be considered 00199804: 00000000 nop | 00199808: 90820047 lbu r2,0x0047(r4) |Load This unit X coordinate 0019980c: 00000000 nop | 00199810: 00451823 subu r3,r2,r5 |Delta X (This Unit - This Tile X) 00199814: 04610002 bgez r3,0x00199820 #If Delta X < 0x00 00199818: 00000000 nop | 0019981c: 00031823 subu r3,r0,r3 |Make delta X positive 00199820: 90820048 lbu r2,0x0048(r4) |Load This unit Y coordinates 00199824: 00000000 nop | 00199828: 00481023 subu r2,r2,r8 |Delta Y (This Unit - This Tile Y) 0019982c: 04410002 bgez r2,0x00199838 #If Delta Y < 0x00 00199830: 00000000 nop | 00199834: 00021023 subu r2,r0,r2 |Make delta Y positive 00199838: 00621821 addu r3,r3,r2 |Distance Between This Unit and This Tile 0019983c: 2862000b slti r2,r3,0x000b | 00199840: 10400005 beq r2,r0,0x00199858 #If Unit Distance from Tile is less than 11 00199844: 01e31823 subu r3,r15,r3 |10 - Distance (5 Panels away) 00199848: 90e20000 lbu r2,0x0000(r7) |Load this Tile Proximity data 0019984c: 00000000 nop | 00199850: 00431021 addu r2,r2,r3 |Add Amounts 00199854: a0e20000 sb r2,0x0000(r7) |Update This tile data : Higher amount = Higher nb of target near the tile 00199858: 26100001 addiu r16,r16,0x0001 |Unit counter + 1 0019985c: 2a020015 slti r2,r16,0x0015 |Check Limit 00199860: 1440ffe4 bne r2,r0,0x001997f4 Λ Loop through all units 00199864: 248401c0 addiu r4,r4,0x01c0 |Unit Battle data offset 00199868: 92420e3a lbu r2,0x0e3a(r18) |Load map max X 0019986c: 24a50001 addiu r5,r5,0x0001 |X counter +1 00199870: 00a2102a slt r2,r5,r2 |Check limit 00199874: 1440ffd7 bne r2,r0,0x001997d4 Λ Loop while not at max X 00199878: 24c60001 addiu r6,r6,0x0001 |X Offset in AI Tile's 0x174 Table (+1 each iteration) 0019987c: 256b0010 addiu r11,r11,0x0010 |Row Offset in AI Tile's 0x174 Table (+0x10 each Y iteration) 00199880: 92420e3b lbu r2,0x0e3b(r18) |Load map max Y 00199884: 25080001 addiu r8,r8,0x0001 |Y counter + 1 00199888: 0102102a slt r2,r8,r2 |Check Y Limit 0019988c: 1440ffc8 bne r2,r0,0x001997b0 Λ Loop while not at max Y 00199890: 254a0002 addiu r10,r10,0x0002 |Offset in AI Tile's 0xa74 Table + 0x02 each iteration (Half word) 00199894: 25ad0120 addiu r13,r13,0x0120 |r13 = ? Offset + 0x120 Each iteration 00199898: 25ce0001 addiu r14,r14,0x0001 |Elevation counter + 1 0019989c: 29c20002 slti r2,r14,0x0002 |Check limit 001998a0: 1440ffbd bne r2,r0,0x00199798 Λ Loop 0x2 Times (Elevation 0 and 1) 001998a4: 258c0024 addiu r12,r12,0x0024 |r12 = ? Offset + 0x24 each iteration 001998a8: 8fbf0030 lw r31,0x0030(r29) END 001998ac: 8fb3002c lw r19,0x002c(r29) 001998b0: 8fb20028 lw r18,0x0028(r29) 001998b4: 8fb10024 lw r17,0x0024(r29) 001998b8: 8fb00020 lw r16,0x0020(r29) 001998bc: 27bd0038 addiu r29,r29,0x0038 001998c0: 03e00008 jr r31 001998c4: 00000000 nop
Return location
BATTLE.BIN 00195e44: 00195d94_-_00195f68