diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 14:01:30 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 14:01:30 +0300 |
| commit | 85082a1c829050f375ad688d9ed563d753b3727b (patch) | |
| tree | 58137bbf74beccd37fefcb80accb366137c0f514 /crates/fparkan-runtime/src/unit_patrol.rs | |
| parent | 2dc43ad60e04922c630449f033f52e9e6839e2df (diff) | |
| download | fparkan-85082a1c829050f375ad688d9ed563d753b3727b.tar.xz fparkan-85082a1c829050f375ad688d9ed563d753b3727b.zip | |
feat(movement): migrate animals between authored sites
Select shared migration sites on the ArealMap cadence and feed them to the common route follower with the animal flight clearance and Control climb limit. In The Constructor, both medusas lift off and travel around the selected site from their stock positions. The window showed the change at a fixed viewpoint with clean Vulkan validation. Path details and threat acquisition remain approximate.
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol.rs | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs index b4b81c7f..59965b4c 100644 --- a/crates/fparkan-runtime/src/unit_patrol.rs +++ b/crates/fparkan-runtime/src/unit_patrol.rs @@ -1,4 +1,5 @@ use super::{ + animal_migration::{flight_clearance, AnimalMigration}, autodemo::{MOBILE_UNIT, PLANT_CLASS}, boarding::WARBOT_CLASS, building_passage::CapturePassage, @@ -9,7 +10,7 @@ use super::{ patrol_points::{PatrolPointReport, PatrolPoints}, route_motion::{follow_route, route_points, turn_toward, RouteClearance}, route_obstacles::BuildingFootprints, - route_traffic::FrameTraffic, + route_traffic::{body_radius, FrameTraffic}, unit_combat::CombatTarget, unit_speed::{order_speed, UnitSpeedKind, UnitSpeedReport}, EngineError, LoadedMissionState, MissionDocument, MissionObjectDraft, MissionScriptBundle, @@ -28,6 +29,8 @@ pub(super) struct UnitPatrol { center: Option<[f32; 2]>, units: Vec<PatrollingUnit>, factory_departures: Vec<FactoryDeparture>, + animal_migration: Vec<AnimalMigration>, + migration_rng: u32, shut_down: HashSet<ObjectHandle>, script_orders: Vec<(ObjectHandle, VecDeque<orders::UnitOrder>)>, script_order_counts: BTreeMap<(u32, u32), u64>, @@ -55,6 +58,7 @@ struct PatrollingUnit { raid_factory: Option<(ObjectHandle, usize)>, ground_support: Option<Option<GroundSupport>>, capture_passage: Option<CapturePassage>, + animal_clearance: Option<f32>, } pub(super) struct PreparedPatrol { @@ -160,6 +164,8 @@ impl UnitPatrol { center: None, units: Vec::new(), factory_departures: Vec::new(), + animal_migration: Vec::new(), + migration_rng: 1, shut_down: HashSet::new(), script_orders: Vec::new(), script_order_counts: BTreeMap::new(), @@ -217,6 +223,7 @@ impl UnitPatrol { raid_factory: None, ground_support: None, capture_passage: None, + animal_clearance: None, }); true } @@ -260,6 +267,39 @@ impl UnitPatrol { } } + pub(super) fn set_animal_migration(&mut self, migration: Vec<AnimalMigration>) { + for clan in &migration { + eprintln!( + "animal_migration_approx clan={} (animal route, arrival and RNG order remain open)", + clan.owner.0 + ); + } + self.animal_migration = migration; + } + + fn advance_animal_migration(&mut self, world: &World, now_ms: u32, crt: &mut u32) { + let mut migrations = std::mem::take(&mut self.animal_migration); + for migration in &mut migrations { + migration + .animals + .retain(|&handle| transform_state(world, handle).is_ok()); + if migration.animals.is_empty() { + continue; + } + let Some(site) = migration.select(now_ms, &mut self.migration_rng) else { + continue; + }; + for &handle in &migration.animals { + self.order(world, handle, site.center, site.radius); + if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == handle) { + unit.animal_clearance = Some(flight_clearance(crt)); + } + } + } + migrations.retain(|migration| !migration.animals.is_empty()); + self.animal_migration = migrations; + } + pub(super) fn hallway_doors( &self, building: ObjectHandle, @@ -445,12 +485,15 @@ impl UnitPatrol { raid_factory: None, ground_support: None, capture_passage: None, + animal_clearance: None, }) .collect(); Some(Self { center: Some(center), units, factory_departures: Vec::new(), + animal_migration: Vec::new(), + migration_rng: 1, shut_down: HashSet::new(), script_orders: Vec::new(), script_order_counts: BTreeMap::new(), @@ -477,6 +520,7 @@ impl UnitPatrol { let chassis = &mission.unit_chassis_flags; let mut state = self.clone(); state.advance_script_orders(world, &mission.control_device_tables); + state.advance_animal_migration(world, now_ms, crt); state.units.retain(|unit| { (unit .destinations @@ -524,7 +568,10 @@ impl UnitPatrol { let from = before.position.map(f32::from_bits); let motion_object = crate::CombatObject::read(world, unit.handle); let original_id = motion_object.original_id.unwrap_or(unit.handle.slot); - let can_fly = chassis.get(&original_id).and_then(|flags| flags.can_fly); + let can_fly = unit + .animal_clearance + .map(|_| true) + .or_else(|| chassis.get(&original_id).and_then(|flags| flags.can_fly)); if let Some(destinations) = &mut unit.destinations { if destinations .front() @@ -653,9 +700,17 @@ impl UnitPatrol { continue; } state.motion_report.update(motion_object, now_ms); - let radius = traffic.radius(unit.handle); + let radius = if unit.animal_clearance.is_some() { + body_radius(&mission.mission_assets, original_id as usize, before).unwrap_or(1.0) + } else { + traffic.radius(unit.handle) + }; let flight = (can_fly == Some(true) && radius > 0.0).then_some(FlightClearance { body_radius: radius, + height: unit.animal_clearance.unwrap_or(2.0 * radius), + vertical_limit: unit.animal_clearance.map_or(f32::INFINITY, |_| { + super::animal_migration::vertical_limit(mission, unit.handle) + }), }); let ground = if can_fly == Some(false) { *unit.ground_support.get_or_insert_with(|| { |
