From e573971544e14c9bfce8908e869cd1d38579ddf8 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 5 Feb 2021 23:48:57 +1000 Subject: [PATCH] Decompile chrSetChrPresetToChrNearPos --- src/game/chr/chraction.c | 219 +++++++-------------------- src/game/chr/chrai.c | 4 +- src/game/chr/chraicommands.c | 10 +- src/game/game_190260.c | 2 +- src/game/padhalllv.c | 2 +- src/game/prop.c | 6 +- src/game/propobj.c | 4 +- src/game/training/training.c | 4 +- src/include/commands.h | 31 +++- src/include/constants.h | 1 + src/include/game/chr/chraction.h | 8 +- src/include/game/chr/chraicommands.h | 4 +- src/include/game/prop.h | 2 +- 13 files changed, 105 insertions(+), 192 deletions(-) diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index e2c0e48eb..331161d2c 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -25047,17 +25047,17 @@ bool chrSetPadPresetToWaypointWithinTargetQuadrant(struct chrdata *chr, u8 quadr return false; } -bool func0f04a76c(struct chrdata *chr, f32 distance) +bool chrSetChrPresetToAnyChrNearSelf(struct chrdata *chr, f32 distance) { - return func0f04a79c(0, chr, distance); + return chrSetChrPresetToChrNearSelf(COMPARE_ANY, chr, distance); } -bool func0f04a79c(u8 chrnum, struct chrdata *chr, f32 distance) +bool chrSetChrPresetToChrNearSelf(u8 checktype, struct chrdata *chr, f32 distance) { - return func0f04a848(chrnum, chr, distance, &chr->prop->pos, chr->prop->rooms); + return chrSetChrPresetToChrNearPos(checktype, chr, distance, &chr->prop->pos, chr->prop->rooms); } -bool func0f04a7dc(u32 chrnum, struct chrdata *chr, f32 distance, s32 padnum) +bool chrSetChrPresetToChrNearPad(u32 checktype, struct chrdata *chr, f32 distance, s32 padnum) { struct pad pad; s16 rooms[2]; @@ -25068,169 +25068,64 @@ bool func0f04a7dc(u32 chrnum, struct chrdata *chr, f32 distance, s32 padnum) rooms[0] = pad.room; rooms[1] = -1; - return func0f04a848(chrnum, chr, distance, &pad.pos, rooms); + return chrSetChrPresetToChrNearPos(checktype, chr, distance, &pad.pos, rooms); } -GLOBAL_ASM( -glabel func0f04a848 -/* f04a848: 27bdfd18 */ addiu $sp,$sp,-744 -/* f04a84c: 44866000 */ mtc1 $a2,$f12 -/* f04a850: afbf006c */ sw $ra,0x6c($sp) -/* f04a854: afbe0068 */ sw $s8,0x68($sp) -/* f04a858: afb70064 */ sw $s7,0x64($sp) -/* f04a85c: afb60060 */ sw $s6,0x60($sp) -/* f04a860: afb5005c */ sw $s5,0x5c($sp) -/* f04a864: afb40058 */ sw $s4,0x58($sp) -/* f04a868: afb30054 */ sw $s3,0x54($sp) -/* f04a86c: afb20050 */ sw $s2,0x50($sp) -/* f04a870: afb1004c */ sw $s1,0x4c($sp) -/* f04a874: afb00048 */ sw $s0,0x48($sp) -/* f04a878: f7be0040 */ sdc1 $f30,0x40($sp) -/* f04a87c: f7bc0038 */ sdc1 $f28,0x38($sp) -/* f04a880: f7ba0030 */ sdc1 $f26,0x30($sp) -/* f04a884: f7b80028 */ sdc1 $f24,0x28($sp) -/* f04a888: f7b60020 */ sdc1 $f22,0x20($sp) -/* f04a88c: f7b40018 */ sdc1 $f20,0x18($sp) -/* f04a890: afa402e8 */ sw $a0,0x2e8($sp) -/* f04a894: c4e00000 */ lwc1 $f0,0x0($a3) -/* f04a898: c4e20004 */ lwc1 $f2,0x4($a3) -/* f04a89c: c4ee0008 */ lwc1 $f14,0x8($a3) -/* f04a8a0: 8fb102f8 */ lw $s1,0x2f8($sp) -/* f04a8a4: 27b300b4 */ addiu $s3,$sp,0xb4 -/* f04a8a8: 00a0a025 */ or $s4,$a1,$zero -/* f04a8ac: 309e00ff */ andi $s8,$a0,0xff -/* f04a8b0: 02602825 */ or $a1,$s3,$zero -/* f04a8b4: 460c0501 */ sub.s $f20,$f0,$f12 -/* f04a8b8: 02202025 */ or $a0,$s1,$zero -/* f04a8bc: 460c0580 */ add.s $f22,$f0,$f12 -/* f04a8c0: 460c1601 */ sub.s $f24,$f2,$f12 -/* f04a8c4: 460c1680 */ add.s $f26,$f2,$f12 -/* f04a8c8: 460c7701 */ sub.s $f28,$f14,$f12 -/* f04a8cc: 0fc195e9 */ jal roomsCopy -/* f04a8d0: 460c7780 */ add.s $f30,$f14,$f12 -/* f04a8d4: 862e0000 */ lh $t6,0x0($s1) -/* f04a8d8: 2412ffff */ addiu $s2,$zero,-1 -/* f04a8dc: 02208025 */ or $s0,$s1,$zero -/* f04a8e0: 524e000f */ beql $s2,$t6,.L0f04a920 -/* f04a8e4: 27b000e0 */ addiu $s0,$sp,0xe0 -/* f04a8e8: 86240000 */ lh $a0,0x0($s1) -/* f04a8ec: 27b10084 */ addiu $s1,$sp,0x84 -/* f04a8f0: 02202825 */ or $a1,$s1,$zero -.L0f04a8f4: -/* f04a8f4: 0fc5916a */ jal roomGetNeighbours -/* f04a8f8: 2406000a */ addiu $a2,$zero,0xa -/* f04a8fc: 02202025 */ or $a0,$s1,$zero -/* f04a900: 02602825 */ or $a1,$s3,$zero -/* f04a904: 0fc195f6 */ jal func0f0657d8 -/* f04a908: 24060014 */ addiu $a2,$zero,0x14 -/* f04a90c: 86040002 */ lh $a0,0x2($s0) -/* f04a910: 26100002 */ addiu $s0,$s0,0x2 -/* f04a914: 5644fff7 */ bnel $s2,$a0,.L0f04a8f4 -/* f04a918: 02202825 */ or $a1,$s1,$zero -/* f04a91c: 27b000e0 */ addiu $s0,$sp,0xe0 -.L0f04a920: -/* f04a920: 02002825 */ or $a1,$s0,$zero -/* f04a924: 02602025 */ or $a0,$s3,$zero -/* f04a928: 0fc197e0 */ jal roomGetProps -/* f04a92c: 24060100 */ addiu $a2,$zero,0x100 -/* f04a930: 87af00e0 */ lh $t7,0xe0($sp) -/* f04a934: 02009025 */ or $s2,$s0,$zero -/* f04a938: 27b800e0 */ addiu $t8,$sp,0xe0 -/* f04a93c: 05e00040 */ bltz $t7,.L0f04aa40 -/* f04a940: 24170006 */ addiu $s7,$zero,0x6 -/* f04a944: 3c15800a */ lui $s5,%hi(g_Vars) -/* f04a948: 26b59fc0 */ addiu $s5,$s5,%lo(g_Vars) -/* f04a94c: 87020000 */ lh $v0,0x0($t8) -/* f04a950: 24160003 */ addiu $s6,$zero,0x3 -/* f04a954: 24130048 */ addiu $s3,$zero,0x48 -.L0f04a958: -/* f04a958: 00530019 */ multu $v0,$s3 -/* f04a95c: 8ea80338 */ lw $t0,0x338($s5) -/* f04a960: 0000c812 */ mflo $t9 -/* f04a964: 03288021 */ addu $s0,$t9,$t0 -/* f04a968: 92030000 */ lbu $v1,0x0($s0) -/* f04a96c: 52c30004 */ beql $s6,$v1,.L0f04a980 -/* f04a970: 8e110004 */ lw $s1,0x4($s0) -/* f04a974: 56e3002f */ bnel $s7,$v1,.L0f04aa34 -/* f04a978: 86420002 */ lh $v0,0x2($s2) -/* f04a97c: 8e110004 */ lw $s1,0x4($s0) -.L0f04a980: -/* f04a980: 86890000 */ lh $t1,0x0($s4) -/* f04a984: 862a0000 */ lh $t2,0x0($s1) -/* f04a988: 512a002a */ beql $t1,$t2,.L0f04aa34 -/* f04a98c: 86420002 */ lh $v0,0x2($s2) -/* f04a990: 0fc0e6a5 */ jal chrIsDead -/* f04a994: 02202025 */ or $a0,$s1,$zero -/* f04a998: 54400026 */ bnezl $v0,.L0f04aa34 -/* f04a99c: 86420002 */ lh $v0,0x2($s2) -/* f04a9a0: c6000008 */ lwc1 $f0,0x8($s0) -/* f04a9a4: 4600a03e */ c.le.s $f20,$f0 -/* f04a9a8: 00000000 */ nop -/* f04a9ac: 45020021 */ bc1fl .L0f04aa34 -/* f04a9b0: 86420002 */ lh $v0,0x2($s2) -/* f04a9b4: 4616003e */ c.le.s $f0,$f22 -/* f04a9b8: 00000000 */ nop -/* f04a9bc: 4502001d */ bc1fl .L0f04aa34 -/* f04a9c0: 86420002 */ lh $v0,0x2($s2) -/* f04a9c4: c600000c */ lwc1 $f0,0xc($s0) -/* f04a9c8: 4600c03e */ c.le.s $f24,$f0 -/* f04a9cc: 00000000 */ nop -/* f04a9d0: 45020018 */ bc1fl .L0f04aa34 -/* f04a9d4: 86420002 */ lh $v0,0x2($s2) -/* f04a9d8: 461a003e */ c.le.s $f0,$f26 -/* f04a9dc: 00000000 */ nop -/* f04a9e0: 45020014 */ bc1fl .L0f04aa34 -/* f04a9e4: 86420002 */ lh $v0,0x2($s2) -/* f04a9e8: c6000010 */ lwc1 $f0,0x10($s0) -/* f04a9ec: 4600e03e */ c.le.s $f28,$f0 -/* f04a9f0: 00000000 */ nop -/* f04a9f4: 4502000f */ bc1fl .L0f04aa34 -/* f04a9f8: 86420002 */ lh $v0,0x2($s2) -/* f04a9fc: 461e003e */ c.le.s $f0,$f30 -/* f04aa00: 02202025 */ or $a0,$s1,$zero -/* f04aa04: 02802825 */ or $a1,$s4,$zero -/* f04aa08: 4502000a */ bc1fl .L0f04aa34 -/* f04aa0c: 86420002 */ lh $v0,0x2($s2) -/* f04aa10: 0fc12aa3 */ jal chrCompareTeams -/* f04aa14: 33c600ff */ andi $a2,$s8,0xff -/* f04aa18: 50400006 */ beqzl $v0,.L0f04aa34 -/* f04aa1c: 86420002 */ lh $v0,0x2($s2) -/* f04aa20: 862b0000 */ lh $t3,0x0($s1) -/* f04aa24: 24020001 */ addiu $v0,$zero,0x1 -/* f04aa28: 10000006 */ b .L0f04aa44 -/* f04aa2c: a68b012a */ sh $t3,0x12a($s4) -/* f04aa30: 86420002 */ lh $v0,0x2($s2) -.L0f04aa34: -/* f04aa34: 26520002 */ addiu $s2,$s2,0x2 -/* f04aa38: 0441ffc7 */ bgez $v0,.L0f04a958 -/* f04aa3c: 00000000 */ nop -.L0f04aa40: -/* f04aa40: 00001025 */ or $v0,$zero,$zero -.L0f04aa44: -/* f04aa44: 8fbf006c */ lw $ra,0x6c($sp) -/* f04aa48: d7b40018 */ ldc1 $f20,0x18($sp) -/* f04aa4c: d7b60020 */ ldc1 $f22,0x20($sp) -/* f04aa50: d7b80028 */ ldc1 $f24,0x28($sp) -/* f04aa54: d7ba0030 */ ldc1 $f26,0x30($sp) -/* f04aa58: d7bc0038 */ ldc1 $f28,0x38($sp) -/* f04aa5c: d7be0040 */ ldc1 $f30,0x40($sp) -/* f04aa60: 8fb00048 */ lw $s0,0x48($sp) -/* f04aa64: 8fb1004c */ lw $s1,0x4c($sp) -/* f04aa68: 8fb20050 */ lw $s2,0x50($sp) -/* f04aa6c: 8fb30054 */ lw $s3,0x54($sp) -/* f04aa70: 8fb40058 */ lw $s4,0x58($sp) -/* f04aa74: 8fb5005c */ lw $s5,0x5c($sp) -/* f04aa78: 8fb60060 */ lw $s6,0x60($sp) -/* f04aa7c: 8fb70064 */ lw $s7,0x64($sp) -/* f04aa80: 8fbe0068 */ lw $s8,0x68($sp) -/* f04aa84: 03e00008 */ jr $ra -/* f04aa88: 27bd02e8 */ addiu $sp,$sp,0x2e8 -); +bool chrSetChrPresetToChrNearPos(u8 checktype, struct chrdata *chr, f32 distance, struct coord *pos, s16 *rooms) +{ + s32 i; + s16 *propnumptr; + s16 propnums[256]; + s16 allrooms[21]; + f32 xmin = pos->x - distance; + f32 xmax = pos->x + distance; + f32 ymin = pos->y - distance; + f32 ymax = pos->y + distance; + f32 zmin = pos->z - distance; + f32 zmax = pos->z + distance; + s16 neighbours[11]; + + roomsCopy(rooms, allrooms); + + for (i = 0; rooms[i] != -1; i++) { + roomGetNeighbours(rooms[i], neighbours, 10); + roomsAppend(neighbours, allrooms, 20); + } + + roomGetProps(allrooms, propnums, 256); + + propnumptr = propnums; + + while (*propnumptr >= 0) { + struct prop *prop = &g_Vars.props[*propnumptr]; + + if (prop->type == PROPTYPE_CHR || prop->type == PROPTYPE_PLAYER) { + struct chrdata *loopchr = prop->chr; + + if (loopchr->chrnum != chr->chrnum + && !chrIsDead(loopchr) + && prop->pos.x >= xmin + && prop->pos.x <= xmax + && prop->pos.y >= ymin + && prop->pos.y <= ymax + && prop->pos.z >= zmin + && prop->pos.z <= zmax + && chrCompareTeams(loopchr, chr, checktype)) { + chr->chrpreset1 = loopchr->chrnum; + return true; + } + } + + *propnumptr++; + } + + return false; +} bool chrCompareTeams(struct chrdata *chr1, struct chrdata *chr2, u8 checktype) { if (chr1 && chr1->prop) { - if (checktype == 0) { + if (checktype == COMPARE_ANY) { return true; } diff --git a/src/game/chr/chrai.c b/src/game/chr/chrai.c index 36e69231d..88fd9d58d 100644 --- a/src/game/chr/chrai.c +++ b/src/game/chr/chrai.c @@ -282,8 +282,8 @@ bool (*g_CommandPointers[])(void) = { /*0x0106*/ aiSetTarget, /*0x0107*/ aiIfPresetsTargetIsNotMyTarget, /*0x0108*/ aiIfChrTarget, - /*0x0109*/ ai0109, - /*0x010a*/ ai010a, + /*0x0109*/ aiSetChrPresetToChrNearSelf, + /*0x010a*/ aiSetChrPresetToChrNearPad, /*0x010b*/ aiChrSetTeam, /*0x010c*/ aiIfCompareChrPresetsTeam, /*0x010d*/ aiNoOp010d, diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index cecc7c56d..46651efa4 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -1905,7 +1905,7 @@ bool ai0058(void) u8 *cmd = g_Vars.ailist + g_Vars.aioffset; f32 distance = (cmd[3] | (cmd[2] << 8)) * 10.0f; - if (func0f04a76c(g_Vars.chrdata, distance)) { + if (chrSetChrPresetToAnyChrNearSelf(g_Vars.chrdata, distance)) { g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[4]); } else { g_Vars.aioffset += 5; @@ -6146,12 +6146,12 @@ bool aiIfChrTarget(void) /** * @cmd 0109 */ -bool ai0109(void) +bool aiSetChrPresetToChrNearSelf(void) { u8 *cmd = g_Vars.ailist + g_Vars.aioffset; f32 distance = (cmd[4] | (cmd[3] << 8)) * 10.0f; - if (func0f04a79c(cmd[2], g_Vars.chrdata, distance)) { + if (chrSetChrPresetToChrNearSelf(cmd[2], g_Vars.chrdata, distance)) { g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[5]); } else { g_Vars.aioffset += 6; @@ -6163,13 +6163,13 @@ bool ai0109(void) /** * @cmd 010a */ -bool ai010a(void) +bool aiSetChrPresetToChrNearPad(void) { u8 *cmd = g_Vars.ailist + g_Vars.aioffset; f32 distance = (cmd[4] | (cmd[3] << 8)) * 10.0f; u16 padnum = cmd[6] | (cmd[5] << 8); - if (func0f04a7dc(cmd[2], g_Vars.chrdata, distance, padnum)) { + if (chrSetChrPresetToChrNearPad(cmd[2], g_Vars.chrdata, distance, padnum)) { g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[7]); } else { g_Vars.aioffset += 8; diff --git a/src/game/game_190260.c b/src/game/game_190260.c index b77a321ad..5e0bcf400 100644 --- a/src/game/game_190260.c +++ b/src/game/game_190260.c @@ -1107,7 +1107,7 @@ glabel func0f19124c /* f1912b0: 2406000a */ addiu $a2,$zero,0xa /* f1912b4: 02202025 */ or $a0,$s1,$zero /* f1912b8: 02602825 */ or $a1,$s3,$zero -/* f1912bc: 0fc195f6 */ jal func0f0657d8 +/* f1912bc: 0fc195f6 */ jal roomsAppend /* f1912c0: 24060014 */ addiu $a2,$zero,0x14 /* f1912c4: 8e8f001c */ lw $t7,0x1c($s4) /* f1912c8: 26100002 */ addiu $s0,$s0,0x2 diff --git a/src/game/padhalllv.c b/src/game/padhalllv.c index 0e73f351a..766ef6045 100644 --- a/src/game/padhalllv.c +++ b/src/game/padhalllv.c @@ -77,7 +77,7 @@ glabel waypointFindClosestToPos /* f1142fc: 2406000a */ addiu $a2,$zero,0xa /* f114300: 02402025 */ or $a0,$s2,$zero /* f114304: 02602825 */ or $a1,$s3,$zero -/* f114308: 0fc195f6 */ jal func0f0657d8 +/* f114308: 0fc195f6 */ jal roomsAppend /* f11430c: 2406001e */ addiu $a2,$zero,0x1e /* f114310: 86040002 */ lh $a0,0x2($s0) /* f114314: 2401ffff */ addiu $at,$zero,-1 diff --git a/src/game/prop.c b/src/game/prop.c index 9f417c1c9..d4373f3b0 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -4097,7 +4097,7 @@ glabel var7f1a9f4c /* f064288: 2406000a */ addiu $a2,$zero,0xa /* f06428c: 02202025 */ or $a0,$s1,$zero /* f064290: 02602825 */ or $a1,$s3,$zero -/* f064294: 0fc195f6 */ jal func0f0657d8 +/* f064294: 0fc195f6 */ jal roomsAppend /* f064298: 24060014 */ addiu $a2,$zero,0x14 /* f06429c: 8e890284 */ lw $t1,0x284($s4) /* f0642a0: 26100002 */ addiu $s0,$s0,0x2 @@ -5499,7 +5499,7 @@ void roomsCopy(s16 *src, s16 *dst) } GLOBAL_ASM( -glabel func0f0657d8 +glabel roomsAppend /* f0657d8: 27bdfff8 */ addiu $sp,$sp,-8 /* f0657dc: afb00004 */ sw $s0,0x4($sp) /* f0657e0: 848e0000 */ lh $t6,0x0($a0) @@ -5911,7 +5911,7 @@ void func0f065dfc(struct coord *pos, s16 *rooms, struct coord *newpos, s16 *newr func0f065e98(pos, rooms, newpos, newrooms); if (morerooms) { - func0f0657d8(newrooms, morerooms, arg5); + roomsAppend(newrooms, morerooms, arg5); } } } diff --git a/src/game/propobj.c b/src/game/propobj.c index e384a9312..1df0c5dc4 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -12880,7 +12880,7 @@ glabel var7f1aa314 /* f0716e0: 27a70198 */ addiu $a3,$sp,0x198 /* f0716e4: 27a4009c */ addiu $a0,$sp,0x9c /* f0716e8: 27a50198 */ addiu $a1,$sp,0x198 -/* f0716ec: 0fc195f6 */ jal func0f0657d8 +/* f0716ec: 0fc195f6 */ jal roomsAppend /* f0716f0: 24060008 */ addiu $a2,$zero,0x8 /* f0716f4: 27a401b4 */ addiu $a0,$sp,0x1b4 /* f0716f8: 3c0540a0 */ lui $a1,0x40a0 @@ -12896,7 +12896,7 @@ glabel var7f1aa314 /* f071720: e7a001c8 */ swc1 $f0,0x1c8($sp) /* f071724: 27a4009c */ addiu $a0,$sp,0x9c /* f071728: 27a50188 */ addiu $a1,$sp,0x188 -/* f07172c: 0fc195f6 */ jal func0f0657d8 +/* f07172c: 0fc195f6 */ jal roomsAppend /* f071730: 24060008 */ addiu $a2,$zero,0x8 /* f071734: 27a401a8 */ addiu $a0,$sp,0x1a8 /* f071738: 3c0540a0 */ lui $a1,0x40a0 diff --git a/src/game/training/training.c b/src/game/training/training.c index 91e4f9519..436692549 100644 --- a/src/game/training/training.c +++ b/src/game/training/training.c @@ -1918,7 +1918,7 @@ void frEndSession(bool hidetargets) for (i = 0; g_Vars.currentplayer->prop->rooms[i] != -1; i++) { roomGetNeighbours(g_Vars.currentplayer->prop->rooms[i], rooms2, 10); - func0f0657d8(rooms2, rooms, 20); + roomsAppend(rooms2, rooms, 20); } // Remove projectiles and throwables @@ -2192,7 +2192,7 @@ bool frIsAmmoWasted(void) for (i = 0; g_Vars.currentplayer->prop->rooms[i] != -1; i++) { roomGetNeighbours(g_Vars.currentplayer->prop->rooms[i], rooms10, 10); - func0f0657d8(rooms10, rooms20, 20); + roomsAppend(rooms10, rooms20, 20); } roomGetProps(rooms20, propnums, 256); diff --git a/src/include/commands.h b/src/include/commands.h index 989de1bdf..6084b3793 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -2366,24 +2366,41 @@ anytarget, \ label, -#define cmd0109(u1, distance, label) \ +/** + * Check all chrs within the given distance of the current chr. If any chr + * passes a team check (as given by checktype), set the current chr's chrpreset + * to that chr and follow the label. + * + * Checktype can be COMPARE_FRIENDS, COMPARE_ENEMIES or COMPANY_ANY. + */ +#define set_chrpreset_to_chr_near_self(checktype, distance, label) \ mkshort(0x0109), \ - u1, \ + checktype, \ mkshort(distance), \ label, \ -#define cmd010a(u1, distance, u2, label) \ +/** + * Check all chrs within the given distance of the given pad. If any chr passes + * a team check (as given by checktype), set the current chr's chrpreset to that + * chr and follow the label. + * + * Checktype can be COMPARE_FRIENDS, COMPARE_ENEMIES or COMPANY_ANY. + */ +#define set_chrpreset_to_chr_near_pad(checktype, distance, padnum, label) \ mkshort(0x010a), \ - u1, \ + checktype, \ mkshort(distance / 10), \ - mkshort(u2), \ + mkshort(padnum), \ label, /** * Set the team that the chr is on. * - * The values are not well understood yet. Enemies are typically assigned to - * team 0x02 and allies to team 0x10, but this varies. + * The value is a single byte bitfield. If two chrs have any matching bits then + * they will be friends. If no bits match then they will be enemies. + * + * Team 0x80 is a special case, and is a non-combat team. + * Chrs will not engage in combat with anyone who is on this team. */ #define set_chr_team(chr, team) \ mkshort(0x010b), \ diff --git a/src/include/constants.h b/src/include/constants.h index ea86b0c0d..9a49980cd 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -559,6 +559,7 @@ #define COLOR_08_RED 0x08 #define COLOR_09_BLUE 0x09 +#define COMPARE_ANY 0 #define COMPARE_FRIENDS 1 #define COMPARE_ENEMIES 2 diff --git a/src/include/game/chr/chraction.h b/src/include/game/chr/chraction.h index 90114b9f4..e2a9e8a5a 100644 --- a/src/include/game/chr/chraction.h +++ b/src/include/game/chr/chraction.h @@ -189,8 +189,8 @@ bool waypointIsWithin90DegreesOfPosAngle(struct waypoint *waypoint, struct coord s32 chrFindWaypointWithinPosQuadrant(struct coord *pos, s16 *rooms, f32 angle, u8 quadrant); bool func0f04a4ec(struct chrdata *chr, u8 quadrant); bool chrSetPadPresetToWaypointWithinTargetQuadrant(struct chrdata *chr, u8 arg1); -bool func0f04a7dc(u32 chrnum, struct chrdata *chr, f32 distance, s32 padnum); -bool func0f04a848(u8 chrnum, struct chrdata *chr, f32 distance, struct coord *pos, s16 *room); +bool chrSetChrPresetToChrNearPad(u32 checktype, struct chrdata *chr, f32 distance, s32 padnum); +bool chrSetChrPresetToChrNearPos(u8 checktype, struct chrdata *chr, f32 distance, struct coord *pos, s16 *room); bool chrSetPadPresetToPadOnRouteToTarget(struct chrdata *chr); u32 func0f04aeb0(void); bool func0f04af84(f32 chrwidth, struct coord *pos, s16 *rooms, f32 angle, bool arg4, bool arg5, bool arg6); @@ -305,8 +305,8 @@ s32 chrGetNumCloseArghs(struct chrdata *chr); void decrementByte(u8 *dst, u8 amount); void incrementByte(u8 *dst, u8 amount); bool chrCanHearAlarm(struct chrdata *chr); -bool func0f04a76c(struct chrdata *chr, f32 distance); -bool func0f04a79c(u8 chrnum, struct chrdata *chr, f32 distance); +bool chrSetChrPresetToAnyChrNearSelf(struct chrdata *chr, f32 distance); +bool chrSetChrPresetToChrNearSelf(u8 checktype, struct chrdata *chr, f32 distance); bool chrCompareTeams(struct chrdata *chr1, struct chrdata *chr2, u8 checktype); void chrSetChrPreset(struct chrdata *chr, s32 chrpreset); void chrSetChrPresetByChrnum(struct chrdata *chr, s32 chrnum, s32 chrpreset); diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index 6f067d00a..94a134cd2 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -265,8 +265,8 @@ /*0x0106*/ bool aiSetTarget(void); /*0x0107*/ bool aiIfPresetsTargetIsNotMyTarget(void); /*0x0108*/ bool aiIfChrTarget(void); -/*0x0109*/ bool ai0109(void); -/*0x010a*/ bool ai010a(void); +/*0x0109*/ bool aiSetChrPresetToChrNearSelf(void); +/*0x010a*/ bool aiSetChrPresetToChrNearPad(void); /*0x010b*/ bool aiChrSetTeam(void); /*0x010c*/ bool aiIfCompareChrPresetsTeam(void); /*0x010d*/ bool aiNoOp010d(void); diff --git a/src/include/game/prop.h b/src/include/game/prop.h index 2bb304360..455356b85 100644 --- a/src/include/game/prop.h +++ b/src/include/game/prop.h @@ -42,7 +42,7 @@ void func0f064ce8(void); u32 propDoorGetCdTypes(struct prop *prop); bool propIsOfCdType(struct prop *prop, u32 types); void roomsCopy(s16 *srcrooms, s16 *dstrooms); -void func0f0657d8(s16 *newrooms, s16 *rooms, u32 arg2); +void roomsAppend(s16 *newrooms, s16 *rooms, u32 arg2); bool arrayIntersects(s16 *a, s16 *b); bool func0f0658e8(s16 arg0, s32 arg1); u32 func0f06593c(void);