aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/research.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-25 17:06:07 +0300
committerValentin Popov <valentin@popov.link>2026-11-25 17:06:07 +0300
commitbef4fbab7701a51945ed93357babe12b416bb9a8 (patch)
tree3990f0e2898b369c53f42b514c185ceeb7372132 /crates/fparkan-runtime/src/research.rs
parent593e38ba45fc7d28e28bdcc0fa8020a6c62deac0 (diff)
downloadfparkan-bef4fbab7701a51945ed93357babe12b416bb9a8.tar.xz
fparkan-bef4fbab7701a51945ed93357babe12b416bb9a8.zip
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.
Diffstat (limited to 'crates/fparkan-runtime/src/research.rs')
-rw-r--r--crates/fparkan-runtime/src/research.rs63
1 files changed, 16 insertions, 47 deletions
diff --git a/crates/fparkan-runtime/src/research.rs b/crates/fparkan-runtime/src/research.rs
index 97e37d2e..3510a295 100644
--- a/crates/fparkan-runtime/src/research.rs
+++ b/crates/fparkan-runtime/src/research.rs
@@ -31,6 +31,21 @@ struct Order {
}
impl FreeResearch {
+ pub(super) fn active(&self, lab: ObjectHandle) -> bool {
+ self.pending.as_ref().is_some_and(|order| order.lab == lab)
+ }
+
+ pub(super) fn take_free(&mut self, slot: usize) -> bool {
+ let Some((_, count)) = self
+ .remaining
+ .iter_mut()
+ .find(|(index, count)| *index == slot && *count > 0)
+ else {
+ return false;
+ };
+ *count -= 1;
+ true
+ }
pub(super) fn new(drafts: &[MissionObjectDraft]) -> Self {
let remaining = drafts
.iter()
@@ -172,52 +187,6 @@ mod tests {
#[test]
#[ignore = "requires licensed corpus"]
- fn licensed_new_lab_rejects_an_unwired_research_task_without_stopping_the_script() {
- 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.02/data.tma".into(),
- mode: MissionMode::SingleMission,
- },
- MissionStartupInput {
- queue_time_ms: 0,
- research_creation_gate: false,
- },
- None,
- )
- .unwrap();
- for now in (0..=900_000).step_by(100) {
- frame(&mut engine, now).unwrap();
- }
- let loaded = engine.loaded.as_ref().unwrap();
- let lab = loaded
- .object_drafts
- .iter()
- .skip(loaded.mission.objects.len())
- .filter(|draft| draft.unit_dat_header_flags == Some(LAB_CLASS))
- .find_map(|draft| handle_by_original_id(&engine.world, draft.original_id?))
- .unwrap();
- let id = loaded
- .mission_events
- .logic_id(&loaded.mission, &engine.world, lab)
- .unwrap();
- assert!(loaded
- .mission_events
- .logic_objects(&loaded.mission, &engine.world, id)
- .any(|handle| handle == lab));
- assert!(loaded
- .clan_ai_events
- .research_status_stubs()
- .any(|(clan, handler, count)| clan == 1 && handler == 41 && count > 0));
- assert!(loaded.clan_ai_events.stops().next().is_none());
- assert!(loaded.free_research.pending.is_none());
- assert!(loaded.free_research.learned.is_empty());
- }
-
- #[test]
- #[ignore = "requires licensed corpus"]
fn licensed_teleport_lab_researches_the_available_turret() {
let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").unwrap();
let vfs: Arc<dyn Vfs> = Arc::new(DirectoryVfs::new(std::path::PathBuf::from(root)));
@@ -268,7 +237,7 @@ mod tests {
}
}
-fn property(draft: &MissionObjectDraft, name: &[u8]) -> Option<u32> {
+pub(super) fn property(draft: &MissionObjectDraft, name: &[u8]) -> Option<u32> {
draft
.properties
.iter()