From da458f8a991644a4033d3b529f23a2dd98a0329d Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 14 Nov 2026 16:18:58 +0400 Subject: feat(game): order robots remotely at allied factories --- apps/fparkan-game/src/main.rs | 76 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 15 deletions(-) (limited to 'apps/fparkan-game/src/main.rs') diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 920bf40f..1955490d 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -10044,10 +10044,17 @@ const PLAYER_MOVEMENT_KEYS: [KeyCode; 6] = [ #[derive(Default)] struct FactoryMenu { - choices: Vec<(usize, String)>, + choices: Vec, selected: usize, } +#[derive(Clone)] +struct FactoryChoice { + factory: Option, + scheme: usize, + name: String, +} + impl FactoryMenu { fn navigate(&mut self, backwards: bool) { let len = self.choices.len(); @@ -10056,11 +10063,16 @@ impl FactoryMenu { } fn title(&self) -> String { + let choice = &self.choices[self.selected]; + let factory = choice.factory.map_or_else( + || "Завод".to_owned(), + |factory| format!("Завод №{}", factory.slot + 1), + ); format!( - "Завод — {}/{} {} · ↑/↓ выбор · B или Enter заказ · Esc отмена", + "{factory} — {}/{} {} · ↑/↓ выбор · B или Enter заказ · Esc отмена", self.selected + 1, self.choices.len(), - self.choices[self.selected].1, + choice.name, ) } } @@ -11251,12 +11263,31 @@ impl StaticVulkanApp { let selected = if let Some(menu) = self.factory_menu.take() { Some(menu.choices[menu.selected].clone()) } else { - match fparkan_runtime::factory_schemes(engine, cockpit) { + let local = fparkan_runtime::factory_schemes(engine, cockpit); + let remote = local.is_err(); + let choices = local + .map(|choices| { + choices + .into_iter() + .map(|(index, path)| (None, index, path)) + .collect() + }) + .or_else(|_| { + fparkan_runtime::clan_factory_schemes(engine, cockpit).map(|choices| { + choices + .into_iter() + .map(|(factory, index, path)| (Some(factory), index, path)) + .collect::>() + }) + }); + match choices { Ok(choices) => { let mut choices = choices .into_iter() - .map(|(index, path)| { - (index, path.rsplit('/').next().unwrap_or(path).to_owned()) + .map(|(factory, scheme, path)| FactoryChoice { + factory, + scheme, + name: path.rsplit('/').next().unwrap_or(path).to_owned(), }) .collect::>(); match choices.len() { @@ -11265,7 +11296,7 @@ impl StaticVulkanApp { Some("Завод — нет подходящих схем".into()); None } - 1 => choices.pop(), + 1 if !remote => choices.pop(), _ => { self.factory_menu = Some(FactoryMenu { choices, @@ -11284,16 +11315,31 @@ impl StaticVulkanApp { } } }; - if let Some((index, name)) = selected { - match fparkan_runtime::order_factory_scheme( - engine, - cockpit, - index, - control_clock_ms, - ) { + if let Some(FactoryChoice { + factory, + scheme, + name, + }) = selected + { + let order = match factory { + Some(factory) => fparkan_runtime::order_clan_factory_scheme( + engine, + cockpit, + factory, + scheme, + control_clock_ms, + ), + None => fparkan_runtime::order_factory_scheme( + engine, + cockpit, + scheme, + control_clock_ms, + ), + }; + match order { Ok(duration) => { self.factory_status = Some(format!("Завод — собирается {name}")); - eprintln!("factory_order scheme={name} minimum_ms={duration} queue_time_ms={control_clock_ms}"); + eprintln!("factory_order scheme={name} remote={} minimum_ms={duration} queue_time_ms={control_clock_ms}", factory.is_some()); } Err(error) => { self.factory_status = Some("Завод — заказ отклонён".into()); -- cgit v1.2.3