From c846377ead77ef7184cdeddd25c3f2c9d76a6736 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 13:27:06 +0400 Subject: feat(ui): send warbots to recharge from the strategic panel Verify LTW-3 approaches the generator and clears its recharge status after leaving from the stock Two Fortresses start. Reuse authored building passages and shared Control replenishment, with a licensed test for refilling an empty magazine. --- crates/fparkan-runtime/src/building_passage.rs | 83 +++++-- crates/fparkan-runtime/src/clan_targeting.rs | 9 +- crates/fparkan-runtime/src/control_resources.rs | 6 +- crates/fparkan-runtime/src/repair_zone.rs | 23 +- crates/fparkan-runtime/src/strategic_orders.rs | 5 + crates/fparkan-runtime/src/strategic_roster.rs | 1 + crates/fparkan-runtime/src/unit_patrol.rs | 41 +++- crates/fparkan-runtime/src/unit_patrol/orders.rs | 17 +- crates/fparkan-runtime/src/unit_patrol/recharge.rs | 267 +++++++++++++++++++++ 9 files changed, 400 insertions(+), 52 deletions(-) create mode 100644 crates/fparkan-runtime/src/unit_patrol/recharge.rs (limited to 'crates/fparkan-runtime/src') diff --git a/crates/fparkan-runtime/src/building_passage.rs b/crates/fparkan-runtime/src/building_passage.rs index a3da910e..69148b49 100644 --- a/crates/fparkan-runtime/src/building_passage.rs +++ b/crates/fparkan-runtime/src/building_passage.rs @@ -1,4 +1,4 @@ -//! Approaches and doors along a building's authored route to the capture point. +//! Approaches and doors along a building's authored routes. use crate::{ building_door::{is_bound_door, DOOR_BLEND_PER_SECOND}, @@ -13,9 +13,9 @@ use fparkan_terrain::SurfaceQuery; use fparkan_world::TransformState; use std::collections::VecDeque; -pub(super) struct CaptureEntrance { +pub(super) struct PassageEntrance { pub(super) staging: [f32; 2], - pub(super) capture: [f32; 3], + pub(super) goal: [f32; 3], pub(super) legs: VecDeque, } @@ -26,34 +26,34 @@ pub(super) struct PassageLeg { } #[derive(Clone)] -pub(super) struct CapturePassage { +pub(super) struct BuildingPassage { pub(super) building: ObjectHandle, pub(super) legs: VecDeque, pub(super) opening: Option<(usize, f32)>, } -pub(super) fn capture_entrance( +pub(super) fn building_entrance( assets: &MissionAssets, terrain: &TerrainWorld, index: usize, pose: TransformState, from: [f32; 3], clearance: f32, -) -> Option { + goal_mask: u32, +) -> Option { let model = &root_model(assets, index)?.validated; let hallway = &model.hallway; - // Behavior::GoInside passes mask 0x40 to HallWay's first-match query. let goal = hallway .points .iter() - .position(|point| point.flags & 0x40 != 0)?; + .position(|point| point.flags & goal_mask != 0)?; let control = assets .object_component_controls .get(index)? .first()? .as_ref()?; let door_for_link = |link: &HallwayLink| linked_door(link, |key| is_bound_door(control, key)); - let toward_capture = links_to(hallway, goal, |link| door_for_link(link).is_some()); + let toward_goal = links_to(hallway, goal, |link| door_for_link(link).is_some()); let hierarchy = node38_fallback_hierarchy(model)?; let transform = LegacyIron3dEulerTransform { translation: pose.position.map(f32::from_bits), @@ -65,7 +65,7 @@ pub(super) fn capture_entrance( let node = hierarchy.poses.get(point.node.0 as usize)?; transform.try_transform_scaled_point(node.transform_point(point.position), scale) }; - let capture = project(goal)?; + let goal_position = project(goal)?; let footprint = model_footprint(assets, index, pose)?.expanded(clearance); hallway .points @@ -74,7 +74,7 @@ pub(super) fn capture_entrance( .filter(|(_, point)| point.flags & 0x1000_0001 == 1) .filter_map(|(index, _)| { let entrance = project(index)?; - let inside = project(toward_capture[index]?.0)?; + let inside = project(toward_goal[index]?.0)?; let staging = footprint.exterior_along( [entrance[0], entrance[1]], [entrance[0] - inside[0], entrance[1] - inside[1]], @@ -82,19 +82,12 @@ pub(super) fn capture_entrance( let ground = terrain.height_at(staging).ok()??; route_points(terrain, from, [staging[0], staging[1], ground]).ok()??; let distance: f32 = (0..3).map(|i| (from[i] - entrance[i]).powi(2)).sum(); - let legs = passage_legs( - index, - goal, - &toward_capture, - hallway, - door_for_link, - project, - )?; + let legs = passage_legs(index, goal, &toward_goal, hallway, door_for_link, project)?; Some(( distance, - CaptureEntrance { + PassageEntrance { staging, - capture, + goal: goal_position, legs, }, )) @@ -168,7 +161,26 @@ fn linked_door(link: &HallwayLink, is_bound: impl Fn(u32) -> bool) -> Option VecDeque { + let reversed = self.legs.iter().rev(); + let mut exit: VecDeque<_> = reversed + .clone() + .zip(reversed.skip(1)) + .map(|(leaving, next)| PassageLeg { + position: next.position, + door: leaving.door, + }) + .collect(); + exit.push_back(PassageLeg { + position: [self.staging[0], self.staging[1], ground], + door: None, + }); + exit + } +} + +impl BuildingPassage { pub(super) fn advance( &mut self, mut pose: TransformState, @@ -275,9 +287,34 @@ mod tests { ); } + #[test] + fn reverse_passage_keeps_door_on_the_same_link() { + let start = [2.0, 0.0, 1.0]; + let target = [2.0, 3.0, 0.0]; + let route = PassageEntrance { + staging: [2.0, -1.0], + goal: target, + legs: VecDeque::from([ + PassageLeg { + position: start, + door: None, + }, + PassageLeg { + position: target, + door: Some(7), + }, + ]), + }; + let exit = route.exit(0.5); + assert_eq!(exit[0].position, start); + assert_eq!(exit[0].door, Some(7)); + assert_eq!(exit[1].position, [2.0, -1.0, 0.5]); + assert_eq!(exit[1].door, None); + } + #[test] fn capture_link_waits_for_the_door_and_follows_the_sloped_passage() { - let mut route = CapturePassage { + let mut route = BuildingPassage { building: ObjectHandle { slot: 0, generation: 1, diff --git a/crates/fparkan-runtime/src/clan_targeting.rs b/crates/fparkan-runtime/src/clan_targeting.rs index 78967333..ca70a382 100644 --- a/crates/fparkan-runtime/src/clan_targeting.rs +++ b/crates/fparkan-runtime/src/clan_targeting.rs @@ -1,5 +1,5 @@ use crate::{ - building_passage::{capture_entrance, CapturePassage}, + building_passage::{building_entrance, BuildingPassage}, clan_combat_strength::unit_strength, projectile::unit_sphere, MissionControlDeviceTableState, MissionDocument, MissionObjectDraft, TerrainWorld, @@ -50,13 +50,14 @@ pub(super) fn send_capturer( let unit_id = identity_metadata(world, unit.handle).ok()?.original_id?; let clearance = unit_sphere(assets, unit_id.0 as usize, unit_pose).map_or(0.0, |(_, r)| r); let (destination, point, passage) = - if let Some(entrance) = capture_entrance(assets, terrain, index, pose, from, clearance) { - let passage = Some(CapturePassage { + // Behavior::GoInside selects the first Hallway point with flag 0x40. + if let Some(entrance) = building_entrance(assets, terrain, index, pose, from, clearance, 0x40) { + let passage = Some(BuildingPassage { building: unit.target, legs: entrance.legs, opening: None, }); - (entrance.staging, entrance.capture, passage) + (entrance.staging, entrance.goal, passage) } else { let point = nearest_platform_point( crate::mission_events::communicator_triangles(assets, index, class, pose)?, diff --git a/crates/fparkan-runtime/src/control_resources.rs b/crates/fparkan-runtime/src/control_resources.rs index 3e7f8aab..676f7008 100644 --- a/crates/fparkan-runtime/src/control_resources.rs +++ b/crates/fparkan-runtime/src/control_resources.rs @@ -133,7 +133,11 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) { continue; }; if mobile_owner { - repair_zone::service_unit(table, world, pose, &facilities, seconds); + let docked = mission + .unit_patrol + .as_ref() + .is_some_and(|patrol| patrol.is_servicing(table.handle)); + repair_zone::service_unit(table, world, pose, &facilities, seconds, docked); } let object = table.original_id.map_or(table.handle.slot, |id| id.0); let ticks = state.profiles.ticks.entry(object).or_default(); diff --git a/crates/fparkan-runtime/src/repair_zone.rs b/crates/fparkan-runtime/src/repair_zone.rs index 20a14d85..89d150a3 100644 --- a/crates/fparkan-runtime/src/repair_zone.rs +++ b/crates/fparkan-runtime/src/repair_zone.rs @@ -183,6 +183,7 @@ pub(super) fn service_unit( pose: TransformState, facilities: &[ActiveFacility<'_>], seconds: f32, + docked: bool, ) { if table.node_provider_depletion_marked || seconds <= 0.0 { return; @@ -194,16 +195,18 @@ pub(super) fn service_unit( return; }; let position = pose.position.map(f32::from_bits); - let in_service = facilities - .iter() - .filter(|site| site.owner == owner) - .any(|site| { - let m = &site.matrix; - let [x, y, z] = [position[0] - m[3], position[1] - m[7], position[2] - m[11]]; - let local = - std::array::from_fn(|i| (m[i] * x + m[i + 4] * y + m[i + 8] * z) / site.scale[i]); - site.volumes.iter().any(|volume| volume.contains(local)) - }); + let in_service = docked + || facilities + .iter() + .filter(|site| site.owner == owner) + .any(|site| { + let m = &site.matrix; + let [x, y, z] = [position[0] - m[3], position[1] - m[7], position[2] - m[11]]; + let local = std::array::from_fn(|i| { + (m[i] * x + m[i + 4] * y + m[i + 8] * z) / site.scale[i] + }); + site.volumes.iter().any(|volume| volume.contains(local)) + }); if in_service { let fraction = seconds * HEALTH_FRACTION_PER_SECOND; repair_nodes(table, fraction); diff --git a/crates/fparkan-runtime/src/strategic_orders.rs b/crates/fparkan-runtime/src/strategic_orders.rs index a20153b0..f99f60bf 100644 --- a/crates/fparkan-runtime/src/strategic_orders.rs +++ b/crates/fparkan-runtime/src/strategic_orders.rs @@ -59,6 +59,11 @@ pub fn search_and_destroy( issue(engine, cockpit, actor, UnitOrder::SearchAndDestroy) } +/// Sends the selected warbot to a friendly facility to replenish its supplies. +pub fn recharge(engine: &mut Engine, cockpit: StartingCockpit, actor: ObjectHandle) -> bool { + issue(engine, cockpit, actor, UnitOrder::Recharge) +} + /// Replaces the selected warbot's order with the confirmed sequence of world points. pub fn follow_route( engine: &mut Engine, diff --git a/crates/fparkan-runtime/src/strategic_roster.rs b/crates/fparkan-runtime/src/strategic_roster.rs index fb46ec90..f5fc4dfd 100644 --- a/crates/fparkan-runtime/src/strategic_roster.rs +++ b/crates/fparkan-runtime/src/strategic_roster.rs @@ -148,6 +148,7 @@ pub(super) fn order_label(order: u32) -> u32 { 3 => 0x182c, 4 => 0x182d, 5 => 0x182e, + 8 => 0x1831, 0x11 => 0x1833, 0x13 => 0x1826, 0x14 => 0x1829, diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs index 48e4924a..6a230135 100644 --- a/crates/fparkan-runtime/src/unit_patrol.rs +++ b/crates/fparkan-runtime/src/unit_patrol.rs @@ -2,7 +2,7 @@ use super::{ animal_migration::{flight_clearance, AnimalMigration}, autodemo::{MOBILE_UNIT, PLANT_CLASS}, boarding::WARBOT_CLASS, - building_passage::CapturePassage, + building_passage::BuildingPassage, factory_release::FactoryDeparture, flight_altitude::FlightClearance, ground_support::GroundSupport, @@ -22,6 +22,7 @@ use fparkan_world::{set_transform, transform_state}; use std::collections::{BTreeMap, HashSet, VecDeque}; mod orders; +mod recharge; mod search_and_destroy; pub(super) use orders::supports_order; pub(super) use orders::UnitOrder; @@ -58,11 +59,12 @@ pub(super) struct PatrollingUnit { retry_ms: u32, attack: Option, search: Option, + recharge: Option, attack_target: Option<(ObjectHandle, usize)>, raid_factory: Option<(ObjectHandle, usize)>, ground_support: Option>, capture_target: Option, - capture_passage: Option, + building_passage: Option, animal_clearance: Option, } @@ -200,14 +202,16 @@ impl UnitPatrol { if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == handle) { unit.raid_factory = None; unit.capture_target = None; - unit.capture_passage = None; + unit.building_passage = None; let was_attacking = unit.attack_target.take().is_some(); let was_moving = unit.destinations.take().is_some(); let was_searching = unit.search.take().is_some(); + let was_recharging = unit.recharge.take().is_some(); if unit.center_object.take().is_some() || was_moving || was_attacking || was_searching + || was_recharging || unit.center != center || unit.radius != radius { @@ -231,11 +235,12 @@ impl UnitPatrol { retry_ms: 0, attack: None, search: None, + recharge: None, attack_target: None, raid_factory: None, ground_support: None, capture_target: None, - capture_passage: None, + building_passage: None, animal_clearance: None, }); true @@ -273,12 +278,12 @@ impl UnitPatrol { handle: ObjectHandle, building: ObjectHandle, destination: [f32; 2], - passage: Option, + passage: Option, ) { self.move_to(world, handle, destination, false); if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == handle) { unit.capture_target = Some(building); - unit.capture_passage = passage; + unit.building_passage = passage; } } @@ -321,7 +326,7 @@ impl UnitPatrol { ) -> impl Iterator + '_ { self.units .iter() - .filter_map(|unit| unit.capture_passage.as_ref()) + .filter_map(|unit| unit.building_passage.as_ref()) .filter(move |route| route.building == building) .filter_map(|route| route.opening) } @@ -493,11 +498,12 @@ impl UnitPatrol { retry_ms: 0, attack: None, search: None, + recharge: None, attack_target: None, raid_factory: None, ground_support: None, capture_target: None, - capture_passage: None, + building_passage: None, animal_clearance: None, }) .collect(); @@ -541,9 +547,10 @@ impl UnitPatrol { .as_ref() .is_none_or(|items| !items.is_empty()) || unit - .capture_passage + .building_passage .as_ref() - .is_some_and(|route| !route.legs.is_empty())) + .is_some_and(|route| !route.legs.is_empty()) + || unit.recharge.is_some()) && unit.center(world).is_some() }); let seconds = now_ms.saturating_sub(state.clock_ms) as f32 * 0.001; @@ -586,6 +593,18 @@ impl UnitPatrol { .animal_clearance .map(|_| true) .or_else(|| chassis.get(&original_id).and_then(|flags| flags.can_fly)); + if unit.recharge.is_some() + && (seconds == 0.0 + || !unit.advance_recharge( + world, + mission, + now_ms, + from, + traffic.radius(unit.handle), + )) + { + continue; + } if let Some(destinations) = &mut unit.destinations { if destinations .front() @@ -596,7 +615,7 @@ impl UnitPatrol { unit.retry_ms = 0; } if destinations.is_empty() { - if let Some(route) = &mut unit.capture_passage { + if let Some(route) = &mut unit.building_passage { if transform_state(world, route.building).is_err() { route.legs.clear(); continue; diff --git a/crates/fparkan-runtime/src/unit_patrol/orders.rs b/crates/fparkan-runtime/src/unit_patrol/orders.rs index b956c599..8198b17d 100644 --- a/crates/fparkan-runtime/src/unit_patrol/orders.rs +++ b/crates/fparkan-runtime/src/unit_patrol/orders.rs @@ -16,6 +16,7 @@ pub(crate) enum UnitOrder { Route(Vec<[f32; 2]>), StrategicPatrol(PatrolTarget), SearchAndDestroy, + Recharge, Shutdown, Resume(Box), } @@ -27,6 +28,7 @@ impl UnitOrder { Self::Attack(..) => 3, Self::Patrol(..) | Self::StrategicPatrol(_) => 4, Self::SearchAndDestroy => 5, + Self::Recharge => 8, Self::Shutdown => 0x13, Self::Stand => 0x15, Self::Resume(_) => unreachable!("a suspended order has already started"), @@ -86,6 +88,8 @@ impl UnitPatrol { 0x11 } else if unit.search.is_some() { UnitOrder::SearchAndDestroy.opcode() + } else if unit.recharge.is_some() { + UnitOrder::Recharge.opcode() } else if unit.attack_target.is_some() || unit.raid_factory.is_some() { 3 } else if unit @@ -105,7 +109,9 @@ impl UnitPatrol { let active = self.units.iter().find(|unit| unit.handle == actor); // iron3d+0x77ae0 draws published waypoints. Search does not publish its // internal navigation path to the satellite map. - if let Some(unit) = active.filter(|unit| unit.search.is_none() && !unit.points.is_empty()) { + if let Some(unit) = active.filter(|unit| { + unit.search.is_none() && unit.recharge.is_none() && !unit.points.is_empty() + }) { return unit.points.iter().copied().collect(); } let mut points = Vec::new(); @@ -127,7 +133,8 @@ impl UnitPatrol { UnitOrder::Attack(..) | UnitOrder::Shutdown | UnitOrder::Stand - | UnitOrder::SearchAndDestroy => {} + | UnitOrder::SearchAndDestroy + | UnitOrder::Recharge => {} } } } @@ -308,6 +315,7 @@ impl UnitPatrol { return true; } UnitOrder::SearchAndDestroy => return self.start_search(world, actor), + UnitOrder::Recharge => return self.start_recharge(world, actor), UnitOrder::Route(route) => { for (index, &point) in route.iter().enumerate() { self.move_to(world, actor, point, index != 0); @@ -399,7 +407,7 @@ impl UnitPatrol { .iter() .find(|unit| unit.handle == actor) .is_none_or(|unit| { - if unit.capture_target.is_some() { + if unit.capture_target.is_some() || unit.recharge.is_some() { return false; } if let Some(points) = &unit.destinations { @@ -434,6 +442,9 @@ impl UnitPatrol { impl PatrollingUnit { fn append_point_orders(&self, points: &mut Vec<[f32; 2]>) { + if self.recharge.is_some() { + return; + } if let Some(destinations) = &self.destinations { points.extend(destinations); } else if self.patrols_point(self.center) && self.raid_factory.is_none() { diff --git a/crates/fparkan-runtime/src/unit_patrol/recharge.rs b/crates/fparkan-runtime/src/unit_patrol/recharge.rs new file mode 100644 index 00000000..2ea9371b --- /dev/null +++ b/crates/fparkan-runtime/src/unit_patrol/recharge.rs @@ -0,0 +1,267 @@ +//! Behavior task 8: approach a friendly recharge point, service, then leave. + +use super::{ObjectHandle, PatrollingUnit, UnitPatrol, World}; +use crate::{ + building_passage::{building_entrance, BuildingPassage, PassageLeg}, + LoadedMissionState, +}; +use fparkan_terrain::SurfaceQuery; +use fparkan_world::{identity_metadata, registration_sequence, transform_state, OwnerId}; +use std::collections::VecDeque; + +#[derive(Clone)] +pub(super) enum Recharge { + FindFacility, + Approach { + facility: ObjectHandle, + exit: VecDeque, + }, + Service { + facility: ObjectHandle, + exit: VecDeque, + since_ms: u32, + }, + Leave { + facility: ObjectHandle, + }, +} + +impl UnitPatrol { + pub(super) fn start_recharge(&mut self, world: &World, actor: ObjectHandle) -> bool { + let Ok(pose) = transform_state(world, actor) else { + return false; + }; + let [x, y, _] = pose.position.map(f32::from_bits); + self.order(world, actor, [x, y], f32::INFINITY); + if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == actor) { + unit.recharge = Some(Recharge::FindFacility); + unit.destinations = Some(VecDeque::new()); + } + true + } + + pub(crate) fn is_servicing(&self, actor: ObjectHandle) -> bool { + self.units.iter().any(|unit| { + unit.handle == actor && matches!(unit.recharge, Some(Recharge::Service { .. })) + }) + } +} + +impl PatrollingUnit { + /// Returns whether the recharge task is still active. + pub(super) fn advance_recharge( + &mut self, + world: &World, + mission: &LoadedMissionState, + now_ms: u32, + from: [f32; 3], + clearance: f32, + ) -> bool { + let Some(task) = self.recharge.take() else { + return false; + }; + let owner = identity_metadata(world, self.handle) + .ok() + .and_then(|meta| meta.owner_id); + let travel_complete = self.destinations.as_ref().is_none_or(VecDeque::is_empty) + && self + .building_passage + .as_ref() + .is_none_or(|route| route.legs.is_empty()); + self.recharge = match task { + Recharge::FindFacility => owner.and_then(|owner| { + let (destination, passage, exit) = + approach(world, mission, owner, from, clearance)?; + let facility = passage.building; + self.destinations = Some(VecDeque::from([destination])); + self.building_passage = Some(passage); + Some(Recharge::Approach { facility, exit }) + }), + Recharge::Approach { facility, exit } if travel_complete => Some(Recharge::Service { + facility, + exit, + since_ms: now_ms, + }), + Recharge::Service { + facility, + exit, + since_ms, + } if now_ms.saturating_sub(since_ms) > 10_000 => { + // Behavior+0x2eaa0 changes from service to leaving after ten seconds. + self.building_passage = Some(BuildingPassage { + building: facility, + legs: exit, + opening: None, + }); + Some(Recharge::Leave { facility }) + } + Recharge::Leave { .. } if travel_complete => None, + _ => Some(task), + }; + let valid = self.recharge.as_ref().is_some_and(|task| match task { + Recharge::FindFacility => false, + Recharge::Approach { facility, .. } + | Recharge::Service { facility, .. } + | Recharge::Leave { facility } => usable(world, mission, *facility, owner), + }); + if !valid { + self.recharge = None; + self.destinations = Some(VecDeque::new()); + self.points.clear(); + self.building_passage = None; + } + valid + } +} + +fn approach( + world: &World, + mission: &LoadedMissionState, + owner: OwnerId, + from: [f32; 3], + clearance: f32, +) -> Option<([f32; 2], BuildingPassage, VecDeque)> { + mission + .control_device_tables + .iter() + .filter_map(|table| { + let facility = table.handle; + let index = table.original_id?.0 as usize; + let class = mission.object_drafts.get(index)?.unit_dat_header_flags?; + if class & 0x8000_0000 == 0 || !usable(world, mission, facility, Some(owner)) { + return None; + } + let pose = transform_state(world, facility).ok()?; + // Behavior+0x23b60 requests a Hallway point with mask 0x620. + let entry = building_entrance( + &mission.mission_assets, + &mission.terrain, + index, + pose, + from, + clearance, + 0x620, + )?; + let ground = mission.terrain.height_at(entry.staging).ok()??; + let distance = (from[0] - entry.staging[0]).hypot(from[1] - entry.staging[1]); + let exit = entry.exit(ground); + Some(( + distance, + entry.staging, + BuildingPassage { + building: facility, + legs: entry.legs, + opening: None, + }, + exit, + )) + }) + .min_by(|a, b| a.0.total_cmp(&b.0)) + .map(|(_, staging, passage, exit)| (staging, passage, exit)) +} + +fn usable( + world: &World, + mission: &LoadedMissionState, + facility: ObjectHandle, + owner: Option, +) -> bool { + owner.is_some() + && registration_sequence(world, facility).is_ok_and(|sequence| sequence.is_some()) + && identity_metadata(world, facility).is_ok_and(|meta| meta.owner_id == owner) + && !mission + .control_device_tables + .iter() + .any(|table| table.handle == facility && table.node_provider_depletion_marked) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + create, frame, load_gameplay_mission, starting_cockpit, strategic_orders, strategic_roster, + EngineServices, MissionControlDeviceTableStatus, MissionMode, MissionRequest, + MissionStartupInput, + }; + use fparkan_vfs::DirectoryVfs; + use std::sync::Arc; + + #[test] + #[ignore = "requires licensed corpus"] + fn licensed_fortresses_recharges_the_first_warbot_from_its_start() { + 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/Single.01/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + let cockpit = starting_cockpit(&engine).unwrap(); + let actor = strategic_roster::warbot_rows(&engine, cockpit)[0].handle; + let before = transform_state(&engine.world, actor).unwrap(); + let mission = engine.loaded.as_mut().unwrap(); + let table = mission + .control_device_tables + .iter_mut() + .find(|table| table.handle == actor) + .unwrap(); + let MissionControlDeviceTableStatus::Available(devices) = &mut table.status else { + panic!("stock LTW-3 has no Control devices"); + }; + let (gun, device) = devices + .iter_mut() + .enumerate() + .find(|(_, device)| { + device.descriptor.tag == 2 && device.weapon_rounds.is_some_and(|rounds| rounds > 0) + }) + .unwrap(); + device.weapon_rounds = Some(0); + + assert!(strategic_orders::recharge(&mut engine, cockpit, actor)); + assert_eq!( + strategic_roster::warbot_rows(&engine, cockpit)[0].order_label, + 0x1831 + ); + let mut docked = None; + for now in (0..=90_000).step_by(100) { + frame(&mut engine, now).unwrap(); + let mission = engine.loaded.as_ref().unwrap(); + let patrol = mission.unit_patrol.as_ref().unwrap(); + assert!(patrol.satellite_route(actor).is_empty()); + if patrol.is_servicing(actor) { + docked = Some(transform_state(&engine.world, actor).unwrap()); + } + if patrol.active_order_code(actor) == 0 { + let docked = docked.expect("recharge finished before reaching the service point"); + let after = transform_state(&engine.world, actor).unwrap(); + assert_ne!(docked.position, before.position); + assert_ne!(after.position, docked.position); + let table = mission + .control_device_tables + .iter() + .find(|table| table.handle == actor) + .unwrap(); + let MissionControlDeviceTableStatus::Available(devices) = &table.status else { + panic!("stock LTW-3 lost its Control devices"); + }; + assert!(devices[gun].weapon_rounds.unwrap() > 0); + return; + } + } + let last = transform_state(&engine.world, actor).unwrap(); + panic!( + "stock LTW-3 did not leave its recharge facility: start={:?} docked={} end={:?}", + before.position.map(f32::from_bits), + docked.is_some(), + last.position.map(f32::from_bits) + ); + } +} -- cgit v1.2.3