F4: protocollo e client per manutenzione e impieghi, ADR 0010, stato dei lavori
- Protocollo: riepilogo di manutenzione nei record (blocco 1), RequestDetail, MaintenanceCard, WorkshopRegister, EmploymentReport con depositi, motivi e convenzioni, MaintenanceAlert. - Server: dettagli su richiesta, avvisi dalla manutenzione, registro dopo le convenzioni. - Client: pannelli Officine (cartella di manutenzione, Registro officina, scorta di ricambi, avvisi, mappa di calore) e Impieghi (Registro degli impieghi con convenzioni); schede di treno, industria e città aggiornate; pilota automatico con le nuove schermate. - ADR 0010, PROTOCOL, ARCHITECTURE e STATE aggiornati; 102 test verdi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
This commit is contained in:
28 files changed
+1618
-64
No files matched your search
@@ -35,6 +35,18 @@ public sealed class ClientWorld(GameData data)
|
||||
public HashSet<(int Cx, int Cy)> Chunks { get; } = [];
|
||||
|
||||
public DailyDigest? LastDigest { get; private set; }
|
||||
|
||||
/// <summary>Dettagli ricevuti su richiesta (F4): cartelle dei treni, registri delle officine, registro degli impieghi.</summary>
|
||||
public Dictionary<int, MaintenanceCard> Cards { get; } = [];
|
||||
public Dictionary<int, WorkshopRegister> Workshops { get; } = [];
|
||||
public EmploymentReport? Employment { get; private set; }
|
||||
|
||||
/// <summary>Ultimi avvisi di manutenzione, dal più recente.</summary>
|
||||
public List<MaintenanceAlert> Alerts { get; } = [];
|
||||
private const int AlertCapacity = 50;
|
||||
|
||||
/// <summary>Contatore dei dettagli ricevuti (per aggiornare i pannelli).</summary>
|
||||
public int DetailVersion { get; private set; }
|
||||
public long Tick { get; private set; }
|
||||
public byte Speed { get; private set; }
|
||||
|
||||
@@ -78,6 +90,23 @@ public sealed class ClientWorld(GameData data)
|
||||
case Pong m:
|
||||
Tick = Math.Max(Tick, (long)m.ServerTick);
|
||||
return true;
|
||||
case MaintenanceCard m:
|
||||
Cards[m.Train] = m;
|
||||
DetailVersion++;
|
||||
return true;
|
||||
case WorkshopRegister m:
|
||||
Workshops[m.Depot] = m;
|
||||
DetailVersion++;
|
||||
return true;
|
||||
case EmploymentReport m:
|
||||
Employment = m;
|
||||
DetailVersion++;
|
||||
return true;
|
||||
case MaintenanceAlert m:
|
||||
Alerts.Insert(0, m);
|
||||
if (Alerts.Count > AlertCapacity) Alerts.RemoveAt(Alerts.Count - 1);
|
||||
DetailVersion++;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -85,6 +114,10 @@ public sealed class ClientWorld(GameData data)
|
||||
|
||||
private void Reset(Welcome m)
|
||||
{
|
||||
Cards.Clear();
|
||||
Workshops.Clear();
|
||||
Employment = null;
|
||||
Alerts.Clear();
|
||||
Summary = m.Summary;
|
||||
SessionId = m.SessionId;
|
||||
Tick = m.Summary.Tick;
|
||||
|
||||
@@ -12,6 +12,8 @@ public enum MessageId : ushort
|
||||
Save = 7,
|
||||
Load = 8,
|
||||
NewGame = 9,
|
||||
/// <summary>Richiesta di un dettaglio (F4): cartella di manutenzione, registro officina, registro impieghi.</summary>
|
||||
RequestDetail = 10,
|
||||
|
||||
Welcome = 101,
|
||||
Reject = 102,
|
||||
@@ -25,6 +27,10 @@ public enum MessageId : ushort
|
||||
MaintenanceAlert = 121,
|
||||
EmploymentReport = 122,
|
||||
MarketTape = 123,
|
||||
/// <summary>Cartella di manutenzione di un treno (F4).</summary>
|
||||
MaintenanceCard = 124,
|
||||
/// <summary>Registro officina di un deposito (F4).</summary>
|
||||
WorkshopRegister = 125,
|
||||
CommandResult = 130,
|
||||
Notification = 131,
|
||||
Newspaper = 132,
|
||||
|
||||
@@ -221,3 +221,36 @@ public sealed class NewGame : IMessage
|
||||
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>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;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ public static class MessageCodec
|
||||
MessageId.Hello => Hello.Read(ref r),
|
||||
MessageId.Ping => Ping.Read(ref r),
|
||||
MessageId.Subscribe => Subscribe.Read(ref r),
|
||||
MessageId.RequestDetail => RequestDetail.Read(ref r),
|
||||
MessageId.Command => CommandMessage.Read(ref r),
|
||||
MessageId.SetSpeed => SetSpeed.Read(ref r),
|
||||
MessageId.ListSaves => ListSaves.Read(ref r),
|
||||
@@ -25,6 +26,8 @@ public static class MessageCodec
|
||||
MessageId.DailyDigest => DailyDigest.Read(ref r),
|
||||
MessageId.MaintenanceAlert => MaintenanceAlert.Read(ref r),
|
||||
MessageId.EmploymentReport => EmploymentReport.Read(ref r),
|
||||
MessageId.MaintenanceCard => MaintenanceCard.Read(ref r),
|
||||
MessageId.WorkshopRegister => WorkshopRegister.Read(ref r),
|
||||
MessageId.MarketTape => MarketTape.Read(ref r),
|
||||
MessageId.CommandResult => CommandResultMessage.Read(ref r),
|
||||
MessageId.Notification => Notification.Read(ref r),
|
||||
|
||||
@@ -68,11 +68,15 @@ public sealed class CompanyInfo : IWritable
|
||||
public byte Tier { get; init; }
|
||||
public bool Bankrupt { get; init; }
|
||||
|
||||
// blocco 1 (F4): politica di manutenzione della flotta
|
||||
public byte MaintenancePolicy { get; set; } = 1;
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Id); w.String(Name); w.String(Color); w.Bool(IsPlayer); w.Money(Cash); w.Money(NetWorth);
|
||||
w.String(Rating); w.U8(Tier); w.Bool(Bankrupt);
|
||||
w.Flags(0);
|
||||
w.Flags(1);
|
||||
w.U8(MaintenancePolicy);
|
||||
}
|
||||
|
||||
public static CompanyInfo Read(ref SpanReader r)
|
||||
@@ -82,7 +86,8 @@ public sealed class CompanyInfo : IWritable
|
||||
Id = r.I32(), Name = r.String(), Color = r.String(), IsPlayer = r.Bool(), Cash = r.Money(), NetWorth = r.Money(),
|
||||
Rating = r.String(), Tier = r.U8(), Bankrupt = r.Bool(),
|
||||
};
|
||||
r.Flags();
|
||||
byte flags = r.Flags();
|
||||
if ((flags & 1) != 0) m.MaintenancePolicy = r.U8();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -242,16 +247,33 @@ public sealed class DepotInfo : IWritable
|
||||
public Vec2 Position { get; init; }
|
||||
public string Size { get; init; } = "";
|
||||
|
||||
// blocco 1 (F4): officina
|
||||
public int Stalls { get; set; }
|
||||
public int JobsStaff { get; set; }
|
||||
/// <summary>Personale presente in percentuale (0–100).</summary>
|
||||
public byte StaffPercent { get; set; }
|
||||
public int SpareParts { get; set; }
|
||||
public int PartsTarget { get; set; }
|
||||
/// <summary>Lavori in officina (in coda e negli stalli).</summary>
|
||||
public int Jobs { get; set; }
|
||||
public bool WaitingParts { get; set; }
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Id); w.I32(Owner); w.String(Name); w.I32(Node); w.Vec2(Position); w.String(Size);
|
||||
w.Flags(0);
|
||||
w.Flags(1);
|
||||
w.I32(Stalls); w.I32(JobsStaff); w.U8(StaffPercent); w.I32(SpareParts); w.I32(PartsTarget); w.I32(Jobs); w.Bool(WaitingParts);
|
||||
}
|
||||
|
||||
public static DepotInfo Read(ref SpanReader r)
|
||||
{
|
||||
var m = new DepotInfo { Id = r.I32(), Owner = r.I32(), Name = r.String(), Node = r.I32(), Position = r.Vec2(), Size = r.String() };
|
||||
r.Flags();
|
||||
byte flags = r.Flags();
|
||||
if ((flags & 1) != 0)
|
||||
{
|
||||
m.Stalls = r.I32(); m.JobsStaff = r.I32(); m.StaffPercent = r.U8(); m.SpareParts = r.I32(); m.PartsTarget = r.I32();
|
||||
m.Jobs = r.I32(); m.WaitingParts = r.Bool();
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -264,6 +286,9 @@ public sealed class LineInfo : IWritable
|
||||
public string Color { get; init; } = "";
|
||||
public LineStop[] Stops { get; init; } = [];
|
||||
|
||||
// blocco 1 (F4): politica di manutenzione propria della linea (255 = quella della compagnia)
|
||||
public byte Policy { get; set; } = byte.MaxValue;
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Id); w.I32(Owner); w.String(Name); w.String(Color);
|
||||
@@ -272,7 +297,8 @@ public sealed class LineInfo : IWritable
|
||||
{
|
||||
w.I32(s.Station.Value); w.Bool(s.Load); w.Bool(s.Unload); w.Bool(s.WaitFull); w.I32(s.MaxWaitDays);
|
||||
}
|
||||
w.Flags(0);
|
||||
w.Flags(1);
|
||||
w.U8(Policy);
|
||||
}
|
||||
|
||||
public static LineInfo Read(ref SpanReader r)
|
||||
@@ -281,8 +307,10 @@ public sealed class LineInfo : IWritable
|
||||
string name = r.String(), color = r.String();
|
||||
var stops = new LineStop[r.Count()];
|
||||
for (int i = 0; i < stops.Length; i++) stops[i] = new LineStop(new StationId(r.I32()), r.Bool(), r.Bool(), r.Bool(), r.I32());
|
||||
r.Flags();
|
||||
return new LineInfo { Id = id, Owner = owner, Name = name, Color = color, Stops = stops };
|
||||
var m = new LineInfo { Id = id, Owner = owner, Name = name, Color = color, Stops = stops };
|
||||
byte flags = r.Flags();
|
||||
if ((flags & 1) != 0) m.Policy = r.U8();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,6 +337,21 @@ public sealed class VehicleInfo : IWritable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Stato di manutenzione di un treno nel riepilogo (blocco F4 di TrainInfo).</summary>
|
||||
public enum TrainMaintenanceStatus : byte
|
||||
{
|
||||
InService = 0,
|
||||
/// <summary>Intervento prenotato: va in officina dopo la fermata corrente.</summary>
|
||||
Booked = 1,
|
||||
InWorkshop = 2,
|
||||
/// <summary>Guasto lieve: velocità dimezzata fino al deposito.</summary>
|
||||
MinorFailure = 3,
|
||||
/// <summary>Fermo in linea in attesa del soccorso (guasto grave o deragliamento).</summary>
|
||||
Stranded = 4,
|
||||
/// <summary>Rimorchiato verso l'officina.</summary>
|
||||
Towed = 5,
|
||||
}
|
||||
|
||||
public sealed class TrainInfo : IWritable
|
||||
{
|
||||
public int Id { get; init; }
|
||||
@@ -323,13 +366,28 @@ public sealed class TrainInfo : IWritable
|
||||
public int Capacity { get; init; }
|
||||
public int Depot { get; init; } = -1;
|
||||
|
||||
// blocco 1 (F4): riepilogo di manutenzione (la cartella completa si chiede con RequestDetail)
|
||||
/// <summary>Condizione del componente più debole (0–100).</summary>
|
||||
public byte Condition { get; set; } = 100;
|
||||
public TrainMaintenanceStatus Maintenance { get; set; }
|
||||
public bool Reserve { get; set; }
|
||||
/// <summary>Politica propria del treno (255 = quella della linea o della compagnia).</summary>
|
||||
public byte Policy { get; set; } = byte.MaxValue;
|
||||
/// <summary>Prossimo intervento (id di maintenance.json) e giorni alla scadenza (negativi se scaduto).</summary>
|
||||
public string NextIntervention { get; set; } = "";
|
||||
public int NextDueDays { get; set; }
|
||||
/// <summary>Officina prenotata o in cui si trova (−1 nessuna).</summary>
|
||||
public int MaintenanceDepot { get; set; } = -1;
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Id); w.I32(Owner); w.String(Name); w.I32(Line); w.U8(State);
|
||||
w.Count(Vehicles.Length);
|
||||
foreach (int v in Vehicles) w.I32(v);
|
||||
w.F32(MaxSpeedKmh); w.F32(LengthM); w.I32(Load); w.I32(Capacity); w.I32(Depot);
|
||||
w.Flags(0);
|
||||
w.Flags(1);
|
||||
w.U8(Condition); w.U8((byte)Maintenance); w.Bool(Reserve); w.U8(Policy); w.String(NextIntervention); w.I32(NextDueDays);
|
||||
w.I32(MaintenanceDepot);
|
||||
}
|
||||
|
||||
public static TrainInfo Read(ref SpanReader r)
|
||||
@@ -345,7 +403,12 @@ public sealed class TrainInfo : IWritable
|
||||
Id = id, Owner = owner, Name = name, Line = line, State = state, Vehicles = vehicles,
|
||||
MaxSpeedKmh = r.F32(), LengthM = r.F32(), Load = r.I32(), Capacity = r.I32(), Depot = r.I32(),
|
||||
};
|
||||
r.Flags();
|
||||
byte flags = r.Flags();
|
||||
if ((flags & 1) != 0)
|
||||
{
|
||||
m.Condition = r.U8(); m.Maintenance = (TrainMaintenanceStatus)r.U8(); m.Reserve = r.Bool(); m.Policy = r.U8();
|
||||
m.NextIntervention = r.String(); m.NextDueDays = r.I32(); m.MaintenanceDepot = r.I32();
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,22 +403,34 @@ public sealed class EmploymentSource
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Riga del Registro degli impieghi: un posto di lavoro (industria o deposito).</summary>
|
||||
public sealed class EmploymentRow
|
||||
{
|
||||
/// <summary>Indice del posto di lavoro (industria o deposito secondo <see cref="Kind"/>).</summary>
|
||||
public int Industry { get; init; }
|
||||
public int JobsWorkers { get; init; }
|
||||
public int JobsStaff { get; init; }
|
||||
public float WorkersPresent { get; init; }
|
||||
public float StaffPresent { get; init; }
|
||||
/// <summary>Motivo dei posti scoperti, in italiano (per i lettori senza il blocco F4).</summary>
|
||||
public string Reason { get; init; } = "";
|
||||
public List<EmploymentSource> Sources { get; init; } = [];
|
||||
|
||||
// blocco 1 (F4): tipo di posto e codici dei motivi (UncoveredReason di Core)
|
||||
/// <summary>0 = industria, 1 = deposito.</summary>
|
||||
public byte Kind { get; set; }
|
||||
public byte WorkersReason { get; set; }
|
||||
public byte StaffReason { get; set; }
|
||||
public int WorkersReasonLine { get; set; } = -1;
|
||||
public int StaffReasonLine { get; set; } = -1;
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Industry); w.I32(JobsWorkers); w.I32(JobsStaff); w.F32(WorkersPresent); w.F32(StaffPresent); w.String(Reason);
|
||||
w.Count(Sources.Count);
|
||||
foreach (var s in Sources) s.Write(ref w);
|
||||
w.Flags(0);
|
||||
w.Flags(1);
|
||||
w.U8(Kind); w.U8(WorkersReason); w.U8(StaffReason); w.I32(WorkersReasonLine); w.I32(StaffReasonLine);
|
||||
}
|
||||
|
||||
public static EmploymentRow Read(ref SpanReader r)
|
||||
@@ -428,30 +440,293 @@ public sealed class EmploymentRow
|
||||
string reason = r.String();
|
||||
var sources = new List<EmploymentSource>();
|
||||
for (int n = r.Count(), i = 0; i < n; i++) sources.Add(EmploymentSource.Read(ref r));
|
||||
r.Flags();
|
||||
return new EmploymentRow { Industry = ind, JobsWorkers = jw, JobsStaff = js, WorkersPresent = wp, StaffPresent = sp, Reason = reason, Sources = sources };
|
||||
var m = new EmploymentRow { Industry = ind, JobsWorkers = jw, JobsStaff = js, WorkersPresent = wp, StaffPresent = sp, Reason = reason, Sources = sources };
|
||||
byte flags = r.Flags();
|
||||
if ((flags & 1) != 0)
|
||||
{
|
||||
m.Kind = r.U8(); m.WorkersReason = r.U8(); m.StaffReason = r.U8(); m.WorkersReasonLine = r.I32(); m.StaffReasonLine = r.I32();
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Resoconto mensile del pendolarismo della compagnia.</summary>
|
||||
/// <summary>Convenzione di pendolarismo (sezione 9) nel Registro degli impieghi.</summary>
|
||||
public sealed class AgreementInfo
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public int Industry { get; init; }
|
||||
public int Carrier { get; init; }
|
||||
public int SeatsPerDay { get; init; }
|
||||
public Money MonthlyFee { get; init; }
|
||||
/// <summary>AgreementState di Core: 0 proposta, 1 attiva, 2 rifiutata, 3 scaduta, 4 saltata, 5 conclusa.</summary>
|
||||
public byte State { get; init; }
|
||||
public long ProposedDay { get; init; }
|
||||
public long StartDay { get; init; } = -1;
|
||||
public long EndDay { get; init; } = -1;
|
||||
public float Coverage { get; init; }
|
||||
public int ShortDays { get; init; }
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Id); w.I32(Industry); w.I32(Carrier); w.I32(SeatsPerDay); w.Money(MonthlyFee); w.U8(State);
|
||||
w.I64(ProposedDay); w.I64(StartDay); w.I64(EndDay); w.F32(Coverage); w.I32(ShortDays);
|
||||
w.Flags(0);
|
||||
}
|
||||
|
||||
public static AgreementInfo Read(ref SpanReader r)
|
||||
{
|
||||
var m = new AgreementInfo
|
||||
{
|
||||
Id = r.I32(), Industry = r.I32(), Carrier = r.I32(), SeatsPerDay = r.I32(), MonthlyFee = r.Money(), State = r.U8(),
|
||||
ProposedDay = r.I64(), StartDay = r.I64(), EndDay = r.I64(), Coverage = r.F32(), ShortDays = r.I32(),
|
||||
};
|
||||
r.Flags();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Registro degli impieghi della compagnia: ogni mese, dopo le convenzioni e su richiesta.</summary>
|
||||
public sealed class EmploymentReport : IMessage
|
||||
{
|
||||
public MessageId Id => MessageId.EmploymentReport;
|
||||
public long Day { get; init; }
|
||||
public List<EmploymentRow> Rows { get; init; } = [];
|
||||
|
||||
// blocco 1 (F4): convenzioni proposte e attive
|
||||
public List<AgreementInfo> Agreements { get; init; } = [];
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I64(Day);
|
||||
w.Count(Rows.Count);
|
||||
foreach (var row in Rows) row.Write(ref w);
|
||||
w.Flags(0);
|
||||
w.Flags(1);
|
||||
w.Count(Agreements.Count);
|
||||
foreach (var a in Agreements) a.Write(ref w);
|
||||
}
|
||||
|
||||
public static EmploymentReport Read(ref SpanReader r)
|
||||
{
|
||||
var m = new EmploymentReport { Day = r.I64() };
|
||||
for (int n = r.Count(), i = 0; i < n; i++) m.Rows.Add(EmploymentRow.Read(ref r));
|
||||
byte flags = r.Flags();
|
||||
if ((flags & 1) != 0)
|
||||
{
|
||||
for (int n = r.Count(), i = 0; i < n; i++) m.Agreements.Add(AgreementInfo.Read(ref r));
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Componente di un veicolo nella cartella di manutenzione.</summary>
|
||||
public sealed class ComponentCard
|
||||
{
|
||||
public string Component { get; init; } = "";
|
||||
public float Condition { get; init; }
|
||||
/// <summary>Usura media giornaliera degli ultimi giorni (punti/giorno).</summary>
|
||||
public float WearPerDay { get; init; }
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.String(Component); w.F32(Condition); w.F32(WearPerDay);
|
||||
w.Flags(0);
|
||||
}
|
||||
|
||||
public static ComponentCard Read(ref SpanReader r)
|
||||
{
|
||||
var m = new ComponentCard { Component = r.String(), Condition = r.F32(), WearPerDay = r.F32() };
|
||||
r.Flags();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class VehicleCard
|
||||
{
|
||||
public int Vehicle { get; init; }
|
||||
public string Type { get; init; } = "";
|
||||
public float OdometerKm { get; init; }
|
||||
public float AgeYears { get; init; }
|
||||
public float AgeFactor { get; init; }
|
||||
public List<ComponentCard> Components { get; init; } = [];
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Vehicle); w.String(Type); w.F32(OdometerKm); w.F32(AgeYears); w.F32(AgeFactor);
|
||||
w.Count(Components.Count);
|
||||
foreach (var c in Components) c.Write(ref w);
|
||||
w.Flags(0);
|
||||
}
|
||||
|
||||
public static VehicleCard Read(ref SpanReader r)
|
||||
{
|
||||
var m = new VehicleCard { Vehicle = r.I32(), Type = r.String(), OdometerKm = r.F32(), AgeYears = r.F32(), AgeFactor = r.F32() };
|
||||
for (int n = r.Count(), i = 0; i < n; i++) m.Components.Add(ComponentCard.Read(ref r));
|
||||
r.Flags();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Voce dello storico della cartella di manutenzione.</summary>
|
||||
public sealed class MaintenanceRecordInfo
|
||||
{
|
||||
public long Day { get; init; }
|
||||
public string Intervention { get; init; } = "";
|
||||
public Money Cost { get; init; }
|
||||
public int Depot { get; init; } = -1;
|
||||
public int Parts { get; init; }
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I64(Day); w.String(Intervention); w.Money(Cost); w.I32(Depot); w.I32(Parts);
|
||||
w.Flags(0);
|
||||
}
|
||||
|
||||
public static MaintenanceRecordInfo Read(ref SpanReader r)
|
||||
{
|
||||
var m = new MaintenanceRecordInfo { Day = r.I64(), Intervention = r.String(), Cost = r.Money(), Depot = r.I32(), Parts = r.I32() };
|
||||
r.Flags();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cartella di manutenzione di un treno (10.3): componenti per veicolo, guasto in corso, politica,
|
||||
/// prossimo intervento, costi dell'anno e storico. Si invia su richiesta (RequestDetail).
|
||||
/// </summary>
|
||||
public sealed class MaintenanceCard : IMessage
|
||||
{
|
||||
public MessageId Id => MessageId.MaintenanceCard;
|
||||
public int Train { get; init; }
|
||||
public long Day { get; init; }
|
||||
public float Condition { get; init; }
|
||||
public TrainMaintenanceStatus Status { get; init; }
|
||||
/// <summary>Politica effettiva e quella propria del treno (255 = ereditata).</summary>
|
||||
public byte Policy { get; init; }
|
||||
public byte PolicyOverride { get; init; } = byte.MaxValue;
|
||||
public bool Reserve { get; init; }
|
||||
/// <summary>FailureKind di Core e componente guasto.</summary>
|
||||
public byte Failure { get; init; }
|
||||
public int FailedVehicle { get; init; } = -1;
|
||||
public string FailedComponent { get; init; } = "";
|
||||
/// <summary>Ore (orologio dei treni) all'arrivo del soccorso, −1 se non serve.</summary>
|
||||
public float RescueHours { get; init; } = -1;
|
||||
public string NextIntervention { get; init; } = "";
|
||||
public float NextDueDays { get; init; }
|
||||
public string PlannedIntervention { get; init; } = "";
|
||||
public int MaintenanceDepot { get; init; } = -1;
|
||||
public float ServiceKmPerDay { get; init; }
|
||||
public Money CostThisYear { get; init; }
|
||||
public Money CostLastYear { get; init; }
|
||||
public int FailuresThisYear { get; init; }
|
||||
public int FailuresTotal { get; init; }
|
||||
public int CoveredBy { get; init; } = -1;
|
||||
public int Covering { get; init; } = -1;
|
||||
public List<VehicleCard> Vehicles { get; init; } = [];
|
||||
public List<MaintenanceRecordInfo> History { get; init; } = [];
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Train); w.I64(Day); w.F32(Condition); w.U8((byte)Status); w.U8(Policy); w.U8(PolicyOverride); w.Bool(Reserve);
|
||||
w.U8(Failure); w.I32(FailedVehicle); w.String(FailedComponent); w.F32(RescueHours);
|
||||
w.String(NextIntervention); w.F32(NextDueDays); w.String(PlannedIntervention); w.I32(MaintenanceDepot);
|
||||
w.F32(ServiceKmPerDay); w.Money(CostThisYear); w.Money(CostLastYear); w.I32(FailuresThisYear); w.I32(FailuresTotal);
|
||||
w.I32(CoveredBy); w.I32(Covering);
|
||||
w.Count(Vehicles.Count);
|
||||
foreach (var v in Vehicles) v.Write(ref w);
|
||||
w.Count(History.Count);
|
||||
foreach (var h in History) h.Write(ref w);
|
||||
w.Flags(0);
|
||||
}
|
||||
|
||||
public static MaintenanceCard Read(ref SpanReader r)
|
||||
{
|
||||
var m = new MaintenanceCard
|
||||
{
|
||||
Train = r.I32(), Day = r.I64(), Condition = r.F32(), Status = (TrainMaintenanceStatus)r.U8(), Policy = r.U8(), PolicyOverride = r.U8(),
|
||||
Reserve = r.Bool(), Failure = r.U8(), FailedVehicle = r.I32(), FailedComponent = r.String(), RescueHours = r.F32(),
|
||||
NextIntervention = r.String(), NextDueDays = r.F32(), PlannedIntervention = r.String(), MaintenanceDepot = r.I32(),
|
||||
ServiceKmPerDay = r.F32(), CostThisYear = r.Money(), CostLastYear = r.Money(), FailuresThisYear = r.I32(), FailuresTotal = r.I32(),
|
||||
CoveredBy = r.I32(), Covering = r.I32(),
|
||||
};
|
||||
for (int n = r.Count(), i = 0; i < n; i++) m.Vehicles.Add(VehicleCard.Read(ref r));
|
||||
for (int n = r.Count(), i = 0; i < n; i++) m.History.Add(MaintenanceRecordInfo.Read(ref r));
|
||||
r.Flags();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Lavoro nel Registro officina.</summary>
|
||||
public sealed class WorkshopJobInfo
|
||||
{
|
||||
public int Train { get; init; }
|
||||
public string Intervention { get; init; } = "";
|
||||
public bool InStall { get; init; }
|
||||
public bool Started { get; init; }
|
||||
public float Progress { get; init; }
|
||||
public float Days { get; init; }
|
||||
public int Parts { get; init; }
|
||||
public long QueuedDay { get; init; }
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Train); w.String(Intervention); w.Bool(InStall); w.Bool(Started); w.F32(Progress); w.F32(Days); w.I32(Parts); w.I64(QueuedDay);
|
||||
w.Flags(0);
|
||||
}
|
||||
|
||||
public static WorkshopJobInfo Read(ref SpanReader r)
|
||||
{
|
||||
var m = new WorkshopJobInfo
|
||||
{
|
||||
Train = r.I32(), Intervention = r.String(), InStall = r.Bool(), Started = r.Bool(), Progress = r.F32(), Days = r.F32(),
|
||||
Parts = r.I32(), QueuedDay = r.I64(),
|
||||
};
|
||||
r.Flags();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registro officina di un deposito (10.3): stalli, personale, ricambi, coda dei lavori e treni
|
||||
/// prenotati. Si invia su richiesta (RequestDetail).
|
||||
/// </summary>
|
||||
public sealed class WorkshopRegister : IMessage
|
||||
{
|
||||
public MessageId Id => MessageId.WorkshopRegister;
|
||||
public int Depot { get; init; }
|
||||
public long Day { get; init; }
|
||||
public int Stalls { get; init; }
|
||||
public int JobsStaff { get; init; }
|
||||
public float StaffPresent { get; init; }
|
||||
/// <summary>Velocità del lavoro (1 a personale completo).</summary>
|
||||
public float WorkRate { get; init; }
|
||||
public int SpareParts { get; init; }
|
||||
public int PartsTarget { get; init; }
|
||||
/// <summary>Ricambi già destinati a lavori in coda e treni prenotati.</summary>
|
||||
public int PartsReserved { get; init; }
|
||||
public List<WorkshopJobInfo> Jobs { get; init; } = [];
|
||||
/// <summary>Treni prenotati in arrivo e relativo intervento.</summary>
|
||||
public List<WorkshopJobInfo> Booked { get; init; } = [];
|
||||
|
||||
public void Write(ref SpanWriter w)
|
||||
{
|
||||
w.I32(Depot); w.I64(Day); w.I32(Stalls); w.I32(JobsStaff); w.F32(StaffPresent); w.F32(WorkRate);
|
||||
w.I32(SpareParts); w.I32(PartsTarget); w.I32(PartsReserved);
|
||||
w.Count(Jobs.Count);
|
||||
foreach (var j in Jobs) j.Write(ref w);
|
||||
w.Count(Booked.Count);
|
||||
foreach (var j in Booked) j.Write(ref w);
|
||||
w.Flags(0);
|
||||
}
|
||||
|
||||
public static WorkshopRegister Read(ref SpanReader r)
|
||||
{
|
||||
var m = new WorkshopRegister
|
||||
{
|
||||
Depot = r.I32(), Day = r.I64(), Stalls = r.I32(), JobsStaff = r.I32(), StaffPresent = r.F32(), WorkRate = r.F32(),
|
||||
SpareParts = r.I32(), PartsTarget = r.I32(), PartsReserved = r.I32(),
|
||||
};
|
||||
for (int n = r.Count(), i = 0; i < n; i++) m.Jobs.Add(WorkshopJobInfo.Read(ref r));
|
||||
for (int n = r.Count(), i = 0; i < n; i++) m.Booked.Add(WorkshopJobInfo.Read(ref r));
|
||||
r.Flags();
|
||||
return m;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user