From 819216b65c4e7bcae4bbb32e1a6272a1b8c9b780 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 12 Feb 2020 17:19:02 +1000 Subject: [PATCH] Decompile aiRetreat --- src/files/setup/setupame.c | 2 +- src/files/setup/setupdam.c | 2 +- src/files/setup/setupdish.c | 4 +- src/files/setup/setuppam.c | 4 +- src/files/setup/setuppete.c | 2 +- src/files/setup/setupsho.c | 2 +- src/game/chr/chraicommands.c | 85 ++++++---------------------- src/game/data/data_0083d0.c | 2 +- src/game/game_02cde0.c | 2 +- src/game/game_197600.c | 2 +- src/include/commands.h | 19 +++++-- src/include/game/chr/chraicommands.h | 2 +- src/include/game/game_02cde0.h | 4 +- 13 files changed, 45 insertions(+), 87 deletions(-) diff --git a/src/files/setup/setupame.c b/src/files/setup/setupame.c index ba1346bf7..550d10793 100644 --- a/src/files/setup/setupame.c +++ b/src/files/setup/setupame.c @@ -3781,7 +3781,7 @@ u8 func042f_surrendering_guard[] = { label(0x58) restart_timer - retreat(0x02, 0x02) + retreat(SPEED_RUN, 2) beginloop(0x0a) if_distance_to_target_gt(300, /*goto*/ 0x06) diff --git a/src/files/setup/setupdam.c b/src/files/setup/setupdam.c index 13d161c24..06082d5c2 100644 --- a/src/files/setup/setupdam.c +++ b/src/files/setup/setupdam.c @@ -1643,7 +1643,7 @@ u8 func0411_labtech_alerted[] = { goto_first(0x42) label(0x04) - retreat(0x02, 0x02) + retreat(SPEED_RUN, 2) restart_timer beginloop(0x14) diff --git a/src/files/setup/setupdish.c b/src/files/setup/setupdish.c index be9689922..4bf571848 100644 --- a/src/files/setup/setupdish.c +++ b/src/files/setup/setupdish.c @@ -4481,7 +4481,7 @@ u8 func0404_holo4_guard2[] = { label(0x2f) restart_timer - retreat(0x02, 0x01) + retreat(SPEED_RUN, 1) beginloop(0x09) if_timer_gt(60, /*goto*/ 0x06) @@ -4741,7 +4741,7 @@ u8 func0407_holo5_guard1[] = { label(0x2f) restart_timer - retreat(0x02, 0x01) + retreat(SPEED_RUN, 1) beginloop(0x09) if_timer_gt(60, /*goto*/ 0x06) diff --git a/src/files/setup/setuppam.c b/src/files/setup/setuppam.c index 84fbcca60..e59860cb1 100644 --- a/src/files/setup/setuppam.c +++ b/src/files/setup/setuppam.c @@ -1146,7 +1146,7 @@ u8 func0405_elvis_follow_nocombat[] = { label(0x08) restart_timer say_quip(CHR_BOND, 0x29, 0xff, 0x14, 0xff, BANK_1, 0x00, 0x00) - retreat(0x02, 0x01) + retreat(SPEED_RUN, 1) beginloop(0x09) if_timer_gt(120, /*goto*/ 0x2e) @@ -3488,7 +3488,7 @@ u8 func040f_miniskedar[] = { label(0x2e) label(0x2f) - retreat(0x02, 0x01) + retreat(SPEED_RUN, 1) beginloop(0x0c) if_timer_gt(120, /*goto*/ 0x06) diff --git a/src/files/setup/setuppete.c b/src/files/setup/setuppete.c index b9e6f1e98..5d9ba85d8 100644 --- a/src/files/setup/setuppete.c +++ b/src/files/setup/setuppete.c @@ -1675,7 +1675,7 @@ u8 func0413_bugspotter[] = { // No other guard to run to label(0x0b) - retreat(0x02, 0x02) + retreat(SPEED_RUN, 2) beginloop(0x07) if_stage_flag_eq(STAGEFLAG_LIMO_READY_TO_LEAVE, TRUE, /*goto*/ LABEL_RUN_AWAY) diff --git a/src/files/setup/setupsho.c b/src/files/setup/setupsho.c index 331d24820..f516b2c0d 100644 --- a/src/files/setup/setupsho.c +++ b/src/files/setup/setupsho.c @@ -829,7 +829,7 @@ u8 func0404_miniskedar[] = { label(0x2d) label(0x2e) - retreat(0x02, 0x01) + retreat(SPEED_RUN, 1) beginloop(0x0d) if_timer_gt(120, /*goto*/ 0x06) diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index 2d46966bc..34be6a25f 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -143,7 +143,6 @@ const u32 var7f1a9d80[] = {0x7f05b0bc}; const u32 var7f1a9d84[] = {0x7f05b100}; const u32 var7f1a9d88[] = {0x7f05b140}; const u32 var7f1a9d8c[] = {0x7f05b184}; -const u32 var7f1a9d90[] = {0x461c4000}; /** * @cmd 0000 @@ -9787,72 +9786,24 @@ bool aiIfHasOrders(void) /** * @cmd 0136 */ -GLOBAL_ASM( -glabel ai0136 -/* f05b2f8: 27bdffd8 */ addiu $sp,$sp,-40 -/* f05b2fc: afb00018 */ sw $s0,0x18($sp) -/* f05b300: 3c10800a */ lui $s0,%hi(g_Vars) -/* f05b304: 26109fc0 */ addiu $s0,$s0,%lo(g_Vars) -/* f05b308: 8e0e0434 */ lw $t6,0x434($s0) -/* f05b30c: 8e0f0438 */ lw $t7,0x438($s0) -/* f05b310: afbf001c */ sw $ra,0x1c($sp) -/* f05b314: 24010001 */ addiu $at,$zero,0x1 -/* f05b318: 01cf1821 */ addu $v1,$t6,$t7 -/* f05b31c: 90620003 */ lbu $v0,0x3($v1) -/* f05b320: 14400011 */ bnez $v0,.L0f05b368 -/* f05b324: 00000000 */ sll $zero,$zero,0x0 -/* f05b328: 90650002 */ lbu $a1,0x2($v1) -/* f05b32c: 3c017f1b */ lui $at,%hi(var7f1a9d90) -/* f05b330: 30b80010 */ andi $t8,$a1,0x10 -/* f05b334: 13000005 */ beqz $t8,.L0f05b34c -/* f05b338: 00000000 */ sll $zero,$zero,0x0 -/* f05b33c: 3c0143c8 */ lui $at,0x43c8 -/* f05b340: 44810000 */ mtc1 $at,$f0 -/* f05b344: 10000003 */ beqz $zero,.L0f05b354 -/* f05b348: 8e040424 */ lw $a0,0x424($s0) -.L0f05b34c: -/* f05b34c: c4209d90 */ lwc1 $f0,%lo(var7f1a9d90)($at) -/* f05b350: 8e040424 */ lw $a0,0x424($s0) -.L0f05b354: -/* f05b354: 44060000 */ mfc1 $a2,$f0 -/* f05b358: 0fc130ba */ jal func0f04c2e8 -/* f05b35c: 248702c8 */ addiu $a3,$a0,0x2c8 -/* f05b360: 10000018 */ beqz $zero,.L0f05b3c4 -/* f05b364: 8e190438 */ lw $t9,0x438($s0) -.L0f05b368: -/* f05b368: 1441000d */ bne $v0,$at,.L0f05b3a0 -/* f05b36c: 2405090a */ addiu $a1,$zero,0x90a -/* f05b370: 8e040424 */ lw $a0,0x424($s0) -/* f05b374: 0fc0a221 */ jal chrGetTargetProp -/* f05b378: afa30024 */ sw $v1,0x24($sp) -/* f05b37c: 8fa30024 */ lw $v1,0x24($sp) -/* f05b380: 3c06461c */ lui $a2,0x461c -/* f05b384: 34c64000 */ ori $a2,$a2,0x4000 -/* f05b388: 8e040424 */ lw $a0,0x424($s0) -/* f05b38c: 24470008 */ addiu $a3,$v0,0x8 -/* f05b390: 0fc130ba */ jal func0f04c2e8 -/* f05b394: 90650002 */ lbu $a1,0x2($v1) -/* f05b398: 1000000a */ beqz $zero,.L0f05b3c4 -/* f05b39c: 8e190438 */ lw $t9,0x438($s0) -.L0f05b3a0: -/* f05b3a0: 8e040424 */ lw $a0,0x424($s0) -/* f05b3a4: 00003025 */ or $a2,$zero,$zero -/* f05b3a8: 0fc12e8d */ jal func0f04ba34 -/* f05b3ac: afa30024 */ sw $v1,0x24($sp) -/* f05b3b0: 8fa30024 */ lw $v1,0x24($sp) -/* f05b3b4: 8e040424 */ lw $a0,0x424($s0) -/* f05b3b8: 0fc1309a */ jal chrGoToCover -/* f05b3bc: 90650002 */ lbu $a1,0x2($v1) -/* f05b3c0: 8e190438 */ lw $t9,0x438($s0) -.L0f05b3c4: -/* f05b3c4: 8fbf001c */ lw $ra,0x1c($sp) -/* f05b3c8: 00001025 */ or $v0,$zero,$zero -/* f05b3cc: 27280004 */ addiu $t0,$t9,0x4 -/* f05b3d0: ae080438 */ sw $t0,0x438($s0) -/* f05b3d4: 8fb00018 */ lw $s0,0x18($sp) -/* f05b3d8: 03e00008 */ jr $ra -/* f05b3dc: 27bd0028 */ addiu $sp,$sp,0x28 -); +bool aiRetreat(void) +{ + u8 *cmd = g_Vars.ailist + g_Vars.aioffset; + + if (cmd[3] == 0) { + chrRunFromPos(g_Vars.chrdata, cmd[2], (cmd[2] & 0x10) ? 400.0f : 10000.0f, &g_Vars.chrdata->runfrompos); + } else if (cmd[3] == 1) { + struct prop *target = chrGetTargetProp(g_Vars.chrdata); + chrRunFromPos(g_Vars.chrdata, cmd[2], 10000, &target->pos); + } else { + func0f04ba34(g_Vars.chrdata, 2314, 0); + chrGoToCover(g_Vars.chrdata, cmd[2]); + } + + g_Vars.aioffset += 4; + + return false; +} /** * @cmd 0137 diff --git a/src/game/data/data_0083d0.c b/src/game/data/data_0083d0.c index 178f9b5f9..b610e0cfe 100644 --- a/src/game/data/data_0083d0.c +++ b/src/game/data/data_0083d0.c @@ -6529,7 +6529,7 @@ bool (*g_CommandPointers[])(void) = { /*0x0133*/ ai0133, /*0x0134*/ aiIfOrders, /*0x0135*/ aiIfHasOrders, - /*0x0136*/ ai0136, + /*0x0136*/ aiRetreat, /*0x0137*/ aiIfChrInSquadronDoingAction, /*0x0138*/ aiIfChannelIdle, /*0x0139*/ ai0139, diff --git a/src/game/game_02cde0.c b/src/game/game_02cde0.c index d9d292d87..dbcd239a5 100644 --- a/src/game/game_02cde0.c +++ b/src/game/game_02cde0.c @@ -34285,7 +34285,7 @@ s16 chrGoToCover(struct chrdata *chr, u8 speed) } GLOBAL_ASM( -glabel func0f04c2e8 +glabel chrRunFromPos /* f04c2e8: 27bdffb0 */ addiu $sp,$sp,-80 /* f04c2ec: afbf0024 */ sw $ra,0x24($sp) /* f04c2f0: afb00020 */ sw $s0,0x20($sp) diff --git a/src/game/game_197600.c b/src/game/game_197600.c index ecebd858b..6ea2d406f 100644 --- a/src/game/game_197600.c +++ b/src/game/game_197600.c @@ -394,7 +394,7 @@ glabel func0f197600 /* f197a84: 34c64000 */ ori $a2,$a2,0x4000 /* f197a88: 24050002 */ addiu $a1,$zero,0x2 /* f197a8c: 8fa7001c */ lw $a3,0x1c($sp) -/* f197a90: 0fc130ba */ jal func0f04c2e8 +/* f197a90: 0fc130ba */ jal chrRunFromPos /* f197a94: afa80054 */ sw $t0,0x54($sp) /* f197a98: 10000010 */ beqz $zero,.L0f197adc /* f197a9c: 8fa80054 */ lw $t0,0x54($sp) diff --git a/src/include/commands.h b/src/include/commands.h index bdfe24bc9..3ac0d573d 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -2641,13 +2641,20 @@ mkshort(0x0135), \ label, -// u1 can theoretically be any value but in practice is only ever 2. -// u2 can be either 0, 1 or 2 and determines what the command does, -// but in practice is only ever 1 or 2. -#define retreat(u1, u2) \ +/** + * If operation is 0, looks like the chr runs from their runfrompos property. + * The distance they run is controlled by bit 0x10 in speed. If set then the run + * distance will be 400 units. If unset it will be 10,000. + * + * If operation is 1, the chr tries to run 10,000 units away from their target. + * + * If operation is anything else, looks like it tries to find a cover point + * within 2314 units then runs to it. + */ +#define retreat(speed, operation) \ mkshort(0x0136), \ - u1, \ - u2, + speed, \ + operation, #define if_chr_in_squadron_doing_action(action, label) \ mkshort(0x0137), \ diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index 977327d5f..ff28c389a 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -308,7 +308,7 @@ /*0x0133*/ bool ai0133(void); /*0x0134*/ bool aiIfOrders(void); /*0x0135*/ bool aiIfHasOrders(void); -/*0x0136*/ bool ai0136(void); +/*0x0136*/ bool aiRetreat(void); /*0x0137*/ bool aiIfChrInSquadronDoingAction(void); /*0x0138*/ bool aiIfChannelIdle(void); /*0x0139*/ bool ai0139(void); diff --git a/src/include/game/game_02cde0.h b/src/include/game/game_02cde0.h index d80f87474..3863f6bfd 100644 --- a/src/include/game/game_02cde0.h +++ b/src/include/game/game_02cde0.h @@ -206,9 +206,9 @@ bool chrSpawnAtCoord(s32 body, s32 head, struct coord *pos, s16 *room, f32 arg4, u32 func0f04b658(struct chrdata *chr); bool chrMoveToPos(struct chrdata *chr, struct coord *pos, s16 *room, f32 arg3, u32 allowonscreen); u32 func0f04b950(struct chrdata *chr, u32 cover, u32 arg2); -u32 func0f04ba34(struct chrdata *chr, u16 arg1, u32 arg2); +s32 func0f04ba34(struct chrdata *chr, u16 arg1, u32 arg2); u32 func0f04bffc(struct chrdata *chr, u32 arg1, u32 arg2); -u32 func0f04c2e8(void); +void chrRunFromPos(struct chrdata *chr, u32 speed, f32 distance, struct coord *pos); u32 func0f04c784(void); void func0f04c874(struct chrdata *chr, u32 flags, struct coord *pos, s32 arg3, s32 arg4); u32 rebuildTeams(void);