F6: mercato globale, storico prezzi a 24 mesi e previsione

Prima parte della F6: il pannello «Mercato globale» dell'immagine di
riferimento 06, con i dati calcolati dal server.

- Lo storico dei prezzi globali passa da 360 a 720 giorni. I salvataggi
  con lo storico di un anno si migrano al caricamento allungando la
  finestra (RollingWindow.Extended), senza cambiare formato.
- MarketOutlook (Core) è un'analisi in sola lettura del mondo: storico
  mensile, variazione a 30 giorni, offerta e domanda con la quota
  mondiale, scorte in mesi, indice materie prime, previsione a 4 mesi
  dalla componente mondiale con banda, destinazioni di vendita ordinate
  per prezzo con la linea che le collega, hub, evento in corso e
  avanzamento verso la compravendita in proprio. Parametri nuovi in
  balance.json (market.outlook); interpretazioni nell'ADR 0015.
- Protocollo: DetailKind.Market (7) e MarketReport (129); il server
  risponde su richiesta, il client lo mostra in un pannello a tutto
  schermo e il pilota automatico ne fa la schermata 16_mercato.
- Test: finestra allungata e migrazione, storico mensile, previsione
  deterministica ed entro i limiti, evento, analisi su Valdoria,
  round-trip del messaggio e quadro via WebSocket.

La simulazione non cambia: l'analisi non scrive nel mondo e
l'accettazione F4 dà gli stessi numeri di prima.

Closes #29.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-07 14:25:38 +01:00
1 parent bfbdb6297e
commit 2992e7cc36
29 files changed
+1877 -50

No files matched your search

@@ -47,6 +47,9 @@ public sealed class ClientWorld(GameData data)
public Dictionary<int, IndustryCard> IndustryCards { get; } = [];
public Chronicle? Chronicle { get; private set; }
/// <summary>Quadro del mercato globale (F6), su richiesta.</summary>
public MarketReport? Market { get; private set; }
/// <summary>Contatore dei listini ricevuti (per aggiornare il pannello della borsa).</summary>
public int TapeVersion { get; private set; }
@@ -127,6 +130,10 @@ public sealed class ClientWorld(GameData data)
Chronicle = m;
DetailVersion++;
return true;
case MarketReport m:
Market = m;
DetailVersion++;
return true;
case MaintenanceAlert m:
Alerts.Insert(0, m);
if (Alerts.Count > AlertCapacity) Alerts.RemoveAt(Alerts.Count - 1);
@@ -146,6 +153,7 @@ public sealed class ClientWorld(GameData data)
CompanyCards.Clear();
IndustryCards.Clear();
Chronicle = null;
Market = null;
Alerts.Clear();
Summary = m.Summary;
SessionId = m.SessionId;
+2
View File
@@ -37,6 +37,8 @@ public enum MessageId : ushort
IndustryCard = 127,
/// <summary>Cronaca finale della partita del giocatore (F5).</summary>
Chronicle = 128,
/// <summary>Quadro del mercato globale: beni, storico a 24 mesi, previsione, hub (F6).</summary>
MarketReport = 129,
CommandResult = 130,
Notification = 131,
Newspaper = 132,
@@ -237,6 +237,8 @@ public enum DetailKind : byte
Industry = 5,
/// <summary>Cronaca finale (risposta Chronicle, F5; Id ignorato).</summary>
Chronicle = 6,
/// <summary>Quadro del mercato globale (risposta MarketReport, F6; Id ignorato).</summary>
Market = 7,
}
/// <summary>Chiede al server un dettaglio che non viaggia con le entità (aggiunto in F4).</summary>
@@ -0,0 +1,210 @@
using RailEnterprise.Core.Common;
namespace RailEnterprise.Protocol.Messages;
// Messaggi della fase F6: pannello «Mercato globale» (immagine di riferimento 06). Il quadro del
// mercato arriva su richiesta (RequestDetail con DetailKind.Market) ed è calcolato dal server con
// MarketOutlook (ADR 0015): il client lo mostra com'è, senza logica di gioco.
/// <summary>Prezzo globale di un giorno (centesimi per unità).</summary>
public sealed class PricePointInfo
{
public long Day { get; init; }
public double Price { get; init; }
public void Write(ref SpanWriter w)
{
w.I64(Day); w.F64(Price);
w.Flags(0);
}
public static PricePointInfo Read(ref SpanReader r)
{
var m = new PricePointInfo { Day = r.I64(), Price = r.F64() };
r.Flags();
return m;
}
}
/// <summary>Prezzo previsto a una distanza in mesi, con la banda bassa e alta (centesimi).</summary>
public sealed class ForecastInfo
{
public byte Months { get; init; }
public double Price { get; init; }
public double Low { get; init; }
public double High { get; init; }
public void Write(ref SpanWriter w)
{
w.U8(Months); w.F64(Price); w.F64(Low); w.F64(High);
w.Flags(0);
}
public static ForecastInfo Read(ref SpanReader r)
{
var m = new ForecastInfo { Months = r.U8(), Price = r.F64(), Low = r.F64(), High = r.F64() };
r.Flags();
return m;
}
}
/// <summary>Destinazione di vendita: Kind 0 industria, 1 hub; Line −1 se la compagnia non la collega.</summary>
public sealed class SellPlaceInfo
{
public const byte Industry = 0;
public const byte Hub = 1;
public byte Kind { get; init; }
public int Target { get; init; }
public double Price { get; init; }
public int Line { get; init; } = -1;
public void Write(ref SpanWriter w)
{
w.U8(Kind); w.I32(Target); w.F64(Price); w.I32(Line);
w.Flags(0);
}
public static SellPlaceInfo Read(ref SpanReader r)
{
var m = new SellPlaceInfo { Kind = r.U8(), Target = r.I32(), Price = r.F64(), Line = r.I32() };
r.Flags();
return m;
}
}
/// <summary>Quadro di un bene: prezzo, variazione, offerta e domanda, scorte, storico, previsione, vendite.</summary>
public sealed class GoodMarketInfo
{
public int Good { get; init; }
public bool Available { get; init; }
public double Price { get; init; }
/// <summary>Variazione a 30 giorni (frazione).</summary>
public float Change { get; init; }
/// <summary>Offerta e domanda della mappa in un mese (unità).</summary>
public double SupplyMonth { get; init; }
public double DemandMonth { get; init; }
/// <summary>Quota mondiale scambiata dagli hub in un mese (unità).</summary>
public double WorldSupplyMonth { get; init; }
public double WorldDemandMonth { get; init; }
public double StockUnits { get; init; }
/// <summary>Scorte in mesi di domanda della mappa (−1 senza domanda).</summary>
public float StockMonths { get; init; } = -1;
public List<PricePointInfo> History { get; init; } = [];
public List<ForecastInfo> Forecast { get; init; } = [];
public List<SellPlaceInfo> SellPlaces { get; init; } = [];
public void Write(ref SpanWriter w)
{
w.I32(Good); w.Bool(Available); w.F64(Price); w.F32(Change);
w.F64(SupplyMonth); w.F64(DemandMonth); w.F64(WorldSupplyMonth); w.F64(WorldDemandMonth); w.F64(StockUnits); w.F32(StockMonths);
w.Count(History.Count);
foreach (var p in History) p.Write(ref w);
w.Count(Forecast.Count);
foreach (var f in Forecast) f.Write(ref w);
w.Count(SellPlaces.Count);
foreach (var s in SellPlaces) s.Write(ref w);
w.Flags(0);
}
public static GoodMarketInfo Read(ref SpanReader r)
{
var m = new GoodMarketInfo
{
Good = r.I32(), Available = r.Bool(), Price = r.F64(), Change = r.F32(),
SupplyMonth = r.F64(), DemandMonth = r.F64(), WorldSupplyMonth = r.F64(), WorldDemandMonth = r.F64(), StockUnits = r.F64(), StockMonths = r.F32(),
};
for (int n = r.Count(), i = 0; i < n; i++) m.History.Add(PricePointInfo.Read(ref r));
for (int n = r.Count(), i = 0; i < n; i++) m.Forecast.Add(ForecastInfo.Read(ref r));
for (int n = r.Count(), i = 0; i < n; i++) m.SellPlaces.Add(SellPlaceInfo.Read(ref r));
r.Flags();
return m;
}
}
/// <summary>Hub verso il mercato mondiale: Kind 0 porto, 1 valico; Line −1 se la compagnia non lo collega.</summary>
public sealed class HubMarketInfo
{
public int Hub { get; init; }
public byte Kind { get; init; }
public int MonthlyCapacity { get; init; }
public float Duty { get; init; }
public int UsedThisMonth { get; init; }
public int Line { get; init; } = -1;
public void Write(ref SpanWriter w)
{
w.I32(Hub); w.U8(Kind); w.I32(MonthlyCapacity); w.F32(Duty); w.I32(UsedThisMonth); w.I32(Line);
w.Flags(0);
}
public static HubMarketInfo Read(ref SpanReader r)
{
var m = new HubMarketInfo { Hub = r.I32(), Kind = r.U8(), MonthlyCapacity = r.I32(), Duty = r.F32(), UsedThisMonth = r.I32(), Line = r.I32() };
r.Flags();
return m;
}
}
/// <summary>
/// Quadro del mercato globale per la compagnia della sessione (F6): indice materie prime, beni con
/// storico mensile e previsione, hub, evento in corso e avanzamento verso la compravendita in proprio.
/// </summary>
public sealed class MarketReport : IMessage
{
public MessageId Id => MessageId.MarketReport;
public long Day { get; init; }
/// <summary>Indice materie prime (100 = prezzi base) e variazione a 30 giorni (frazione).</summary>
public float Index { get; init; }
public float IndexChange { get; init; }
public List<GoodMarketInfo> Goods { get; init; } = [];
public List<HubMarketInfo> Hubs { get; init; } = [];
/// <summary>Evento in corso: bene (−1 nessuno), shock mondiale con segno (frazione del prezzo base), mesi stimati.</summary>
public int EventGood { get; init; } = -1;
public float EventShock { get; init; }
public float EventMonths { get; init; }
/// <summary>Compravendita in proprio: sbloccata, livello che la sblocca, avanzamento 0–1 e requisiti.</summary>
public bool TradingUnlocked { get; init; }
public byte TradingTier { get; init; }
public float TradingProgress { get; init; }
public Money NetWorth { get; init; }
public Money NetWorthRequired { get; init; }
public int TownsConnected { get; init; }
public int TownsRequired { get; init; }
public int TownPopulation { get; init; }
public string Rating { get; init; } = "";
public string RatingRequired { get; init; } = "";
public bool RatingMet { get; init; }
public void Write(ref SpanWriter w)
{
w.I64(Day); w.F32(Index); w.F32(IndexChange);
w.Count(Goods.Count);
foreach (var g in Goods) g.Write(ref w);
w.Count(Hubs.Count);
foreach (var h in Hubs) h.Write(ref w);
w.I32(EventGood); w.F32(EventShock); w.F32(EventMonths);
w.Bool(TradingUnlocked); w.U8(TradingTier); w.F32(TradingProgress); w.Money(NetWorth); w.Money(NetWorthRequired);
w.I32(TownsConnected); w.I32(TownsRequired); w.I32(TownPopulation); w.String(Rating); w.String(RatingRequired); w.Bool(RatingMet);
w.Flags(0);
}
public static MarketReport Read(ref SpanReader r)
{
long day = r.I64();
float index = r.F32(), change = r.F32();
var goods = new List<GoodMarketInfo>();
for (int n = r.Count(), i = 0; i < n; i++) goods.Add(GoodMarketInfo.Read(ref r));
var hubs = new List<HubMarketInfo>();
for (int n = r.Count(), i = 0; i < n; i++) hubs.Add(HubMarketInfo.Read(ref r));
var m = new MarketReport
{
Day = day, Index = index, IndexChange = change, Goods = goods, Hubs = hubs,
EventGood = r.I32(), EventShock = r.F32(), EventMonths = r.F32(),
TradingUnlocked = r.Bool(), TradingTier = r.U8(), TradingProgress = r.F32(), NetWorth = r.Money(), NetWorthRequired = r.Money(),
TownsConnected = r.I32(), TownsRequired = r.I32(), TownPopulation = r.I32(), Rating = r.String(), RatingRequired = r.String(), RatingMet = r.Bool(),
};
r.Flags();
return m;
}
}
@@ -31,6 +31,7 @@ public static class MessageCodec
MessageId.CompanyCard => CompanyCard.Read(ref r),
MessageId.IndustryCard => IndustryCard.Read(ref r),
MessageId.Chronicle => Chronicle.Read(ref r),
MessageId.MarketReport => MarketReport.Read(ref r),
MessageId.MarketTape => MarketTape.Read(ref r),
MessageId.CommandResult => CommandResultMessage.Read(ref r),
MessageId.Notification => Notification.Read(ref r),