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;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using ViaFerrea.Core.Commands;
|
||||
using ViaFerrea.Core.Common;
|
||||
using ViaFerrea.Core.Data;
|
||||
using ViaFerrea.Core.Simulation;
|
||||
@@ -223,6 +224,9 @@ public sealed class GameHost : IDisposable
|
||||
_slow = false;
|
||||
_log.LogInformation("Velocità {Speed}×", _speed);
|
||||
break;
|
||||
case RequestDetail m:
|
||||
SendDetail(s, m);
|
||||
break;
|
||||
case ListSaves:
|
||||
s.Send(new SaveList { Saves = _saves.List() });
|
||||
break;
|
||||
@@ -362,7 +366,22 @@ public sealed class GameHost : IDisposable
|
||||
{
|
||||
Seq = p.ClientSeq, Type = (ushort)r.Type, Error = (ushort)r.Error, Message = r.Message, Created = r.Created, Tick = r.Tick,
|
||||
});
|
||||
// le convenzioni cambiano il Registro degli impieghi: lo si rimanda subito
|
||||
if (r.Ok && r.Type is CommandType.AcceptAgreement or CommandType.RejectAgreement)
|
||||
p.Session.Send(Projection.Employment(w, p.Session.Company));
|
||||
}
|
||||
foreach (var a in w.Alerts)
|
||||
{
|
||||
var alert = new MaintenanceAlert
|
||||
{
|
||||
Train = a.Train.Value, Depot = a.Depot.Value, Component = a.Component, Condition = (float)a.Condition, DueDays = a.DueDays, Text = a.Text,
|
||||
};
|
||||
foreach (var s in _sessions.Values)
|
||||
{
|
||||
if (s.Connected && s.Company == a.Company) s.Send(alert);
|
||||
}
|
||||
}
|
||||
w.Alerts.Clear();
|
||||
foreach (var e in w.Events.Drain())
|
||||
{
|
||||
var info = Projection.Event(e);
|
||||
@@ -599,37 +618,30 @@ public sealed class GameHost : IDisposable
|
||||
s.Send(Projection.Chunk(w, key.Cx, key.Cy));
|
||||
}
|
||||
}
|
||||
if (_monthlyDue) s.Send(EmploymentReport(w, s.Company));
|
||||
if (_monthlyDue) s.Send(Projection.Employment(w, s.Company));
|
||||
}
|
||||
_monthlyDue = false;
|
||||
_dayEvents.Clear();
|
||||
}
|
||||
|
||||
/// <summary>Registro degli impieghi della compagnia: posti serviti dai suoi treni e provenienze.</summary>
|
||||
private static EmploymentReport EmploymentReport(World w, CompanyId company)
|
||||
/// <summary>Dettagli su richiesta: cartella di manutenzione, registro officina, registro degli impieghi.</summary>
|
||||
private void SendDetail(Session s, RequestDetail m)
|
||||
{
|
||||
var report = new EmploymentReport { Day = w.Clock.Day };
|
||||
foreach (var ind in w.Industries)
|
||||
var w = _world;
|
||||
switch (m.Kind)
|
||||
{
|
||||
if (ind.Closed) continue;
|
||||
var sources = new List<EmploymentSource>();
|
||||
foreach (var c in w.Commutes)
|
||||
{
|
||||
if (c.Walking || c.Carrier != company || c.Workplace.Kind != Core.Economy.WorkplaceKind.Industry || c.Workplace.Index != ind.Id.Value) continue;
|
||||
sources.Add(new EmploymentSource
|
||||
{
|
||||
Town = c.Town.Value, HomeStation = c.HomeStation.Value, Line = c.Route.Count > 0 ? c.Route[0].Value : -1,
|
||||
Category = (byte)c.Category, Headcount = c.Headcount, Coverage = (float)c.Coverage,
|
||||
});
|
||||
}
|
||||
if (sources.Count == 0) continue;
|
||||
report.Rows.Add(new EmploymentRow
|
||||
{
|
||||
Industry = ind.Id.Value, JobsWorkers = ind.JobsWorkers, JobsStaff = ind.JobsStaff,
|
||||
WorkersPresent = (float)ind.WorkersPresent, StaffPresent = (float)ind.StaffPresent, Sources = sources,
|
||||
});
|
||||
case DetailKind.TrainCard:
|
||||
if (m.Target >= 0 && m.Target < w.Trains.Count && w.Trains[m.Target] is { Removed: false } t && t.Owner == s.Company)
|
||||
s.Send(Projection.Card(w, t));
|
||||
break;
|
||||
case DetailKind.Workshop:
|
||||
if (m.Target >= 0 && m.Target < w.Network.Depots.Count && w.Network.Depots[m.Target] is { } d && d.Owner == s.Company && w.Network.IsAlive(d))
|
||||
s.Send(Projection.Workshop(w, d));
|
||||
break;
|
||||
case DetailKind.Employment:
|
||||
s.Send(Projection.Employment(w, s.Company));
|
||||
break;
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
private void PublishMotion()
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using ViaFerrea.Core.Common;
|
||||
using ViaFerrea.Core.Economy;
|
||||
using ViaFerrea.Core.Rail;
|
||||
using ViaFerrea.Core.Data;
|
||||
using ViaFerrea.Core.Simulation;
|
||||
using ViaFerrea.Core.Simulation.Systems;
|
||||
using ViaFerrea.Protocol;
|
||||
using ViaFerrea.Protocol.Messages;
|
||||
|
||||
@@ -76,7 +78,7 @@ public static class Projection
|
||||
e.Companies.Add(new CompanyInfo
|
||||
{
|
||||
Id = c.Id.Value, Name = c.Name, Color = c.Color, IsPlayer = c.IsPlayer, Cash = c.Cash, NetWorth = c.NetWorth,
|
||||
Rating = c.Rating.ToString(), Tier = (byte)c.Tier, Bankrupt = c.Bankrupt,
|
||||
Rating = c.Rating.ToString(), Tier = (byte)c.Tier, Bankrupt = c.Bankrupt, MaintenancePolicy = (byte)c.MaintenancePolicy,
|
||||
});
|
||||
}
|
||||
foreach (var t in w.Towns)
|
||||
@@ -120,17 +122,29 @@ public static class Projection
|
||||
foreach (var d in net.Depots)
|
||||
{
|
||||
if (!net.IsAlive(d)) continue;
|
||||
e.Depots.Add(new DepotInfo { Id = d.Id.Value, Owner = d.Owner.Value, Name = d.Name, Node = d.Node.Value, Position = d.Position, Size = d.Size });
|
||||
bool waiting = false;
|
||||
foreach (var j in d.Jobs) waiting |= j.InStall && !j.Started && d.SpareParts < j.Parts;
|
||||
e.Depots.Add(new DepotInfo
|
||||
{
|
||||
Id = d.Id.Value, Owner = d.Owner.Value, Name = d.Name, Node = d.Node.Value, Position = d.Position, Size = d.Size,
|
||||
Stalls = d.Stalls, JobsStaff = d.JobsStaff, StaffPercent = (byte)Math.Round(d.StaffRatio * 100), SpareParts = d.SpareParts,
|
||||
PartsTarget = d.PartsTarget, Jobs = d.Jobs.Count, WaitingParts = waiting,
|
||||
});
|
||||
}
|
||||
foreach (var l in w.Lines)
|
||||
{
|
||||
if (l.Removed) continue;
|
||||
e.Lines.Add(new LineInfo { Id = l.Id.Value, Owner = l.Owner.Value, Name = l.Name, Color = l.Color, Stops = l.Stops.ToArray() });
|
||||
e.Lines.Add(new LineInfo
|
||||
{
|
||||
Id = l.Id.Value, Owner = l.Owner.Value, Name = l.Name, Color = l.Color, Stops = l.Stops.ToArray(),
|
||||
Policy = l.Policy is { } p ? (byte)p : byte.MaxValue,
|
||||
});
|
||||
}
|
||||
foreach (var v in w.Vehicles)
|
||||
{
|
||||
if (v.Sold) continue;
|
||||
double cond = v.Components.Length == 0 ? 100 : v.Components.Min();
|
||||
// condizione arrotondata all'unità: il record cambia (e viaggia nei delta) solo quando serve
|
||||
double cond = Math.Floor(v.Components.Length == 0 ? 100 : v.Components.Min());
|
||||
e.Vehicles.Add(new VehicleInfo { Id = v.Id.Value, Owner = v.Owner.Value, Type = v.Def.Id, Depot = v.Depot.Value, Train = v.Train.Value, Condition = (float)cond });
|
||||
}
|
||||
foreach (var t in w.Trains)
|
||||
@@ -144,16 +158,163 @@ public static class Projection
|
||||
capacity += (v.Def.Capacity ?? 0) + (v.Def.PaxCapacity ?? 0);
|
||||
}
|
||||
var atDepot = t.AtNode.IsValid ? net.Nodes[t.AtNode.Value].Depot : DepotId.None;
|
||||
var next = t.Vehicles.Count > 0 ? Fleet.Next(w, t) : new NextIntervention(-1, 0);
|
||||
e.Trains.Add(new TrainInfo
|
||||
{
|
||||
Id = t.Id.Value, Owner = t.Owner.Value, Name = t.Name, Line = t.Line.Value, State = (byte)t.State,
|
||||
Vehicles = t.Vehicles.Select(x => x.Value).ToArray(), MaxSpeedKmh = (float)t.MaxSpeedKmh, LengthM = (float)t.LengthM,
|
||||
Load = load, Capacity = capacity, Depot = atDepot.Value,
|
||||
Condition = (byte)Math.Clamp(Math.Floor(Fleet.TrainCondition(w, t)), 0, 100), Maintenance = MaintenanceStatus(t),
|
||||
Reserve = t.Reserve, Policy = t.Policy is { } p ? (byte)p : byte.MaxValue,
|
||||
NextIntervention = next.Intervention >= 0 ? w.Data.Maintenance.Interventions[next.Intervention].Id : "",
|
||||
NextDueDays = (int)Math.Clamp(Math.Floor(next.Days), -9999, 9999), MaintenanceDepot = t.MaintenanceDepot.Value,
|
||||
});
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
public static TrainMaintenanceStatus MaintenanceStatus(Train t)
|
||||
{
|
||||
if (t.State == TrainState.Broken) return TrainMaintenanceStatus.Stranded;
|
||||
if (t.Towed) return TrainMaintenanceStatus.Towed;
|
||||
if (t.InWorkshop) return TrainMaintenanceStatus.InWorkshop;
|
||||
if (t.Failure == FailureKind.Minor) return TrainMaintenanceStatus.MinorFailure;
|
||||
return t.MaintenanceDepot.IsValid ? TrainMaintenanceStatus.Booked : TrainMaintenanceStatus.InService;
|
||||
}
|
||||
|
||||
/// <summary>Cartella di manutenzione di un treno (10.3).</summary>
|
||||
public static MaintenanceCard Card(World w, Train t)
|
||||
{
|
||||
var m = w.Data.Maintenance;
|
||||
var next = t.Vehicles.Count > 0 ? Fleet.Next(w, t) : new NextIntervention(-1, 0);
|
||||
var card = new MaintenanceCard
|
||||
{
|
||||
Train = t.Id.Value, Day = w.Clock.Day, Condition = (float)Fleet.TrainCondition(w, t), Status = MaintenanceStatus(t),
|
||||
Policy = (byte)Fleet.PolicyOf(w, t).Id, PolicyOverride = t.Policy is { } p ? (byte)p : byte.MaxValue, Reserve = t.Reserve,
|
||||
Failure = (byte)t.Failure, FailedVehicle = t.FailedVehicle.Value,
|
||||
FailedComponent = t.FailedVehicle.IsValid && t.FailedComponent >= 0
|
||||
? Fleet.ComponentsOf(w.Data, w.Vehicles[t.FailedVehicle.Value].Def)[t.FailedComponent].Id : "",
|
||||
RescueHours = t.RescueTick >= 0 ? (float)((t.RescueTick - w.Clock.Tick) * w.Calendar.TrainSecondsPerTick / 3600) : -1,
|
||||
NextIntervention = next.Intervention >= 0 ? m.Interventions[next.Intervention].Id : "", NextDueDays = (float)next.Days,
|
||||
PlannedIntervention = t.PlannedIntervention >= 0 ? m.Interventions[t.PlannedIntervention].Id : "",
|
||||
MaintenanceDepot = t.MaintenanceDepot.Value, ServiceKmPerDay = (float)t.ServiceKmPerDay,
|
||||
CostThisYear = new Money(t.MaintenanceThisYear), CostLastYear = new Money(t.MaintenanceLastYear),
|
||||
FailuresThisYear = t.FailuresThisYear, FailuresTotal = t.FailuresTotal, CoveredBy = t.CoveredBy.Value, Covering = t.Covering.Value,
|
||||
};
|
||||
foreach (var id in t.Vehicles)
|
||||
{
|
||||
var v = w.Vehicles[id.Value];
|
||||
var comps = Fleet.ComponentsOf(w.Data, v.Def);
|
||||
var vc = new VehicleCard
|
||||
{
|
||||
Vehicle = v.Id.Value, Type = v.Def.Id, OdometerKm = (float)v.OdometerKm,
|
||||
AgeYears = (float)((w.Clock.Day - v.BoughtDay) / (double)w.Calendar.DaysPerYear), AgeFactor = (float)Fleet.AgeFactor(w, v),
|
||||
};
|
||||
for (int j = 0; j < v.Components.Length && j < comps.Count; j++)
|
||||
vc.Components.Add(new ComponentCard { Component = comps[j].Id, Condition = (float)v.Components[j], WearPerDay = j < v.WearEma.Length ? (float)v.WearEma[j] : 0 });
|
||||
card.Vehicles.Add(vc);
|
||||
}
|
||||
foreach (var h in t.History)
|
||||
{
|
||||
card.History.Add(new MaintenanceRecordInfo
|
||||
{
|
||||
Day = h.Day, Intervention = m.Interventions[h.Intervention].Id, Cost = new Money(h.CostCents), Depot = h.Depot.Value, Parts = h.Parts,
|
||||
});
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
/// <summary>Registro officina di un deposito (10.3).</summary>
|
||||
public static WorkshopRegister Workshop(World w, Depot d)
|
||||
{
|
||||
var m = w.Data.Maintenance;
|
||||
var backlog = new double[w.Network.Depots.Count];
|
||||
var reserved = new int[w.Network.Depots.Count];
|
||||
FleetMaintenanceSystem.DepotLoads(w, null, backlog, reserved);
|
||||
var reg = new WorkshopRegister
|
||||
{
|
||||
Depot = d.Id.Value, Day = w.Clock.Day, Stalls = d.Stalls, JobsStaff = d.JobsStaff, StaffPresent = (float)d.StaffPresent,
|
||||
WorkRate = (float)FleetMaintenanceSystem.WorkRate(w, d), SpareParts = d.SpareParts, PartsTarget = d.PartsTarget,
|
||||
PartsReserved = reserved[d.Id.Value],
|
||||
};
|
||||
foreach (var j in d.Jobs)
|
||||
{
|
||||
reg.Jobs.Add(new WorkshopJobInfo
|
||||
{
|
||||
Train = j.Train.Value, Intervention = m.Interventions[j.Intervention].Id, InStall = j.InStall, Started = j.Started,
|
||||
Progress = (float)j.Progress, Days = (float)j.Days, Parts = j.Parts, QueuedDay = j.QueuedDay,
|
||||
});
|
||||
}
|
||||
foreach (var t in w.Trains)
|
||||
{
|
||||
if (t.Removed || t.InWorkshop || t.MaintenanceDepot != d.Id || t.PlannedIntervention < 0) continue;
|
||||
var def = m.Interventions[t.PlannedIntervention];
|
||||
reg.Booked.Add(new WorkshopJobInfo { Train = t.Id.Value, Intervention = def.Id, Days = def.Days, Parts = Fleet.PartsFor(w, t, def), QueuedDay = -1 });
|
||||
}
|
||||
return reg;
|
||||
}
|
||||
|
||||
/// <summary>Testo italiano del motivo dei posti scoperti (per i lettori senza il blocco F4).</summary>
|
||||
public static string ReasonText(World w, UncoveredReason reason, LineId line, PaxClass cls) => reason switch
|
||||
{
|
||||
UncoveredReason.NoStation => "nessuna stazione serve il posto di lavoro",
|
||||
UncoveredReason.NoTownInReach => $"nessuna città raggiungibile entro {(cls == PaxClass.Staff ? w.Data.Balance.Employment.StaffMaxMinutes : w.Data.Balance.Employment.WorkerMaxMinutes):F0} min",
|
||||
UncoveredReason.NoFreeWorkers => "le città raggiungibili non hanno lavoratori liberi",
|
||||
UncoveredReason.NoStaffServices => "città senza servizi per il personale",
|
||||
UncoveredReason.LineCapacity => $"capacità delle carrozze insufficiente sulla {(line.IsValid && line.Value < w.Lines.Count ? w.Lines[line.Value].Name : "linea")}",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Registro degli impieghi della compagnia: industrie servite dai suoi treni e suoi depositi, con
|
||||
/// provenienze, posti scoperti e motivi, più le convenzioni proposte o attive.
|
||||
/// </summary>
|
||||
public static EmploymentReport Employment(World w, CompanyId company)
|
||||
{
|
||||
var report = new EmploymentReport { Day = w.Clock.Day };
|
||||
var places = new List<IWorkplace>();
|
||||
EmploymentSystem.Workplaces(w, places);
|
||||
foreach (var p in places)
|
||||
{
|
||||
bool mine = p is Depot depot && depot.Owner == company;
|
||||
var sources = new List<EmploymentSource>();
|
||||
foreach (var c in w.Commutes)
|
||||
{
|
||||
if (c.Workplace != p.Ref || (!mine && c.Carrier != company)) continue;
|
||||
sources.Add(new EmploymentSource
|
||||
{
|
||||
Town = c.Town.Value, HomeStation = c.HomeStation.Value, Line = c.Route.Count > 0 ? c.Route[0].Value : -1,
|
||||
Category = (byte)c.Category, Headcount = c.Headcount, Coverage = (float)c.Coverage,
|
||||
});
|
||||
}
|
||||
bool served = w.Network.Stations.Any(s => s.Owner == company && w.Network.IsAlive(s) && p is Industry ind && s.Industries.Contains(ind.Id));
|
||||
if (!mine && sources.Count == 0 && !served) continue;
|
||||
string reason = string.Join("; ", new[]
|
||||
{
|
||||
ReasonText(w, p.WorkersReason, p.WorkersReasonLine, PaxClass.Worker),
|
||||
ReasonText(w, p.StaffReason, p.StaffReasonLine, PaxClass.Staff),
|
||||
}.Where(x => x.Length > 0));
|
||||
report.Rows.Add(new EmploymentRow
|
||||
{
|
||||
Industry = p.Ref.Index, JobsWorkers = p.JobsWorkers, JobsStaff = p.JobsStaff,
|
||||
WorkersPresent = (float)p.WorkersPresent, StaffPresent = (float)p.StaffPresent, Reason = reason, Sources = sources,
|
||||
Kind = (byte)p.Ref.Kind, WorkersReason = (byte)p.WorkersReason, StaffReason = (byte)p.StaffReason,
|
||||
WorkersReasonLine = p.WorkersReasonLine.Value, StaffReasonLine = p.StaffReasonLine.Value,
|
||||
});
|
||||
}
|
||||
foreach (var a in w.Agreements)
|
||||
{
|
||||
if (a.Carrier != company) continue;
|
||||
report.Agreements.Add(new AgreementInfo
|
||||
{
|
||||
Id = a.Id.Value, Industry = a.Industry.Value, Carrier = a.Carrier.Value, SeatsPerDay = a.SeatsPerDay, MonthlyFee = a.MonthlyFee,
|
||||
State = (byte)a.State, ProposedDay = a.ProposedDay, StartDay = a.StartDay, EndDay = a.EndDay, Coverage = (float)a.Coverage,
|
||||
ShortDays = a.ShortDays,
|
||||
});
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
public static EdgeInfo Edge(World w, TrackEdge e)
|
||||
{
|
||||
float progress = 1;
|
||||
|
||||
Reference in new issue
Block a user