From 201ce5445546fdf52cf00d385dd345fed4c4c7e9 Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Wed, 18 Nov 2020 22:17:41 -0500 Subject: [PATCH] 197F40 funcs --- .../code_197F40/CountPlayerTargets.s | 45 ---- asm/nonmatchings/code_197F40/ForceHomePos.s | 62 ------ .../code_197F40/GetIndexFromHome.s | 35 --- .../code_197F40/GetIndexFromPos.s | 35 --- .../code_197F40/GetTargetListLength.s | 22 -- asm/nonmatchings/code_197F40/SetGoalToHome.s | 31 --- .../code_197F40/SetGoalToTarget.s | 28 --- asm/nonmatchings/code_197F40/SetHomePos.s | 59 ------ .../code_197F40/SetIdleGoalToHome.s | 31 --- .../code_197F40/get_nearest_home_index.s | 53 ----- .../code_197F40/set_actor_current_position.s | 23 -- .../code_197F40/set_actor_home_position.s | 23 -- include/common_structs.h | 4 +- src/code_197F40.c | 199 ++++++++++++++++-- 14 files changed, 187 insertions(+), 463 deletions(-) delete mode 100644 asm/nonmatchings/code_197F40/CountPlayerTargets.s delete mode 100644 asm/nonmatchings/code_197F40/ForceHomePos.s delete mode 100644 asm/nonmatchings/code_197F40/GetIndexFromHome.s delete mode 100644 asm/nonmatchings/code_197F40/GetIndexFromPos.s delete mode 100644 asm/nonmatchings/code_197F40/GetTargetListLength.s delete mode 100644 asm/nonmatchings/code_197F40/SetGoalToHome.s delete mode 100644 asm/nonmatchings/code_197F40/SetGoalToTarget.s delete mode 100644 asm/nonmatchings/code_197F40/SetHomePos.s delete mode 100644 asm/nonmatchings/code_197F40/SetIdleGoalToHome.s delete mode 100644 asm/nonmatchings/code_197F40/get_nearest_home_index.s delete mode 100644 asm/nonmatchings/code_197F40/set_actor_current_position.s delete mode 100644 asm/nonmatchings/code_197F40/set_actor_home_position.s diff --git a/asm/nonmatchings/code_197F40/CountPlayerTargets.s b/asm/nonmatchings/code_197F40/CountPlayerTargets.s deleted file mode 100644 index 2d9426ecf2..0000000000 --- a/asm/nonmatchings/code_197F40/CountPlayerTargets.s +++ /dev/null @@ -1,45 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel CountPlayerTargets -/* 198A2C 8026A14C 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 198A30 8026A150 AFB10014 */ sw $s1, 0x14($sp) -/* 198A34 8026A154 0080882D */ daddu $s1, $a0, $zero -/* 198A38 8026A158 AFBF0020 */ sw $ra, 0x20($sp) -/* 198A3C 8026A15C AFB3001C */ sw $s3, 0x1c($sp) -/* 198A40 8026A160 AFB20018 */ sw $s2, 0x18($sp) -/* 198A44 8026A164 AFB00010 */ sw $s0, 0x10($sp) -/* 198A48 8026A168 8E30000C */ lw $s0, 0xc($s1) -/* 198A4C 8026A16C 8E050000 */ lw $a1, ($s0) -/* 198A50 8026A170 0C0B1EAF */ jal get_variable -/* 198A54 8026A174 26100004 */ addiu $s0, $s0, 4 -/* 198A58 8026A178 0040202D */ daddu $a0, $v0, $zero -/* 198A5C 8026A17C 2402FF81 */ addiu $v0, $zero, -0x7f -/* 198A60 8026A180 8E120000 */ lw $s2, ($s0) -/* 198A64 8026A184 14820002 */ bne $a0, $v0, .L8026A190 -/* 198A68 8026A188 8E130004 */ lw $s3, 4($s0) -/* 198A6C 8026A18C 8E240148 */ lw $a0, 0x148($s1) -.L8026A190: -/* 198A70 8026A190 0C09A75B */ jal get_actor -/* 198A74 8026A194 00000000 */ nop -/* 198A78 8026A198 0040802D */ daddu $s0, $v0, $zero -/* 198A7C 8026A19C 8E06014C */ lw $a2, 0x14c($s0) -/* 198A80 8026A1A0 C60C0144 */ lwc1 $f12, 0x144($s0) -/* 198A84 8026A1A4 0C09A5A6 */ jal get_nearest_home_index -/* 198A88 8026A1A8 C60E0148 */ lwc1 $f14, 0x148($s0) -/* 198A8C 8026A1AC 0200202D */ daddu $a0, $s0, $zero -/* 198A90 8026A1B0 0040282D */ daddu $a1, $v0, $zero -/* 198A94 8026A1B4 0C09A598 */ jal count_targets -/* 198A98 8026A1B8 0240302D */ daddu $a2, $s2, $zero -/* 198A9C 8026A1BC 0220202D */ daddu $a0, $s1, $zero -/* 198AA0 8026A1C0 0260282D */ daddu $a1, $s3, $zero -/* 198AA4 8026A1C4 0C0B2026 */ jal set_variable -/* 198AA8 8026A1C8 0040302D */ daddu $a2, $v0, $zero -/* 198AAC 8026A1CC 8FBF0020 */ lw $ra, 0x20($sp) -/* 198AB0 8026A1D0 8FB3001C */ lw $s3, 0x1c($sp) -/* 198AB4 8026A1D4 8FB20018 */ lw $s2, 0x18($sp) -/* 198AB8 8026A1D8 8FB10014 */ lw $s1, 0x14($sp) -/* 198ABC 8026A1DC 8FB00010 */ lw $s0, 0x10($sp) -/* 198AC0 8026A1E0 24020002 */ addiu $v0, $zero, 2 -/* 198AC4 8026A1E4 03E00008 */ jr $ra -/* 198AC8 8026A1E8 27BD0028 */ addiu $sp, $sp, 0x28 diff --git a/asm/nonmatchings/code_197F40/ForceHomePos.s b/asm/nonmatchings/code_197F40/ForceHomePos.s deleted file mode 100644 index fa38623fac..0000000000 --- a/asm/nonmatchings/code_197F40/ForceHomePos.s +++ /dev/null @@ -1,62 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel ForceHomePos -/* 198ACC 8026A1EC 27BDFFC8 */ addiu $sp, $sp, -0x38 -/* 198AD0 8026A1F0 AFB20018 */ sw $s2, 0x18($sp) -/* 198AD4 8026A1F4 0080902D */ daddu $s2, $a0, $zero -/* 198AD8 8026A1F8 AFBF001C */ sw $ra, 0x1c($sp) -/* 198ADC 8026A1FC AFB10014 */ sw $s1, 0x14($sp) -/* 198AE0 8026A200 AFB00010 */ sw $s0, 0x10($sp) -/* 198AE4 8026A204 F7B80030 */ sdc1 $f24, 0x30($sp) -/* 198AE8 8026A208 F7B60028 */ sdc1 $f22, 0x28($sp) -/* 198AEC 8026A20C F7B40020 */ sdc1 $f20, 0x20($sp) -/* 198AF0 8026A210 8E50000C */ lw $s0, 0xc($s2) -/* 198AF4 8026A214 8E050000 */ lw $a1, ($s0) -/* 198AF8 8026A218 0C0B1EAF */ jal get_variable -/* 198AFC 8026A21C 26100004 */ addiu $s0, $s0, 4 -/* 198B00 8026A220 0040882D */ daddu $s1, $v0, $zero -/* 198B04 8026A224 2402FF81 */ addiu $v0, $zero, -0x7f -/* 198B08 8026A228 16220002 */ bne $s1, $v0, .L8026A234 -/* 198B0C 8026A22C 00000000 */ nop -/* 198B10 8026A230 8E510148 */ lw $s1, 0x148($s2) -.L8026A234: -/* 198B14 8026A234 8E050000 */ lw $a1, ($s0) -/* 198B18 8026A238 26100004 */ addiu $s0, $s0, 4 -/* 198B1C 8026A23C 0C0B1EAF */ jal get_variable -/* 198B20 8026A240 0240202D */ daddu $a0, $s2, $zero -/* 198B24 8026A244 8E050000 */ lw $a1, ($s0) -/* 198B28 8026A248 26100004 */ addiu $s0, $s0, 4 -/* 198B2C 8026A24C 4482C000 */ mtc1 $v0, $f24 -/* 198B30 8026A250 00000000 */ nop -/* 198B34 8026A254 4680C620 */ cvt.s.w $f24, $f24 -/* 198B38 8026A258 0C0B1EAF */ jal get_variable -/* 198B3C 8026A25C 0240202D */ daddu $a0, $s2, $zero -/* 198B40 8026A260 8E050000 */ lw $a1, ($s0) -/* 198B44 8026A264 4482B000 */ mtc1 $v0, $f22 -/* 198B48 8026A268 00000000 */ nop -/* 198B4C 8026A26C 4680B5A0 */ cvt.s.w $f22, $f22 -/* 198B50 8026A270 0C0B1EAF */ jal get_variable -/* 198B54 8026A274 0240202D */ daddu $a0, $s2, $zero -/* 198B58 8026A278 4482A000 */ mtc1 $v0, $f20 -/* 198B5C 8026A27C 00000000 */ nop -/* 198B60 8026A280 4680A520 */ cvt.s.w $f20, $f20 -/* 198B64 8026A284 0C09A75B */ jal get_actor -/* 198B68 8026A288 0220202D */ daddu $a0, $s1, $zero -/* 198B6C 8026A28C 0040182D */ daddu $v1, $v0, $zero -/* 198B70 8026A290 E4780138 */ swc1 $f24, 0x138($v1) -/* 198B74 8026A294 E4780144 */ swc1 $f24, 0x144($v1) -/* 198B78 8026A298 E476013C */ swc1 $f22, 0x13c($v1) -/* 198B7C 8026A29C E4760148 */ swc1 $f22, 0x148($v1) -/* 198B80 8026A2A0 E4740140 */ swc1 $f20, 0x140($v1) -/* 198B84 8026A2A4 E474014C */ swc1 $f20, 0x14c($v1) -/* 198B88 8026A2A8 8FBF001C */ lw $ra, 0x1c($sp) -/* 198B8C 8026A2AC 8FB20018 */ lw $s2, 0x18($sp) -/* 198B90 8026A2B0 8FB10014 */ lw $s1, 0x14($sp) -/* 198B94 8026A2B4 8FB00010 */ lw $s0, 0x10($sp) -/* 198B98 8026A2B8 D7B80030 */ ldc1 $f24, 0x30($sp) -/* 198B9C 8026A2BC D7B60028 */ ldc1 $f22, 0x28($sp) -/* 198BA0 8026A2C0 D7B40020 */ ldc1 $f20, 0x20($sp) -/* 198BA4 8026A2C4 24020002 */ addiu $v0, $zero, 2 -/* 198BA8 8026A2C8 03E00008 */ jr $ra -/* 198BAC 8026A2CC 27BD0038 */ addiu $sp, $sp, 0x38 diff --git a/asm/nonmatchings/code_197F40/GetIndexFromHome.s b/asm/nonmatchings/code_197F40/GetIndexFromHome.s deleted file mode 100644 index 84e6a008bc..0000000000 --- a/asm/nonmatchings/code_197F40/GetIndexFromHome.s +++ /dev/null @@ -1,35 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel GetIndexFromHome -/* 1989B4 8026A0D4 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 1989B8 8026A0D8 AFB10014 */ sw $s1, 0x14($sp) -/* 1989BC 8026A0DC 0080882D */ daddu $s1, $a0, $zero -/* 1989C0 8026A0E0 AFBF0018 */ sw $ra, 0x18($sp) -/* 1989C4 8026A0E4 AFB00010 */ sw $s0, 0x10($sp) -/* 1989C8 8026A0E8 8E30000C */ lw $s0, 0xc($s1) -/* 1989CC 8026A0EC 8E050000 */ lw $a1, ($s0) -/* 1989D0 8026A0F0 0C0B1EAF */ jal get_variable -/* 1989D4 8026A0F4 26100004 */ addiu $s0, $s0, 4 -/* 1989D8 8026A0F8 0040202D */ daddu $a0, $v0, $zero -/* 1989DC 8026A0FC 2402FF81 */ addiu $v0, $zero, -0x7f -/* 1989E0 8026A100 14820002 */ bne $a0, $v0, .L8026A10C -/* 1989E4 8026A104 8E100000 */ lw $s0, ($s0) -/* 1989E8 8026A108 8E240148 */ lw $a0, 0x148($s1) -.L8026A10C: -/* 1989EC 8026A10C 0C09A75B */ jal get_actor -/* 1989F0 8026A110 00000000 */ nop -/* 1989F4 8026A114 8C460140 */ lw $a2, 0x140($v0) -/* 1989F8 8026A118 C44C0138 */ lwc1 $f12, 0x138($v0) -/* 1989FC 8026A11C 0C09A5A6 */ jal get_nearest_home_index -/* 198A00 8026A120 C44E013C */ lwc1 $f14, 0x13c($v0) -/* 198A04 8026A124 0220202D */ daddu $a0, $s1, $zero -/* 198A08 8026A128 0200282D */ daddu $a1, $s0, $zero -/* 198A0C 8026A12C 0C0B2026 */ jal set_variable -/* 198A10 8026A130 0040302D */ daddu $a2, $v0, $zero -/* 198A14 8026A134 8FBF0018 */ lw $ra, 0x18($sp) -/* 198A18 8026A138 8FB10014 */ lw $s1, 0x14($sp) -/* 198A1C 8026A13C 8FB00010 */ lw $s0, 0x10($sp) -/* 198A20 8026A140 24020002 */ addiu $v0, $zero, 2 -/* 198A24 8026A144 03E00008 */ jr $ra -/* 198A28 8026A148 27BD0020 */ addiu $sp, $sp, 0x20 diff --git a/asm/nonmatchings/code_197F40/GetIndexFromPos.s b/asm/nonmatchings/code_197F40/GetIndexFromPos.s deleted file mode 100644 index 94a049c957..0000000000 --- a/asm/nonmatchings/code_197F40/GetIndexFromPos.s +++ /dev/null @@ -1,35 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel GetIndexFromPos -/* 19893C 8026A05C 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 198940 8026A060 AFB10014 */ sw $s1, 0x14($sp) -/* 198944 8026A064 0080882D */ daddu $s1, $a0, $zero -/* 198948 8026A068 AFBF0018 */ sw $ra, 0x18($sp) -/* 19894C 8026A06C AFB00010 */ sw $s0, 0x10($sp) -/* 198950 8026A070 8E30000C */ lw $s0, 0xc($s1) -/* 198954 8026A074 8E050000 */ lw $a1, ($s0) -/* 198958 8026A078 0C0B1EAF */ jal get_variable -/* 19895C 8026A07C 26100004 */ addiu $s0, $s0, 4 -/* 198960 8026A080 0040202D */ daddu $a0, $v0, $zero -/* 198964 8026A084 2402FF81 */ addiu $v0, $zero, -0x7f -/* 198968 8026A088 14820002 */ bne $a0, $v0, .L8026A094 -/* 19896C 8026A08C 8E100000 */ lw $s0, ($s0) -/* 198970 8026A090 8E240148 */ lw $a0, 0x148($s1) -.L8026A094: -/* 198974 8026A094 0C09A75B */ jal get_actor -/* 198978 8026A098 00000000 */ nop -/* 19897C 8026A09C 8C46014C */ lw $a2, 0x14c($v0) -/* 198980 8026A0A0 C44C0144 */ lwc1 $f12, 0x144($v0) -/* 198984 8026A0A4 0C09A5A6 */ jal get_nearest_home_index -/* 198988 8026A0A8 C44E0148 */ lwc1 $f14, 0x148($v0) -/* 19898C 8026A0AC 0220202D */ daddu $a0, $s1, $zero -/* 198990 8026A0B0 0200282D */ daddu $a1, $s0, $zero -/* 198994 8026A0B4 0C0B2026 */ jal set_variable -/* 198998 8026A0B8 0040302D */ daddu $a2, $v0, $zero -/* 19899C 8026A0BC 8FBF0018 */ lw $ra, 0x18($sp) -/* 1989A0 8026A0C0 8FB10014 */ lw $s1, 0x14($sp) -/* 1989A4 8026A0C4 8FB00010 */ lw $s0, 0x10($sp) -/* 1989A8 8026A0C8 24020002 */ addiu $v0, $zero, 2 -/* 1989AC 8026A0CC 03E00008 */ jr $ra -/* 1989B0 8026A0D0 27BD0020 */ addiu $sp, $sp, 0x20 diff --git a/asm/nonmatchings/code_197F40/GetTargetListLength.s b/asm/nonmatchings/code_197F40/GetTargetListLength.s deleted file mode 100644 index 0f53b33a9c..0000000000 --- a/asm/nonmatchings/code_197F40/GetTargetListLength.s +++ /dev/null @@ -1,22 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel GetTargetListLength -/* 19D144 8026E864 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 19D148 8026E868 AFB00010 */ sw $s0, 0x10($sp) -/* 19D14C 8026E86C 0080802D */ daddu $s0, $a0, $zero -/* 19D150 8026E870 AFBF0018 */ sw $ra, 0x18($sp) -/* 19D154 8026E874 AFB10014 */ sw $s1, 0x14($sp) -/* 19D158 8026E878 8E040148 */ lw $a0, 0x148($s0) -/* 19D15C 8026E87C 0C09A75B */ jal get_actor -/* 19D160 8026E880 8E11000C */ lw $s1, 0xc($s0) -/* 19D164 8026E884 8E250000 */ lw $a1, ($s1) -/* 19D168 8026E888 8046040C */ lb $a2, 0x40c($v0) -/* 19D16C 8026E88C 0C0B2026 */ jal set_variable -/* 19D170 8026E890 0200202D */ daddu $a0, $s0, $zero -/* 19D174 8026E894 8FBF0018 */ lw $ra, 0x18($sp) -/* 19D178 8026E898 8FB10014 */ lw $s1, 0x14($sp) -/* 19D17C 8026E89C 8FB00010 */ lw $s0, 0x10($sp) -/* 19D180 8026E8A0 24020002 */ addiu $v0, $zero, 2 -/* 19D184 8026E8A4 03E00008 */ jr $ra -/* 19D188 8026E8A8 27BD0020 */ addiu $sp, $sp, 0x20 diff --git a/asm/nonmatchings/code_197F40/SetGoalToHome.s b/asm/nonmatchings/code_197F40/SetGoalToHome.s deleted file mode 100644 index ad56c519db..0000000000 --- a/asm/nonmatchings/code_197F40/SetGoalToHome.s +++ /dev/null @@ -1,31 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel SetGoalToHome -/* 1987A4 80269EC4 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 1987A8 80269EC8 AFB00010 */ sw $s0, 0x10($sp) -/* 1987AC 80269ECC 0080802D */ daddu $s0, $a0, $zero -/* 1987B0 80269ED0 AFBF0014 */ sw $ra, 0x14($sp) -/* 1987B4 80269ED4 8E02000C */ lw $v0, 0xc($s0) -/* 1987B8 80269ED8 0C0B1EAF */ jal get_variable -/* 1987BC 80269EDC 8C450000 */ lw $a1, ($v0) -/* 1987C0 80269EE0 0040202D */ daddu $a0, $v0, $zero -/* 1987C4 80269EE4 2402FF81 */ addiu $v0, $zero, -0x7f -/* 1987C8 80269EE8 14820002 */ bne $a0, $v0, .L80269EF4 -/* 1987CC 80269EEC 00000000 */ nop -/* 1987D0 80269EF0 8E040148 */ lw $a0, 0x148($s0) -.L80269EF4: -/* 1987D4 80269EF4 0C09A75B */ jal get_actor -/* 1987D8 80269EF8 00000000 */ nop -/* 1987DC 80269EFC 0040182D */ daddu $v1, $v0, $zero -/* 1987E0 80269F00 C4600138 */ lwc1 $f0, 0x138($v1) -/* 1987E4 80269F04 C462013C */ lwc1 $f2, 0x13c($v1) -/* 1987E8 80269F08 C4640140 */ lwc1 $f4, 0x140($v1) -/* 1987EC 80269F0C E4600018 */ swc1 $f0, 0x18($v1) -/* 1987F0 80269F10 E462001C */ swc1 $f2, 0x1c($v1) -/* 1987F4 80269F14 E4640020 */ swc1 $f4, 0x20($v1) -/* 1987F8 80269F18 8FBF0014 */ lw $ra, 0x14($sp) -/* 1987FC 80269F1C 8FB00010 */ lw $s0, 0x10($sp) -/* 198800 80269F20 24020002 */ addiu $v0, $zero, 2 -/* 198804 80269F24 03E00008 */ jr $ra -/* 198808 80269F28 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_197F40/SetGoalToTarget.s b/asm/nonmatchings/code_197F40/SetGoalToTarget.s deleted file mode 100644 index 4f4fe45a4d..0000000000 --- a/asm/nonmatchings/code_197F40/SetGoalToTarget.s +++ /dev/null @@ -1,28 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel SetGoalToTarget -/* 198C88 8026A3A8 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 198C8C 8026A3AC AFB00010 */ sw $s0, 0x10($sp) -/* 198C90 8026A3B0 0080802D */ daddu $s0, $a0, $zero -/* 198C94 8026A3B4 AFBF0014 */ sw $ra, 0x14($sp) -/* 198C98 8026A3B8 8E02000C */ lw $v0, 0xc($s0) -/* 198C9C 8026A3BC 0C0B1EAF */ jal get_variable -/* 198CA0 8026A3C0 8C450000 */ lw $a1, ($v0) -/* 198CA4 8026A3C4 0040202D */ daddu $a0, $v0, $zero -/* 198CA8 8026A3C8 2402FF81 */ addiu $v0, $zero, -0x7f -/* 198CAC 8026A3CC 14820002 */ bne $a0, $v0, .L8026A3D8 -/* 198CB0 8026A3D0 00000000 */ nop -/* 198CB4 8026A3D4 8E040148 */ lw $a0, 0x148($s0) -.L8026A3D8: -/* 198CB8 8026A3D8 0C09A75B */ jal get_actor -/* 198CBC 8026A3DC 00000000 */ nop -/* 198CC0 8026A3E0 84450428 */ lh $a1, 0x428($v0) -/* 198CC4 8026A3E4 80460426 */ lb $a2, 0x426($v0) -/* 198CC8 8026A3E8 0C09A5D5 */ jal set_goal_pos_to_part -/* 198CCC 8026A3EC 2444000C */ addiu $a0, $v0, 0xc -/* 198CD0 8026A3F0 8FBF0014 */ lw $ra, 0x14($sp) -/* 198CD4 8026A3F4 8FB00010 */ lw $s0, 0x10($sp) -/* 198CD8 8026A3F8 24020002 */ addiu $v0, $zero, 2 -/* 198CDC 8026A3FC 03E00008 */ jr $ra -/* 198CE0 8026A400 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_197F40/SetHomePos.s b/asm/nonmatchings/code_197F40/SetHomePos.s deleted file mode 100644 index e8a41b80df..0000000000 --- a/asm/nonmatchings/code_197F40/SetHomePos.s +++ /dev/null @@ -1,59 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel SetHomePos -/* 198BB0 8026A2D0 27BDFFC8 */ addiu $sp, $sp, -0x38 -/* 198BB4 8026A2D4 AFB20018 */ sw $s2, 0x18($sp) -/* 198BB8 8026A2D8 0080902D */ daddu $s2, $a0, $zero -/* 198BBC 8026A2DC AFBF001C */ sw $ra, 0x1c($sp) -/* 198BC0 8026A2E0 AFB10014 */ sw $s1, 0x14($sp) -/* 198BC4 8026A2E4 AFB00010 */ sw $s0, 0x10($sp) -/* 198BC8 8026A2E8 F7B80030 */ sdc1 $f24, 0x30($sp) -/* 198BCC 8026A2EC F7B60028 */ sdc1 $f22, 0x28($sp) -/* 198BD0 8026A2F0 F7B40020 */ sdc1 $f20, 0x20($sp) -/* 198BD4 8026A2F4 8E50000C */ lw $s0, 0xc($s2) -/* 198BD8 8026A2F8 8E050000 */ lw $a1, ($s0) -/* 198BDC 8026A2FC 0C0B1EAF */ jal get_variable -/* 198BE0 8026A300 26100004 */ addiu $s0, $s0, 4 -/* 198BE4 8026A304 0040882D */ daddu $s1, $v0, $zero -/* 198BE8 8026A308 2402FF81 */ addiu $v0, $zero, -0x7f -/* 198BEC 8026A30C 16220002 */ bne $s1, $v0, .L8026A318 -/* 198BF0 8026A310 00000000 */ nop -/* 198BF4 8026A314 8E510148 */ lw $s1, 0x148($s2) -.L8026A318: -/* 198BF8 8026A318 8E050000 */ lw $a1, ($s0) -/* 198BFC 8026A31C 26100004 */ addiu $s0, $s0, 4 -/* 198C00 8026A320 0C0B1EAF */ jal get_variable -/* 198C04 8026A324 0240202D */ daddu $a0, $s2, $zero -/* 198C08 8026A328 8E050000 */ lw $a1, ($s0) -/* 198C0C 8026A32C 26100004 */ addiu $s0, $s0, 4 -/* 198C10 8026A330 4482C000 */ mtc1 $v0, $f24 -/* 198C14 8026A334 00000000 */ nop -/* 198C18 8026A338 4680C620 */ cvt.s.w $f24, $f24 -/* 198C1C 8026A33C 0C0B1EAF */ jal get_variable -/* 198C20 8026A340 0240202D */ daddu $a0, $s2, $zero -/* 198C24 8026A344 8E050000 */ lw $a1, ($s0) -/* 198C28 8026A348 4482B000 */ mtc1 $v0, $f22 -/* 198C2C 8026A34C 00000000 */ nop -/* 198C30 8026A350 4680B5A0 */ cvt.s.w $f22, $f22 -/* 198C34 8026A354 0C0B1EAF */ jal get_variable -/* 198C38 8026A358 0240202D */ daddu $a0, $s2, $zero -/* 198C3C 8026A35C 4482A000 */ mtc1 $v0, $f20 -/* 198C40 8026A360 00000000 */ nop -/* 198C44 8026A364 4680A520 */ cvt.s.w $f20, $f20 -/* 198C48 8026A368 0C09A75B */ jal get_actor -/* 198C4C 8026A36C 0220202D */ daddu $a0, $s1, $zero -/* 198C50 8026A370 0040182D */ daddu $v1, $v0, $zero -/* 198C54 8026A374 E4780138 */ swc1 $f24, 0x138($v1) -/* 198C58 8026A378 E476013C */ swc1 $f22, 0x13c($v1) -/* 198C5C 8026A37C E4740140 */ swc1 $f20, 0x140($v1) -/* 198C60 8026A380 8FBF001C */ lw $ra, 0x1c($sp) -/* 198C64 8026A384 8FB20018 */ lw $s2, 0x18($sp) -/* 198C68 8026A388 8FB10014 */ lw $s1, 0x14($sp) -/* 198C6C 8026A38C 8FB00010 */ lw $s0, 0x10($sp) -/* 198C70 8026A390 D7B80030 */ ldc1 $f24, 0x30($sp) -/* 198C74 8026A394 D7B60028 */ ldc1 $f22, 0x28($sp) -/* 198C78 8026A398 D7B40020 */ ldc1 $f20, 0x20($sp) -/* 198C7C 8026A39C 24020002 */ addiu $v0, $zero, 2 -/* 198C80 8026A3A0 03E00008 */ jr $ra -/* 198C84 8026A3A4 27BD0038 */ addiu $sp, $sp, 0x38 diff --git a/asm/nonmatchings/code_197F40/SetIdleGoalToHome.s b/asm/nonmatchings/code_197F40/SetIdleGoalToHome.s deleted file mode 100644 index 426f614b58..0000000000 --- a/asm/nonmatchings/code_197F40/SetIdleGoalToHome.s +++ /dev/null @@ -1,31 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel SetIdleGoalToHome -/* 19880C 80269F2C 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 198810 80269F30 AFB00010 */ sw $s0, 0x10($sp) -/* 198814 80269F34 0080802D */ daddu $s0, $a0, $zero -/* 198818 80269F38 AFBF0014 */ sw $ra, 0x14($sp) -/* 19881C 80269F3C 8E02000C */ lw $v0, 0xc($s0) -/* 198820 80269F40 0C0B1EAF */ jal get_variable -/* 198824 80269F44 8C450000 */ lw $a1, ($v0) -/* 198828 80269F48 0040202D */ daddu $a0, $v0, $zero -/* 19882C 80269F4C 2402FF81 */ addiu $v0, $zero, -0x7f -/* 198830 80269F50 14820002 */ bne $a0, $v0, .L80269F5C -/* 198834 80269F54 00000000 */ nop -/* 198838 80269F58 8E040148 */ lw $a0, 0x148($s0) -.L80269F5C: -/* 19883C 80269F5C 0C09A75B */ jal get_actor -/* 198840 80269F60 00000000 */ nop -/* 198844 80269F64 0040182D */ daddu $v1, $v0, $zero -/* 198848 80269F68 C4600138 */ lwc1 $f0, 0x138($v1) -/* 19884C 80269F6C C462013C */ lwc1 $f2, 0x13c($v1) -/* 198850 80269F70 C4640140 */ lwc1 $f4, 0x140($v1) -/* 198854 80269F74 E46000D4 */ swc1 $f0, 0xd4($v1) -/* 198858 80269F78 E46200D8 */ swc1 $f2, 0xd8($v1) -/* 19885C 80269F7C E46400DC */ swc1 $f4, 0xdc($v1) -/* 198860 80269F80 8FBF0014 */ lw $ra, 0x14($sp) -/* 198864 80269F84 8FB00010 */ lw $s0, 0x10($sp) -/* 198868 80269F88 24020002 */ addiu $v0, $zero, 2 -/* 19886C 80269F8C 03E00008 */ jr $ra -/* 198870 80269F90 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_197F40/get_nearest_home_index.s b/asm/nonmatchings/code_197F40/get_nearest_home_index.s deleted file mode 100644 index f63168aace..0000000000 --- a/asm/nonmatchings/code_197F40/get_nearest_home_index.s +++ /dev/null @@ -1,53 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel get_nearest_home_index -/* 197F78 80269698 3C014220 */ lui $at, 0x4220 -/* 197F7C 8026969C 44810000 */ mtc1 $at, $f0 -/* 197F80 802696A0 00000000 */ nop -/* 197F84 802696A4 4600703C */ c.lt.s $f14, $f0 -/* 197F88 802696A8 00000000 */ nop -/* 197F8C 802696AC 45010010 */ bc1t .L802696F0 -/* 197F90 802696B0 0000102D */ daddu $v0, $zero, $zero -/* 197F94 802696B4 3C0142AA */ lui $at, 0x42aa -/* 197F98 802696B8 44810000 */ mtc1 $at, $f0 -/* 197F9C 802696BC 00000000 */ nop -/* 197FA0 802696C0 4600703C */ c.lt.s $f14, $f0 -/* 197FA4 802696C4 00000000 */ nop -/* 197FA8 802696C8 45010009 */ bc1t .L802696F0 -/* 197FAC 802696CC 24020001 */ addiu $v0, $zero, 1 -/* 197FB0 802696D0 3C0142C8 */ lui $at, 0x42c8 -/* 197FB4 802696D4 44810000 */ mtc1 $at, $f0 -/* 197FB8 802696D8 00000000 */ nop -/* 197FBC 802696DC 4600703C */ c.lt.s $f14, $f0 -/* 197FC0 802696E0 00000000 */ nop -/* 197FC4 802696E4 45000002 */ bc1f .L802696F0 -/* 197FC8 802696E8 24020003 */ addiu $v0, $zero, 3 -/* 197FCC 802696EC 24020002 */ addiu $v0, $zero, 2 -.L802696F0: -/* 197FD0 802696F0 3C0141C8 */ lui $at, 0x41c8 -/* 197FD4 802696F4 44810000 */ mtc1 $at, $f0 -/* 197FD8 802696F8 00000000 */ nop -/* 197FDC 802696FC 4600603C */ c.lt.s $f12, $f0 -/* 197FE0 80269700 00000000 */ nop -/* 197FE4 80269704 45010010 */ bc1t .L80269748 -/* 197FE8 80269708 0000182D */ daddu $v1, $zero, $zero -/* 197FEC 8026970C 3C014282 */ lui $at, 0x4282 -/* 197FF0 80269710 44810000 */ mtc1 $at, $f0 -/* 197FF4 80269714 00000000 */ nop -/* 197FF8 80269718 4600603C */ c.lt.s $f12, $f0 -/* 197FFC 8026971C 00000000 */ nop -/* 198000 80269720 45010009 */ bc1t .L80269748 -/* 198004 80269724 24030001 */ addiu $v1, $zero, 1 -/* 198008 80269728 3C0142D2 */ lui $at, 0x42d2 -/* 19800C 8026972C 44810000 */ mtc1 $at, $f0 -/* 198010 80269730 00000000 */ nop -/* 198014 80269734 4600603C */ c.lt.s $f12, $f0 -/* 198018 80269738 00000000 */ nop -/* 19801C 8026973C 45000002 */ bc1f .L80269748 -/* 198020 80269740 24030003 */ addiu $v1, $zero, 3 -/* 198024 80269744 24030002 */ addiu $v1, $zero, 2 -.L80269748: -/* 198028 80269748 00021080 */ sll $v0, $v0, 2 -/* 19802C 8026974C 03E00008 */ jr $ra -/* 198030 80269750 00621025 */ or $v0, $v1, $v0 diff --git a/asm/nonmatchings/code_197F40/set_actor_current_position.s b/asm/nonmatchings/code_197F40/set_actor_current_position.s deleted file mode 100644 index 47ae27e515..0000000000 --- a/asm/nonmatchings/code_197F40/set_actor_current_position.s +++ /dev/null @@ -1,23 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel set_actor_current_position -/* 198504 80269C24 27BDFFD0 */ addiu $sp, $sp, -0x30 -/* 198508 80269C28 F7B40018 */ sdc1 $f20, 0x18($sp) -/* 19850C 80269C2C 4485A000 */ mtc1 $a1, $f20 -/* 198510 80269C30 F7B60020 */ sdc1 $f22, 0x20($sp) -/* 198514 80269C34 4486B000 */ mtc1 $a2, $f22 -/* 198518 80269C38 F7B80028 */ sdc1 $f24, 0x28($sp) -/* 19851C 80269C3C 4487C000 */ mtc1 $a3, $f24 -/* 198520 80269C40 AFBF0010 */ sw $ra, 0x10($sp) -/* 198524 80269C44 0C09A75B */ jal get_actor -/* 198528 80269C48 00000000 */ nop -/* 19852C 80269C4C E4540144 */ swc1 $f20, 0x144($v0) -/* 198530 80269C50 E4560148 */ swc1 $f22, 0x148($v0) -/* 198534 80269C54 E458014C */ swc1 $f24, 0x14c($v0) -/* 198538 80269C58 8FBF0010 */ lw $ra, 0x10($sp) -/* 19853C 80269C5C D7B80028 */ ldc1 $f24, 0x28($sp) -/* 198540 80269C60 D7B60020 */ ldc1 $f22, 0x20($sp) -/* 198544 80269C64 D7B40018 */ ldc1 $f20, 0x18($sp) -/* 198548 80269C68 03E00008 */ jr $ra -/* 19854C 80269C6C 27BD0030 */ addiu $sp, $sp, 0x30 diff --git a/asm/nonmatchings/code_197F40/set_actor_home_position.s b/asm/nonmatchings/code_197F40/set_actor_home_position.s deleted file mode 100644 index 16a400bc3f..0000000000 --- a/asm/nonmatchings/code_197F40/set_actor_home_position.s +++ /dev/null @@ -1,23 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel set_actor_home_position -/* 198600 80269D20 27BDFFD0 */ addiu $sp, $sp, -0x30 -/* 198604 80269D24 F7B40018 */ sdc1 $f20, 0x18($sp) -/* 198608 80269D28 4485A000 */ mtc1 $a1, $f20 -/* 19860C 80269D2C F7B60020 */ sdc1 $f22, 0x20($sp) -/* 198610 80269D30 4486B000 */ mtc1 $a2, $f22 -/* 198614 80269D34 F7B80028 */ sdc1 $f24, 0x28($sp) -/* 198618 80269D38 4487C000 */ mtc1 $a3, $f24 -/* 19861C 80269D3C AFBF0010 */ sw $ra, 0x10($sp) -/* 198620 80269D40 0C09A75B */ jal get_actor -/* 198624 80269D44 00000000 */ nop -/* 198628 80269D48 E4540138 */ swc1 $f20, 0x138($v0) -/* 19862C 80269D4C E456013C */ swc1 $f22, 0x13c($v0) -/* 198630 80269D50 E4580140 */ swc1 $f24, 0x140($v0) -/* 198634 80269D54 8FBF0010 */ lw $ra, 0x10($sp) -/* 198638 80269D58 D7B80028 */ ldc1 $f24, 0x28($sp) -/* 19863C 80269D5C D7B60020 */ ldc1 $f22, 0x20($sp) -/* 198640 80269D60 D7B40018 */ ldc1 $f20, 0x18($sp) -/* 198644 80269D64 03E00008 */ jr $ra -/* 198648 80269D68 27BD0030 */ addiu $sp, $sp, 0x30 diff --git a/include/common_structs.h b/include/common_structs.h index a9ad536802..2e734b9d30 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -1305,10 +1305,10 @@ typedef struct Actor { /* 0x224 */ u8 chillOutTurns; /* 0x225 */ char unk_225[7]; /* 0x22C */ struct SelectableTarget targetData[24]; - /* 0x40C */ u8 targetListLength; + /* 0x40C */ s8 targetListLength; /* 0x40D */ u8 targetIndexList[24]; /* into targetData */ /* 0x425 */ u8 selectedTargetIndex; /* into target index list */ - /* 0x426 */ u8 targetPartIndex; + /* 0x426 */ s8 targetPartIndex; /* 0x427 */ char unk_427; /* 0x428 */ s16 targetActorID; /* 0x42A */ char unk_42A[2]; diff --git a/src/code_197F40.c b/src/code_197F40.c index 11c23b5a66..1255ed52be 100644 --- a/src/code_197F40.c +++ b/src/code_197F40.c @@ -1,6 +1,6 @@ #include "common.h" -s8 count_targets(Actor* actor, s32 targetHomeIndex, s32 targetSelectionFlags) { +s32 count_targets(Actor* actor, s32 targetHomeIndex, s32 targetSelectionFlags) { BattleStatus* battleStatus = &gBattleStatus; battleStatus->targetHomeIndex = targetHomeIndex; @@ -9,17 +9,56 @@ s8 count_targets(Actor* actor, s32 targetHomeIndex, s32 targetSelectionFlags) { return actor->targetListLength; } -INCLUDE_ASM(s32, "code_197F40", get_nearest_home_index); +s32 get_nearest_home_index(f32 x, f32 y, f32 z) { + s32 xVal; + s32 yVal; -INCLUDE_ASM(s32, "code_197F40", set_goal_pos_to_part); + xVal = 0; + if (!(y < 40.0f)) { + xVal = 1; + if (!(y < 85.0f)) { + xVal = 3; + if (y < 100.0f) { + xVal = 2; + } + } + } + + yVal = 0; + if (!(x < 25.0f)) { + yVal = 1; + if (!(x < 65.0f)) { + yVal = 3; + if (x < 105.0f) { + yVal = 2; + } + } + } + + return yVal | (xVal * 4); +} + +INCLUDE_ASM(void, "code_197F40", set_goal_pos_to_part, f32* goalPos, ActorId target, s32 partIndex); INCLUDE_ASM(s32, "code_197F40", set_part_goal_to_actor_part); -INCLUDE_ASM(s32, "code_197F40", set_actor_current_position); +void set_actor_current_position(ActorId actorID, f32 x, f32 y, f32 z) { + Actor* actor = get_actor(actorID); + + actor->currentPos.x = x; + actor->currentPos.y = y; + actor->currentPos.z = z; +} INCLUDE_ASM(s32, "code_197F40", set_part_absolute_position); -INCLUDE_ASM(s32, "code_197F40", set_actor_home_position); +void set_actor_home_position(ActorId actorID, f32 x, f32 y, f32 z) { + Actor* actor = get_actor(actorID); + + actor->homePos.x = x; + actor->homePos.y = y; + actor->homePos.z = z; +} INCLUDE_ASM(Actor*, "code_197F40", get_actor, s32 actorID); @@ -39,23 +78,150 @@ INCLUDE_ASM(s32, "code_197F40", func_80269E80); INCLUDE_ASM(s32, "code_197F40", func_80269EAC); -INCLUDE_ASM(s32, "code_197F40", SetGoalToHome); +ApiStatus SetGoalToHome(ScriptInstance* script, s32 isInitialCall) { + ActorId actorID = get_variable(script, *script->ptrReadPos); + Actor* actor; -INCLUDE_ASM(s32, "code_197F40", SetIdleGoalToHome); + if (actorID == ActorId_SELF) { + actorID = script->owner1.actorID; + } + + actor = get_actor(actorID); + actor->movePos[1].x = actor->homePos.x; + actor->movePos[1].y = actor->homePos.y; + actor->movePos[1].z = actor->homePos.z; + + return ApiStatus_DONE2; +} + +ApiStatus SetIdleGoalToHome(ScriptInstance* script, s32 isInitialCall) { + ActorId actorID = get_variable(script, *script->ptrReadPos); + Actor* actor; + + if (actorID == ActorId_SELF) { + actorID = script->owner1.actorID; + } + + actor = get_actor(actorID); + actor->flyGoalPos.x = actor->homePos.x; + actor->flyGoalPos.y = actor->homePos.y; + actor->flyGoalPos.z = actor->homePos.z; + + return ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_197F40", SetGoalToIndex); -INCLUDE_ASM(s32, "code_197F40", GetIndexFromPos); +ApiStatus GetIndexFromPos(ScriptInstance* script, s32 isInitialCall) { + Bytecode* args = script->ptrReadPos; + ActorId actorID = get_variable(script, *args++); + s32 a1 = *args++; + Actor* actor; -INCLUDE_ASM(s32, "code_197F40", GetIndexFromHome); + if (actorID == ActorId_SELF) { + actorID = script->owner1.actorID; + } -INCLUDE_ASM(s32, "code_197F40", CountPlayerTargets); + actor = get_actor(actorID); + set_variable(script, a1, get_nearest_home_index(actor->currentPos.x, actor->currentPos.y, actor->currentPos.z)); -INCLUDE_ASM(s32, "code_197F40", ForceHomePos); + return ApiStatus_DONE2; +} -INCLUDE_ASM(s32, "code_197F40", SetHomePos); +ApiStatus GetIndexFromHome(ScriptInstance* script, s32 isInitialCall) { + Bytecode* args = script->ptrReadPos; + ActorId actorID = get_variable(script, *args++); + s32 a1 = *args++; + Actor* actor; -INCLUDE_ASM(s32, "code_197F40", SetGoalToTarget); + if (actorID == ActorId_SELF) { + actorID = script->owner1.actorID; + } + + actor = get_actor(actorID); + set_variable(script, a1, get_nearest_home_index(actor->homePos.x, actor->homePos.y, actor->homePos.z)); + + return ApiStatus_DONE2; +} + +ApiStatus CountPlayerTargets(ScriptInstance* script, s32 isInitialCall) { + Bytecode* args = script->ptrReadPos; + ActorId actorID = get_variable(script, *args++); + s32 targetSelectionFlags = *args++; + s32 outVar = *args++; + Actor* actor; + + if (actorID == ActorId_SELF) { + actorID = script->owner1.actorID; + } + + actor = get_actor(actorID); + set_variable(script, outVar, count_targets(actor, get_nearest_home_index(actor->currentPos.x, actor->currentPos.y, actor->currentPos.z), targetSelectionFlags)); + + return ApiStatus_DONE2; +} + +ApiStatus ForceHomePos(ScriptInstance* script, s32 isInitialCall) { + Bytecode* args = script->ptrReadPos; + ActorId actorID = get_variable(script, *args++); + f32 x, y, z; + Actor* actor; + + if (actorID == ActorId_SELF) { + actorID = script->owner1.actorID; + } + + x = get_variable(script, *args++); + y = get_variable(script, *args++); + z = get_variable(script, *args++); + + actor = get_actor(actorID); + actor->homePos.x = x; + actor->currentPos.x = x; + actor->homePos.y = y; + actor->currentPos.y = y; + actor->homePos.z = z; + actor->currentPos.z = z; + + return ApiStatus_DONE2; +} + +ApiStatus SetHomePos(ScriptInstance* script, s32 isInitialCall) { + Bytecode* args = script->ptrReadPos; + ActorId actorID = get_variable(script, *args++); + f32 x, y, z; + Actor* actor; + + if (actorID == ActorId_SELF) { + actorID = script->owner1.actorID; + } + + x = get_variable(script, *args++); + y = get_variable(script, *args++); + z = get_variable(script, *args++); + + actor = get_actor(actorID); + actor->homePos.x = x; + actor->homePos.y = y; + actor->homePos.z = z; + + return ApiStatus_DONE2; +} + +ApiStatus SetGoalToTarget(ScriptInstance* script, s32 isInitialCall) { + Bytecode* args = script->ptrReadPos; + ActorId actorID = get_variable(script, *args++); + Actor* actor; + + if (actorID == ActorId_SELF) { + actorID = script->owner1.actorID; + } + actor = get_actor(actorID); + + set_goal_pos_to_part(&actor->movePos, actor->targetActorID, actor->targetPartIndex); + + return ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_197F40", SetPartGoalToTarget); @@ -356,7 +522,12 @@ INCLUDE_ASM(s32, "code_197F40", ChooseNextTarget); INCLUDE_ASM(s32, "code_197F40", func_8026E558); -INCLUDE_ASM(s32, "code_197F40", GetTargetListLength); +ApiStatus GetTargetListLength(ScriptInstance *script) { + Bytecode* args = script->ptrReadPos; + + set_variable(script, *args, get_actor(script->owner1.actorID)->targetListLength); + return ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_197F40", GetOwnerTarget);