F3: client Godot minimo, replay dei comandi e collaudi automatici

- Client Godot 4.7 .NET (Godot.NET.Sdk 4.7.2): menu, collegamento, partita
  locale con server figlio; mappa con terreno (fasce, ombreggiatura, rive
  curve con shader, curve di livello), opere, entità, alberi, treni
  interpolati con fumo; strumenti binari con profilo, stazione, deposito,
  segnali, demolizione; pannelli treni, linee, mercato, finanze, schede;
  barra superiore, minimappa, notiziario; italiano e inglese.
- Pilota automatico del client e scripts/client-autopilot.sh: partita locale,
  linea con ponte, treni in moto e schermate (docs/screenshots).
- Registro dei comandi del server (--record) e viaferrea-tools replay.
- PROTOCOL.md normativo, ADR 0009, ARCHITECTURE, STATE e README aggiornati.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
This commit is contained in:
Claude committed 2026-10-02 00:47:42 +00:00
1 parent 5a318e6528
commit 9a4ada6d9d
97 files changed
+5151 -96

No files matched your search

@@ -0,0 +1,51 @@
using System.Diagnostics;
using ViaFerrea.Core.Data;
using ViaFerrea.Core.Persistence;
using ViaFerrea.Protocol;
namespace ViaFerrea.Tools.Commands;
/// <summary>
/// replay: carica un salvataggio, riapplica i comandi registrati dal server (<c>--record</c>) ai
/// loro tick e stampa l'hash di stato finale; con <c>--expect</c> lo confronta (determinismo).
/// </summary>
public sealed class ReplayCommand : IToolCommand
{
public string Name => "replay";
public string Usage => "replay --save <file.vfsave> --commands <file.vfcmd> [--until <tick>] [--expect <hash esadecimale>]";
public int Run(CommandLine args)
{
string savePath = args.Required("save");
string commandsPath = args.Required("commands");
long until = args.Int("until", -1);
string? expect = args.String("expect");
args.EnsureAllUsed();
var data = GameData.LoadDefault();
var world = SaveFile.LoadFromFile(data, savePath);
var commands = CommandLogFile.ReadAll(File.ReadAllBytes(commandsPath));
long start = world.Clock.Tick;
long last = commands.Count > 0 ? commands[^1].Tick : start;
long end = until >= 0 ? until : last + 1;
var clock = Stopwatch.StartNew();
int next = 0;
while (next < commands.Count && commands[next].Tick < start) next++;
int skipped = next;
while (world.Clock.Tick < end)
{
while (next < commands.Count && commands[next].Tick == world.Clock.Tick) world.Enqueue(commands[next++].Command);
world.Tick();
world.DrainResults();
world.Events.Drain();
}
ulong hash = StateHasher.Compute(world);
Console.WriteLine($"replay: {next - skipped} comandi su {commands.Count} (saltati {skipped} precedenti al salvataggio), tick {start} → {world.Clock.Tick} in {clock.ElapsedMilliseconds} ms");
Console.WriteLine($" data {world.Clock.Date}, hash di stato {hash:x16}");
if (expect is null) return 0;
bool ok = string.Equals(expect.Trim(), hash.ToString("x16"), StringComparison.OrdinalIgnoreCase);
Console.WriteLine(ok ? " hash atteso: coincide" : $" hash atteso {expect}: DIVERSO");
return ok ? 0 : 1;
}
}
+2 -39
View File
@@ -93,9 +93,9 @@ public sealed class SmokeCommand : IToolCommand
break;
}
await s.Until(() => w.Companies.TryGetValue(summary.CompanyId, out var c) && c.Cash.Cents > 0, ct);
var site = FindBridgeSite(w);
var site = BridgeSiteFinder.Find(w);
if (site is null) return Fail("nessun attraversamento di fiume adatto trovato");
var (a, b, depotAt) = site.Value;
var (a, b, depotAt, _) = site.Value;
Console.WriteLine($" sito: da ({a.X / 1000:F2}, {a.Y / 1000:F2}) a ({b.X / 1000:F2}, {b.Y / 1000:F2}) km");
var sa = await s.Do(new BuildStationCommand(a, 2, "Smoke Ovest"), ct);
@@ -173,41 +173,4 @@ public sealed class SmokeCommand : IToolCommand
Console.Error.WriteLine($"smoke: FALLITO — {why}");
return 1;
}
/// <summary>
/// Cerca un attraversamento di fiume rettilineo di 1,5–2,5 km con estremità e deposito su
/// terreno libero e un'anteprima valida con ponte.
/// </summary>
private static (Vec2 A, Vec2 B, Vec2 Depot)? FindBridgeSite(ClientWorld w)
{
var t = w.Terrain!;
var rng = new Rng(7);
bool Free(Vec2 p)
{
if (p.X < 2000 || p.Y < 2000 || p.X > t.WidthM - 2000 || p.Y > t.HeightM - 2000) return false;
var (x, y) = t.CellAt(p);
return (CellType)t.Types[y * t.Width + x] is CellType.Plain or CellType.Field or CellType.Forest or CellType.Hill;
}
var rivers = new List<int>();
for (int i = 0; i < t.RiverWidth.Length; i++)
{
if (t.RiverWidth[i] > 0) rivers.Add(i);
}
if (rivers.Count == 0) return null;
for (int attempt = 0; attempt < 400; attempt++)
{
int cell = rivers[rng.NextInt(rivers.Count)];
var center = t.CellCenter(cell % t.Width, cell / t.Width);
double angle = rng.NextDouble(0, Math.PI);
var dir = new Vec2(Math.Cos(angle), Math.Sin(angle));
double half = rng.NextDouble(750, 1250);
var a = center - dir * half;
var b = center + dir * half;
var depot = a - dir * 600;
if (!Free(a) || !Free(b) || !Free(depot)) continue;
var plan = w.PreviewTrack(new BuildTrackCommand([a, b]));
if (plan.Valid && plan.LengthOf(WorkKind.Bridge) > 0 && plan.Days <= 120) return (a, b, depot);
}
return null;
}
}
+1
View File
@@ -13,6 +13,7 @@ public static class ToolsProgram
new ProfileCommand(),
new BenchCommand(),
new SmokeCommand(),
new ReplayCommand(),
];
public static int Main(string[] args)