using System; namespace KernelPanic.Combat { public enum NixGovernor { Performance, Powersave, Schedutil } /// Wave-local policy state. Commit only after combat validates phase and target. public sealed class NixGovernorState { // Explicit checkpoint values: no gameplay hooks or random draws during restoration. internal NixGovernorStateValues CaptureValues() => new() { Governor = Governor, Version = Version, FreeSwitchUsed = FreeSwitchUsed, LastSwitchRound = LastSwitchRound, }; internal void RestoreValues(NixGovernorStateValues value) { Governor = value.Governor; Version = value.Version; FreeSwitchUsed = value.FreeSwitchUsed; LastSwitchRound = value.LastSwitchRound; } public NixGovernor Governor { get; private set; } = NixGovernor.Schedutil; public int Version { get; private set; } public bool Active => Version > 0; public bool FreeSwitchUsed { get; private set; } public int LastSwitchRound { get; private set; } = -1; public int SwitchCost => Version >= 3 && !FreeSwitchUsed ? 0 : 1; public int DamagePercent => DamageFor(Governor); public int ShieldPercent => ShieldFor(Governor); public int DamageFor(NixGovernor governor) => governor switch { NixGovernor.Performance => !Active ? 100 : Version >= 4 ? 130 : 120, NixGovernor.Powersave => !Active ? 100 : 80, NixGovernor.Schedutil => !Active ? 100 : Version >= 2 ? 110 : 105, _ => throw new ArgumentOutOfRangeException(nameof(governor), governor, "Unknown governor.") }; public int ShieldFor(NixGovernor governor) => governor switch { NixGovernor.Performance => !Active ? 100 : 75, NixGovernor.Powersave => !Active ? 100 : Version >= 4 ? 140 : 130, NixGovernor.Schedutil => !Active ? 100 : Version >= 2 ? 110 : 105, _ => throw new ArgumentOutOfRangeException(nameof(governor), governor, "Unknown governor.") }; public void BeginWave(int version) { Version = Math.Max(0, Math.Min(5, version)); Governor = NixGovernor.Schedutil; LastSwitchRound = -1; FreeSwitchUsed = false; } public NixGovernorSwitchBlockReason GetSwitchBlockReason(NixGovernor governor, int round, int cycles) { if (!Enum.IsDefined(typeof(NixGovernor), governor)) return NixGovernorSwitchBlockReason.InvalidGovernor; if (!Active) return NixGovernorSwitchBlockReason.Inactive; if (governor == Governor) return NixGovernorSwitchBlockReason.AlreadySelected; if (LastSwitchRound == round) return NixGovernorSwitchBlockReason.AlreadySwitchedThisRound; if (cycles < SwitchCost) return NixGovernorSwitchBlockReason.InsufficientCycles; return NixGovernorSwitchBlockReason.None; } public bool CanSwitch(NixGovernor governor, int round, int cycles) => GetSwitchBlockReason(governor, round, cycles) == NixGovernorSwitchBlockReason.None; public bool TrySwitch(NixGovernor governor, int round, int cycles, out int cost) { cost = 0; if (!CanSwitch(governor, round, cycles)) return false; cost = SwitchCost; Governor = governor; LastSwitchRound = round; FreeSwitchUsed = true; return true; } } }