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:
1 parent
b258e0858a
commit
1f8da87e51
41 files changed
+1892
-41
No files matched your search
@@ -0,0 +1,189 @@
|
||||
using RailEnterprise.Core.Common;
|
||||
using RailEnterprise.Core.Data;
|
||||
using RailEnterprise.Core.Economy;
|
||||
using RailEnterprise.Core.Rail;
|
||||
|
||||
namespace RailEnterprise.Core.Simulation;
|
||||
|
||||
/// <summary>
|
||||
/// Evento del mondo in corso (ADR 0017): tipo del catalogo, bersaglio, bene (per la domanda di un
|
||||
/// bene), giorno d'inizio e di fine e intensità in [0, 1] da cui si ricavano i moltiplicatori.
|
||||
/// </summary>
|
||||
public sealed class ActiveWorldEvent
|
||||
{
|
||||
public required int Id { get; init; }
|
||||
public required WorldEventDef Def { get; init; }
|
||||
/// <summary>Entità bersaglio: industria, città (anche centro di zona e area) o deposito.</summary>
|
||||
public required EntityKind TargetKind { get; init; }
|
||||
public required int Target { get; init; }
|
||||
/// <summary>Bene coinvolto (TownGood), altrimenti −1.</summary>
|
||||
public int Good { get; init; } = -1;
|
||||
public required long StartDay { get; init; }
|
||||
/// <summary>Primo giorno senza l'evento: dura EndDay − StartDay giorni.</summary>
|
||||
public required long EndDay { get; init; }
|
||||
public required double Intensity { get; init; }
|
||||
|
||||
/// <summary>Centro della zona in metri (città bersaglio), per area e domanda di un bene.</summary>
|
||||
public Vec2 Center { get; init; }
|
||||
|
||||
/// <summary>Quadrato del raggio della zona in metri (0 senza zona).</summary>
|
||||
public double RadiusSquaredM { get; init; }
|
||||
|
||||
public int DurationDays => (int)(EndDay - StartDay);
|
||||
|
||||
/// <summary>Moltiplicatore dell'effetto indicato (1 se il tipo non ce l'ha).</summary>
|
||||
public double Effect(EventEffectKind kind)
|
||||
{
|
||||
foreach (var e in Def.Effects)
|
||||
{
|
||||
if (e.Kind == kind) return e.At(Intensity);
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
public bool Has(EventEffectKind kind)
|
||||
{
|
||||
foreach (var e in Def.Effects)
|
||||
{
|
||||
if (e.Kind == kind) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Moltiplicatore dell'effetto principale (il primo del catalogo).</summary>
|
||||
public double Primary => Def.Effects[0].At(Intensity);
|
||||
|
||||
public bool InZone(Vec2 p) => RadiusSquaredM > 0 && (p - Center).LengthSquared <= RadiusSquaredM;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eventi del mondo in corso: unica sorgente dei moltiplicatori temporanei letti dai sistemi. Ogni
|
||||
/// interrogazione restituisce il prodotto degli effetti attivi sull'entità (1 senza eventi), così a
|
||||
/// evento scaduto tutto torna come prima. L'elenco è in ordine d'inizio (id crescente).
|
||||
/// </summary>
|
||||
public sealed class WorldEventState
|
||||
{
|
||||
private readonly List<ActiveWorldEvent> _active = [];
|
||||
private int _areaEvents;
|
||||
|
||||
public IReadOnlyList<ActiveWorldEvent> Active => _active;
|
||||
|
||||
/// <summary>Prossimo id libero (mai riutilizzato).</summary>
|
||||
public int NextId { get; set; }
|
||||
|
||||
internal void Add(ActiveWorldEvent e)
|
||||
{
|
||||
_active.Add(e);
|
||||
Recount();
|
||||
}
|
||||
|
||||
internal void RemoveAt(int index)
|
||||
{
|
||||
_active.RemoveAt(index);
|
||||
Recount();
|
||||
}
|
||||
|
||||
internal void Clear()
|
||||
{
|
||||
_active.Clear();
|
||||
Recount();
|
||||
}
|
||||
|
||||
private void Recount()
|
||||
{
|
||||
_areaEvents = 0;
|
||||
foreach (var e in _active)
|
||||
{
|
||||
if (e.Def.Target == EventTarget.Area) _areaEvents++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Vero se un evento dello stesso tipo è già in corso sullo stesso bersaglio.</summary>
|
||||
public bool IsActive(WorldEventDef def, EntityKind kind, int target)
|
||||
{
|
||||
foreach (var e in _active)
|
||||
{
|
||||
if (e.Def == def && e.TargetKind == kind && e.Target == target) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Eventi che riguardano un'entità (bersaglio diretto o città centro di una zona).</summary>
|
||||
public IEnumerable<ActiveWorldEvent> For(EntityKind kind, int index)
|
||||
{
|
||||
foreach (var e in _active)
|
||||
{
|
||||
if (e.TargetKind == kind && e.Target == index) yield return e;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Capacità produttiva dell'industria (IndustrySystem, DemandSystem).</summary>
|
||||
public double IndustryCapacity(IndustryId industry)
|
||||
{
|
||||
double f = 1.0;
|
||||
foreach (var e in _active)
|
||||
{
|
||||
if (e.TargetKind == EntityKind.Industry && e.Target == industry.Value) f *= e.Effect(EventEffectKind.IndustryCapacity);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>Domanda della città per un bene: eventi sulla città e sul bene nella zona.</summary>
|
||||
public double TownDemand(Town town, int good)
|
||||
{
|
||||
if (_active.Count == 0) return 1.0;
|
||||
double f = 1.0;
|
||||
foreach (var e in _active)
|
||||
{
|
||||
switch (e.Def.Target)
|
||||
{
|
||||
case EventTarget.Town when e.Target == town.Id.Value:
|
||||
f *= e.Effect(EventEffectKind.TownDemand);
|
||||
break;
|
||||
case EventTarget.TownGood when e.Good == good && (e.Target == town.Id.Value || e.InZone(town.Position)):
|
||||
f *= e.Effect(EventEffectKind.GoodDemand);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Quota dei pendolari che si presenta al lavoro: eventi sulla città di provenienza (epidemia,
|
||||
/// sciopero) e sul deposito di destinazione (sciopero del personale).
|
||||
/// </summary>
|
||||
public double Attendance(TownId town, WorkplaceRef workplace)
|
||||
{
|
||||
if (_active.Count == 0) return 1.0;
|
||||
double f = 1.0;
|
||||
foreach (var e in _active)
|
||||
{
|
||||
bool hit = e.Def.Target switch
|
||||
{
|
||||
EventTarget.Town => e.Target == town.Value,
|
||||
EventTarget.Depot => workplace.Kind == WorkplaceKind.Depot && e.Target == workplace.Index,
|
||||
_ => false,
|
||||
};
|
||||
if (hit) f *= e.Effect(EventEffectKind.Attendance);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>Velocità dei treni sull'arco (TrainSystem): aree di maltempo che contengono il suo punto medio.</summary>
|
||||
public double EdgeSpeed(TrackEdge edge) => _areaEvents == 0 ? 1.0 : AreaEffect(edge, EventEffectKind.TrainSpeed);
|
||||
|
||||
/// <summary>Usura del binario dovuta al traffico sull'arco (ConstructionSystem).</summary>
|
||||
public double EdgeWear(TrackEdge edge) => _areaEvents == 0 ? 1.0 : AreaEffect(edge, EventEffectKind.TrackWear);
|
||||
|
||||
private double AreaEffect(TrackEdge edge, EventEffectKind kind)
|
||||
{
|
||||
int mid = edge.X.Length / 2;
|
||||
var p = new Vec2(edge.X[mid], edge.Y[mid]);
|
||||
double f = 1.0;
|
||||
foreach (var e in _active)
|
||||
{
|
||||
if (e.Def.Target == EventTarget.Area && e.InZone(p)) f *= e.Effect(kind);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user