diff options
Diffstat (limited to 'crates/fparkan-runtime/src/production.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/production.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/crates/fparkan-runtime/src/production.rs b/crates/fparkan-runtime/src/production.rs index c6bad31c..8c3b2c13 100644 --- a/crates/fparkan-runtime/src/production.rs +++ b/crates/fparkan-runtime/src/production.rs @@ -26,8 +26,8 @@ use std::sync::Arc; mod strategic; pub use strategic::{ - cancel_clan_factory_order, factory_panel_plants, factory_panel_project, FactoryPanelPlant, - FactoryPanelProject, + cancel_clan_factory_order, factory_panel_plants, factory_panel_project, + remember_strategic_factory_project, FactoryPanelPlant, FactoryPanelProject, }; // shortcut: GPU geometry is prepared for a bounded number of live builds per scheme. @@ -47,6 +47,7 @@ pub(super) struct Production { ai_schemes: Vec<crate::clan_factory_schemes::ScriptDesign>, controls: std::collections::BTreeMap<usize, MissionControlDeviceTableState>, plants: Vec<(usize, u32)>, + transferred_projects: std::collections::BTreeMap<(usize, u16), Vec<usize>>, pending: VecDeque<Order>, clock_ticks: std::collections::BTreeMap<(u16, u32), u64>, buildings: BuildingFootprints, @@ -185,6 +186,7 @@ impl Production { ai_schemes, controls: (reserve_start..).zip(controls).collect(), plants: Vec::new(), + transferred_projects: Default::default(), pending: VecDeque::new(), clock_ticks: Default::default(), buildings: BuildingFootprints::default(), @@ -434,7 +436,8 @@ pub fn factory_schemes( ) -> Result<Vec<(usize, &str)>, EngineError> { let (mission, production) = loaded_production(engine)?; let (plant, _) = factory_at_communicator(&engine.world, mission, production, cockpit)?; - Ok(recent_schemes_for_plant(mission, production, plant)) + let owner = player_owner(&engine.world, cockpit)?; + Ok(recent_schemes_for_plant(mission, production, plant, owner)) } /// Lists the live factories of the player's clan and matching configured schemes. @@ -446,7 +449,7 @@ pub fn clan_factory_schemes( let owner = player_owner(&engine.world, cockpit)?; Ok(owned_factories(&engine.world, mission, production, owner) .flat_map(|(index, factory, _)| { - recent_schemes_for_plant(mission, production, index) + recent_schemes_for_plant(mission, production, index, owner) .into_iter() .map(move |(scheme, path)| (factory, scheme, path)) }) @@ -534,9 +537,20 @@ fn recent_schemes_for_plant<'a>( mission: &'a LoadedMissionState, production: &'a Production, plant: usize, + owner: OwnerId, ) -> Vec<(usize, &'a str)> { - let mut recent = schemes_for_plant(mission, production, plant) - .filter(|&(scheme, _)| scheme < production.player_scheme_count) + let history = production.transferred_projects.get(&(plant, owner.0)); + let mut recent = history + .into_iter() + .flatten() + .map(|&id| (id, production.schemes[id].as_str())) + .chain( + schemes_for_plant(mission, production, plant).filter(|&(scheme, _)| { + scheme < production.player_scheme_count + && history.is_none_or(|history| !history.contains(&scheme)) + }), + ) + .take(fparkan_assets::factory_projects::PROJECT_SLOTS) .collect::<Vec<_>>(); if recent.is_empty() { recent.extend( |
