F6: scheda industria e schermata di connessione definitive

La scheda dell'industria e la schermata di connessione si allineano alle
immagini di riferimento 07 e 09. I dati che mancavano li calcola il Core
con una funzione pura, e viaggiano in blocchi compatibili del protocollo.
Il formato dei salvataggi non cambia (ADR 0021).

- IndustryOutlook calcola la scheda in sola lettura:
  - fattori dell'efficienza e quello che la limita;
  - ingressi e uscite al mese, con giorni di scorta o di magazzino;
  - fornitori e clienti con prezzo, distanza e linea che li collega;
  - forza lavoro dai contratti dei pendolari;
  - punteggio di crescita del trimestre con le soglie;
  - prezzo medio, utile annuo, stazioni che la servono, sblocco
    dell'acquisto.
  IndustryMath.GrowthScore è ora l'unica formula del punteggio e la usa
  anche IndustrySystem: gli hash non cambiano. Nuovi parametri in
  balance.json, industry.outlook.
- Protocollo:
  - IndustryCard: blocco 1 IndustrySheetInfo;
  - Welcome: blocco 1 ServerInfo (versione, sistema, Docker, tempo di
    attività, passo del ciclo, client collegati);
  - ClientWorld conserva lo stato del server e l'elenco dei salvataggi.
- Client:
  - IndustryPanel a tutto schermo, con tre schede, il grafo della
    catena, impianti e crescita, e i comandi del proprietario;
  - ConnectScreen sostituisce MenuScreen: server locale o in rete,
    stato del server, partite salvate, «Connetti e riprendi» e «Nuova
    partita sul server» su una sessione di prova;
  - testi in strings.csv;
  - pilota automatico: schermate 19_scheda_industria e 20_connessione.
- Test:
  - IndustryOutlookTests;
  - scheda e stato del server via WebSocket;
  - campioni del protocollo con i blocchi nuovi.
  200 test, 181 senza i lenti.

Refs #42.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-08 14:04:28 +01:00
1 parent 7eec322202
commit 45462bf9ec
28 files changed
+2810 -329

No files matched your search

@@ -56,6 +56,12 @@ public sealed class ClientWorld(GameData data)
/// <summary>Quadro delle finanze (F6), su richiesta: lo usa il pannello «Finanze».</summary>
public FinanceReport? Finance { get; private set; }
/// <summary>Stato del server dall'ultimo Welcome (F6, ADR 0021): versione, sistema, attività, tick, sessioni.</summary>
public ServerInfo? Server { get; private set; }
/// <summary>Ultimo elenco dei salvataggi del server (risposta a ListSaves e a Save); resta valido anche dopo un nuovo Welcome.</summary>
public SaveList? Saves { get; private set; }
/// <summary>Contatore dei listini ricevuti (per aggiornare il pannello della borsa).</summary>
public int TapeVersion { get; private set; }
@@ -148,6 +154,10 @@ public sealed class ClientWorld(GameData data)
Finance = m;
DetailVersion++;
return true;
case SaveList m:
Saves = m;
DetailVersion++;
return true;
case MaintenanceAlert m:
Alerts.Insert(0, m);
if (Alerts.Count > AlertCapacity) Alerts.RemoveAt(Alerts.Count - 1);
@@ -172,6 +182,7 @@ public sealed class ClientWorld(GameData data)
Finance = null;
Alerts.Clear();
Summary = m.Summary;
Server = m.Server;
SessionId = m.SessionId;
Tick = m.Summary.Tick;
Speed = m.Summary.Speed;
@@ -161,6 +161,8 @@ public sealed class IndustryCard : IMessage
public Money Cash { get; init; }
public float BreakdownChancePerYear { get; init; }
public List<IndustryStopInfo> Stops { get; init; } = [];
/// <summary>Blocco 1 (F6, ADR 0021): scheda dell'immagine 07 per la compagnia della sessione; null se assente.</summary>
public IndustrySheetInfo? Sheet { get; init; }
public void Write(ref SpanWriter w)
{
@@ -169,7 +171,8 @@ public sealed class IndustryCard : IMessage
w.I32(MachineryRequired); w.Money(UpgradeCost); w.Money(Valuation); w.Money(Cash); w.F32(BreakdownChancePerYear);
w.Count(Stops.Count);
foreach (var s in Stops) s.Write(ref w);
w.Flags(0);
w.Flags((byte)(Sheet is not null ? 1 : 0));
Sheet?.Write(ref w);
}
public static IndustryCard Read(ref SpanReader r)
@@ -181,9 +184,18 @@ public sealed class IndustryCard : IMessage
MachineryRequired = r.I32(), UpgradeCost = r.Money(), Valuation = r.Money(), Cash = r.Money(), BreakdownChancePerYear = r.F32(),
};
for (int n = r.Count(), i = 0; i < n; i++) m.Stops.Add(IndustryStopInfo.Read(ref r));
r.Flags();
byte flags = r.Flags();
if ((flags & 1) != 0) m = m.With(IndustrySheetInfo.Read(ref r));
return m;
}
private IndustryCard With(IndustrySheetInfo sheet) => new()
{
Industry = Industry, Margin = Margin, ConditionMultiplier = ConditionMultiplier, WearPerDay = WearPerDay, RecoveryPerDay = RecoveryPerDay,
MaintenanceCostPerDay = MaintenanceCostPerDay, MaintenanceSpentYear = MaintenanceSpentYear, PartsTarget = PartsTarget, PartsPerMonth = PartsPerMonth,
PartsOrdered = PartsOrdered, MachineryRequired = MachineryRequired, UpgradeCost = UpgradeCost, Valuation = Valuation, Cash = Cash,
BreakdownChancePerYear = BreakdownChancePerYear, Stops = Stops, Sheet = sheet,
};
}
/// <summary>Primato della Cronaca finale (descrizione e valore già formattati in italiano).</summary>
@@ -0,0 +1,269 @@
using RailEnterprise.Core.Common;
namespace RailEnterprise.Protocol.Messages;
// Blocchi della fase F6 (ADR 0021): scheda dell'industria dell'immagine di riferimento 07 (blocco 1 di
// IndustryCard, calcolato dal server con IndustryOutlook) e stato del server per la schermata di
// connessione dell'immagine 09 (blocco 1 di Welcome). Il client li mostra come arrivano.
/// <summary>
/// Fornitore o cliente nella catena produttiva. Kind: 0 industria, 1 hub, 2 città (ChainPartnerKind);
/// unità al mese, prezzo in centesimi per unità, linea della compagnia che collega (−1 nessuna), km in linea d'aria.
/// </summary>
public sealed class ChainPartnerInfo
{
public byte Kind { get; init; }
public int Target { get; init; }
public float MonthlyUnits { get; init; }
public double Price { get; init; }
public int Line { get; init; } = -1;
public float DistanceKm { get; init; }
public void Write(ref SpanWriter w)
{
w.U8(Kind); w.I32(Target); w.F32(MonthlyUnits); w.F64(Price); w.I32(Line); w.F32(DistanceKm);
w.Flags(0);
}
public static ChainPartnerInfo Read(ref SpanReader r)
{
var m = new ChainPartnerInfo { Kind = r.U8(), Target = r.I32(), MonthlyUnits = r.F32(), Price = r.F64(), Line = r.I32(), DistanceKm = r.F32() };
r.Flags();
return m;
}
}
/// <summary>
/// Input o output dell'industria: al mese a piena efficienza (fabbisogno o capacità) e al ritmo attuale,
/// scorta, capienza, giorni (di scorta per un input, prima del magazzino pieno per un output; −1 senza
/// ritmo), input limitante, fornitori o clienti.
/// </summary>
public sealed class IndustryFlowInfo
{
public int Good { get; init; }
public float FullMonth { get; init; }
public float CurrentMonth { get; init; }
public int Stock { get; init; }
public int Storage { get; init; }
public float Days { get; init; } = -1;
public bool Limiting { get; init; }
public List<ChainPartnerInfo> Partners { get; init; } = [];
public void Write(ref SpanWriter w)
{
w.I32(Good); w.F32(FullMonth); w.F32(CurrentMonth); w.I32(Stock); w.I32(Storage); w.F32(Days); w.Bool(Limiting);
w.Count(Partners.Count);
foreach (var p in Partners) p.Write(ref w);
w.Flags(0);
}
public static IndustryFlowInfo Read(ref SpanReader r)
{
var m = new IndustryFlowInfo { Good = r.I32(), FullMonth = r.F32(), CurrentMonth = r.F32(), Stock = r.I32(), Storage = r.I32(), Days = r.F32(), Limiting = r.Bool() };
for (int n = r.Count(), i = 0; i < n; i++) m.Partners.Add(ChainPartnerInfo.Read(ref r));
r.Flags();
return m;
}
}
/// <summary>Provenienza dei lavoratori o del personale: città, persone, copertura, linea del primo tratto (−1 a piedi), vettore, minuti.</summary>
public sealed class WorkforceSourceInfo
{
public int Town { get; init; }
public int Headcount { get; init; }
public float Coverage { get; init; }
public int Line { get; init; } = -1;
public int Carrier { get; init; } = -1;
public float Minutes { get; init; }
public bool Walking { get; init; }
public void Write(ref SpanWriter w)
{
w.I32(Town); w.I32(Headcount); w.F32(Coverage); w.I32(Line); w.I32(Carrier); w.F32(Minutes); w.Bool(Walking);
w.Flags(0);
}
public static WorkforceSourceInfo Read(ref SpanReader r)
{
var m = new WorkforceSourceInfo { Town = r.I32(), Headcount = r.I32(), Coverage = r.F32(), Line = r.I32(), Carrier = r.I32(), Minutes = r.F32(), Walking = r.Bool() };
r.Flags();
return m;
}
}
/// <summary>
/// Lavoratori o personale: posti, presenti, quota in sede, copertura media, posti scoperti, motivo
/// (UncoveredReason) e linea del motivo, viaggio medio in treno (−1 senza), provenienze elencate e in tutto.
/// </summary>
public sealed class WorkforceInfo
{
public int Jobs { get; init; }
public float Present { get; init; }
public float OnSite { get; init; }
public float Coverage { get; init; }
public int Missing { get; init; }
public byte Reason { get; init; }
public int ReasonLine { get; init; } = -1;
public float AverageMinutes { get; init; } = -1;
public int SourceCount { get; init; }
public List<WorkforceSourceInfo> Sources { get; init; } = [];
public void Write(ref SpanWriter w)
{
w.I32(Jobs); w.F32(Present); w.F32(OnSite); w.F32(Coverage); w.I32(Missing); w.U8(Reason); w.I32(ReasonLine); w.F32(AverageMinutes); w.I32(SourceCount);
w.Count(Sources.Count);
foreach (var s in Sources) s.Write(ref w);
w.Flags(0);
}
public static WorkforceInfo Read(ref SpanReader r)
{
var m = new WorkforceInfo
{
Jobs = r.I32(), Present = r.F32(), OnSite = r.F32(), Coverage = r.F32(), Missing = r.I32(), Reason = r.U8(), ReasonLine = r.I32(),
AverageMinutes = r.F32(), SourceCount = r.I32(),
};
for (int n = r.Count(), i = 0; i < n; i++) m.Sources.Add(WorkforceSourceInfo.Read(ref r));
r.Flags();
return m;
}
}
/// <summary>
/// Blocco 1 di IndustryCard (F6, ADR 0021): scheda dell'immagine 07 calcolata da IndustryOutlook per la
/// compagnia della sessione. Limit come IndustryLimit del Core (0 nessuno, 1 input, 2 lavoratori,
/// 3 personale, 4 profitto, 5 impianti, 6 giacimento, 7 evento, 8 fermo, 9 dormiente).
/// </summary>
public sealed class IndustrySheetInfo
{
public byte Level { get; init; }
public byte MaxLevel { get; init; }
public float Efficiency { get; init; }
public byte Limit { get; init; }
public float CovInput { get; init; }
public float CovWorkers { get; init; }
public float CovStaff { get; init; }
public int CoverageWindowDays { get; init; }
public float ProfitFactor { get; init; }
public float Depletion { get; init; }
public float EventCapacity { get; init; }
/// <summary>Riserva residua del giacimento (0–1), −1 se non esauribile.</summary>
public float ReserveFraction { get; init; } = -1;
public int StorageDays { get; init; }
public List<IndustryFlowInfo> Inputs { get; init; } = [];
public List<IndustryFlowInfo> Outputs { get; init; } = [];
public WorkforceInfo Workers { get; init; } = new();
public WorkforceInfo Staff { get; init; } = new();
/// <summary>Ricavo medio per unità del prodotto (centesimi), −1 se non stimabile.</summary>
public double AveragePrice { get; init; } = -1;
public Money AnnualProfit { get; init; }
/// <summary>Crescita trimestrale: ultimo punteggio, componenti e punteggio del trimestre in corso, soglie, trimestri.</summary>
public float LastScore { get; init; }
public float Shipped { get; init; }
public float Coverage { get; init; }
public float Profit { get; init; }
public float Score { get; init; }
public float UpgradeThreshold { get; init; }
public float DowngradeThreshold { get; init; }
public byte UpgradeQuarters { get; init; }
public byte QuartersAbove { get; init; }
public int QuarterDay { get; init; }
public int QuarterDays { get; init; }
public bool Served { get; init; }
/// <summary>Stazioni (di qualunque compagnia) che servono l'industria; linea della compagnia della sessione (−1 nessuna).</summary>
public List<int> ServingStations { get; init; } = [];
public int ServingLine { get; init; } = -1;
/// <summary>Acquisto: dei privati e attiva, sbloccato dal livello, livello che lo sblocca e avanzamento verso di esso.</summary>
public bool ForSale { get; init; }
public bool BuyUnlocked { get; init; }
public byte BuyTier { get; init; }
public float BuyProgress { get; init; }
public void Write(ref SpanWriter w)
{
w.U8(Level); w.U8(MaxLevel); w.F32(Efficiency); w.U8(Limit); w.F32(CovInput); w.F32(CovWorkers); w.F32(CovStaff); w.I32(CoverageWindowDays);
w.F32(ProfitFactor); w.F32(Depletion); w.F32(EventCapacity); w.F32(ReserveFraction); w.I32(StorageDays);
w.Count(Inputs.Count);
foreach (var f in Inputs) f.Write(ref w);
w.Count(Outputs.Count);
foreach (var f in Outputs) f.Write(ref w);
Workers.Write(ref w);
Staff.Write(ref w);
w.F64(AveragePrice); w.Money(AnnualProfit);
w.F32(LastScore); w.F32(Shipped); w.F32(Coverage); w.F32(Profit); w.F32(Score); w.F32(UpgradeThreshold); w.F32(DowngradeThreshold);
w.U8(UpgradeQuarters); w.U8(QuartersAbove); w.I32(QuarterDay); w.I32(QuarterDays); w.Bool(Served);
w.Count(ServingStations.Count);
foreach (int s in ServingStations) w.I32(s);
w.I32(ServingLine); w.Bool(ForSale); w.Bool(BuyUnlocked); w.U8(BuyTier); w.F32(BuyProgress);
w.Flags(0);
}
public static IndustrySheetInfo Read(ref SpanReader r)
{
byte level = r.U8(), maxLevel = r.U8();
float efficiency = r.F32();
byte limit = r.U8();
float covInput = r.F32(), covWorkers = r.F32(), covStaff = r.F32();
int window = r.I32();
float pf = r.F32(), depletion = r.F32(), eventCapacity = r.F32(), reserve = r.F32();
int storageDays = r.I32();
var inputs = new List<IndustryFlowInfo>();
for (int n = r.Count(), i = 0; i < n; i++) inputs.Add(IndustryFlowInfo.Read(ref r));
var outputs = new List<IndustryFlowInfo>();
for (int n = r.Count(), i = 0; i < n; i++) outputs.Add(IndustryFlowInfo.Read(ref r));
var workers = WorkforceInfo.Read(ref r);
var staff = WorkforceInfo.Read(ref r);
double averagePrice = r.F64();
var profit = r.Money();
float last = r.F32(), shipped = r.F32(), coverage = r.F32(), profitShare = r.F32(), score = r.F32(), up = r.F32(), down = r.F32();
byte upQuarters = r.U8(), above = r.U8();
int quarterDay = r.I32(), quarterDays = r.I32();
bool served = r.Bool();
var stations = new List<int>();
for (int n = r.Count(), i = 0; i < n; i++) stations.Add(r.I32());
var m = new IndustrySheetInfo
{
Level = level, MaxLevel = maxLevel, Efficiency = efficiency, Limit = limit, CovInput = covInput, CovWorkers = covWorkers, CovStaff = covStaff,
CoverageWindowDays = window, ProfitFactor = pf, Depletion = depletion, EventCapacity = eventCapacity, ReserveFraction = reserve, StorageDays = storageDays,
Inputs = inputs, Outputs = outputs, Workers = workers, Staff = staff, AveragePrice = averagePrice, AnnualProfit = profit,
LastScore = last, Shipped = shipped, Coverage = coverage, Profit = profitShare, Score = score, UpgradeThreshold = up, DowngradeThreshold = down,
UpgradeQuarters = upQuarters, QuartersAbove = above, QuarterDay = quarterDay, QuarterDays = quarterDays, Served = served, ServingStations = stations,
ServingLine = r.I32(), ForSale = r.Bool(), BuyUnlocked = r.Bool(), BuyTier = r.U8(), BuyProgress = r.F32(),
};
r.Flags();
return m;
}
}
/// <summary>
/// Blocco 1 di Welcome (F6, ADR 0021): stato del server per la schermata di connessione (immagine 09):
/// versione del gioco, sistema operativo, container, secondi di attività, durata del tick (ms), sessioni
/// collegate e massime, server locale (figlio del client).
/// </summary>
public sealed class ServerInfo
{
public string Version { get; init; } = "";
public string Os { get; init; } = "";
public bool Container { get; init; }
public long UptimeSeconds { get; init; }
public float TickMs { get; init; }
public int Sessions { get; init; }
public int MaxSessions { get; init; }
public bool Local { get; init; }
public void Write(ref SpanWriter w)
{
w.String(Version); w.String(Os); w.Bool(Container); w.I64(UptimeSeconds); w.F32(TickMs); w.I32(Sessions); w.I32(MaxSessions); w.Bool(Local);
w.Flags(0);
}
public static ServerInfo Read(ref SpanReader r)
{
var m = new ServerInfo
{
Version = r.String(), Os = r.String(), Container = r.Bool(), UptimeSeconds = r.I64(), TickMs = r.F32(), Sessions = r.I32(), MaxSessions = r.I32(), Local = r.Bool(),
};
r.Flags();
return m;
}
}
@@ -13,6 +13,8 @@ public sealed class Welcome : IMessage
public required WorldSummary Summary { get; init; }
public ulong DataHash { get; init; }
public string Difficulty { get; init; } = "";
/// <summary>Blocco 1 (F6, ADR 0021): stato del server per la schermata di connessione; null se assente.</summary>
public ServerInfo? Server { get; init; }
public void Write(ref SpanWriter w)
{
@@ -20,14 +22,19 @@ public sealed class Welcome : IMessage
Summary.Write(ref w);
w.U64(DataHash);
w.String(Difficulty);
w.Flags(0);
w.Flags((byte)(Server is not null ? 1 : 0));
Server?.Write(ref w);
}
public static Welcome Read(ref SpanReader r)
{
var m = new Welcome { SessionId = r.U64(), Summary = WorldSummary.Read(ref r), DataHash = r.U64(), Difficulty = r.String() };
r.Flags();
return m;
ulong session = r.U64();
var summary = WorldSummary.Read(ref r);
ulong hash = r.U64();
string difficulty = r.String();
byte flags = r.Flags();
var server = (flags & 1) != 0 ? ServerInfo.Read(ref r) : null;
return new Welcome { SessionId = session, Summary = summary, DataHash = hash, Difficulty = difficulty, Server = server };
}
}