diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-25 21:50:05 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-25 21:50:05 +0300 |
| commit | f50fb0dcae975cd964b7606cc7248d9e771abb2c (patch) | |
| tree | 6a3656b2f8ed66d4904e655a8d23bd64b6ea59c5 /crates/fparkan-runtime/src/lib.rs | |
| parent | 574a1c02ba88b5205437cca3c0b0c29fe1afa945 (diff) | |
| download | fparkan-f50fb0dcae975cd964b7606cc7248d9e771abb2c.tar.xz fparkan-f50fb0dcae975cd964b7606cc7248d9e771abb2c.zip | |
fix(production): use Control energy budgets for factory work
Factories now run the recovered Control resource-budget pass on its own
randomized clock before Behavior task updates. Paid production reads its
current work-device E00 value, including the local power reserve and
allocation, instead of gating full speed on any clan generation.
The clock redraws jitter on every accepted frame and uses a separate Control
RNG. Initial phase, seed and ordering with other owners remain explicit
approximations. Budget failures preserve the table and are counted per owner.
Original DLL calls verify the budget callbacks, strict deadline, per-call RNG,
forced update and inactive baseline. A live class-3 factory executes the same
budget with the default 250 ms setting. Licensed regressions cover an empty
factory power reserve, subsequent generator capture, four completed paid
orders, the Behavior task deadline and scripted warbot/transport/builder births.
Workspace fmt/check/tests and release build pass. All 29 stock missions run
900 seconds without script or new budget stops. Stock mission 28 accepts and
completes a free and then a paid player order in the Vulkan-validation window.
Diffstat (limited to 'crates/fparkan-runtime/src/lib.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index ac635ad2..762c18f3 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -51,6 +51,7 @@ mod clan_area_strength; mod clan_build_limits; mod clan_building_queries; mod clan_clock; +mod control_resources; pub use clan_clock::note_mission_pause_elapsed; mod clan_combat_groups; mod clan_combat_strength; @@ -1368,6 +1369,7 @@ struct LoadedMissionState { research_trf_tables: Vec<MissionResearchTrfTable>, free_research: research::FreeResearch, laboratories: laboratory::Laboratories, + factory_resources: control_resources::FactoryResources, ai_startup_states: Vec<MissionAiStartupState>, script_bundles: Vec<MissionScriptBundle>, script_varset: Option<MissionScriptVarSet>, @@ -2697,6 +2699,7 @@ fn load_mission_with_options( research_trf_tables, free_research, laboratories: Default::default(), + factory_resources: Default::default(), ai_startup_states: loaded_scripts.ai_startup_states, script_bundles: loaded_scripts.bundles, script_varset: loaded_scripts.varset, @@ -2782,6 +2785,9 @@ pub fn step_headless( if let Some(resources) = resources { resources.apply(engine); } + if let Some(mission) = &mut engine.loaded { + control_resources::tick(mission, &engine.world, queue_time_ms); + } let (autodemo_combat_events, autodemo_combat_unavailable) = if let Some(mut combat) = engine.autodemo_combat.take() { let result = combat.tick(engine, queue_time_ms); @@ -2941,6 +2947,8 @@ pub struct SimulationReport { pub script_factory_orders: Vec<(u16, u32, u64)>, /// Active factory task updates; idle owner phases and global RNG order remain approximate. pub factory_clock_ticks: Vec<(u16, u32, u64)>, + pub factory_control_ticks: Vec<(u32, u64)>, + pub factory_control_stops: Vec<(u32, u64, String)>, /// 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)>, @@ -3015,6 +3023,8 @@ pub fn simulate_mission_report( script_factory_rejections: Vec::new(), script_factory_orders: Vec::new(), factory_clock_ticks: Vec::new(), + factory_control_ticks: Vec::new(), + factory_control_stops: Vec::new(), script_strength_queries: Vec::new(), script_capture_queries: Vec::new(), script_attack_queries: Vec::new(), @@ -3122,6 +3132,15 @@ pub fn simulate_mission_report( .clan_research_catalogs .extend(loaded.clan_ai_events.research_catalogs()); report.laboratory = loaded.laboratories.report(); + report + .factory_control_ticks + .extend(loaded.factory_resources.ticks()); + report.factory_control_stops.extend( + loaded + .factory_resources + .stops() + .map(|(unit, count, reason)| (unit, count, reason.to_owned())), + ); if let Some(production) = &engine.production { report.factory_clock_ticks.extend(production.clock_ticks()); } @@ -3724,8 +3743,8 @@ pub fn query_loaded_mission_control_resource( /// readers use the device key to read the current provider value and multiply /// it by coefficient 0. Only current tag 26 also multiplies by `M`; current /// tag 5 ignores `M` and descriptor word 8 for this selector. Explicit Control -/// update calls can change current provider or multiplier values; the mission -/// clock does not advance them automatically. Selector `6` first checks the +/// update calls can change current provider or multiplier values; factory +/// resource budgets also advance during mission steps. Selector `6` first checks the /// current descriptor tag: a non-2 tag returns `Ok(None)`. For the represented /// factory-2 layout it reads `+0x174`, subject to the normal-or-zero float /// range checks; an unsupported field or layout returns a typed error. This is @@ -3793,8 +3812,8 @@ pub fn set_loaded_mission_control_device_selector( /// `Transfer_Ore_OffBoard` value. Unsupported table/query paths return an error. /// Profile values come from full mission loading, while `0xe00` reads the /// current CPU-projected provider and device state. Explicit Control updates -/// can therefore change `0x1002`; the mission clock does not update it -/// automatically. +/// can therefore change `0x1002`; factory Control resource budgets also run +/// during mission steps. /// /// # Errors /// Returns an error for an invalid handle, unavailable mission/profile/table, @@ -4095,7 +4114,7 @@ pub fn distribute_loaded_mission_control_provider_amount( /// The pass supports the original factory callbacks for tags 9, 15, 19, and 26, /// plus the generic default callback pair. Current descriptor category tags are /// supported for the native map prefix `0..=34`. This is an explicit CPU update; -/// the mission clock does not call it yet. Rate outputs at `+0x5dc/+0x5e0` are +/// factories also run this pass on their resource clock. Rate outputs at `+0x5dc/+0x5e0` are /// stored on the table after a successful pass. /// /// # Errors |
