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>
265 lines
7.5 KiB
C#
265 lines
7.5 KiB
C#
using RailEnterprise.Core.Commands;
|
|
|
|
namespace RailEnterprise.Protocol.Messages;
|
|
|
|
/// <summary>Apertura della sessione: versione, token, sessione da riprendere (0 = nuova) e hash dei dati del client.</summary>
|
|
public sealed class Hello : IMessage
|
|
{
|
|
public MessageId Id => MessageId.Hello;
|
|
public ushort ProtocolVersion { get; init; } = Frame.ProtocolVersion;
|
|
public string ClientVersion { get; init; } = "";
|
|
public string Token { get; init; } = "";
|
|
public ulong ResumeSessionId { get; init; }
|
|
/// <summary>Hash dei dati del client (0 = non verificare).</summary>
|
|
public ulong DataHash { get; init; }
|
|
|
|
public void Write(ref SpanWriter w)
|
|
{
|
|
w.U16(ProtocolVersion);
|
|
w.String(ClientVersion);
|
|
w.String(Token);
|
|
w.U64(ResumeSessionId);
|
|
w.U64(DataHash);
|
|
w.Flags(0);
|
|
}
|
|
|
|
public static Hello Read(ref SpanReader r)
|
|
{
|
|
var m = new Hello { ProtocolVersion = r.U16(), ClientVersion = r.String(), Token = r.String(), ResumeSessionId = r.U64(), DataHash = r.U64() };
|
|
r.Flags();
|
|
return m;
|
|
}
|
|
}
|
|
|
|
public sealed class Ping : IMessage
|
|
{
|
|
public MessageId Id => MessageId.Ping;
|
|
public ulong Nonce { get; init; }
|
|
|
|
public void Write(ref SpanWriter w)
|
|
{
|
|
w.U64(Nonce);
|
|
w.Flags(0);
|
|
}
|
|
|
|
public static Ping Read(ref SpanReader r)
|
|
{
|
|
var m = new Ping { Nonce = r.U64() };
|
|
r.Flags();
|
|
return m;
|
|
}
|
|
}
|
|
|
|
/// <summary>Area di interesse in celle (estremi inclusi) e livello di dettaglio (0 pieno, 1 medio, 2 lontano).</summary>
|
|
public sealed class Subscribe : IMessage
|
|
{
|
|
public MessageId Id => MessageId.Subscribe;
|
|
public int X0 { get; init; }
|
|
public int Y0 { get; init; }
|
|
public int X1 { get; init; }
|
|
public int Y1 { get; init; }
|
|
public byte Lod { get; init; }
|
|
|
|
public void Write(ref SpanWriter w)
|
|
{
|
|
w.I32(X0);
|
|
w.I32(Y0);
|
|
w.I32(X1);
|
|
w.I32(Y1);
|
|
w.U8(Lod);
|
|
w.Flags(0);
|
|
}
|
|
|
|
public static Subscribe Read(ref SpanReader r)
|
|
{
|
|
var m = new Subscribe { X0 = r.I32(), Y0 = r.I32(), X1 = r.I32(), Y1 = r.I32(), Lod = r.U8() };
|
|
r.Flags();
|
|
return m;
|
|
}
|
|
}
|
|
|
|
/// <summary>Comando di gioco con il numero di sequenza del client; il payload segue <see cref="CommandCodec"/>.</summary>
|
|
public sealed class CommandMessage : IMessage
|
|
{
|
|
public MessageId Id => MessageId.Command;
|
|
public uint Seq { get; init; }
|
|
public required GameCommand Command { get; init; }
|
|
|
|
public void Write(ref SpanWriter w)
|
|
{
|
|
w.U32(Seq);
|
|
w.U16((ushort)Command.Type);
|
|
// payload con lunghezza: un lettore vecchio può saltarlo anche se il comando cresce
|
|
var inner = new SpanWriter(64);
|
|
CommandCodec.Write(ref inner, Command);
|
|
w.Bytes(inner.Written);
|
|
w.Flags(0);
|
|
}
|
|
|
|
public static CommandMessage Read(ref SpanReader r)
|
|
{
|
|
uint seq = r.U32();
|
|
var type = (CommandType)r.U16();
|
|
byte[] payload = r.Bytes();
|
|
var inner = new SpanReader(payload);
|
|
var command = CommandCodec.Read(type, ref inner) with { Seq = seq };
|
|
r.Flags();
|
|
return new CommandMessage { Seq = seq, Command = command };
|
|
}
|
|
}
|
|
|
|
/// <summary>Velocità della simulazione: 0 (pausa), 1, 2, 4, 8.</summary>
|
|
public sealed class SetSpeed : IMessage
|
|
{
|
|
public MessageId Id => MessageId.SetSpeed;
|
|
public byte Speed { get; init; }
|
|
|
|
public void Write(ref SpanWriter w)
|
|
{
|
|
w.U8(Speed);
|
|
w.Flags(0);
|
|
}
|
|
|
|
public static SetSpeed Read(ref SpanReader r)
|
|
{
|
|
var m = new SetSpeed { Speed = r.U8() };
|
|
r.Flags();
|
|
return m;
|
|
}
|
|
}
|
|
|
|
public sealed class ListSaves : IMessage
|
|
{
|
|
public MessageId Id => MessageId.ListSaves;
|
|
|
|
public void Write(ref SpanWriter w) => w.Flags(0);
|
|
|
|
public static ListSaves Read(ref SpanReader r)
|
|
{
|
|
r.Flags();
|
|
return new ListSaves();
|
|
}
|
|
}
|
|
|
|
public sealed class Save : IMessage
|
|
{
|
|
public MessageId Id => MessageId.Save;
|
|
public string Name { get; init; } = "";
|
|
|
|
public void Write(ref SpanWriter w)
|
|
{
|
|
w.String(Name);
|
|
w.Flags(0);
|
|
}
|
|
|
|
public static Save Read(ref SpanReader r)
|
|
{
|
|
var m = new Save { Name = r.String() };
|
|
r.Flags();
|
|
return m;
|
|
}
|
|
}
|
|
|
|
public sealed class Load : IMessage
|
|
{
|
|
public MessageId Id => MessageId.Load;
|
|
public string SaveId { get; init; } = "";
|
|
|
|
public void Write(ref SpanWriter w)
|
|
{
|
|
w.String(SaveId);
|
|
w.Flags(0);
|
|
}
|
|
|
|
public static Load Read(ref SpanReader r)
|
|
{
|
|
var m = new Load { SaveId = r.String() };
|
|
r.Flags();
|
|
return m;
|
|
}
|
|
}
|
|
|
|
/// <summary>Nuova partita: seme, lato della mappa (km), anno d'inizio (0 = predefinito), difficoltà, ritocchi e opzioni del gioco infinito.</summary>
|
|
public sealed class NewGame : IMessage
|
|
{
|
|
public MessageId Id => MessageId.NewGame;
|
|
public ulong Seed { get; init; }
|
|
public int SizeKm { get; init; }
|
|
public int StartYear { get; init; }
|
|
public string DifficultyPreset { get; init; } = "";
|
|
/// <summary>Ritocchi della difficoltà «Personalizzata»: nome del campo (camelCase) e valore.</summary>
|
|
public List<(string Key, double Value)> Overrides { get; init; } = [];
|
|
public uint EndlessFlags { get; init; }
|
|
|
|
public void Write(ref SpanWriter w)
|
|
{
|
|
w.U64(Seed);
|
|
w.I32(SizeKm);
|
|
w.I32(StartYear);
|
|
w.String(DifficultyPreset);
|
|
w.Count(Overrides.Count);
|
|
foreach (var (key, value) in Overrides)
|
|
{
|
|
w.String(key);
|
|
w.F64(value);
|
|
}
|
|
w.U32(EndlessFlags);
|
|
w.Flags(0);
|
|
}
|
|
|
|
public static NewGame Read(ref SpanReader r)
|
|
{
|
|
ulong seed = r.U64();
|
|
int size = r.I32();
|
|
int year = r.I32();
|
|
string preset = r.String();
|
|
int n = r.Count();
|
|
var overrides = new List<(string, double)>(n);
|
|
for (int i = 0; i < n; i++) overrides.Add((r.String(), r.F64()));
|
|
var m = new NewGame { Seed = seed, SizeKm = size, StartYear = year, DifficultyPreset = preset, Overrides = overrides, EndlessFlags = r.U32() };
|
|
r.Flags();
|
|
return m;
|
|
}
|
|
}
|
|
|
|
/// <summary>Dettaglio richiesto dal client (F4).</summary>
|
|
public enum DetailKind : byte
|
|
{
|
|
/// <summary>Cartella di manutenzione di un treno (risposta MaintenanceCard).</summary>
|
|
TrainCard = 1,
|
|
/// <summary>Registro officina di un deposito (risposta WorkshopRegister).</summary>
|
|
Workshop = 2,
|
|
/// <summary>Registro degli impieghi della compagnia (risposta EmploymentReport; Id ignorato).</summary>
|
|
Employment = 3,
|
|
/// <summary>Scheda di una compagnia (risposta CompanyCard, F5).</summary>
|
|
Company = 4,
|
|
/// <summary>Scheda del proprietario di un'industria (risposta IndustryCard, F5).</summary>
|
|
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>
|
|
public sealed class RequestDetail : IMessage
|
|
{
|
|
public MessageId Id => MessageId.RequestDetail;
|
|
public DetailKind Kind { get; init; }
|
|
public int Target { get; init; }
|
|
|
|
public void Write(ref SpanWriter w)
|
|
{
|
|
w.U8((byte)Kind);
|
|
w.I32(Target);
|
|
w.Flags(0);
|
|
}
|
|
|
|
public static RequestDetail Read(ref SpanReader r)
|
|
{
|
|
var m = new RequestDetail { Kind = (DetailKind)r.U8(), Target = r.I32() };
|
|
r.Flags();
|
|
return m;
|
|
}
|
|
}
|