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/lib.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'crates/fparkan-runtime/src/lib.rs') diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index a1866dd3..103c669e 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -53,9 +53,11 @@ mod clan_building_queries; mod clan_clock; mod control_profile; mod control_resources; +mod mobile_budget; pub use clan_clock::note_mission_pause_elapsed; use control_profile::project_initial as project_control_owner_profile_fca0; pub use control_profile::{ControlProfileReport, ControlProfileScalars}; +pub use mobile_budget::MobileBudgetReport; mod clan_combat_groups; mod clan_combat_strength; mod clan_factory_schemes; @@ -555,6 +557,8 @@ pub struct EffectiveControlDevice { pub tag26_extra_rate_bits: Option, /// Factory-2 value read by selector 6 at native `+0x174`. pub device174_bits: Option, + /// Factory-2 charge at native +0x120, initialized by the weapon reader. + pub weapon_charge_bits: Option, /// Six class-9 budget values at native `+0x98..+0xac`. pub class9_values_bits: Option<[u32; 6]>, /// Six accumulated class-9 changes at native `+0xb0..+0xc4`. @@ -2988,6 +2992,7 @@ pub struct SimulationReport { pub patrol_points: PatrolPointReport, pub patrol_speeds: PatrolSpeedReport, pub control_profiles: ControlProfileReport, + pub mobile_budget: MobileBudgetReport, /// Approximate clan strength queries, grouped by caller and target clan. pub script_strength_queries: Vec<(usize, u16, u64)>, pub script_capture_queries: Vec<(usize, u64)>, @@ -3068,6 +3073,7 @@ pub fn simulate_mission_report( patrol_points: PatrolPointReport::default(), patrol_speeds: PatrolSpeedReport::default(), control_profiles: ControlProfileReport::default(), + mobile_budget: MobileBudgetReport::default(), script_strength_queries: Vec::new(), script_capture_queries: Vec::new(), script_attack_queries: Vec::new(), @@ -3176,6 +3182,7 @@ pub fn simulate_mission_report( .extend(loaded.clan_ai_events.research_catalogs()); report.laboratory = loaded.laboratories.report(); report.control_profiles = loaded.control_resources.profiles.clone(); + report.mobile_budget = loaded.control_resources.mobile.clone(); if let Some(patrol) = &loaded.unit_patrol { report.patrol_points = patrol.point_report.clone(); report.patrol_speeds = patrol.speed_report.clone(); @@ -4816,7 +4823,7 @@ fn control_resource_budget_pass_inner( for index in 0..device_count { let device = control_budget_device(table, index)?; control_budget_category(device.descriptor.tag)?; - if !matches!(device.factory_tag, 9 | 15 | 19 | 26) + if !matches!(device.factory_tag, 1 | 2 | 5 | 9 | 10 | 15 | 19 | 26 | 30) && !control_factory_uses_generic_budget_callbacks(device.factory_tag) { return Err(ControlResourceAccessError::UnsupportedFactoryTag { @@ -5093,6 +5100,9 @@ fn control_device_resource_rate( device: &EffectiveControlDevice, delta_time_seconds: f32, ) -> Result { + if matches!(device.factory_tag, 2 | 30) { + return mobile_budget::weapon_rate(table, device, delta_time_seconds); + } let Some(provider_value) = control_device_budget_active_provider_value(table, device)? else { return Ok(0.0); }; @@ -5100,6 +5110,8 @@ fn control_device_resource_rate( control_device_budget_descriptor_float(device, 8, "descriptor resource rate +0x20")?; match device.factory_tag { + 5 => Ok(mobile_budget::unmodeled_motion_rate()), + 10 => mobile_budget::passive_device_rate(device, delta_time_seconds), 9 => { let coefficient_0 = control_device_budget_coefficient(device, 0)?; let coefficient_1 = control_device_budget_coefficient(device, 1)?; @@ -5362,6 +5374,12 @@ fn control_device_resource_update( delta_time_seconds: f32, allocation: f32, ) -> Result<(), ControlResourceAccessError> { + if matches!( + control_budget_device(table, device_index)?.factory_tag, + 2 | 30 + ) { + return mobile_budget::weapon_update(table, device_index, delta_time_seconds, allocation); + } let device = control_budget_device(table, device_index)?; let Some(provider_value) = control_device_budget_active_provider_value(table, &device)? else { return Ok(()); @@ -5573,7 +5591,7 @@ fn control_device_resource_update( )?; } } - 26 => set_control_device_multiplier(table, device_index, allocation)?, + 5 | 10 | 26 => set_control_device_multiplier(table, device_index, allocation)?, factory_tag if control_factory_uses_generic_budget_callbacks(factory_tag) => { set_control_device_multiplier(table, device_index, allocation)?; } @@ -7232,6 +7250,7 @@ fn append_effective_control_device( class9_selector0_scale_bits: (descriptor.tag == 9).then_some(0x3f80_0000), tag26_extra_rate_bits: (descriptor.tag == 26).then_some(0), device174_bits: (descriptor.tag == 2).then_some(0), + weapon_charge_bits: matches!(descriptor.tag, 2 | 30).then_some(coefficient_words[1]), class9_values_bits: (descriptor.tag == 9).then_some([0x3f80_0000; 6]), class9_deltas_bits: (descriptor.tag == 9).then_some([0; 6]), native_word_50_bits, @@ -7310,6 +7329,9 @@ fn apply_effective_control_override( let mut coefficient_words = [0; 16]; coefficient_words.copy_from_slice(&descriptor.fixed_words[11..27]); device.coefficient_bits = Some(coefficient_words); + if matches!(device.factory_tag, 2 | 30) { + device.weapon_charge_bits = Some(coefficient_words[1]); + } if descriptor.fixed_words[6] != u32::MAX { device.native_word_50_bits = Some(descriptor.fixed_words[6]); } @@ -7319,7 +7341,7 @@ fn apply_effective_control_override( } fn control_factory_uses_generic_budget_callbacks(factory_tag: u32) -> bool { - !matches!(factory_tag, 1 | 2 | 5 | 9 | 10 | 15 | 17 | 19 | 26 | 30) + !matches!(factory_tag, 2 | 5 | 9 | 10 | 15 | 17 | 19 | 26 | 30) } fn control_factory_override_is_supported(factory_tag: u32) -> bool { @@ -7332,7 +7354,7 @@ fn native_control_factory_defaults(factory_tag: u32) -> (Option, Option (Some(0x3f80_0000), Some(0x5)), 10 => (Some(0x3f80_0000), Some(0x2000)), 17 | 19 => (Some(0x3f80_0000), Some(0x20)), - 2 | 27 => (Some(0x3f80_0000), Some(0)), + 2 | 27 | 30 => (Some(0x3f80_0000), Some(0)), 9 => (Some(0x3f80_0000), Some(0x20)), 15 => (Some(0x3f80_0000), Some(0)), _ => (Some(0x3f80_0000), Some(0x5)), @@ -9979,6 +10001,7 @@ mod tests { class9_selector0_scale_bits: class9_scale_bits, tag26_extra_rate_bits: (factory_tag == 26).then_some(0), device174_bits: (factory_tag == 2).then_some(0), + weapon_charge_bits: matches!(factory_tag, 2 | 30).then_some(coefficients[1]), class9_values_bits: (factory_tag == 9).then_some([0x3f80_0000; 6]), class9_deltas_bits: (factory_tag == 9).then_some([0; 6]), native_word_50_bits, @@ -10452,7 +10475,7 @@ mod tests { #[test] fn control_budget_generic_default_callbacks_match_native_rate_and_update() { - for factory_tag in [3, 4, 6, 8, 12, 13, 21, 25, 27, 34] { + for factory_tag in [1, 3, 4, 6, 8, 12, 13, 21, 25, 27, 34] { let mut device = synthetic_effective_control_device( factory_tag, factory_tag, -- cgit v1.2.3