From aa43b4b57ff353f19e8bfbc3f54d233daed7ea2d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 30 Nov 2019 21:58:42 +1000 Subject: [PATCH] Decompile aiSetPadPresetToInvestigationTerminal --- src/files/setup/setupear.c | 12 ++--- src/game/chr/chraicommands.c | 65 +++++++++------------------- src/include/commands.h | 11 ++++- src/include/game/chr/chraicommands.h | 2 +- src/include/setup/setup_000000.h | 2 +- src/setup/setup_000000.c | 51 +++++++++++++--------- 6 files changed, 68 insertions(+), 75 deletions(-) diff --git a/src/files/setup/setupear.c b/src/files/setup/setupear.c index 36fd1de1e..88d42ba45 100644 --- a/src/files/setup/setupear.c +++ b/src/files/setup/setupear.c @@ -1055,15 +1055,15 @@ u8 func0404_scientist[] = { label(0x06) if_self_flag_bankx_eq(CHRFLAG0_00002000, TRUE, BANK_0, /*goto*/ 0x06) if_self_flag_bankx_eq(CHRFLAG0_00004000, TRUE, BANK_0, /*goto*/ 0x2f) - jog_to_object(OBJ_GOODTERM3) + set_pad_preset_to_investigation_terminal(OBJ_GOODTERM3) goto_next(0x12) label(0x06) - jog_to_object(OBJ_GOODTERM1) + set_pad_preset_to_investigation_terminal(OBJ_GOODTERM1) goto_next(0x12) label(0x2f) - jog_to_object(OBJ_GOODTERM2) + set_pad_preset_to_investigation_terminal(OBJ_GOODTERM2) label(0x12) go_to_target_pad(SPEED_JOG) @@ -1176,15 +1176,15 @@ u8 func0406_nasty_scientist[] = { label(0x06) if_self_flag_bankx_eq(CHRFLAG0_00002000, TRUE, BANK_0, /*goto*/ 0x06) if_self_flag_bankx_eq(CHRFLAG0_00004000, TRUE, BANK_0, /*goto*/ 0x2f) - jog_to_object(OBJ_ALARMTERM3) + set_pad_preset_to_investigation_terminal(OBJ_ALARMTERM3) goto_next(0x12) label(0x06) - jog_to_object(OBJ_ALARMTERM1) + set_pad_preset_to_investigation_terminal(OBJ_ALARMTERM1) goto_next(0x12) label(0x2f) - jog_to_object(OBJ_ALARMTERM2) + set_pad_preset_to_investigation_terminal(OBJ_ALARMTERM2) label(0x12) if_num_times_shot_lt(1, /*goto*/ 0x13) go_to_target_pad(SPEED_JOG) diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index 3ededddf1..e0c4b4cff 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -11571,51 +11571,26 @@ glabel aiShuffleInvestigationTerminals /** * @cmd 0142 */ -GLOBAL_ASM( -glabel ai0142 -/* f05bd0c: 27bdffd8 */ addiu $sp,$sp,-40 -/* f05bd10: afb30020 */ sw $s3,0x20($sp) -/* f05bd14: 3c13800a */ lui $s3,%hi(g_Vars) -/* f05bd18: 26739fc0 */ addiu $s3,$s3,%lo(g_Vars) -/* f05bd1c: 8e6e0434 */ lw $t6,0x434($s3) -/* f05bd20: 8e6f0438 */ lw $t7,0x438($s3) -/* f05bd24: afbf0024 */ sw $ra,0x24($sp) -/* f05bd28: afb2001c */ sw $s2,0x1c($sp) -/* f05bd2c: afb10018 */ sw $s1,0x18($sp) -/* f05bd30: afb00014 */ sw $s0,0x14($sp) -/* f05bd34: 01cf1021 */ addu $v0,$t6,$t7 -/* f05bd38: 0fc2556c */ jal objFindByTagId -/* f05bd3c: 90440002 */ lbu $a0,0x2($v0) -/* f05bd40: 1040000e */ beqz $v0,.L0f05bd7c -/* f05bd44: 3c108007 */ lui $s0,%hi(var80069730) -/* f05bd48: 3c128007 */ lui $s2,%hi(var80069780) -/* f05bd4c: 84510006 */ lh $s1,0x6($v0) -/* f05bd50: 26529780 */ addiu $s2,$s2,%lo(var80069780) -/* f05bd54: 26109730 */ addiu $s0,$s0,%lo(var80069730) -/* f05bd58: 96180000 */ lhu $t8,0x0($s0) -.L0f05bd5c: -/* f05bd5c: 56380005 */ bnel $s1,$t8,.L0f05bd74 -/* f05bd60: 26100004 */ addiu $s0,$s0,0x4 -/* f05bd64: 8e640424 */ lw $a0,0x424($s3) -/* f05bd68: 0fc12b28 */ jal chrSetPadPreset -/* f05bd6c: 96050002 */ lhu $a1,0x2($s0) -/* f05bd70: 26100004 */ addiu $s0,$s0,0x4 -.L0f05bd74: -/* f05bd74: 5612fff9 */ bnel $s0,$s2,.L0f05bd5c -/* f05bd78: 96180000 */ lhu $t8,0x0($s0) -.L0f05bd7c: -/* f05bd7c: 8e790438 */ lw $t9,0x438($s3) -/* f05bd80: 8fbf0024 */ lw $ra,0x24($sp) -/* f05bd84: 8fb00014 */ lw $s0,0x14($sp) -/* f05bd88: 27280004 */ addiu $t0,$t9,0x4 -/* f05bd8c: ae680438 */ sw $t0,0x438($s3) -/* f05bd90: 8fb30020 */ lw $s3,0x20($sp) -/* f05bd94: 8fb10018 */ lw $s1,0x18($sp) -/* f05bd98: 8fb2001c */ lw $s2,0x1c($sp) -/* f05bd9c: 27bd0028 */ addiu $sp,$sp,0x28 -/* f05bda0: 03e00008 */ jr $ra -/* f05bda4: 00001025 */ or $v0,$zero,$zero -); +bool aiSetPadPresetToInvestigationTerminal(void) +{ + u8 *cmd = g_Vars.ailist + g_Vars.aioffset; + struct defaultobj *obj = objFindByTagId(cmd[2]); + + if (obj) { + s16 objpad = obj->pad; + s32 i; + + for (i = 0; i < sizeof(g_InvestigationPadMap) / sizeof(g_InvestigationPadMap[0]); i += 2) { + if (objpad == g_InvestigationPadMap[i]) { + chrSetPadPreset(g_Vars.chrdata, g_InvestigationPadMap[i + 1]); + } + } + } + + g_Vars.aioffset += 4; + + return false; +} /** * @cmd 0143 diff --git a/src/include/commands.h b/src/include/commands.h index e0efc8835..f0d9b91a7 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -1364,7 +1364,16 @@ src4, \ 0x00, -#define jog_to_object(object) \ +/** + * Takes the given object, looks at the pad ID that the object is sitting on, + * then uses a lookup table at g_InvestigationPadMap to decide which pad to set + * as the current chr's pad preset. + * + * It's only used for investigation scientists to run to a spot in front of the + * terminal. Due to the fact that this lookup table is hard coded in a global + * location, it's recommended to keep usage of this function to one stage only. + */ +#define set_pad_preset_to_investigation_terminal(object) \ mkshort(0x0142), \ object, \ 0x00, diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index e0408bd6b..504e8cdd2 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -320,7 +320,7 @@ /*0x013f*/ bool ai013f(void); /*0x0140*/ bool ai0140(void); /*0x0141*/ bool aiShuffleInvestigationTerminals(void); -/*0x0142*/ bool ai0142(void); +/*0x0142*/ bool aiSetPadPresetToInvestigationTerminal(void); /*0x0143*/ bool ai0143(void); /*0x0144*/ bool ai0144(void); /*0x0145*/ bool aiRebuildTeams(void); diff --git a/src/include/setup/setup_000000.h b/src/include/setup/setup_000000.h index 867e70e80..008ddd536 100644 --- a/src/include/setup/setup_000000.h +++ b/src/include/setup/setup_000000.h @@ -418,7 +418,7 @@ extern s16 ciquiptable_bank0[]; extern s16 ciquiptable_bank1[]; extern s16 ciquiptable_bank2[]; extern s16 ciquiptable_bank3[]; -extern u32 var80069730; +extern u16 g_InvestigationPadMap[40]; extern u32 var80069780; extern u32 var8006978c; extern u16 special_animations[]; diff --git a/src/setup/setup_000000.c b/src/setup/setup_000000.c index f508dfb77..071a514b6 100644 --- a/src/setup/setup_000000.c +++ b/src/setup/setup_000000.c @@ -14454,7 +14454,7 @@ bool (*g_CommandPointers[])(void) = { /*0x013f*/ ai013f, /*0x0140*/ ai0140, /*0x0141*/ aiShuffleInvestigationTerminals, - /*0x0142*/ ai0142, + /*0x0142*/ aiSetPadPresetToInvestigationTerminal, /*0x0143*/ ai0143, /*0x0144*/ ai0144, /*0x0145*/ aiRebuildTeams, @@ -15015,26 +15015,35 @@ u16 quiptable_maian[] = { 0x0000, 0x0000, 0x0000, 0x0000, }; -u32 var80069730 = 0x0246007b; -u32 var80069734 = 0x0247007d; -u32 var80069738 = 0x0248007e; -u32 var8006973c = 0x0249007c; -u32 var80069740 = 0x024a0093; -u32 var80069744 = 0x024b0091; -u32 var80069748 = 0x024c0092; -u32 var8006974c = 0x024d0093; -u32 var80069750 = 0x024e00ae; -u32 var80069754 = 0x024f00ac; -u32 var80069758 = 0x025000ab; -u32 var8006975c = 0x025100ad; -u32 var80069760 = 0x025200a1; -u32 var80069764 = 0x0253009f; -u32 var80069768 = 0x025400a0; -u32 var8006976c = 0x0255009e; -u32 var80069770 = 0x025600bb; -u32 var80069774 = 0x025700b8; -u32 var80069778 = 0x025800b9; -u32 var8006977c = 0x025900ba; +/** + * Used by AI command 0142, which makes Investigation scientists run to the + * computer terminals. The number of the left is the pad that the terminal sits + * on, and the number on the right is the pad that the scientist will run to + * when running to the terminal. + */ +u16 g_InvestigationPadMap[40] = { + 0x0246, 0x007b, + 0x0247, 0x007d, + 0x0248, 0x007e, + 0x0249, 0x007c, + 0x024a, 0x0093, + 0x024b, 0x0091, + 0x024c, 0x0092, + 0x024d, 0x0093, + 0x024e, 0x00ae, + 0x024f, 0x00ac, + 0x0250, 0x00ab, + 0x0251, 0x00ad, + 0x0252, 0x00a1, + 0x0253, 0x009f, + 0x0254, 0x00a0, + 0x0255, 0x009e, + 0x0256, 0x00bb, + 0x0257, 0x00b8, + 0x0258, 0x00b9, + 0x0259, 0x00ba, +}; + u32 var80069780 = 0x00000000; u32 var80069784 = 0x00000000; u32 var80069788 = 0x00000000;