aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/laboratory.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-25 22:08:00 +0300
committerValentin Popov <valentin@popov.link>2026-11-25 22:08:00 +0300
commit9e5a8867d1a12a66772e6e97c3a0213f9636d56c (patch)
tree1757612044774f3a304d490ba52e8f9be93e3458 /crates/fparkan-runtime/src/laboratory.rs
parentf50fb0dcae975cd964b7606cc7248d9e771abb2c (diff)
downloadfparkan-9e5a8867d1a12a66772e6e97c3a0213f9636d56c.tar.xz
fparkan-9e5a8867d1a12a66772e6e97c3a0213f9636d56c.zip
fix(research): advance laboratory Control energy budgets
Paid laboratory work read a work-device coefficient that never received a Control budget update. Run the recovered resource clock and budget for laboratories as well as factories, so energy work follows the actual device allocation. Generalize the state and report counters to control_resource_*. A licensed outage regression drains the lab reserve and removes external power: energy work stays fixed while task time advances, then resumes when the original generation is restored. Stock research for both AI clans, player free research and paid factory production still pass. The original laboratory task reaches its class-3 Control owner, whose native budget runs on the same quarter-second resource path as the factory. Verified this in the running stock mission through Behavior 0x2f76e and Control 0x2d340. Workspace fmt/check/tests and release build pass. All 29 stock missions run 900 seconds without script or resource-budget stops. A stock mission-28 window completes paid technologies and starts subsequent projects. Control initial phase, RNG seed, other owners and global ordering remain approximate.
Diffstat (limited to 'crates/fparkan-runtime/src/laboratory.rs')
-rw-r--r--crates/fparkan-runtime/src/laboratory.rs126
1 files changed, 125 insertions, 1 deletions
diff --git a/crates/fparkan-runtime/src/laboratory.rs b/crates/fparkan-runtime/src/laboratory.rs
index 08953eb9..610a7c0c 100644
--- a/crates/fparkan-runtime/src/laboratory.rs
+++ b/crates/fparkan-runtime/src/laboratory.rs
@@ -4,7 +4,7 @@ use fparkan_vfs::Vfs;
use fparkan_world::{identity_metadata, ObjectHandle, OwnerId, World};
use std::collections::BTreeMap;
-const LAB_CLASS: u32 = 0x8000_0400;
+pub(super) const LAB_CLASS: u32 = 0x8000_0400;
/// Executed laboratory orders and technology state changes.
#[derive(Default, Debug, Clone, PartialEq, Eq)]
@@ -443,6 +443,130 @@ mod tests {
#[test]
#[ignore = "requires licensed corpus"]
+ fn licensed_paid_research_waits_for_control_power_and_resumes_after_supply() {
+ use crate::{
+ create, frame, load_gameplay_mission, EngineServices, MissionMode, MissionRequest,
+ MissionStartupInput,
+ };
+ use fparkan_vfs::DirectoryVfs;
+ use std::sync::Arc;
+ let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").unwrap();
+ let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap();
+ load_gameplay_mission(
+ &mut engine,
+ MissionRequest {
+ key: "MISSIONS/Single.01/data.tma".into(),
+ mode: MissionMode::SingleMission,
+ },
+ MissionStartupInput {
+ queue_time_ms: 0,
+ research_creation_gate: false,
+ },
+ None,
+ )
+ .unwrap();
+ let loaded = engine.loaded.as_mut().unwrap();
+ let lab = loaded
+ .control_device_tables
+ .iter()
+ .find(|table| {
+ table.original_id.is_some_and(|id| {
+ loaded.object_drafts[id.0 as usize].unit_dat_header_flags == Some(LAB_CLASS)
+ }) && identity_metadata(&engine.world, table.handle)
+ .unwrap()
+ .owner_id
+ == Some(OwnerId(1))
+ })
+ .unwrap()
+ .handle;
+ let slot = identity_metadata(&engine.world, lab)
+ .unwrap()
+ .original_id
+ .unwrap()
+ .0 as usize;
+ // Debug outage: consume free jobs, empty the local reserve and stop external generation.
+ while loaded.free_research.take_free(slot) {}
+ let supply = loaded
+ .behavior_profiles
+ .iter()
+ .map(|profile| profile.transfer_power_out_bits)
+ .collect::<Vec<_>>();
+ for profile in &mut loaded.behavior_profiles {
+ profile.transfer_power_out_bits = 0;
+ }
+ crate::set_control_device_table_multiplier(
+ loaded
+ .control_device_tables
+ .iter_mut()
+ .find(|table| table.handle == lab)
+ .unwrap(),
+ 0.0,
+ )
+ .unwrap();
+ for now in (0..=1_000).step_by(50) {
+ frame(&mut engine, now).unwrap();
+ }
+ let loaded = engine.loaded.as_ref().unwrap();
+ assert!(
+ loaded
+ .control_resources
+ .ticks()
+ .any(|(unit, count)| unit == lab.slot && count > 0),
+ "laboratory Control clock must run"
+ );
+ assert!(!loaded
+ .control_resources
+ .stops()
+ .any(|(unit, _, _)| unit == lab.slot));
+ let task = loaded
+ .laboratories
+ .tasks
+ .iter()
+ .find(|task| task.lab == lab)
+ .unwrap();
+ let (row, work) = task.current.as_ref().expect("active paid research");
+ assert!(work.power_cost > 0.0);
+ let (row, before, elapsed) = (*row, work.power, work.time);
+ for now in (1_050..=2_000).step_by(50) {
+ frame(&mut engine, now).unwrap();
+ }
+ let loaded = engine.loaded.as_ref().unwrap();
+ let task = loaded
+ .laboratories
+ .tasks
+ .iter()
+ .find(|task| task.lab == lab)
+ .unwrap();
+ let (current, work) = task.current.as_ref().unwrap();
+ assert_eq!(*current, row);
+ assert_eq!(
+ work.power, before,
+ "no power work while the reserve and supply are empty"
+ );
+ assert!(work.time > elapsed);
+ let loaded = engine.loaded.as_mut().unwrap();
+ for (profile, bits) in loaded.behavior_profiles.iter_mut().zip(supply) {
+ profile.transfer_power_out_bits = bits;
+ }
+ for now in (2_050..=10_000).step_by(50) {
+ frame(&mut engine, now).unwrap();
+ let state = &engine.loaded.as_ref().unwrap().laboratories;
+ if state.completed.contains_key(&(1, lab.slot, row))
+ || state
+ .tasks
+ .iter()
+ .find(|task| task.lab == lab)
+ .and_then(|task| task.current.as_ref())
+ .is_some_and(|(current, work)| *current == row && work.power > before)
+ {
+ return;
+ }
+ }
+ panic!("research power work must resume after restoring the original generation");
+ }
+
+ #[test]
+ #[ignore = "requires licensed corpus"]
fn licensed_stock_ai_laboratories_continue_research_and_keep_the_request_pending() {
use crate::{
create, frame, load_gameplay_mission, EngineServices, MissionMode, MissionRequest,