From 8ac763f7bfda827016d17c66372d02b85d5a9bb5 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 01:38:43 +0400 Subject: feat(combat): feed weapon charge from Control energy budgets Keep factory-2/30 charge in the owner's Control table. AI and player banks read it before firing, debit completed shots and wait for regeneration. Preserve one charge across bank changes and accumulate energy waits by object, including an idle bank publishing after an active bank. Mobile owners now run the resource budget. Restore the shared factory-1 callbacks, factory-2/30 charging and factory-10 passive upkeep. Factory 30 uses the weapon constructor's native disabled default. Motion demand is still an explicit zero-rate stub; unsupported budgets disable charge limiting for that owner and record the reason. Execute unmodified GOG Control.dll callbacks at RVA 0x29a40/0x29a90, 0x264b0/0x26510 and 0x21860/0x21890; check the common constructor at 0x294c0. Rust golden vectors cover disabled refill, zero capacity, negative charge and x87 rounding at control word 0x007f. SHA-256: bcb86318089028548a178b03a21accdce15df0cc85ddd91674cf3c2f55012c6e. Validated fmt, workspace check/tests, release, licensed shared-bank charge exhaustion/recovery, stock combat and damaged-profile regressions. All 29 stock missions reached 900 seconds; the only mobile-budget stub was the known motion input. Observed stock window combat and replenishment. Full live native mission comparison and motion energy remain open. --- crates/fparkan-runtime/src/control_resources.rs | 46 ++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'crates/fparkan-runtime/src/control_resources.rs') diff --git a/crates/fparkan-runtime/src/control_resources.rs b/crates/fparkan-runtime/src/control_resources.rs index 86a402e1..f8eedee0 100644 --- a/crates/fparkan-runtime/src/control_resources.rs +++ b/crates/fparkan-runtime/src/control_resources.rs @@ -1,16 +1,19 @@ use crate::{ control_profile, control_resource_budget_pass, ControlProfileReport, LoadedMissionState, + MissionControlDeviceTableStatus, MobileBudgetReport, }; use fparkan_world::{transform_state, ObjectHandle, World}; use std::collections::BTreeMap; -/// Factory and laboratory Control budgets; other owners and global RNG ordering remain open. +/// Supported Control budgets; motion callbacks and global RNG ordering remain open. pub(super) struct Resources { clocks: Vec<(ObjectHandle, ResourceClock)>, rng: u32, ticks: BTreeMap, stops: BTreeMap, pub(super) profiles: ControlProfileReport, + pub(super) mobile: MobileBudgetReport, + blocked_budgets: Vec, } impl Default for Resources { @@ -22,11 +25,17 @@ impl Default for Resources { ticks: BTreeMap::new(), stops: BTreeMap::new(), profiles: ControlProfileReport::default(), + mobile: MobileBudgetReport::default(), + blocked_budgets: Vec::new(), } } } impl Resources { + pub(super) fn energy_available(&self, handle: ObjectHandle) -> bool { + !self.blocked_budgets.contains(&handle) + } + pub(super) fn ticks(&self) -> impl Iterator + '_ { self.ticks.iter().map(|(&unit, &count)| (unit, count)) } @@ -43,6 +52,9 @@ pub(super) fn tick(mission: &mut LoadedMissionState, world: &World, now_ms: u32) state .clocks .retain(|(handle, _)| transform_state(world, *handle).is_ok()); + state + .blocked_budgets + .retain(|handle| transform_state(world, *handle).is_ok()); for table in &mut mission.control_device_tables { let flags = table .original_id @@ -121,18 +133,42 @@ pub(super) fn tick(mission: &mut LoadedMissionState, world: &World, now_ms: u32) } } } - if !budget_owner { - continue; - } match control_resource_budget_pass(table, seconds) { Ok(()) => { + state + .blocked_budgets + .retain(|handle| *handle != table.handle); + if mobile_owner { + *state.mobile.ticks.entry(object).or_default() += 1; + if let MissionControlDeviceTableStatus::Available(devices) = &table.status { + for device in devices { + if device.factory_tag == 5 && device.native_word_50_bits != Some(0) { + state + .mobile + .stub(object, format!("motion_factory_{}", device.factory_tag)); + } + if matches!(device.factory_tag, 2 | 30) + && f32::from_bits(device.descriptor.fixed_words[8]) != 0.0 + { + state.mobile.stub(object, "weapon_command_mode".into()); + } + } + } + } let count = state.ticks.entry(table.handle.slot).or_default(); *count += 1; if *count == 1 { - eprintln!("sim_coverage control_resource_clock_approx=1 unit={} (factory and laboratory owners; Control RNG seed and global order remain open)", table.handle.slot); + eprintln!("sim_coverage control_resource_clock_approx=1 unit={} (supported owners; Control RNG seed, activation and global order remain open)", table.handle.slot); } } Err(reason) => { + if !state.blocked_budgets.contains(&table.handle) { + state.blocked_budgets.push(table.handle); + } + if mobile_owner { + state.mobile.stub(object, format!("budget_{reason:?}")); + continue; + } let stop = state .stops .entry(table.handle.slot) -- cgit v1.2.3