From f643cd5fe3d17c33c48011a103abfc26e51529d8 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 22 Dec 2019 16:45:33 +1000 Subject: [PATCH] Decompile chrSawTargetRecently and chrHeardTargetRecently --- src/files/setup/setuplue.c | 4 +- src/game/chr/chr.c | 56 +++++++++------------------- src/game/chr/chraicommands.c | 10 ++--- src/include/commands.h | 12 +++++- src/include/game/chr/chr.h | 4 +- src/include/game/chr/chraicommands.h | 4 +- src/include/gvars/gvars.h | 2 +- src/include/types.h | 4 +- src/setup/ailists.c | 4 +- src/setup/setup_000000.c | 4 +- 10 files changed, 47 insertions(+), 57 deletions(-) diff --git a/src/files/setup/setuplue.c b/src/files/setup/setuplue.c index 0ceb926e1..5f21ca266 100644 --- a/src/files/setup/setuplue.c +++ b/src/files/setup/setuplue.c @@ -1618,7 +1618,7 @@ u8 func0416_mechanic[] = { beginloop(0x0d) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_shot_at_close_range(/*goto*/ 0x2e) + if_heard_target_recently(/*goto*/ 0x2e) if_target_chr_in_sight(/*goto*/ 0x2e) if_chr_stopped(/*goto*/ 0x06) endloop(0x0d) @@ -2888,7 +2888,7 @@ u8 func0421_activate_autogun[] = { chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) if_target_chr_in_sight(/*goto*/ 0x2e) - if_shot_at_close_range(/*goto*/ 0x2e) + if_heard_target_recently(/*goto*/ 0x2e) if_alertness(99, OPERATOR_GREATER_THAN, /*goto*/ 0x2e) endloop(0x04) diff --git a/src/game/chr/chr.c b/src/game/chr/chr.c index e018e1311..21ae8fd14 100644 --- a/src/game/chr/chr.c +++ b/src/game/chr/chr.c @@ -31614,13 +31614,13 @@ glabel func0f039558 void chrSaveLastSeeTarget(struct chrdata *chr) { - chr->lastseetarget60 = g_Vars.unk000008; + chr->lastseetarget60 = g_Vars.tickcount; } void chrSaveLastHearTarget(struct chrdata *chr) { chr->hidden |= CHRHFLAG_00000002; - chr->lastheartarget60 = g_Vars.unk000008; + chr->lastheartarget60 = g_Vars.tickcount; } GLOBAL_ASM( @@ -48648,43 +48648,23 @@ glabel func0f048398 /* f048a10: 27bd00e8 */ addiu $sp,$sp,0xe8 ); -GLOBAL_ASM( -glabel func0f048a14 -/* f048a14: 8c8200e0 */ lw $v0,0xe0($a0) -/* f048a18: 3c0e800a */ lui $t6,0x800a -/* f048a1c: 58400009 */ blezl $v0,.L0f048a44 -/* f048a20: 00001025 */ or $v0,$zero,$zero -/* f048a24: 8dce9fc8 */ lw $t6,-0x6038($t6) -/* f048a28: 01c27823 */ subu $t7,$t6,$v0 -/* f048a2c: 29e10258 */ slti $at,$t7,0x258 -/* f048a30: 50200004 */ beqzl $at,.L0f048a44 -/* f048a34: 00001025 */ or $v0,$zero,$zero -/* f048a38: 03e00008 */ jr $ra -/* f048a3c: 24020001 */ addiu $v0,$zero,0x1 -/* f048a40: 00001025 */ or $v0,$zero,$zero -.L0f048a44: -/* f048a44: 03e00008 */ jr $ra -/* f048a48: 00000000 */ sll $zero,$zero,0x0 -); +bool chrSawTargetRecently(struct chrdata *chr) +{ + if (chr->lastseetarget60 > 0 && g_Vars.tickcount - chr->lastseetarget60 < 600) { + return true; + } -GLOBAL_ASM( -glabel func0f048a4c -/* f048a4c: 8c8200f4 */ lw $v0,0xf4($a0) -/* f048a50: 3c0e800a */ lui $t6,0x800a -/* f048a54: 58400009 */ blezl $v0,.L0f048a7c -/* f048a58: 00001025 */ or $v0,$zero,$zero -/* f048a5c: 8dce9fc8 */ lw $t6,-0x6038($t6) -/* f048a60: 01c27823 */ subu $t7,$t6,$v0 -/* f048a64: 29e10258 */ slti $at,$t7,0x258 -/* f048a68: 50200004 */ beqzl $at,.L0f048a7c -/* f048a6c: 00001025 */ or $v0,$zero,$zero -/* f048a70: 03e00008 */ jr $ra -/* f048a74: 24020001 */ addiu $v0,$zero,0x1 -/* f048a78: 00001025 */ or $v0,$zero,$zero -.L0f048a7c: -/* f048a7c: 03e00008 */ jr $ra -/* f048a80: 00000000 */ sll $zero,$zero,0x0 -); + return false; +} + +bool chrHeardTargetRecently(struct chrdata *chr) +{ + if (chr->lastheartarget60 > 0 && g_Vars.tickcount - chr->lastheartarget60 < 600) { + return true; + } + + return false; +} GLOBAL_ASM( glabel func0f048a84 diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index ca19f78a7..d85f6f140 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -1741,9 +1741,9 @@ bool aiIfInLoadedRoom(void) /** * @cmd 0043 */ -bool ai0043(void) +bool aiIfSawTargetRecently(void) { - if (func0f048a14(g_Vars.chrdata)) { + if (chrSawTargetRecently(g_Vars.chrdata)) { u8 *cmd = g_Vars.ailist + g_Vars.aioffset; g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[2]); } else { @@ -1756,9 +1756,9 @@ bool ai0043(void) /** * @cmd 0044 */ -bool aiIfShotAtCloseRange(void) +bool aiIfHeardTargetRecently(void) { - if (func0f048a4c(g_Vars.chrdata)) { + if (chrHeardTargetRecently(g_Vars.chrdata)) { u8 *cmd = g_Vars.ailist + g_Vars.aioffset; g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[2]); } else { @@ -7746,7 +7746,7 @@ bool aiSetDoorClosed(void) struct doorobj *door = (struct doorobj *) obj; door->speed = door->unk5c; door->unk80 = 0; - door->unkc0 = g_Vars.unk000008; + door->unkc0 = g_Vars.tickcount; door->state = 0; func0f08c54c(door); func0f08d4e8(door); diff --git a/src/include/commands.h b/src/include/commands.h index 5453bac06..9f117da8a 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -279,7 +279,17 @@ mkword(value), \ label, -#define if_shot_at_close_range(label) \ +/** + * Go to the label if the chr saw their target within the last 10 seconds. + */ +#define if_saw_target_recently(label) \ + mkshort(0x0043), \ + label, + +/** + * Go to the label if the chr heard their target within the last 10 seconds. + */ +#define if_heard_target_recently(label) \ mkshort(0x0044), \ label, diff --git a/src/include/game/chr/chr.h b/src/include/game/chr/chr.h index 24b67d7a6..6c0ac2ad9 100644 --- a/src/include/game/chr/chr.h +++ b/src/include/game/chr/chr.h @@ -349,8 +349,8 @@ u32 func0f047934(void); u32 func0f047c80(void); u32 func0f0482cc(void); u32 func0f048398(void); -u32 func0f048a14(struct chrdata *chr); -u32 func0f048a4c(struct chrdata *chr); +bool chrSawTargetRecently(struct chrdata *chr); +bool chrHeardTargetRecently(struct chrdata *chr); float func0f048a84(struct chrdata *chr, struct coord *coord); float chrGetAngleToTarget(struct chrdata *chr); u32 func0f048b78(void); diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index 610e9fca4..f83202b5a 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -70,8 +70,8 @@ /*0x0040*/ bool ai0040(void); /*0x0041*/ bool ai0041(void); /*0x0042*/ bool aiIfInLoadedRoom(void); -/*0x0043*/ bool ai0043(void); -/*0x0044*/ bool aiIfShotAtCloseRange(void); +/*0x0043*/ bool aiIfSawTargetRecently(void); +/*0x0044*/ bool aiIfHeardTargetRecently(void); /*0x0045*/ bool ai0045(void); /*0x0046*/ bool aiIfNeverBeenOnScreen(void); /*0x0047*/ bool ai0047(void); diff --git a/src/include/gvars/gvars.h b/src/include/gvars/gvars.h index 9c29c81e5..4f381e4a6 100644 --- a/src/include/gvars/gvars.h +++ b/src/include/gvars/gvars.h @@ -19,7 +19,7 @@ struct g_vars { /*000000*/ u32 unk000000; /*000004*/ u32 unk000004; - /*000008*/ u32 unk000008; + /*000008*/ s32 tickcount; /*00000c*/ u32 unk00000c; /*000010*/ u32 unk000010; /*000014*/ u32 unk000014; diff --git a/src/include/types.h b/src/include/types.h index e3333753f..b17b75837 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -154,13 +154,13 @@ struct chrdata { /*0x0d4*/ u32 lastwalk60; /*0x0d8*/ u32 lastmoveok60; /*0x0dc*/ float visionrange; - /*0x0e0*/ u32 lastseetarget60; + /*0x0e0*/ s32 lastseetarget60; /*0x0e4*/ u32 lastvisibletarg; /*0x0e8*/ void *unk0e8; /*0x0ec*/ u16 lastshooter; /*0x0ee*/ u16 timeshooter; /*0x0f0*/ float hearingscale; - /*0x0f4*/ u32 lastheartarget60; + /*0x0f4*/ s32 lastheartarget60; /*0x0f8*/ u32 shadecol; /*0x0fc*/ u32 nextcol; /*0x100*/ float damage; diff --git a/src/setup/ailists.c b/src/setup/ailists.c index 284f3eef7..5ee185876 100644 --- a/src/setup/ailists.c +++ b/src/setup/ailists.c @@ -188,7 +188,7 @@ u8 func0006_unalerted[] = { label(0x16) dprint 'C','H','E','K','H','E','A','R','\n',0, - if_shot_at_close_range(/*goto*/ LABEL_HEAR_DETECT) + if_heard_target_recently(/*goto*/ LABEL_HEAR_DETECT) label(0x13) dprint 'N','O','T','H','E','A','R','D','\n',0, @@ -4497,7 +4497,7 @@ u8 func001f_related_to_spawning[] = { goto_next(0x13) label(0x16) - if_shot_at_close_range(/*goto*/ 0x1f) + if_heard_target_recently(/*goto*/ 0x1f) label(0x13) if_self_flag_bankx_eq(CHRFLAG0_CAN_HEAR_ALARMS, FALSE, BANK_0, /*goto*/ 0x16) if_alarm_active(/*goto*/ 0x23) diff --git a/src/setup/setup_000000.c b/src/setup/setup_000000.c index d0dd3e7b8..f59b160a7 100644 --- a/src/setup/setup_000000.c +++ b/src/setup/setup_000000.c @@ -14199,8 +14199,8 @@ bool (*g_CommandPointers[])(void) = { /*0x0040*/ ai0040, /*0x0041*/ ai0041, /*0x0042*/ aiIfInLoadedRoom, - /*0x0043*/ ai0043, - /*0x0044*/ aiIfShotAtCloseRange, + /*0x0043*/ aiIfSawTargetRecently, + /*0x0044*/ aiIfHeardTargetRecently, /*0x0045*/ ai0045, /*0x0046*/ aiIfNeverBeenOnScreen, /*0x0047*/ ai0047,