From e765532e1f89497b4913f0a07da84ce7cfcc5f92 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 5 Feb 2021 17:08:40 +1000 Subject: [PATCH] Decompile chrSetPadPresetToPadOnRouteToTarget --- src/game/bondmove.c | 2 +- src/game/chr/chraction.c | 169 +++++++++------------------ src/game/chr/chrai.c | 2 +- src/game/chr/chraicommands.c | 4 +- src/game/core.c | 8 +- src/game/game_0b69d0.c | 8 +- src/game/padhalllv.c | 6 +- src/game/propobj.c | 4 +- src/include/commands.h | 6 +- src/include/game/chr/chraction.h | 2 +- src/include/game/chr/chraicommands.h | 2 +- src/include/gvars/gvars.h | 6 +- src/lib/gvars.c | 4 +- 13 files changed, 80 insertions(+), 143 deletions(-) diff --git a/src/game/bondmove.c b/src/game/bondmove.c index c582c9874..7c5d6b6f6 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -4869,7 +4869,7 @@ glabel var7f1ad8e4 // // a944 // // I think this is checking which gun is making the loudest noise and is // // alerting nearby chrs to it. -// if (g_Vars.unk000324 && (handIsAttackingOnThisTick(0) || handIsAttackingOnThisTick(1))) { +// if (g_Vars.bondvisible && (handIsAttackingOnThisTick(0) || handIsAttackingOnThisTick(1))) { // spb4 = 0; // // if (handIsAttackingOnThisTick(0) && func0f09cf58(0) > spb4) { diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index f663ec003..309630cfc 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -24856,7 +24856,7 @@ bool chrCanSeeTargetWithExtraCheck(struct chrdata *chr) } if (target->type == PROPTYPE_PLAYER) { - if (g_Vars.unk000324 && + if (g_Vars.bondvisible && (hasLineOfSight(&target->pos, target->rooms, &chr->prop->pos, chr->prop->rooms, 51, 8))) { struct model *model = chr->model; struct coord sp68; @@ -25475,122 +25475,57 @@ void chrSetPadPresetByChrnum(struct chrdata *basechr, s32 chrnum, s32 pad_id) } } -GLOBAL_ASM( -glabel chrIsInLoadedRoom -/* f04ad08: 27bdff28 */ addiu $sp,$sp,-216 -/* f04ad0c: afbf0034 */ sw $ra,0x34($sp) -/* f04ad10: afb60030 */ sw $s6,0x30($sp) -/* f04ad14: afb5002c */ sw $s5,0x2c($sp) -/* f04ad18: afb40028 */ sw $s4,0x28($sp) -/* f04ad1c: afb30024 */ sw $s3,0x24($sp) -/* f04ad20: afb20020 */ sw $s2,0x20($sp) -/* f04ad24: afb1001c */ sw $s1,0x1c($sp) -/* f04ad28: afb00018 */ sw $s0,0x18($sp) -/* f04ad2c: 0fc0a221 */ jal chrGetTargetProp -/* f04ad30: afa400d8 */ sw $a0,0xd8($sp) -/* f04ad34: 904f0000 */ lbu $t7,0x0($v0) -/* f04ad38: 8fae00d8 */ lw $t6,0xd8($sp) -/* f04ad3c: 24010006 */ addiu $at,$zero,0x6 -/* f04ad40: 00408825 */ or $s1,$v0,$zero -/* f04ad44: 15e10004 */ bne $t7,$at,.L0f04ad58 -/* f04ad48: 8dc3001c */ lw $v1,0x1c($t6) -/* f04ad4c: 3c18800a */ lui $t8,%hi(g_Vars+0x324) -/* f04ad50: 8f18a2e4 */ lw $t8,%lo(g_Vars+0x324)($t8) -/* f04ad54: 1300004b */ beqz $t8,.L0f04ae84 -.L0f04ad58: -/* f04ad58: 24740008 */ addiu $s4,$v1,0x8 -/* f04ad5c: 24750028 */ addiu $s5,$v1,0x28 -/* f04ad60: 26360008 */ addiu $s6,$s1,0x8 -/* f04ad64: 02c03025 */ or $a2,$s6,$zero -/* f04ad68: 02a02825 */ or $a1,$s5,$zero -/* f04ad6c: 02802025 */ or $a0,$s4,$zero -/* f04ad70: 0c00b706 */ jal func0002dc18 -/* f04ad74: 24070020 */ addiu $a3,$zero,0x20 -/* f04ad78: 10400003 */ beqz $v0,.L0f04ad88 -/* f04ad7c: 02802025 */ or $a0,$s4,$zero -/* f04ad80: 10000041 */ b .L0f04ae88 -/* f04ad84: 00001025 */ or $v0,$zero,$zero -.L0f04ad88: -/* f04ad88: 0fc45095 */ jal waypointFindClosestToPos -/* f04ad8c: 02a02825 */ or $a1,$s5,$zero -/* f04ad90: 26330028 */ addiu $s3,$s1,0x28 -/* f04ad94: 00408025 */ or $s0,$v0,$zero -/* f04ad98: 02602825 */ or $a1,$s3,$zero -/* f04ad9c: 0fc45095 */ jal waypointFindClosestToPos -/* f04ada0: 02c02025 */ or $a0,$s6,$zero -/* f04ada4: 12000037 */ beqz $s0,.L0f04ae84 -/* f04ada8: 00408825 */ or $s1,$v0,$zero -/* f04adac: 10400035 */ beqz $v0,.L0f04ae84 -/* f04adb0: 3c19800a */ lui $t9,%hi(g_Vars+0x8) -/* f04adb4: 8faa00d8 */ lw $t2,0xd8($sp) -/* f04adb8: 8f399fc8 */ lw $t9,%lo(g_Vars+0x8)($t9) -/* f04adbc: 854b0000 */ lh $t3,0x0($t2) -/* f04adc0: 00194243 */ sra $t0,$t9,0x9 -/* f04adc4: 000849c0 */ sll $t1,$t0,0x7 -/* f04adc8: 000b60c0 */ sll $t4,$t3,0x3 -/* f04adcc: 012c2021 */ addu $a0,$t1,$t4 -/* f04add0: 0fc45090 */ jal waypointSetHashThing -/* f04add4: 00802825 */ or $a1,$a0,$zero -/* f04add8: 02202025 */ or $a0,$s1,$zero -/* f04addc: 02002825 */ or $a1,$s0,$zero -/* f04ade0: 27a600b4 */ addiu $a2,$sp,0xb4 -/* f04ade4: 0fc4547b */ jal waypointFindRoute -/* f04ade8: 24070005 */ addiu $a3,$zero,0x5 -/* f04adec: 00408025 */ or $s0,$v0,$zero -/* f04adf0: 00002025 */ or $a0,$zero,$zero -/* f04adf4: 0fc45090 */ jal waypointSetHashThing -/* f04adf8: 00002825 */ or $a1,$zero,$zero -/* f04adfc: 2a010003 */ slti $at,$s0,0x3 -/* f04ae00: 14200020 */ bnez $at,.L0f04ae84 -/* f04ae04: 8fad00b4 */ lw $t5,0xb4($sp) -/* f04ae08: 11a0001e */ beqz $t5,.L0f04ae84 -/* f04ae0c: 27b000b4 */ addiu $s0,$sp,0xb4 -/* f04ae10: 8e020000 */ lw $v0,0x0($s0) -/* f04ae14: 27b10058 */ addiu $s1,$sp,0x58 -/* f04ae18: 00409025 */ or $s2,$v0,$zero -.L0f04ae1c: -/* f04ae1c: 8c440000 */ lw $a0,0x0($v0) -/* f04ae20: 24050002 */ addiu $a1,$zero,0x2 -/* f04ae24: 0fc456ac */ jal padUnpack -/* f04ae28: 02203025 */ or $a2,$s1,$zero -/* f04ae2c: 02c02025 */ or $a0,$s6,$zero -/* f04ae30: 02602825 */ or $a1,$s3,$zero -/* f04ae34: 02203025 */ or $a2,$s1,$zero -/* f04ae38: 0c00b706 */ jal func0002dc18 -/* f04ae3c: 24070020 */ addiu $a3,$zero,0x20 -/* f04ae40: 1040000c */ beqz $v0,.L0f04ae74 -/* f04ae44: 02802025 */ or $a0,$s4,$zero -/* f04ae48: 02a02825 */ or $a1,$s5,$zero -/* f04ae4c: 02203025 */ or $a2,$s1,$zero -/* f04ae50: 0c00b706 */ jal func0002dc18 -/* f04ae54: 24070020 */ addiu $a3,$zero,0x20 -/* f04ae58: 50400007 */ beqzl $v0,.L0f04ae78 -/* f04ae5c: 8e020004 */ lw $v0,0x4($s0) -/* f04ae60: 8e4f0000 */ lw $t7,0x0($s2) -/* f04ae64: 8fb800d8 */ lw $t8,0xd8($sp) -/* f04ae68: 24020001 */ addiu $v0,$zero,0x1 -/* f04ae6c: 10000006 */ b .L0f04ae88 -/* f04ae70: a70f0128 */ sh $t7,0x128($t8) -.L0f04ae74: -/* f04ae74: 8e020004 */ lw $v0,0x4($s0) -.L0f04ae78: -/* f04ae78: 26100004 */ addiu $s0,$s0,0x4 -/* f04ae7c: 5440ffe7 */ bnezl $v0,.L0f04ae1c -/* f04ae80: 00409025 */ or $s2,$v0,$zero -.L0f04ae84: -/* f04ae84: 00001025 */ or $v0,$zero,$zero -.L0f04ae88: -/* f04ae88: 8fbf0034 */ lw $ra,0x34($sp) -/* f04ae8c: 8fb00018 */ lw $s0,0x18($sp) -/* f04ae90: 8fb1001c */ lw $s1,0x1c($sp) -/* f04ae94: 8fb20020 */ lw $s2,0x20($sp) -/* f04ae98: 8fb30024 */ lw $s3,0x24($sp) -/* f04ae9c: 8fb40028 */ lw $s4,0x28($sp) -/* f04aea0: 8fb5002c */ lw $s5,0x2c($sp) -/* f04aea4: 8fb60030 */ lw $s6,0x30($sp) -/* f04aea8: 03e00008 */ jr $ra -/* f04aeac: 27bd00d8 */ addiu $sp,$sp,0xd8 -); +/** + * Check if chr has line of sight (I think?) to their target. If so, find a + * route to them, then iterate the route backwards (from target to chr). Find + * the first waypoint with line of sight and store it as the chr's pad preset. + */ +bool chrSetPadPresetToPadOnRouteToTarget(struct chrdata *chr) +{ + struct prop *target = chrGetTargetProp(chr); + struct prop *prop = chr->prop; + struct waypoint *fromwp; + struct waypoint *towp; + struct waypoint *waypoints[5]; + s32 numwaypoints; + s32 i; + struct pad pad; + + if (target->type != PROPTYPE_PLAYER || g_Vars.bondvisible) { + if (func0002dc18(&prop->pos, prop->rooms, &target->pos, CDTYPE_BG)) { + return false; + } + + fromwp = waypointFindClosestToPos(&prop->pos, prop->rooms); + towp = waypointFindClosestToPos(&target->pos, target->rooms); + + if (fromwp && towp) { + u32 hash = (g_Vars.lvframe60 >> 9) * 128 + chr->chrnum * 8; + + // Note from/to are swapped here, so the route is from target to chr + waypointSetHashThing(hash, hash); + numwaypoints = waypointFindRoute(towp, fromwp, waypoints, 5); + waypointSetHashThing(0, 0); + + if (numwaypoints >= 3) { + for (i = 0; waypoints[i] != NULL; i++) { + struct waypoint *wp = waypoints[i]; + + padUnpack(wp->padnum, PADFIELD_POS, &pad); + + if (func0002dc18(&target->pos, target->rooms, &pad.pos, CDTYPE_BG)) { + if (func0002dc18(&prop->pos, prop->rooms, &pad.pos, CDTYPE_BG)) { + chr->padpreset1 = wp->padnum; + return true; + } + } + } + } + } + } + + return false; +} GLOBAL_ASM( glabel func0f04aeb0 diff --git a/src/game/chr/chrai.c b/src/game/chr/chrai.c index 24e821a8a..0ffa4d065 100644 --- a/src/game/chr/chrai.c +++ b/src/game/chr/chrai.c @@ -83,7 +83,7 @@ bool (*g_CommandPointers[])(void) = { /*0x003f*/ aiIfCanSeeTarget, /*0x0040*/ aiIfTargetNearlyInSight, /*0x0041*/ aiIfNearlyInTargetsSight, - /*0x0042*/ aiIfInLoadedRoom, + /*0x0042*/ aiSetPadPresetToPadOnRouteToTarget, /*0x0043*/ aiIfSawTargetRecently, /*0x0044*/ aiIfHeardTargetRecently, /*0x0045*/ ai0045, diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index bb4e44537..c56068092 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -1409,9 +1409,9 @@ bool aiIfNearlyInTargetsSight(void) /** * @cmd 0042 */ -bool aiIfInLoadedRoom(void) +bool aiSetPadPresetToPadOnRouteToTarget(void) { - if (chrIsInLoadedRoom(g_Vars.chrdata)) { + if (chrSetPadPresetToPadOnRouteToTarget(g_Vars.chrdata)) { u8 *cmd = g_Vars.ailist + g_Vars.aioffset; g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[2]); } else { diff --git a/src/game/core.c b/src/game/core.c index c2f0f25f1..41ea425b9 100644 --- a/src/game/core.c +++ b/src/game/core.c @@ -162,7 +162,7 @@ void setVar80084040(u32 value) void func0f167af8(void) { - g_Vars.unk000320 = 0; + g_Vars.lockscreen = 0; g_Vars.unk0004d8 = -1; } @@ -1063,7 +1063,7 @@ Gfx *coreRender(Gfx *gdl) && !g_Vars.normmplayerisrunning && g_Vars.tickmode != TICKMODE_CUTSCENE) { if (var80084050 < 6) { - g_Vars.unk000320 = 1; + g_Vars.lockscreen = 1; } var80084050++; @@ -1075,9 +1075,9 @@ Gfx *coreRender(Gfx *gdl) g_Vars.currentplayer->unk1583_06 = func0f09eae4(); } - if (g_Vars.unk000320) { + if (g_Vars.lockscreen) { gdl = bviewRenderMotionBlur(gdl, 0xffffffff, 255); - g_Vars.unk000320--; + g_Vars.lockscreen--; } else if (var8009dfc0) { gdl = func0000b330(gdl); gdl = func0f15cb74(gdl); diff --git a/src/game/game_0b69d0.c b/src/game/game_0b69d0.c index 697231573..f0fd815b5 100644 --- a/src/game/game_0b69d0.c +++ b/src/game/game_0b69d0.c @@ -9535,14 +9535,14 @@ void setInvincible(bool enable) } } -void setGvars324(s32 arg0) +void setBondVisible(bool visible) { - g_Vars.unk000324 = arg0; + g_Vars.bondvisible = visible; } -void setGvars328(s32 arg0) +void setBondCollisions(bool enabled) { - g_Vars.bondcollisions = arg0; + g_Vars.bondcollisions = enabled; } void currentPlayerSetCameraMode(s32 mode) diff --git a/src/game/padhalllv.c b/src/game/padhalllv.c index 8ebc1f835..0e73f351a 100644 --- a/src/game/padhalllv.c +++ b/src/game/padhalllv.c @@ -441,7 +441,7 @@ struct waygroup *func0f114810(s32 *groupnums, s32 value, u32 mask) if (group->unk08 == value) { best = group; - if (g_Vars.unk000330 == 0) { + if (!g_Vars.padrandomroutes) { break; } @@ -562,7 +562,7 @@ struct waypoint *func0f114b7c(s32 *pointnums, s32 arg1, s32 groupnum, u32 mask) if (point->groupnum == groupnum && point->unk0c == arg1) { best = point; - if (g_Vars.unk000330 == 0) { + if (!g_Vars.padrandomroutes) { break; } @@ -722,7 +722,7 @@ void func0f11505c(struct waygroup *groupa, struct waygroup *groupb, struct waypo *pointa = groupapoint; *pointb = neighbour; - if (g_Vars.unk000330 == 0) { + if (!g_Vars.padrandomroutes) { break; } diff --git a/src/game/propobj.c b/src/game/propobj.c index c1b3183c8..6363daf2c 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -20308,7 +20308,7 @@ void cameraTick(struct prop *camprop) } } - if (g_Vars.unk000324 == 0 + if (g_Vars.bondvisible == false || (obj->flags & OBJFLAG_CAMERA_DISABLED) || (playerprop->chr->hidden & CHRHFLAG_CLOAKED)) { canseeplayer = false; @@ -23121,7 +23121,7 @@ bool chopperCheckTargetInSight(struct chopperobj *obj) bool visible = false; struct prop *target = chopperGetTargetProp(chopper); - if (target->type != PROPTYPE_PLAYER || g_Vars.unk000324) { + if (target->type != PROPTYPE_PLAYER || g_Vars.bondvisible) { visible = hasLineOfSight(&target->pos, target->rooms, &chopper->base.prop->pos, chopper->base.prop->rooms, 307, 16); } diff --git a/src/include/commands.h b/src/include/commands.h index 025b229e9..262032e18 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -612,9 +612,11 @@ label, /** - * Checks if the chr is in a loaded room. + * Checks if the current chr can see their target. If so, the chr's pad preset + * is set to a pad along the route to their target. The pad chosen is the pad + * on the route which is closest to the target and in sight of the current chr. */ -#define if_in_loaded_room(label) \ +#define set_pad_preset_to_pad_on_route_to_target(label) \ mkshort(0x0042), \ label, diff --git a/src/include/game/chr/chraction.h b/src/include/game/chr/chraction.h index 6a3333e4d..c0918967c 100644 --- a/src/include/game/chr/chraction.h +++ b/src/include/game/chr/chraction.h @@ -191,7 +191,7 @@ u32 func0f04a4ec(struct chrdata *chr, u8 arg1); 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); -u32 chrIsInLoadedRoom(struct chrdata *chr); +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); struct prop *chrSpawnAtCoord(s32 body, s32 head, struct coord *pos, s16 *room, f32 arg4, u8 *ailist, u32 flags); diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index ab4c5d003..adb1591cc 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -69,7 +69,7 @@ /*0x003f*/ bool aiIfCanSeeTarget(void); /*0x0040*/ bool aiIfTargetNearlyInSight(void); /*0x0041*/ bool aiIfNearlyInTargetsSight(void); -/*0x0042*/ bool aiIfInLoadedRoom(void); +/*0x0042*/ bool aiSetPadPresetToPadOnRouteToTarget(void); /*0x0043*/ bool aiIfSawTargetRecently(void); /*0x0044*/ bool aiIfHeardTargetRecently(void); /*0x0045*/ bool ai0045(void); diff --git a/src/include/gvars/gvars.h b/src/include/gvars/gvars.h index 2ebd694ae..c8ecb27b2 100644 --- a/src/include/gvars/gvars.h +++ b/src/include/gvars/gvars.h @@ -81,11 +81,11 @@ struct g_vars { /*000314*/ bool mplayerisrunning; // combat sim with any number of players, coop with human buddy, and counter-op /*000318*/ bool normmplayerisrunning; // combat sim with any number of players /*00031c*/ s32 lvmpbotlevel; - /*000320*/ s32 unk000320; - /*000324*/ s32 unk000324; + /*000320*/ s32 lockscreen; + /*000324*/ bool bondvisible; /*000328*/ bool bondcollisions; /*00032c*/ bool enableslopes; - /*000330*/ u32 unk000330; + /*000330*/ u32 padrandomroutes; /*000334*/ s32 maxprops; /*000338*/ struct prop *props; // pointer to array /*00033c*/ struct prop *list1head; diff --git a/src/lib/gvars.c b/src/lib/gvars.c index 5a1a63d44..000fb4359 100644 --- a/src/lib/gvars.c +++ b/src/lib/gvars.c @@ -16,7 +16,7 @@ void gvarsInit(void) g_Vars.lvframe60 = 0; g_Vars.lvframenum = 0; g_Vars.lvmpbotlevel = 0; - g_Vars.unk000320 = 0; + g_Vars.lockscreen = 0; g_Vars.diffframe60 = 1; g_Vars.lastframe240 = -1; g_Vars.thisframe240 = 0; @@ -44,7 +44,7 @@ void gvarsInit(void) g_Vars.pendingantiplayernum = 1; g_Vars.unk000458 = 0; g_Vars.numaibuddies = 0; - g_Vars.unk000324 = 1; + g_Vars.bondvisible = true; g_Vars.bondcollisions = true; g_Vars.tickmode = TICKMODE_0; g_Vars.roomcount = 350;