diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-14 22:55:21 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-14 22:55:21 +0300 |
| commit | 64bb8b476b525706d08d00be7c6f6cc397606c06 (patch) | |
| tree | 8a6bb33086190196517ff7e255d815480da4d9b7 /crates/fparkan-runtime/src/production.rs | |
| parent | d43524a8e40bb923d9275e17d3dc586701f08bbf (diff) | |
| download | fparkan-64bb8b476b525706d08d00be7c6f6cc397606c06.tar.xz fparkan-64bb8b476b525706d08d00be7c6f6cc397606c06.zip | |
feat(ai): carry ore from clan mines to storage
Resolve the stock transport order against the newly produced unit. Move between owned endpoints and limit transfers by rate, source stock and destination space. The window logged the first departure and the stock simulation completed an unloading cycle. Native roster selection was called directly. Port approaches and rates remain approximations.
Diffstat (limited to 'crates/fparkan-runtime/src/production.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/production.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/production.rs b/crates/fparkan-runtime/src/production.rs index 8781febd..6bc3e306 100644 --- a/crates/fparkan-runtime/src/production.rs +++ b/crates/fparkan-runtime/src/production.rs @@ -276,6 +276,26 @@ impl Production { position, self.controls[order.slot - self.reserve_start].clone(), )?; + let draft = &mission.object_drafts[order.slot]; + if draft.unit_dat_header_flags == Some(crate::clan_transport_schemes::TRANSPORT_CLASS) { + let id = draft + .original_id + .expect("prepared factory object has an ID"); + mission + .mission_events + .issue_logic_id(&mission.mission, world, handle); + mission + .behavior_ore_states + .retain(|ore| ore.original_id != id); + mission + .behavior_ore_states + .push(crate::initialize_behavior_ore_state( + id, + handle, + crate::clan_transport_schemes::TRANSPORT_CLASS, + &draft.properties, + )); + } if order.paid.is_none() { let (_, count) = self .plants @@ -810,6 +830,46 @@ mod tests { && (cargo_slots..cargo_slots + RESERVE_SLOTS).contains(&index)), "{completed:?}" ); + let transport = completed + .iter() + .find_map(|&(clan, index)| { + (clan == 1 && (cargo_slots..cargo_slots + RESERVE_SLOTS).contains(&index)) + .then_some(index) + }) + .unwrap(); + let draft = &engine.loaded.as_ref().unwrap().object_drafts[transport]; + let id = draft.original_id.unwrap(); + let handle = handle_by_original_id(&engine.world, id).unwrap(); + let storage = engine + .loaded + .as_ref() + .unwrap() + .behavior_ore_states + .iter() + .find(|ore| { + ore.class_flags == 0x8000_0008 + && identity_metadata(&engine.world, ore.handle) + .unwrap() + .owner_id + == Some(OwnerId(1)) + }) + .unwrap(); + let storage_handle = storage.handle; + let initial_stock = f32::from_bits(storage.current_ore_bits); + for time in ((40_000 + duration + 2016)..=175_000).step_by(200) { + step_headless(&mut engine, InputSnapshot::default(), time).unwrap(); + let loaded = engine.loaded.as_ref().unwrap(); + if loaded.behavior_ore_states.iter().any(|ore| { + ore.handle == storage_handle && f32::from_bits(ore.current_ore_bits) > initial_stock + }) { + assert!(loaded + .clan_ai_events + .transport_orders() + .any(|(clan, unit, _)| clan == 1 && unit == handle.slot)); + return; + } + } + panic!("transport should unload ore into the enemy storage"); } #[test] |
