diff --git a/src/ViaFerrea.Core/Simulation/Systems/TownSystem.cs b/src/ViaFerrea.Core/Simulation/Systems/TownSystem.cs index 8c9c6b1..aa39f2f 100644 --- a/src/ViaFerrea.Core/Simulation/Systems/TownSystem.cs +++ b/src/ViaFerrea.Core/Simulation/Systems/TownSystem.cs @@ -47,14 +47,18 @@ public sealed class TownSystem : ISimSystem continue; } int cat = (int)data.Goods[g].Town!.Category; + int stockBefore = town.Stock[g]; town.DemandAccumulator[g] += demand; int want = (int)Math.Floor(town.DemandAccumulator[g]); - int used = Math.Min(want, town.Stock[g]); + int used = Math.Min(want, stockBefore); town.Stock[g] -= used; w.Goods.Consumed[g] += used; town.DemandAccumulator[g] -= want; // la domanda non servita non si accumula + // quota servita: con domande frazionarie il consumo è a scatti, quindi conta se la + // scorta copriva la richiesta del giorno, non il rapporto tra unità intere e decimali + double served = want > 0 ? (double)used / want : stockBefore > 0 ? 1.0 : 0.0; _catDemand[cat] += demand; - _catConsumed[cat] += used; + _catConsumed[cat] += demand * served; } for (int c = 0; c < Town.CategoryCount; c++) {