From 0c9bb52b78571ef57d10dee052ec284eb2b7a3b4 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 5 Feb 2021 22:04:01 +1000 Subject: [PATCH] Rename functions and an AI command relating to FOV checks --- src/files/setup/setupame.c | 4 +- src/files/setup/setupazt.c | 2 +- src/files/setup/setupcave.c | 6 +-- src/files/setup/setupdepo.c | 2 +- src/files/setup/setupdish.c | 8 ++-- src/files/setup/setuplee.c | 6 +-- src/files/setup/setuplip.c | 4 +- src/files/setup/setuppam.c | 2 +- src/files/setup/setupsho.c | 6 +-- src/files/setup/setuptra.c | 2 +- src/files/setup/setupwax.c | 2 +- src/game/chr/chraction.c | 14 +++--- src/game/chr/chrai.c | 2 +- src/game/chr/chraicommands.c | 30 ++++++++----- src/game/data/ailists.c | 44 +++++++++--------- src/include/commands.h | 67 ++++++++++++++++++++++------ src/include/game/chr/chraction.h | 4 +- src/include/game/chr/chraicommands.h | 2 +- 18 files changed, 126 insertions(+), 81 deletions(-) diff --git a/src/files/setup/setupame.c b/src/files/setup/setupame.c index 24fb33440..01752cb52 100644 --- a/src/files/setup/setupame.c +++ b/src/files/setup/setupame.c @@ -1817,7 +1817,7 @@ u8 func0414_programmer[] = { if_can_see_target(/*goto*/ 0x06) goto_next(0x2c) label(0x06) - if_player_looking_at_something_maybe(0x28, 0x01, 0x00, /*goto*/ LABEL_JO_SPEAK) + if_within_targets_fovx_by_angle(40, /*goto*/ LABEL_JO_SPEAK) label(0x2c) endloop(0x0d) @@ -1887,7 +1887,7 @@ u8 func0414_programmer[] = { if_chr_stopped(/*goto*/ LABEL_LOG_ON) if_stage_flag_eq(STAGEFLAG_PROGRAMMER_INJURED, TRUE, /*goto*/ 0x06) if_distance_to_target_lt(500, /*goto*/ 0x06) - if_player_looking_at_something_maybe(0x28, 0x01, 0x00, /*goto*/ 0x06) + if_within_targets_fovx_by_angle(40, /*goto*/ 0x06) if_chr_in_room(CHR_PROGRAMMER, 0x00, 0x007d, /*goto*/ 0x06) if_chr_in_room(CHR_PROGRAMMER, 0x00, 0x007e, /*goto*/ 0x06) if_chr_in_room(CHR_PROGRAMMER, 0x00, 0x007f, /*goto*/ 0x06) diff --git a/src/files/setup/setupazt.c b/src/files/setup/setupazt.c index 9fb06a94a..11b049ec5 100644 --- a/src/files/setup/setupazt.c +++ b/src/files/setup/setupazt.c @@ -1421,7 +1421,7 @@ u8 func041a_pres_clone[] = { chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) if_alertness(99, OPERATOR_GREATER_THAN, /*goto*/ 0x31) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x08) + if_target_outside_my_yvisang(/*goto*/ 0x08) if_target_in_sight(/*goto*/ 0x31) label(0x08) endloop(0x06) diff --git a/src/files/setup/setupcave.c b/src/files/setup/setupcave.c index ed27749ef..f1a8fcaf1 100644 --- a/src/files/setup/setupcave.c +++ b/src/files/setup/setupcave.c @@ -1193,7 +1193,7 @@ u8 func0407_stewardess[] = { if_distance_to_target_gt(500, /*goto*/ 0x31) if_alertness(99, OPERATOR_GREATER_THAN, /*goto*/ 0x04) label(0x31) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x02) + if_target_outside_my_yvisang(/*goto*/ 0x02) if_target_in_sight(/*goto*/ 0x04) label(0x02) if_timer_gt(120, /*goto*/ 0x16) @@ -1220,7 +1220,7 @@ u8 func0407_stewardess[] = { if_saw_death(0x00, /*goto*/ 0x0f) label(0x31) if_alertness(99, OPERATOR_GREATER_THAN, /*goto*/ 0x04) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x02) + if_target_outside_my_yvisang(/*goto*/ 0x02) if_target_in_sight(/*goto*/ 0x04) label(0x02) if_chr_stopped(/*goto*/ 0x0b) @@ -1291,7 +1291,7 @@ u8 func0407_stewardess[] = { label(0x75) if_alertness(99, OPERATOR_GREATER_THAN, /*goto*/ 0x4e) dprint 'W','A','L','K','I','N','G','\n',0, - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x31) + if_target_outside_my_yvisang(/*goto*/ 0x31) if_target_in_sight(/*goto*/ 0x02) label(0x31) if_distance_to_chr_lt(200, 0xfb, /*goto*/ 0x4a) diff --git a/src/files/setup/setupdepo.c b/src/files/setup/setupdepo.c index 17a2f04cd..0f51c7286 100644 --- a/src/files/setup/setupdepo.c +++ b/src/files/setup/setupdepo.c @@ -2305,7 +2305,7 @@ u8 func0412_cloak_guard[] = { goto_next(0x06) label(0x2c) - if_player_looking_at_something_maybe(0x0f, 0x01, 0x00, /*goto*/ 0x0e) + if_within_targets_fovx_by_angle(15, /*goto*/ 0x0e) label(0x06) if_can_see_attack_target(/*goto*/ 0x2c) goto_next(0x0d) diff --git a/src/files/setup/setupdish.c b/src/files/setup/setupdish.c index 673009474..1ef2fb85b 100644 --- a/src/files/setup/setupdish.c +++ b/src/files/setup/setupdish.c @@ -631,7 +631,7 @@ u8 func041e_colleague[] = { goto_first(0x59) label(0x06) - if_player_looking_at_something_maybe(0x14, 0x01, 0x00, /*goto*/ 0x06) + if_within_targets_fovx_by_angle(20, /*goto*/ 0x06) goto_first(0x59) label(0x06) @@ -658,7 +658,7 @@ u8 func041e_colleague[] = { goto_next(0x2f) label(0x06) - if_player_looking_at_something_maybe(0x14, 0x01, 0x00, /*goto*/ 0x30) + if_within_targets_fovx_by_angle(20, /*goto*/ 0x30) label(0x2f) if_chr_idle(/*goto*/ 0x06) if_self_flag_bankx_eq(CHRFLAG1_DOINGIDLEANIMATION, FALSE, BANK_1, /*goto*/ 0x7f) @@ -4052,7 +4052,7 @@ u8 func042f_holo2_part2[] = { endloop(0x08) beginloop(0x04) - if_player_looking_at_something_maybe(0x14, 0x01, 0x00, /*goto*/ 0x06) + if_within_targets_fovx_by_angle(20, /*goto*/ 0x06) goto_next(0x2f) label(0x06) @@ -5153,7 +5153,7 @@ u8 func0415_holo_guard_unarmed_unalert[] = { beginloop(0x08) if_timer_gt(120, /*goto*/ 0x04) - if_player_looking_at_something_maybe(0x28, 0x01, 0x00, /*goto*/ 0x04) + if_within_targets_fovx_by_angle(40, /*goto*/ 0x04) endloop(0x08) beginloop(0x04) diff --git a/src/files/setup/setuplee.c b/src/files/setup/setuplee.c index 01781dd5a..04ad50ae4 100644 --- a/src/files/setup/setuplee.c +++ b/src/files/setup/setuplee.c @@ -2998,7 +2998,7 @@ u8 func0421_bridge_skedar[] = { chr_toggle_p1p2(CHR_SELF) label(0x2c) set_target_chr(CHR_P1P2) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x06) + if_target_outside_my_yvisang(/*goto*/ 0x06) if_target_in_sight(/*goto*/ 0xc8) label(0x06) if_saw_injury(0x00, /*goto*/ 0xc8) @@ -3008,7 +3008,7 @@ u8 func0421_bridge_skedar[] = { reloop(0xc7) label(0x06) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x2c) + if_target_outside_my_yvisang(/*goto*/ 0x2c) if_target_in_sight(/*goto*/ 0xc8) label(0x2c) set_target_chr(CHR_BOND) @@ -3053,7 +3053,7 @@ u8 func0421_bridge_skedar[] = { call_rng chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x06) + if_target_outside_my_yvisang(/*goto*/ 0x06) if_target_in_sight(/*goto*/ 0xce) label(0x06) if_timer_gt(60, /*goto*/ 0xcf) diff --git a/src/files/setup/setuplip.c b/src/files/setup/setuplip.c index 61d31a675..1bf880ed0 100644 --- a/src/files/setup/setuplip.c +++ b/src/files/setup/setuplip.c @@ -3467,7 +3467,7 @@ u8 func0426_check_looking_at_alien[] = { // Jo is in range label(0x64) - if_player_looking_at_something_maybe(0x0a, 0x01, 0x00, /*goto*/ 0x2d) + if_within_targets_fovx_by_angle(10, /*goto*/ 0x2d) // Jo is too far away or not looking at alien label(0x66) @@ -3477,7 +3477,7 @@ u8 func0426_check_looking_at_alien[] = { // Velvet is in range label(0x68) - if_player_looking_at_something_maybe(0x0a, 0x01, 0x00, /*goto*/ 0x2d) + if_within_targets_fovx_by_angle(10, /*goto*/ 0x2d) // Both players are too far away label(0x69) diff --git a/src/files/setup/setuppam.c b/src/files/setup/setuppam.c index 8cdc7a968..46c727696 100644 --- a/src/files/setup/setuppam.c +++ b/src/files/setup/setuppam.c @@ -3210,7 +3210,7 @@ u8 func041d_sniper[] = { label(0x2e) dprint 'C','H','E','C','K',' ','P','L','A','Y','E','R',' ','D','I','R','\n',0, - if_player_looking_at_something_maybe(0x14, 0x01, 0x00, /*goto*/ 0x0d) + if_within_targets_fovx_by_angle(20, /*goto*/ 0x0d) dprint '3','\n',0, label(0x06) if_can_see_target(/*goto*/ 0x2e) diff --git a/src/files/setup/setupsho.c b/src/files/setup/setupsho.c index a22cdae04..a47df76a8 100644 --- a/src/files/setup/setupsho.c +++ b/src/files/setup/setupsho.c @@ -1704,7 +1704,7 @@ u8 func0409_reaper_slayer_skedar[] = { if_self_flag_bankx_eq(CHRFLAG0_AIVSAI, FALSE, BANK_0, /*goto*/ 0x2e) if_enemy_distance_lt_and_los(2540, /*goto*/ 0x60) label(0x2e) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x06) + if_target_outside_my_yvisang(/*goto*/ 0x06) if_target_in_sight(/*goto*/ 0x60) label(0x06) if_just_injured(CHR_SELF, /*goto*/ 0x58) @@ -1716,7 +1716,7 @@ u8 func0409_reaper_slayer_skedar[] = { endloop(0x5f) label(0x06) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x2d) + if_target_outside_my_yvisang(/*goto*/ 0x2d) if_target_in_sight(/*goto*/ 0x60) label(0x2d) set_target_chr(CHR_BOND) @@ -1768,7 +1768,7 @@ u8 func0409_reaper_slayer_skedar[] = { call_rng chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x06) + if_target_outside_my_yvisang(/*goto*/ 0x06) if_target_in_sight(/*goto*/ 0x6b) label(0x06) if_timer_gt(60, /*goto*/ 0x6c) diff --git a/src/files/setup/setuptra.c b/src/files/setup/setuptra.c index cae742d31..23d470c57 100644 --- a/src/files/setup/setuptra.c +++ b/src/files/setup/setuptra.c @@ -831,7 +831,7 @@ u8 func0402_jonathan_waiting_for_meetup[] = { do_preset_animation(3) beginloop(0x09) - if_player_looking_at_something_maybe(0x0a, 0x01, 0x00, /*goto*/ 0x06) + if_within_targets_fovx_by_angle(10, /*goto*/ 0x06) if_timer_gt(60, /*goto*/ 0x06) endloop(0x09) diff --git a/src/files/setup/setupwax.c b/src/files/setup/setupwax.c index 851946d4f..efc34a90e 100644 --- a/src/files/setup/setupwax.c +++ b/src/files/setup/setupwax.c @@ -1579,7 +1579,7 @@ u8 func0415_chief[] = { beginloop(0x03) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x06) + if_target_outside_my_yvisang(/*goto*/ 0x06) if_target_in_sight(/*goto*/ 0x2c) label(0x06) reloop(0x03) diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index 5a3989b61..550f7482f 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -24215,24 +24215,24 @@ f32 chrGetVerticalAngleToTarget(struct chrdata *chr) return result; } -bool func0f048e74(struct chrdata *chr, u8 fov) +bool chrIsInTargetsFovX(struct chrdata *chr, u8 fov360) { f32 angle = chrGetAngleFromTargetsFov(chr); - if ((angle < fov * 0.024539785459638f && angle < M_PI) - || (angle > M_BADTAU - fov * 0.024539785459638f && angle > M_PI)) { + if ((angle < fov360 * 0.024539785459638f && angle < M_PI) + || (angle > M_BADTAU - fov360 * 0.024539785459638f && angle > M_PI)) { return true; } return false; } -bool func0f048f20(struct chrdata *chr, u8 angle) +bool chrIsVerticalAngleToTargetWithin(struct chrdata *chr, u8 fov360) { f32 val = chrGetVerticalAngleToTarget(chr); - if ((val < angle * 0.024539785459638f && val < M_PI) - || (val > M_BADTAU - angle * 0.024539785459638f && val > M_PI)) { + if ((val < fov360 * 0.024539785459638f && val < M_PI) + || (val > M_BADTAU - fov360 * 0.024539785459638f && val > M_PI)) { return true; } @@ -24776,7 +24776,7 @@ bool chrCanSeeTargetWithExtraCheck(struct chrdata *chr) return false; } - return func0f048e74(chr, 20); + return chrIsInTargetsFovX(chr, 20); } if (target->type == PROPTYPE_PLAYER) { diff --git a/src/game/chr/chrai.c b/src/game/chr/chrai.c index 0ffa4d065..36e69231d 100644 --- a/src/game/chr/chrai.c +++ b/src/game/chr/chrai.c @@ -95,7 +95,7 @@ bool (*g_CommandPointers[])(void) = { /*0x004b*/ aiIfNearMiss, /*0x004c*/ aiIfSeesSuspiciousItem, /*0x004d*/ aiIfTargetInFovLeft, - /*0x004e*/ ai004e, + /*0x004e*/ aiIfCheckFovWithTarget, /*0x004f*/ aiIfTargetOutOfFovLeft, /*0x0050*/ aiIfTargetInFov, /*0x0051*/ aiIfTargetOutOfFov, diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index 8c03197fb..cecc7c56d 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -1625,19 +1625,19 @@ bool aiIfSeesSuspiciousItem(void) /** * @cmd 004e */ -bool ai004e(void) +bool aiIfCheckFovWithTarget(void) { bool pass; u8 *cmd = g_Vars.ailist + g_Vars.aioffset; if (cmd[4] == 0) { if (cmd[3]) { - pass = func0f048e74(g_Vars.chrdata, cmd[2]); + pass = chrIsInTargetsFovX(g_Vars.chrdata, cmd[2]); } else { - pass = func0f048f20(g_Vars.chrdata, cmd[2]); + pass = chrIsVerticalAngleToTargetWithin(g_Vars.chrdata, cmd[2]); } } else { - pass = g_Vars.chrdata->yvisang && func0f048f20(g_Vars.chrdata, g_Vars.chrdata->yvisang) == 0; + pass = g_Vars.chrdata->yvisang && chrIsVerticalAngleToTargetWithin(g_Vars.chrdata, g_Vars.chrdata->yvisang) == 0; } if (pass) { @@ -6790,7 +6790,7 @@ bool aiDetectEnemy(void) s16 prevtarget = g_Vars.chrdata->target; g_Vars.chrdata->target = propGetIndexByChrId(g_Vars.chrdata, chr->chrnum); - if (func0f048f20(g_Vars.chrdata, g_Vars.chrdata->yvisang)) { + if (chrIsVerticalAngleToTargetWithin(g_Vars.chrdata, g_Vars.chrdata->yvisang)) { closestdist = distance; closesttarg = chr->chrnum; } @@ -8192,8 +8192,12 @@ bool aiSetTeamOrders(void) s32 num; u32 stack; u8 *cmd = g_Vars.ailist + g_Vars.aioffset; + + // Get list of chrs in the current chr's squadron chrnums = squadronGetChrIds(g_Vars.chrdata->squadron); + // Iterate chrs in squadron and build list of their actions. + // Put the current chr's action first. chraction = chractions; chraction->chrnum = g_Vars.chrdata->chrnum; chraction->myaction = g_Vars.chrdata->myaction; @@ -8227,6 +8231,8 @@ bool aiSetTeamOrders(void) chraction->myaction = MA_END; + // Iterate the list of chrs and decide how to reassign orders to them + // based on the current chr's action if (chrcount != 1) { chraction = &chractions[1]; num = 1; @@ -8236,25 +8242,25 @@ bool aiSetTeamOrders(void) switch (chractions[0].myaction) { case MA_COVERGOTO: - if (func0f048e74(chr, 45) == 0) { + if (!chrIsInTargetsFovX(chr, 45)) { chr->orders = MA_SHOOTING; } break; case MA_COVERBREAK: - if (func0f048e74(chr, 30) == 0) { + if (!chrIsInTargetsFovX(chr, 30)) { chr->orders = MA_SHOOTING; } num++; break; case MA_COVERSEEN: - if (func0f048e74(chr, 30) == 0) { + if (!chrIsInTargetsFovX(chr, 30)) { chr->orders = MA_SHOOTING; g_Vars.chrdata->orders = MA_COVERGOTO; } num++; break; case MA_FLANKLEFT: - if (func0f048e74(chr, 50)) { + if (chrIsInTargetsFovX(chr, 50)) { chr->orders = MA_FLANKRIGHT; } else { chr->orders = MA_SHOOTING; @@ -8263,7 +8269,7 @@ bool aiSetTeamOrders(void) g_Vars.chrdata->orders = MA_FLANKLEFT; break; case MA_FLANKRIGHT: - if (func0f048e74(chr, 50)) { + if (chrIsInTargetsFovX(chr, 50)) { chr->orders = MA_FLANKLEFT; } else { chr->orders = MA_SHOOTING; @@ -8272,7 +8278,7 @@ bool aiSetTeamOrders(void) g_Vars.chrdata->orders = MA_FLANKRIGHT; break; case MA_DODGE: - if (func0f048e74(chr, 30) == 0 && + if (!chrIsInTargetsFovX(chr, 30) && chrHasFlagById(chr, CHR_SELF, CHRFLAG0_CAN_BACKOFF, BANK_0)) { chr->orders = MA_WITHDRAW; } else { @@ -8289,7 +8295,7 @@ bool aiSetTeamOrders(void) num++; break; case MA_WAITSEEN: - if (func0f048e74(chr, 30) && + if (chrIsInTargetsFovX(chr, 30) && chrHasFlagById(chr, CHR_SELF, CHRFLAG0_CAN_BACKOFF, BANK_0)) { chr->orders = MA_WITHDRAW; } else { diff --git a/src/game/data/ailists.c b/src/game/data/ailists.c index 21c7a3ade..8c82868d4 100644 --- a/src/game/data/ailists.c +++ b/src/game/data/ailists.c @@ -161,7 +161,7 @@ u8 func0006_unalerted[] = { // Warned label(0x13) dprint 'A','1','\n',0, - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x16) + if_target_outside_my_yvisang(/*goto*/ 0x16) if_target_in_sight(/*goto*/ LABEL_SEE_DETECT) label(0x16) dprint 'B','4',' ','A','I','V','S','A','I','\n',0, @@ -344,7 +344,7 @@ u8 func0006_unalerted[] = { label(0xe9) label(0x13) - if_player_looking_at_something_maybe(0x0a, 0x01, 0x00, /*goto*/ 0x13) + if_within_targets_fovx_by_angle(10, /*goto*/ 0x13) goto_next(0x15) label(0x13) @@ -542,7 +542,7 @@ u8 func0006_unalerted[] = { if_saw_injury(0x00, /*goto*/ 0x16) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x13) + if_target_outside_my_yvisang(/*goto*/ 0x13) if_target_in_sight(/*goto*/ 0x16) label(0x13) if_distance_to_chr_lt(150, CHR_SEEDIE, /*goto*/ 0x7f) @@ -565,7 +565,7 @@ u8 func0006_unalerted[] = { chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) if_hears_target(/*goto*/ 0x16) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x13) + if_target_outside_my_yvisang(/*goto*/ 0x13) if_target_in_sight(/*goto*/ 0x17) label(0x13) if_self_flag_bankx_eq(CHRFLAG0_CAN_EXAMINE_BODY, FALSE, BANK_0, /*goto*/ 0x13) @@ -1417,7 +1417,7 @@ u8 func0007_alerted[] = { // label(0x52) dprint 'A','M','B','U','S','H',' ','F','A','I','L','E','D','3','\n',0, - if_player_looking_at_something_maybe(0x3c, 0x01, 0x00, /*goto*/ 0x16) + if_within_targets_fovx_by_angle(60, /*goto*/ 0x16) goto_next(0x68) label(0x16) @@ -1429,7 +1429,7 @@ u8 func0007_alerted[] = { if_self_flag_bankx_eq(CHRFLAG0_00000080, TRUE, BANK_0, /*goto*/ 0x13) call_rng if_rand_gt(100, /*goto*/ 0x13) - if_player_looking_at_something_maybe(0x1e, 0x01, 0x00, /*goto*/ 0x16) + if_within_targets_fovx_by_angle(30, /*goto*/ 0x16) label(0x13) if_nearly_in_targets_sight(30, /*goto*/ 0x5f) label(0x16) @@ -1554,7 +1554,7 @@ u8 func0007_alerted[] = { label(0x69) if_distance_to_target_gt(4000, /*goto*/ 0x16) label(0x6a) - if_player_looking_at_something_maybe(0x11, 0x01, 0x00, /*goto*/ 0x63) + if_within_targets_fovx_by_angle(17, /*goto*/ 0x63) label(0x16) label(0x64) set_action(MA_COVERBREAK, FALSE) @@ -1583,7 +1583,7 @@ u8 func0007_alerted[] = { label(0x63) if_self_flag_bankx_eq(CHRFLAG0_00008000, FALSE, BANK_0, /*goto*/ 0x13) - if_player_looking_at_something_maybe(0x11, 0x01, 0x00, /*goto*/ 0x16) + if_within_targets_fovx_by_angle(17, /*goto*/ 0x16) goto_first(0x64) label(0x13) @@ -1730,7 +1730,7 @@ u8 func0007_alerted[] = { label(0x4d) if_self_flag_bankx_eq(CHRFLAG1_00040000, TRUE, BANK_1, /*goto*/ 0x32) call_rng - if_player_looking_at_something_maybe(0x1e, 0x01, 0x00, /*goto*/ 0x16) + if_within_targets_fovx_by_angle(30, /*goto*/ 0x16) goto_next(0x32) label(0x16) @@ -1795,7 +1795,7 @@ u8 func0007_alerted[] = { if_self_flag_bankx_eq(CHRFLAG1_00020000, TRUE, BANK_1, /*goto*/ 0x2f) label(0x32) - if_player_looking_at_something_maybe(0x14, 0x01, 0x00, /*goto*/ 0x16) + if_within_targets_fovx_by_angle(20, /*goto*/ 0x16) goto_next(0x2f) label(0x16) @@ -1822,7 +1822,7 @@ u8 func0007_alerted[] = { goto_next(LABEL_TRACK) label(0x51) - if_player_looking_at_something_maybe(0x15, 0x01, 0x00, /*goto*/ 0x16) + if_within_targets_fovx_by_angle(21, /*goto*/ 0x16) goto_next(LABEL_TRACK) // @@ -1930,7 +1930,7 @@ u8 func0007_alerted[] = { if_timer_gt(600, /*goto*/ 0x3d) if_timer_gt(60, /*goto*/ 0x16) label(0x16) - if_player_looking_at_something_maybe(0x15, 0x01, 0x00, /*goto*/ 0x16) + if_within_targets_fovx_by_angle(21, /*goto*/ 0x16) goto_next(LABEL_TRACK) label(0x16) if_distance_to_target_gt(2000, /*goto*/ 0x41) @@ -2061,7 +2061,7 @@ u8 func0007_alerted[] = { label(0x13) label(0x8b) dprint 'B','A','C','K','O','F','F','\n',0, - if_player_looking_at_something_maybe(0x14, 0x01, 0x00, /*goto*/ 0x13) + if_within_targets_fovx_by_angle(20, /*goto*/ 0x13) goto_next(0x50) label(0x13) @@ -2181,7 +2181,7 @@ u8 func0007_alerted[] = { if_distance_to_target_gt(1300, /*goto*/ 0x13) if_self_flag_bankx_eq(CHRFLAG1_01000000, TRUE, BANK_1, /*goto*/ 0x16) if_self_flag_bankx_eq(CHRFLAG1_02000000, FALSE, BANK_1, /*goto*/ 0x16) - if_player_looking_at_something_maybe(0x15, 0x01, 0x00, /*goto*/ 0x3b) + if_within_targets_fovx_by_angle(21, /*goto*/ 0x3b) goto_next(0x16) label(0xc8) @@ -2218,13 +2218,13 @@ u8 func0007_alerted[] = { label(0x39) if_self_flag_bankx_eq(CHRFLAG1_01000000, TRUE, BANK_1, /*goto*/ 0x3c) - if_player_looking_at_something_maybe(0x15, 0x01, 0x00, /*goto*/ 0x3b) + if_within_targets_fovx_by_angle(21, /*goto*/ 0x3b) if_distance_to_target_lt(1300, /*goto*/ 0x3b) goto_next(0x17) label(0x3a) if_self_flag_bankx_eq(CHRFLAG1_01000000, TRUE, BANK_1, /*goto*/ 0x3c) - if_player_looking_at_something_maybe(0x15, 0x01, 0x00, /*goto*/ 0x3b) + if_within_targets_fovx_by_angle(21, /*goto*/ 0x3b) goto_next(0x3c) label(0x3c) @@ -4156,7 +4156,7 @@ u8 func001b_observe_camspy[] = { if_distance_to_target_lt(300, /*goto*/ 0x13) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x16) + if_target_outside_my_yvisang(/*goto*/ 0x16) if_target_in_sight(/*goto*/ 0x0b) label(0x16) set_target_chr(CHR_PRESET) @@ -4176,7 +4176,7 @@ u8 func001b_observe_camspy[] = { if_distance_to_target_gt(400, /*goto*/ 0x13) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x16) + if_target_outside_my_yvisang(/*goto*/ 0x16) if_target_in_sight(/*goto*/ 0x0b) label(0x16) set_target_chr(CHR_PRESET) @@ -4198,7 +4198,7 @@ u8 func001b_observe_camspy[] = { label(0x13) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x16) + if_target_outside_my_yvisang(/*goto*/ 0x16) if_target_in_sight(/*goto*/ 0x0b) label(0x16) set_target_chr(CHR_PRESET) @@ -4322,7 +4322,7 @@ u8 func001d_search_for_player[] = { label(0x13) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x15) + if_target_outside_my_yvisang(/*goto*/ 0x15) if_target_in_sight(/*goto*/ 0x12) label(0x15) if_timer_gt(30, /*goto*/ 0x05) @@ -4402,7 +4402,7 @@ u8 func001d_search_for_player[] = { if_distance_to_target_gt(500, /*goto*/ 0x15) label(0x13) dprint 'C','H','E','K',' ','V','I','S','\n',0, - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x15) + if_target_outside_my_yvisang(/*goto*/ 0x15) if_target_in_sight(/*goto*/ 0x12) label(0x15) if_saw_death(0x00, /*goto*/ 0x28) @@ -4480,7 +4480,7 @@ u8 func001f_related_to_spawning[] = { label(0x16) if_saw_death(0x01, /*goto*/ 0x1e) if_saw_injury(0x01, /*goto*/ 0x1e) - if_player_looking_at_something_maybe(0x00, 0x00, 0x01, /*goto*/ 0x16) + if_target_outside_my_yvisang(/*goto*/ 0x16) if_target_in_sight(/*goto*/ 0x1e) label(0x16) if_self_flag_bankx_eq(CHRFLAG0_AIVSAI, FALSE, BANK_0, /*goto*/ 0x16) diff --git a/src/include/commands.h b/src/include/commands.h index 262032e18..989de1bdf 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -708,14 +708,34 @@ angle, \ label, -// Either bool1 or bool2 are set - never none or both -// When bool1 is set, u1 is populated -// When bool2 is set, u1 is 0 (likely unused) -#define if_player_looking_at_something_maybe(u1, bool1, bool2, label) \ +/** + * Check if the current chr is in their target's field of view (FOV). + * + * Depending on the arguments given, the check is either on the X axis or the Y + * axis. If the X axis is being used then the turn direction that the target is + * facing is relevant. If the Y axis is being used then the pitch that the + * target is ignored and the check is purely positional. + * + * if op2 is TRUE, the command checks if the chr is *outside* of their target's + * FOV Y and is based on the chr's yvisang property. The given angle is ignored. + * + * if op2 is FALSE, then op1 is checked: + * + * if op1 is TRUE, the command checks if the chr is within their target's FOV X + * by the given angle (ie. their target is looking at them). + * + * if op1 is FALSE, the command checks if the chr is within their target's FOV Y. + * + * Consider using the following macros for this command instead: + * if_within_targets_fovx_by_angle + * if_y_angle_to_target_lt + * if_target_outside_my_yvisang + */ +#define if_fov_check_with_target(angle, op1, op2, label) \ mkshort(0x004e), \ - u1, \ - bool1, \ - bool2, \ + angle, \ + op1, \ + op2, \ label, /** @@ -4180,15 +4200,34 @@ mkshort(0x01e0), // Convenience macros for readability -#define beginloop(id) label(id) yield +#define beginloop(id) \ + label(id) \ + yield -#define endloop(id) goto_first(id) +#define endloop(id) \ + goto_first(id) -#define reloop(id) goto_first(id) +#define reloop(id) \ + goto_first(id) -#define remove_hudmsgs show_hudmsg_middle(0x02, 0, 0x0002) +#define remove_hudmsgs \ + show_hudmsg_middle(0x02, 0, 0x0002) -#define if_stage_is_not(stage, label) if_stage_lt(stage, label) if_stage_gt(stage, label) +#define if_stage_is_not(stage, label) \ + if_stage_lt(stage, label) \ + if_stage_gt(stage, label) -#define go_to_gun(label) do_gun_command(0, label) -#define if_gun_landed(label) do_gun_command(1, label) +#define go_to_gun(label) \ + do_gun_command(0, label) + +#define if_gun_landed(label) \ + do_gun_command(1, label) + +#define if_within_targets_fovx_by_angle(angle, label) \ + if_fov_check_with_target(angle, TRUE, FALSE, label) + +#define if_y_angle_to_target_lt(angle, label) \ + if_fov_check_with_target(angle, FALSE, FALSE, label) + +#define if_target_outside_my_yvisang(label) \ + if_fov_check_with_target(0, FALSE, TRUE, label) diff --git a/src/include/game/chr/chraction.h b/src/include/game/chr/chraction.h index b113e5067..5a9a9b83f 100644 --- a/src/include/game/chr/chraction.h +++ b/src/include/game/chr/chraction.h @@ -173,8 +173,8 @@ f32 chrGetAngleToPos(struct chrdata *chr, struct coord *pos); u32 func0f048b78(void); f32 chrGetAngleFromTargetsFov(struct chrdata *chr); f32 chrGetVerticalAngleToTarget(struct chrdata *chr); -bool func0f048e74(struct chrdata *chr, u8 arg1); -bool func0f048f20(struct chrdata *chr, u8 arg1); +bool chrIsInTargetsFovX(struct chrdata *chr, u8 fov360); +bool chrIsVerticalAngleToTargetWithin(struct chrdata *chr, u8 arg1); f32 func0f048fcc(struct chrdata *chr, u8 arg1); bool chrIsTargetInFov(struct chrdata *chr, u8 arg1, u8 arg2); bool func0f04911c(struct chrdata *chr, struct coord *pos, u8 arg2); diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index adb1591cc..6f067d00a 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -81,7 +81,7 @@ /*0x004b*/ bool aiIfNearMiss(void); /*0x004c*/ bool aiIfSeesSuspiciousItem(void); /*0x004d*/ bool aiIfTargetInFovLeft(void); -/*0x004e*/ bool ai004e(void); +/*0x004e*/ bool aiIfCheckFovWithTarget(void); /*0x004f*/ bool aiIfTargetOutOfFovLeft(void); /*0x0050*/ bool aiIfTargetInFov(void); /*0x0051*/ bool aiIfTargetOutOfFov(void);