diff options
Diffstat (limited to 'crates/fparkan-runtime/src')
| -rw-r--r-- | crates/fparkan-runtime/src/production.rs | 2 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/production/batch.rs | 2 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/production/strategic.rs | 60 |
3 files changed, 55 insertions, 9 deletions
diff --git a/crates/fparkan-runtime/src/production.rs b/crates/fparkan-runtime/src/production.rs index 50acdd94..37246b8a 100644 --- a/crates/fparkan-runtime/src/production.rs +++ b/crates/fparkan-runtime/src/production.rs @@ -60,6 +60,7 @@ pub(super) struct Production { struct Order { slot: usize, + scheme: usize, plant: ObjectHandle, plant_index: usize, owner: OwnerId, @@ -745,6 +746,7 @@ fn order_owned_factory( }; let order = Order { slot, + scheme, plant, plant_index, owner, diff --git a/crates/fparkan-runtime/src/production/batch.rs b/crates/fparkan-runtime/src/production/batch.rs index c0fb2690..ed8dee9a 100644 --- a/crates/fparkan-runtime/src/production/batch.rs +++ b/crates/fparkan-runtime/src/production/batch.rs @@ -10,7 +10,7 @@ use fparkan_world::{identity_metadata, ObjectHandle, OwnerId}; pub(super) struct BatchOrder { pub(super) plant: ObjectHandle, pub(super) owner: OwnerId, - scheme: usize, + pub(super) scheme: usize, } /// Starts a repeating order at an idle factory and reserves one clan slot. diff --git a/crates/fparkan-runtime/src/production/strategic.rs b/crates/fparkan-runtime/src/production/strategic.rs index 5b4e08f9..83360548 100644 --- a/crates/fparkan-runtime/src/production/strategic.rs +++ b/crates/fparkan-runtime/src/production/strategic.rs @@ -82,6 +82,8 @@ pub struct FactoryPanelPlant { pub free_minds: u32, pub progress: Option<u8>, pub batch: bool, + pub active_project: Option<usize>, + pub free_build: bool, pub projects: Vec<usize>, } @@ -98,7 +100,7 @@ pub fn factory_panel_plants( }; let free_minds = production.free_minds(&engine.world, mission, owner); let mut plants: Vec<_> = owned_factories(&engine.world, mission, production, owner) - .filter_map(|(index, handle, _)| { + .filter_map(|(index, handle, free_build)| { if factory_depleted(mission, handle) { return None; } @@ -113,6 +115,14 @@ pub fn factory_panel_plants( .pending .iter() .find(|order| order.plant == handle && order.owner == owner); + let batch = production + .batches + .iter() + .find(|batch| batch.plant == handle && batch.owner == owner); + let active_project = order + .map(|order| order.scheme) + .or_else(|| batch.map(|batch| batch.scheme)) + .filter(|&scheme| production.player_project(scheme)); let progress = order.map(|order| { let time = ratio( now_ms.wrapping_sub(order.start_ms) as f32, @@ -135,10 +145,9 @@ pub fn factory_panel_plants( label_id: label, free_minds, progress, - batch: production - .batches - .iter() - .any(|batch| batch.plant == handle && batch.owner == owner), + batch: batch.is_some(), + active_project, + free_build, projects, }, )) @@ -162,7 +171,11 @@ pub struct FactoryPanelProject { pub stats: WarbotStats, } -pub fn factory_panel_project(engine: &Engine, scheme: usize) -> Option<FactoryPanelProject> { +pub fn factory_panel_project( + engine: &Engine, + scheme: usize, + current_factory: Option<ObjectHandle>, +) -> Option<FactoryPanelProject> { let (mission, production) = loaded_production(engine).ok()?; let root = factory_project_root(engine, scheme)?; let draft = &mission.object_drafts[root]; @@ -180,7 +193,14 @@ pub fn factory_panel_project(engine: &Engine, scheme: usize) -> Option<FactoryPa .and_then(|flags| flags.chassis_type) .unwrap_or(0); let prefix = crate::strategic_roster::unit_prefix(size, chassis, role); - let stats = stats_from_table(production.controls.get(&root)?); + let order_controls = current_factory.and_then(|plant| { + let order = production + .pending + .iter() + .find(|order| order.plant == plant && order.scheme == scheme)?; + order.design.as_ref().map(|(_, controls)| controls) + }); + let stats = stats_from_table(order_controls.or_else(|| production.controls.get(&root))?); Some(FactoryPanelProject { prefix, label_id, @@ -225,12 +245,33 @@ mod tests { assert_eq!(plant.free_minds, 3); assert!(plant.progress.is_none()); let scheme = plant.projects[0]; - assert!(factory_panel_project(&engine, scheme).is_some()); + assert!(factory_panel_project(&engine, scheme, None).is_some()); let duration = order_clan_factory_scheme(&mut engine, cockpit, plant.handle, scheme, 100).unwrap(); let pending = factory_panel_plants(&engine, cockpit, 100 + duration / 2); assert_eq!(pending[0].free_minds, 2); assert_eq!(pending[0].progress, Some(50)); + assert_eq!(pending[0].active_project, Some(scheme)); + let production = engine.production.as_mut().unwrap(); + let order = production.pending.front_mut().unwrap(); + let mut controls = production.controls[&order.slot].clone(); + let speed = 12.5_f32; + controls.owner_profile.as_mut().unwrap().current_words[7] = speed.to_bits(); + order.design = Some((Vec::new(), controls)); + assert_eq!( + factory_panel_project(&engine, scheme, Some(plant.handle)) + .unwrap() + .stats + .speed, + Some(speed) + ); + assert_ne!( + factory_panel_project(&engine, scheme, None) + .unwrap() + .stats + .speed, + Some(speed) + ); cancel_clan_factory_order(&mut engine, cockpit, plant.handle).unwrap(); let idle = factory_panel_plants(&engine, cockpit, 100 + duration / 2); @@ -246,6 +287,7 @@ mod tests { 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_eq!(after_transfer[0].active_project, Some(scheme)); assert!(engine .production .as_ref() @@ -289,6 +331,7 @@ mod tests { .expect("initial batch order releases its machine"); let full = &factory_panel_plants(&engine, cockpit, completed_at)[0]; assert!(full.batch); + assert_eq!(full.active_project, Some(scheme)); assert_eq!(full.free_minds, 0); assert_eq!(full.progress, None); @@ -309,6 +352,7 @@ mod tests { super::super::tick_production(&mut engine, completed_at + 200).unwrap(); let stopped = &factory_panel_plants(&engine, cockpit, completed_at + 200)[0]; assert!(!stopped.batch); + assert_eq!(stopped.active_project, None); assert_eq!(stopped.progress, None); } } |
