F6: tooltip perché sui valori calcolati dal server
Ogni valore importante dei pannelli spiega al passaggio del mouse da dove viene: formula, termini con i valori di oggi e note, calcolati dal Core e mandati dal server, perché il client non deve rifare né ricomporre formule. - Core: modello comune Explanation ed Explanations, pure funzioni che chiamano le stesse funzioni del motore; estratte senza cambiare l'aritmetica (hash invariati) Market.NextPrice e LocalPriceTerms, Tariffs.FreightTerms e PassengerTerms, TownSystem.GrowthOf, Fleet.DailyHazard, GameClock.YearsAt; Industry.LastEfficiency transitorio (né salvato né nell'hash). - Protocollo: RequestDetail kind 11 con un blocco 1 (subject, arg) ed ExplanationReport 137; il server risponde sempre, anche con available falso. Nessun campo nei delta, formato dei salvataggi invariato. - Client: WhyTooltip comune (palette 05, apertura dopo 0,45 s, «in arrivo…» finché la spiegazione manca) su barra superiore, Mercato, Scalata, Finanze, scheda industria, Treni e Officine; testi in strings.csv. - ADR 0024, PROTOCOL.md, ARCHITECTURE.md, STATE.md; 10 test nuovi in Economy/ExplanationTests.cs con uguaglianza esatta ai valori del motore. Refs #44. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
767661957b
commit
19a3dd3af1
33 files changed
+2089
-64
No files matched your search
@@ -47,6 +47,33 @@ public static class Fleet
|
||||
public static double Hazard(double condition, FailureParams f) =>
|
||||
condition < f.Pivot ? f.H0 * DMath.Exp(f.Slope * (f.Pivot - condition) / f.Scale) : f.H0 / f.HealthyDivisor;
|
||||
|
||||
/// <summary>
|
||||
/// Rischio giornaliero di guasto del treno nel giorno indicato: il più alto tra i componenti di tutti i
|
||||
/// veicoli (<see cref="Hazard"/>, ridotto dopo un'ispezione), con il veicolo e il componente che lo danno
|
||||
/// (il primo a parità). Lo usa il controllo dei guasti e la spiegazione della condizione (ADR 0024).
|
||||
/// </summary>
|
||||
public static (double Hazard, Vehicle? Vehicle, int Component) DailyHazard(World w, Train t, long day)
|
||||
{
|
||||
var m = w.Data.Maintenance;
|
||||
double best = -1;
|
||||
Vehicle? bv = null;
|
||||
int bc = -1;
|
||||
foreach (var id in t.Vehicles)
|
||||
{
|
||||
var v = w.Vehicles[id.Value];
|
||||
for (int j = 0; j < v.Components.Length; j++)
|
||||
{
|
||||
double h = Hazard(v.Components[j], m.Failure);
|
||||
if (day < v.HazardReducedUntilDay) h *= m.Inspection.HazardFactor;
|
||||
if (h <= best) continue;
|
||||
best = h;
|
||||
bv = v;
|
||||
bc = j;
|
||||
}
|
||||
}
|
||||
return (best, bv, bc);
|
||||
}
|
||||
|
||||
/// <summary>Fattore d'età: 1 fino alla vita utile, poi +0,5 ogni 5 anni, meno le riduzioni delle revisioni (minimo 1).</summary>
|
||||
public static double AgeFactor(World w, Vehicle v) => AgeFactor(w.Data.Maintenance.Wear, v, w.Clock.Day, w.Calendar.DaysPerYear);
|
||||
|
||||
|
||||
@@ -120,22 +120,7 @@ public sealed class FleetMaintenanceSystem : ISimSystem
|
||||
{
|
||||
var w = ctx.World;
|
||||
var m = w.Data.Maintenance;
|
||||
double best = -1;
|
||||
Vehicle? bv = null;
|
||||
int bc = -1;
|
||||
foreach (var id in t.Vehicles)
|
||||
{
|
||||
var v = w.Vehicles[id.Value];
|
||||
for (int j = 0; j < v.Components.Length; j++)
|
||||
{
|
||||
double h = Fleet.Hazard(v.Components[j], m.Failure);
|
||||
if (ctx.Day < v.HazardReducedUntilDay) h *= m.Inspection.HazardFactor;
|
||||
if (h <= best) continue;
|
||||
best = h;
|
||||
bv = v;
|
||||
bc = j;
|
||||
}
|
||||
}
|
||||
var (best, bv, bc) = Fleet.DailyHazard(w, t, ctx.Day);
|
||||
if (bv is null) return;
|
||||
var rng = w.Stream("fleet");
|
||||
if (rng.NextDouble() >= best) return;
|
||||
|
||||
@@ -112,6 +112,8 @@ public sealed class IndustrySystem : ISimSystem
|
||||
site.ReserveTonnes = Math.Max(0, site.ReserveTonnes - extracted);
|
||||
}
|
||||
ind.Efficiency = eLabor * covInToday * depletion * capacity;
|
||||
// termini di oggi per la spiegazione dell'efficienza (ADR 0024): non entrano nel salvataggio né nell'hash
|
||||
ind.LastEfficiency = new EfficiencyTerms(ctx.Day, ind.CovWorkers, ind.CovStaff, pf, mc, stopped, eLabor, covInToday, depletion, capacity, ind.Efficiency);
|
||||
|
||||
// salari giornalieri ai presenti
|
||||
double wages = (ind.WorkersPresent * ib.WagePerWorkerPerMonth + ind.StaffPresent * ib.WagePerStaffPerMonth) / dpm;
|
||||
|
||||
@@ -55,15 +55,9 @@ public sealed class MarketSystem : ISimSystem
|
||||
market.CapacityToday[g] = 0;
|
||||
continue;
|
||||
}
|
||||
double pw = pb * Math.Max(m.World.PriceFloor, 1 + Market.WorldFactor(m, volatility, years, market.Shock[g]));
|
||||
double d = market.Demand[g].Sum;
|
||||
double s = market.Supply[g].Sum;
|
||||
double v = Math.Max(m.World.BaselinePerDay * market.Demand[g].Count, m.World.VolumeShare * (d + s) / 2);
|
||||
double dTot = d + v * DMath.Pow(pw / pg, m.World.Elasticity);
|
||||
double sTot = s + v * DMath.Pow(pg / pw, m.World.Elasticity);
|
||||
double ratio = DMath.Clamp(dTot / Math.Max(1e-9, sTot), m.RatioMin, m.RatioMax);
|
||||
double target = DMath.Clamp(pg * (1 + m.K * (ratio - 1)), m.MinPriceFactor * pb, m.MaxPriceFactor * pb);
|
||||
pg = m.Alpha * target + (1 - m.Alpha) * pg;
|
||||
// una sola formula per il passo del prezzo: la rifà anche la spiegazione del prezzo (ADR 0024)
|
||||
pg = Market.NextPrice(m, pb, pg, market.Demand[g].Sum, market.Supply[g].Sum, market.Demand[g].Count,
|
||||
volatility, years, market.Shock[g]).Price;
|
||||
market.GlobalPrice[g] = pg;
|
||||
market.PriceHistory[g].Add(pg);
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ using RailEnterprise.Core.Map;
|
||||
|
||||
namespace RailEnterprise.Core.Simulation.Systems;
|
||||
|
||||
/// <summary>Termini della crescita mensile di una città: servizi, soddisfazione, occupati per abitante, g grezza e limitata, popolazione nuova.</summary>
|
||||
public readonly record struct TownGrowthTerms(int Services, double Satisfaction, double Employment, double RawGrowth, double Growth, int Population);
|
||||
|
||||
/// <summary>
|
||||
/// Città: consumo giornaliero e soddisfazione per categoria, crescita mensile, espansione
|
||||
/// dell'abitato e migrazione annuale verso le città meglio servite (guida 6.3).
|
||||
@@ -70,22 +73,34 @@ public sealed class TownSystem : ISimSystem
|
||||
town.WorkDissatisfaction *= 1.0 - 1.0 / tb.WorkDissatisfactionDecayDays;
|
||||
}
|
||||
|
||||
private static void Grow(WorldContext ctx, Town town)
|
||||
/// <summary>
|
||||
/// Crescita mensile della città dallo stato attuale (guida 6.3): servizi, soddisfazione, occupati per
|
||||
/// abitante, g = base + ps·(soddisfazione − perno) + po·(occupati/popolazione − perno), limitata a ±max,
|
||||
/// e popolazione che ne risulta. La usa la crescita del mese e la spiegazione del valore (ADR 0024).
|
||||
/// </summary>
|
||||
public static TownGrowthTerms GrowthOf(Town town, TownBalance tb)
|
||||
{
|
||||
var tb = ctx.Data.Balance.Town;
|
||||
int services = town.Population / Math.Max(1, tb.BaseServicesPerPopulation);
|
||||
for (int c = 0; c < Town.CategoryCount; c++)
|
||||
{
|
||||
if (town.CategoryActive[c] && town.Satisfaction[c] >= tb.ServicesSatisfactionThreshold) services++;
|
||||
}
|
||||
town.Services = services;
|
||||
double sat = town.OverallSatisfaction;
|
||||
double employment = town.Population > 0 ? (double)(town.EmployedWorkers + town.EmployedStaff) / town.Population : 0;
|
||||
double g = tb.BaseGrowth + tb.SatisfactionWeight * (sat - tb.SatisfactionPivot) + tb.EmploymentWeight * (employment - tb.EmploymentPivot);
|
||||
g = Math.Clamp(g, -tb.MaxMonthlyGrowth, tb.MaxMonthlyGrowth);
|
||||
town.LastGrowth = g;
|
||||
double raw = tb.BaseGrowth + tb.SatisfactionWeight * (sat - tb.SatisfactionPivot) + tb.EmploymentWeight * (employment - tb.EmploymentPivot);
|
||||
double g = Math.Clamp(raw, -tb.MaxMonthlyGrowth, tb.MaxMonthlyGrowth);
|
||||
int population = Math.Clamp((int)Math.Round(town.Population * (1 + g)), 0, tb.MaxPopulation);
|
||||
return new TownGrowthTerms(services, sat, employment, raw, g, population);
|
||||
}
|
||||
|
||||
private static void Grow(WorldContext ctx, Town town)
|
||||
{
|
||||
var tb = ctx.Data.Balance.Town;
|
||||
var growth = GrowthOf(town, tb);
|
||||
town.Services = growth.Services;
|
||||
town.LastGrowth = growth.Growth;
|
||||
int before = town.Population;
|
||||
town.Population = Math.Clamp((int)Math.Round(town.Population * (1 + g)), 0, tb.MaxPopulation);
|
||||
town.Population = growth.Population;
|
||||
if (before < tb.PopulationMilestone && town.Population >= tb.PopulationMilestone)
|
||||
ctx.Emit(EventKind.Town, EventSeverity.Info, $"{town.Name} supera i {Money.GroupThousands((ulong)tb.PopulationMilestone)} abitanti", EntityKind.Town, town.Id.Value);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user