Infrastruttura: nome «Rail Enterprise», CI e rilasci su Gitea, documentazione
Il progetto adotta il nome «Rail Enterprise» ovunque (codice RailEnterprise.*, variabili RE_*, intestazioni RESV/RECL, immagine rail-enterprise-server) per allinearsi al repository Gitea. Aggiunge Gitea Actions sul modello di Chronos: CI su PR e main, rilascio da tag con gioco Windows (client Godot + server in server/), server Windows/Linux e immagine Docker nel registro Gitea, nightly. Aggiunge i riferimenti visivi 06–09, i modelli di PR e issue, l'ADR 0014 e aggiorna README (comandi locali), STATE e CLAUDE.md. 120 test verdi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f6c2a17b4d
commit
c1a0049bcf
300 files changed
+1602
-1045
No files matched your search
@@ -0,0 +1,136 @@
|
||||
using RailEnterprise.Core.Commands;
|
||||
using RailEnterprise.Core.Common;
|
||||
using RailEnterprise.Core.Data;
|
||||
using RailEnterprise.Core.Economy;
|
||||
using RailEnterprise.Core.Rail;
|
||||
using RailEnterprise.Core.Simulation.Systems;
|
||||
|
||||
namespace RailEnterprise.Core.Simulation;
|
||||
|
||||
/// <summary>Comandi della manutenzione della flotta (10.2–10.3) e delle convenzioni di pendolarismo (9).</summary>
|
||||
public static class MaintenanceCommandHandlers
|
||||
{
|
||||
public static CommandResult SetReserve(World w, Company company, SetReserveCommand c, RailCommandHandlers.Reply reply)
|
||||
{
|
||||
if (!TryTrain(w, c.Train, company, out var train)) return reply(CommandError.NotFound, "Treno inesistente");
|
||||
if (!c.Reserve)
|
||||
{
|
||||
train.Reserve = false;
|
||||
return reply(CommandError.None, $"{train.Name} non è più una riserva");
|
||||
}
|
||||
if (train.Covering.IsValid) return reply(CommandError.NotAllowed, $"{train.Name} sta già coprendo una linea");
|
||||
if (!train.HomeDepot.IsValid || !w.Network.IsAlive(w.Network.Depots[train.HomeDepot.Value]))
|
||||
return reply(CommandError.NotAllowed, "Il treno non ha un deposito di appartenenza");
|
||||
train.Reserve = true;
|
||||
if (train.Line.IsValid)
|
||||
{
|
||||
train.Line = LineId.None;
|
||||
w.LineGraphs.Touch();
|
||||
}
|
||||
var home = w.Network.Depots[train.HomeDepot.Value];
|
||||
if (train.AtNode != home.Node && !train.InWorkshop && !train.MaintenanceDepot.IsValid)
|
||||
{
|
||||
train.GoingToDepot = home.Id;
|
||||
if (train.State == TrainState.NoRoute) train.State = TrainState.Waiting;
|
||||
}
|
||||
return reply(CommandError.None, $"{train.Name} è una riserva del {home.Name}");
|
||||
}
|
||||
|
||||
public static CommandResult SetPolicy(World w, Company company, SetMaintenancePolicyCommand c, RailCommandHandlers.Reply reply)
|
||||
{
|
||||
MaintenancePolicy? policy = c.Policy switch
|
||||
{
|
||||
"economy" => MaintenancePolicy.Economy,
|
||||
"standard" => MaintenancePolicy.Standard,
|
||||
"thorough" => MaintenancePolicy.Thorough,
|
||||
"" or "inherit" => null,
|
||||
_ => (MaintenancePolicy)255,
|
||||
};
|
||||
if (policy == (MaintenancePolicy)255) return reply(CommandError.InvalidArgument, "Politica: economy, standard, thorough o inherit");
|
||||
string name = policy is { } p ? w.Data.Maintenance.Policy(p).NameIt : "quella generale";
|
||||
switch (c.Scope)
|
||||
{
|
||||
case MaintenanceScope.Company:
|
||||
if (policy is null) return reply(CommandError.InvalidArgument, "La flotta richiede una politica");
|
||||
company.MaintenancePolicy = policy.Value;
|
||||
return reply(CommandError.None, $"Politica di manutenzione della flotta: {name}");
|
||||
case MaintenanceScope.Line:
|
||||
if (c.Target < 0 || c.Target >= w.Lines.Count || w.Lines[c.Target].Owner != company.Id || w.Lines[c.Target].Removed)
|
||||
return reply(CommandError.NotFound, "Linea inesistente");
|
||||
w.Lines[c.Target].Policy = policy;
|
||||
return reply(CommandError.None, $"{w.Lines[c.Target].Name}: politica {name}");
|
||||
case MaintenanceScope.Train:
|
||||
if (!TryTrain(w, new TrainId(c.Target), company, out var train)) return reply(CommandError.NotFound, "Treno inesistente");
|
||||
train.Policy = policy;
|
||||
return reply(CommandError.None, $"{train.Name}: politica {name}");
|
||||
default:
|
||||
return reply(CommandError.InvalidArgument, "Ambito sconosciuto");
|
||||
}
|
||||
}
|
||||
|
||||
public static CommandResult ScheduleService(World w, Company company, ScheduleServiceCommand c, WorldContext ctx, RailCommandHandlers.Reply reply)
|
||||
{
|
||||
if (!TryTrain(w, c.Train, company, out var train)) return reply(CommandError.NotFound, "Treno inesistente");
|
||||
var m = w.Data.Maintenance;
|
||||
int idx = m.InterventionIndex(c.Intervention);
|
||||
if (idx < 0 || m.Interventions[idx].Effect is not (InterventionEffect.Inspection or InterventionEffect.Service or InterventionEffect.Overhaul))
|
||||
return reply(CommandError.InvalidArgument, "Intervento: inspection, service o overhaul");
|
||||
if (train.Vehicles.Count == 0) return reply(CommandError.NotAllowed, "Treno senza veicoli");
|
||||
if (train.InWorkshop) return reply(CommandError.NotAllowed, $"{train.Name} è già in officina");
|
||||
if (train.State == TrainState.Broken) return reply(CommandError.NotAllowed, $"{train.Name} attende il soccorso");
|
||||
if (train.Failure != FailureKind.None) return reply(CommandError.NotAllowed, $"{train.Name} ha un guasto: prima la riparazione");
|
||||
var def = m.Interventions[idx];
|
||||
int parts = Fleet.PartsFor(w, train, def);
|
||||
FleetMaintenanceSystem.CancelBooking(train);
|
||||
if (!FleetMaintenanceSystem.Book(ctx, train, idx, parts, requireParts: true))
|
||||
return reply(CommandError.Blocked, parts > 0 ? $"Nessun deposito raggiungibile con {parts} ricambi" : "Nessun deposito raggiungibile");
|
||||
var depot = w.Network.Depots[train.MaintenanceDepot.Value];
|
||||
return reply(CommandError.None, $"{train.Name}: {def.NameIt.ToLowerInvariant()} prenotato a {depot.Name}", depot.Id.Value);
|
||||
}
|
||||
|
||||
public static CommandResult OrderParts(World w, Company company, OrderPartsCommand c, RailCommandHandlers.Reply reply)
|
||||
{
|
||||
if (c.Industry.IsValid) return IndustryCommandHandlers.OrderParts(w, company, c, reply);
|
||||
if (!c.Depot.IsValid || c.Depot.Value >= w.Network.Depots.Count) return reply(CommandError.NotFound, "Deposito inesistente");
|
||||
var d = w.Network.Depots[c.Depot.Value];
|
||||
if (d.Owner != company.Id || !w.Network.IsAlive(d)) return reply(CommandError.NotFound, "Deposito inesistente");
|
||||
int max = w.Data.Maintenance.Depots.MaxSpareParts;
|
||||
if (c.Quantity < 0 || c.Quantity > max) return reply(CommandError.InvalidArgument, $"Scorta tra 0 e {max} casse");
|
||||
d.PartsTarget = c.Quantity;
|
||||
string unit = w.Data.Goods[w.Data.SparePartsGood].Unit;
|
||||
return reply(CommandError.None, $"{d.Name}: scorta desiderata di ricambi {c.Quantity} {unit} (oggi {d.SpareParts})");
|
||||
}
|
||||
|
||||
public static CommandResult AcceptAgreement(World w, Company company, AcceptAgreementCommand c, RailCommandHandlers.Reply reply)
|
||||
{
|
||||
var a = w.Agreements.FirstOrDefault(x => x.Id == c.Agreement);
|
||||
if (a is null || a.Carrier != company.Id) return reply(CommandError.NotFound, "Convenzione inesistente");
|
||||
if (a.State != AgreementState.Proposed) return reply(CommandError.NotAllowed, "La convenzione non è più in attesa di risposta");
|
||||
var ab = w.Data.Balance.Employment.Agreements;
|
||||
a.State = AgreementState.Active;
|
||||
a.StartDay = w.Clock.Day;
|
||||
a.EndDay = w.Clock.Day + (long)ab.DurationMonths * w.Calendar.DaysPerMonth;
|
||||
a.Coverage = 1;
|
||||
a.ShortDays = 0;
|
||||
var ind = w.Industries[a.Industry.Value];
|
||||
return reply(CommandError.None, $"Convenzione con {ind.Name}: {a.SeatsPerDay} posti al giorno per {a.MonthlyFee} al mese");
|
||||
}
|
||||
|
||||
public static CommandResult RejectAgreement(World w, Company company, RejectAgreementCommand c, RailCommandHandlers.Reply reply)
|
||||
{
|
||||
var a = w.Agreements.FirstOrDefault(x => x.Id == c.Agreement);
|
||||
if (a is null || a.Carrier != company.Id) return reply(CommandError.NotFound, "Convenzione inesistente");
|
||||
if (a.State != AgreementState.Proposed) return reply(CommandError.NotAllowed, "La convenzione non è più in attesa di risposta");
|
||||
a.State = AgreementState.Rejected;
|
||||
a.EndDay = w.Clock.Day;
|
||||
return reply(CommandError.None, $"Convenzione con {w.Industries[a.Industry.Value].Name} rifiutata");
|
||||
}
|
||||
|
||||
private static bool TryTrain(World w, TrainId id, Company company, out Train train)
|
||||
{
|
||||
train = null!;
|
||||
if (!id.IsValid || id.Value >= w.Trains.Count) return false;
|
||||
train = w.Trains[id.Value];
|
||||
return train.Owner == company.Id && !train.Removed;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user