diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index d0e2f7a18..aa8b20dd8 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -13428,7 +13428,7 @@ bool func0f03af44(struct chrdata *chr, u32 anim_id, f32 fstartframe, f32 fendfra } GLOBAL_ASM( -glabel func0f03afac +glabel chrTryRunFromTarget /* f03afac: 27bdff78 */ addiu $sp,$sp,-136 /* f03afb0: afbf002c */ sw $ra,0x2c($sp) /* f03afb4: afb00028 */ sw $s0,0x28($sp) @@ -13580,6 +13580,77 @@ glabel func0f03afac /* f03b1dc: 00000000 */ sll $zero,$zero,0x0 ); +//bool chrTryRunFromTarget(struct chrdata *chr) +//{ +// struct prop *target = chrGetTargetProp(chr); // sp132 +// struct prop *prop = chr->prop; +// f32 ymax; // sp124 +// f32 ymin; // sp120 +// f32 width; // sp116 +// struct coord dst; // sp104 +// s16 rooms[8]; // sp88 +// struct coord diff; // sp76 +// f32 distance; +// +// if (!chrIsReadyForOrders(chr) || !target) { +// return false; +// } +// +// diff.x = target->pos.x - prop->pos.x; +// diff.y = 0; +// diff.z = target->pos.z - prop->pos.z; +// +// distance = sqrtf(diff.z * diff.z + diff.x * diff.x); +// +// // 02c +// // Scale diff into range -1 to +1 +// diff.x *= (1 / distance); +// diff.y *= (1 / distance); +// diff.z *= (1 / distance); +// +// // Set dst to 1000 units in the opposite direction +// dst.x = prop->pos.x - diff.x * 1000; +// dst.y = prop->pos.y; +// dst.z = prop->pos.z - diff.z * 1000; +// +// propGetBbox(prop, &width, &ymax, &ymin); +// +// // 098 +// // If dst runs into a wall, set it to closest valid spot +// if (!func0002d7c0(&prop->pos, prop->rooms, &dst, 0x33, 1, +// ymax - prop->pos.y, ymin - prop->pos.y)) { +// func00024ebc(&dst, 8788, "chraction.c"); // var7f1a8ad8 +// } +// +// // 0f0 +// // Adjust dst to be two chr widths closer to avoid collision with wall +// dst.x += diff.x * width + diff.x * width; +// dst.z += diff.z * width + diff.z * width; +// +// if (func0f036974(prop, &dst)) { +// u32 speed = SPEED_RUN; +// +// if (CHRRACE(chr) == RACE_HUMAN) { +// f32 dist = chrGetDistanceToCoord(chr, &dst); +// +// if (dist > 100) { +// speed = SPEED_RUN; +// } else if (dist < 50) { +// speed = SPEED_WALK; +// } else { +// speed = SPEED_JOG; +// } +// } +// +// func0f065e74(&prop->pos, prop->rooms, &dst, rooms); +// chrGoToPos(chr, &dst, rooms, speed); +// +// return true; +// } +// +// return false; +//} + GLOBAL_ASM( glabel func0f03b1e0 .late_rodata diff --git a/src/game/chr/chrai.c b/src/game/chr/chrai.c index 37cb4f6cb..eec38a203 100644 --- a/src/game/chr/chrai.c +++ b/src/game/chr/chrai.c @@ -60,7 +60,7 @@ bool (*g_CommandPointers[])(void) = { /*0x0027*/ aiTryStartAlarm, /*0x0028*/ aiActivateAlarm, /*0x0029*/ aiDeactivateAlarm, - /*0x002a*/ ai002a, + /*0x002a*/ aiTryRunFromTarget, /*0x002b*/ aiTryJogToTargetProp, /*0x002c*/ aiTryWalkToTargetProp, /*0x002d*/ aiTryRunToTargetProp, diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index c95d5eca3..f74b86dec 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -976,9 +976,9 @@ bool aiDeactivateAlarm(void) /** * @cmd 002a */ -bool ai002a(void) +bool aiTryRunFromTarget(void) { - if (func0f03afac(g_Vars.chrdata)) { + if (chrTryRunFromTarget(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/include/commands.h b/src/include/commands.h index 12e77291b..22ae52efc 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -404,7 +404,12 @@ #define deactivate_alarm \ mkshort(0x0029), -#define cmd002a(label) \ +/** + * Makes the chr attempt to run 1000 units in the opposite direction to their + * target, without any pathfinding. If this destination is obstructed by a wall + * then they'll run as far as they can and stop at the wall. + */ +#define try_run_from_target(label) \ mkshort(0x002a), \ label, diff --git a/src/include/game/chr/chraction.h b/src/include/game/chr/chraction.h index 86e23f02f..7e575174f 100644 --- a/src/include/game/chr/chraction.h +++ b/src/include/game/chr/chraction.h @@ -59,7 +59,7 @@ u32 func0f03645c(void); u32 func0f03654c(void); bool propHasClearLineToPos(struct prop *prop, struct coord *dstpos, struct coord *vector); bool func0f036918(struct prop *prop, struct coord *coord, f32 arg2); -u32 func0f036974(void); +bool func0f036974(struct prop *prop, struct coord *coord); void chrGetSideVectorToTarget(struct chrdata *chr, bool side, struct coord *vector); u32 chrCanRollInDirection(struct chrdata *chr, bool side, f32 distance); void chrGetSideVector(struct chrdata *chr, bool side, struct coord *vector); @@ -102,7 +102,7 @@ u32 func0f03a3ec(struct chrdata *chr, u32 arg1, u32 arg2, u32 arg3, u32 arg4); u32 func0f03a894(struct chrdata *chr, s32 pad, s32 arg2); u32 func0f03abd0(void); u32 func0f03aca0(struct chrdata *chr, u32 arg1, u32 arg2); -u32 func0f03afac(struct chrdata *chr); +u32 chrTryRunFromTarget(struct chrdata *chr); u32 func0f03b1e0(struct chrdata *chr); bool chrDropItem(struct chrdata *chr, u32 modelnum, u32 weaponnum); void func0f03ba44(struct chrdata *chr, u32 arg1, u32 arg2, u32 arg3); diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index 8dd6ed6b9..4622c23f5 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -45,7 +45,7 @@ /*0x0027*/ bool aiTryStartAlarm(void); /*0x0028*/ bool aiActivateAlarm(void); /*0x0029*/ bool aiDeactivateAlarm(void); -/*0x002a*/ bool ai002a(void); +/*0x002a*/ bool aiTryRunFromTarget(void); /*0x002b*/ bool aiTryJogToTargetProp(void); /*0x002c*/ bool aiTryWalkToTargetProp(void); /*0x002d*/ bool aiTryRunToTargetProp(void); diff --git a/src/include/lib/lib_233c0.h b/src/include/lib/lib_233c0.h index 9bc5ba656..43c49787a 100644 --- a/src/include/lib/lib_233c0.h +++ b/src/include/lib/lib_233c0.h @@ -27,7 +27,7 @@ void func00024e4c(struct coord *arg0, struct coord *arg1, u32 line, char *file); f32 func00024e98(void); u32 func00024ea4(void); struct prop *func00024eb0(void); -u32 func00024ebc(void); +void func00024ebc(struct coord *pos, u32 line, char *file); u32 func00024ee8(void); u32 func00024f10(void); u32 func00024f6c(void); @@ -102,7 +102,7 @@ u32 func0002d15c(void); u32 func0002d3b0(void); bool func0002d6ac(struct coord *pos, s16 *rooms, struct coord *targetpos, u32 arg3, u32 arg4, f32 arg5, f32 arg6); u32 func0002d72c(void); -u32 func0002d7c0(void); +bool func0002d7c0(struct coord *pos, s16 *rooms, struct coord *arg2, u32 arg3, u32 arg4, f32 arg5, f32 arg6); u32 func0002d840(void); u32 func0002d8b8(void); u32 func0002d95c(void);