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,41 @@
|
||||
using Godot;
|
||||
using RailEnterprise.Client.App;
|
||||
using RailEnterprise.Client.Panels;
|
||||
using RailEnterprise.Protocol.Client;
|
||||
using static RailEnterprise.Client.App.Localization;
|
||||
|
||||
namespace RailEnterprise.Client.Hud;
|
||||
|
||||
/// <summary>
|
||||
/// Riquadro «Eventi in corso» del pannello destro, sopra la minimappa (ADR 0017): gli eventi del
|
||||
/// mondo attivi dal resoconto giornaliero, con luogo, effetti e scadenza. Nascosto se non ce ne sono.
|
||||
/// </summary>
|
||||
public partial class WorldEventsBox : PanelContainer
|
||||
{
|
||||
private readonly VBoxContainer _list = new();
|
||||
private readonly Label _title = UiTheme.Text("", 13, Palette.AmberLight, bold: true);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
AddThemeStyleboxOverride("panel", UiTheme.Box(Palette.Inner, Palette.Border, 8, 10));
|
||||
var col = new VBoxContainer();
|
||||
col.AddThemeConstantOverride("separation", 6);
|
||||
AddChild(col);
|
||||
col.AddChild(_title);
|
||||
_list.AddThemeConstantOverride("separation", 8);
|
||||
col.AddChild(_list);
|
||||
Visible = false;
|
||||
}
|
||||
|
||||
/// <summary>Ridisegna l'elenco (a ogni resoconto giornaliero).</summary>
|
||||
public void Update(ClientWorld w)
|
||||
{
|
||||
var events = w.LastDigest?.WorldEvents ?? [];
|
||||
Visible = events.Count > 0;
|
||||
foreach (var c in _list.GetChildren()) c.QueueFree();
|
||||
_title.Text = $"{T("Eventi in corso")} ({events.Count})";
|
||||
// al massimo quattro righe: il riquadro non deve schiacciare la minimappa
|
||||
foreach (var e in events.OrderBy(e => e.EndDay).Take(4)) _list.AddChild(WorldEventText.Row(w, e));
|
||||
if (events.Count > 4) _list.AddChild(UiTheme.Text($"+ {events.Count - 4} {T("altri")}", 12, Palette.TextSecondary));
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,7 @@ public partial class InfoPanel : VBoxContainer
|
||||
AddChild(PanelKit.Pair(T("Produce"), PanelKit.Value(outputs)));
|
||||
}
|
||||
if (ind.Closed) AddChild(UiTheme.Notice(T("Chiusa")));
|
||||
WorldEventText.AddNotices(w, this, WorldEventText.Industry, ind.Id);
|
||||
// pannello del proprietario (sezione 11): manutenzione degli impianti o acquisto
|
||||
int me = w.Summary?.CompanyId ?? 0;
|
||||
string owner = ind.Owner == me ? T("La tua compagnia") : ind.Owner < 0 ? T("Proprietari privati") : Fmt.Company(w, ind.Owner);
|
||||
@@ -180,6 +181,7 @@ public partial class InfoPanel : VBoxContainer
|
||||
AddChild(PanelKit.Pair(T("Abitanti"), PanelKit.Value(Money.GroupThousands((ulong)town.Population))));
|
||||
AddChild(PanelKit.Pair(T("Soddisfazione"), PanelKit.Value($"{town.Satisfaction * 100:0}%")));
|
||||
AddChild(PanelKit.Pair(T("Servizi"), PanelKit.Value($"{town.Services}")));
|
||||
WorldEventText.AddNotices(w, this, WorldEventText.Town, town.Id);
|
||||
// dove lavorano gli abitanti (posti serviti dai tuoi treni)
|
||||
if (w.Employment is { } report)
|
||||
{
|
||||
|
||||
@@ -485,15 +485,22 @@ public partial class MarketPanel : VBoxContainer
|
||||
{
|
||||
var card = Card(Palette.Inner, Palette.Inner);
|
||||
var col = (VBoxContainer)card.GetChild(0);
|
||||
if (report.EventGood < 0)
|
||||
if (report.EventGood < 0 && report.GoodEvents.Count == 0)
|
||||
{
|
||||
col.AddChild(UiTheme.Text(T("Nessun evento in corso"), 13, Palette.TextSecondary, bold: true));
|
||||
col.AddChild(Wrapped(T("I prezzi mondiali seguono il loro ciclo pluriennale, senza scosse."), 13, Palette.TextSecondary));
|
||||
return card;
|
||||
}
|
||||
col.AddChild(UiTheme.Text(T("Evento in corso"), 13, Palette.AmberLight, bold: true));
|
||||
// eventi del mondo sulla domanda di un bene in una zona (ADR 0017)
|
||||
foreach (var e in report.GoodEvents)
|
||||
{
|
||||
col.AddChild(Wrapped($"{GoodName(w, e.Good)}: {WorldEventText.Name(w, e).ToLowerInvariant()} {WorldEventText.Where(w, e)}", 17, Palette.Text, bold: true));
|
||||
col.AddChild(Wrapped($"{WorldEventText.Effects(w, e)}, {WorldEventText.Until(w, e)}.", 13, Palette.Text));
|
||||
}
|
||||
if (report.EventGood < 0) return card;
|
||||
bool up = report.EventShock > 0;
|
||||
string good = GoodName(w, report.EventGood);
|
||||
col.AddChild(UiTheme.Text(T("Evento in corso"), 13, Palette.AmberLight, bold: true));
|
||||
col.AddChild(Wrapped(up ? $"{good}: {T("prezzo mondiale in rialzo")}" : $"{good}: {T("prezzo mondiale in calo")}", 17, Palette.Text, bold: true));
|
||||
int months = Math.Max(1, (int)Math.Ceiling(report.EventMonths));
|
||||
col.AddChild(Wrapped($"{T("Il prezzo mondiale di")} {good.ToLowerInvariant()} {(up ? T("è più alto del") : T("è più basso del"))} {Fmt.Pct(Math.Abs(report.EventShock), 0)} " +
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
using Godot;
|
||||
using RailEnterprise.Client.App;
|
||||
using RailEnterprise.Core.Data;
|
||||
using RailEnterprise.Protocol.Client;
|
||||
using RailEnterprise.Protocol.Messages;
|
||||
using static RailEnterprise.Client.App.Localization;
|
||||
|
||||
namespace RailEnterprise.Client.Panels;
|
||||
|
||||
/// <summary>
|
||||
/// Testi degli eventi del mondo in corso (ADR 0017) per l'elenco «Eventi in corso», le schede delle
|
||||
/// entità e il Mercato globale. Solo presentazione: i valori dei moltiplicatori arrivano dal server.
|
||||
/// </summary>
|
||||
public static class WorldEventText
|
||||
{
|
||||
// codici di EntityKind del protocollo
|
||||
private const byte TownEntity = 1, IndustryEntity = 2, DepotEntity = 7;
|
||||
|
||||
private static bool English => TranslationServer.GetLocale().StartsWith("en");
|
||||
|
||||
public static WorldEventDef? Def(ClientWorld w, WorldEventInfo e) => w.Data.Events.Events.FirstOrDefault(d => d.Id == e.Type);
|
||||
|
||||
/// <summary>Nome del tipo di evento nella lingua dell'interfaccia.</summary>
|
||||
public static string Name(ClientWorld w, WorldEventInfo e) =>
|
||||
Def(w, e) is { } d ? (English ? d.NameEn : d.NameIt) : e.Type;
|
||||
|
||||
/// <summary>Nome dell'entità coinvolta (città, industria, deposito).</summary>
|
||||
public static string Target(ClientWorld w, WorldEventInfo e) => e.Entity switch
|
||||
{
|
||||
TownEntity => w.Towns.TryGetValue(e.EntityIndex, out var t) ? t.Name : "?",
|
||||
IndustryEntity => w.Industries.TryGetValue(e.EntityIndex, out var i) ? i.Name : "?",
|
||||
DepotEntity => w.Depots.TryGetValue(e.EntityIndex, out var d) ? d.Name : "?",
|
||||
_ => "?",
|
||||
};
|
||||
|
||||
public static string GoodName(ClientWorld w, int good)
|
||||
{
|
||||
if (good < 0 || good >= w.Data.Goods.Count) return "";
|
||||
var def = w.Data.Goods[good];
|
||||
return English ? def.NameEn : def.NameIt;
|
||||
}
|
||||
|
||||
/// <summary>Effetti con il loro valore («Produzione 25%», «Velocità dei treni 80%»).</summary>
|
||||
public static string Effects(ClientWorld w, WorldEventInfo e)
|
||||
{
|
||||
var def = Def(w, e);
|
||||
if (def is null) return "";
|
||||
var parts = new List<string>();
|
||||
for (int i = 0; i < def.Effects.Count && i < e.Effects.Length; i++)
|
||||
{
|
||||
string label = def.Effects[i].Kind switch
|
||||
{
|
||||
EventEffectKind.IndustryCapacity => T("Capacità produttiva"),
|
||||
EventEffectKind.TownDemand => T("Consumi della città"),
|
||||
EventEffectKind.GoodDemand => $"{T("Domanda di")} {GoodName(w, e.Good).ToLowerInvariant()}",
|
||||
EventEffectKind.Attendance => T("Presenze al lavoro"),
|
||||
EventEffectKind.TrainSpeed => T("Velocità dei treni"),
|
||||
EventEffectKind.TrackWear => T("Usura dei binari"),
|
||||
_ => "",
|
||||
};
|
||||
parts.Add($"{label} {Fmt.Pct(e.Effects[i], 0)}");
|
||||
}
|
||||
return string.Join(" · ", parts);
|
||||
}
|
||||
|
||||
/// <summary>Zona dell'evento («entro 12 km da Valdoria») per area e domanda di un bene.</summary>
|
||||
public static string Where(ClientWorld w, WorldEventInfo e)
|
||||
{
|
||||
var def = Def(w, e);
|
||||
string target = Target(w, e);
|
||||
return def?.RadiusKm is { } km ? $"{T("entro")} {Fmt.Number(km, 0)} km {T("da")} {target}" : target;
|
||||
}
|
||||
|
||||
public static string Until(ClientWorld w, WorldEventInfo e)
|
||||
{
|
||||
long left = Math.Max(0, e.EndDay - Fmt.Today(w));
|
||||
return $"{T("fino al")} {Fmt.Date(w, e.EndDay - 1)} ({left} {(left == 1 ? T("giorno") : T("giorni"))})";
|
||||
}
|
||||
|
||||
/// <summary>Colore della gravità: opportunità in verde, avvisi in ambra, critici in rosso.</summary>
|
||||
public static Color Color(WorldEventInfo e) => e.Severity switch
|
||||
{
|
||||
1 => Palette.Ok,
|
||||
2 => Palette.AmberLight,
|
||||
3 => Palette.Danger,
|
||||
_ => Palette.Text,
|
||||
};
|
||||
|
||||
/// <summary>Riga compatta: titolo, luogo, effetti e scadenza.</summary>
|
||||
public static Control Row(ClientWorld w, WorldEventInfo e)
|
||||
{
|
||||
var col = PanelKit.Column(2);
|
||||
col.AddChild(UiTheme.Text($"{Name(w, e)} · {Where(w, e)}", 14, Color(e), bold: true));
|
||||
var effects = UiTheme.Text(Effects(w, e), 12, Palette.Text);
|
||||
effects.AutowrapMode = TextServer.AutowrapMode.WordSmart;
|
||||
col.AddChild(effects);
|
||||
col.AddChild(UiTheme.Text(Until(w, e), 12, Palette.TextSecondary));
|
||||
return col;
|
||||
}
|
||||
|
||||
/// <summary>Eventi che riguardano un'entità: bersaglio diretto oppure città centro della zona.</summary>
|
||||
public static IEnumerable<WorldEventInfo> For(ClientWorld w, byte entity, int index) =>
|
||||
(w.LastDigest?.WorldEvents ?? []).Where(e => e.Entity == entity && e.EntityIndex == index);
|
||||
|
||||
/// <summary>Avvisi «Evento in corso» per la scheda dell'entità.</summary>
|
||||
public static void AddNotices(ClientWorld w, Control into, byte entity, int index)
|
||||
{
|
||||
foreach (var e in For(w, entity, index))
|
||||
into.AddChild(UiTheme.Notice($"{T("Evento in corso")}: {Name(w, e)} · {Effects(w, e)} · {Until(w, e)}"));
|
||||
}
|
||||
|
||||
public const byte Town = TownEntity, Industry = IndustryEntity, Depot = DepotEntity;
|
||||
}
|
||||
@@ -28,6 +28,7 @@ public partial class GameScreen : Node
|
||||
private readonly Toolbar _toolbar = new();
|
||||
private readonly Ticker _ticker = new();
|
||||
private readonly Minimap _minimap = new();
|
||||
private readonly WorldEventsBox _worldEvents = new();
|
||||
private readonly ScrollContainer _scroll = new() { SizeFlagsVertical = Control.SizeFlags.ExpandFill, HorizontalScrollMode = ScrollContainer.ScrollMode.Disabled };
|
||||
private readonly VBoxContainer _content = new() { SizeFlagsHorizontal = Control.SizeFlags.ExpandFill };
|
||||
private readonly VBoxContainer _toasts = new();
|
||||
@@ -206,6 +207,7 @@ public partial class GameScreen : Node
|
||||
miniTitle.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
miniHeader.AddChild(miniTitle);
|
||||
miniHeader.AddChild(UiTheme.Text(_session.World.Summary?.RegionId is { Length: > 0 } r ? $"{T("Regione di")} {char.ToUpperInvariant(r[0])}{r[1..]}" : "", 13, Palette.TextSecondary));
|
||||
sideCol.AddChild(_worldEvents);
|
||||
sideCol.AddChild(miniHeader);
|
||||
sideCol.AddChild(_minimap);
|
||||
root.AddChild(_ticker);
|
||||
@@ -231,6 +233,9 @@ public partial class GameScreen : Node
|
||||
|
||||
public override void _ExitTree() => _session.MessageApplied -= OnMessage;
|
||||
|
||||
/// <summary>Codice di EventKind.World nel protocollo (notizie degli eventi del mondo, ADR 0017).</summary>
|
||||
private const byte WorldEventKind = 10;
|
||||
|
||||
/// <summary>Avviso permanente dopo la fine della partita: si guarda il mondo, la Cronaca resta a portata.</summary>
|
||||
private void BuildObserverBanner(Control mapArea)
|
||||
{
|
||||
@@ -304,7 +309,9 @@ public partial class GameScreen : Node
|
||||
_session.Send(new RequestDetail { Kind = DetailKind.Employment, Target = 0 });
|
||||
break;
|
||||
case DailyDigest d:
|
||||
foreach (var e in d.Events.Where(e => e.Severity >= 2)) _ticker.Add(e);
|
||||
// gli eventi del mondo (inizio e fine) vanno sempre nel notiziario
|
||||
foreach (var e in d.Events.Where(e => e.Severity >= 2 || e.Kind == WorldEventKind)) _ticker.Add(e);
|
||||
_worldEvents.Update(_session.World);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user