aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/production
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/production')
-rw-r--r--crates/fparkan-runtime/src/production/strategic.rs46
1 files changed, 44 insertions, 2 deletions
diff --git a/crates/fparkan-runtime/src/production/strategic.rs b/crates/fparkan-runtime/src/production/strategic.rs
index c39566fe..cbbafee0 100644
--- a/crates/fparkan-runtime/src/production/strategic.rs
+++ b/crates/fparkan-runtime/src/production/strategic.rs
@@ -1,6 +1,6 @@
use super::{
clear_factory_demand, loaded_production, owned_factories, player_owner, production_error,
- recent_schemes_for_plant,
+ recent_schemes_for_plant, schemes_for_plant,
};
use crate::{
factory_project_root,
@@ -36,6 +36,34 @@ pub fn cancel_clan_factory_order(
Ok(())
}
+/// Places a compatible prepared project in the selected factory's recent list.
+pub fn remember_strategic_factory_project(
+ engine: &mut Engine,
+ cockpit: StartingCockpit,
+ plant: ObjectHandle,
+ scheme: usize,
+) -> Result<(), EngineError> {
+ let index = super::player_factory_index(engine, cockpit, Some(plant))?;
+ let owner = player_owner(&engine.world, cockpit)?;
+ let (mission, production) = loaded_production(engine)?;
+ if !production.player_project(scheme)
+ || !schemes_for_plant(mission, production, index).any(|(id, _)| id == scheme)
+ {
+ return Err(production_error(
+ "project is incompatible with the selected factory",
+ ));
+ }
+ let production = engine.production.as_mut().expect("loaded production");
+ let history = production
+ .transferred_projects
+ .entry((index, owner.0))
+ .or_default();
+ history.retain(|&id| id != scheme);
+ history.insert(0, scheme);
+ history.truncate(fparkan_assets::factory_projects::PROJECT_SLOTS);
+ Ok(())
+}
+
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FactoryPanelPlant {
pub handle: ObjectHandle,
@@ -97,7 +125,7 @@ pub fn factory_panel_plants(
});
(time.min(collected) * 100.0).round_ties_even() as u8
});
- let projects = recent_schemes_for_plant(mission, production, index)
+ let projects = recent_schemes_for_plant(mission, production, index, owner)
.into_iter()
.map(|(id, _)| id)
.collect();
@@ -210,5 +238,19 @@ mod tests {
.unwrap(),
duration
);
+ let other = plant.projects[1];
+ remember_strategic_factory_project(&mut engine, cockpit, plant.handle, other).unwrap();
+ let after_transfer = factory_panel_plants(&engine, cockpit, 100 + duration);
+ assert_eq!(after_transfer[0].projects, [other, scheme]);
+ assert_eq!(after_transfer[0].free_minds, 2);
+ assert!(engine
+ .production
+ .as_ref()
+ .unwrap()
+ .pending
+ .iter()
+ .all(|order| {
+ order.slot == engine.production.as_ref().unwrap().slot_starts[scheme]
+ }));
}
}