Set and Validate Arc Trajectory

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
001aff18 - 001b045c Summary

Parameters : r4 = Attacker ID
             r5 = Pointer to Attacker data 0x17a
             r6 = Target ID  (-0x01 if no target - tile not targetable)

Returns : r2 = Target ID (might be updated if unit is in the arrow way) 
          r2 = -0x01 if Map obstacle is in the way
---------------------------------------------------------------------------------------------------
001aff18: 27bdff30 addiu r29,r29,-0x00d0    |
001aff1c: afb500bc sw r21,0x00bc(r29)       |
001aff20: 0080a821 addu r21,r4,r0           |r21 = Attacker ID
001aff24: afb000a8 sw r16,0x00a8(r29)       |
001aff28: 00a08021 addu r16,r5,r0           |r16 =  Pointer - Attacker data 0x17a
001aff2c: afb400b8 sw r20,0x00b8(r29)       |
001aff30: 00c0a021 addu r20,r6,r0           |r20 = Target ID (-0x01 if no target - tile not targetable)
001aff34: afbf00cc sw r31,0x00cc(r29)       |
001aff38: afbe00c8 sw r30,0x00c8(r29)       |
001aff3c: afb700c4 sw r23,0x00c4(r29)       |
001aff40: afb600c0 sw r22,0x00c0(r29)       |
001aff44: afb300b4 sw r19,0x00b4(r29)       |
001aff48: afb200b0 sw r18,0x00b0(r29)       |
001aff4c: afb100ac sw r17,0x00ac(r29)       |
001aff50: 3c01801c lui r1,0x801c            |
001aff54: ac358b60 sw r21,-0x74a0(r1)       |Store Attacker ID at 0x801b8b60
001aff58: afb50078 sw r21,0x0078(r29)       |Store Attacker ID on stack 0x78
001aff5c: 0c023727 jal 0x0008dc9c           |-->Find_Unit%27s_Misc_Data_Pointer_and_Load_Spritesheet_Value  returns r2 = Attacker spritesheet graphic height (or 0x00 if invalid, dead, crystal or treasure)
001aff60: afb40088 sw r20,0x0088(r29)       |Store Target ID on stack 0x88
001aff64: 3c035555 lui r3,0x5555            |
001aff68: 34635556 ori r3,r3,0x5556         |r3 = 0x55555556 (= 0,33 * 2^32)
001aff6c: 00021040 sll r2,r2,0x01           |r2 = Attacker graphic height * 2
001aff70: 00430018 mult r2,r3               |
001aff74: 000217c3 sra r2,r2,0x1f           |r2 = Attacker graphic height first bit (0x00 or 0x01 - for rounding stuff)
001aff78: 00001810 mfhi r3                  |r3 = Attacker graphic height * 2/3
001aff7c: 00621823 subu r3,r3,r2            |r3 = Attacker graphic height * 2/3 ( - 1 or - 0)
001aff80: 2402ffff addiu r2,r0,-0x0001      |r2 = -0x01
001aff84: 12820005 beq r20,r2,0x001aff9c    #If Target Exist (ID <> -0x01) / Else branch to target graphic height nullification
001aff88: afa3007c sw r3,0x007c(r29)        |Store Value Attacker graphic height * 2/3 on stack 0x7c
001aff8c: 0c023727 jal 0x0008dc9c                |-->Find_Unit%27s_Misc_Data_Pointer_and_Load_Spritesheet_Value
001aff90: 02802021 addu r4,r20,r0                |r4 = Target ID
001aff94: 0806bfe8 j 0x001affa0                  >>Jump 3 lines below (avoid target height nullification) 
001aff98: afa2008c sw r2,0x008c(r29)             |Store Target graphic height on stack 0x8c
001aff9c: afa0008c sw r0,0x008c(r29)        #Else (Target doesn't exists) Store Target graphic height = 0x00 (stack 0x8c)
001affa0: 02a02021 addu r4,r21,r0           |r4 = Attacker ID
001affa4: 2405ffff addiu r5,r0,-0x0001      |r5 = -0x01
001affa8: 0c06bddc jal 0x001af770           |-->List_targeting_data_of_all_valid_units Store Xmod Ymod and height data of all valid units Store something at r29 0x2c of 1afb38 ?
001affac: 27a60090 addiu r6,r29,0x0090      |r6 = Stack Pointer + 0x90
001affb0: 3c05801c lui r5,0x801c            |r5 = 0x801c0000
001affb4: 24a5925c addiu r5,r5,-0x6da4      |r5 = 0x801b925c
001affb8: 0c02311a jal 0x0008c468           |-->Set_Unit_Xmod,_Y_Mod_and_Height_data_from_unit_ID Store Attacker Xmod, Ymod and height data at r5 (0x00 0x04 and 0x02)
001affbc: 02a02021 addu r4,r21,r0           |r4 = Attacker ID
001affc0: 3c02801c lui r2,0x801c            |r2 = 0x801c0000
001affc4: 9442925e lhu r2,-0x6da2(r2)       |r2 = Attacker height data (negative value) 0x801c0000 - 0x6da2 = 0x801b925e = 0x801b925c + 0x02
001affc8: 97a3007c lhu r3,0x007c(r29)       |r3 = Attacker spritesheet height
001affcc: 00000000 nop                      |
001affd0: 00431023 subu r2,r2,r3            |r2 = -(Attacker height data + spritesheet height)
001affd4: 3c01801c lui r1,0x801c            |r1 = 0x801c0000
001affd8: a422925e sh r2,-0x6da2(r1)        |Store Updated height data at 0x801b925e  0x801b925c + 0x02
001affdc: 2402ffff addiu r2,r0,0xffff       |r2 = -0x01
001affe0: 16820022 bne r20,r2,0x001b006c    #If Target Exist (ID <> -0x01)
001affe4: 00000000 nop                           | 
001affe8: 86040000 lh r4,0x0000(r16)             |r4 = Target X coord   (Attacker data 0x17a)
001affec: 86050004 lh r5,0x0004(r16)             |r5 = Target Y coord   (Attacker data 0x17e)
001afff0: 86060002 lh r6,0x0002(r16)             |r6 = Target Elevation   (Attacker data 0x17c)
001afff4: 0c060fed jal 0x00183fb4                |-->Get_Tile_Data_Pointer  Returns r2 = Tile data pointer (0x00 if not valid)
001afff8: 00000000 nop                           |
001afffc: 86040000 lh r4,0x0000(r16)             |r4 = Target X coord   (Attacker data 0x17a)
001b0000: 00000000 nop                           |
001b0004: 000418c0 sll r3,r4,0x03                |r3 = Target X coord * 8
001b0008: 00641823 subu r3,r3,r4                 |r3 = Target X coord * 7
001b000c: 00031880 sll r3,r3,0x02                |r3 = Target X coord * 28
001b0010: 2463000e addiu r3,r3,0x000e            |r3 = Target X coord * 28 + 14 (= Target X mod)
001b0014: 3c01801c lui r1,0x801c                 |r1 = 0x801c0000
001b0018: a4239264 sh r3,-0x6d9c(r1)             |Store Target X mod at 0x801b9264
001b001c: 86040004 lh r4,0x0004(r16)             |r5 = Target Y coord   (Attacker data 0x17e)
001b0020: 00000000 nop                           |
001b0024: 000418c0 sll r3,r4,0x03                |r3 = Target Y coord * 8
001b0028: 00641823 subu r3,r3,r4                 |r3 = Target Y coord * 7
001b002c: 00031880 sll r3,r3,0x02                |r3 = Target Y coord * 28
001b0030: 2463000e addiu r3,r3,0x000e            |r3 = Target Y coord * 28 + 14 (= Target Y mod)
001b0034: 3c01801c lui r1,0x801c                 |r1 = 0x801c0000
001b0038: a4239268 sh r3,-0x6d98(r1)             |Store Target Y mod at 0x801b9268
001b003c: 90430003 lbu r3,0x0003(r2)             |r3 = Target tile Halves + depht
001b0040: 90440002 lbu r4,0x0002(r2)             |r4 = Target tile height
001b0044: 00031942 srl r3,r3,0x05                |r3 = Target tile Effective depht
001b0048: 00832021 addu r4,r4,r3                 |r4 = Target tile Depht + Height
001b004c: 00041040 sll r2,r4,0x01                |r2 = (Target tile deph +height) * 2
001b0050: 00441021 addu r2,r2,r4                 |r2 = (Target tile deph +height) * 3
001b0054: 00021080 sll r2,r2,0x02                |r2 = (Target tile deph +height) * 12
001b0058: 00021023 subu r2,r0,r2                 |r2 = - (Target tile deph +height) * 12
001b005c: 3c01801c lui r1,0x801c                 |r1 = 0x801c0000
001b0060: a4229266 sh r2,-0x6d9a(r1)             |Store Target Z mod at 0x801b9266 Z mod = - (Target tile deph +height) * 12
001b0064: 0806c01f j 0x001b007c                  >>Jump avoiding Inexisting target section
001b0068: 00000000 nop                           |
001b006c: 3c05801c lui r5,0x801c            |Else (Target doesn't exists) r5 = 0x801c0000
001b0070: 24a59264 addiu r5,r5,0x-6d9c           |r5 = 0x801b9264
001b0074: 0c02311a jal 0x0008c468                |-->Set_Unit_Xmod,_Y_Mod_and_Height_data_from_unit_ID  Will Eventualy store X mod Y mod and Z mod from misc unit data pointer (at r5 0x00 0x04 and 0x02)
001b0078: 02802021 addu r4,r20,r0                |r4 = Target ID (or -0x01 if no target - tile not targetable)
001b007c: 3c05801c lui r5,0x801c            |r5 = 0x801c0000
001b0080: 84a59264 lh r5,-0x6d9c(r5)        |r5 = Target X mod  from 0x801b9264
001b0084: 3c02801c lui r2,0x801c            |r2 = 0x801c0000
001b0088: 8442925c lh r2,-0x6da4(r2)        |r2 = Attacker X mod from 0x801b925c
001b008c: 00000000 nop                      |
001b0090: 00a22823 subu r5,r5,r2            |r5 = Target X mod - Attacker X mod (Delta X mod)
001b0094: 00a50018 mult r5,r5               |(Delta X mod)^2
001b0098: 3c03801c lui r3,0x801c            |r3 = 0x801c0000
001b009c: 84639268 lh r3,-0x6d98(r3)        |r3 = Target Y mod  from 0x801b9268
001b00a0: 3c02801c lui r2,0x801c            |r2 = 0x801c0000
001b00a4: 84429260 lh r2,-0x6da0(r2)        |r2 = Attacker Y mod  from 0x801b9260
001b00a8: 00002012 mflo r4                  |r4 = (Delta Xmod)^2
001b00ac: 00621823 subu r3,r3,r2            |r3 = Delta Y mod
001b00b0: 00000000 nop                      |
001b00b4: 00630018 mult r3,r3               |(Delta Y mod)^2
001b00b8: 3c06801c lui r6,0x801c            |r6 = 0x801c0000
001b00bc: 84c69266 lh r6,-0x6d9a(r6)        |r6 = Target Z mod  from 0x801b9266
001b00c0: 3c02801c lui r2,0x801c            |
001b00c4: 8442925e lh r2,-0x6da2(r2)        |r2 = Attacker Z mod from 0x801b925e
001b00c8: afa50060 sw r5,0x0060(r29)        |Store Delta X mod on stack 0x60
001b00cc: afa30068 sw r3,0x0068(r29)        |Store delta Y mod on stack 0x68
001b00d0: 00461023 subu r2,r2,r6            |r2 = delta Z mod (Height is stored as negative number, so delta Z is positive if Target is heigher than attacker)
001b00d4: afa20064 sw r2,0x0064(r29)        |Store delta Z mod on stack 0x64
001b00d8: 00001012 mflo r2                  |r2 = (Delta Y mod)^2
001b00dc: 00822021 addu r4,r4,r2            |r4 = (Delta Xmod)^2 + (Delta Y mod)^2 = (distance between attacker and target)^2 - pythagore
001b00e0: 0c00709a jal 0x0001c268           |-->Get_Square_root_of_r4_dealing_with_4096 return r2 = (Attacker-Target distance)*4096
001b00e4: 00042300 sll r4,r4,0x0c           |r4 = (distance^2)*4096     
001b00e8: 8fa50060 lw r5,0x0060(r29)        |r5 = Delta X mod
001b00ec: 8fa40068 lw r4,0x0068(r29)        |r4 = Delta Y mod
001b00f0: afa2006c sw r2,0x006c(r29)        |store (Attacker-Target distance)*4096 on stack 0x6c
001b00f4: 0c00763a jal 0x0001d8e8           |-->Get_Angle_Value_via_ArcTan_Table returns r2 = attacker to Target angle value (clockwise, East = 0°, counter clockwise is negative) in XY plan
001b00f8: 00042023 subu r4,r0,r4            |r4 = - Delta Y mod
001b00fc: 27a40060 addiu r4,r29,0x0060      |r4 = Stack 0x60
001b0100: 27b20094 addiu r18,r29,0x0094     |r18 = Stack 0x94
001b0104: 02402821 addu r5,r18,r0           |r5 = Stack 0x94
001b0108: 27b00098 addiu r16,r29,0x0098     |r16 = Stack 0x98
001b010c: 02003021 addu r6,r16,r0           |r6 = Stack 0x98
001b0110: 0c06bcf7 jal 0x001af3dc           |-->Maths_For_Arcing_Trajectory Returns Some Trajectory data at r5 and r6 . R2 = 0x00 if no data.
001b0114: a7a2002a sh r2,0x002a(r29)        |Store Attacker to Target angle value on Stack 0x2a
001b0118: 14400004 bne r2,r0,0x001b012c     #If there's nothing stored at stack 0x94 and 0x98
001b011c: 02002821 addu r5,r16,r0           |r5 = Stack 0x98
001b0120: 34021000 ori r2,r0,0x1000              |r2 = 0x1000
001b0124: afa20098 sw r2,0x0098(r29)             |Store 0x1000 at stack 0x98
001b0128: afa20094 sw r2,0x0094(r29)             |Store 0x1000 at stack 0x94
001b012c: 3c04801c lui r4,0x801c            |r4 = 0x801c0000
001b0130: 2484925c addiu r4,r4,-0x6da4      |r4 = 0x801b925c
001b0134: 27b1006c addiu r17,r29,0x006c     |r17 = stack 0x6c
001b0138: 02203021 addu r6,r17,r0           |r6 = stack 0x6c
001b013c: 27b00028 addiu r16,r29,0x0028     |r16 = stack 0x28
001b0140: 8fa20090 lw r2,0x0090(r29)        |r2 = 0x1f800000 see 001affac
001b0144: 02003821 addu r7,r16,r0           |r7 = Stack 0x28
001b0148: 0c06bece jal 0x001afb38           |-->Set_Arcing_Trajectory Set Trajectory data, return r2 = 0x00 if obstacle, 0x01 if attack reaches target
001b014c: afa20010 sw r2,0x0010(r29)        |Store 0x1f800000 on stack 0x10
001b0150: 3c1e801c lui r30,0x801c           |r30 = 0x801c0000
001b0154: 27de8b7c addiu r30,r30,-0x7484    |r30 = 0x801b8b7c  known as Attack's X Mod Difference
001b0158: 8fc30000 lw r3,0x0000(r30)        |r3 = Attacks X mod difference
001b015c: 8fc40004 lw r4,0x0004(r30)        |r4 = Attacks Z mod difference  0x801b8b80
001b0160: 8fc50008 lw r5,0x0008(r30)        |r5 = Attacks Y mod difference  0x801b8b84
001b0164: 8fc6000c lw r6,0x000c(r30)        |r6 = ??? At 0x801b8b88  0x801b8b88
001b0168: afa30040 sw r3,0x0040(r29)        |Store Attacks X mod difference on stack 0x40
001b016c: afa40044 sw r4,0x0044(r29)        |Store Attacks Z mod difference on stack 0x44
001b0170: afa50048 sw r5,0x0048(r29)        |Store Attacks Y mod difference on stack 0x48
001b0174: afa6004c sw r6,0x004c(r29)        |Store ?? mod on stack 0x4c
001b0178: 3c17801c lui r23,0x801c           |r23 = 0x801c0000
001b017c: 26f78b8c addiu r23,r23,-0x7474    |r23 = 0x801b8b8c
001b0180: 8ae30003 lwl r3,0x0003(r23)       |r3 = unaligned word from 0x801b8bc   which is in fact aligned ?
001b0184: 9ae30000 lwr r3,0x0000(r23)       |r3 = Attack current Z mod & Attack current X mod
001b0188: 8ae40007 lwl r4,0x0007(r23)       |
001b018c: 9ae40004 lwr r4,0x0004(r23)       |r4 = unknown halfword (0x0000 wheen tested) & Attacks current Y mod
001b0190: aba3005b swl r3,0x005b(r29)       |Store Attack current X mod at stack 0x58
001b0194: bba30058 swr r3,0x0058(r29)       |Store Attack current Z mod at stack 0x5a
001b0198: aba4005f swl r4,0x005f(r29)       |Store Attack current Y mod at stack 0x5c
001b019c: bba4005c swr r4,0x005c(r29)       |Store ?? At stack 0x5e
001b01a0: 00401821 addu r3,r2,r0            |r3 = r2 (0x00 if obstacle)
001b01a4: 3c13801c lui r19,0x801c           |r19 = 0x801c0000
001b01a8: 8e738b64 lw r19,-0x749c(r19)      |r19 = Target ID from 0x801b8b64
001b01ac: 3c02801c lui r2,0x801c            |r2 = 0x801c0000
001b01b0: 8c428b64 lw r2,-0x749c(r2)        |r2 = Target ID  from 0x801b8b64
001b01b4: 3c08801c lui r8,0x801c            |r8 = 0x801c0000
001b01b8: 8d08bf3c lw r8,-0x40c4(r8)        |r8 = 3D step counter from 0x801bbf3c
001b01bc: 2416ffff addiu r22,r0,0xffff      |r22 = -0x0001
001b01c0: 14560003 bne r2,r22,0x001b01d0    #If Target Exist (ID <> -0x01)
001b01c4: afa800a0 sw r8,0x00a0(r29)        |Store 3D step counter on stack 0xa0
001b01c8: 3c16801c lui r22,0x801c                |r22 = 0x801c0000
001b01cc: 8ed68b94 lw r22,-0x746c(r22)           |r22 = if map obstacle =  [Tile 0x06] flags 0x10 0x20 0x40 as 0x01 0x02 and/or 0x04
001b01d0: 10600004 beq r3,r0,0x001b01e4     #If Attacks reaches target - keep data and  EXIT ROUTINE /Else 2nd trajectory attempt
001b01d4: 02801021 addu r2,r20,r0                |r2 = Target ID (before trajectory calculation)
001b01d8: 8fa30098 lw r3,0x0098(r29)             |r3 = [001af3dc val2] (or 0x1000)
001b01dc: 0806c109 j 0x001b0424                  >>jump near end  storing [001af3dc val2] (or 0x1000) at 0x801b8874 (unknown)
001b01e0: 00000000 nop                           |
001b01e4: 3c04801c lui r4,0x801c            #Else (1st attempt ends in an Obstacle !!) r4 = 0x801c0000
001b01e8: 2484925c addiu r4,r4,-0x6da4      |r4 = Attacker XYZ mods pointer  *0x801b925c
001b01ec: 02402821 addu r5,r18,r0           |r5 = Stack 0x94
001b01f0: 02203021 addu r6,r17,r0           |r6 = stack 0x6c
001b01f4: 02003821 addu r7,r16,r0           |r7 = Stack 0x28
001b01f8: 8fa20090 lw r2,0x0090(r29)        |r2 = 0x1f800000
001b01fc: 2411ffff addiu r17,r0,-0x0001     |r17 = -0x0001
001b0200: 0c06bece jal 0x001afb38           |-->Set_Arcing_Trajectory Set Trajectory data, using [001af3dc val1] instead of  [001af3dc val2]  return r2 = 0x00 if obstacle
001b0204: afa20010 sw r2,0x0010(r29)        |Store 0x1f800000 on stack 0x10
001b0208: 8fc30000 lw r3,0x0000(r30)        |r3 = 2nd attempt Attacks X mod difference  All datas below may have been updated
001b020c: 8fc40004 lw r4,0x0004(r30)        |r4 = 2nd attempt Attacks Z mod difference  0x801b8b80
001b0210: 8fc50008 lw r5,0x0008(r30)        |r5 = 2nd attempt Attacks Y mod difference  0x801b8b84
001b0214: 8fc6000c lw r6,0x000c(r30)        |r6 = 2nd ??? At 0x801b8b88  0x801b8b88
001b0218: afa30030 sw r3,0x0030(r29)        |Store 2nd Attacks X mod difference on stack 0x30
001b021c: afa40034 sw r4,0x0034(r29)        |Store 2nd Attacks Z mod difference on stack 0x34
001b0220: afa50038 sw r5,0x0038(r29)        |Store 2nd Attacks Y mod difference on stack 0x38
001b0224: afa6003c sw r6,0x003c(r29)        |Store 2nd ?? mod on stack 0x3c
001b0228: 8ae30003 lwl r3,0x0003(r23)       |r3 = unaligned word from 0x801b8bc 
001b022c: 9ae30000 lwr r3,0x0000(r23)       |r3 = Attack current Z mod & Attack current X mod
001b0230: 8ae40007 lwl r4,0x0007(r23)       |
001b0234: 9ae40004 lwr r4,0x0004(r23)       |r4 = unknown halfword (0x0000 wheen tested) & Attacks current Y mod
001b0238: aba30053 swl r3,0x0053(r29)       |Store 2nd Attack current X mod at stack 0x50
001b023c: bba30050 swr r3,0x0050(r29)       |Store 2nd Attack current Z mod at stack 0x52
001b0240: aba40057 swl r4,0x0057(r29)       |Store 2nd Attack current Y mod at stack 0x54
001b0244: bba40054 swr r4,0x0054(r29)       |Store 2nd ?? At stack 0x56
001b0248: 00401821 addu r3,r2,r0            |r3 = 0x00 if ends in an obstacle
001b024c: 3c10801c lui r16,0x801c           |r16 = 0x801c0000
001b0250: 8e108b64 lw r16,-0x749c(r16)      |r16 = 2nd attempt Target ID from 0x801b8b64
001b0254: 3c02801c lui r2,0x801c            |r2 = 0x801c0000
001b0258: 8c428b64 lw r2,-0x749c(r2)        |r2 = 2nd attempt Target ID  from 0x801b8b64
001b025c: 3c12801c lui r18,0x801c           |r8 = 0x801c0000
001b0260: 8e52bf3c lw r18,-0x40c4(r18)      |r18 = 2nd attempt 3D step counter from 0x801bbf3c
001b0264: 14510003 bne r2,r17,0x001b0274    #If Target Exist (ID <> -0x01)
001b0268: 00000000 nop                           | 
001b026c: 3c11801c lui r17,0x801c                |r17 = 0x801c0000
001b0270: 8e318b94 lw r17,-0x746c(r17)           |r17 = if map obstacle =  [Tile 0x06] flags 0x10 0x20 0x40 as 0x01 0x02 and/or 0x04
001b0274: 10600004 beq r3,r0,0x001b0288     #If Attacks reaches target - keep 2nd attempt data and  EXIT ROUTINE
001b0278: 02801021 addu r2,r20,r0                |r2 = Target ID (before trajectory calculation)
001b027c: 8fa30094 lw r3,0x0094(r29)             |r3 = [001af3dc val1]
001b0280: 0806c109 j 0x001b0424                  >>jump near end  storing [001af3dc val1]at 0x801b8874 (unknown)
001b0284: 00000000 nop                           |
001b0288: 0c0602bf jal 0x00180afc           #Else (Obstacle 2 times !!) -->Get Unit's Data Pointer Returns r2 =  Attacker data pointer
001b028c: 02a02021 addu r4,r21,r0           |r4 =  Attacker ID
001b0290: 2408ffff addiu r8,r0,-0x0001      |r8 = -0x0001
001b0294: 1268001f beq r19,r8,0x001b0314    #If Hitted unit in the 1st trajectory attempt exists
001b0298: 0040a021 addu r20,r2,r0           |r20 = Initial Target ID
001b029c: 0c0602bf jal 0x00180afc                |-->Get_Unit%27s_Data_Pointer Returns r2 = 1st attempt Target data pointer
001b02a0: 02602021 addu r4,r19,r0                |r4 = 1st attempt hitted unit
001b02a4: 92830005 lbu r3,0x0005(r20)            |r3 = Initial Target ENTD flags
001b02a8: 904201ba lbu r2,0x01ba(r2)             |r2 = 1st attempt Target modified ENTD flags
001b02ac: 30630030 andi r3,r3,0x0030             |r3 = Initial Target Team
001b02b0: 30420030 andi r2,r2,0x0030             |r2 = 1st attempt Target Team (modified)
001b02b4: 10620018 beq r3,r2,0x001b0318          #If initial Target is not in 1st attempt Target team : update Attack's data with first attempt (favours undesired team...) and exit
001b02b8: 2415ffff addiu r21,r0,-0x0001          |r21 = -0x01
001b02bc: 8fa20040 lw r2,0x0040(r29)                 |r2 = 1st attempt Attacks X mod difference 
001b02c0: 8fa30044 lw r3,0x0044(r29)                 |r3 = 1st attempt Attacks Z mod difference 
001b02c4: 8fa40048 lw r4,0x0048(r29)                 |r4 = 1st attempt  Attacks Y mod difference 
001b02c8: 8fa5004c lw r5,0x004c(r29)                 |r5 = 1st attempt ??? 
001b02cc: afc20000 sw r2,0x0000(r30)                 |Store  = 1st Attacks X mod difference at 0x801b8b7c 
001b02d0: afc30004 sw r3,0x0004(r30)                 |Store  = 1st Attacks Z mod difference at 0x801b8b80 
001b02d4: afc40008 sw r4,0x0008(r30)                 |Store  = 1st Attacks Y mod difference at 0x801b8b84
001b02d8: afc5000c sw r5,0x000c(r30)                 |Store  = 1st Attacks ???? difference at 0x801b8b88
001b02dc: 8ba2005b lwl r2,0x005b(r29)                |r2 =  unaligned word (Zmod & X mod)
001b02e0: 9ba20058 lwr r2,0x0058(r29)                |
001b02e4: 8ba3005f lwl r3,0x005f(r29)                |r3 = unaligned word (??? & Y mod)
001b02e8: 9ba3005c lwr r3,0x005c(r29)                |
001b02ec: aae20003 swl r2,0x0003(r23)                |Store 1st Attack current X mod at 0x801b8b8c
001b02f0: bae20000 swr r2,0x0000(r23)                |Store 1st Attack current Z mod at 0x801b8b8e
001b02f4: aae30007 swl r3,0x0007(r23)                |Store 1st Attack current Y mod at 0x801b8b90
001b02f8: bae30004 swr r3,0x0004(r23)                |Store 1st Attack current ??? at 0x801b8b92
001b02fc: 8fa30098 lw r3,0x0098(r29)                 |r3 = [001af3dc val2]
001b0300: 8fa800a0 lw r8,0x00a0(r29)                 |r8 = 1st Attack 3D step counter
001b0304: 3c01801c lui r1,0x801c                     |r1 = 0x801c0000
001b0308: ac338b64 sw r19,-0x749c(r1)                |Store 1st Attack Target (in the way) at 0x801b8b64
001b030c: 0806c107 j 0x001b041c                      >>jump to END (store r8 et r3 before exit)
001b0310: 02601021 addu r2,r19,r0                    |r2 = 1st Attack Target ID
001b0314: 2415ffff addiu r21,r0,-0x0001     |Else (1st attempt Target does not exists) r21 = -0x01
001b0318: 12150010 beq r16,r21,0x001b035c        #Else If 2nd attempt Target exists (1st target does not exists or is in desired team)
001b031c: 00000000 nop                               | 
001b0320: 0c0602bf jal 0x00180afc                    |-->Get_Unit%27s_Data_Pointer Returns r2 = 2nd attempt Target data pointer
001b0324: 02002021 addu r4,r16,r0                    |r4 = 2nd attempt Target ID
001b0328: 92830005 lbu r3,0x0005(r20)                |r3 = Initial Target ENTD flags
001b032c: 904201ba lbu r2,0x01ba(r2)                 |r2 = New Target modified ENTD flags
001b0330: 30630030 andi r3,r3,0x0030                 |r3 = Initial Target Team
001b0334: 30420030 andi r2,r2,0x0030                 |r2 = 2nd attempt Target Team (modified)
001b0338: 10620011 beq r3,r2,0x001b0380              #if Initial Target and 2nd attempt target are not in the same team
001b033c: 02001021 addu r2,r16,r0                    |r2 = 2nd attempt Target ID
001b0340: 8fa30094 lw r3,0x0094(r29)                     |r3 = [001af3dc val1]
001b0344: 3c01801c lui r1,0x801c                         |r1 = 0x801c0000
001b0348: ac32bf3c sw r18,-0x40c4(r1)                    |Store 2nd attempt 3D step counter at 0x801bbf3c
001b034c: 3c01801c lui r1,0x801c                         |r1 = 0x801c0000
001b0350: ac228b64 sw r2,-0x749c(r1)                     |Store 2nd attempt Target ID at 0x801b8b64
001b0354: 0806c109 j 0x001b0424                          >>jump near end (store r3 and exits)
001b0358: 00000000 nop                                   | 
001b035c: 8fa30094 lw r3,0x0094(r29)             |Else (2nd attempt Target doesn't exist - Attack will hit tile) r3 = [001af3dc val1]
001b0360: 3c01801c lui r1,0x801c                 |r1 = 0x801c0000
001b0364: ac32bf3c sw r18,-0x40c4(r1)            |Store 2nd attempt 3D step counter at 0x801bbf3c
001b0368: 3c01801c lui r1,0x801c                 |r1 = 0x801c0000
001b036c: ac308b64 sw r16,-0x749c(r1)            |Store -0x01 at 0x801b8b64 (Attack Target)
001b0370: 3c01801c lui r1,0x801c                 |r1 = 0x801c0000
001b0374: ac318b94 sw r17,-0x746c(r1)            |Store [Tile 0x06] data at 0x801b8b94  (0x01, 0x02 or  0x04 for 0x10, 0x20 or 0x40)
001b0378: 0806c109 j 0x001b0424                  >>jump to END (store r3 before exit)
001b037c: 2402ffff addiu r2,r0,-0x0001           |r2 = -0x01 (no unit target)
001b0380: 1275000a beq r19,r21,0x001b03ac            #Else If 1st attack Target ID exists (hit 2nd target)
001b0384: 00000000 nop                                   | 
001b0388: 8fa30094 lw r3,0x0094(r29)                     |r3 = [001af3dc val1]
001b038c: 3c01801c lui r1,0x801c                         |r1 = 0x801c0000
001b0390: ac32bf3c sw r18,-0x40c4(r1)                    |Store 2nd attempt 3D step counter at 0x801bbf3c
001b0394: 3c01801c lui r1,0x801c                         |r1 = 0x801c0000
001b0398: ac318b94 sw r17,-0x746c(r1)                    |Store [Tile 0x06] data at 0x801b8b94  (0x01, 0x02 or  0x04 for 0x10, 0x20 or 0x40)
001b039c: 3c01801c lui r1,0x801c                         |r1 = 0x801c0000
001b03a0: ac228b64 sw r2,-0x749c(r1)                     |Store2nd target ID at 0x801b8b64 (Attack Target)
001b03a4: 0806c109 j 0x001b0424                          >>jump to End (store r3)
001b03a8: 00000000 nop                                   |
001b03ac: 3c05801c lui r5,0x801c                     |Else 1st attack unit does not exists (hit 1st attempt tile) r5 = 0x801c0000
001b03b0: 24a58b7c addiu r5,r5,-0x7484               |r5 = 0x801b8b7c
001b03b4: 8fa20040 lw r2,0x0040(r29)                 |r2 = 1st attempt Attacks X mod difference 
001b03b8: 8fa30044 lw r3,0x0044(r29)                 |r3 = 1st attempt Attacks Z mod difference 
001b03bc: 8fa40048 lw r4,0x0048(r29)                 |r4 = 1st attempt  Attacks Y mod difference 
001b03c0: aca20000 sw r2,0x0000(r5)                  |Store  = 1st Attacks X mod difference at 0x801b8b7c 
001b03c4: aca30004 sw r3,0x0004(r5)                  |Store  = 1st Attacks Z mod difference at 0x801b8b80 
001b03c8: aca40008 sw r4,0x0008(r5)                  |Store  = 1st Attacks Y mod difference at 0x801b8b84
001b03cc: 8fa2004c lw r2,0x004c(r29)                 |r2 = 1st attempt ??? 
001b03d0: 00000000 nop                               |
001b03d4: aca2000c sw r2,0x000c(r5)                  |Store  = 1st Attacks ???? difference at 0x801b8b88
001b03d8: 3c05801c lui r5,0x801c                     |r5 = 0x801c0000
001b03dc: 24a58b8c addiu r5,r5,-0x7474               |r5 = 0x801b8b8c
001b03e0: 8ba2005b lwl r2,0x005b(r29)                |r2 =  unaligned word (Zmod & X mod)
001b03e4: 9ba20058 lwr r2,0x0058(r29)                |
001b03e8: 8ba3005f lwl r3,0x005f(r29)                |r3 = unaligned word (??? & Y mod)
001b03ec: 9ba3005c lwr r3,0x005c(r29)                |
001b03f0: a8a20003 swl r2,0x0003(r5)                 |Store 1st Attack current X mod at 0x801b8b8c
001b03f4: b8a20000 swr r2,0x0000(r5)                 |Store 1st Attack current Z mod at 0x801b8b8e
001b03f8: a8a30007 swl r3,0x0007(r5)                 |Store 1st Attack current Y mod at 0x801b8b90
001b03fc: b8a30004 swr r3,0x0004(r5)                 |Store 1st Attack current ??? at 0x801b8b92
001b0400: 8fa30098 lw r3,0x0098(r29)                 |r3 = [001af3dc val2]
001b0404: 8fa800a0 lw r8,0x00a0(r29)                 |r8 = 1st attempt 3D step counter
001b0408: 2402ffff addiu r2,r0,-0x0001               |r2 = -0x01
001b040c: 3c01801c lui r1,0x801c                     |r1 = 0801c0000
001b0410: ac338b64 sw r19,-0x749c(r1)                |store 1st attempt target ID (= -0x01 if here) at 0x801b8b64
001b0414: 3c01801c lui r1,0x801c                     |r1 = 0801c0000
001b0418: ac368b94 sw r22,-0x746c(r1)                | [Tile 0x06] data at 0x801b8b94
001b041c: 3c01801c lui r1,0x801c            >>j      |r1 = 0801c0000
001b0420: ac28bf3c sw r8,-0x40c4(r1)                 |Store r8 as Attack's 3D step counter at 0x801bbf3c
001b0424: 3c01801c lui r1,0x801c            >>j      |r1 = 0801c0000
001b0428: ac238b74 sw r3,-0x748c(r1)                 |Store r3 as Attack's ??? (trajectory ?) at 0x801b8b74  [001af3dc val1] or  [001af3dc val2]
001b042c: 8fbf00cc lw r31,0x00cc(r29)       END
001b0430: 8fbe00c8 lw r30,0x00c8(r29)       
001b0434: 8fb700c4 lw r23,0x00c4(r29)       
001b0438: 8fb600c0 lw r22,0x00c0(r29)       
001b043c: 8fb500bc lw r21,0x00bc(r29)       
001b0440: 8fb400b8 lw r20,0x00b8(r29)       
001b0444: 8fb300b4 lw r19,0x00b4(r29)       
001b0448: 8fb200b0 lw r18,0x00b0(r29)      
001b044c: 8fb100ac lw r17,0x00ac(r29)       
001b0450: 8fb000a8 lw r16,0x00a8(r29)       
001b0454: 27bd00d0 addiu r29,r29,0x00d0     
001b0458: 03e00008 jr r31                   
001b045c: 00000000 nop

Summary

Set trajectory data and a list of tragetable units

Tests two trajectories
- if first attempt reaches target, keep first (don't even test the 2nd)
- if second reaches target keep second
- if the two ends in obstacle
     - if 1st unit exists and is not in desired* team - keep 1st trajectory
     - if 1st unit does not exists or is in desired team
          - if 2nd target exists in undesired team - keep second trajectory
          - 2nd target doesn't exists - hit second tile
          - 2nd target is in good team
               - if 1st unit exists (in good team) : hit 2nd target
               - if 1st unit doesn't exist : hit 1st tile 
* desired team is the team of the initial unit. Ending in obstacle is set to be the most punishing.
 
Set Attack data : 
0x801b8b60 - Attacker ID 
0x801b8b64 - Target's ID (Word)
0x801b8b68 - Attack's Current X (for checking targets)
0x801b8b6a - Attack's Current Map Level
0x801b8b6c - Attack's Current Y
0x801b8b70 - ArcTan Angle Mod (may be for other angle mods too)
0x801b8b74 - ??? Related to trajectory  : 1st attempt[001af3dc val2] or 2nd attempt [001af3dc val1] 
0x801b8b7c - Attack's X Mod Difference (Current X Mod - Previous X Mod)
0x801b8b80 - Attack's Z Mod Difference ()
0x801b8b84 - Attack's Y Mod Difference
0x801b8b88 - ??? Stored (not seen set) in arc weapon trajectory routine
0x801b8b8c - Attack's Current X Mod
0x801b8b8e - Attack's Current Z Mod
0x801b8b90 - Attack's Current Y Mod
0x801b8b94 - Target Tile's 0x06 byte's 0x10-0x40 flags stored as 0x01 0x02 0x04(on hitting a tile) 

Return locations

 0017ae94: Targeting_validation_(weapon_flags)