F3: protocollo binario completo, server con WebSocket e immagine Docker
- Protocol: SpanWriter/SpanReader, frame [u32][u16][payload], tutti i messaggi dei due versi con byte di estensione, codec di tutti i 38 comandi, test di round-trip, troncamento e corruzione. - Comandi delle fasi successive con formato definitivo (NotImplemented). - ClientWorld e ProtocolClient condivisi da client Godot e test: copia del terreno a chunk, entità, rete con gli stessi id, moto dei treni. - TrackPreview estratto dai comandi: anteprima del client e piano del server con lo stesso codice; stazioni e depositi demoliti esclusi dagli agganci. - Server: GameLoop con accumulatore e velocità effettiva, sessioni con coda a due classi e ripresa, delta per hash, TrackWorks a lotti, moto dei treni nel viewport, resoconti giornalieri, /health, /metrics, /api/saves, autosave a rotazione, log JSON, --local e --healthcheck. - Docker: Dockerfile, compose, modello Unraid; build senza rete. - viaferrea-tools smoke: collaudo end-to-end contro un server in esecuzione. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
This commit is contained in:
36 files changed
+4940
-62
No files matched your search
@@ -104,12 +104,3 @@ public sealed record SetIndustryPolicyCommand(IndustryId Industry, Economy.Indus
|
||||
{
|
||||
public override CommandType Type => CommandType.SetIndustryPolicy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Comando non ancora implementato nella fase corrente: viaggia nel protocollo e riceve
|
||||
/// l'esito NotImplemented. Permette al protocollo di essere completo fin da subito.
|
||||
/// </summary>
|
||||
public sealed record PendingCommand(CommandType Kind, byte[] Payload) : GameCommand
|
||||
{
|
||||
public override CommandType Type => Kind;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
using ViaFerrea.Core.Common;
|
||||
|
||||
namespace ViaFerrea.Core.Commands;
|
||||
|
||||
// Comandi delle fasi F4–F7: il formato è già definitivo (protocollo stabile), l'esecuzione
|
||||
// risponde NotImplemented finché il sistema corrispondente non esiste.
|
||||
|
||||
/// <summary>Ambito di una politica di manutenzione.</summary>
|
||||
public enum MaintenanceScope : byte { Company = 0, Line = 1, Train = 2 }
|
||||
|
||||
/// <summary>Marca o smarca un treno come riserva in deposito (10.3).</summary>
|
||||
public sealed record SetReserveCommand(TrainId Train, bool Reserve) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.SetReserve;
|
||||
}
|
||||
|
||||
/// <summary>Politica di manutenzione (id di <c>maintenance.json</c>: economy, standard, thorough).</summary>
|
||||
public sealed record SetMaintenancePolicyCommand(MaintenanceScope Scope, int Target, string Policy) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.SetMaintenancePolicy;
|
||||
}
|
||||
|
||||
/// <summary>Programma un intervento (id di <c>maintenance.json</c>: inspection, service, overhaul).</summary>
|
||||
public sealed record ScheduleServiceCommand(TrainId Train, string Intervention) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.ScheduleService;
|
||||
}
|
||||
|
||||
/// <summary>Ordina ricambi per un deposito (domanda esplicita sul grafo delle linee).</summary>
|
||||
public sealed record OrderPartsCommand(DepotId Depot, int Quantity) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.OrderParts;
|
||||
}
|
||||
|
||||
/// <summary>Accetta una convenzione di pendolarismo proposta da un'industria.</summary>
|
||||
public sealed record AcceptAgreementCommand(AgreementId Agreement) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.AcceptAgreement;
|
||||
}
|
||||
|
||||
/// <summary>Rifiuta una convenzione di pendolarismo.</summary>
|
||||
public sealed record RejectAgreementCommand(AgreementId Agreement) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.RejectAgreement;
|
||||
}
|
||||
|
||||
/// <summary>Compra merce al prezzo locale in una stazione (commercio, livello 2).</summary>
|
||||
public sealed record BuyGoodsCommand(StationId Station, string Good, int Units, Money MaxUnitPrice) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.BuyGoods;
|
||||
}
|
||||
|
||||
/// <summary>Vende merce della compagnia al prezzo locale in una stazione.</summary>
|
||||
public sealed record SellGoodsCommand(StationId Station, string Good, int Units, Money MinUnitPrice) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.SellGoods;
|
||||
}
|
||||
|
||||
/// <summary>Offerta d'acquisto di un'industria.</summary>
|
||||
public sealed record BuyIndustryCommand(IndustryId Industry, Money Offer) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.BuyIndustry;
|
||||
}
|
||||
|
||||
/// <summary>Fermo programmato (revisione) di un'industria posseduta.</summary>
|
||||
public sealed record OverhaulIndustryCommand(IndustryId Industry) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.OverhaulIndustry;
|
||||
}
|
||||
|
||||
/// <summary>Ammodernamento di livello di un'industria posseduta.</summary>
|
||||
public sealed record UpgradeIndustryCommand(IndustryId Industry) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.UpgradeIndustry;
|
||||
}
|
||||
|
||||
/// <summary>Quotazione in borsa: quota del capitale offerta.</summary>
|
||||
public sealed record IpoCommand(double FloatShare) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.Ipo;
|
||||
}
|
||||
|
||||
/// <summary>Acquisto di azioni di una compagnia quotata.</summary>
|
||||
public sealed record BuySharesCommand(CompanyId Company, long Shares, Money MaxPrice) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.BuyShares;
|
||||
}
|
||||
|
||||
/// <summary>Vendita di azioni possedute.</summary>
|
||||
public sealed record SellSharesCommand(CompanyId Company, long Shares, Money MinPrice) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.SellShares;
|
||||
}
|
||||
|
||||
/// <summary>Dividendo per azione.</summary>
|
||||
public sealed record PayDividendCommand(Money PerShare) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.PayDividend;
|
||||
}
|
||||
|
||||
/// <summary>Offerta pubblica di acquisto sulle azioni di una compagnia.</summary>
|
||||
public sealed record LaunchBidCommand(CompanyId Target, Money PricePerShare, double TargetShare) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.LaunchBid;
|
||||
}
|
||||
|
||||
/// <summary>Risposta a un'offerta pubblica (azionisti del bersaglio).</summary>
|
||||
public sealed record RespondBidCommand(BidId Bid, bool Accept) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.RespondBid;
|
||||
}
|
||||
|
||||
/// <summary>Acquisto della concessione di una regione.</summary>
|
||||
public sealed record BuyConcessionCommand(RegionId Region) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.BuyConcession;
|
||||
}
|
||||
|
||||
/// <summary>Accettazione di un contratto (data/contracts.json).</summary>
|
||||
public sealed record AcceptContractCommand(ContractId Contract) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.AcceptContract;
|
||||
}
|
||||
|
||||
/// <summary>Finanziamento di un progetto di ricerca.</summary>
|
||||
public sealed record FundResearchCommand(string Project, Money Amount) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.FundResearch;
|
||||
}
|
||||
|
||||
/// <summary>Delega di una regione a un direttore (modalità holding) con obiettivo e budget annuo.</summary>
|
||||
public sealed record DelegateRegionCommand(RegionId Region, string Objective, Money Budget) : GameCommand
|
||||
{
|
||||
public override CommandType Type => CommandType.DelegateRegion;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
namespace ViaFerrea.Core.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Difficoltà «Personalizzata»: ritocchi di un preset per nome di campo (camelCase, come in
|
||||
/// <c>difficulty.json</c>). Gli enum si indicano con il loro valore numerico.
|
||||
/// </summary>
|
||||
public static class DifficultyOverrides
|
||||
{
|
||||
public static readonly string[] Keys =
|
||||
[
|
||||
"initialCapital", "initialCredit", "baseInterestRate", "constructionCostMultiplier", "tariffMultiplier", "wearMultiplier",
|
||||
"marketVolatilityMultiplier", "aiCompetitors", "aiCapitalMultiplier", "aiCostDiscount", "playerTakeover", "takeoverRansomYears",
|
||||
"bankruptcyDays", "publicFromStart", "playerShareAtStart", "ironman", "depletion",
|
||||
];
|
||||
|
||||
/// <summary>Applica i ritocchi; una chiave sconosciuta o un valore fuori limite solleva ArgumentException.</summary>
|
||||
public static DifficultyDef Apply(DifficultyDef preset, IEnumerable<(string Key, double Value)> overrides)
|
||||
{
|
||||
var d = preset;
|
||||
foreach (var (key, value) in overrides)
|
||||
{
|
||||
if (double.IsNaN(value) || double.IsInfinity(value)) throw new ArgumentException($"Valore non valido per {key}");
|
||||
d = key switch
|
||||
{
|
||||
"initialCapital" => d with { InitialCapital = NonNegativeLong(key, value) },
|
||||
"initialCredit" => d with { InitialCredit = NonNegativeLong(key, value) },
|
||||
"baseInterestRate" => d with { BaseInterestRate = Range(key, value, 0, 1) },
|
||||
"constructionCostMultiplier" => d with { ConstructionCostMultiplier = Range(key, value, 0.1, 10) },
|
||||
"tariffMultiplier" => d with { TariffMultiplier = Range(key, value, 0.1, 10) },
|
||||
"wearMultiplier" => d with { WearMultiplier = Range(key, value, 0, 10) },
|
||||
"marketVolatilityMultiplier" => d with { MarketVolatilityMultiplier = Range(key, value, 0, 10) },
|
||||
"aiCompetitors" => d with { AiCompetitors = (int)Range(key, value, 0, 8) },
|
||||
"aiCapitalMultiplier" => d with { AiCapitalMultiplier = Range(key, value, 0, 10) },
|
||||
"aiCostDiscount" => d with { AiCostDiscount = Range(key, value, 0, 0.9) },
|
||||
"playerTakeover" => d with { PlayerTakeover = (TakeoverRule)(int)Range(key, value, 0, 2) },
|
||||
"takeoverRansomYears" => d with { TakeoverRansomYears = (int)Range(key, value, 0, 50) },
|
||||
"bankruptcyDays" => d with { BankruptcyDays = (int)Range(key, value, 1, 3600) },
|
||||
"publicFromStart" => d with { PublicFromStart = value != 0 },
|
||||
"playerShareAtStart" => d with { PlayerShareAtStart = Range(key, value, 0, 1) },
|
||||
"ironman" => d with { Ironman = (IronmanRule)(int)Range(key, value, 0, 2) },
|
||||
"depletion" => d with { Depletion = (DepletionRate)(int)Range(key, value, 0, 2) },
|
||||
_ => throw new ArgumentException($"Campo di difficoltà sconosciuto: {key}"),
|
||||
};
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
private static double Range(string key, double v, double min, double max) =>
|
||||
v < min || v > max ? throw new ArgumentException($"{key} fuori dai limiti ({min}–{max})") : v;
|
||||
|
||||
private static long NonNegativeLong(string key, double v) =>
|
||||
v < 0 || v > 1e17 ? throw new ArgumentException($"{key} fuori dai limiti") : (long)v;
|
||||
}
|
||||
@@ -33,6 +33,12 @@ public sealed class RailNetwork
|
||||
|
||||
public void Touch() => Version++;
|
||||
|
||||
/// <summary>Vero se la stazione non è stata demolita (il suo nodo la indica ancora).</summary>
|
||||
public bool IsAlive(Station s) => s.Node.IsValid && s.Node.Value < Nodes.Count && Nodes[s.Node.Value].Station == s.Id;
|
||||
|
||||
/// <summary>Vero se il deposito non è stato demolito.</summary>
|
||||
public bool IsAlive(Depot d) => d.Node.IsValid && d.Node.Value < Nodes.Count && Nodes[d.Node.Value].Depot == d.Id;
|
||||
|
||||
public TrackNode AddNode(Vec2 position, double heightM, CompanyId owner)
|
||||
{
|
||||
var node = new TrackNode { Id = new NodeId(Nodes.Count), Position = position, HeightM = heightM, Owner = owner };
|
||||
@@ -145,12 +151,12 @@ public sealed class RailNetwork
|
||||
// stazioni e depositi: tutta l'area aggancia al nodo
|
||||
foreach (var s in Stations)
|
||||
{
|
||||
if (s.Owner == company && Vec2.Distance(s.Position, p) <= stationRadiusM)
|
||||
if (s.Owner == company && IsAlive(s) && Vec2.Distance(s.Position, p) <= stationRadiusM)
|
||||
return new AttachPoint(s.Node, EdgeId.None, -1, Nodes[s.Node.Value].Position, Nodes[s.Node.Value].HeightM);
|
||||
}
|
||||
foreach (var d in Depots)
|
||||
{
|
||||
if (d.Owner == company && Vec2.Distance(d.Position, p) <= stationRadiusM)
|
||||
if (d.Owner == company && IsAlive(d) && Vec2.Distance(d.Position, p) <= stationRadiusM)
|
||||
return new AttachPoint(d.Node, EdgeId.None, -1, Nodes[d.Node.Value].Position, Nodes[d.Node.Value].HeightM);
|
||||
}
|
||||
TrackNode? bestNode = null;
|
||||
@@ -238,7 +244,7 @@ public sealed class RailNetwork
|
||||
foreign = false;
|
||||
foreach (var s in net.Stations)
|
||||
{
|
||||
if (Vec2.Distance(s.Position, p) > r) continue;
|
||||
if (!net.IsAlive(s) || Vec2.Distance(s.Position, p) > r) continue;
|
||||
if (Vec2.Distance(p, start) <= r || Vec2.Distance(p, end) <= r)
|
||||
{
|
||||
if (s.Owner == company) continue;
|
||||
@@ -248,7 +254,7 @@ public sealed class RailNetwork
|
||||
}
|
||||
foreach (var d in net.Depots)
|
||||
{
|
||||
if (Vec2.Distance(d.Position, p) > r) continue;
|
||||
if (!net.IsAlive(d) || Vec2.Distance(d.Position, p) > r) continue;
|
||||
if (d.Owner == company && (Vec2.Distance(p, start) <= r || Vec2.Distance(p, end) <= r)) continue;
|
||||
foreign = d.Owner != company;
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
using ViaFerrea.Core.Commands;
|
||||
using ViaFerrea.Core.Common;
|
||||
using ViaFerrea.Core.Data;
|
||||
using ViaFerrea.Core.Map;
|
||||
|
||||
namespace ViaFerrea.Core.Rail;
|
||||
|
||||
/// <summary>
|
||||
/// Ciò che serve al pianificatore oltre al comando: dati, terreno, rete, anno e costi. Il server
|
||||
/// lo ricava dal mondo, il client dalla propria copia (terreno ricevuto a chunk, rete da
|
||||
/// TrackWorks): stesso codice, stesso risultato.
|
||||
/// </summary>
|
||||
public sealed class TrackPreviewInputs
|
||||
{
|
||||
public required GameData Data { get; init; }
|
||||
public required TerrainSampler Sampler { get; init; }
|
||||
public required RailNetwork Network { get; init; }
|
||||
public required int Year { get; init; }
|
||||
public required double CostMultiplier { get; init; }
|
||||
public required Func<Vec2, double> NearestTownEdgeKm { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>Anteprima di un binario: aggancio delle estremità, attraversamenti, profilo, opere e costo.</summary>
|
||||
public static class TrackPreview
|
||||
{
|
||||
public static TrackPlanContext Context(TrackPreviewInputs inputs, ITrackObstacles? obstacles) => new()
|
||||
{
|
||||
Data = inputs.Data,
|
||||
Sampler = inputs.Sampler,
|
||||
Year = inputs.Year,
|
||||
CostMultiplier = inputs.CostMultiplier,
|
||||
Obstacles = obstacles,
|
||||
NearestTownEdgeKm = inputs.NearestTownEdgeKm,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Prepara il piano come farebbe il comando: aggancia le estremità a nodi e archi esistenti e
|
||||
/// considera gli attraversamenti.
|
||||
/// </summary>
|
||||
public static (TrackPlan Plan, AttachPoint Start, AttachPoint End) Prepare(TrackPreviewInputs inputs, CompanyId company, BuildTrackCommand c)
|
||||
{
|
||||
var sp = inputs.Data.Construction.Stations;
|
||||
var net = inputs.Network;
|
||||
var start = net.FindAttach(c.Polyline[0], company, sp.SnapM, sp.AreaRadiusM);
|
||||
var end = net.FindAttach(c.Polyline[^1], company, sp.SnapM, sp.AreaRadiusM);
|
||||
var points = c.Polyline.ToList();
|
||||
points[0] = start.Position;
|
||||
points[^1] = end.Position;
|
||||
var request = new TrackPlanRequest
|
||||
{
|
||||
Polyline = points,
|
||||
HeightOffsetM = c.HeightOffsetM,
|
||||
AllowBridges = c.AllowBridges,
|
||||
AllowTunnels = c.AllowTunnels,
|
||||
TrackClass = c.TrackClass,
|
||||
DoubleTrack = c.DoubleTrack,
|
||||
Electrified = c.Electrified,
|
||||
Company = company,
|
||||
StartHeightM = start.IsFree ? null : start.HeightM,
|
||||
EndHeightM = end.IsFree ? null : end.HeightM,
|
||||
};
|
||||
var obstacles = net.Obstacles(start.Position, end.Position, sp.SnapM + 1, sp.AreaRadiusM);
|
||||
return (TrackPlanner.Plan(Context(inputs, obstacles), request), start, end);
|
||||
}
|
||||
}
|
||||
@@ -12,46 +12,28 @@ public static class RailCommandHandlers
|
||||
{
|
||||
public delegate CommandResult Reply(CommandError error, string message, params int[] created);
|
||||
|
||||
/// <summary>Contesto del pianificatore per una compagnia (difficoltà e sconto IA inclusi).</summary>
|
||||
public static TrackPlanContext PlanContext(World w, Company company, ITrackObstacles? obstacles = null) => new()
|
||||
/// <summary>Moltiplicatore dei costi di costruzione di una compagnia (difficoltà e sconto IA).</summary>
|
||||
public static double CostMultiplier(World w, Company company) =>
|
||||
w.Difficulty.ConstructionCostMultiplier * (company.IsPlayer ? 1.0 : 1.0 - w.Difficulty.AiCostDiscount);
|
||||
|
||||
/// <summary>Ingressi dell'anteprima ricavati dal mondo autorevole.</summary>
|
||||
public static TrackPreviewInputs PreviewInputs(World w, Company company) => new()
|
||||
{
|
||||
Data = w.Data,
|
||||
Sampler = w.Sampler,
|
||||
Network = w.Network,
|
||||
Year = w.Clock.Year,
|
||||
CostMultiplier = w.Difficulty.ConstructionCostMultiplier * (company.IsPlayer ? 1.0 : 1.0 - w.Difficulty.AiCostDiscount),
|
||||
Obstacles = obstacles,
|
||||
CostMultiplier = CostMultiplier(w, company),
|
||||
NearestTownEdgeKm = p => w.Towns.Count == 0 ? double.MaxValue : w.Towns.Min(t => w.TownEdgeDistanceKm(t, p)),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Prepara il piano di un binario come farebbe il comando: aggancia le estremità a nodi e archi
|
||||
/// esistenti e considera gli attraversamenti. Usato anche per l'anteprima nel client.
|
||||
/// </summary>
|
||||
public static (TrackPlan Plan, AttachPoint Start, AttachPoint End) PreparePlan(World w, Company company, BuildTrackCommand c)
|
||||
{
|
||||
var sp = w.Data.Construction.Stations;
|
||||
var net = w.Network;
|
||||
var start = net.FindAttach(c.Polyline[0], company.Id, sp.SnapM, sp.AreaRadiusM);
|
||||
var end = net.FindAttach(c.Polyline[^1], company.Id, sp.SnapM, sp.AreaRadiusM);
|
||||
var points = c.Polyline.ToList();
|
||||
points[0] = start.Position;
|
||||
points[^1] = end.Position;
|
||||
var request = new TrackPlanRequest
|
||||
{
|
||||
Polyline = points,
|
||||
HeightOffsetM = c.HeightOffsetM,
|
||||
AllowBridges = c.AllowBridges,
|
||||
AllowTunnels = c.AllowTunnels,
|
||||
TrackClass = c.TrackClass,
|
||||
DoubleTrack = c.DoubleTrack,
|
||||
Electrified = c.Electrified,
|
||||
Company = company.Id,
|
||||
StartHeightM = start.IsFree ? null : start.HeightM,
|
||||
EndHeightM = end.IsFree ? null : end.HeightM,
|
||||
};
|
||||
var obstacles = net.Obstacles(start.Position, end.Position, sp.SnapM + 1, sp.AreaRadiusM);
|
||||
return (TrackPlanner.Plan(PlanContext(w, company, obstacles), request), start, end);
|
||||
}
|
||||
/// <summary>Contesto del pianificatore per una compagnia (difficoltà e sconto IA inclusi).</summary>
|
||||
public static TrackPlanContext PlanContext(World w, Company company, ITrackObstacles? obstacles = null) =>
|
||||
TrackPreview.Context(PreviewInputs(w, company), obstacles);
|
||||
|
||||
/// <summary>Prepara il piano di un binario come farebbe il comando (stesso codice dell'anteprima del client).</summary>
|
||||
public static (TrackPlan Plan, AttachPoint Start, AttachPoint End) PreparePlan(World w, Company company, BuildTrackCommand c) =>
|
||||
TrackPreview.Prepare(PreviewInputs(w, company), company.Id, c);
|
||||
|
||||
public static CommandResult BuildTrack(World w, Company company, BuildTrackCommand c, Reply reply)
|
||||
{
|
||||
@@ -111,8 +93,8 @@ public static class RailCommandHandlers
|
||||
var type = w.Sampler.TypeAt(c.Position);
|
||||
if (type is CellType.Water or CellType.Sea or CellType.Town or CellType.Industry)
|
||||
return reply(CommandError.NotAllowed, "La stazione deve stare su terreno libero, fuori da città e industrie");
|
||||
if (w.Network.Stations.Any(s => Vec2.Distance(s.Position, c.Position) < sp.AreaRadiusM * 2)
|
||||
|| w.Network.Depots.Any(d => Vec2.Distance(d.Position, c.Position) < sp.AreaRadiusM * 2))
|
||||
if (w.Network.Stations.Any(s => w.Network.IsAlive(s) && Vec2.Distance(s.Position, c.Position) < sp.AreaRadiusM * 2)
|
||||
|| w.Network.Depots.Any(d => w.Network.IsAlive(d) && Vec2.Distance(d.Position, c.Position) < sp.AreaRadiusM * 2))
|
||||
return reply(CommandError.NotAllowed, "Troppo vicino a un'altra stazione o deposito");
|
||||
var attach = w.Network.FindAttach(c.Position, company.Id, sp.SnapM, 0);
|
||||
if (attach.Node.IsValid)
|
||||
@@ -123,7 +105,7 @@ public static class RailCommandHandlers
|
||||
if (attach.SplitEdge.IsValid && !RailNetwork.IsFree(w.Network.Edges[attach.SplitEdge.Value]))
|
||||
return reply(CommandError.Blocked, "Il binario è occupato da un treno");
|
||||
var cost = new Money(w.Data.Construction.Costs.StationBase + w.Data.Construction.Costs.StationPerPlatform * c.Platforms)
|
||||
* (w.Difficulty.ConstructionCostMultiplier * (company.IsPlayer ? 1.0 : 1.0 - w.Difficulty.AiCostDiscount));
|
||||
* CostMultiplier(w, company);
|
||||
if (company.Cash < cost) return reply(CommandError.InsufficientFunds, $"Servono {cost}");
|
||||
|
||||
var node = attach.Node.IsValid ? w.Network.Nodes[attach.Node.Value]
|
||||
@@ -161,15 +143,15 @@ public static class RailCommandHandlers
|
||||
var type = w.Sampler.TypeAt(c.Position);
|
||||
if (type is CellType.Water or CellType.Sea or CellType.Town or CellType.Industry)
|
||||
return reply(CommandError.NotAllowed, "Il deposito deve stare su terreno libero");
|
||||
if (w.Network.Stations.Any(s => Vec2.Distance(s.Position, c.Position) < sp.AreaRadiusM * 2)
|
||||
|| w.Network.Depots.Any(d => Vec2.Distance(d.Position, c.Position) < sp.AreaRadiusM * 2))
|
||||
if (w.Network.Stations.Any(s => w.Network.IsAlive(s) && Vec2.Distance(s.Position, c.Position) < sp.AreaRadiusM * 2)
|
||||
|| w.Network.Depots.Any(d => w.Network.IsAlive(d) && Vec2.Distance(d.Position, c.Position) < sp.AreaRadiusM * 2))
|
||||
return reply(CommandError.NotAllowed, "Troppo vicino a un'altra stazione o deposito");
|
||||
var attach = w.Network.FindAttach(c.Position, company.Id, sp.SnapM, 0);
|
||||
if (attach.Node.IsValid && (w.Network.Nodes[attach.Node.Value].Station.IsValid || w.Network.Nodes[attach.Node.Value].Depot.IsValid))
|
||||
return reply(CommandError.NotAllowed, "Il nodo ha già una stazione o un deposito");
|
||||
if (attach.SplitEdge.IsValid && !RailNetwork.IsFree(w.Network.Edges[attach.SplitEdge.Value]))
|
||||
return reply(CommandError.Blocked, "Il binario è occupato da un treno");
|
||||
var cost = new Money(baseCost) * (w.Difficulty.ConstructionCostMultiplier * (company.IsPlayer ? 1.0 : 1.0 - w.Difficulty.AiCostDiscount));
|
||||
var cost = new Money(baseCost) * CostMultiplier(w, company);
|
||||
if (company.Cash < cost) return reply(CommandError.InsufficientFunds, $"Servono {cost}");
|
||||
|
||||
var node = attach.Node.IsValid ? w.Network.Nodes[attach.Node.Value]
|
||||
|
||||
@@ -23,7 +23,10 @@ public sealed class StationSystem : ISimSystem
|
||||
var net = w.Network;
|
||||
if (ctx.IsNewMonth || ctx.Day == 0)
|
||||
{
|
||||
foreach (var s in net.Stations) RailCommandHandlers.UpdateCatchment(w, s);
|
||||
foreach (var s in net.Stations)
|
||||
{
|
||||
if (net.IsAlive(s)) RailCommandHandlers.UpdateCatchment(w, s);
|
||||
}
|
||||
}
|
||||
foreach (var s in net.Stations)
|
||||
{
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
<!-- Motore di simulazione deterministico: nessuna dipendenza oltre la BCL. -->
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net10.0;net8.0</TargetFrameworks>
|
||||
<!-- Immagine del server: solo net10.0, così la build non scarica il targeting pack net8.0 (ADR 0009). -->
|
||||
<TargetFrameworks Condition="'$(VfServerOnly)' == 'true'">net10.0</TargetFrameworks>
|
||||
<RootNamespace>ViaFerrea.Core</RootNamespace>
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user