aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/mining.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 06:35:08 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 06:35:08 +0300
commit5be1b800d028ba30c5e2a4ff84983c700b4e9175 (patch)
tree111eca3acb2cbeff5dedfef3b1a55732ed3c3985 /crates/fparkan-runtime/src/mining.rs
parentb0c3a064c29c2bf97981f45806696c2dd0d4dd90 (diff)
downloadfparkan-5be1b800d028ba30c5e2a4ff84983c700b4e9175.tar.xz
fparkan-5be1b800d028ba30c5e2a4ff84983c700b4e9175.zip
feat(factory): register new designs in a running mission
Load control devices and visuals for saved Unit DAT designs, keep the project bytes pinned for later orders, and select mine reserve drafts by identity. The Field Camp runtime test registers a design without a startup reserve, supplies the factory from a new mine, and checks the released mounts and devices. Stock mission window starts with Vulkan validation clean. Connecting the in-game designer order and world rendering is the next step.
Diffstat (limited to 'crates/fparkan-runtime/src/mining.rs')
-rw-r--r--crates/fparkan-runtime/src/mining.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/crates/fparkan-runtime/src/mining.rs b/crates/fparkan-runtime/src/mining.rs
index c3be7e07..abf510b5 100644
--- a/crates/fparkan-runtime/src/mining.rs
+++ b/crates/fparkan-runtime/src/mining.rs
@@ -110,14 +110,12 @@ pub fn deploy_mine(
let player = transform_state(&engine.world, cockpit.handle)?
.position
.map(f32::from_bits);
- let start = mission.object_drafts.len() - mission.mine_sites.len();
// shortcut: an order from the hero selects a nearby deposit and builder
// until the strategic selection and builder movement UI are available.
- let (offset, site) = mission
+ let site = mission
.mine_sites
.iter()
- .enumerate()
- .filter(|(_, site)| {
+ .filter(|site| {
site.remaining > 0.0
&& site
.control
@@ -126,10 +124,10 @@ pub fn deploy_mine(
.is_some()
&& site.live_mine(&engine.world).is_none()
})
- .map(|(offset, site)| (distance_xy(site.position, player), offset, site))
- .filter(|(distance, _, _)| *distance <= BUILD_DISTANCE)
+ .map(|site| (distance_xy(site.position, player), site))
+ .filter(|(distance, _)| *distance <= BUILD_DISTANCE)
.min_by(|a, b| a.0.total_cmp(&b.0))
- .map(|(_, offset, site)| (offset, site))
+ .map(|(_, site)| site)
.ok_or_else(|| reject("stand within 150 units of a free ore deposit"))?;
let builder = mission
.behavior_ore_states
@@ -167,8 +165,12 @@ pub fn deploy_mine(
.filter(|entry| entry.super_ai_visible)
.ok_or_else(|| reject("player clan has no resource distributor"))?;
let clan = distributor.clan_index;
- let index = start + offset;
- let draft = &mission.object_drafts[index];
+ let index = id.0 as usize;
+ let draft = mission
+ .object_drafts
+ .get(index)
+ .filter(|draft| draft.original_id == Some(id))
+ .ok_or_else(|| reject("mine slot has no draft"))?;
if draft.unit_dat_header_flags != Some(MINE_CLASS)
|| !matches!(
table.status,