F6: eventi del mondo, correzioni della revisione
Allinea i giorni degli eventi a quelli annunciati, toglie le sovrapposizioni
di zona e impedisce che l'IA trasformi un effetto temporaneo in un
investimento permanente.
- Un evento è in vigore nei giorni [inizio, fine) per tutti: le
interrogazioni di WorldEventState contano solo gli eventi in vigore nel
giorno dell'orologio, l'usura conta il maltempo del giorno del traffico.
Il maltempo non rallenta più i treni il giorno dell'estrazione e agisce
per intero l'ultimo giorno; l'evento esce dall'elenco il mattino del
primo giorno libero, con la notizia di fine. {until} è l'ultimo giorno.
- Niente zone sovrapposte tra due maltempi o tra due eventi sulla domanda
dello stesso bene (né due boom né boom e crollo insieme): nessuna città
e nessun arco ricevono due volte lo stesso effetto.
- IA: stime dei candidati sulla domanda senza eventi, sui posti scoperti
senza le assenze di epidemie e scioperi (PresentWithoutEvents) e
sull'efficienza senza il moltiplicatore di capacità (ADR 0017 §9).
- Client: conto alla rovescia dalla durata a 1 e «da domani» per gli
eventi estratti oggi; avviso anche nelle città della zona e nel Registro
officina del deposito in sciopero; dal resoconto il notiziario prende
solo le notizie di fine, le altre arrivano già come Notification.
ADR 0017, STATE, ARCHITECTURE e PROTOCOL aggiornati; 2 test nuovi e
3 adattati alla nuova finestra.
Refs #33.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1f8da87e51
commit
5a4a156d52
14 files changed
+309
-54
No files matched your search
@@ -2,6 +2,7 @@ using RailEnterprise.Core.Common;
|
||||
using RailEnterprise.Core.Data;
|
||||
using RailEnterprise.Core.Economy;
|
||||
using RailEnterprise.Core.Rail;
|
||||
using RailEnterprise.Core.Time;
|
||||
|
||||
namespace RailEnterprise.Core.Simulation;
|
||||
|
||||
@@ -31,6 +32,9 @@ public sealed class ActiveWorldEvent
|
||||
|
||||
public int DurationDays => (int)(EndDay - StartDay);
|
||||
|
||||
/// <summary>Vero se l'evento è in vigore nel giorno indicato: [StartDay, EndDay).</summary>
|
||||
public bool InForce(long day) => StartDay <= day && day < EndDay;
|
||||
|
||||
/// <summary>Moltiplicatore dell'effetto indicato (1 se il tipo non ce l'ha).</summary>
|
||||
public double Effect(EventEffectKind kind)
|
||||
{
|
||||
@@ -59,13 +63,18 @@ public sealed class ActiveWorldEvent
|
||||
/// <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).
|
||||
/// evento scaduto tutto torna come prima. L'elenco è in ordine d'inizio (id crescente) e contiene
|
||||
/// gli eventi dall'estrazione fino al mattino del primo giorno libero: le interrogazioni contano solo
|
||||
/// quelli in vigore nel giorno dell'orologio (<see cref="ActiveWorldEvent.InForce"/>), così un evento
|
||||
/// estratto oggi agisce da domani anche sui treni e l'ultimo giorno agisce per intero (ADR 0017 §5).
|
||||
/// </summary>
|
||||
public sealed class WorldEventState
|
||||
public sealed class WorldEventState(GameClock clock)
|
||||
{
|
||||
private readonly List<ActiveWorldEvent> _active = [];
|
||||
private int _areaEvents;
|
||||
|
||||
private long Today => clock.Day;
|
||||
|
||||
public IReadOnlyList<ActiveWorldEvent> Active => _active;
|
||||
|
||||
/// <summary>Prossimo id libero (mai riutilizzato).</summary>
|
||||
@@ -108,7 +117,17 @@ public sealed class WorldEventState
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Eventi che riguardano un'entità (bersaglio diretto o città centro di una zona).</summary>
|
||||
/// <summary>Vero se un evento in elenco (anche non ancora iniziato) ha l'effetto indicato.</summary>
|
||||
public bool AnyWith(EventEffectKind kind)
|
||||
{
|
||||
foreach (var e in _active)
|
||||
{
|
||||
if (e.Has(kind)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Eventi il cui bersaglio diretto è l'entità (anche non ancora iniziati).</summary>
|
||||
public IEnumerable<ActiveWorldEvent> For(EntityKind kind, int index)
|
||||
{
|
||||
foreach (var e in _active)
|
||||
@@ -121,9 +140,10 @@ public sealed class WorldEventState
|
||||
public double IndustryCapacity(IndustryId industry)
|
||||
{
|
||||
double f = 1.0;
|
||||
long day = Today;
|
||||
foreach (var e in _active)
|
||||
{
|
||||
if (e.TargetKind == EntityKind.Industry && e.Target == industry.Value) f *= e.Effect(EventEffectKind.IndustryCapacity);
|
||||
if (e.TargetKind == EntityKind.Industry && e.Target == industry.Value && e.InForce(day)) f *= e.Effect(EventEffectKind.IndustryCapacity);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
@@ -133,8 +153,10 @@ public sealed class WorldEventState
|
||||
{
|
||||
if (_active.Count == 0) return 1.0;
|
||||
double f = 1.0;
|
||||
long day = Today;
|
||||
foreach (var e in _active)
|
||||
{
|
||||
if (!e.InForce(day)) continue;
|
||||
switch (e.Def.Target)
|
||||
{
|
||||
case EventTarget.Town when e.Target == town.Id.Value:
|
||||
@@ -156,8 +178,10 @@ public sealed class WorldEventState
|
||||
{
|
||||
if (_active.Count == 0) return 1.0;
|
||||
double f = 1.0;
|
||||
long day = Today;
|
||||
foreach (var e in _active)
|
||||
{
|
||||
if (!e.InForce(day)) continue;
|
||||
bool hit = e.Def.Target switch
|
||||
{
|
||||
EventTarget.Town => e.Target == town.Value,
|
||||
@@ -169,20 +193,23 @@ public sealed class WorldEventState
|
||||
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>Velocità dei treni sull'arco (TrainSystem, a ogni tick): aree di maltempo in vigore oggi che contengono il suo punto medio.</summary>
|
||||
public double EdgeSpeed(TrackEdge edge) => _areaEvents == 0 ? 1.0 : AreaEffect(edge, EventEffectKind.TrainSpeed, Today);
|
||||
|
||||
/// <summary>Usura del binario dovuta al traffico sull'arco (ConstructionSystem).</summary>
|
||||
public double EdgeWear(TrackEdge edge) => _areaEvents == 0 ? 1.0 : AreaEffect(edge, EventEffectKind.TrackWear);
|
||||
/// <summary>
|
||||
/// Usura del binario dovuta al traffico sull'arco (ConstructionSystem): il sistema la applica al
|
||||
/// mattino al traffico del giorno prima, quindi conta il maltempo in vigore ieri.
|
||||
/// </summary>
|
||||
public double EdgeWear(TrackEdge edge) => _areaEvents == 0 ? 1.0 : AreaEffect(edge, EventEffectKind.TrackWear, Today - 1);
|
||||
|
||||
private double AreaEffect(TrackEdge edge, EventEffectKind kind)
|
||||
private double AreaEffect(TrackEdge edge, EventEffectKind kind, long day)
|
||||
{
|
||||
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);
|
||||
if (e.Def.Target == EventTarget.Area && e.InForce(day) && e.InZone(p)) f *= e.Effect(kind);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user