Infrastruttura: nome «Rail Enterprise», CI e rilasci su Gitea, documentazione
Il progetto adotta il nome «Rail Enterprise» ovunque (codice RailEnterprise.*, variabili RE_*, intestazioni RESV/RECL, immagine rail-enterprise-server) per allinearsi al repository Gitea. Aggiunge Gitea Actions sul modello di Chronos: CI su PR e main, rilascio da tag con gioco Windows (client Godot + server in server/), server Windows/Linux e immagine Docker nel registro Gitea, nightly. Aggiunge i riferimenti visivi 06–09, i modelli di PR e issue, l'ADR 0014 e aggiorna README (comandi locali), STATE e CLAUDE.md. 120 test verdi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f6c2a17b4d
commit
c1a0049bcf
300 files changed
+1602
-1045
No files matched your search
@@ -0,0 +1,99 @@
|
||||
using RailEnterprise.Core.Common;
|
||||
using RailEnterprise.Core.Data;
|
||||
using RailEnterprise.Core.Economy;
|
||||
|
||||
namespace RailEnterprise.Core.Simulation.Systems;
|
||||
|
||||
/// <summary>Formule dell'industria condivise da più sistemi (guida 6.3 e 11).</summary>
|
||||
public static class IndustryMath
|
||||
{
|
||||
/// <summary>pf = clamp(1 + 0,5·margine, 0,6, 1,2).</summary>
|
||||
public static double ProfitFactor(Industry ind, IndustryBalance b) =>
|
||||
Math.Clamp(1 + b.ProfitFactorSlope * ind.Margin, b.ProfitFactorMin, b.ProfitFactorMax);
|
||||
|
||||
/// <summary>mc: 1 sopra 70, lineare fino a 0,5 a 20, 0,3 sotto 20.</summary>
|
||||
public static double ConditionMultiplier(double condition, IndustryMaintenanceBalance m)
|
||||
{
|
||||
if (condition >= m.EfficiencyFullAbove) return 1.0;
|
||||
if (condition < 20) return m.EfficiencyBelow20;
|
||||
double t = (condition - 20) / (m.EfficiencyFullAbove - 20);
|
||||
return m.EfficiencyAt20 + (1.0 - m.EfficiencyAt20) * t;
|
||||
}
|
||||
|
||||
/// <summary>Capienza del magazzino di un output (unità) al livello corrente.</summary>
|
||||
public static int OutputCapacity(Industry ind, int outputIndex, int daysPerMonth)
|
||||
{
|
||||
if (ind.Level <= 0) return 0;
|
||||
var outputs = ind.Def.Recipe.Outputs;
|
||||
double perDay = ind.CyclesPerDayAtFullCapacity(daysPerMonth) * outputs[outputIndex].PerCycle;
|
||||
return (int)Math.Ceiling(perDay * ind.Def.StorageDays);
|
||||
}
|
||||
|
||||
/// <summary>Capienza del magazzino di un input (unità) al livello corrente.</summary>
|
||||
public static int InputCapacity(Industry ind, int inputIndex, int daysPerMonth)
|
||||
{
|
||||
if (ind.Level <= 0 || ind.Closed) return 0;
|
||||
var inputs = ind.Def.Recipe.Inputs;
|
||||
double perDay = ind.CyclesPerDayAtFullCapacity(daysPerMonth) * inputs[inputIndex].PerCycle;
|
||||
return (int)Math.Ceiling(perDay * ind.Def.StorageDays);
|
||||
}
|
||||
|
||||
/// <summary>Ricambi consumati al mese dalla politica corrente: unità per livello.</summary>
|
||||
public static int MonthlyPartsUse(Industry ind, IndustryMaintenanceBalance m) =>
|
||||
ind.Level <= 0 || ind.Closed ? 0 : m.For(ind.Budget).SparePartsPerLevelPerMonth * ind.Level;
|
||||
|
||||
/// <summary>Scorta di ricambi desiderata: mesi di consumo della politica più quanto ordinato dal proprietario.</summary>
|
||||
public static int PartsTarget(Industry ind, IndustryMaintenanceBalance m) =>
|
||||
ind.Closed ? 0 : (int)Math.Ceiling(MonthlyPartsUse(ind, m) * m.PartsTargetMonths) + ind.PartsOrdered;
|
||||
|
||||
/// <summary>Macchinari richiesti dal lavoro programmato (revisione o ammodernamento).</summary>
|
||||
public static int MachineryRequired(Industry ind, IndustryMaintenanceBalance m) => ind.PendingWork switch
|
||||
{
|
||||
IndustryWork.Overhaul => m.OverhaulMachineryPerLevel * Math.Max(1, ind.Level),
|
||||
IndustryWork.Upgrade => m.UpgradeMachineryPerLevel * Math.Max(1, ind.Level),
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Bisogno di ricambi o macchinari per la manutenzione degli impianti (domanda esplicita: scorta
|
||||
/// desiderata − scorta); 0 per gli altri beni e per le industrie chiuse.
|
||||
/// </summary>
|
||||
public static int ServiceNeed(World w, Industry ind, int good)
|
||||
{
|
||||
if (ind.Closed) return 0;
|
||||
var m = w.Data.Balance.IndustryMaintenance;
|
||||
if (good == w.Data.SparePartsGood) return Math.Max(0, PartsTarget(ind, m) - ind.SpareParts);
|
||||
if (good == w.Data.MachineryGood) return Math.Max(0, MachineryRequired(ind, m) - ind.Machinery);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>Riceve ricambi o macchinari pagandoli al prezzo indicato; restituisce le unità prese.</summary>
|
||||
public static int ReceiveService(World w, Industry ind, int good, int units, double unitPrice)
|
||||
{
|
||||
int take = Math.Min(units, ServiceNeed(w, ind, good));
|
||||
if (take <= 0) return 0;
|
||||
if (good == w.Data.SparePartsGood) ind.SpareParts += take;
|
||||
else ind.Machinery += take;
|
||||
var cost = Common.Money.FromCentsRounded(take * unitPrice);
|
||||
w.Money.Transfer(Account.Of(ind.Id), Account.External, cost, LedgerEntry.Other);
|
||||
ind.PurchasesToday += cost.Cents;
|
||||
ind.MaintenanceSpentYear += cost.Cents;
|
||||
ind.LastServedDay = w.Clock.Day;
|
||||
return take;
|
||||
}
|
||||
|
||||
/// <summary>Utile annuo stimato dell'industria (ricavi − costi medi giornalieri × giorni dell'anno).</summary>
|
||||
public static double AnnualProfit(World w, Industry ind) => (ind.RevenueEma - ind.CostEma) * w.Calendar.DaysPerYear;
|
||||
|
||||
/// <summary>
|
||||
/// Prezzo di vendita di un'industria: quota del costo cumulato degli impianti (pesato dalla
|
||||
/// condizione) + multiplo dell'utile annuo positivo + cassa dell'impresa.
|
||||
/// </summary>
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user