Discover and document AI commands if_target_nearly_in_sight and if_nearly_in_targets_sight and attempt to decompile func0002f308

This commit is contained in:
Ryan Dwyer 2020-05-28 20:21:16 +10:00
parent 48d54019a2
commit 2f8d66db55
16 changed files with 117 additions and 66 deletions

View File

@ -2066,7 +2066,7 @@ u8 func040d_cass[] = {
label(0x00)
set_stage_flag(STAGEFLAG_TOP_GUARDS_ATTACKING)
// Wait until Jo not in top room
// Wait until Cass not in top room
beginloop(0x2c)
if_chr_in_room(CHR_SELF, 0x00, 0x003a, /*goto*/ 0x20)
if_chr_in_room(CHR_SELF, 0x00, 0x003b, /*goto*/ 0x20)
@ -2079,9 +2079,9 @@ u8 func040d_cass[] = {
label(0x00)
chr_toggle_p1p2(CHR_SELF)
set_target_chr(CHR_P1P2)
if_within_units_of_sight(30, /*goto*/ 0x20)
if_nearly_in_targets_sight(30, /*goto*/ 0x20)
set_target_chr(CHR_ANTI)
if_within_units_of_sight(30, /*goto*/ 0x20)
if_nearly_in_targets_sight(30, /*goto*/ 0x20)
goto_next(0x2d)
label(0x20)

View File

@ -452,7 +452,7 @@ u8 func0403_jon_combat[] = {
beginloop(0x04)
if_timer_gt(240, /*goto*/ 0x58)
if_within_units_of_sight(30, /*goto*/ 0x58)
if_nearly_in_targets_sight(30, /*goto*/ 0x58)
endloop(0x04)
label(0x58)

View File

@ -1804,9 +1804,9 @@ u8 func0420_trent_running[] = {
if_chr_stopped(/*goto*/ 0x08)
goto_first(0x0a)
// Player not in sight
// Player not in sight, or Trent has reached his destination
label(0x08)
if_within_units_of_sight(30, /*goto*/ 0x31)
if_nearly_in_targets_sight(30, /*goto*/ 0x31)
goto_next(0x08)
label(0x31)

View File

@ -3087,15 +3087,15 @@ u8 func0427_init_posttakeover_guard[] = {
u8 func0428_posttakeover_guard[] = {
beginloop(0x00)
set_target_chr(CHR_BOND)
if_within_units_of_sight(30, /*goto*/ 0x31)
if_nearly_in_targets_sight(30, /*goto*/ 0x31)
if_chr_death_animation_finished(CHR_COOP, /*goto*/ 0x02)
set_target_chr(CHR_COOP)
if_within_units_of_sight(30, /*goto*/ 0x31)
if_nearly_in_targets_sight(30, /*goto*/ 0x31)
label(0x02)
if_chr_death_animation_finished(CHR_ANTI, /*goto*/ 0x02)
set_target_chr(CHR_ANTI)
if_within_units_of_sight(30, /*goto*/ 0x31)
if_nearly_in_targets_sight(30, /*goto*/ 0x31)
label(0x02)
unset_self_chrflag(CHRCFLAG_HIDDEN)
@ -4035,14 +4035,14 @@ u8 func0417_remove_or_unalert[] = {
label(0x00)
yield
set_target_chr(CHR_BOND)
if_within_units_of_sight(30, /*goto*/ 0x02)
if_nearly_in_targets_sight(30, /*goto*/ 0x02)
if_chr_death_animation_finished(CHR_COOP, /*goto*/ 0x31)
set_target_chr(CHR_COOP)
if_within_units_of_sight(30, /*goto*/ 0x02)
if_nearly_in_targets_sight(30, /*goto*/ 0x02)
label(0x31)
if_chr_death_animation_finished(CHR_ANTI, /*goto*/ 0x04)
set_target_chr(CHR_ANTI)
if_within_units_of_sight(30, /*goto*/ 0x02)
if_nearly_in_targets_sight(30, /*goto*/ 0x02)
label(0x04)
yield
chr_drop_weapon(CHR_SELF)
@ -4060,14 +4060,14 @@ u8 func0418_remove_or_cower[] = {
label(0x00)
yield
set_target_chr(CHR_BOND)
if_within_units_of_sight(30, /*goto*/ 0x02)
if_nearly_in_targets_sight(30, /*goto*/ 0x02)
if_chr_death_animation_finished(CHR_COOP, /*goto*/ 0x31)
set_target_chr(CHR_COOP)
if_within_units_of_sight(30, /*goto*/ 0x02)
if_nearly_in_targets_sight(30, /*goto*/ 0x02)
label(0x31)
if_chr_death_animation_finished(CHR_ANTI, /*goto*/ 0x04)
set_target_chr(CHR_ANTI)
if_within_units_of_sight(30, /*goto*/ 0x02)
if_nearly_in_targets_sight(30, /*goto*/ 0x02)
label(0x04)
yield
remove_chr(CHR_SELF)

View File

@ -922,11 +922,11 @@ u8 func0402_elvis_follow_and_reactive_teleportals[] = {
u8 func0433_unused[] = {
beginloop(0x04)
set_target_chr(CHR_BOND)
if_within_units_of_sight(30, /*goto*/ 0x06)
if_nearly_in_targets_sight(30, /*goto*/ 0x06)
set_target_chr(CHR_COOP)
if_within_units_of_sight(30, /*goto*/ 0x06)
if_nearly_in_targets_sight(30, /*goto*/ 0x06)
set_target_chr(CHR_ANTI)
if_within_units_of_sight(30, /*goto*/ 0x06)
if_nearly_in_targets_sight(30, /*goto*/ 0x06)
goto_next(0x2e)
label(0x06)

View File

@ -1685,10 +1685,10 @@ u8 func0413_bugspotter[] = {
label(0x03)
chr_toggle_p1p2(CHR_SELF)
set_target_chr(CHR_P1P2)
if_within_units_of_sight(30, /*goto*/ 0x03)
if_nearly_in_targets_sight(30, /*goto*/ 0x03)
chr_toggle_p1p2(CHR_SELF)
set_target_chr(CHR_P1P2)
if_within_units_of_sight(30, /*goto*/ 0x03)
if_nearly_in_targets_sight(30, /*goto*/ 0x03)
goto_next(0x04)
label(0x03)
goto_first(0x07)
@ -1703,7 +1703,7 @@ u8 func0413_bugspotter[] = {
label(0x03)
chr_toggle_p1p2(CHR_SELF)
set_target_chr(CHR_P1P2)
if_within_units_of_sight(30, /*goto*/ 0x03)
if_nearly_in_targets_sight(30, /*goto*/ 0x03)
goto_next(0x04)
label(0x03)
goto_first(0x07)

View File

@ -1157,7 +1157,7 @@ u8 func1004_check_saucer_destroyed[] = {
endlist
};
u8 func1005_check_experiemnt_destroyed_pointless[] = {
u8 func1005_check_experiment_destroyed_pointless[] = {
// This is a pointless function
beginloop(0x04)
if_object_in_good_condition(OBJ_EXPERIMENT, /*goto*/ 0x2c)
@ -1887,14 +1887,14 @@ u8 func0414_unload[] = {
label(0x2c)
yield
set_target_chr(CHR_BOND)
if_within_units_of_sight(30, /*goto*/ 0x06)
if_nearly_in_targets_sight(30, /*goto*/ 0x06)
if_chr_death_animation_finished(CHR_COOP, /*goto*/ 0x2c)
set_target_chr(CHR_COOP)
if_within_units_of_sight(30, /*goto*/ 0x06)
if_nearly_in_targets_sight(30, /*goto*/ 0x06)
label(0x2c)
if_chr_death_animation_finished(CHR_ANTI, /*goto*/ 0x08)
set_target_chr(CHR_ANTI)
if_within_units_of_sight(30, /*goto*/ 0x06)
if_nearly_in_targets_sight(30, /*goto*/ 0x06)
label(0x08)
yield
chr_drop_weapon(CHR_SELF)
@ -1912,7 +1912,7 @@ struct ailist ailists[] = {
{ func1002_intro, 0x1002 },
{ func1003_check_experiment_destroyed, 0x1003 },
{ func1004_check_saucer_destroyed, 0x1004 },
{ func1005_check_experiemnt_destroyed_pointless, 0x1005 },
{ func1005_check_experiment_destroyed_pointless, 0x1005 },
{ func1006_activate_alarm, 0x1006 },
{ func1007_disable_pods, 0x1007 },
{ func1008_check_console, 0x1008 },

View File

@ -30597,18 +30597,18 @@ s32 chrGetDistanceLostToTargetInLastSecond(struct chrdata *chr)
return curdist - olddist;
}
bool func0f04c6b4(struct chrdata *chr, u32 distance)
bool chrIsTargetNearlyInSight(struct chrdata *chr, u32 distance)
{
struct prop *prop = chrGetTargetProp(chr);
struct prop *target = chrGetTargetProp(chr);
return func0002f450(&chr->prop->pos, &chr->prop->rooms[0], &prop->pos, distance, 32);
return func0002f450(&chr->prop->pos, &chr->prop->rooms[0], &target->pos, distance, 32);
}
bool func0f04c71c(struct chrdata *chr, u32 distance)
bool chrIsNearlyInTargetsSight(struct chrdata *chr, u32 distance)
{
struct prop *prop = chrGetTargetProp(chr);
struct prop *target = chrGetTargetProp(chr);
return func0002f450(&prop->pos, &prop->rooms[0], &chr->prop->pos, distance, 32);
return func0002f450(&target->pos, &target->rooms[0], &chr->prop->pos, distance, 32);
}
GLOBAL_ASM(

View File

@ -82,8 +82,8 @@ bool (*g_CommandPointers[])(void) = {
/*0x003d*/ aiIfSawInjury,
/*0x003e*/ aiIfSawDeath,
/*0x003f*/ aiIfSeesPlayer,
/*0x0040*/ ai0040,
/*0x0041*/ ai0041,
/*0x0040*/ aiIfTargetNearlyInSight,
/*0x0041*/ aiIfNearlyInTargetsSight,
/*0x0042*/ aiIfInLoadedRoom,
/*0x0043*/ aiIfSawTargetRecently,
/*0x0044*/ aiIfHeardTargetRecently,

View File

@ -1377,12 +1377,12 @@ bool ai017a(void)
/**
* @cmd 0040
*/
bool ai0040(void)
bool aiIfTargetNearlyInSight(void)
{
u8 *cmd = g_Vars.ailist + g_Vars.aioffset;
u32 flags = (cmd[3] << 16) | (cmd[4] << 8) | cmd[5] | (cmd[2] << 24);
u32 distance = (cmd[3] << 16) | (cmd[4] << 8) | cmd[5] | (cmd[2] << 24);
if (func0f04c6b4(g_Vars.chrdata, flags)) {
if (chrIsTargetNearlyInSight(g_Vars.chrdata, distance)) {
cmd = g_Vars.ailist + g_Vars.aioffset;
g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[6]);
} else {
@ -1395,12 +1395,12 @@ bool ai0040(void)
/**
* @cmd 0041
*/
bool ai0041(void)
bool aiIfNearlyInTargetsSight(void)
{
u8 *cmd = g_Vars.ailist + g_Vars.aioffset;
u32 value = (cmd[3] << 16) | (cmd[4] << 8) | cmd[5] | (cmd[2] << 24);
u32 distance = (cmd[3] << 16) | (cmd[4] << 8) | cmd[5] | (cmd[2] << 24);
if (func0f04c71c(g_Vars.chrdata, value)) {
if (chrIsNearlyInTargetsSight(g_Vars.chrdata, distance)) {
cmd = g_Vars.ailist + g_Vars.aioffset;
g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[6]);
} else {

View File

@ -484,7 +484,7 @@ u8 func0006_unalerted[] = {
increase_self_alertness(100)
say_quip(CHR_BOND, QUIP_SHOTUNALERT, 0xff, 0x03, 0x00, BANK_0, 0x00, 0x00)
set_target_chr(CHR_BOND)
if_within_units_of_sight(30, /*goto*/ 0x13)
if_nearly_in_targets_sight(30, /*goto*/ 0x13)
goto_next(0x16)
label(0x13)
@ -498,7 +498,7 @@ u8 func0006_unalerted[] = {
label(0x16)
if_chr_death_animation_finished(CHR_COOP, /*goto*/ 0x16)
set_target_chr(CHR_COOP)
if_within_units_of_sight(30, /*goto*/ 0x13)
if_nearly_in_targets_sight(30, /*goto*/ 0x13)
goto_next(0x16)
label(0x13)
@ -592,7 +592,7 @@ u8 func0006_unalerted[] = {
label(0x7d)
dprint 'E','X','A','M',' ','B','O','D','Y','D','O','N','E','\n',0,
set_target_chr(CHR_BOND)
if_within_units_of_sight(30, /*goto*/ 0x13)
if_nearly_in_targets_sight(30, /*goto*/ 0x13)
goto_next(0x16)
label(0x13)
@ -604,7 +604,7 @@ u8 func0006_unalerted[] = {
label(0x16)
if_chr_death_animation_finished(CHR_COOP, /*goto*/ 0x16)
set_target_chr(CHR_COOP)
if_within_units_of_sight(30, /*goto*/ 0x13)
if_nearly_in_targets_sight(30, /*goto*/ 0x13)
goto_next(0x16)
label(0x13)
@ -1431,9 +1431,9 @@ u8 func0007_alerted[] = {
if_rand_gt(100, /*goto*/ 0x13)
if_player_looking_at_something_maybe(0x1e, 0x01, 0x00, /*goto*/ 0x16)
label(0x13)
if_within_units_of_sight(30, /*goto*/ 0x5f)
if_nearly_in_targets_sight(30, /*goto*/ 0x5f)
label(0x16)
if_within_units_of_sight(30, /*goto*/ 0x16)
if_nearly_in_targets_sight(30, /*goto*/ 0x16)
if_player_using_cmp150_or_ar34(/*goto*/ 0x69)
if_distance_to_target_gt(2000, /*goto*/ 0x61)
goto_next(0x16)
@ -1443,7 +1443,7 @@ u8 func0007_alerted[] = {
label(0x16)
dprint 'O','K','F','O','R','C','O','V','E','R','\n',0,
if_in_disarm_range(/*goto*/ 0x5b)
if_within_units_of_sight(30, /*goto*/ 0x5b)
if_nearly_in_targets_sight(30, /*goto*/ 0x5b)
if_chr_in_view(/*goto*/ 0x5b)
goto_next(0x56)
@ -1531,7 +1531,7 @@ u8 func0007_alerted[] = {
if_dangerous_object_nearby(3, /*goto*/ LABEL_FLEE_GRENADE)
chr_toggle_p1p2(CHR_SELF)
set_target_chr(CHR_P1P2)
if_within_units_of_sight(30, /*goto*/ 0x5f)
if_nearly_in_targets_sight(30, /*goto*/ 0x5f)
if_timer_gt(240, /*goto*/ 0x61)
if_self_flag_bankx_eq(CHRFLAG0_CAN_FLANK, FALSE, BANK_0, /*goto*/ 0x93)
if_has_orders(/*goto*/ 0x84)
@ -1877,7 +1877,7 @@ u8 func0007_alerted[] = {
try_face_entity(ENTITYTYPE_TARGET, 0, /*goto*/ 0x4b)
beginloop(0x4b)
if_within_units_of_sight(30, /*goto*/ 0x42)
if_nearly_in_targets_sight(30, /*goto*/ 0x42)
if_chr_in_view(/*goto*/ 0x42)
if_chr_target_eq(CHR_SELF, CHR_P1P2, FALSE, /*goto*/ 0xee)
goto_next(0xef)
@ -1886,7 +1886,7 @@ u8 func0007_alerted[] = {
chr_toggle_p1p2(CHR_SELF)
if_chr_target_eq(CHR_SELF, CHR_P1P2, FALSE, /*goto*/ 0xee)
set_target_chr(CHR_P1P2)
if_within_units_of_sight(30, /*goto*/ 0x42)
if_nearly_in_targets_sight(30, /*goto*/ 0x42)
if_chr_in_view(/*goto*/ 0x42)
label(0xee)
chr_toggle_p1p2(CHR_SELF)
@ -1915,14 +1915,14 @@ u8 func0007_alerted[] = {
if_self_flag_bankx_eq(CHRFLAG0_CAN_FLANK, FALSE, BANK_0, /*goto*/ 0x93)
if_has_orders(/*goto*/ 0x84)
label(0x93)
if_within_units_of_sight(30, /*goto*/ 0x42)
if_nearly_in_targets_sight(30, /*goto*/ 0x42)
if_chr_target_eq(CHR_SELF, CHR_P1P2, FALSE, /*goto*/ 0xee)
goto_next(0xef)
label(0xee)
chr_toggle_p1p2(CHR_SELF)
if_chr_target_eq(CHR_SELF, CHR_P1P2, FALSE, /*goto*/ 0xee)
set_target_chr(CHR_P1P2)
if_within_units_of_sight(30, /*goto*/ 0x42)
if_nearly_in_targets_sight(30, /*goto*/ 0x42)
label(0xee)
chr_toggle_p1p2(CHR_SELF)
set_target_chr(CHR_P1P2)

View File

@ -592,15 +592,24 @@
mkshort(0x003f), \
label,
#define cmd0040(flags, label) \
/**
* Checks if the current chr's target is in sight of the current chr, or would
* be in sight if the target were to move <distance> units left or right in a
* circle around the current chr.
*/
#define if_target_nearly_in_sight(distance, label) \
mkshort(0x0040), \
mkword(flags), \
mkword(distance), \
label,
// Not sure about this.
#define if_within_units_of_sight(value, label) \
/**
* Checks if the current chr is in sight of their target, or would be in sight
* if the current chr were to move <distance> units left or right in a circle
* around their target.
*/
#define if_nearly_in_targets_sight(distance, label) \
mkshort(0x0041), \
mkword(value), \
mkword(distance), \
label,
/**

View File

@ -317,8 +317,8 @@ struct prop *chrSpawnAtChr(struct chrdata *basechr, s32 body, s32 head, u32 chrn
s16 chrGoToCover(struct chrdata *chr, u8 speed);
void chrAddTargetToBdlist(struct chrdata *chr);
s32 chrGetDistanceLostToTargetInLastSecond(struct chrdata *chr);
bool func0f04c6b4(struct chrdata *chr, u32 distance);
bool func0f04c71c(struct chrdata *chr, u32 distance);
bool chrIsTargetNearlyInSight(struct chrdata *chr, u32 distance);
bool chrIsNearlyInTargetsSight(struct chrdata *chr, u32 distance);
s16 *teamGetChrIds(s32 team_id);
s16 *squadronGetChrIds(s32 squadron_id);
void audioMarkAsRecentlyPlayed(s16 audioid);

View File

@ -67,8 +67,8 @@
/*0x003d*/ bool aiIfSawInjury(void);
/*0x003e*/ bool aiIfSawDeath(void);
/*0x003f*/ bool aiIfSeesPlayer(void);
/*0x0040*/ bool ai0040(void);
/*0x0041*/ bool ai0041(void);
/*0x0040*/ bool aiIfTargetNearlyInSight(void);
/*0x0041*/ bool aiIfNearlyInTargetsSight(void);
/*0x0042*/ bool aiIfInLoadedRoom(void);
/*0x0043*/ bool aiIfSawTargetRecently(void);
/*0x0044*/ bool aiIfHeardTargetRecently(void);

View File

@ -108,7 +108,7 @@ u32 func0002d8b8(void);
u32 func0002d95c(void);
u32 func0002da50(void);
u32 func0002dac8(void);
u32 func0002db98(void);
bool func0002db98(struct coord *viewpos, s16 *rooms, struct coord *targetpos, s32 arg3, u32 arg4);
u32 func0002dc18(struct coord *coord, s16 *room, struct coord *coord2, s32 arg3);
bool hasLineOfSight(struct coord *coord, s16 *room, struct coord *coord2, s16 *room2, s32 arg4, s32 arg5);
u32 func0002dcd0(void);
@ -127,7 +127,7 @@ u32 func0002e9d8(void);
u32 func0002eb84(void);
u32 func0002ed30(void);
u32 func0002f02c(void);
bool func0002f308(struct coord *pos, s16 *rooms, struct coord *pos2, f32 distance, s32 arg4, s32 arg5);
bool func0002f450(struct coord *pos, s16 *rooms, struct coord *pos2, f32 distance, s32 arg4);
bool func0002f308(struct coord *viewpos, s16 *rooms, struct coord *targetpos, f32 distance, s32 arg4, u16 arg5);
bool func0002f450(struct coord *viewpos, s16 *rooms, struct coord *targetpos, f32 distance, s32 arg4);
#endif

View File

@ -13498,7 +13498,49 @@ glabel func0002f308
/* 2f44c: 27bd0048 */ addiu $sp,$sp,0x48
);
bool func0002f450(struct coord *pos, s16 *rooms, struct coord *pos2, f32 distance, s32 arg4)
//bool func0002f308(struct coord *viewpos, s16 *rooms, struct coord *targetpos, f32 distance, s32 arg4, u16 arg5)
//{
// struct coord diff; // sp60
// f32 x; // sp56
// f32 z; // sp52
// struct coord vector; // sp40
//
// if (func0002db98(viewpos, rooms, targetpos, arg4, arg5)) {
// return true;
// }
//
// vector.x = targetpos->x - viewpos->x;
// vector.y = 0;
// vector.z = targetpos->z - viewpos->z;
//
// // 378
// scaleTo1(&vector.x, &vector.y, &vector.z);
//
// x = vector.x * distance;
// z = vector.z * distance;
//
// diff.x = targetpos->x - z;
// diff.y = targetpos->y;
// diff.z = targetpos->z + x;
//
// // 3d0
// if (func0002db98(viewpos, rooms, &diff, arg4, arg5)) {
// return true;
// }
//
// diff.x = targetpos->x + z;
// diff.y = targetpos->y;
// diff.z = targetpos->z - x;
//
// // 420
// if (func0002db98(viewpos, rooms, &diff, arg4, arg5)) {
// return true;
// }
//
// return false;
//}
bool func0002f450(struct coord *viewpos, s16 *rooms, struct coord *targetpos, f32 distance, s32 arg4)
{
return func0002f308(pos, rooms, pos2, distance, arg4, 8);
return func0002f308(viewpos, rooms, targetpos, distance, arg4, 8);
}