Aggiunge gli eventi della F6: fatti del mondo che cambiano il gioco per un periodo limitato, leggibili nel notiziario e reversibili. - Catalogo data/events.json con schema e validazione: incidente e boom di un'industria, fiera ed epidemia, boom e crollo della domanda di un bene in una zona, maltempo su un'area, sciopero di città o deposito. - Effetti come moltiplicatori letti da un'unica sorgente (World.WorldEvents) dai sistemi esistenti: capacità delle industrie, consumi delle città, presenze dei pendolari, velocità dei treni e usura del binario. A evento finito il moltiplicatore torna 1. - EventSystem tra le IA e l'hash, con flusso Rng dedicato «events», bersaglio in ordine di id, frequenza per mappa scalata dalla difficoltà (eventFrequencyMultiplier), tetto di 6, niente doppioni, notizie di inizio e fine in italiano (EventKind.World). - Salvataggio corpo versione 5 con gli eventi nell'hash; le versioni 1-4 si caricano senza eventi e con la frequenza del preset. - Protocollo: eventi in corso nel DailyDigest e nel MarketReport; client con il riquadro «Eventi in corso», avvisi nelle schede e «evento in corso» nel Mercato globale. - Lo scenario Valdoria disattiva gli eventi: con gli eventi attivi la flotta F4 senza linea dei ricambi non scendeva più sotto 40, e l'accettazione deve misurare la manutenzione, non la fortuna (ADR 0017). Accettazione F4 invariata: 35 / 20 guasti senza linea, 75 / 2 con. Decisioni in docs/adr/0017-eventi-del-mondo.md; 17 test nuovi. Refs #33. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using System.Diagnostics;
|
|
using RailEnterprise.Core.Simulation.Ai;
|
|
using RailEnterprise.Core.Simulation.Systems;
|
|
|
|
namespace RailEnterprise.Core.Simulation;
|
|
|
|
/// <summary>
|
|
/// Sistemi nell'ordine fisso della guida (sezione 4). I sistemi delle fasi successive si
|
|
/// inseriscono nella loro posizione quando vengono implementati:
|
|
/// Clock → Commands → Construction → Trains → Signals → Stations (+ trasporto locale)
|
|
/// → Maintenance → Demand → Commuting → Industries → IndustryMaintenance → Towns → Market
|
|
/// → Finance → StockMarket → AiAgents → Events → Contracts → Hash.
|
|
/// </summary>
|
|
public sealed class SystemPipeline(IReadOnlyList<ISimSystem> systems)
|
|
{
|
|
public IReadOnlyList<ISimSystem> Systems { get; } = systems;
|
|
|
|
/// <summary>Se attivo, misura il tempo di ogni sistema (diagnostica e bench).</summary>
|
|
public bool Profile { get; set; }
|
|
|
|
/// <summary>Tick totali (Stopwatch) spesi per sistema quando Profile è attivo.</summary>
|
|
public long[] ElapsedTicks { get; } = new long[systems.Count];
|
|
|
|
/// <summary>Byte allocati per sistema quando Profile è attivo.</summary>
|
|
public long[] AllocatedBytes { get; } = new long[systems.Count];
|
|
|
|
public static SystemPipeline CreateDefault() => new(
|
|
[
|
|
new ClockSystem(),
|
|
new CommandSystem(),
|
|
new ConstructionSystem(),
|
|
new TrainSystem(),
|
|
new StationSystem(),
|
|
new LocalTransportSystem(),
|
|
new FleetMaintenanceSystem(),
|
|
new DemandSystem(),
|
|
new EmploymentSystem(),
|
|
new IndustrySystem(),
|
|
new IndustryMaintenanceSystem(),
|
|
new TownSystem(),
|
|
new MarketSystem(),
|
|
new FinanceSystem(),
|
|
new StockMarketSystem(),
|
|
new AiSystem(),
|
|
new EventSystem(),
|
|
new HashSystem(),
|
|
]);
|
|
|
|
public void Run(WorldContext ctx)
|
|
{
|
|
if (!Profile)
|
|
{
|
|
for (int i = 0; i < Systems.Count; i++) Systems[i].Step(ctx);
|
|
return;
|
|
}
|
|
for (int i = 0; i < Systems.Count; i++)
|
|
{
|
|
long bytes = GC.GetAllocatedBytesForCurrentThread();
|
|
long start = Stopwatch.GetTimestamp();
|
|
Systems[i].Step(ctx);
|
|
ElapsedTicks[i] += Stopwatch.GetTimestamp() - start;
|
|
AllocatedBytes[i] += GC.GetAllocatedBytesForCurrentThread() - bytes;
|
|
}
|
|
}
|
|
|
|
public T Get<T>() where T : ISimSystem => Systems.OfType<T>().First();
|
|
}
|