Set chosen ability/target for AI status

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search

Pick ability/target for berserk/confuse/chicken/bloodsuck

Note: Chicken should override all AI status because it's the first status handled, then Bloodsuck, Confusion, and finally Berserk.
001971b8: 3c02801a lui r2,0x801a
001971bc: 90420d7b lbu r2,0x0d7b(r2)				If Action = Decided
001971c0: 27bdffd8 addiu r29,r29,0xffd8
001971c4: afb3001c sw r19,0x001c(r29)
001971c8: 3c13801a lui r19,0x801a
001971cc: 2673f3c4 addiu r19,r19,0xf3c4			r19 = AI Data Offset
001971d0: afbf0020 sw r31,0x0020(r29)
001971d4: afb20018 sw r18,0x0018(r29)
001971d8: afb10014 sw r17,0x0014(r29)
001971dc: 10400008 beq r2,r0,0x 00197200			Branch if Action = Not Decided
001971e0: afb00010 sw r16,0x0010(r29)

<Action = Decided>

001971e4: 3c02801a lui r2,0x801a
001971e8: 90420032 lbu r2,0x0032(r2)				load Decision Byte
001971ec: 00000000 nop
001971f0: 1040000c beq r2,r0,0x 00197224			<Chicken> if Decision Byte is unset
001971f4: 00000000 nop
001971f8: 08065cb9 j 0x 001972e4					else <Movement>
001971fc: 00000000 nop

<Action = Undecided>

00197200: 3c03801a lui r3,0x801a
00197204: 8c630bbc lw r3,0x0bbc(r3)				load acting units data
00197208: 3c01801a lui r1,0x801a
0019720c: a02001f1 sb r0,0x01f1(r1)				Ability Decided = False
00197210: 9064005a lbu r4,0x005a(r3)				load status
00197214: 00000000 nop
00197218: 30820004 andi r2,r4,0x0004
0019721c: 10400011 beq r2,r0,0x 00197264			<Blood Suck> if not Chicken
00197220: 00000000 nop

<Chicken>

00197224: 0c066672 jal 0x 001999c8					AI Target Priority Super Routine (Sets a ton of data)
00197228: 00000000 nop
0019722c: 2403ffff addiu r3,r0,0xffff
00197230: 14430004 bne r2,r3,0x 00197244			Continue if frame cycle is not ending yet
00197234: 266403b4 addiu r4,r19,0x03b4
00197238: a2600c6e sb r0,0x0c6e(r19)				Action Decided = False
0019723c: 08065d46 j 0x 00197518					Frame Cycle is ending, exit out of everything
00197240: 2402ffff addiu r2,r0,0xffff

00197244: 0c066ade jal 0x 0019ab78					Null Words (Matrix Data)
00197248: 34050240 ori r5,r0,0x0240
0019724c: 340400ff ori r4,r0,0x00ff
00197250: 0c065a4f jal 0x 0019693c					AI Ability CT Usage
00197254: 34050001 ori r5,r0,0x0001
00197258: 8e620cc4 lw r2,0x0cc4(r19)				Load Target Unit AI Pointer
0019725c: 08065ccb j 0x 0019732c					Jump to Empty more bytes
00197260: a26017fc sb r0,0x17fc(r19)				Empty ?

<Blood Suck>

00197264: 90630059 lbu r3,0x0059(r3)
00197268: 00000000 nop
0019726c: 30620004 andi r2,r3,0x0004
00197270: 10400031 beq r2,r0,0x 00197338			<Confusion> if not blood suck
00197274: 00000000 nop
00197278: 0c066449 jal 0x 00199124					calculate physical target
0019727c: 00002021 addu r4,r0,r0
00197280: 00409021 addu r18,r2,r0
00197284: 26711770 addiu r17,r19,0x1770			Load AI-Status abilities Hardcode
00197288: 3c02801a lui r2,0x801a
0019728c: 904201f2 lbu r2,0x01f2(r2)				load acting unit ID?
00197290: 96631770 lhu r3,0x1770(r19)				r3 = 00c8 (Blood Suck's Ability ID)
00197294: 00021280 sll r2,r2,0x0a 					ID * 400
00197298: 00621825 or r3,r3,r2						
0019729c: a6631770 sh r3,0x1770(r19)				Save Unit ID to 0x1771

<Get Ability Properties> (Berserk jumps here)

001972a0: 0c06561e jal 0x 00195878					AI ability setting
001972a4: 02202021 addu r4,r17,r0
001972a8: 34100014 ori r16,r0,0x0014				CLEAR TARGETABLE LIST
001972ac: 26620014 addiu r2,r19,0x0014				r2 = AI data + 0x14
001972b0: a0400c8d sb r0,0x0c8d(r2)				clear byte
001972b4: 2610ffff addiu r16,r16,0xffff			counter--
001972b8: 0601fffd bgez r16,0x 001972b0		
001972bc: 2442ffff addiu r2,r2,0xffff				address--
001972c0: 02721821 addu r3,r19,r18					8019f3c4 + chosen targets ID
001972c4: 34020001 ori r2,r0,0x0001
001972c8: 0c065d4e jal 0x 00197538					Ability Usage/Targeting
001972cc: a0620c8d sb r2,0x0c8d(r3)				set unit targetable
001972d0: 14400091 bne r2,r0,0x 00197518			Exit if Ability Usage/Targeting was successful
001972d4: 34020001 ori r2,r0,0x0001

<Validation>

001972d8: 02402021 addu r4,r18,r0
001972dc: 0c067ca9 jal 0x 0019f2a4					transfer unit coordinates to AI
001972e0: 26650c74 addiu r5,r19,0x0c74	

<Movement>

001972e4: 0c06653e jal 0x 001994f8					See if able to move to target
001972e8: 26640c74 addiu r4,r19,0x0c74
001972ec: 2403ffff addiu r3,r0,0xffff
001972f0: 14430005 bne r2,r3,0x 00197308			branch if able to move to target
001972f4: 3c047fff lui r4,0x7fff

<Can't Move to Target>

001972f8: 34020001 ori r2,r0,0x0001
001972fc: a2620c6e sb r2,0x0c6e(r19)				Set Decision Byte to 1
00197300: 08065d46 j 0x 00197518					<Exit>
00197304: 2402ffff addiu r2,r0,0xffff				return 0xffff (Fail)

????
00197308: 3484ffff ori r4,r4,0xffff
0019730c: 0c065a4f jal 0x 0019693c					AI Ability CT? Usage
00197310: 34050001 ori r5,r0,0x0001
00197314: 92620e2d lbu r2,0x0e2d(r19)				Ability = isDecided
00197318: 00000000 nop
0019731c: 00021080 sll r2,r2,0x02					??*4
00197320: 00531021 addu r2,r2,r19					AI data + ??*4
00197324: 8c420cc4 lw r2,0x0cc4(r2)				Load Target Unit AI Pointer
00197328: a26017fc sb r0,0x17fc(r19)				Empty ?
0019732c: a2601805 sb r0,0x1805(r19)				Empty ?
00197330: 08065d45 j 0x 00197514					<Exit>
00197334: ae621800 sw r2,0x1800(r19)				Save Target Unit AI Pointer

<Confusion>

00197338: 30620010 andi r2,r3,0x0010
0019733c: 10400054 beq r2,r0,0x 00197490			<Berserk> if not Confusion
00197340: 30820008 andi r2,r4,0x0008
00197344: 00002021 addu r4,r0,r0
00197348: 0c065f43 jal 0x 00197d0c					Set valid targets for turn consideration
0019734c: 340500ff ori r5,r0,0x00ff				#Any Target (besides self)
00197350: 1040004b beq r2,r0,0x 00197480			Next Unit if no targets are available
00197354: 00000000 nop								(r16 is -1 at this point)
00197358: 00008021 addu r16,r0,r0
0019735c: 02708821 addu r17,r19,r16
00197360: a2200c8d sb r0,0x0c8d(r17)				clear targetable unit list byte
00197364: 0c065b23 jal 0x 00196c8c					check target type
00197368: 02002021 addu r4,r16,r0
0019736c: 14400004 bne r2,r0,0x 00197380			branch if not targetable
00197370: 26100001 addiu r16,r16,0x0001
00197374: 92220c78 lbu r2,0x0c78(r17)				load active unit list
00197378: 00000000 nop
0019737c: a2220c8d sb r2,0x0c8d(r17)				store targetable/nontargetable
00197380: 2a020015 slti r2,r16,0x0015
00197384: 1440fff6 bne r2,r0,0x 00197360			do for all units
00197388: 02708821 addu r17,r19,r16

0019738c: 00009021 addu r18,r0,r0
00197390: 00008021 addu r16,r0,r0
00197394: 92630e2f lbu r3,0x0e2f(r19)				load battle ID?
00197398: 340400ff ori r4,r0,0x00ff
0019739c: 00031100 sll r2,r3,0x04					byte*16
001973a0: 00431021 addu r2,r2,r3					byte*17
001973a4: 000210c0 sll r2,r2,0x03					byte*136 (0x88)
001973a8: 24420ef0 addiu r2,r2,0x0ef0				r2 = units move pointer
001973ac: 02621821 addu r3,r19,r2					r3 = units move list
001973b0: 00101080 sll r2,r16,0x02					move counter prep

<Count usable Abilities>

001973b4: 00628821 addu r17,r3,r2					r17 = units move list address
001973b8: 92220002 lbu r2,0x0002(r17)				load skillset
001973bc: 00000000 nop
001973c0: 1044000a beq r2,r4,0x 001973ec			<Get Random Move> if invalid skillset (0xff)
001973c4: 00000000 nop	
001973c8: 96220002 lhu r2,0x0002(r17)				load usage type
001973cc: 00000000 nop
001973d0: 30428000 andi r2,r2,0x8000			
001973d4: 10400002 beq r2,r0,0x 001973e0			branch if not usable
001973d8: 26100001 addiu r16,r16,0x0001			move counter++
001973dc: 26520001 addiu r18,r18,0x0001			usable move counter++
001973e0: 2a020022 slti r2,r16,0x0022				do for all moves
001973e4: 1440fff3 bne r2,r0,0x 001973b4
001973e8: 00101080 sll r2,r16,0x02					move address prep

<Get Random Ability>

001973ec: 12400024 beq r18,r0,0x 00197480			<Calculate Target> if no moves found
001973f0: 00000000 nop
001973f4: 0c0088c3 jal 0x0002230c					random routine
001973f8: 00000000 nop
001973fc: 00002021 addu r4,r0,r0
00197400: 92630e2f lbu r3,0x0e2f(r19)				load units ID
00197404: 0052001a div r2,r18						random / move list
00197408: 00008010 mfhi r16						r16 = remainder
0019740c: 00031100 sll r2,r3,0x04
00197410: 00431021 addu r2,r2,r3
00197414: 000210c0 sll r2,r2,0x03
00197418: 24420ef0 addiu r2,r2,0x0ef0
0019741c: 02621821 addu r3,r19,r2

<Pick move?>

00197420: 00608821 addu r17,r3,r0					r3, r17 = move list
00197424: 94620002 lhu r2,0x0002(r3)				load usage
00197428: 00000000 nop		
0019742c: 30428000 andi r2,r2,0x8000			
00197430: 10400004 beq r2,r0,0x 00197444			Branch if unusable 
00197434: 26230004 addiu r3,r17,0x0004				move list++
00197438: 12000006 beq r16,r0,0x 00197454			branch if remainder of random / move list = 0
0019743c: 00000000 nop		
00197440: 2610ffff addiu r16,r16,0xffff			remainder--
00197444: 24840001 addiu r4,r4,0x0001				move counter++
00197448: 28820022 slti r2,r4,0x0022		
0019744c: 1440fff4 bne r2,r0,0x 00197420			do for all moves
00197450: 00000000 nop


00197454: 0c06561e jal 0x 00195878					AI ability setting
00197458: 02202021 addu r4,r17,r0					r4 = address of chosen move in list?
0019745c: 0c065d4e jal 0x 00197538					Store ability/skillset data, set AI settings for ability?
00197460: 00000000 nop
00197464: 1440002b bne r2,r0,0x 00197514			branch to end if return != 0
00197468: 2652ffff addiu r18,r18,0xffff			move counter--
0019746c: 96220002 lhu r2,0x0002(r17)				load usage flags
00197470: 00000000 nop
00197474: 30427fff andi r2,r2,0x7fff				remove usable flag
00197478: 1640ffde bne r18,r0,0x 001973f4			branch if not finished?
0019747c: a6220002 sh r2,0x0002(r17)				store new flags
00197480: 0c066449 jal 0x 00199124					calculate target
00197484: 34040003 ori r4,r0,0x0003				#Choose closest unit
00197488: 08065cb6 j 0x 001972d8					branch to targeting/movement validation
0019748c: 00409021 addu r18,r2,r0

<Berserk>

00197490: 10400021 beq r2,r0,0x 00197518			Exit if not Berserk
00197494: 00001021 addu r2,r0,r0					Return False
00197498: 0c066449 jal 0x 00199124					Calculate Physical target choose unit to attack
0019749c: 34040002 ori r4,r0,0x0002				#target enemy
001974a0: 3c04801a lui r4,0x801a		
001974a4: 8c840bbc lw r4,0x0bbc(r4)				load acting units data
001974a8: 00000000 nop		
001974ac: 90830012 lbu r3,0x0012(r4)				load primary skillset
001974b0: 00000000 nop		
001974b4: 2c6300b0 sltiu r3,r3,0x00b0				
001974b8: 1060000f beq r3,r0,0x 001974f8			<Monster/Frog> if monster skillset
001974bc: 00409021 addu r18,r2,r0
001974c0: 9082005a lbu r2,0x005a(r4)				
001974c4: 00000000 nop
001974c8: 30420002 andi r2,r2,0x0002
001974cc: 1440000b bne r2,r0,0x 001974fc			<Monster/Frog> if frog
001974d0: 26711774 addiu r17,r19,0x1774
001974d4: 3c03801a lui r3,0x801a
001974d8: 906301f3 lbu r3,0x01f3(r3)				load acting units battle ID
001974dc: 00000000 nop
001974e0: 00031100 sll r2,r3,0x04					ID * 16
001974e4: 00431021 addu r2,r2,r3					ID*17
001974e8: 000210c0 sll r2,r2,0x03					ID*104 (0x88)
001974ec: 24420ef0 addiu r2,r2,0x0ef0				
001974f0: 08065ca8 j 0x 001972a0					<Get Ability Properties>
001974f4: 00538821 addu r17,r2,r19					r17 = units move list (defaults to Attack)

<Monster/Frog>

001974f8: 26711774 addiu r17,r19,0x1774			r17 = Berserk Monster/Frog Hardcode
001974fc: 92620e2e lbu r2,0x0e2e(r19)				load acting unit ID
00197500: 96631774 lhu r3,0x1774(r19)				Load Berserk Monster/Frog Hardcode (Use Frog Attack instead of Attack)
00197504: 00021280 sll r2,r2,0x0a					(Use Frog Attack instead of Attack)
00197508: 00621825 or r3,r3,r2						(Can't have Frogs dealing decent damage now, can we?)
0019750c: 08065ca8 j 0x 001972a0					<Get Ability Properties>
00197510: a6631774 sh r3,0x1774(r19)				store shifted acting unit ID

<Exit>

00197514: 34020001 ori r2,r0,0x0001
00197518: 8fbf0020 lw r31,0x0020(r29)
0019751c: 8fb3001c lw r19,0x001c(r29)
00197520: 8fb20018 lw r18,0x0018(r29)
00197524: 8fb10014 lw r17,0x0014(r29)
00197528: 8fb00010 lw r16,0x0010(r29)
0019752c: 27bd0028 addiu r29,r29,0x0028
00197530: 03e00008 jr r31
00197534: 00000000 nop

Blood Suck / Berserk MonsterFrog Hardcoding

 001a0b34: 84a700c8 (Blood Suck) [Ability ID = Blood Suck, Unit ID, Skillset = a7, Usage = Usable by AI and Weapon Range]
 001a0b38: 84a9016f (Berserk) [Ability ID = Frog Attack, Skillset = a9, Usage = Usable by AI and Weapon Range]