F6: livelli e sblocchi visibili, pannello La tua scalata
I livelli esistevano dalla F5 ma il giocatore li vedeva solo come distintivo e come rifiuti con nomi scritti a mano. Ora il motore espone un quadro della scalata e il client lo mostra come l'immagine di riferimento 08. - ClimbOutlook (Core, sola lettura): livelli con gli sblocchi letti dai dati, giorno in cui sono stati raggiunti, requisiti del prossimo livello con valore, soglia, frazione e avanzamento (media delle tre frazioni, ora anche nel Mercato globale), stato patrimoniale, conto economico, prestiti, storico del patrimonio dalla Cronaca. - Stato patrimoniale con una sola fonte: FinanceSystem.BookValues scompone il valore contabile per voce e AssetBookValue ne e' la somma, cosi' il pannello somma al centesimo al patrimonio netto del motore. Le industrie possedute entrano nel patrimonio (impianti piu' cassa, senza avviamento): prima comprarle bruciava patrimonio. - Notizia di promozione con gli sblocchi ottenuti; rifiuti dei comandi bloccati con il livello che serve e il suo nome dai dati (compravendita, industrie, quotazione, scalate, concessioni, fido). - Salvataggio versione 6 (BalanceSheetSerializer) con voci e giorni dei livelli nell'hash; le versioni 1-5 si migrano con lo stesso patrimonio. - Protocollo: DetailKind.Climb (8) e ClimbReport (134), su richiesta. - Client: pannello ClimbPanel a tutto schermo, pulsante Scalata, livello e avanzamento nella barra superiore, schermata nel pilota automatico. - Test: Economy/ClimbTests.cs e quadro via WebSocket (170 test verdi). Decisioni in docs/adr/0018-scalata-e-livelli.md. Refs #38. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a61bf1dc27
commit
d473e21708
37 files changed
+2060
-70
No files matched your search
@@ -23,11 +23,7 @@ public sealed class ConstructionSystem : ISimSystem
|
||||
}
|
||||
|
||||
/// <summary>Squadre disponibili per una compagnia secondo il livello.</summary>
|
||||
public static int Crews(World w, Company c)
|
||||
{
|
||||
var byTier = w.Data.Construction.Crews.CrewsByTier;
|
||||
return byTier[Math.Clamp(c.Tier, 1, byTier.Length) - 1];
|
||||
}
|
||||
public static int Crews(World w, Company c) => Tiers.Crews(w, c.Tier);
|
||||
|
||||
private static void Projects(WorldContext ctx, World w)
|
||||
{
|
||||
|
||||
@@ -85,46 +85,66 @@ public sealed class FinanceSystem : ISimSystem
|
||||
|
||||
/// <summary>
|
||||
/// Valore contabile degli attivi: binari e veicoli ammortizzati, stazioni e depositi al costo,
|
||||
/// merce della compagnia (magazzini e spedizioni in viaggio) al prezzo globale (ADR 0016).
|
||||
/// industrie possedute (impianti e cassa dell'impresa, ADR 0018), merce della compagnia
|
||||
/// (magazzini e spedizioni in viaggio) al prezzo globale (ADR 0016). Scrive le voci in
|
||||
/// <see cref="Company.BookValues"/>: il patrimonio netto le somma.
|
||||
/// </summary>
|
||||
public static void UpdateBookValues(World w)
|
||||
{
|
||||
var values = BookValues(w);
|
||||
for (int i = 0; i < w.Companies.Count; i++) Array.Copy(values[i], w.Companies[i].BookValues, AssetCategories.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stato patrimoniale degli attivi non monetari di ogni compagnia, per voce
|
||||
/// (<see cref="AssetCategory"/>), calcolato al giorno corrente. Unica fonte del valore contabile.
|
||||
/// </summary>
|
||||
public static long[][] BookValues(World w)
|
||||
{
|
||||
var fb = w.Data.Balance.Finance;
|
||||
var values = new long[w.Companies.Count];
|
||||
var values = new long[w.Companies.Count][];
|
||||
for (int i = 0; i < values.Length; i++) values[i] = new long[AssetCategories.Count];
|
||||
const int track = (int)AssetCategory.Track, stations = (int)AssetCategory.Stations, vehicles = (int)AssetCategory.Vehicles,
|
||||
industries = (int)AssetCategory.Industries, goods = (int)AssetCategory.Goods;
|
||||
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));
|
||||
values[e.Owner.Value][track] += (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;
|
||||
if (w.Network.Nodes[s.Node.Value].Station == s.Id) values[s.Owner.Value][stations] += 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;
|
||||
if (w.Network.Nodes[d.Node.Value].Depot == d.Id) values[d.Owner.Value][stations] += 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));
|
||||
values[v.Owner.Value][vehicles] += (long)(v.Def.Price * Math.Max(fb.BookValueFloor, 1 - age / v.Def.LifeYears));
|
||||
}
|
||||
foreach (var ind in w.Industries)
|
||||
{
|
||||
if (ind.Closed || !ind.Owner.IsValid || ind.Owner.Value >= values.Length) continue;
|
||||
values[ind.Owner.Value][industries] += IndustryMath.BookValue(w, ind).Cents;
|
||||
}
|
||||
var prices = w.Market.GlobalPrice;
|
||||
foreach (var s in w.Network.Stations)
|
||||
{
|
||||
if (!s.Owner.IsValid || s.Owner.Value >= values.Length) continue;
|
||||
for (int g = 0; g < s.Stock.Length; g++) values[s.Owner.Value] += (long)(s.Stock[g] * prices[g]);
|
||||
values[s.Owner.Value] += OwnedGoodsValue(s.Waiting, prices);
|
||||
for (int g = 0; g < s.Stock.Length; g++) values[s.Owner.Value][goods] += (long)(s.Stock[g] * prices[g]);
|
||||
values[s.Owner.Value][goods] += OwnedGoodsValue(s.Waiting, prices);
|
||||
}
|
||||
foreach (var t in w.Trains)
|
||||
{
|
||||
if (!t.Removed && t.Owner.IsValid && t.Owner.Value < values.Length) values[t.Owner.Value] += OwnedGoodsValue(t.Cargo, prices);
|
||||
if (!t.Removed && t.Owner.IsValid && t.Owner.Value < values.Length) values[t.Owner.Value][goods] += OwnedGoodsValue(t.Cargo, prices);
|
||||
}
|
||||
for (int i = 0; i < w.Companies.Count; i++) w.Companies[i].AssetBookValue = new Money(values[i]);
|
||||
return values;
|
||||
}
|
||||
|
||||
private static long OwnedGoodsValue(List<Rail.Packet> packets, double[] prices)
|
||||
@@ -192,11 +212,7 @@ public sealed class FinanceSystem : ISimSystem
|
||||
}
|
||||
|
||||
/// <summary>Fido massimo della compagnia secondo il livello raggiunto.</summary>
|
||||
public static Money MaxLoan(World w, Company c)
|
||||
{
|
||||
var tier = w.Data.Tiers.Tiers[Math.Clamp(c.Tier, 1, w.Data.Tiers.Tiers.Count) - 1];
|
||||
return c.BaseCredit * tier.Unlocks.MaxLoanFactor;
|
||||
}
|
||||
public static Money MaxLoan(World w, Company c) => Tiers.LoanLimit(c, Tiers.Def(w, c.Tier));
|
||||
|
||||
/// <summary>Tasso annuo per un nuovo prestito: base della difficoltà + spread del rating.</summary>
|
||||
public static double LoanRate(World w, Company c) =>
|
||||
|
||||
@@ -92,8 +92,21 @@ public static class IndustryMath
|
||||
public static Common.Money Valuation(World w, Industry ind)
|
||||
{
|
||||
var p = w.Data.Balance.IndustryMaintenance.Purchase;
|
||||
double plant = ind.Def.UpgradeCost * Math.Max(1, ind.Level) * p.AssetShare * (1 - p.ConditionWeight + p.ConditionWeight * ind.Condition / 100);
|
||||
double earnings = Math.Max(0, AnnualProfit(w, ind)) * p.EarningsMultiple;
|
||||
return Common.Money.FromCentsRounded(plant + earnings + Math.Max(0, ind.Cash.Cents));
|
||||
return Common.Money.FromCentsRounded(PlantValue(w, ind) + earnings + Math.Max(0, ind.Cash.Cents));
|
||||
}
|
||||
|
||||
/// <summary>Valore degli impianti nel prezzo d'acquisto: costo d'ammodernamento × livello × quota, secondo le condizioni.</summary>
|
||||
public static double PlantValue(World w, Industry ind)
|
||||
{
|
||||
var p = w.Data.Balance.IndustryMaintenance.Purchase;
|
||||
return ind.Def.UpgradeCost * Math.Max(1, ind.Level) * p.AssetShare * (1 - p.ConditionWeight + p.ConditionWeight * ind.Condition / 100);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Valore contabile di un'industria per il proprietario (ADR 0018): il prezzo d'acquisto senza
|
||||
/// l'avviamento (multiplo degli utili), cioè impianti più cassa dell'impresa.
|
||||
/// </summary>
|
||||
public static Common.Money BookValue(World w, Industry ind) =>
|
||||
Common.Money.FromCentsRounded(PlantValue(w, ind) + Math.Max(0, ind.Cash.Cents));
|
||||
}
|
||||
@@ -4,16 +4,36 @@ using RailEnterprise.Core.Economy;
|
||||
|
||||
namespace RailEnterprise.Core.Simulation.Systems;
|
||||
|
||||
/// <summary>Sblocco di un livello (ADR 0018): tipo e valore (fido in centesimi, numero di squadre).</summary>
|
||||
public enum UnlockKind : byte
|
||||
{
|
||||
/// <summary>Fido massimo (valore: centesimi per la compagnia).</summary>
|
||||
LoanLimit = 0,
|
||||
/// <summary>Squadre di cantiere (valore: numero).</summary>
|
||||
Crews = 1,
|
||||
Trading = 2,
|
||||
BuyIndustry = 3,
|
||||
Ipo = 4,
|
||||
HostileTakeover = 5,
|
||||
Concessions = 6,
|
||||
}
|
||||
|
||||
public readonly record struct TierUnlock(UnlockKind Kind, long Value);
|
||||
|
||||
/// <summary>
|
||||
/// Livelli della compagnia (tiers.json): ogni mese, dopo il rating, una compagnia che soddisfa i
|
||||
/// requisiti del livello successivo (patrimonio netto, città collegate sopra una popolazione,
|
||||
/// rating) sale di un livello. Il livello non scende: gli sblocchi restano acquisiti (ADR 0011).
|
||||
/// Al passaggio la notizia elenca gli sblocchi ottenuti (ADR 0018).
|
||||
/// </summary>
|
||||
public static class Tiers
|
||||
{
|
||||
/// <summary>Definizione del livello indicato (limitato tra 1 e l'ultimo).</summary>
|
||||
public static TierDef Def(World w, int level) =>
|
||||
w.Data.Tiers.Tiers[Math.Clamp(level, 1, w.Data.Tiers.Tiers.Count) - 1];
|
||||
|
||||
/// <summary>Sblocchi del livello attuale della compagnia.</summary>
|
||||
public static TierUnlocks Unlocks(World w, Company c) =>
|
||||
w.Data.Tiers.Tiers[Math.Clamp(c.Tier, 1, w.Data.Tiers.Tiers.Count) - 1].Unlocks;
|
||||
public static TierUnlocks Unlocks(World w, Company c) => Def(w, c.Tier).Unlocks;
|
||||
|
||||
/// <summary>Promuove la compagnia se soddisfa i requisiti del livello successivo.</summary>
|
||||
public static void Evaluate(WorldContext ctx, Company c)
|
||||
@@ -24,12 +44,84 @@ public static class Tiers
|
||||
{
|
||||
var next = tiers[c.Tier];
|
||||
c.Tier = next.Level;
|
||||
c.TierReachedDay[next.Level - 1] = ctx.Day;
|
||||
Corporate.Milestone(w, c, $"diventa «{next.NameIt}»");
|
||||
ctx.Emit(new GameEvent(ctx.Day, EventKind.Company, EventSeverity.Opportunity,
|
||||
$"{c.Name} diventa «{next.NameIt}» (livello {next.Level})", EntityKind.Company, c.Id.Value, c.Id));
|
||||
ctx.Emit(new GameEvent(ctx.Day, EventKind.Company, EventSeverity.Opportunity, PromotionText(w, c, next.Level),
|
||||
EntityKind.Company, c.Id.Value, c.Id));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Testo della notizia di promozione con gli sblocchi ottenuti.</summary>
|
||||
public static string PromotionText(World w, Company c, int level)
|
||||
{
|
||||
var def = Def(w, level);
|
||||
var unlocks = NewUnlocks(w, c, level);
|
||||
string text = $"{c.Name} diventa «{def.NameIt}» (livello {def.Level})";
|
||||
return unlocks.Count == 0 ? text : $"{text}: sblocca {string.Join(", ", unlocks.Select(UnlockLabel))}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sblocchi che il livello aggiunge al precedente, nell'ordine di <see cref="UnlockKind"/>: per il
|
||||
/// primo livello la dotazione di partenza (fido e squadre). Tutto viene da tiers.json e dalle
|
||||
/// squadre di construction.json; il fido è quello della compagnia (fido iniziale × fattore).
|
||||
/// </summary>
|
||||
public static List<TierUnlock> NewUnlocks(World w, Company c, int level)
|
||||
{
|
||||
var def = Def(w, level);
|
||||
var u = def.Unlocks;
|
||||
var prev = def.Level > 1 ? Def(w, def.Level - 1) : null;
|
||||
var p = prev?.Unlocks;
|
||||
var list = new List<TierUnlock>();
|
||||
if (p is null || u.MaxLoanFactor > p.MaxLoanFactor) list.Add(new TierUnlock(UnlockKind.LoanLimit, LoanLimit(c, def).Cents));
|
||||
int crews = Crews(w, def.Level);
|
||||
if (prev is null || crews > Crews(w, prev.Level)) list.Add(new TierUnlock(UnlockKind.Crews, crews));
|
||||
if (u.Trading && p?.Trading != true) list.Add(new TierUnlock(UnlockKind.Trading, 0));
|
||||
if (u.BuyIndustry && p?.BuyIndustry != true) list.Add(new TierUnlock(UnlockKind.BuyIndustry, 0));
|
||||
if (u.Ipo && p?.Ipo != true) list.Add(new TierUnlock(UnlockKind.Ipo, 0));
|
||||
if (u.HostileTakeover && p?.HostileTakeover != true) list.Add(new TierUnlock(UnlockKind.HostileTakeover, 0));
|
||||
if (u.Concessions && p?.Concessions != true) list.Add(new TierUnlock(UnlockKind.Concessions, 0));
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>Fido massimo della compagnia a un livello: fido iniziale × fattore del livello.</summary>
|
||||
public static Money LoanLimit(Company c, TierDef def) => c.BaseCredit * def.Unlocks.MaxLoanFactor;
|
||||
|
||||
/// <summary>Squadre di cantiere a un livello (construction.json, le stesse di ConstructionSystem).</summary>
|
||||
public static int Crews(World w, int level)
|
||||
{
|
||||
var byTier = w.Data.Construction.Crews.CrewsByTier;
|
||||
return byTier[Math.Clamp(level, 1, byTier.Length) - 1];
|
||||
}
|
||||
|
||||
/// <summary>Etichetta italiana di uno sblocco (per le notizie del motore).</summary>
|
||||
public static string UnlockLabel(TierUnlock u) => u.Kind switch
|
||||
{
|
||||
UnlockKind.LoanLimit => $"fido fino a {new Money(u.Value).ToString("short")}",
|
||||
UnlockKind.Crews => $"{u.Value} squadre di cantiere",
|
||||
UnlockKind.Trading => "compravendita in proprio",
|
||||
UnlockKind.BuyIndustry => "acquisto di industrie",
|
||||
UnlockKind.Ipo => "quotazione in borsa",
|
||||
UnlockKind.HostileTakeover => "scalate ostili",
|
||||
UnlockKind.Concessions => "concessioni",
|
||||
_ => u.Kind.ToString(),
|
||||
};
|
||||
|
||||
/// <summary>Primo livello di tiers.json che ha lo sblocco indicato (null se nessuno).</summary>
|
||||
public static TierDef? FirstUnlocking(World w, Func<TierUnlocks, bool> unlock) =>
|
||||
w.Data.Tiers.Tiers.FirstOrDefault(t => unlock(t.Unlocks));
|
||||
|
||||
/// <summary>
|
||||
/// Testo di rifiuto per una funzione bloccata dal livello: «{funzione} si sblocca al livello N,
|
||||
/// «nome»» dai dati, oppure «{funzione} non è disponibile» se nessun livello la sblocca.
|
||||
/// </summary>
|
||||
public static string LockedText(World w, string feature, Func<TierUnlocks, bool> unlock, bool plural = false)
|
||||
{
|
||||
var tier = FirstUnlocking(w, unlock);
|
||||
return tier is null
|
||||
? $"{feature} {(plural ? "non sono disponibili" : "non è disponibile")}"
|
||||
: $"{feature} {(plural ? "si sbloccano" : "si sblocca")} al livello {tier.Level}, «{tier.NameIt}»";
|
||||
}
|
||||
|
||||
/// <summary>Requisiti di un livello soddisfatti dalla compagnia.</summary>
|
||||
public static bool Meets(World w, Company c, TierRequirements req) =>
|
||||
c.NetWorth.Cents >= req.NetWorth
|
||||
|
||||
Reference in new issue
Block a user