F2: rete ferroviaria, cantieri, treni con fisica e blocchi, merci in stazione
- 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
This commit is contained in:
28 files changed
+4122
-6
No files matched your search
@@ -12,10 +12,13 @@ public sealed class FinanceSystem : ISimSystem
|
||||
{
|
||||
public string Name => "Finance";
|
||||
|
||||
private double[] _running = [];
|
||||
|
||||
public void Step(WorldContext ctx)
|
||||
{
|
||||
if (!ctx.IsNewDay) return;
|
||||
var w = ctx.World;
|
||||
PayRunningCosts(w);
|
||||
foreach (var c in w.Companies)
|
||||
{
|
||||
if (c.Bankrupt) continue;
|
||||
@@ -29,6 +32,7 @@ public sealed class FinanceSystem : ISimSystem
|
||||
}
|
||||
if (ctx.IsNewMonth && ctx.Day > 0)
|
||||
{
|
||||
UpdateBookValues(w);
|
||||
foreach (var c in w.Companies)
|
||||
{
|
||||
if (!c.Bankrupt) PayLoans(w, c);
|
||||
@@ -46,6 +50,62 @@ public sealed class FinanceSystem : ISimSystem
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Costi d'esercizio giornalieri: veicoli posseduti, binari di stazione, depositi.</summary>
|
||||
private void PayRunningCosts(World w)
|
||||
{
|
||||
if (_running.Length < w.Companies.Count) _running = new double[w.Companies.Count];
|
||||
Array.Clear(_running);
|
||||
double days = w.Calendar.DaysPerYear;
|
||||
foreach (var v in w.Vehicles)
|
||||
{
|
||||
if (!v.Sold) _running[v.Owner.Value] += v.Def.RunningCostPerYear / days;
|
||||
}
|
||||
var sp = w.Data.Construction.Stations;
|
||||
foreach (var s in w.Network.Stations)
|
||||
{
|
||||
if (w.Network.Nodes[s.Node.Value].Station == s.Id) _running[s.Owner.Value] += s.Platforms * sp.UpkeepPerPlatformPerYear / days;
|
||||
}
|
||||
foreach (var d in w.Network.Depots)
|
||||
{
|
||||
if (w.Network.Nodes[d.Node.Value].Depot == d.Id) _running[d.Owner.Value] += sp.DepotUpkeepPerYear[d.Size] / days;
|
||||
}
|
||||
for (int i = 0; i < w.Companies.Count; i++)
|
||||
{
|
||||
if (_running[i] <= 0 || w.Companies[i].Bankrupt) continue;
|
||||
w.Money.Transfer(Account.Of(w.Companies[i].Id), Account.External, Money.FromCentsRounded(_running[i]), LedgerEntry.RunningCosts);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Valore contabile degli attivi: binari e veicoli ammortizzati, stazioni e depositi al costo.</summary>
|
||||
public static void UpdateBookValues(World w)
|
||||
{
|
||||
var fb = w.Data.Balance.Finance;
|
||||
var values = new long[w.Companies.Count];
|
||||
double daysPerYear = w.Calendar.DaysPerYear;
|
||||
long today = w.Clock.Day;
|
||||
foreach (var e in w.Network.Edges)
|
||||
{
|
||||
if (e.State == Rail.EdgeState.Demolished) continue;
|
||||
double age = (today - e.BuiltDay) / daysPerYear;
|
||||
values[e.Owner.Value] += (long)(e.BuildCostCents * Math.Max(fb.BookValueFloor, 1 - age / fb.DepreciationYearsTrack));
|
||||
}
|
||||
foreach (var s in w.Network.Stations)
|
||||
{
|
||||
if (w.Network.Nodes[s.Node.Value].Station == s.Id) values[s.Owner.Value] += s.BuildCostCents;
|
||||
}
|
||||
foreach (var d in w.Network.Depots)
|
||||
{
|
||||
if (w.Network.Nodes[d.Node.Value].Depot == d.Id) values[d.Owner.Value] += d.BuildCostCents;
|
||||
}
|
||||
foreach (var v in w.Vehicles)
|
||||
{
|
||||
if (v.Sold) continue;
|
||||
double age = (today - v.BoughtDay) / daysPerYear;
|
||||
values[v.Owner.Value] += (long)(v.Def.Price * Math.Max(fb.BookValueFloor, 1 - age / v.Def.LifeYears));
|
||||
}
|
||||
for (int i = 0; i < w.Companies.Count; i++) w.Companies[i].AssetBookValue = new Money(values[i]);
|
||||
}
|
||||
|
||||
/// <summary>Rata mensile costante (alla francese) per il residuo e i mesi restanti.</summary>
|
||||
public static Money MonthlyPayment(Money remaining, double annualRate, int monthsLeft)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user