F6: ere e obsolescenza, correzioni della revisione
Due revisori hanno trovato 12 rilievi. I principali: - Il rinnovo si ricontrolla all'avvio dei lavori: piano, spesa e cassa possono cambiare tra prenotazione e avvio. Se la cassa non basta il rinnovo si annulla senza pagare e con un avviso, così non va mai in scoperto. - La cassa impegnata dai rinnovi prenotati e non ancora avviati (Obsolescence.Committed) conta per il giocatore e per le IA, così la stessa cassa non si spende due volte nello stesso mese. - Le IA comprano il successore solo se non peggiora il treno, e rinnovano solo se le prestazioni restano almeno quelle di oggi. - Dopo un deragliamento la ricostruzione non ringiovanisce nel patrimonio un modello fuori produzione. - Quadro della flotta e pannelli mostrano un rinnovo già prenotato e la spesa netta al netto degli altri rinnovi. Suite completa 210 su 210, client senza avvisi. Refs #41. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f7c286bf1d
commit
b7737455c6
18 files changed
+447
-96
No files matched your search
@@ -53,7 +53,7 @@ public sealed class EraSystem : ISimSystem
|
||||
var e = new GameEvent(w.Clock.Day, EventKind.Technology, EventSeverity.Opportunity, text, Company: CompanyId.None);
|
||||
w.Events.Add(e);
|
||||
if (w.Companies.Count > 0)
|
||||
Corporate.Milestone(w, w.Player, era is not null ? $"inizia l'{era.NameIt}" : $"novità del {year}: {Join(Unlocks(w.Data, year).Select(u => u.TextIt))}");
|
||||
Corporate.Milestone(w, w.Player, era is not null ? $"inizia l'{era.NameIt}" : $"novità del {year}: {string.Join("; ", NewsParts(w.Data, year))}");
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -126,17 +126,24 @@ public sealed class EraSystem : ISimSystem
|
||||
public static string? NewsText(GameData d, int year)
|
||||
{
|
||||
var era = EraStarting(d, year);
|
||||
var parts = NewsParts(d, year);
|
||||
if (era is null && parts.Count == 0) return null;
|
||||
string head = era is not null ? $"Inizia l'{era.NameIt} ({year})" : $"Novità del {year}";
|
||||
return parts.Count == 0 ? head : $"{head}: {string.Join("; ", parts)}";
|
||||
}
|
||||
|
||||
/// <summary>Parti della notizia dell'anno: sblocchi, modelli superati, fuori produzione (vuota se nessuna).</summary>
|
||||
public static List<string> NewsParts(GameData d, int year)
|
||||
{
|
||||
var unlocks = Unlocks(d, year);
|
||||
var retired = Retired(d, year);
|
||||
var superseded = NewlySuperseded(d, year);
|
||||
if (era is null && unlocks.Count == 0 && retired.Count == 0 && superseded.Count == 0) return null;
|
||||
var parts = new List<string>();
|
||||
if (unlocks.Count > 0) parts.Add($"sblocca {Join(unlocks.Select(u => u.TextIt))}");
|
||||
if (superseded.Count > 0)
|
||||
parts.Add($"{(superseded.Count == 1 ? "modello superato" : "modelli superati")}: {Join(superseded.Select(v => $"{v.NameIt} (successore {v.SuccessorDef!.NameIt})"))}");
|
||||
if (retired.Count > 0) parts.Add($"fuori produzione: {Join(retired.Select(v => v.NameIt))}");
|
||||
string head = era is not null ? $"Inizia l'{era.NameIt} ({year})" : $"Novità del {year}";
|
||||
return parts.Count == 0 ? head : $"{head}: {string.Join("; ", parts)}";
|
||||
return parts;
|
||||
}
|
||||
|
||||
private static string Join(IEnumerable<string> items)
|
||||
|
||||
@@ -200,12 +200,8 @@ public static class Fleet
|
||||
var m = w.Data.Maintenance;
|
||||
long today = w.Clock.Day;
|
||||
double ef = policy.EffectFactor;
|
||||
if (def.Effect == InterventionEffect.Renew)
|
||||
{
|
||||
// rinnovo: i veicoli superati si vendono e al loro posto entrano i successori nuovi (ADR 0020)
|
||||
Obsolescence.Renew(w, t);
|
||||
return;
|
||||
}
|
||||
// rinnovo: i veicoli superati si sono già sostituiti all'avvio dei lavori, quando si è pagato (ADR 0020)
|
||||
if (def.Effect == InterventionEffect.Renew) return;
|
||||
foreach (var id in t.Vehicles)
|
||||
{
|
||||
var v = w.Vehicles[id.Value];
|
||||
@@ -239,11 +235,17 @@ public static class Fleet
|
||||
Raise(v, t.FailedComponent, def.RestoreTo ?? 100, ef);
|
||||
break;
|
||||
case InterventionEffect.Replace:
|
||||
// veicolo sostituito: nuovo di fabbrica
|
||||
// veicolo ricostruito: componenti nuovi di fabbrica. L'età contabile riparte solo se il
|
||||
// modello è ancora in produzione: un modello che non si compra più non torna nuovo nel
|
||||
// patrimonio (ADR 0020), l'usura però riparte da capo
|
||||
for (int j = 0; j < v.Components.Length; j++) v.Components[j] = 100;
|
||||
v.BoughtDay = today;
|
||||
if (Obsolescence.InProduction(v.Def, w.Clock.Year))
|
||||
{
|
||||
v.BoughtDay = today;
|
||||
v.AgeFactorOffset = 0;
|
||||
}
|
||||
else v.AgeFactorOffset = Math.Max(0, RawAgeFactor(m.Wear, v, today, w.Calendar.DaysPerYear) - 1);
|
||||
v.OdometerKm = 0;
|
||||
v.AgeFactorOffset = 0;
|
||||
Array.Clear(v.WearEma);
|
||||
MarkInspection(v, today);
|
||||
MarkService(v, today);
|
||||
|
||||
@@ -489,7 +489,13 @@ public sealed class FleetMaintenanceSystem : ISimSystem
|
||||
waitingParts = true;
|
||||
continue;
|
||||
}
|
||||
Start(ctx, d, job, t, rate);
|
||||
if (!Start(ctx, d, job, t, rate))
|
||||
{
|
||||
// rinnovo annullato all'avvio: il treno esce dall'officina senza lavori
|
||||
d.Jobs.RemoveAt(i--);
|
||||
inStall--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
job.Progress += rate;
|
||||
if (job.Progress + 1e-9 < job.Days) continue;
|
||||
@@ -507,19 +513,50 @@ public sealed class FleetMaintenanceSystem : ISimSystem
|
||||
else if (!waitingParts) d.PartsAlerted = false;
|
||||
}
|
||||
|
||||
private static void Start(WorldContext ctx, Depot d, WorkshopJob job, Train t, double rate)
|
||||
/// <summary>Avvia il lavoro: preleva i ricambi e paga l'intervento. Falso se un rinnovo si annulla.</summary>
|
||||
private static bool Start(WorldContext ctx, Depot d, WorkshopJob job, Train t, double rate)
|
||||
{
|
||||
var w = ctx.World;
|
||||
var m = w.Data.Maintenance;
|
||||
var def = m.Interventions[job.Intervention];
|
||||
var cost = Fleet.CostOf(w, t, def, Fleet.PolicyOf(w, t));
|
||||
List<RenewalItem>? plan = null;
|
||||
if (def.Effect == InterventionEffect.Renew)
|
||||
{
|
||||
// rinnovo (ADR 0020): piano, spesa e cassa si controllano qui, quando si paga, non solo alla
|
||||
// prenotazione: tra le due l'anno può cambiare il piano e la cassa può essersi spesa altrove
|
||||
plan = Obsolescence.RenewalPlan(w, t);
|
||||
var total = Obsolescence.NetCost(plan) + cost;
|
||||
var company = w.Companies[t.Owner.Value];
|
||||
string? why = plan.Count == 0 ? "nessun veicolo superato con un successore in produzione"
|
||||
: total.IsPositive && company.Cash < total ? $"cassa insufficiente per la spesa netta di {total}" : null;
|
||||
if (why is not null)
|
||||
{
|
||||
t.InWorkshop = false;
|
||||
t.MaintenanceDepot = DepotId.None;
|
||||
t.PlannedIntervention = -1;
|
||||
w.Events.Add(new GameEvent(ctx.Day, EventKind.Maintenance, EventSeverity.Warning,
|
||||
$"{t.Name}: rinnovo annullato a {d.Name}, {why}", EntityKind.Train, t.Id.Value, t.Owner));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
d.SpareParts -= job.Parts;
|
||||
w.Goods.Consumed[w.Data.SparePartsGood] += job.Parts;
|
||||
var cost = Fleet.CostOf(w, t, def, Fleet.PolicyOf(w, t));
|
||||
if (cost.IsPositive) w.Money.Transfer(Account.Of(t.Owner), Account.External, cost, LedgerEntry.FleetMaintenance);
|
||||
job.CostCents = cost.Cents;
|
||||
job.Started = true;
|
||||
t.MaintenanceThisYear += cost.Cents;
|
||||
if (plan is not null)
|
||||
{
|
||||
// i veicoli si sostituiscono all'avvio, con il piano appena pagato; i giorni d'officina sono la messa in servizio
|
||||
var net = Obsolescence.NetCost(plan);
|
||||
int renewed = Obsolescence.Renew(w, t, plan);
|
||||
string what = renewed == 1 ? "1 veicolo sostituito" : $"{renewed} veicoli sostituiti";
|
||||
w.Events.Add(new GameEvent(ctx.Day, EventKind.Maintenance, EventSeverity.Info,
|
||||
$"{t.Name}: rinnovo avviato a {d.Name}, {what} (spesa netta {net + cost})", EntityKind.Train, t.Id.Value, t.Owner));
|
||||
}
|
||||
if (job.Days / rate >= m.Planner.ReserveMinDays) Cover(ctx, t, d);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void Complete(WorldContext ctx, Depot d, WorkshopJob job, Train t)
|
||||
@@ -527,7 +564,6 @@ public sealed class FleetMaintenanceSystem : ISimSystem
|
||||
var w = ctx.World;
|
||||
var m = w.Data.Maintenance;
|
||||
var def = m.Interventions[job.Intervention];
|
||||
int renewed = def.Effect == InterventionEffect.Renew ? Obsolescence.RenewalPlan(w, t).Count : 0;
|
||||
Fleet.Apply(w, t, def, Fleet.PolicyOf(w, t));
|
||||
bool repair = def.Effect is InterventionEffect.Repair or InterventionEffect.Replace;
|
||||
if (def.Effect != InterventionEffect.Inspection)
|
||||
@@ -552,9 +588,8 @@ public sealed class FleetMaintenanceSystem : ISimSystem
|
||||
}
|
||||
else if (def.Effect == InterventionEffect.Renew)
|
||||
{
|
||||
string what = renewed == 1 ? "1 veicolo sostituito" : $"{renewed} veicoli sostituiti";
|
||||
w.Events.Add(new GameEvent(ctx.Day, EventKind.Maintenance, EventSeverity.Info,
|
||||
$"{t.Name}: rinnovo completato a {d.Name}, {what}", EntityKind.Train, t.Id.Value, t.Owner));
|
||||
$"{t.Name}: rinnovo completato a {d.Name}", EntityKind.Train, t.Id.Value, t.Owner));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,16 +116,85 @@ public static class Obsolescence
|
||||
return new Money(cents);
|
||||
}
|
||||
|
||||
/// <summary>Indice in maintenance.json dell'intervento con effetto «renew» (il validatore ne garantisce uno).</summary>
|
||||
public static int RenewalIntervention(GameData d) => d.Maintenance.Interventions.FindIndex(i => i.Effect == InterventionEffect.Renew);
|
||||
|
||||
/// <summary>Spesa complessiva del rinnovo del treno oggi: successori − rivendite + lavoro dell'officina.</summary>
|
||||
public static Money RenewalCost(World w, Train t, List<RenewalItem> plan) =>
|
||||
NetCost(plan) + Fleet.CostOf(w, t, w.Data.Maintenance.Interventions[RenewalIntervention(w.Data)], Fleet.PolicyOf(w, t));
|
||||
|
||||
/// <summary>Vero se il treno ha un rinnovo prenotato o in officina.</summary>
|
||||
public static bool RenewalBooked(World w, Train t) => t.PlannedIntervention >= 0 && t.PlannedIntervention == RenewalIntervention(w.Data);
|
||||
|
||||
/// <summary>
|
||||
/// Rinnovo in officina (intervento con effetto «renew»): ogni veicolo superato del treno si vende al
|
||||
/// valore di rivendita (voce «vendita di treni») e al suo posto, nella stessa posizione della
|
||||
/// composizione, entra un veicolo nuovo del successore consigliato (voce «acquisto di treni»). I
|
||||
/// veicoli venduti restano nell'elenco con <c>Sold</c>, come quelli di <c>SellVehicle</c>.
|
||||
/// Restituisce quanti veicoli sono stati sostituiti.
|
||||
/// Spesa impegnata dal rinnovo prenotato del treno e non ancora pagata: la spesa di oggi (se positiva)
|
||||
/// finché i lavori non partono. All'avvio i veicoli si sostituiscono e il piano si svuota, quindi un
|
||||
/// rinnovo già pagato non impegna più nulla.
|
||||
/// </summary>
|
||||
public static int Renew(World w, Train t)
|
||||
public static Money Commitment(World w, Train t)
|
||||
{
|
||||
if (t.Removed || !RenewalBooked(w, t)) return Money.Zero;
|
||||
var plan = RenewalPlan(w, t);
|
||||
if (plan.Count == 0) return Money.Zero;
|
||||
var cost = RenewalCost(w, t, plan);
|
||||
return cost.IsPositive ? cost : Money.Zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spesa impegnata dai rinnovi prenotati della compagnia e non ancora avviati, escluso eventualmente
|
||||
/// un treno: va tolta dalla cassa prima di prenotarne un altro o di investire (ADR 0020).
|
||||
/// </summary>
|
||||
public static Money Committed(World w, CompanyId company, Train? except = null)
|
||||
{
|
||||
long cents = 0;
|
||||
foreach (var t in w.Trains)
|
||||
{
|
||||
if (t != except && t.Owner == company) cents += Commitment(w, t).Cents;
|
||||
}
|
||||
return new Money(cents);
|
||||
}
|
||||
|
||||
/// <summary>Vero se il modello <paramref name="next"/> non ha sforzo di trazione, potenza o velocità massima inferiori a <paramref name="old"/>.</summary>
|
||||
public static bool NoWorseThan(VehicleDef next, VehicleDef old) =>
|
||||
next.TractiveEffortKn >= old.TractiveEffortKn && next.PowerKw >= old.PowerKw && next.MaxSpeedKmh >= old.MaxSpeedKmh;
|
||||
|
||||
/// <summary>
|
||||
/// Vero se il rinnovo non peggiora le prestazioni del treno: sforzo di trazione, potenza, velocità
|
||||
/// massima e rapporto potenza/massa restano almeno quelli di oggi. Le IA rinnovano solo così; il
|
||||
/// giocatore vede il successore con le sue prestazioni e decide da sé.
|
||||
/// </summary>
|
||||
public static bool KeepsPerformance(World w, Train t, List<RenewalItem> plan)
|
||||
{
|
||||
double te = 0, power = 0, mass = 0, vmax = double.MaxValue;
|
||||
double te2 = 0, power2 = 0, mass2 = 0, vmax2 = double.MaxValue;
|
||||
foreach (var id in t.Vehicles)
|
||||
{
|
||||
var def = w.Vehicles[id.Value].Def;
|
||||
var next = def;
|
||||
foreach (var item in plan)
|
||||
{
|
||||
if (item.Old.Id == id) next = item.Successor;
|
||||
}
|
||||
te += def.TractiveEffortKn; power += def.PowerKw; mass += def.MassT; vmax = Math.Min(vmax, def.MaxSpeedKmh);
|
||||
te2 += next.TractiveEffortKn; power2 += next.PowerKw; mass2 += next.MassT; vmax2 = Math.Min(vmax2, next.MaxSpeedKmh);
|
||||
}
|
||||
if (mass <= 0 || mass2 <= 0) return true;
|
||||
const double eps = 1e-9;
|
||||
return te2 + eps >= te && power2 + eps >= power && vmax2 + eps >= vmax && power2 / mass2 + eps >= power / mass;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rinnovo in officina (intervento con effetto «renew»), all'avvio dei lavori: ogni veicolo del piano
|
||||
/// si vende al valore di rivendita (voce «vendita di treni») e al suo posto, nella stessa posizione
|
||||
/// della composizione, entra un veicolo nuovo del successore consigliato (voce «acquisto di treni»).
|
||||
/// I veicoli venduti restano nell'elenco con <c>Sold</c>, come quelli di <c>SellVehicle</c>.
|
||||
/// Il controllo della cassa spetta a chi chiama. Restituisce quanti veicoli sono stati sostituiti.
|
||||
/// </summary>
|
||||
public static int Renew(World w, Train t) => Renew(w, t, RenewalPlan(w, t));
|
||||
|
||||
/// <summary>Rinnovo con un piano già calcolato oggi (vedi <see cref="Renew(World, Train)"/>).</summary>
|
||||
public static int Renew(World w, Train t, List<RenewalItem> plan)
|
||||
{
|
||||
if (plan.Count == 0) return 0;
|
||||
var owner = Account.Of(t.Owner);
|
||||
foreach (var item in plan)
|
||||
|
||||
Reference in new issue
Block a user