- RailNetwork: nodi, archi con profilo campionato, divisione degli archi agli agganci (anche in cantiere), indice spaziale, cavalcavia sui binari altrui - Comandi: binari, stazioni, depositi, segnali, demolizioni, rinnovi, ammodernamenti, veicoli, composizioni, linee, assegnazioni, rientro - ConstructionSystem: squadre per livello, avanzamento, usura dei binari e invecchiamento delle strutture; costi d'esercizio e valore contabile - TrainSystem: A* con vincolo di svolta, prenotazione a blocchi con catena fino a un punto sicuro sul binario semplice, fisica 8.4, stallo in salita - StationSystem e StationWork: bacini, merci con destinazione sul grafo delle linee, carico sui carri, consegne con tariffa, trasbordi - Salvataggi estesi a tutto lo stato ferroviario; 11 nuovi test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
82 lines
3.1 KiB
C#
82 lines
3.1 KiB
C#
using ViaFerrea.Core.Commands;
|
|
using ViaFerrea.Core.Common;
|
|
using ViaFerrea.Core.Rail;
|
|
using ViaFerrea.Core.Simulation;
|
|
using ViaFerrea.Core.Simulation.Scenarios;
|
|
using ViaFerrea.Tests.Harness;
|
|
using ViaFerrea.Tests.Scenarios;
|
|
|
|
namespace ViaFerrea.Tests.Rail;
|
|
|
|
/// <summary>Mondo con comandi di comodo per i test ferroviari.</summary>
|
|
public sealed class RailFixture
|
|
{
|
|
public World W { get; }
|
|
public LoadedScenario? Scenario { get; }
|
|
public CompanyId Me => W.Player.Id;
|
|
|
|
public RailFixture(World w, LoadedScenario? scenario = null)
|
|
{
|
|
W = w;
|
|
Scenario = scenario;
|
|
}
|
|
|
|
public static RailFixture Valdoria() { var s = ScenarioHelper.Load("valdoria"); return new RailFixture(s.World, s); }
|
|
|
|
public static Vec2 K(double x, double y) => new(x * 1000, y * 1000);
|
|
|
|
/// <summary>Esegue il comando nel prossimo tick e ne restituisce l'esito.</summary>
|
|
public CommandResult Do(GameCommand c, CompanyId? issuer = null)
|
|
{
|
|
W.Enqueue(c with { Issuer = issuer ?? Me });
|
|
W.RunTicks(1);
|
|
return W.DrainResults().Last();
|
|
}
|
|
|
|
public int Ok(GameCommand c, CompanyId? issuer = null)
|
|
{
|
|
var r = Do(c, issuer);
|
|
Assert.True(r.Ok, $"{c.Type}: {r.Error} {r.Message}");
|
|
return r.Created.Length > 0 ? r.Created[0] : -1;
|
|
}
|
|
|
|
/// <summary>Esegue giorni finché la condizione è vera (o scade il limite).</summary>
|
|
public bool RunUntil(Func<bool> condition, int maxDays)
|
|
{
|
|
for (int d = 0; d < maxDays * 8; d++)
|
|
{
|
|
if (condition()) return true;
|
|
W.RunTicks(W.Calendar.TicksPerDay / 8);
|
|
}
|
|
return condition();
|
|
}
|
|
|
|
/// <summary>Compra veicoli e compone un treno nel deposito.</summary>
|
|
public int Train(int depot, string loco, int locos, string car, int cars, string name)
|
|
{
|
|
var ids = new List<VehicleId>();
|
|
ids.AddRange(W_Buy(loco, depot, locos));
|
|
if (cars > 0) ids.AddRange(W_Buy(car, depot, cars));
|
|
return Ok(new ComposeTrainCommand(new DepotId(depot), ids, name));
|
|
}
|
|
|
|
private IEnumerable<VehicleId> W_Buy(string type, int depot, int count) =>
|
|
Do(new BuyVehicleCommand(type, new DepotId(depot), count)).Created.Select(i => new VehicleId(i));
|
|
|
|
/// <summary>
|
|
/// Rete merci di Valdoria: stazione delle miniere, stazione dell'acciaieria, deposito e
|
|
/// tracciato per il valico; restituisce (miniera, acciaieria, deposito).
|
|
/// </summary>
|
|
public (int Mine, int Mill, int Depot) BuildFreightNetwork(bool waitForConstruction = true)
|
|
{
|
|
int mine = Ok(new BuildStationCommand(K(2.2, 2.6), 2, "Rocca Bruna"));
|
|
int mill = Ok(new BuildStationCommand(K(10.6, 5.4), 4, "Acciaieria"));
|
|
int depot = Ok(new BuildDepotCommand(K(2.6, 4.4), "small", "Deposito Rocca Bruna"));
|
|
Ok(new BuildTrackCommand(Scenario!.Route("valico", Me).Polyline, AllowTunnels: false));
|
|
Ok(new BuildTrackCommand(new[] { K(2.6, 4.4), K(2.92, 4.95) }));
|
|
if (waitForConstruction)
|
|
Assert.True(RunUntil(() => W.Network.Edges.All(e => e.State == EdgeState.Active), 400), "cantieri completati");
|
|
return (mine, mill, depot);
|
|
}
|
|
}
|