aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/production.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 15:28:59 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 15:28:59 +0300
commitaafdd0c398923f51625b632789ff0c7948b006e8 (patch)
tree34717d5b9750e5d0ccf7e11ff91de66b09cb762c /crates/fparkan-runtime/src/production.rs
parentcc6bbdfa4aebf844ec7be2e8eb01b7fd1c69d24b (diff)
downloadfparkan-aafdd0c398923f51625b632789ff0c7948b006e8.tar.xz
fparkan-aafdd0c398923f51625b632789ff0c7948b006e8.zip
feat(ui): stop an active strategic factory order
Diffstat (limited to 'crates/fparkan-runtime/src/production.rs')
-rw-r--r--crates/fparkan-runtime/src/production.rs34
1 files changed, 30 insertions, 4 deletions
diff --git a/crates/fparkan-runtime/src/production.rs b/crates/fparkan-runtime/src/production.rs
index d314aa88..c6bad31c 100644
--- a/crates/fparkan-runtime/src/production.rs
+++ b/crates/fparkan-runtime/src/production.rs
@@ -26,7 +26,8 @@ use std::sync::Arc;
mod strategic;
pub use strategic::{
- factory_panel_plants, factory_panel_project, FactoryPanelPlant, FactoryPanelProject,
+ cancel_clan_factory_order, factory_panel_plants, factory_panel_project, FactoryPanelPlant,
+ FactoryPanelProject,
};
// shortcut: GPU geometry is prepared for a bounded number of live builds per scheme.
@@ -298,9 +299,7 @@ impl Production {
.is_ok_and(|identity| identity.owner_id == Some(order.owner))
{
if order.paid.is_some() && identity_metadata(world, order.plant).is_ok() {
- let (table, ore) = factory_resources(mission, order.plant)?;
- set_factory_power(table, 0.0)?;
- ore.maximum_ore_bits = 0;
+ clear_factory_demand(mission, order.plant)?;
}
return Ok(None);
}
@@ -946,6 +945,16 @@ fn factory_resources(
))
}
+fn clear_factory_demand(
+ mission: &mut LoadedMissionState,
+ plant: ObjectHandle,
+) -> Result<&mut BehaviorOreState, EngineError> {
+ let (table, ore) = factory_resources(mission, plant)?;
+ set_factory_power(table, 0.0)?;
+ ore.maximum_ore_bits = 0;
+ Ok(ore)
+}
+
fn factory_rate(table: &MissionControlDeviceTableState) -> Result<f32, EngineError> {
query_behavior_profile_ore_rate(table, 1.0_f32.to_bits())
.map_err(|error| EngineError::Production(format!("{error:?}")))
@@ -1414,6 +1423,23 @@ mod tests {
production.clock_ticks().collect::<Vec<_>>(),
[(0, plant.slot, 2)]
);
+ let cockpit = starting_cockpit(&engine).unwrap();
+ strategic::cancel_clan_factory_order(&mut engine, cockpit, plant).unwrap();
+ let (table, ore) = factory_resources(engine.loaded.as_mut().unwrap(), plant).unwrap();
+ assert_eq!(ore.maximum_ore_bits, 0);
+ assert_eq!(ore.current_ore_bits, 0);
+ let MissionControlDeviceTableStatus::Available(devices) = &table.status else {
+ panic!("factory devices");
+ };
+ assert_eq!(
+ devices
+ .iter()
+ .find(|device| device.descriptor.tag == 26)
+ .unwrap()
+ .tag26_extra_rate_bits,
+ Some(0)
+ );
+ assert!(engine.production.as_ref().unwrap().pending.is_empty());
}
#[test]