From 19a3dd3af1735ff0a3a2454db670fad2981be3ef Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Sun, 8 Nov 2026 15:14:57 +0100 Subject: [PATCH 1/2] =?UTF-8?q?F6:=20tooltip=20perch=C3=A9=20sui=20valori?= =?UTF-8?q?=20calcolati=20dal=20server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../assets/i18n/strings.csv | 226 +++++++ .../scripts/Hud/TopBar.cs | 9 +- .../scripts/Panels/ClimbPanel.cs | 6 + .../scripts/Panels/FinancePanel.cs | 2 + .../scripts/Panels/IndustryPanel.cs | 32 +- .../scripts/Panels/MaintenancePanel.cs | 7 +- .../scripts/Panels/MarketPanel.cs | 10 + .../scripts/Panels/TrainsPanel.cs | 16 + .../scripts/Panels/WhyTooltip.cs | 255 +++++++ .../scripts/Screens/GameScreen.cs | 6 + docs/ARCHITECTURE.md | 4 +- docs/PROTOCOL.md | 7 +- docs/STATE.md | 11 +- docs/adr/0024-tooltip-perche.md | 85 +++ .../Economy/Explanation.cs | 93 +++ .../Economy/Explanations.cs | 632 ++++++++++++++++++ src/RailEnterprise.Core/Economy/Industry.cs | 11 + src/RailEnterprise.Core/Economy/Market.cs | 72 +- .../Simulation/Systems/Fleet.cs | 27 + .../Systems/FleetMaintenanceSystem.cs | 17 +- .../Simulation/Systems/IndustrySystem.cs | 2 + .../Simulation/Systems/MarketSystem.cs | 12 +- .../Simulation/Systems/TownSystem.cs | 29 +- src/RailEnterprise.Core/Time/GameClock.cs | 5 +- .../Client/ClientWorld.cs | 14 + src/RailEnterprise.Protocol/Message.cs | 2 + .../Messages/ClientMessages.cs | 36 +- .../Messages/ExplanationMessages.cs | 92 +++ .../Messages/MessageCodec.cs | 1 + src/RailEnterprise.Server/GameHost.cs | 4 + src/RailEnterprise.Server/Projection.cs | 13 + .../Economy/ExplanationTests.cs | 406 +++++++++++ .../Protocol/ProtocolTests.cs | 9 + 33 files changed, 2089 insertions(+), 64 deletions(-) create mode 100644 client/RailEnterprise.Client/scripts/Panels/WhyTooltip.cs create mode 100644 docs/adr/0024-tooltip-perche.md create mode 100644 src/RailEnterprise.Core/Economy/Explanation.cs create mode 100644 src/RailEnterprise.Core/Economy/Explanations.cs create mode 100644 src/RailEnterprise.Protocol/Messages/ExplanationMessages.cs create mode 100644 tests/RailEnterprise.Tests/Economy/ExplanationTests.cs diff --git a/client/RailEnterprise.Client/assets/i18n/strings.csv b/client/RailEnterprise.Client/assets/i18n/strings.csv index c7ab4f1..38ae12b 100644 --- a/client/RailEnterprise.Client/assets/i18n/strings.csv +++ b/client/RailEnterprise.Client/assets/i18n/strings.csv @@ -825,3 +825,229 @@ Interfaccia,,Interface Muto,,Mute Il tasto M attiva e toglie il muto durante la partita.,,The M key toggles mute during the game. Audio (M: muto),,Audio (M: mute) +Perché questo valore,,Why this value +in arrivo…,,on its way… +aggiornamento in arrivo…,,update on its way… +motore,,engine +freni,,brakes +cassa,,body +Valore non disponibile.,,Value not available. +Avanzamento del livello,,Level progress +Prezzo globale,,Global price +Prezzo base,,Base price +Prezzo iniziale: il prezzo base del bene.,,Starting price: the good's base price. +Bene non ancora in commercio: il prezzo resta quello di partenza.,,Good not yet on the market: the price stays at its starting value. +Prezzo di ieri,,Yesterday's price +Domanda della regione (finestra),,Regional demand (window) +Offerta della regione (finestra),,Regional supply (window) +Prezzo mondiale,,World price +Scambi con il resto del mondo,,Trade with the rest of the world +Rapporto domanda / offerta (con il mondo),,Demand / supply ratio (with the world) +Sensibilità al rapporto,,Sensitivity to the ratio +Prezzo minimo,,Minimum price +Prezzo massimo,,Maximum price +Prezzo obiettivo,,Target price +Peso del giorno,,Weight of the day +"D e S comprendono gli scambi con il resto del mondo al prezzo mondiale, che segue il ciclo economico e gli shock.",,"D and S include trade with the rest of the world at the world price, which follows the business cycle and shocks." +Il prezzo è cambiato dopo l'ultimo passo del mercato.,,The price changed after the last market step. +Prezzo locale,,Local price +"Prezzo a cui l'industria compra la prossima unità: Dl è la scorta desiderata dell'ingresso, Sl la scorta.",,"Price at which the industry buys the next unit: Dl is the desired input stock, Sl the stock." +"Prezzo a cui l'industria vende la prossima unità: Dl è lo spazio libero del magazzino, Sl la giacenza.",,"Price at which the industry sells the next unit: Dl is the free warehouse space, Sl the stock on hand." +Domanda locale,,Local demand +Offerta locale,,Local supply +Peso dello squilibrio,,Weight of the imbalance +Correzione per scorte nulle,,Correction for empty stock +Scarto massimo dal prezzo globale,,Maximum deviation from the global price +Squilibrio locale,,Local imbalance +Fattore locale,,Local factor +Tariffa merci,,Freight fare +Tariffa di una unità consegnata nel tempo atteso; tf scende dopo la soglia di ritardo fino al minimo.,,Fare for one unit delivered in the expected time; tf falls after the lateness threshold down to the minimum. +Nessun treno della linea collega la tratta con questo bene: il tempo atteso non è noto e tf vale 1.,,No train on the line links the stretch with this good: the expected time is unknown and tf is 1. +tariffa = u × Tb × (a + b·Pg/Pb) × km^e × tf × d,,fare = u × Tb × (a + b·Pg/Pb) × km^e × tf × d +Unità,,Units +Tariffa base,,Base fare +Quota fissa,,Fixed part +Quota legata al prezzo,,Price-linked part +Fattore del prezzo,,Price factor +Distanza in linea d'aria,,Straight-line distance +Esponente della distanza,,Distance exponent +Fattore della distanza,,Distance factor +Puntualità,,Punctuality +Moltiplicatore della difficoltà,,Difficulty multiplier +Tempo atteso,,Expected time +soglia,,threshold +Soglia di ritardo (volte il tempo atteso),,Lateness threshold (times the expected time) +Puntualità minima,,Minimum punctuality +Puntualità a due volte il tempo atteso,,Punctuality at twice the expected time +tariffa 2×,,fare 2× +Tariffa a due volte il tempo atteso,,Fare at twice the expected time +Tariffa passeggeri,,Passenger fare +Tariffa di un posto consegnato nel tempo atteso; tf scende dopo la soglia di ritardo fino al minimo.,,Fare for one seat delivered in the expected time; tf falls after the lateness threshold down to the minimum. +Nessun treno sulla linea: il comfort delle carrozze vale 1.,,No train on the line: carriage comfort is 1. +Nessun treno della linea collega la tratta per questa classe: il tempo atteso non è noto e tf vale 1.,,No train on the line links the stretch for this class: the expected time is unknown and tf is 1. +Tariffa del personale,,Staff fare +Tariffa dei lavoratori,,Workers' fare +tariffa = p × Tp × km^e × classe × tf × d × comfort,,fare = p × Tp × km^e × class × tf × d × comfort +Posti,,Seats +Tariffa base per posto,,Base fare per seat +classe,,class +Moltiplicatore della classe,,Class multiplier +Comfort delle carrozze,,Carriage comfort +senza comfort,,no comfort +Tariffa prima del comfort,,Fare before comfort +Industria chiusa.,,Industry closed. +I termini arrivano con la prossima produzione giornaliera (dopo un caricamento non sono salvati).,,"The terms arrive with the next daily production (they are not saved, so they are missing after a load)." +Copertura dei lavoratori (media mobile),,Worker coverage (moving average) +Copertura del personale (media mobile),,Staff coverage (moving average) +Fattore di profitto,,Profit factor +lavoro,,work +Ritmo del lavoro,,Work pace +Copertura degli ingressi di oggi,,Today's input coverage +Giacimento,,Deposit +margine,,margin +Margine (media mobile),,Margin (moving average) +condizione,,condition +Condizione degli impianti (0–100),,Plant condition (0–100) +"Industria ferma (guasto, incidente, revisione o ammodernamento): il ritmo del lavoro è zero.",,"Industry stopped (failure, accident, overhaul or upgrade): the work pace is zero." +Livello 0: l'industria è inattiva.,,Level 0: the industry is inactive. +Sopra la soglia di crescita per i trimestri richiesti il livello sale; sotto la soglia di calo scende.,,Above the growth threshold for the required quarters the level rises; below the decline threshold it falls. +Non servita da un vettore nel trimestre: il livello non cambia.,,Not served by a carrier this quarter: the level does not change. +punteggio = ws·quota + wc·copertura + wr·redditività,,score = ws·share + wc·coverage + wr·profitability +quota,,share +Quota trasportata,,Share carried +spedite,,shipped +Unità spedite nel trimestre,,Units shipped in the quarter +prodotte,,produced +Unità prodotte nel trimestre,,Units produced in the quarter +Copertura media,,Average coverage +Giorni del trimestre,,Days in the quarter +redditività,,profitability +Redditività (margine + 1)/2,,Profitability (margin + 1)/2 +Peso della quota,,Weight of the share +Peso della copertura,,Weight of the coverage +Peso della redditività,,Weight of the profitability +soglia su,,threshold up +Soglia di crescita,,Growth threshold +soglia giù,,threshold down +Soglia di calo,,Decline threshold +trimestri,,quarters +Trimestri sopra soglia,,Quarters above threshold +richiesti,,required +Trimestri richiesti,,Quarters required +Crescita della città,,Town growth +"g = g₀ + ws·(s − s₀) + wo·(o − o₀), limitata a ±gmax",,"g = g₀ + ws·(s − s₀) + wo·(o − o₀), capped at ±gmax" +Crescita di base,,Base growth +Soddisfazione neutra,,Neutral satisfaction +Peso della soddisfazione,,Weight of satisfaction +Occupati per abitante,,Employed per inhabitant +Occupazione neutra,,Neutral employment +Peso dell'occupazione,,Weight of employment +g grezza,,raw g +Crescita prima del limite,,Growth before the cap +Crescita massima al mese,,Maximum growth per month +dopo,,after +Abitanti dopo il mese,,Population after the month +ultimo mese,,last month +Crescita dell'ultimo mese,,Last month's growth +Stima con lo stato di oggi: la crescita si applica all'inizio del mese.,,Estimate from today's state: growth is applied at the start of the month. +Condizione del treno,,Train condition +Componente più debole,,Weakest component +veicolo,,vehicle +Veicolo,,Vehicle +Usura al giorno (media mobile),,Wear per day (moving average) +c rischio,,c risk +Componente più a rischio,,Component most at risk +Rischio di base al giorno,,Base risk per day +Condizione di soglia,,Threshold condition +Pendenza del rischio,,Risk slope +Scala della condizione,,Condition scale +Riduzione sopra soglia,,Reduction above threshold +ispezione,,inspection +Fattore dopo un'ispezione,,Factor after an inspection +Rischio di guasto al giorno,,Failure risk per day +Giorni attesi al prossimo guasto,,Expected days to the next failure +Condizione obiettivo del pianificatore,,Planner's target condition +Margine del pianificatore,,Planner's margin +stima,,estimate +Giorni all'intervento sulla condizione,,Days to condition-based maintenance +Nessuna stima del pianificatore: i componenti non si sono ancora consumati.,,No planner estimate: the components have not worn yet. +Il guasto è estratto ogni giorno con il rischio h: 1/h è il numero medio di giorni prima del prossimo.,,A failure is drawn every day with risk h: 1/h is the average number of days before the next one. +"c = min(componenti); h = h₀·exp(k·(c₀ − c)/σ) sotto c₀, altrimenti h₀/div; stima = (c − obiettivo)/usura − margine",,"c = min(components); h = h₀·exp(k·(c₀ − c)/σ) below c₀, otherwise h₀/div; estimate = (c − target)/wear − margin" +Valore del veicolo,,Vehicle value +prezzo,,price +Prezzo di listino,,List price +età,,age +Età,,Age +vita,,life +Vita utile,,Useful life +Superato dal,,Superseded since +anni superato,,years superseded +Anni da superato,,Years since superseded +perdita,,loss +Perdita immediata,,Immediate loss +velocità,,speed +Ammortamento più rapido,,Faster depreciation +successore,,successor +Successore consigliato,,Recommended successor +"r = max(rmin, (1 − perdita)·(1 − (età + (velocità − 1)·anni superato)/vita)); valore = prezzo·r; rivendita = prezzo·r·condizione",,"r = max(rmin, (1 − loss)·(1 − (age + (speed − 1)·years superseded)/life)); value = price·r; resale = price·r·condition" +Modello superato: perde subito una quota del valore e si ammortizza più in fretta.,,Superseded model: it loses part of its value at once and depreciates faster. +"r = max(rmin, 1 − età/vita); valore = prezzo·r; rivendita = prezzo·r·condizione",,"r = max(rmin, 1 − age/life); value = price·r; resale = price·r·condition" +Valore minimo,,Minimum value +Quota residua del valore,,Remaining share of value +Condizione media dei componenti,,Average component condition +rivendita,,resale +Rivendita,,Resale +"Margine (utile operativo / ricavi, 12 mesi)",,"Margin (operating profit / revenue, 12 months)" +Componente del margine,,Margin component +leva,,leverage +Debiti / patrimonio netto,,Debt / net worth +Componente della leva,,Leverage component +Peso del margine,,Weight of the margin +Peso della leva,,Weight of the leverage +"Rating iniziale: le misure sono quelle di oggi, il primo calcolo è a inizio mese.",,"Initial rating: the measures are today's, the first calculation is at the start of the month." +Margine neutro finché la finestra non ha abbastanza mesi con ricavi.,,Neutral margin until the window has enough months with revenue. +Compagnia in bancarotta: il rating è D.,,Company bankrupt: the rating is D. +gradino,,step +Gradino sopra,,Next step up +Punteggio del gradino sopra,,Score of the next step up +Il punteggio vale già il gradino sopra: il rating cambia al prossimo calcolo mensile.,,The score already earns the next step up: the rating changes at the next monthly calculation. +margine necessario,,margin needed +"Margine che basta, a leva invariata",,"Margin that is enough, with leverage unchanged" +leva massima,,max leverage +"Leva che basta, a margine invariato",,"Leverage that is enough, with margin unchanged" +rimborso,,repayment +Debito da rimborsare per la leva che basta,,Debt to repay to reach that leverage +Rating più alto.,,Highest rating. +"punteggio = pm·clamp(0,5 + margine, 0, 1) + pl·1/(1 + leva)",,"score = pm·clamp(0.5 + margin, 0, 1) + pl·1/(1 + leverage)" +Livello più alto.,,Highest level. +Finché un requisito manca l'avanzamento resta sotto il 100%.,,"While a requirement is missing, progress stays below 100%." +"avanzamento = (fP + fC + fR)/3; fP = min(1, patrimonio/soglia); fC = min(1, città/richieste); fR = 1 − gradini mancanti/n",,"progress = (fP + fC + fR)/3; fP = min(1, net worth/threshold); fC = min(1, cities/wanted); fR = 1 − missing steps/n" +Patrimonio richiesto,,Net worth required +Frazione del patrimonio,,Net worth fraction +città,,cities +Città collegate,,Towns connected +Città richieste,,Towns required +Abitanti minimi per città,,Minimum population per town +Frazione delle città,,Towns fraction +rating richiesto,,rating required +Rating richiesto,,Rating required +Gradini per lo zero,,Steps to zero +Frazione del rating,,Rating fraction +tetto,,cap +Tetto con un requisito mancante,,Cap with a requirement missing +Le voci del mese sono nel pannello «Finanze».,,The month's items are in the «Finances» panel. +inizio,,start +Cassa a inizio mese,,Cash at the start of the month +ricavi,,revenue +Ricavi del mese,,Revenue this month +costi,,costs +Costi del mese,,Costs this month +capitale,,capital +Investimenti e finanziamenti del mese,,Investment and financing this month +flusso,,flow +Flusso di cassa del mese,,Cash flow this month +Giorni di cassa negativa,,Days of negative cash +limite,,limit +Giorni che portano alla bancarotta,,Days that lead to bankruptcy +Con la cassa negativa per troppi giorni di fila la compagnia fallisce.,,With negative cash for too many days in a row the company goes bankrupt. +cassa = cassa a inizio mese + ricavi + costi + investimenti e finanziamenti,,cash = cash at start of month + revenue + costs + investment and financing diff --git a/client/RailEnterprise.Client/scripts/Hud/TopBar.cs b/client/RailEnterprise.Client/scripts/Hud/TopBar.cs index 89bae21..32fce48 100644 --- a/client/RailEnterprise.Client/scripts/Hud/TopBar.cs +++ b/client/RailEnterprise.Client/scripts/Hud/TopBar.cs @@ -2,6 +2,7 @@ using Godot; using RailEnterprise.Client.App; using RailEnterprise.Client.Net; using RailEnterprise.Client.Panels; +using RailEnterprise.Core.Economy; using RailEnterprise.Protocol.Messages; using static RailEnterprise.Client.App.Localization; @@ -26,7 +27,6 @@ public partial class TopBar : PanelContainer private readonly Label _server = UiTheme.Text("", 14); private readonly ColorRect _serverDot = new() { CustomMinimumSize = new Vector2(10, 10) }; private readonly List