diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-14 23:18:34 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-14 23:18:34 +0300 |
| commit | 66c02b87b96e63d3cfce29c8ca33a2bb28662ec6 (patch) | |
| tree | c949f84e12efad4126851bc61eb617ccc87c3948 /crates/fparkan-runtime/src/construction_site.rs | |
| parent | bbd6088b7fb1162a976bcfa1ca6720c2c91e8a72 (diff) | |
| download | fparkan-66c02b87b96e63d3cfce29c8ca33a2bb28662ec6.tar.xz fparkan-66c02b87b96e63d3cfce29c8ca33a2bb28662ec6.zip | |
feat(ai): execute tower construction orders
Use the first BuildDat scheme for the requested class, check learned components, and route the builder before spending onboard ore. The Behavior.dll oracle rejected the stock scheme and returned 1100 ore after unlocking the components.
The stock mission 28 window showed the refusal with its original tech tree. A licensed prepared test exercised construction and ore deduction. Onboard supply remains required pending warehouse refill.
Diffstat (limited to 'crates/fparkan-runtime/src/construction_site.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/construction_site.rs | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/crates/fparkan-runtime/src/construction_site.rs b/crates/fparkan-runtime/src/construction_site.rs index 5993d244..ddb92a8e 100644 --- a/crates/fparkan-runtime/src/construction_site.rs +++ b/crates/fparkan-runtime/src/construction_site.rs @@ -6,6 +6,28 @@ use crate::{mining::MineSite, MissionObjectDraft}; #[derive(Default)] pub(super) struct SiteReservations(Vec<([u32; 2], u32)>); +pub(super) fn building_centers<'a>( + world: &'a World, + drafts: &'a [MissionObjectDraft], +) -> impl Iterator<Item = [f32; 2]> + 'a { + drafts.iter().filter_map(|draft| { + if draft.unit_dat_header_flags? & 0x8000_0000 == 0 { + return None; + } + let handle = handle_by_original_id(world, draft.original_id?)?; + registration_sequence(world, handle).ok()??; + let [x, y, _] = transform_state(world, handle) + .ok()? + .position + .map(f32::from_bits); + Some([x, y]) + }) +} + +pub(super) fn separated([x, y]: [f32; 2], [a, b]: [f32; 2]) -> bool { + (x - a).trunc().hypot((y - b).trunc()) >= 250.0 +} + impl SiteReservations { pub(super) fn find( &mut self, @@ -18,18 +40,7 @@ impl SiteReservations { ) -> Option<[u32; 2]> { self.0 .retain(|&(_, time)| now_ms.wrapping_sub(time) <= 60_000); - let occupied = drafts.iter().filter_map(|draft| { - if draft.unit_dat_header_flags? & 0x8000_0000 == 0 { - return None; - } - let handle = handle_by_original_id(world, draft.original_id?)?; - registration_sequence(world, handle).ok()??; - let [x, y, _] = transform_state(world, handle) - .ok()? - .position - .map(f32::from_bits); - Some([x, y]) - }); + let occupied = building_centers(world, drafts); let deposits = mines.iter().filter_map(|site| { let [x, y, _] = site.position; site.live_mine(world).is_none().then_some([x, y]) @@ -68,12 +79,7 @@ fn find_site( let (sin, cos) = f64::from(angle).sin_cos(); let x = base_x + (radius * cos).trunc() as f32; let y = base_y + (radius * sin).trunc() as f32; - if x > 0.0 - && y > 0.0 - && occupied - .iter() - .all(|&[a, b]| (x - a).trunc().hypot((y - b).trunc()) >= 250.0) - { + if x > 0.0 && y > 0.0 && occupied.iter().all(|&other| separated([x, y], other)) { let corners = [ [x + 75.0, y + 75.0], [x - 75.0, y - 75.0], |
