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 +++++++++++++++++++------- 1 file changed, 60 insertions(+), 23 deletions(-) (limited to 'crates/fparkan-runtime/src/building_passage.rs') 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, -- cgit v1.2.3