F6: eventi del mondo con effetti temporanei e notizie

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>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-07 16:59:48 +01:00
1 parent b258e0858a
commit 1f8da87e51
41 files changed
+1892 -41

No files matched your search

@@ -229,6 +229,7 @@ public static class DataValidator
if (t.Kind is ContractKind.Deliver or ContractKind.Service && t.Quantity is null) Err("contracts.json", $"{t.Id}: richiede quantity");
if (t.Kind == ContractKind.GreatWork && t.LengthKm is null) Err("contracts.json", $"{t.Id}: una grande opera richiede lengthKm");
}
ValidateEvents(d, goodIds, errors);
Unique("regions.json", d.Regions.Regions.Select(r => r.Id), errors);
Unique("regions.json", d.Regions.NamePools.Select(r => r.Id), errors);
var pools = d.Regions.NamePools.Select(p => p.Id).ToHashSet(StringComparer.Ordinal);
@@ -238,6 +239,44 @@ public static class DataValidator
}
}
/// <summary>Effetti ammessi per ogni bersaglio (ADR 0017).</summary>
public static bool EffectFits(EventTarget target, EventEffectKind effect) => effect switch
{
EventEffectKind.IndustryCapacity => target == EventTarget.Industry,
EventEffectKind.TownDemand => target == EventTarget.Town,
EventEffectKind.GoodDemand => target == EventTarget.TownGood,
EventEffectKind.Attendance => target is EventTarget.Town or EventTarget.Depot,
EventEffectKind.TrainSpeed or EventEffectKind.TrackWear => target == EventTarget.Area,
_ => false,
};
private static void ValidateEvents(GameData d, HashSet<string> goodIds, List<string> errors)
{
const string file = "events.json";
Unique(file, d.Events.Events.Select(e => e.Id), errors);
foreach (var e in d.Events.Events)
{
string p = $"{e.Id}:";
if (e.DurationDays[0] > e.DurationDays[1]) errors.Add($"{file}: {p} durationDays [min, max] invertito");
bool zone = e.Target is EventTarget.Area or EventTarget.TownGood;
if (zone && e.RadiusKm is null) errors.Add($"{file}: {p} il bersaglio «{e.Target}» richiede radiusKm");
if (!zone && e.RadiusKm is not null) errors.Add($"{file}: {p} radiusKm vale solo per area e townGood");
if (e.Goods is not null && e.Target != EventTarget.TownGood) errors.Add($"{file}: {p} goods vale solo per townGood");
if (e.IndustryKinds is not null && e.Target != EventTarget.Industry) errors.Add($"{file}: {p} industryKinds vale solo per industry");
foreach (string g in e.Goods ?? [])
{
if (!goodIds.Contains(g)) errors.Add($"{file}: {p} bene sconosciuto «{g}»");
else if (d.Goods.First(x => x.Id == g).Town is null) errors.Add($"{file}: {p} «{g}» non è un bene di consumo delle città");
}
Unique(file, e.Effects.Select(x => x.Kind.ToString()), errors, $"{p} effetti");
foreach (var x in e.Effects)
{
if (x.Min > x.Max) errors.Add($"{file}: {p} effetto {x.Kind} con min > max");
if (!EffectFits(e.Target, x.Kind)) errors.Add($"{file}: {p} l'effetto {x.Kind} non si applica al bersaglio {e.Target}");
}
}
}
private static void CheckCarComponents(VehicleDef v, HashSet<string> carComponents, List<string> errors)
{
foreach (string c in v.Components.Keys)