diff options
Diffstat (limited to 'crates/fparkan-runtime/src/production.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/production.rs | 34 |
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] |
