- Sezione 11: usura e recupero degli impianti, fermi e incidenti, ricambi e macchinari come domanda esplicita (treno, trasporto locale, trasbordo nel bacino), revisione e ammodernamento, acquisto delle industrie dal livello 3, conguaglio mensile con il proprietario (ADR 0011). - Livelli della compagnia con soglie ritarate e ritaratura economica misurata con le IA. - Sezione 12.2–12.3: libro dei soci, prezzo con sentiment, quotazione, riacquisto, dividendi, controllo e fusione (comando 39), offerte pubbliche con difese, esiti per difficoltà, aste delle IA fallite, nuovi concorrenti, fine partita e Cronaca finale (ADR 0012). - Sezione 12.1: agenti IA con candidati, Dijkstra sulle celle, TrackPreview e ROI, tre personalità, linee dei ricambi, rimedio agli stalli, borsa (ADR 0013). - Salvataggio versione 3, protocollo (messaggi 126–128, blocchi di estensione), server, simulate --trace-ai; test di 14.5 su IA e borsa e accettazione F5 (120 test). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
68 lines
2.6 KiB
C#
68 lines
2.6 KiB
C#
using ViaFerrea.Core.Common;
|
|
using ViaFerrea.Core.Economy;
|
|
|
|
namespace ViaFerrea.Core.Simulation.Systems;
|
|
|
|
/// <summary>
|
|
/// Domanda giornaliera: consumo desiderato delle città (con elasticità al prezzo), input
|
|
/// richiesti dalle industrie al loro potenziale di lavoro e ricambi per gli impianti.
|
|
/// Alimenta D del mercato.
|
|
/// </summary>
|
|
public sealed class DemandSystem : ISimSystem
|
|
{
|
|
public string Name => "Demand";
|
|
|
|
public void Step(WorldContext ctx)
|
|
{
|
|
if (!ctx.IsNewDay) return;
|
|
var w = ctx.World;
|
|
var data = w.Data;
|
|
var market = w.Market;
|
|
int year = ctx.Year;
|
|
|
|
foreach (var town in w.Towns)
|
|
{
|
|
for (int g = 0; g < data.GoodCount; g++)
|
|
{
|
|
double d = TownDemand(w, town, g, year);
|
|
town.DemandToday[g] = d;
|
|
market.DemandToday[g] += d;
|
|
}
|
|
}
|
|
|
|
int dpm = w.Calendar.DaysPerMonth;
|
|
var im = data.Balance.IndustryMaintenance;
|
|
foreach (var ind in w.Industries)
|
|
{
|
|
if (ind.Closed || ind.Level <= 0)
|
|
{
|
|
Array.Clear(ind.InputDemandToday);
|
|
continue;
|
|
}
|
|
// ricambi per la manutenzione degli impianti (sezione 11)
|
|
market.DemandToday[data.SparePartsGood] += (double)IndustryMath.MonthlyPartsUse(ind, im) / dpm;
|
|
double eLabor = Math.Min(ind.CovWorkers, ind.CovStaff) * IndustryMath.ProfitFactor(ind, data.Balance.Industry)
|
|
* IndustryMath.ConditionMultiplier(ind.Condition, data.Balance.IndustryMaintenance);
|
|
double cycles = ind.CyclesPerDayAtFullCapacity(dpm) * eLabor;
|
|
var inputs = ind.Def.Recipe.Inputs;
|
|
for (int i = 0; i < inputs.Count; i++)
|
|
{
|
|
double need = cycles * inputs[i].PerCycle;
|
|
ind.InputDemandToday[i] = need;
|
|
market.DemandToday[inputs[i].GoodIndex] += need;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Domanda giornaliera di una città per un bene, in unità.</summary>
|
|
public static double TownDemand(World w, Town town, int good, int year)
|
|
{
|
|
var def = w.Data.Goods[good];
|
|
if (def.Town is not { } td || def.Era > year || (td.UntilYear is { } until && year >= until)) return 0;
|
|
double ratio = w.Market.GlobalPrice[good] / def.BasePrice;
|
|
var tb = w.Data.Balance.Town;
|
|
double priceFactor = DMath.Clamp(DMath.Pow(ratio, -def.Elasticity), tb.DemandPriceFactorMin, tb.DemandPriceFactorMax);
|
|
return town.Population / 1000.0 * td.DemandPerThousand * priceFactor;
|
|
}
|
|
}
|