aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-25 17:31:38 +0300
committerValentin Popov <valentin@popov.link>2026-11-25 17:31:38 +0300
commitcd67d44101faf180e2f2891e897d0215689fd706 (patch)
tree52a31d67256ff1c3ed9fa6c0e663f9972861df85 /crates/fparkan-runtime/src
parenta09bc5526cb8f5a38099c5c0bc2b6bb4b47ddfda (diff)
downloadfparkan-cd67d44101faf180e2f2891e897d0215689fd706.tar.xz
fparkan-cd67d44101faf180e2f2891e897d0215689fd706.zip
fix(ai): refresh research projects before laboratory orders
AI laboratories now move beyond their first DAT project. Handler 41 refreshes the clan catalog from its current technology table before dispatching the selected project, including when the eventual laboratory order is rejected. The original ai.dll wrapper at 0xd4a3 calls the chooser at 0xd524 before 0x11100. A native wrapper fixture observes the catalog scan-state transition for a completed candidate. The stock Single.02 regression keeps each active request queued and checks that both clans learn later projects and publish the free descendants to construction and production. Workspace fmt/check/tests, the licensed stock regression, all 29 stock missions at 900 seconds and the Vulkan window check pass. Factory selection parameter 69, candidate metadata query 65 and matching window/report AI chronology remain open. This does not close G7.
Diffstat (limited to 'crates/fparkan-runtime/src')
-rw-r--r--crates/fparkan-runtime/src/clan_ai_events.rs2
-rw-r--r--crates/fparkan-runtime/src/laboratory.rs33
2 files changed, 26 insertions, 9 deletions
diff --git a/crates/fparkan-runtime/src/clan_ai_events.rs b/crates/fparkan-runtime/src/clan_ai_events.rs
index 3b3bb708..c80b7d03 100644
--- a/crates/fparkan-runtime/src/clan_ai_events.rs
+++ b/crates/fparkan-runtime/src/clan_ai_events.rs
@@ -1055,7 +1055,7 @@ impl LoadedMissionState {
)
.find(|handle| Some(*handle) == assignment);
let Some(lab) = lab else { return Ok(Some(VarSetDefault::Dword(u32::MAX))); };
- let result = crate::laboratory::order(&mut self.laboratories, &self.clan_ai_events.research_catalogs,
+ let result = crate::laboratory::order(&mut self.laboratories, &mut self.clan_ai_events.research_catalogs,
&self.object_drafts, &self.free_research, world, vfs, clan, lab, now_ms);
if let Err(reason) = &result { self.laboratories.rejected(clan, lab, reason); }
Ok(Some(VarSetDefault::Dword(u32::from(result.is_ok()))))
diff --git a/crates/fparkan-runtime/src/laboratory.rs b/crates/fparkan-runtime/src/laboratory.rs
index eeb39527..ec9d27f9 100644
--- a/crates/fparkan-runtime/src/laboratory.rs
+++ b/crates/fparkan-runtime/src/laboratory.rs
@@ -127,7 +127,7 @@ impl Laboratories {
pub(super) fn order(
state: &mut Laboratories,
- catalogs: &BTreeMap<usize, crate::clan_research::ClanResearch>,
+ catalogs: &mut BTreeMap<usize, crate::clan_research::ClanResearch>,
drafts: &[crate::MissionObjectDraft],
free: &crate::research::FreeResearch,
world: &World,
@@ -136,9 +136,6 @@ pub(super) fn order(
lab: ObjectHandle,
now_ms: u32,
) -> Result<(), String> {
- if state.active(lab) || free.active(lab) {
- return Err("laboratory is busy".into());
- }
let owner = OwnerId(u16::try_from(clan).map_err(|_| "invalid research clan")?);
let identity = identity_metadata(world, lab).map_err(|error| error.to_string())?;
if identity.owner_id != Some(owner) {
@@ -154,8 +151,12 @@ pub(super) fn order(
}
let vfs = vfs.ok_or("research VFS is unavailable")?;
let catalog = catalogs
- .get(&clan)
+ .get_mut(&clan)
.ok_or("research catalog is unavailable")?;
+ catalog.refresh(vfs)?;
+ if state.active(lab) || free.active(lab) {
+ return Err("laboratory is busy".into());
+ }
let selected = catalog
.candidates
.entries
@@ -419,7 +420,7 @@ mod tests {
#[test]
#[ignore = "requires licensed corpus"]
- fn licensed_stock_ai_laboratories_finish_a_technology_and_release_the_lab() {
+ fn licensed_stock_ai_laboratories_continue_research_and_keep_the_request_pending() {
use crate::{
create, frame, load_gameplay_mission, EngineServices, MissionMode, MissionRequest,
MissionStartupInput,
@@ -465,11 +466,27 @@ mod tests {
);
assert!(!loaded.free_research.learned.is_empty());
assert!(loaded.laboratories.stopped.is_empty());
+ for clan in [1, 2] {
+ assert!(
+ loaded
+ .laboratories
+ .completed
+ .keys()
+ .filter(|&&(owner, _, _)| owner == clan)
+ .count()
+ >= 2,
+ "clan {clan} did not continue research after its first project"
+ );
+ }
assert!(
- loaded.laboratories.tasks.is_empty(),
- "laboratory remained busy"
+ !loaded.laboratories.available.is_empty(),
+ "later projects did not unlock technologies"
);
for &(clan, _, row, _) in &loaded.laboratories.report().completed {
+ assert!(loaded
+ .free_research
+ .learned
+ .contains(&(OwnerId(clan as u16), row)));
assert_eq!(
loaded.clan_ai_events.research_catalogs[&clan]
.table