From 5d3c5dad1a291c0bdc17e76b2e69858c3eec112a Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 08:24:11 +0400 Subject: fix(combat): let projectiles damage animals Verify the placed Constructor animal can be reached by a projectile segment, wounded and removed. The stock mission also starts in the Vulkan window. --- crates/fparkan-runtime/src/projectile.rs | 66 +++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'crates/fparkan-runtime/src/projectile.rs') diff --git a/crates/fparkan-runtime/src/projectile.rs b/crates/fparkan-runtime/src/projectile.rs index 2ad708eb..e2203fe2 100644 --- a/crates/fparkan-runtime/src/projectile.rs +++ b/crates/fparkan-runtime/src/projectile.rs @@ -16,6 +16,8 @@ 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; + /// Prepared visuals and travel parameters for one projectile prototype. pub struct ProjectileAssets { /// Visual, materials and control profile for the single projectile mesh. @@ -194,7 +196,8 @@ pub fn projectile_unit_hit( .filter_map(|(index, draft)| { let class = draft.unit_dat_header_flags?; let building = class & UNIT_DAT_CONTROL_CLASS_HIGH_BIT != 0; - if !building && class & super::autodemo::MOBILE_UNIT == 0 { + let animal = class == ANIMAL_UNIT_CLASS; + if !building && !animal && class & super::autodemo::MOBILE_UNIT == 0 { return None; } let handle = handle_by_original_id(&engine.world, draft.original_id?)?; @@ -394,6 +397,67 @@ pub fn apply_projectile_hit( mod tests { use super::*; + #[test] + #[ignore = "requires licensed corpus"] + fn licensed_constructor_animal_takes_projectile_damage() { + use crate::{ + create, load_gameplay_mission, starting_cockpit, EngineServices, MissionMode, + MissionRequest, MissionStartupInput, + }; + use fparkan_vfs::DirectoryVfs; + + 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(); + let shooter = starting_cockpit(&engine).unwrap().handle; + let mission = engine.loaded.as_ref().unwrap(); + let (index, draft) = mission + .object_drafts + .iter() + .enumerate() + .find(|(_, draft)| draft.unit_dat_header_flags == Some(ANIMAL_UNIT_CLASS)) + .unwrap(); + let creature = handle_by_original_id(&engine.world, draft.original_id.unwrap()).unwrap(); + let pose = transform_state(&engine.world, creature).unwrap(); + let ([x, y, z], radius) = unit_sphere(&mission.mission_assets, index, pose).unwrap(); + let shot = [[x, y, z + 2.0 * radius], [x, y, z]]; + let contact = projectile_unit_hit(&engine, shooter, shot).expect("animal contact"); + assert_eq!(contact.handle, creature); + let table = mission + .control_device_tables + .iter() + .find(|table| table.handle == creature) + .unwrap(); + let hp = f32::from_bits( + crate::control_node_provider_row(table, 0) + .unwrap() + .current_amount_bits, + ); + assert!(hp.is_finite() && hp > 0.0); + let remaining = hp * 0.5; + assert_eq!( + apply_projectile_contact(&mut engine, contact, remaining).unwrap(), + Some((remaining, false)) + ); + assert_eq!( + apply_projectile_contact(&mut engine, contact, remaining).unwrap(), + Some((0.0, true)) + ); + assert!(transform_state(&engine.world, creature).is_err()); + } + #[test] fn projectile_uses_queue_age_and_tests_only_the_traveled_segment() { let mut shot = -- cgit v1.2.3