From bef4fbab7701a51945ed93357babe12b416bb9a8 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 25 Nov 2026 18:06:07 +0400 Subject: feat(ai): execute laboratory research from clan scripts Clan laboratories accept the selected DAT project, request power and ore, accumulate native research progress, and publish learned technologies to construction and production. Research requests wait for the live laboratory; newly built objects are no longer mistaken for destroyed targets. Behavior.dll task 0x2f730 was called with paid and free work under x87 0x007f. The stock Single.02 regression checks both completed technologies and keeps the request pending while the laboratory is busy. Workspace fmt/check/tests, the 29-mission 900-second corpus, and the Vulkan window check pass. Dependent availability and free child propagation remain explicit script_research_unlock_stub counters; candidate properties 65 and policy 69 remain open. This does not close G7 or establish live AI chronology parity. --- crates/fparkan-assets/src/research.rs | 60 ++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 19 deletions(-) (limited to 'crates/fparkan-assets/src/research.rs') diff --git a/crates/fparkan-assets/src/research.rs b/crates/fparkan-assets/src/research.rs index b2619284..cba41c95 100644 --- a/crates/fparkan-assets/src/research.rs +++ b/crates/fparkan-assets/src/research.rs @@ -492,6 +492,24 @@ impl ResearchTrfDocument { self.flags.get(index).copied() } + /// Sets the researched bit without propagating availability to related rows. + /// + /// # Errors + /// Rejects a row outside the decoded table. + pub fn mark_researched_flag(&mut self, index: usize) -> Result<(), ResearchError> { + let count = self.flags.len(); + let flag = self + .flags + .get_mut(index) + .ok_or(ResearchError::InvalidResearchIndex { + type_id: TRF1, + index: u32::try_from(index).unwrap_or(u32::MAX), + row_count: count, + })?; + *flag |= 2; + Ok(()) + } + /// Returns the raw name bytes selected by a row's low-16-bit TRFB link. /// /// # Errors @@ -747,6 +765,28 @@ pub fn calc_full_research_cost( candidate: &UnitDat, research: &ResearchTrfDocument, ) -> Result { + let closure = research_project_rows(candidate, research)?; + let mut ore = 0.0_f32; + let mut power = 0.0_f32; + for index in closure { + let (included, _, _) = research.gates(index)?; + if included == 0 { + let row = &research.records[index]; + ore = ore + f32::from_bits(row[1]); + power = power + f32::from_bits(row[0]); + } + } + Ok(ResearchCost { ore, power }) +} + +/// Collects unresearched project rows and their ordered prerequisite closure. +/// +/// # Errors +/// Rejects the same malformed candidates and table links as the cost calculation. +pub fn research_project_rows( + candidate: &UnitDat, + research: &ResearchTrfDocument, +) -> Result, ResearchError> { if research.records.is_empty() { return Err(ResearchError::EmptyResearchTable); } @@ -766,25 +806,7 @@ pub fn calc_full_research_cost( } } - let mut ore = 0.0_f32; - let mut power = 0.0_f32; - for index in closure { - let (included, _, _) = research.gates(index)?; - if included == 0 { - let row = research - .records - .get(index) - .ok_or(ResearchError::InvalidResearchIndex { - type_id: TRF0, - index: u32::try_from(index).unwrap_or(u32::MAX), - row_count: research.records.len(), - })?; - ore = ore + f32::from_bits(row[1]); - power = power + f32::from_bits(row[0]); - } - } - - Ok(ResearchCost { ore, power }) + Ok(closure) } fn collect_direct_indices( -- cgit v1.2.3