diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 08:15:38 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 08:15:38 +0300 |
| commit | 25f0b76a10dbd5ac2cfabd5354f621ae82cf19b4 (patch) | |
| tree | 3e75179b9d41cdbf67903d42ee3883593f48b913 /crates/fparkan-runtime | |
| parent | 7f2f07669898e66b2391cfd36dcd7a9ea21bd90f (diff) | |
| download | fparkan-25f0b76a10dbd5ac2cfabd5354f621ae82cf19b4.tar.xz fparkan-25f0b76a10dbd5ac2cfabd5354f621ae82cf19b4.zip | |
feat(combat): enable the authored weapons of hostile animals
The armed Constructor creatures use the shared enemy search and fire their CTL weapon from Gun_Y. The stock start is outside range. The close encounter fixture shows the projectile in the Vulkan window and leaves the hero at 30 percent after one hit.
Diffstat (limited to 'crates/fparkan-runtime')
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 30 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/player_weapon.rs | 3 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/projectile.rs | 2 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/unit_combat.rs | 78 |
4 files changed, 91 insertions, 22 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index e54c81bb..24341ef6 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -2681,18 +2681,24 @@ node_provider_distribution_suspended: false, event.name_raw == b"Problems0\0" && !event.instructions.is_empty() }) }); - let autodemo_combat = (unit_patrol.is_some() || guard_clans.contains(&true) || periodic_ai) - .then(|| { - unit_combat::AutoDemoCombat::new( - &vfs, - &mission, - &object_drafts, - &handles, - &mission_assets, - reserve_start, - guard_clans, - ) - }); + let animals = options.start_autodemo + && object_drafts[..reserve_start] + .iter() + .any(|draft| draft.unit_dat_header_flags == Some(projectile::ANIMAL_UNIT_CLASS)); + let autodemo_combat = + (unit_patrol.is_some() || guard_clans.contains(&true) || periodic_ai || animals).then( + || { + unit_combat::AutoDemoCombat::new( + &vfs, + &mission, + &object_drafts, + &handles, + &mission_assets, + reserve_start, + guard_clans, + ) + }, + ); for &handle in &handles[reserve_start..] { fparkan_world::request_delete(&mut new_runtime_world, handle)?; } diff --git a/crates/fparkan-runtime/src/player_weapon.rs b/crates/fparkan-runtime/src/player_weapon.rs index 2ced63cd..b95b0cb7 100644 --- a/crates/fparkan-runtime/src/player_weapon.rs +++ b/crates/fparkan-runtime/src/player_weapon.rs @@ -271,7 +271,8 @@ fn prepare_weapons( let muzzle = points.points.get(row.raw_parameters[1] as usize)?; let rate = f32::from_bits(row.raw_parameters[2]); if muzzle.raw_signed_field_04 < 0 - || muzzle.raw_signed_field_04 != muzzle.raw_signed_field_08 + || (muzzle.raw_signed_field_08 != -1 + && muzzle.raw_signed_field_04 != muzzle.raw_signed_field_08) || !rate.is_finite() || rate <= 0.0 || row.flags & 1 != 0 diff --git a/crates/fparkan-runtime/src/projectile.rs b/crates/fparkan-runtime/src/projectile.rs index 0767ee4e..75790dbf 100644 --- a/crates/fparkan-runtime/src/projectile.rs +++ b/crates/fparkan-runtime/src/projectile.rs @@ -16,7 +16,7 @@ use fparkan_vfs::Vfs; use fparkan_world::{handle_by_original_id, request_delete, transform_state, ObjectHandle}; use std::sync::Arc; -const ANIMAL_UNIT_CLASS: u32 = 0x2000_0000; +pub(super) const ANIMAL_UNIT_CLASS: u32 = 0x2000_0000; /// Prepared visuals and travel parameters for one projectile prototype. pub struct ProjectileAssets { diff --git a/crates/fparkan-runtime/src/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs index 35ff1a93..3cf268ec 100644 --- a/crates/fparkan-runtime/src/unit_combat.rs +++ b/crates/fparkan-runtime/src/unit_combat.rs @@ -3,7 +3,7 @@ use super::{ autodemo::MOBILE_UNIT, combat_report::{CombatObject, CombatReport}, player_weapon::prepare_unit_weapons, - projectile::{load_projectile, segment_sphere_fraction, unit_sphere}, + projectile::{load_projectile, segment_sphere_fraction, unit_sphere, ANIMAL_UNIT_CLASS}, projectile_terrain_hit, projectile_unit_hit, turret_aim::{hull_local_point, TurretAim}, unit_patrol::UnitPatrol, @@ -164,10 +164,8 @@ impl AutoDemoCombat { unavailable: 0, }; for (index, (draft, &handle)) in drafts.iter().zip(handles).enumerate() { - if !draft - .unit_dat_header_flags - .is_some_and(|class| class & MOBILE_UNIT != 0) - { + let class = draft.unit_dat_header_flags.unwrap_or(0); + if class & MOBILE_UNIT == 0 && class != ANIMAL_UNIT_CLASS { continue; } let object = CombatObject { @@ -181,6 +179,9 @@ impl AutoDemoCombat { .get(index) .map_or(&[], Vec::as_slice), ); + if class == ANIMAL_UNIT_CLASS && weapons.weapons().is_empty() { + continue; + } let slots = weapons .weapons() .iter() @@ -505,12 +506,14 @@ impl AutoDemoCombat { .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 defends_from_position = matches!( + mission.object_drafts[unit.index].unit_dat_header_flags, + Some(super::boarding::WARBOT_CLASS | ANIMAL_UNIT_CLASS) + ); let eligible = !manually_controlled && (mission.script_host_mode != super::MissionMode::SingleMission || guard - || warbot + || defends_from_position || mission .unit_patrol .as_ref() @@ -711,6 +714,65 @@ mod tests { #[test] #[ignore = "requires licensed corpus"] + fn licensed_constructor_animal_fires_at_a_nearby_hero() { + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus"); + let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/CAMPAIGN/CAMPAIGN.00/Mission.02/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + assert!(frame(&mut engine, 0) + .unwrap() + .autodemo_combat_events + .is_empty()); + + let hero = starting_cockpit(&engine).unwrap().handle; + let animal = mission_object_handle(&engine, OriginalObjectId(2)).unwrap(); + let [x, y, z] = transform_state(&engine.world, animal) + .unwrap() + .position + .map(f32::from_bits); + let mut pose = transform_state(&engine.world, hero).unwrap(); + pose.position = [x + 24.0, y, z + 6.0].map(f32::to_bits); + set_transform(&mut engine.world, hero, pose).unwrap(); + let mut fired = false; + for now in (50..=1_500).step_by(50) { + let result = frame(&mut engine, now).unwrap(); + fired |= result.autodemo_combat_events.iter().any(|event| { + let AutoDemoCombatEvent::Shot { + shooter, + target, + projectile, + .. + } = *event + else { + return false; + }; + shooter == animal + && target == hero + && engine.autodemo_combat.as_ref().unwrap().projectiles[projectile].name + == "ba_a_03" + }); + if fired + && player_status(&engine, hero).and_then(|status| status.health_percent) == Some(30) + { + return; + } + } + panic!("the stock animal must fire its projectile and damage the hero (fired={fired})"); + } + + #[test] + #[ignore = "requires licensed corpus"] fn licensed_autodemo_combat_preserves_muzzles_and_event_identities() { let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus"); let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); |
