From b6a756b89d163e4d1cfaec56a23eb34b15264b9d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 26 Nov 2019 23:46:02 +1000 Subject: [PATCH] Decompile aiIfGunUnclaimed --- src/game/chr/chraicommands.c | 88 ++++++++-------------------- src/include/commands.h | 3 +- src/include/game/chr/chraicommands.h | 2 +- src/include/types.h | 2 +- src/setup/setup_000000.c | 2 +- 5 files changed, 30 insertions(+), 67 deletions(-) diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index 22d9245de..10e83538f 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -3116,67 +3116,31 @@ bool aiIfChrHasWeaponEquipped(void) /** * @cmd 0061 */ -GLOBAL_ASM( -glabel ai0061 -/* f051828: 27bdffd8 */ addiu $sp,$sp,-40 -/* f05182c: afb00018 */ sw $s0,0x18($sp) -/* f051830: 3c10800a */ lui $s0,%hi(g_Vars) -/* f051834: 26109fc0 */ addiu $s0,$s0,%lo(g_Vars) -/* f051838: 8e040438 */ lw $a0,0x438($s0) -/* f05183c: 8e0e0434 */ lw $t6,0x434($s0) -/* f051840: afbf001c */ sw $ra,0x1c($sp) -/* f051844: 01c41821 */ addu $v1,$t6,$a0 -/* f051848: 906f0003 */ lbu $t7,0x3($v1) -/* f05184c: 55e00014 */ bnezl $t7,.L0f0518a0 -/* f051850: 8e090424 */ lw $t1,0x424($s0) -/* f051854: 90640002 */ lbu $a0,0x2($v1) -/* f051858: 0fc2556c */ jal objFindByTagId -/* f05185c: afa30024 */ sw $v1,0x24($sp) -/* f051860: 1040000a */ beqz $v0,.L0f05188c -/* f051864: 8fa30024 */ lw $v1,0x24($sp) -/* f051868: 8c580014 */ lw $t8,0x14($v0) -/* f05186c: 53000008 */ beqzl $t8,.L0f051890 -/* f051870: 8e190438 */ lw $t9,0x438($s0) -/* f051874: 8e040434 */ lw $a0,0x434($s0) -/* f051878: 8e050438 */ lw $a1,0x438($s0) -/* f05187c: 0fc13583 */ jal chraiGoToLabel -/* f051880: 90660004 */ lbu $a2,0x4($v1) -/* f051884: 10000019 */ beqz $zero,.L0f0518ec -/* f051888: ae020438 */ sw $v0,0x438($s0) -.L0f05188c: -/* f05188c: 8e190438 */ lw $t9,0x438($s0) -.L0f051890: -/* f051890: 27280005 */ addiu $t0,$t9,0x5 -/* f051894: 10000015 */ beqz $zero,.L0f0518ec -/* f051898: ae080438 */ sw $t0,0x438($s0) -/* f05189c: 8e090424 */ lw $t1,0x424($s0) -.L0f0518a0: -/* f0518a0: 248e0005 */ addiu $t6,$a0,0x5 -/* f0518a4: 8d2a0300 */ lw $t2,0x300($t1) -/* f0518a8: 8d420004 */ lw $v0,0x4($t2) -/* f0518ac: 5040000f */ beqzl $v0,.L0f0518ec -/* f0518b0: ae0e0438 */ sw $t6,0x438($s0) -/* f0518b4: 8c4b0014 */ lw $t3,0x14($v0) -/* f0518b8: 5160000c */ beqzl $t3,.L0f0518ec -/* f0518bc: ae0e0438 */ sw $t6,0x438($s0) -/* f0518c0: 8c4c0008 */ lw $t4,0x8($v0) -/* f0518c4: 3c010040 */ lui $at,0x40 -/* f0518c8: 01816825 */ or $t5,$t4,$at -/* f0518cc: ac4d0008 */ sw $t5,0x8($v0) -/* f0518d0: 90660004 */ lbu $a2,0x4($v1) -/* f0518d4: 8e050438 */ lw $a1,0x438($s0) -/* f0518d8: 0fc13583 */ jal chraiGoToLabel -/* f0518dc: 8e040434 */ lw $a0,0x434($s0) -/* f0518e0: 10000002 */ beqz $zero,.L0f0518ec -/* f0518e4: ae020438 */ sw $v0,0x438($s0) -/* f0518e8: ae0e0438 */ sw $t6,0x438($s0) -.L0f0518ec: -/* f0518ec: 8fbf001c */ lw $ra,0x1c($sp) -/* f0518f0: 8fb00018 */ lw $s0,0x18($sp) -/* f0518f4: 27bd0028 */ addiu $sp,$sp,0x28 -/* f0518f8: 03e00008 */ jr $ra -/* f0518fc: 00001025 */ or $v0,$zero,$zero -); +bool aiIfGunUnclaimed(void) +{ + u8 *cmd = g_Vars.ailist + g_Vars.aioffset; + + if (cmd[3] == 0) { + struct defaultobj *obj = objFindByTagId(cmd[2]); + + if (obj && obj->pos) { + g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[4]); + } else { + g_Vars.aioffset += 5; + } + } else { + struct weaponobj *weapon = g_Vars.chrdata->gungroundpos->master; + + if (weapon && weapon->pos) { + weapon->flags |= 0x00400000; + g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[4]); + } else { + g_Vars.aioffset += 5; + } + } + + return false; +} /** * @cmd 0062 @@ -13384,7 +13348,7 @@ bool aiIfY(void) struct position *target = heliGetTargetPosition(heli); if (target && (target->unk00 == 3 || target->unk00 == 6)) { - chr = target->chr; + chr = target->master; } } } else { diff --git a/src/include/commands.h b/src/include/commands.h index 29343a074..175981305 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -417,8 +417,7 @@ label, // If behavior is zero, go to label if object exists. -// If behavior is nonzero, do something related to the current chr and ignore -// the object parameter. +// If behavior is nonzero, set flag on unclaimed gun. // In practice this is always called with object = -1 and behavior = 1. #define if_gun_unclaimed(object, behavior, label) \ mkshort(0x0061), \ diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index 196a0e796..85408bde0 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -100,7 +100,7 @@ /*0x005e*/ bool aiIfWeaponThrown(void); /*0x005f*/ bool aiIfWeaponThrownOnObject(void); /*0x0060*/ bool aiIfChrHasWeaponEquipped(void); -/*0x0061*/ bool ai0061(void); +/*0x0061*/ bool aiIfGunUnclaimed(void); /*0x0062*/ bool aiIfObjectHealthy(void); /*0x0063*/ bool ai0063(void); /*0x0065*/ bool ai0065(void); diff --git a/src/include/types.h b/src/include/types.h index 2a2e5fa53..fd58408f0 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -32,7 +32,7 @@ struct position { u8 unk00; u8 flags; u16 unk02; - struct chrdata *chr; + void *master; // pointer to specific struct that has this position. eg. chrdata or weaponobj struct coord coord; u32 unk14; u32 unk18; // related to gun recovery diff --git a/src/setup/setup_000000.c b/src/setup/setup_000000.c index f564c5960..88a83c073 100644 --- a/src/setup/setup_000000.c +++ b/src/setup/setup_000000.c @@ -14229,7 +14229,7 @@ bool (*g_CommandPointers[])(void) = { /*0x005e*/ aiIfWeaponThrown, /*0x005f*/ aiIfWeaponThrownOnObject, /*0x0060*/ aiIfChrHasWeaponEquipped, - /*0x0061*/ ai0061, + /*0x0061*/ aiIfGunUnclaimed, /*0x0062*/ aiIfObjectHealthy, /*0x0063*/ ai0063, /*0x0064*/ NULL,