F6: finanza completa con prestiti per rating, conto economico e bancarotta
Completa la finanza della guida 6.3 partendo da un'analisi delle lacune (ADR 0019): prestiti, fido per livello, rate e bancarotta ai giorni di difficulty.json c'erano già; mancavano gli stipendi delle compagnie, un rating spiegabile, il conto economico per voce e gli avvisi. - Prestiti a tasso fisso (base della difficoltà + spread del rating all'accensione), per non innescare la spirale rating -> rata -> utile; rimborso anticipato parziale e totale con messaggi chiari in italiano. - Rating mensile da margine (utile/ricavi sugli ultimi 12 mesi chiusi) e leva (debiti/patrimonio netto); il motore conserva le misure e FinanceOutlook spiega soglie, tassi e cosa serve per salire. - Voci nuove del registro (stazioni e depositi, magazzini, dazi, dividendi incassati) e stipendi del personale presente nei depositi, così il conto economico per voce somma esattamente all'utile operativo del motore. - Mesi e anni chiusi per voce nel salvataggio (versione 7, con migrazione e nell'hash); avvisi di cassa negativa alle scadenze fisse prima del limite della difficoltà, esito dell'ADR 0012 invariato. - Protocollo: DetailKind.Finance e FinanceReport; client: pannello «Finanze» a tutto schermo con conto economico, rating, prestiti e barra della cassa negativa, schermata 18_finanze nel pilota automatico. - Test in Economy/FinanceTests.cs, round-trip del protocollo e quadro via WebSocket; IA e accettazioni F4/F5 invariate. Refs #39. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2e5215c570
commit
9bf64b9286
32 files changed
+2338
-118
No files matched your search
@@ -29,6 +29,66 @@ public enum LedgerEntry : byte
|
||||
Industries = 19,
|
||||
/// <summary>Utili versati dalle compagnie controllate.</summary>
|
||||
Subsidiaries = 20,
|
||||
/// <summary>Esercizio dei binari di stazione e dei depositi (prima dentro <see cref="RunningCosts"/>, ADR 0019).</summary>
|
||||
StationUpkeep = 21,
|
||||
/// <summary>Giacenza della merce nei magazzini della compagnia (prima dentro <see cref="Trading"/>, ADR 0019).</summary>
|
||||
Storage = 22,
|
||||
/// <summary>Dazi sugli scambi in proprio con gli hub (prima dentro <see cref="Trading"/>, ADR 0019).</summary>
|
||||
Duties = 23,
|
||||
/// <summary>Dividendi incassati dalle azioni di altre compagnie (ADR 0019); <see cref="Dividends"/> resta per quelli pagati.</summary>
|
||||
DividendsReceived = 24,
|
||||
}
|
||||
|
||||
/// <summary>Sezione del conto economico di una voce del registro (ADR 0019).</summary>
|
||||
public enum IncomeSection : byte
|
||||
{
|
||||
/// <summary>Ricavi d'esercizio: entrano nell'utile operativo.</summary>
|
||||
Revenue = 0,
|
||||
/// <summary>Costi d'esercizio: entrano nell'utile operativo.</summary>
|
||||
Cost = 1,
|
||||
/// <summary>Investimenti e finanziamenti: muovono la cassa ma non l'utile operativo.</summary>
|
||||
Capital = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Classificazione delle voci del registro (ADR 0019): unica fonte dell'utile operativo, dei ricavi del
|
||||
/// rating e delle righe del conto economico del pannello delle finanze.
|
||||
/// </summary>
|
||||
public static class LedgerEntries
|
||||
{
|
||||
/// <summary>Voci nell'ordine del conto economico: ricavi, costi, investimenti e finanziamenti.</summary>
|
||||
public static readonly LedgerEntry[] Ordered =
|
||||
[
|
||||
LedgerEntry.FreightRevenue, LedgerEntry.PassengerRevenue, LedgerEntry.Trading, LedgerEntry.Contracts,
|
||||
LedgerEntry.Industries, LedgerEntry.Subsidiaries, LedgerEntry.DividendsReceived,
|
||||
LedgerEntry.RunningCosts, LedgerEntry.StationUpkeep, LedgerEntry.FleetMaintenance, LedgerEntry.TrackMaintenance,
|
||||
LedgerEntry.Wages, LedgerEntry.Interest, LedgerEntry.Duties, LedgerEntry.Storage, LedgerEntry.Penalties,
|
||||
LedgerEntry.Construction, LedgerEntry.VehiclePurchase, LedgerEntry.VehicleSale, LedgerEntry.IndustryPurchase,
|
||||
LedgerEntry.LoanTaken, LedgerEntry.LoanRepaid, LedgerEntry.Shares, LedgerEntry.Dividends, LedgerEntry.Other,
|
||||
];
|
||||
|
||||
public static IncomeSection Section(LedgerEntry e) => e switch
|
||||
{
|
||||
LedgerEntry.FreightRevenue or LedgerEntry.PassengerRevenue or LedgerEntry.Trading or LedgerEntry.Contracts
|
||||
or LedgerEntry.Industries or LedgerEntry.Subsidiaries or LedgerEntry.DividendsReceived => IncomeSection.Revenue,
|
||||
LedgerEntry.RunningCosts or LedgerEntry.StationUpkeep or LedgerEntry.FleetMaintenance or LedgerEntry.TrackMaintenance
|
||||
or LedgerEntry.Wages or LedgerEntry.Interest or LedgerEntry.Duties or LedgerEntry.Storage or LedgerEntry.Penalties => IncomeSection.Cost,
|
||||
_ => IncomeSection.Capital,
|
||||
};
|
||||
|
||||
/// <summary>Vero per le voci che entrano nell'utile operativo (ricavi e costi d'esercizio).</summary>
|
||||
public static bool Operating(LedgerEntry e) => Section(e) != IncomeSection.Capital;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Movimenti per voce di un mese o di un anno chiuso (ADR 0019): <see cref="Month"/> 1–12 per un mese,
|
||||
/// 0 per un anno intero.
|
||||
/// </summary>
|
||||
public sealed class IncomeRecord
|
||||
{
|
||||
public required int Year { get; init; }
|
||||
public required int Month { get; init; }
|
||||
public required long[] Entries { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>Voci dello stato patrimoniale per gli attivi non monetari (ADR 0018).</summary>
|
||||
@@ -65,7 +125,7 @@ public sealed class Loan
|
||||
/// <summary>Compagnia ferroviaria (giocatore o IA).</summary>
|
||||
public sealed class Company
|
||||
{
|
||||
public const int EntryCount = 21;
|
||||
public const int EntryCount = 25;
|
||||
|
||||
public required CompanyId Id { get; init; }
|
||||
public required string Name { get; set; }
|
||||
@@ -97,6 +157,22 @@ public sealed class Company
|
||||
/// <summary>Movimenti dell'anno precedente per voce (per rating e borsa).</summary>
|
||||
public long[] LastYearEntries { get; } = new long[EntryCount];
|
||||
|
||||
/// <summary>Mesi chiusi per voce, dal più vecchio (al massimo finance.incomeMonths, ADR 0019).</summary>
|
||||
public List<IncomeRecord> IncomeMonths { get; } = [];
|
||||
|
||||
/// <summary>Anni chiusi per voce, dal più vecchio (al massimo finance.incomeYears, ADR 0019).</summary>
|
||||
public List<IncomeRecord> IncomeYears { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Misure dell'ultimo calcolo del rating (ADR 0019): margine = utile operativo / ricavi dei mesi della
|
||||
/// finestra, leva = debiti / patrimonio netto (+∞ con patrimonio non positivo e debiti), punteggio
|
||||
/// pesato e numero di mesi della finestra (0 prima del primo calcolo).
|
||||
/// </summary>
|
||||
public double RatingMargin { get; set; }
|
||||
public double RatingLeverage { get; set; }
|
||||
public double RatingScore { get; set; }
|
||||
public int RatingMonths { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Valore contabile degli attivi non monetari per voce (<see cref="AssetCategory"/>, centesimi),
|
||||
/// aggiornato ogni mese da <c>FinanceSystem.UpdateBookValues</c> (ADR 0018).
|
||||
@@ -204,20 +280,33 @@ public sealed class Company
|
||||
/// <summary>Capitalizzazione di borsa (centesimi).</summary>
|
||||
public double MarketCap => SharePrice * Shares.Outstanding;
|
||||
|
||||
/// <summary>Utile operativo dell'anno indicato (ricavi meno costi d'esercizio, esclusi prestiti e investimenti).</summary>
|
||||
/// <summary>
|
||||
/// Utile operativo dei movimenti indicati: somma delle voci di ricavo e di costo d'esercizio
|
||||
/// (<see cref="LedgerEntries.Operating"/>), esclusi prestiti, investimenti e capitale.
|
||||
/// </summary>
|
||||
public static long OperatingProfit(long[] entries)
|
||||
{
|
||||
long revenue = entries[(int)LedgerEntry.FreightRevenue] + entries[(int)LedgerEntry.PassengerRevenue]
|
||||
+ entries[(int)LedgerEntry.Trading] + entries[(int)LedgerEntry.Contracts]
|
||||
+ entries[(int)LedgerEntry.Industries] + entries[(int)LedgerEntry.Subsidiaries];
|
||||
long costs = entries[(int)LedgerEntry.RunningCosts] + entries[(int)LedgerEntry.TrackMaintenance]
|
||||
+ entries[(int)LedgerEntry.FleetMaintenance] + entries[(int)LedgerEntry.Wages]
|
||||
+ entries[(int)LedgerEntry.Interest] + entries[(int)LedgerEntry.Penalties];
|
||||
return revenue + costs; // i costi sono già negativi
|
||||
long sum = 0;
|
||||
for (int i = 0; i < entries.Length && i < EntryCount; i++)
|
||||
{
|
||||
if (LedgerEntries.Operating((LedgerEntry)i)) sum += entries[i]; // i costi sono già negativi
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static long Revenue(long[] entries) =>
|
||||
entries[(int)LedgerEntry.FreightRevenue] + entries[(int)LedgerEntry.PassengerRevenue]
|
||||
+ Math.Max(0, entries[(int)LedgerEntry.Trading]) + Math.Max(0, entries[(int)LedgerEntry.Contracts])
|
||||
+ Math.Max(0, entries[(int)LedgerEntry.Industries]) + Math.Max(0, entries[(int)LedgerEntry.Subsidiaries]);
|
||||
/// <summary>
|
||||
/// Ricavi d'esercizio: tariffe merci e passeggeri come sono, le altre voci di ricavo solo se positive
|
||||
/// (commercio, contratti, industrie, controllate, dividendi incassati).
|
||||
/// </summary>
|
||||
public static long Revenue(long[] entries)
|
||||
{
|
||||
long sum = entries[(int)LedgerEntry.FreightRevenue] + entries[(int)LedgerEntry.PassengerRevenue];
|
||||
for (int i = 0; i < entries.Length && i < EntryCount; i++)
|
||||
{
|
||||
var e = (LedgerEntry)i;
|
||||
if (e is LedgerEntry.FreightRevenue or LedgerEntry.PassengerRevenue || LedgerEntries.Section(e) != IncomeSection.Revenue) continue;
|
||||
sum += Math.Max(0, entries[i]);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user