aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime
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
parentcc6bbdfa4aebf844ec7be2e8eb01b7fd1c69d24b (diff)
downloadfparkan-aafdd0c398923f51625b632789ff0c7948b006e8.tar.xz
fparkan-aafdd0c398923f51625b632789ff0c7948b006e8.zip
feat(ui): stop an active strategic factory order
Diffstat (limited to 'crates/fparkan-runtime')
-rw-r--r--crates/fparkan-runtime/src/lib.rs9
-rw-r--r--crates/fparkan-runtime/src/production.rs34
-rw-r--r--crates/fparkan-runtime/src/production/strategic.rs46
3 files changed, 78 insertions, 11 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 206c41cb..f073672e 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -212,10 +212,11 @@ pub use player_weapon::{
WeaponIndicator, WeaponLamp,
};
pub use production::{
- clan_factory_schemes, factory_panel_plants, factory_panel_project, factory_part_variants,
- factory_project_components, factory_project_root, factory_project_schemes,
- factory_saved_schemes, factory_schemes, order_clan_factory_scheme, order_factory_design,
- order_factory_robot, order_factory_scheme, FactoryPanelPlant, FactoryPanelProject,
+ cancel_clan_factory_order, clan_factory_schemes, factory_panel_plants, factory_panel_project,
+ factory_part_variants, factory_project_components, factory_project_root,
+ factory_project_schemes, factory_saved_schemes, factory_schemes, order_clan_factory_scheme,
+ order_factory_design, order_factory_robot, order_factory_scheme, FactoryPanelPlant,
+ FactoryPanelProject,
};
pub use projectile::{
apply_projectile_contact, apply_projectile_hit, apply_projectile_impact,
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]
diff --git a/crates/fparkan-runtime/src/production/strategic.rs b/crates/fparkan-runtime/src/production/strategic.rs
index a6dc21d3..c39566fe 100644
--- a/crates/fparkan-runtime/src/production/strategic.rs
+++ b/crates/fparkan-runtime/src/production/strategic.rs
@@ -1,10 +1,40 @@
-use super::{loaded_production, owned_factories, player_owner, recent_schemes_for_plant};
+use super::{
+ clear_factory_demand, loaded_production, owned_factories, player_owner, production_error,
+ recent_schemes_for_plant,
+};
use crate::{
factory_project_root,
warbot_stats::{stats_from_table, WarbotStats},
- Engine, StartingCockpit,
+ Engine, EngineError, StartingCockpit,
};
-use fparkan_world::{registration_sequence, ObjectHandle};
+use fparkan_world::{identity_metadata, registration_sequence, ObjectHandle};
+
+/// Stops an order that has not released a robot and frees its reserved slot.
+pub fn cancel_clan_factory_order(
+ engine: &mut Engine,
+ cockpit: StartingCockpit,
+ plant: ObjectHandle,
+) -> Result<(), EngineError> {
+ let owner = player_owner(&engine.world, cockpit)?;
+ if !identity_metadata(&engine.world, plant).is_ok_and(|meta| meta.owner_id == Some(owner)) {
+ return Err(production_error(
+ "selected factory no longer belongs to the player's clan",
+ ));
+ }
+ let (Some(mission), Some(production)) = (&mut engine.loaded, &mut engine.production) else {
+ return Err(production_error("mission has no factory production"));
+ };
+ let index = production
+ .pending
+ .iter()
+ .position(|order| order.plant == plant && order.owner == owner)
+ .ok_or_else(|| production_error("factory has no active order to cancel"))?;
+ if production.pending[index].paid.is_some() {
+ clear_factory_demand(mission, plant)?.current_ore_bits = 0;
+ }
+ production.pending.remove(index);
+ Ok(())
+}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FactoryPanelPlant {
@@ -170,5 +200,15 @@ mod tests {
let pending = factory_panel_plants(&engine, cockpit, 100 + duration / 2);
assert_eq!(pending[0].free_minds, 2);
assert_eq!(pending[0].progress, Some(50));
+
+ cancel_clan_factory_order(&mut engine, cockpit, plant.handle).unwrap();
+ let idle = factory_panel_plants(&engine, cockpit, 100 + duration / 2);
+ assert_eq!(idle[0], *plant);
+ assert!(cancel_clan_factory_order(&mut engine, cockpit, plant.handle).is_err());
+ assert_eq!(
+ order_clan_factory_scheme(&mut engine, cockpit, plant.handle, scheme, 100 + duration)
+ .unwrap(),
+ duration
+ );
}
}