From 3b10d83864d84715b875d596fcd5b4147fcd8ed3 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 1 Dec 2026 19:58:11 +0400 Subject: fix(control): repair damaged nodes on facility pads --- crates/fparkan-runtime/src/control_resources.rs | 2 +- crates/fparkan-runtime/src/repair_zone.rs | 65 ++++++++++++++++--------- 2 files changed, 43 insertions(+), 24 deletions(-) (limited to 'crates') diff --git a/crates/fparkan-runtime/src/control_resources.rs b/crates/fparkan-runtime/src/control_resources.rs index 095ac3ab..e682ee5b 100644 --- a/crates/fparkan-runtime/src/control_resources.rs +++ b/crates/fparkan-runtime/src/control_resources.rs @@ -133,7 +133,7 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) { continue; }; if mobile_owner { - repair_zone::repair_hull(table, table.handle, world, pose, &facilities, seconds); + repair_zone::repair_nodes(table, world, pose, &facilities, seconds); } 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 07124e88..e137a85e 100644 --- a/crates/fparkan-runtime/src/repair_zone.rs +++ b/crates/fparkan-runtime/src/repair_zone.rs @@ -1,9 +1,9 @@ //! Health service inside the repair volumes authored on facilities. use crate::{ - initial_component_node_times, node_amount::apply_control_node_delta, MissionAssets, - MissionControlDeviceTableState, MissionControlNodeProviderTableStatus, MissionObjectDraft, - ObjectHandle, TransformState, World, + initial_component_node_times, node_amount::distribute_control_node_amount, + ControlNodeDistributionMode, MissionAssets, MissionControlDeviceTableState, MissionObjectDraft, + TransformState, World, }; use fparkan_assets::PreparedControlPoint; use fparkan_msh::{node38_fallback_hierarchy, node38_sampled_hierarchy_at_times}; @@ -13,8 +13,8 @@ use fparkan_world::{ OriginalObjectId, OwnerId, }; -// shortcut: interpolate hull recovery until the facility's supply and repair rate are wired. -const HULL_FRACTION_PER_SECOND: f32 = 0.1; +// Behavior.dll+0x193b2 adds this fraction of total provider capacity per second. +const HEALTH_FRACTION_PER_SECOND: f32 = 0.1; #[derive(Clone, Copy)] struct RepairVolume { @@ -177,24 +177,25 @@ fn facility_volumes(assets: &MissionAssets, index: usize) -> Vec { .collect() } -pub(super) fn repair_hull( +pub(super) fn repair_nodes( table: &mut MissionControlDeviceTableState, - handle: ObjectHandle, world: &World, pose: TransformState, facilities: &[ActiveFacility<'_>], seconds: f32, ) { - let MissionControlNodeProviderTableStatus::Available(rows) = &table.node_provider_status else { + let Some((amount, maximum)) = table + .node_provider_amount_bits + .zip(table.node_provider_maximum_amount_bits) + .map(|(amount, maximum)| (f32::from_bits(amount), f32::from_bits(maximum))) + else { return; }; - let Some(root) = rows.first() else { return }; - let volume = f32::from_bits(root.current_amount_bits); - let max = root.source_row.max_volume; - if !(volume > 0.0 && volume < max && seconds > 0.0) { + if table.node_provider_depletion_marked || !(0.0 < amount && amount < maximum && seconds > 0.0) + { return; } - let Some(owner) = identity_metadata(world, handle) + let Some(owner) = identity_metadata(world, table.handle) .ok() .and_then(|meta| meta.owner_id) else { @@ -212,7 +213,13 @@ pub(super) fn repair_hull( site.volumes.iter().any(|volume| volume.contains(local)) }); if in_service { - let _ = apply_control_node_delta(table, 0, max * HULL_FRACTION_PER_SECOND * seconds); + let target = (amount / maximum + seconds * HEALTH_FRACTION_PER_SECOND).min(1.0); + let _ = distribute_control_node_amount( + table, + target * maximum - amount, + ControlNodeDistributionMode::Sequential, + true, + ); } } @@ -272,7 +279,7 @@ mod tests { .unwrap(); let hero = starting_cockpit(&engine).unwrap().handle; let initial_pose = transform_state(&engine.world, hero).unwrap(); - let read_hull = |engine: &crate::Engine| { + let read_node = |engine: &crate::Engine, key| { let table = engine .loaded .as_ref() @@ -281,7 +288,7 @@ mod tests { .iter() .find(|table| table.handle == hero) .unwrap(); - let row = crate::control_node_provider_row(table, 0).unwrap(); + let row = crate::control_node_provider_row(table, key).unwrap(); ( f32::from_bits(row.current_amount_bits), row.source_row.max_volume, @@ -310,22 +317,34 @@ mod tests { .try_transform_scaled_point(floor, pose.scale.map(f32::from_bits)) .unwrap() .map(f32::to_bits); - let (health, max) = read_hull(&engine); - apply_loaded_mission_control_node_delta(&mut engine, hero, 0, max * 0.5 - health) - .unwrap(); - let damaged = read_hull(&engine).0; + // Exercise the hull first, then a damaged component with a full hull. + let damage_key = u32::from(case != 0); + if damage_key != 0 { + let (amount, maximum) = read_node(&engine, 0); + apply_loaded_mission_control_node_delta(&mut engine, hero, 0, maximum - amount) + .unwrap(); + } + let (health, max) = read_node(&engine, damage_key); + apply_loaded_mission_control_node_delta( + &mut engine, + hero, + damage_key, + max * 0.5 - health, + ) + .unwrap(); + let damaged = read_node(&engine, damage_key).0; set_transform(&mut engine.world, hero, actor).unwrap(); set_owner(&mut engine.world, facility, Some(OwnerId(1))).unwrap(); frame(&mut engine, start).unwrap(); frame(&mut engine, start + 1000).unwrap(); - assert_eq!(read_hull(&engine).0, damaged); + assert_eq!(read_node(&engine, damage_key).0, damaged); set_owner(&mut engine.world, facility, Some(OwnerId(0))).unwrap(); frame(&mut engine, start + 2000).unwrap(); - let repaired = read_hull(&engine).0; + let repaired = read_node(&engine, damage_key).0; assert!(repaired > damaged && repaired <= max); set_transform(&mut engine.world, hero, initial_pose).unwrap(); frame(&mut engine, start + 3000).unwrap(); - assert_eq!(read_hull(&engine).0, repaired); + assert_eq!(read_node(&engine, damage_key).0, repaired); } } } -- cgit v1.2.3