aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-26 07:43:22 +0300
committerValentin Popov <valentin@popov.link>2026-11-26 07:43:22 +0300
commitcc3c6bcb3b8d5ed2f6bb09ca3ee423d3d5d8716a (patch)
treec1f8fe89feba84f44ef871d62ab44ee8397e59e8 /crates
parent5d3c5dad1a291c0bdc17e76b2e69858c3eec112a (diff)
downloadfparkan-cc3c6bcb3b8d5ed2f6bb09ca3ee423d3d5d8716a.tar.xz
fparkan-cc3c6bcb3b8d5ed2f6bb09ca3ee423d3d5d8716a.zip
feat(combat): give idle warbots local defensive fire
Free armed warbots use the existing hostile target search and fire without a movement order. A boarded warbot keeps manual firing. From the unmodified Two Fortresses start, the plant defender fires at 158.5 s and destroys the scripted capturer at 161.9 s in the Vulkan window.
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-runtime/src/unit_combat.rs54
1 files changed, 48 insertions, 6 deletions
diff --git a/crates/fparkan-runtime/src/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs
index 7059a09b..35ff1a93 100644
--- a/crates/fparkan-runtime/src/unit_combat.rs
+++ b/crates/fparkan-runtime/src/unit_combat.rs
@@ -500,12 +500,21 @@ impl AutoDemoCombat {
.and_then(|identity| identity.owner_id);
let guard = owner
.is_some_and(|owner| self.guard_clans.get(usize::from(owner.0)) == Some(&true));
- let eligible = mission.script_host_mode != super::MissionMode::SingleMission
- || guard
- || mission
- .unit_patrol
- .as_ref()
- .is_some_and(|patrol| patrol.is_patrolling(unit.handle));
+ let manually_controlled = mission
+ .boarding
+ .is_some_and(|boarding| boarding.cockpit.handle == unit.handle);
+ // shortcut: free warbots defend from their current position until the
+ // default Behavior task and its pursuit rules are wired.
+ let warbot = mission.object_drafts[unit.index].unit_dat_header_flags
+ == Some(super::boarding::WARBOT_CLASS);
+ let eligible = !manually_controlled
+ && (mission.script_host_mode != super::MissionMode::SingleMission
+ || guard
+ || warbot
+ || mission
+ .unit_patrol
+ .as_ref()
+ .is_some_and(|patrol| patrol.is_patrolling(unit.handle)));
let aim = eligible
.then(|| {
targets
@@ -921,6 +930,39 @@ mod tests {
#[test]
#[ignore = "requires licensed corpus"]
+ fn licensed_stock_defender_fires_at_an_approaching_capturer() {
+ let mut engine = stock_two_fortresses();
+ let defender = mission_object_handle(&engine, OriginalObjectId(17)).unwrap();
+ let before = transform_state(&engine.world, defender).unwrap();
+ assert_eq!(mission_guard_fallback_count(&engine), 0);
+ assert!(frame(&mut engine, 0)
+ .unwrap()
+ .autodemo_combat_events
+ .is_empty());
+
+ for tick in 1..=60 * 190 {
+ let result = frame(&mut engine, tick * 1000 / 60).unwrap();
+ for event in result.autodemo_combat_events {
+ if let AutoDemoCombatEvent::Shot {
+ shooter, target, ..
+ } = event
+ {
+ if shooter == defender {
+ assert_eq!(
+ identity_metadata(&engine.world, target).unwrap().owner_id,
+ Some(OwnerId(1))
+ );
+ assert_eq!(transform_state(&engine.world, defender).unwrap(), before);
+ return;
+ }
+ }
+ }
+ }
+ panic!("the stock defender never fired at the enemy approach");
+ }
+
+ #[test]
+ #[ignore = "requires licensed corpus"]
fn licensed_scripted_patrol_fires_without_a_guard_fallback() {
let mut engine = stock_two_fortresses();
assert_eq!(mission_guard_fallback_count(&engine), 0);