F4: manutenzione della flotta, officine, ricambi via treno e pendolarismo completo nel motore
- FleetMaintenanceSystem: usura per componente in km di servizio, rischio e guasti (lieve, grave con soccorso, deragliamento), pianificatore predittivo con scelta del deposito, officine con stalli, ricambi e personale, riserve, avvisi. - Depositi come posti di lavoro; motivi dei posti scoperti; convenzioni di pendolarismo. - Ricambi consegnati alle officine nel bacino e importati dagli hub. - Inversione di marcia in stazione come sosta tecnica e transito in stazione che libera l'arco d'arrivo (eliminano due stalli della circolazione). - Salvataggio versione 2 con migrazione dalla versione 1; test di 14.5 e accettazione F4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
This commit is contained in:
34 files changed
+2854
-94
No files matched your search
@@ -4,6 +4,7 @@ using ViaFerrea.Core.Data;
|
||||
using ViaFerrea.Core.Economy;
|
||||
using ViaFerrea.Core.Map;
|
||||
using ViaFerrea.Core.Rail;
|
||||
using ViaFerrea.Core.Simulation.Systems;
|
||||
|
||||
namespace ViaFerrea.Core.Simulation;
|
||||
|
||||
@@ -169,15 +170,33 @@ public static class RailCommandHandlers
|
||||
BuiltDay = w.Clock.Day,
|
||||
BuildCostCents = cost.Cents,
|
||||
SpareParts = w.Data.Maintenance.Depots.InitialSpareParts,
|
||||
PartsTarget = w.Data.Maintenance.Depots.TargetSpareParts,
|
||||
};
|
||||
InitDepot(w.Data, depot);
|
||||
// la scorta iniziale è compresa nel prezzo del deposito
|
||||
w.Goods.Imported[w.Data.SparePartsGood] += depot.SpareParts;
|
||||
node.Depot = depot.Id;
|
||||
w.Network.Depots.Add(depot);
|
||||
w.NextIds.Depot = w.Network.Depots.Count;
|
||||
foreach (var st in w.Network.Stations)
|
||||
{
|
||||
if (st.Owner == company.Id && w.Network.IsAlive(st) && Vec2.Distance(st.Position, depot.Position) <= sp.CatchmentKm * 1000)
|
||||
UpdateCatchment(w, st);
|
||||
}
|
||||
w.Network.Touch();
|
||||
w.Money.Transfer(Account.Of(company.Id), Account.External, cost, LedgerEntry.Construction);
|
||||
return reply(CommandError.None, $"{name} costruito", depot.Id.Value, node.Id.Value);
|
||||
}
|
||||
|
||||
/// <summary>Stalli e posti di lavoro del deposito secondo la dimensione (maintenance.json).</summary>
|
||||
public static void InitDepot(GameData data, Depot depot)
|
||||
{
|
||||
var dp = data.Maintenance.Depots;
|
||||
depot.Stalls = dp.StallsBySize.GetValueOrDefault(depot.Size, 0);
|
||||
depot.JobsStaff = depot.Stalls * dp.StaffPerStall;
|
||||
depot.JobsWorkers = depot.Stalls * dp.JobsWorkersPerStall;
|
||||
}
|
||||
|
||||
public static CommandResult PlaceSignal(World w, Company company, PlaceSignalCommand c, Reply reply)
|
||||
{
|
||||
if (!TryEdge(w, c.Edge, company, out var edge)) return reply(CommandError.NotFound, "Binario inesistente");
|
||||
@@ -244,6 +263,7 @@ public static class RailCommandHandlers
|
||||
st.Industries.Clear();
|
||||
st.Towns.Clear();
|
||||
st.Hubs.Clear();
|
||||
st.Depots.Clear();
|
||||
net.Touch();
|
||||
var refund = new Money(st.BuildCostCents) * refundShare;
|
||||
w.Money.Transfer(Account.External, Account.Of(company.Id), refund, LedgerEntry.Construction);
|
||||
@@ -257,7 +277,15 @@ public static class RailCommandHandlers
|
||||
if (node.Depot != depot.Id) return reply(CommandError.NotFound, "Deposito già demolito");
|
||||
if (w.Vehicles.Any(v => !v.Sold && v.Depot == depot.Id) || w.Trains.Any(t => !t.Removed && t.AtNode == depot.Node))
|
||||
return reply(CommandError.Blocked, "Ci sono veicoli nel deposito");
|
||||
if (depot.Jobs.Count > 0) return reply(CommandError.Blocked, "L'officina ha lavori in corso");
|
||||
node.Depot = DepotId.None;
|
||||
// prenotazioni verso l'officina demolita: il pianificatore ne sceglierà un'altra
|
||||
foreach (var t in w.Trains)
|
||||
{
|
||||
if (!t.Removed && t.MaintenanceDepot == depot.Id && !t.InWorkshop) FleetMaintenanceSystem.CancelBooking(t);
|
||||
if (!t.Removed && t.GoingToDepot == depot.Id) t.GoingToDepot = DepotId.None;
|
||||
}
|
||||
foreach (var st in net.Stations) st.Depots.Remove(depot.Id);
|
||||
net.Touch();
|
||||
var refund = new Money(depot.BuildCostCents) * refundShare;
|
||||
w.Money.Transfer(Account.External, Account.Of(company.Id), refund, LedgerEntry.Construction);
|
||||
@@ -343,7 +371,6 @@ public static class RailCommandHandlers
|
||||
var cost = new Money(def.Price) * c.Count;
|
||||
if (company.Cash < cost) return reply(CommandError.InsufficientFunds, $"Servono {cost}");
|
||||
var created = new int[c.Count];
|
||||
var components = def.Kind == VehicleKind.Locomotive ? w.Data.Maintenance.Components.Locomotive : w.Data.Maintenance.Components.Car;
|
||||
for (int i = 0; i < c.Count; i++)
|
||||
{
|
||||
var v = new Vehicle
|
||||
@@ -353,8 +380,8 @@ public static class RailCommandHandlers
|
||||
Owner = company.Id,
|
||||
BoughtDay = w.Clock.Day,
|
||||
Depot = c.Depot,
|
||||
Components = Enumerable.Repeat(100.0, components.Count).ToArray(),
|
||||
};
|
||||
Fleet.InitVehicle(w.Data, v, w.Clock.Day);
|
||||
w.Vehicles.Add(v);
|
||||
created[i] = v.Id.Value;
|
||||
}
|
||||
@@ -428,7 +455,7 @@ public static class RailCommandHandlers
|
||||
public static void RecomputeTrain(World w, Train t)
|
||||
{
|
||||
var cx = w.Data.Construction.Physics.CxByKind;
|
||||
double mass = 0, locoMass = 0, power = 0, te = 0, length = 0, drag = 0, vmax = double.MaxValue;
|
||||
double mass = 0, locoMass = 0, power = 0, te = 0, length = 0, drag = 0, vmax = double.MaxValue, capacity = 0;
|
||||
bool electric = false;
|
||||
int locos = 0;
|
||||
foreach (var id in t.Vehicles)
|
||||
@@ -438,6 +465,7 @@ public static class RailCommandHandlers
|
||||
length += d.LengthM;
|
||||
vmax = Math.Min(vmax, d.MaxSpeedKmh);
|
||||
drag += cx[d.Kind.ToString().ToLowerInvariant()];
|
||||
capacity += (d.Capacity ?? 0) + (d.PaxCapacity ?? 0) * w.Data.Construction.Physics.PassengerMassT;
|
||||
if (d.Kind != VehicleKind.Locomotive) continue;
|
||||
locos++;
|
||||
locoMass += d.MassT;
|
||||
@@ -454,6 +482,7 @@ public static class RailCommandHandlers
|
||||
t.MaxSpeedKmh = vmax == double.MaxValue ? 0 : vmax;
|
||||
t.NeedsElectrification = electric;
|
||||
t.Locomotives = locos;
|
||||
t.CapacityT = capacity;
|
||||
}
|
||||
|
||||
public static CommandResult CreateLine(World w, Company company, CreateLineCommand c, Reply reply)
|
||||
@@ -507,9 +536,17 @@ public static class RailCommandHandlers
|
||||
if (!TryTrain(w, c.Train, company, out var train)) return reply(CommandError.NotFound, "Treno inesistente");
|
||||
if (c.Line.IsValid && (c.Line.Value >= w.Lines.Count || w.Lines[c.Line.Value].Owner != company.Id || w.Lines[c.Line.Value].Removed))
|
||||
return reply(CommandError.NotFound, "Linea inesistente");
|
||||
// un'assegnazione esplicita chiude la copertura di una riserva
|
||||
if (train.Covering.IsValid)
|
||||
{
|
||||
var covered = w.Trains[train.Covering.Value];
|
||||
if (covered.CoveredBy == train.Id) covered.CoveredBy = TrainId.None;
|
||||
train.Covering = TrainId.None;
|
||||
}
|
||||
if (c.Line.IsValid) train.Reserve = false;
|
||||
train.Line = c.Line;
|
||||
train.StopIndex = 0;
|
||||
train.GoingToDepot = DepotId.None;
|
||||
if (!train.MaintenanceDepot.IsValid || train.GoingToDepot != train.MaintenanceDepot) train.GoingToDepot = DepotId.None;
|
||||
if (train.State == TrainState.NoRoute) train.State = TrainState.Waiting;
|
||||
w.LineGraphs.Touch();
|
||||
return reply(CommandError.None, c.Line.IsValid ? $"{train.Name} assegnato a {w.Lines[c.Line.Value].Name}" : $"{train.Name} tolto dal servizio");
|
||||
@@ -520,6 +557,16 @@ public static class RailCommandHandlers
|
||||
if (!TryTrain(w, c.Train, company, out var train)) return reply(CommandError.NotFound, "Treno inesistente");
|
||||
if (!c.Depot.IsValid || c.Depot.Value >= w.Network.Depots.Count || w.Network.Depots[c.Depot.Value].Owner != company.Id)
|
||||
return reply(CommandError.NotFound, "Deposito inesistente");
|
||||
if (train.InWorkshop) return reply(CommandError.NotAllowed, $"{train.Name} è in officina");
|
||||
if (train.State == TrainState.Broken) return reply(CommandError.NotAllowed, $"{train.Name} attende il soccorso");
|
||||
// il rientro voluto dal giocatore sostituisce l'intervento prenotato (il pianificatore lo riproporrà)
|
||||
FleetMaintenanceSystem.CancelBooking(train);
|
||||
if (train.Covering.IsValid)
|
||||
{
|
||||
var covered = w.Trains[train.Covering.Value];
|
||||
if (covered.CoveredBy == train.Id) covered.CoveredBy = TrainId.None;
|
||||
train.Covering = TrainId.None;
|
||||
}
|
||||
train.GoingToDepot = c.Depot;
|
||||
train.Line = LineId.None;
|
||||
if (train.State == TrainState.NoRoute) train.State = TrainState.Waiting;
|
||||
@@ -534,6 +581,7 @@ public static class RailCommandHandlers
|
||||
s.Industries.Clear();
|
||||
s.Towns.Clear();
|
||||
s.Hubs.Clear();
|
||||
s.Depots.Clear();
|
||||
if (w.Network.Nodes[s.Node.Value].Station != s.Id) return;
|
||||
foreach (var i in w.Industries)
|
||||
{
|
||||
@@ -547,6 +595,10 @@ public static class RailCommandHandlers
|
||||
{
|
||||
if (Vec2.Distance(h.Position, s.Position) <= km * 1000) s.Hubs.Add(h.Id);
|
||||
}
|
||||
foreach (var d in w.Network.Depots)
|
||||
{
|
||||
if (d.Owner == s.Owner && w.Network.IsAlive(d) && Vec2.Distance(d.Position, s.Position) <= km * 1000) s.Depots.Add(d.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private static string DefaultName(World w, Vec2 p, string kind)
|
||||
|
||||
Reference in new issue
Block a user