F6: ere e obsolescenza dei veicoli
La tecnologia avanzava solo come filtro d'acquisto: nessuna notizia del cambio d'era, nessun modello «superato», due formule diverse per valore di libro e rivendita e nessun modo di sostituire i veicoli di un treno. Ora rinnovare la flotta è una scelta con costi e benefici visibili. - vehicles.json: successore per modello (validato: stessa categoria, introdotto dopo) e parametri di obsolescenza; Obsolescence, senza stato, ricava produzione, superato, successore consigliato, curva del valore (gradino all'arrivo del successore, poi ammortamento più rapido) e fattore di manutenzione: una sola fonte per patrimonio, SellVehicle, rinnovo e quadri. - Rinnovo come intervento «renewal» di maintenance.json prenotato con ScheduleService: in officina i veicoli superati si vendono e il successore prende il loro posto. Nessun comando nuovo. - EraSystem: il 1° gennaio la notizia dell'era e delle novità dell'anno lette dai dati, annotata nella Cronaca, una volta sola anche attraverso un salvataggio. - Nessuno stato nuovo, quindi il salvataggio resta alla versione 7. - IA: modelli dei progetti aggiornati quando escono di produzione e rinnovo mensile con una regola in ai.json. - Protocollo: DetailKind.Fleet (10) e FleetReport (136); client: catalogo senza i fuori produzione e con i superati segnati, rivendita, Vendi e Rinnova nel pannello Treni, sezione «Rinnovo della flotta» in Officine. - ADR 0020, STATE, ARCHITECTURE e PROTOCOL aggiornati; ErasTests (11). Accettazione F4 e F5 invariate. Refs #41. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b3a9bdb9c
commit
f7c286bf1d
39 files changed
+1648
-53
No files matched your search
@@ -3,6 +3,7 @@ using RailEnterprise.Client.App;
|
||||
using RailEnterprise.Client.Net;
|
||||
using RailEnterprise.Core.Commands;
|
||||
using RailEnterprise.Core.Common;
|
||||
using RailEnterprise.Core.Data;
|
||||
using RailEnterprise.Protocol.Messages;
|
||||
using static RailEnterprise.Client.App.Localization;
|
||||
|
||||
@@ -11,7 +12,8 @@ namespace RailEnterprise.Client.Panels;
|
||||
/// <summary>
|
||||
/// Officine (sezione 10.3): politica della flotta, avvisi, flotta ordinata per condizione con la
|
||||
/// mappa di calore, cartella di manutenzione del treno scelto, depositi con il Registro officina e
|
||||
/// la scorta di ricambi. Le cartelle e i registri arrivano su richiesta dal server.
|
||||
/// la scorta di ricambi, rinnovo della flotta (ere e obsolescenza, ADR 0020). Le cartelle, i registri
|
||||
/// e il quadro della flotta arrivano su richiesta dal server: età, successori e valori non si calcolano qui.
|
||||
/// </summary>
|
||||
public partial class MaintenancePanel : VBoxContainer
|
||||
{
|
||||
@@ -29,12 +31,15 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
private readonly VBoxContainer _workshop = PanelKit.Column(8);
|
||||
private readonly VBoxContainer _workshopDetails = PanelKit.Column(6);
|
||||
private readonly HBoxContainer _orderRow = PanelKit.Row();
|
||||
private readonly VBoxContainer _fleet = PanelKit.Column(6);
|
||||
private readonly Label _status = UiTheme.Text("", 13, Palette.TextSecondary);
|
||||
private readonly List<int> _trainIds = [];
|
||||
private readonly List<int> _depotIds = [];
|
||||
private int _train = -1, _depot = -1;
|
||||
private int _entityVersion = -1, _detailVersion = -1;
|
||||
private double _request;
|
||||
private long _fleetDay = long.MinValue;
|
||||
private double _sinceFleet = double.MaxValue;
|
||||
private bool _updating;
|
||||
|
||||
public event Action<bool>? HeatMapToggled;
|
||||
@@ -69,6 +74,9 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
AddChild(_workshop);
|
||||
AddChild(_workshopDetails);
|
||||
AddChild(_orderRow);
|
||||
AddChild(PanelKit.Separator());
|
||||
AddChild(UiTheme.Text(T("Rinnovo della flotta"), 14, bold: true));
|
||||
AddChild(_fleet);
|
||||
_status.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
AddChild(_status);
|
||||
|
||||
@@ -113,10 +121,26 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
if (_depot >= 0) _session.Send(new RequestDetail { Kind = DetailKind.Workshop, Target = _depot });
|
||||
}
|
||||
var w = _session.World;
|
||||
// quadro della flotta: all'apertura e a ogni nuovo giorno; di nuovo dopo 5 s se non arriva
|
||||
_sinceFleet += delta;
|
||||
long today = Fmt.Today(w);
|
||||
if (today != _fleetDay || (w.Fleet is null && _sinceFleet > 5)) RequestFleet(today);
|
||||
if (w.EntityVersion != _entityVersion || w.DetailVersion != _detailVersion) Refresh();
|
||||
}
|
||||
|
||||
private void Result(CommandResultMessage r) => _status.Text = r.Message;
|
||||
private void RequestFleet(long day)
|
||||
{
|
||||
_fleetDay = day;
|
||||
_sinceFleet = 0;
|
||||
_session.Send(new RequestDetail { Kind = DetailKind.Fleet, Target = 0 });
|
||||
}
|
||||
|
||||
private void Result(CommandResultMessage r)
|
||||
{
|
||||
_status.Text = r.Message;
|
||||
// un rinnovo prenotato o completato cambia il quadro della flotta
|
||||
RequestFleet(Fmt.Today(_session.World));
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
@@ -160,6 +184,7 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
|
||||
BuildCard();
|
||||
BuildWorkshop();
|
||||
BuildFleet();
|
||||
}
|
||||
|
||||
private string DueText(TrainInfo t)
|
||||
@@ -212,6 +237,12 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
{
|
||||
var def = w.Data.Vehicles.FirstOrDefault(d => d.Id == v.Type);
|
||||
_cardDetails.AddChild(UiTheme.Text($"{def?.NameIt ?? v.Type} #{v.Vehicle} · {v.OdometerKm / 1000:0.#} {T("mila km")} · {v.AgeYears:0.#} {T("anni")}", 13, bold: true));
|
||||
if (w.Fleet?.Vehicles.FirstOrDefault(f => f.Vehicle == v.Vehicle) is { } info)
|
||||
{
|
||||
var value = UiTheme.Text(VehicleOutlook(info), 12, info.Superseded ? Palette.Amber : Palette.TextSecondary);
|
||||
value.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
_cardDetails.AddChild(value);
|
||||
}
|
||||
foreach (var c in v.Components)
|
||||
{
|
||||
var row = PanelKit.Row(6);
|
||||
@@ -261,6 +292,82 @@ public partial class MaintenancePanel : VBoxContainer
|
||||
actions.AddChild(b);
|
||||
}
|
||||
_cardControls.AddChild(actions);
|
||||
// rinnovo: l'intervento con effetto «renew» dei dati, vende i veicoli superati e compra i successori
|
||||
if (w.Data.Maintenance.Interventions.FirstOrDefault(i => i.Effect == InterventionEffect.Renew) is { } renewal)
|
||||
{
|
||||
var renew = new Button { Text = renewal.NameIt };
|
||||
renew.Pressed += () => _session.Command(new ScheduleServiceCommand(new TrainId(_train), renewal.Id), Result);
|
||||
_cardControls.AddChild(renew);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ rinnovo della flotta
|
||||
|
||||
/// <summary>Riga di obsolescenza di un veicolo: superato, successore con prestazioni e prezzo, valori, costo di manutenzione.</summary>
|
||||
private string VehicleOutlook(FleetVehicleInfo v)
|
||||
{
|
||||
var parts = new List<string>();
|
||||
if (v.Superseded)
|
||||
{
|
||||
parts.Add(string.Format(T("superato dal {0}"), v.SupersededYear));
|
||||
var next = _session.World.Data.Vehicles.FirstOrDefault(d => d.Id == v.Successor);
|
||||
if (next is not null)
|
||||
parts.Add(string.Format(T("successore {0} ({1} kW, {2} km/h, {3})"), next.NameIt, next.PowerKw, next.MaxSpeedKmh, new Money(next.Price)));
|
||||
}
|
||||
if (!v.InProduction) parts.Add(T("fuori produzione"));
|
||||
parts.Add(string.Format(T("valore {0}"), v.BookValue));
|
||||
parts.Add(string.Format(T("rivendita {0}"), v.Resale));
|
||||
if (v.MaintenanceFactor > 1.001f) parts.Add(string.Format(T("manutenzione ×{0:0.##}"), v.MaintenanceFactor));
|
||||
return string.Join(" · ", parts);
|
||||
}
|
||||
|
||||
private void BuildFleet()
|
||||
{
|
||||
foreach (var c in _fleet.GetChildren()) c.QueueFree();
|
||||
var w = _session.World;
|
||||
var report = w.Fleet;
|
||||
if (report is null)
|
||||
{
|
||||
_fleet.AddChild(UiTheme.Text(T("Quadro della flotta in arrivo dal server…"), 13, Palette.TextSecondary));
|
||||
return;
|
||||
}
|
||||
_fleet.AddChild(PanelKit.Pair(T("Era"), PanelKit.Value(report.Era)));
|
||||
if (report.NextEra.Length > 0)
|
||||
_fleet.AddChild(PanelKit.Pair(T("Prossima era"), PanelKit.Value($"{report.NextEra} · {report.NextEraYear}")));
|
||||
_fleet.AddChild(PanelKit.Pair(T("Valore della flotta"), PanelKit.Value(report.BookValueTotal.ToString())));
|
||||
var superseded = report.Vehicles.Where(v => v.Superseded).ToList();
|
||||
if (superseded.Count == 0)
|
||||
{
|
||||
_fleet.AddChild(UiTheme.Text(T("Nessun veicolo superato"), 13, Palette.TextSecondary));
|
||||
return;
|
||||
}
|
||||
foreach (var v in superseded.Take(8))
|
||||
{
|
||||
var def = w.Data.Vehicles.FirstOrDefault(d => d.Id == v.Type);
|
||||
string where = v.Train >= 0 && w.Trains.TryGetValue(v.Train, out var t) ? t.Name
|
||||
: v.Depot >= 0 && w.Depots.TryGetValue(v.Depot, out var d) ? d.Name : "";
|
||||
_fleet.AddChild(UiTheme.Text($"{def?.NameIt ?? v.Type} #{v.Vehicle} · {where} · {v.AgeYears:0.#}/{v.LifeYears} {T("anni")}", 13, bold: true));
|
||||
var line = UiTheme.Text(VehicleOutlook(v), 12, Palette.Amber);
|
||||
line.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
_fleet.AddChild(line);
|
||||
}
|
||||
if (superseded.Count > 8)
|
||||
_fleet.AddChild(UiTheme.Text(string.Format(T("e altri {0} veicoli superati"), superseded.Count - 8), 12, Palette.TextSecondary));
|
||||
foreach (var r in report.Trains)
|
||||
{
|
||||
string name = w.Trains.TryGetValue(r.Train, out var t) ? t.Name : $"#{r.Train}";
|
||||
var row = PanelKit.Row(6);
|
||||
var text = UiTheme.Text(string.Format(T("{0}: {1} veicoli da rinnovare, spesa netta {2}"), name, r.Vehicles, r.NetCost), 13,
|
||||
r.Affordable ? Palette.Text : Palette.Danger);
|
||||
text.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
text.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
row.AddChild(text);
|
||||
int train = r.Train;
|
||||
var button = new Button { Text = T("Rinnova") };
|
||||
button.Pressed += () => _session.Command(new ScheduleServiceCommand(new TrainId(train), report.RenewalIntervention), Result);
|
||||
row.AddChild(button);
|
||||
_fleet.AddChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ registro officina
|
||||
|
||||
Reference in new issue
Block a user