Chessistics/chessistics-engine/Model/DemandState.cs
Samuel Bouchet 8a377c2e41 Add recurring-demand mode with shortage tracking
DemandDef gains optional ConsumptionPerTurn and SustainTurns. When
ConsumptionPerTurn > 0 the demand maintains a buffer filled by
deliveries and drained each turn. Shortage fires the first turn the
buffer can't cover consumption; it clears when the buffer refills.
SustainedTurns counts consecutive non-shortage turns, and IsSatisfied
flips to true once it meets SustainTurns — so the victory condition
becomes "no shortage for N consecutive turns" as soon as a mission opts
in. Classic demands (ConsumptionPerTurn = 0) behave exactly as before.

TurnExecutor runs the consumption sub-phase after transfers. Two new
events (DemandShortageStarted / DemandShortageCleared) let the
presentation surface the state later. BoardSnapshot + CampaignLoader
carry the new fields; no existing mission opts in yet, so
campaign_01.json is unaffected.
2026-04-17 22:39:28 +02:00

43 lines
1.3 KiB
C#

namespace Chessistics.Engine.Model;
public class DemandState
{
public DemandDef Definition { get; }
public int ReceivedCount { get; set; }
public int MissionIndex { get; }
// Recurring demand tracking (only used when Definition.ConsumptionPerTurn > 0)
public int Buffer { get; set; }
public int SustainedTurns { get; set; }
public bool InShortage { get; set; }
public DemandState(DemandDef definition, int missionIndex = 0)
{
Definition = definition;
MissionIndex = missionIndex;
ReceivedCount = 0;
}
public bool IsRecurring => Definition.ConsumptionPerTurn > 0;
public bool IsSatisfied => IsRecurring
? SustainedTurns >= Definition.SustainTurns
: ReceivedCount >= Definition.Amount;
public Coords Position => Definition.Position;
public string Name => Definition.Name;
public CargoType Cargo => Definition.Cargo;
public int Required => Definition.Amount;
public int Deadline => Definition.Deadline;
public DemandState Clone()
{
return new DemandState(Definition, MissionIndex)
{
ReceivedCount = ReceivedCount,
Buffer = Buffer,
SustainedTurns = SustainedTurns,
InShortage = InShortage
};
}
}