From d541957074026e391fdbd5326e583227c007bc03 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 30 May 2020 00:06:00 +1000 Subject: [PATCH] Discover AI command if_can_see_attack_target and decompile chrCanSeeAttackTarget --- src/files/setup/setupate.c | 2 +- src/files/setup/setupdam.c | 2 +- src/files/setup/setupdepo.c | 2 +- src/files/setup/setupdish.c | 4 +- src/files/setup/setupeld.c | 2 +- src/files/setup/setupsho.c | 4 +- src/files/setup/setupwax.c | 2 +- src/game/chr/chraction.c | 42 +++++++--------- src/game/chr/chrai.c | 2 +- src/game/chr/chraicommands.c | 4 +- src/game/data/ailists.c | 74 ++++++++++++++-------------- src/include/commands.h | 11 +++-- src/include/game/chr/chraction.h | 4 +- src/include/game/chr/chraicommands.h | 2 +- 14 files changed, 77 insertions(+), 80 deletions(-) diff --git a/src/files/setup/setupate.c b/src/files/setup/setupate.c index cce4c5607..211ce843f 100644 --- a/src/files/setup/setupate.c +++ b/src/files/setup/setupate.c @@ -460,7 +460,7 @@ u8 func0403_jon_combat[] = { beginloop(0x08) if_distance_to_target_lt(250, /*goto*/ 0x0e) - if_in_disarm_range(/*goto*/ 0x06) + if_can_see_attack_target(/*goto*/ 0x06) reloop(0x08) label(0x06) diff --git a/src/files/setup/setupdam.c b/src/files/setup/setupdam.c index 5daf4bf74..d48458970 100644 --- a/src/files/setup/setupdam.c +++ b/src/files/setup/setupdam.c @@ -2213,7 +2213,7 @@ u8 func0404_angry_pilot[] = { try_run_to_target(/*goto*/ 0x6d) beginloop(0x6d) - if_in_disarm_range(/*goto*/ 0x07) + if_can_see_attack_target(/*goto*/ 0x07) if_timer_gt(120, /*goto*/ 0x04) endloop(0x6d) diff --git a/src/files/setup/setupdepo.c b/src/files/setup/setupdepo.c index aed5276e9..9b8642205 100644 --- a/src/files/setup/setupdepo.c +++ b/src/files/setup/setupdepo.c @@ -2307,7 +2307,7 @@ u8 func0412_cloak_guard[] = { label(0x2c) if_player_looking_at_something_maybe(0x0f, 0x01, 0x00, /*goto*/ 0x0e) label(0x06) - if_in_disarm_range(/*goto*/ 0x2c) + if_can_see_attack_target(/*goto*/ 0x2c) goto_next(0x0d) label(0x0e) add_morale(1) diff --git a/src/files/setup/setupdish.c b/src/files/setup/setupdish.c index e558ba22d..494fba210 100644 --- a/src/files/setup/setupdish.c +++ b/src/files/setup/setupdish.c @@ -5218,7 +5218,7 @@ u8 func0416_holo_guard_unarmed_alert2[] = { if_chr_dead(CHR_TARGET, /*goto*/ 0x57) if_chr_knockedout(CHR_TARGET, /*goto*/ 0x57) if_distance_to_target_gt(100, /*goto*/ 0x2f) - if_in_disarm_range(/*goto*/ 0x2f) + if_can_see_attack_target(/*goto*/ 0x2f) if_timer_gt(120, /*goto*/ 0x10) endloop(0x04) @@ -5607,7 +5607,7 @@ u8 func0419_holo_guard_armed_alert[] = { try_attack_stand(ENTITYTYPE_TARGET | ENTITYTYPE_AIMONLY, 0, /*goto*/ 0x04) beginloop(0x04) - if_in_disarm_range(/*goto*/ 0x2f) + if_can_see_attack_target(/*goto*/ 0x2f) endloop(0x04) label(0x2f) diff --git a/src/files/setup/setupeld.c b/src/files/setup/setupeld.c index 248ad9121..6b2b91821 100644 --- a/src/files/setup/setupeld.c +++ b/src/files/setup/setupeld.c @@ -1883,7 +1883,7 @@ u8 func0404_sniper[] = { // Detected player label(0x58) - if_in_disarm_range(/*goto*/ 0x2d) + if_can_see_attack_target(/*goto*/ 0x2d) reloop(0x04) label(0x2d) diff --git a/src/files/setup/setupsho.c b/src/files/setup/setupsho.c index 8cebd4a10..7035be5e4 100644 --- a/src/files/setup/setupsho.c +++ b/src/files/setup/setupsho.c @@ -1973,7 +1973,7 @@ u8 func040d_king_combat[] = { beginloop(0x59) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_in_disarm_range(/*goto*/ 0x03) + if_can_see_attack_target(/*goto*/ 0x03) if_chr_shield_lt(CHR_SELF, 20, /*goto*/ LABEL_LOW_SHIELD) endloop(0x59) @@ -2037,7 +2037,7 @@ u8 func040d_king_combat[] = { beginloop(0x7a) if_chr_death_animation_finished(CHR_P1P2, /*goto*/ LABEL_PLAYER_DEAD) if_chr_shield_lt(CHR_SELF, 20, /*goto*/ LABEL_LOW_SHIELD) - if_in_disarm_range(/*goto*/ 0x06) + if_can_see_attack_target(/*goto*/ 0x06) endloop(0x7a) label(0x06) diff --git a/src/files/setup/setupwax.c b/src/files/setup/setupwax.c index be96b1cdc..b75f6c6bc 100644 --- a/src/files/setup/setupwax.c +++ b/src/files/setup/setupwax.c @@ -1346,7 +1346,7 @@ u8 func0411_cass_in_office[] = { beginloop(0x5a) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) - if_in_disarm_range(/*goto*/ 0x83) + if_can_see_attack_target(/*goto*/ 0x83) reloop(0x5a) label(0x83) diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index e831c4dcd..26d3e7a4e 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -11955,7 +11955,7 @@ void chrRecordLastVisibleTargetTime(struct chrdata *chr) } GLOBAL_ASM( -glabel func0f038f40 +glabel chrCanSeeEntity /* f038f40: 27bdff88 */ addiu $sp,$sp,-120 /* f038f44: 8fae0088 */ lw $t6,0x88($sp) /* f038f48: afbf001c */ sw $ra,0x1c($sp) @@ -12147,26 +12147,18 @@ glabel func0f038f40 /* f0391e8: 00000000 */ sll $zero,$zero,0x0 ); -GLOBAL_ASM( -glabel func0f0391ec -/* f0391ec: 27bdffe0 */ addiu $sp,$sp,-32 -/* f0391f0: afbf001c */ sw $ra,0x1c($sp) -/* f0391f4: 808e0007 */ lb $t6,0x7($a0) -/* f0391f8: 24010008 */ addiu $at,$zero,0x8 -/* f0391fc: 24020200 */ addiu $v0,$zero,0x200 -/* f039200: 15c10003 */ bne $t6,$at,.L0f039210 -/* f039204: 00001825 */ or $v1,$zero,$zero -/* f039208: 8c82004c */ lw $v0,0x4c($a0) -/* f03920c: 8c830050 */ lw $v1,0x50($a0) -.L0f039210: -/* f039210: afa20010 */ sw $v0,0x10($sp) -/* f039214: 0fc0e3d0 */ jal func0f038f40 -/* f039218: afa30014 */ sw $v1,0x14($sp) -/* f03921c: 8fbf001c */ lw $ra,0x1c($sp) -/* f039220: 27bd0020 */ addiu $sp,$sp,0x20 -/* f039224: 03e00008 */ jr $ra -/* f039228: 00000000 */ sll $zero,$zero,0x0 -); +bool chrCanSeeAttackTarget(struct chrdata *chr, struct coord *pos, s16 *rooms, bool arg3) +{ + u32 entitytype = ENTITYTYPE_TARGET; + u32 entityid = 0; + + if (chr->actiontype == ACT_ATTACK) { + entitytype = chr->act_attack.entitytype; + entityid = chr->act_attack.entityid; + } + + return chrCanSeeEntity(chr, pos, rooms, arg3, entitytype, entityid); +} bool chrCanSeeChr(struct chrdata *chr, struct chrdata *target, s16 *room) { @@ -12824,7 +12816,7 @@ bool chrTryAttackWalk(struct chrdata *chr) if (chrIsReadyForOrders(chr)) { struct prop *prop = chr->prop; - if (func0f0391ec(chr, &prop->pos, prop->rooms, 0) + if (chrCanSeeAttackTarget(chr, &prop->pos, prop->rooms, 0) && (chrGetEquippedWeaponPropWithCheck(chr, 0) || chrGetEquippedWeaponPropWithCheck(chr, 1)) && g_Vars.lvframe60 - chr->lastwalk60 > 120) { struct prop *target = chrGetTargetProp(chr); @@ -12853,7 +12845,7 @@ bool chrTryAttackRun(struct chrdata *chr) if (chrIsReadyForOrders(chr)) { struct prop *prop = chr->prop; - if (func0f0391ec(chr, &prop->pos, prop->rooms, 0) + if (chrCanSeeAttackTarget(chr, &prop->pos, prop->rooms, 0) && (chrGetEquippedWeaponPropWithCheck(chr, 0) || chrGetEquippedWeaponPropWithCheck(chr, 1)) && g_Vars.lvframe60 - chr->lastwalk60 > 180) { struct prop *target = chrGetTargetProp(chr); @@ -12876,7 +12868,7 @@ bool chrTryAttackRoll(struct chrdata *chr) if (CHRRACE(chr) == RACE_HUMAN && chrIsReadyForOrders(chr)) { struct prop *prop = chr->prop; - if (func0f0391ec(chr, &prop->pos, prop->rooms, 0) && + if (chrCanSeeAttackTarget(chr, &prop->pos, prop->rooms, 0) && (chrGetEquippedWeaponPropWithCheck(chr, 0) || chrGetEquippedWeaponPropWithCheck(chr, 1))) { struct prop *target = chrGetTargetProp(chr); f32 x = target->pos.x - prop->pos.x; @@ -19493,7 +19485,7 @@ glabel var7f1a9184 /* f041284: 15a10047 */ bne $t5,$at,.L0f0413a4 /* f041288: 27a50244 */ addiu $a1,$sp,0x244 /* f04128c: 27a60234 */ addiu $a2,$sp,0x234 -/* f041290: 0fc0e47b */ jal func0f0391ec +/* f041290: 0fc0e47b */ jal chrCanSeeAttackTarget /* f041294: 00003825 */ or $a3,$zero,$zero /* f041298: 10400042 */ beqz $v0,.L0f0413a4 /* f04129c: 8faa025c */ lw $t2,0x25c($sp) diff --git a/src/game/chr/chrai.c b/src/game/chr/chrai.c index a2fd29e28..d9f2ba90f 100644 --- a/src/game/chr/chrai.c +++ b/src/game/chr/chrai.c @@ -396,7 +396,7 @@ bool (*g_CommandPointers[])(void) = { /*0x0177*/ aiPlayerAutoWalk, /*0x0178*/ aiIfPlayerAutoWalkFinished, /*0x0179*/ ai0179, - /*0x017a*/ ai017a, + /*0x017a*/ aiIfCanSeeAttackTarget, /*0x017b*/ aiIfChrKnockedOut, /*0x017c*/ aiAssignSound, /*0x017d*/ aiAudioSetMusicTrack, diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index e39276cf8..736c62e9b 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -1358,9 +1358,9 @@ bool aiIfCanSeeTarget(void) /** * @cmd 017a */ -bool ai017a(void) +bool aiIfCanSeeAttackTarget(void) { - if ((g_Vars.chrdata && g_Vars.chrdata->prop && func0f0391ec(g_Vars.chrdata, &g_Vars.chrdata->prop->pos, &g_Vars.chrdata->prop->rooms[0], 1)) + if ((g_Vars.chrdata && g_Vars.chrdata->prop && chrCanSeeAttackTarget(g_Vars.chrdata, &g_Vars.chrdata->prop->pos, g_Vars.chrdata->prop->rooms, true)) || (g_Vars.hovercar && chopperCheckTargetInFov(g_Vars.hovercar, 64) && chopperCheckTargetInSight(g_Vars.hovercar))) { u8 *cmd = g_Vars.ailist + g_Vars.aioffset; g_Vars.aioffset = chraiGoToLabel(g_Vars.ailist, g_Vars.aioffset, cmd[2]); diff --git a/src/game/data/ailists.c b/src/game/data/ailists.c index d66d4af0c..ce1a3cfc3 100644 --- a/src/game/data/ailists.c +++ b/src/game/data/ailists.c @@ -1113,7 +1113,7 @@ u8 func0007_alerted[] = { if_self_flag_bankx_eq(CHRFLAG0_00000004, FALSE, BANK_0, /*goto*/ 0x16) label(0x13) dprint 'V','I','S','\n',0, - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x98) label(0x16) @@ -1122,7 +1122,7 @@ u8 func0007_alerted[] = { if_self_flag_bankx_eq(CHRFLAG0_01000000, FALSE, BANK_0, /*goto*/ 0x16) label(0x13) dprint 'V','I','S','\n',0, - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0xa1) label(0x16) @@ -1171,7 +1171,7 @@ u8 func0007_alerted[] = { try_attack_kneel(ENTITYTYPE_TARGET | ENTITYTYPE_AIMONLY, 0, /*goto*/ 0x03) beginloop(0x03) - if_in_disarm_range(/*goto*/ 0x9a) + if_can_see_attack_target(/*goto*/ 0x9a) if_chr_target_eq(CHR_SELF, CHR_P1P2, FALSE, /*goto*/ 0xee) goto_next(0xef) @@ -1179,7 +1179,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_in_disarm_range(/*goto*/ 0x9a) + if_can_see_attack_target(/*goto*/ 0x9a) label(0xee) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) @@ -1209,7 +1209,7 @@ u8 func0007_alerted[] = { beginloop(0xa2) dprint 'W','A','I','T',' ','F','O','R',' ','A','M','B','\n',0, - if_in_disarm_range(/*goto*/ 0xa3) + if_can_see_attack_target(/*goto*/ 0xa3) dprint 'A','M','B','1','\n',0, if_distance_from_target_to_pad_lt(200, PAD_PRESET, /*goto*/ 0x13) dprint 'A','M','B','2','\n',0, @@ -1268,13 +1268,13 @@ u8 func0007_alerted[] = { if_near_miss(/*goto*/ 0x13) if_saw_injury(0x00, /*goto*/ 0x13) if_saw_death(0x00, /*goto*/ 0x13) - if_in_disarm_range(/*goto*/ 0x13) + if_can_see_attack_target(/*goto*/ 0x13) endloop(0xa9) label(0x13) call_rng if_rand_gt(150, /*goto*/ 0x13) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -1301,7 +1301,7 @@ u8 func0007_alerted[] = { goto_first(0xa8) label(0x13) - if_in_disarm_range(/*goto*/ 0x13) + if_can_see_attack_target(/*goto*/ 0x13) goto_first(0xa8) label(0x13) @@ -1340,7 +1340,7 @@ u8 func0007_alerted[] = { endloop(0xec) label(0x13) - if_in_disarm_range(/*goto*/ 0x13) + if_can_see_attack_target(/*goto*/ 0x13) if_chr_target_eq(CHR_SELF, CHR_P1P2, FALSE, /*goto*/ 0xee) goto_next(0xef) @@ -1348,7 +1348,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_in_disarm_range(/*goto*/ 0x13) + if_can_see_attack_target(/*goto*/ 0x13) label(0xee) chr_toggle_p1p2(CHR_SELF) set_target_chr(CHR_P1P2) @@ -1377,7 +1377,7 @@ u8 func0007_alerted[] = { endloop(0xdf) label(0x13) - if_in_disarm_range(/*goto*/ 0x13) + if_can_see_attack_target(/*goto*/ 0x13) set_self_flag_bankx(CHRFLAG0_80000000, BANK_0) stop_chr goto_first(0x1b) @@ -1442,7 +1442,7 @@ u8 func0007_alerted[] = { if_distance_to_target_gt(4000, /*goto*/ 0x61) label(0x16) dprint 'O','K','F','O','R','C','O','V','E','R','\n',0, - if_in_disarm_range(/*goto*/ 0x5b) + if_can_see_attack_target(/*goto*/ 0x5b) if_nearly_in_targets_sight(30, /*goto*/ 0x5b) if_chr_in_view(/*goto*/ 0x5b) goto_next(0x56) @@ -1503,7 +1503,7 @@ u8 func0007_alerted[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -1569,7 +1569,7 @@ u8 func0007_alerted[] = { beginloop(0x62) if_dangerous_object_nearby(3, /*goto*/ LABEL_FLEE_GRENADE) - if_in_disarm_range(/*goto*/ 0x5f) + if_can_see_attack_target(/*goto*/ 0x5f) if_player_using_cmp150_or_ar34(/*goto*/ 0x69) if_distance_to_target_gt(2000, /*goto*/ 0x65) goto_next(0x16) @@ -1609,7 +1609,7 @@ u8 func0007_alerted[] = { if_self_flag_bankx_eq(CHRFLAG0_CAN_FLANK, FALSE, BANK_0, /*goto*/ 0x93) if_has_orders(/*goto*/ 0x84) label(0x93) - if_in_disarm_range(/*goto*/ 0x26) + if_can_see_attack_target(/*goto*/ 0x26) goto_next(0x87) if_chr_has_hiddenflag(CHR_TARGET, CHRHFLAG_CLOAKED, /*goto*/ LABEL_CLOAKED) @@ -1620,7 +1620,7 @@ u8 func0007_alerted[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -1707,7 +1707,7 @@ u8 func0007_alerted[] = { label(0x54) dprint 'N','O',' ','C','O','V','E','R','A','V','A','I','L','A','B','L','E','\n',0, label(0x68) - if_in_disarm_range(/*goto*/ 0x24) + if_can_see_attack_target(/*goto*/ 0x24) goto_next(0x25) label(0x25) @@ -1778,7 +1778,7 @@ u8 func0007_alerted[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -1805,7 +1805,7 @@ u8 func0007_alerted[] = { label(0x2f) dprint 'C',' ','1','\n',0, if_distance_to_target_gt(1300, /*goto*/ LABEL_TRACK) - if_in_disarm_range(/*goto*/ 0x26) + if_can_see_attack_target(/*goto*/ 0x26) dprint 'C',' ','2','\n',0, if_self_flag_bankx_eq(CHRFLAG0_CAN_RETREAT, FALSE, BANK_0, /*goto*/ 0x16) if_self_flag_bankx_eq(CHRFLAG0_CANT_ALERT_GROUP, TRUE, BANK_0, /*goto*/ LABEL_RETREAT) @@ -1946,7 +1946,7 @@ u8 func0007_alerted[] = { set_team_orders(MA_WAITSEEN, /*goto*/ 0x16) label(0x16) dprint 'S','E','E','W','A','I','T','3','\n',0, - if_in_disarm_range(/*goto*/ 0x8a) + if_can_see_attack_target(/*goto*/ 0x8a) restart_timer try_run_to_target(/*goto*/ 0x89) @@ -1957,7 +1957,7 @@ u8 func0007_alerted[] = { label(0x91) if_retreat_risk_lt(5, /*goto*/ 0x41) label(0x16) - if_in_disarm_range(/*goto*/ 0x8a) + if_can_see_attack_target(/*goto*/ 0x8a) if_timer_gt(60, /*goto*/ 0x29) endloop(0x89) @@ -1970,7 +1970,7 @@ u8 func0007_alerted[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -2091,7 +2091,7 @@ u8 func0007_alerted[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -2168,7 +2168,7 @@ u8 func0007_alerted[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -2189,7 +2189,7 @@ u8 func0007_alerted[] = { goto_first(0x31) label(0x16) - if_in_disarm_range(/*goto*/ 0x26) + if_can_see_attack_target(/*goto*/ 0x26) label(0x13) dprint 'N','O','S','E','E','P','L','A','Y','E','R','\n',0, if_self_flag_bankx_eq(CHRFLAG0_AIVSAI, FALSE, BANK_0, /*goto*/ 0x13) @@ -2275,7 +2275,7 @@ u8 func0007_alerted[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -2283,7 +2283,7 @@ u8 func0007_alerted[] = { set_ailist(CHR_SELF, GAILIST_HAND_COMBAT) label(0x13) - if_in_disarm_range(/*goto*/ 0x26) + if_can_see_attack_target(/*goto*/ 0x26) if_timer_gt(120, /*goto*/ 0x86) endloop(0x85) @@ -2300,7 +2300,7 @@ u8 func0007_alerted[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -3030,7 +3030,7 @@ u8 func000c_combat_with_target_chr[] = { call_rng if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x16) - if_in_disarm_range(/*goto*/ 0x13) + if_can_see_attack_target(/*goto*/ 0x13) goto_next(0x16) label(0x13) @@ -3062,7 +3062,7 @@ u8 func000c_combat_with_target_chr[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) dprint 'N','O','U','N','A','R','M','\n',0, goto_next(0x13) @@ -3074,7 +3074,7 @@ u8 func000c_combat_with_target_chr[] = { label(0x13) label(0x13) if_enemy_distance_lt_and_los(1200, /*goto*/ 0xb5) - if_in_disarm_range(/*goto*/ 0xb6) + if_can_see_attack_target(/*goto*/ 0xb6) endloop(0xb4) label(0x09) @@ -3082,7 +3082,7 @@ u8 func000c_combat_with_target_chr[] = { label(0xb7) label(0xb9) - if_in_disarm_range(/*goto*/ 0xb6) + if_can_see_attack_target(/*goto*/ 0xb6) if_chr_dead(CHR_TARGET, /*goto*/ 0xba) if_chr_death_animation_finished(CHR_TARGET, /*goto*/ 0xba) if_chr_knockedout(CHR_TARGET, /*goto*/ 0xba) @@ -3106,7 +3106,7 @@ u8 func000c_combat_with_target_chr[] = { label(0x13) if_chr_has_hiddenflag(CHR_TARGET, CHRHFLAG_CLOAKED, /*goto*/ 0x13) - if_in_disarm_range(/*goto*/ 0xbf) + if_can_see_attack_target(/*goto*/ 0xbf) label(0x13) if_timer_gt(120, /*goto*/ 0xc0) endloop(0xbc) @@ -3149,7 +3149,7 @@ u8 func000c_combat_with_target_chr[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -3167,7 +3167,7 @@ u8 func000c_combat_with_target_chr[] = { if_rand_lt(128, /*goto*/ 0x13) if_distance_to_target_gt(250, /*goto*/ 0x13) label(0x16) - if_in_disarm_range(/*goto*/ 0x16) + if_can_see_attack_target(/*goto*/ 0x16) goto_next(0x13) label(0x16) @@ -3321,7 +3321,7 @@ u8 func000c_combat_with_target_chr[] = { label(0x13) if_enemy_distance_lt_and_los(400, /*goto*/ 0x15) if_chr_has_hiddenflag(CHR_TARGET, CHRHFLAG_CLOAKED, /*goto*/ 0x13) - if_in_disarm_range(/*goto*/ 0xca) + if_can_see_attack_target(/*goto*/ 0xca) label(0x13) if_timer_gt(200, /*goto*/ 0x16) endloop(0xc9) @@ -3806,7 +3806,7 @@ u8 func000f_hand_combat[] = { if_distance_to_target_gt(150, /*goto*/ 0x13) label(0x10) - if_in_disarm_range(/*goto*/ 0x13) + if_can_see_attack_target(/*goto*/ 0x13) if_timer_gt(120, /*goto*/ 0x0b) goto_first(0x0c) diff --git a/src/include/commands.h b/src/include/commands.h index f31eb0be4..a2f2bd383 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -3237,9 +3237,14 @@ mkshort(u2), \ entity_type, -// Suspected to be named incorrectly. Global functions suggests this checks if -// the chr can see the player. -#define if_in_disarm_range(label) \ +/** + * Checks if the chr can see their attack target, which should have been + * specified in a prior attack command using entitytype and entityid. + * + * If the chr is not currently doing an attack action, it checks if they can see + * their normal target (same as if_can_see_target). + */ +#define if_can_see_attack_target(label) \ mkshort(0x017a), \ label, diff --git a/src/include/game/chr/chraction.h b/src/include/game/chr/chraction.h index b05adce1b..6d4882289 100644 --- a/src/include/game/chr/chraction.h +++ b/src/include/game/chr/chraction.h @@ -83,8 +83,8 @@ void func0f037b70(struct chrdata *chr); u32 chrGoToPos(struct chrdata *chr, struct coord *pos, s16 *room, u32 speed); u32 func0f038868(void); void func0f038b9c(struct chrdata *chr, struct path *path); -u32 func0f038f40(void); -u32 func0f0391ec(struct chrdata *chr, struct coord *pos, s16 *room, u32 arg3); +bool chrCanSeeEntity(struct chrdata *chr, struct coord *pos, s16 *rooms, bool arg3, u32 entitytype, u32 entityid); +bool chrCanSeeAttackTarget(struct chrdata *chr, struct coord *pos, s16 *rooms, bool arg3); bool chrCanSeeChr(struct chrdata *chr, struct chrdata *target, s16 *room); u32 func0f0393b4(struct chrdata *chr, struct coord *pos, s16 *room); bool func0f039474(struct chrdata *chr, struct coord *pos, s16 *room); diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index 8143d683d..74601281d 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -355,7 +355,7 @@ /*0x0177*/ bool aiPlayerAutoWalk(void); /*0x0178*/ bool aiIfPlayerAutoWalkFinished(void); /*0x0179*/ bool ai0179(void); -/*0x017a*/ bool ai017a(void); +/*0x017a*/ bool aiIfCanSeeAttackTarget(void); /*0x017b*/ bool aiIfChrKnockedOut(void); /*0x017c*/ bool aiAssignSound(void); /*0x017d*/ bool aiAudioSetMusicTrack(void);