Move battery status text to the presentation adapter
Sam::status, Comps::describe/worst and Sam::parts_text formatted player-facing Russian in the simulation. The adapter now owns that text: battery_view::sam_status for the panel and map, why_view::parts and why_view::worst for the monitor and the status line. The core keeps the data and gains only the accessors the adapter needs (preparing_cell, public cells/reload_time/magazine/gun facts). Texts are unchanged; the adapter tests pin the existing strings. Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
@@ -112,30 +112,6 @@ impl Comps {
|
||||
pub fn whole(&self) -> bool {
|
||||
self.0.iter().all(|&v| v >= 1.0)
|
||||
}
|
||||
/// Parts of this kind that are not whole, as "РЛС 40%, ходовая отказ".
|
||||
pub fn describe(&self, kind: SamKind) -> String {
|
||||
Part::ALL
|
||||
.iter()
|
||||
.filter(|p| p.on(kind) && self.get(**p) < 1.0)
|
||||
.map(|p| match self.state(*p) {
|
||||
PartState::Failed => format!("{} отказ", p.short()),
|
||||
_ => format!("{} {:.0}%", p.short(), self.get(*p) * 100.0),
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
}
|
||||
/// The weakest part alone, for a one-line status (the full list is on the monitor).
|
||||
pub fn worst(&self, kind: SamKind) -> String {
|
||||
Part::ALL
|
||||
.iter()
|
||||
.filter(|p| p.on(kind) && self.get(**p) < 1.0)
|
||||
.min_by(|a, b| self.get(**a).total_cmp(&self.get(**b)))
|
||||
.map(|p| match self.state(*p) {
|
||||
PartState::Failed => format!("{} отказ", p.short()),
|
||||
_ => format!("{} {:.0}%", p.short(), self.get(*p) * 100.0),
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Health points an object loses at the centre of a blast.
|
||||
@@ -443,9 +419,6 @@ impl Sam {
|
||||
pub fn part_state(&self, p: Part) -> PartState {
|
||||
if p.on(self.kind) { self.comps.state(p) } else { PartState::Ok }
|
||||
}
|
||||
pub fn parts_text(&self) -> String {
|
||||
self.comps.describe(self.kind)
|
||||
}
|
||||
/// The aiming drive's share of its speed: a failed one doesn't turn at all.
|
||||
pub(super) fn drive_fit(&self) -> f64 {
|
||||
let h = self.part(Part::Mount);
|
||||
@@ -461,7 +434,7 @@ impl Sam {
|
||||
0.5 + 0.5 * self.part(Part::Gun)
|
||||
}
|
||||
/// Its launcher's cells still good: a damaged one holds fewer missiles.
|
||||
pub(super) fn cells(&self) -> u32 {
|
||||
pub fn cells(&self) -> u32 {
|
||||
let Some(load) = &self.kind.spec().missile else { return 0 };
|
||||
let h = self.part(Part::Launcher);
|
||||
if h <= 0.0 { 0 } else { ((load.magazine as f64 * (0.4 + 0.6 * h)).ceil() as u32).clamp(1, load.magazine) }
|
||||
@@ -475,7 +448,7 @@ impl Sam {
|
||||
}
|
||||
}
|
||||
/// Ticks a reload takes: longer with a damaged launcher.
|
||||
pub(super) fn reload_time(&self) -> u32 {
|
||||
pub fn reload_time(&self) -> u32 {
|
||||
let r = self.kind.spec().reload.max(1);
|
||||
(r as f64 * (1.0 + 1.5 * (1.0 - self.part(Part::Launcher)))).round() as u32
|
||||
}
|
||||
|
||||
@@ -1220,57 +1220,9 @@ impl Sam {
|
||||
self.yaw_vel = 0.0;
|
||||
self.pitch_vel = 0.0;
|
||||
}
|
||||
pub fn status(&self) -> String {
|
||||
let spec = self.kind.spec();
|
||||
let mut text = spec.name.to_string();
|
||||
if !self.alive() {
|
||||
return text + " УНИЧТОЖЕН";
|
||||
}
|
||||
if self.moving() {
|
||||
return text + " " + &self.state.name().to_lowercase();
|
||||
}
|
||||
match self.kind {
|
||||
SamKind::Depot => return format!("{text}: {} перезарядок, RM48U {}, снятых ПВО {}", self.cargo, self.ground_stock, self.air_48n6_stock),
|
||||
SamKind::Tzm => return format!("{text}: на борту {}/2, RM48U {}, снятых ПВО {}{}", self.cargo, self.ground_stock, self.air_48n6_stock, if self.return_cargo { ", везёт RM48U на склад" } else if self.job.is_some() { ", в пути" } else { "" }),
|
||||
SamKind::Ew => {
|
||||
let state = if self.ew_on { "ГЛУШИТ" } else if self.ew_lock { "остывает" } else { "готова" };
|
||||
return format!("{text}: {state}, нагрев {:.0}%", self.heat * 100.0);
|
||||
}
|
||||
SamKind::Radar => {
|
||||
let broken = if self.comps.whole() { String::new() } else { format!(" [{}]", self.comps.worst(self.kind)) };
|
||||
return format!("{text}: целей {}{broken}", self.own.len());
|
||||
}
|
||||
SamKind::Light => return format!("{text}{}", if self.target.is_some() { ": в луче цель" } else { "" }),
|
||||
_ => {}
|
||||
}
|
||||
if let Some(p) = self.preparing {
|
||||
text += &format!(" · открытие ТПК №{}", p.cell + 1);
|
||||
}
|
||||
if self.empty && self.missiles == 0 {
|
||||
text += " ЖДЁТ БК";
|
||||
}
|
||||
if self.health < 1.0 {
|
||||
text += &format!(" ({:.0}%)", self.health * 100.0);
|
||||
}
|
||||
if !self.comps.whole() {
|
||||
text += &format!(" [{}]", self.comps.worst(self.kind));
|
||||
}
|
||||
if self.reloading > 0 {
|
||||
text += &format!(" перезарядка {}с", self.reloading.div_ceil(20));
|
||||
} else {
|
||||
if let Some(m) = &spec.missile {
|
||||
if self.kind == SamKind::S400 {
|
||||
text += &format!(" ПВО {} · RM48U {} / {} ячеек", self.missiles, self.ground_rounds, self.cells());
|
||||
if self.ground_return { text += " · ожидает вывоза RM48U"; }
|
||||
} else {
|
||||
text += &format!(" ракеты {}/{}", self.missiles, m.magazine);
|
||||
}
|
||||
}
|
||||
if spec.gun.is_some() {
|
||||
text += &format!(" очереди {}", self.bursts);
|
||||
}
|
||||
}
|
||||
text
|
||||
/// The TPK cell being opened, for the presentation adapter.
|
||||
pub fn preparing_cell(&self) -> Option<u32> {
|
||||
self.preparing.map(|p| p.cell)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -179,6 +179,14 @@ impl SamKind {
|
||||
let s = self.spec();
|
||||
s.missile.is_some() || s.gun.is_some()
|
||||
}
|
||||
/// Missiles its launcher's magazine holds; `None` without a launcher.
|
||||
pub fn missile_magazine(self) -> Option<u32> {
|
||||
self.spec().missile.as_ref().map(|m| m.magazine)
|
||||
}
|
||||
/// Whether it has a gun (its bursts are read by the status line).
|
||||
pub fn has_gun(self) -> bool {
|
||||
self.spec().gun.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
impl Sam {
|
||||
|
||||
Reference in New Issue
Block a user