using System; using UnityEngine; namespace Heroes.Battle { /// Which of the two armies a stack belongs to. public enum BattleSide { Attacker, Defender, } /// /// One army slot: a unit prototype and how many units of it the slot holds. /// A slot with no unit or a non-positive count is considered empty. /// [Serializable] public struct ArmySlot { public UnitDefinition Unit; [Min(0)] public int Count; public ArmySlot(UnitDefinition unit, int count) { Unit = unit; Count = count; } public bool IsEmpty => Unit == null || Count <= 0; } /// /// An army participating in a battle: a fixed set of 7 slots. Several slots /// may reference the same unit prototype. Serializable so it can be edited /// in the inspector or assembled in code and passed to the battle facade. /// [Serializable] public sealed class Army { public const int SlotCount = 7; [SerializeField] private ArmySlot[] slots = new ArmySlot[SlotCount]; public ArmySlot GetSlot(int index) { if (index < 0 || index >= SlotCount) throw new ArgumentOutOfRangeException(nameof(index)); EnsureSize(); return slots[index]; } public void SetSlot(int index, UnitDefinition unit, int count) { if (index < 0 || index >= SlotCount) throw new ArgumentOutOfRangeException(nameof(index)); EnsureSize(); slots[index] = new ArmySlot(unit, count); } /// True when at least one slot holds units. public bool HasUnits { get { EnsureSize(); for (int i = 0; i < SlotCount; i++) { if (!slots[i].IsEmpty) return true; } return false; } } /// True when any occupied slot holds a 2-hex-wide unit. public bool HasWideUnits { get { EnsureSize(); for (int i = 0; i < SlotCount; i++) { if (!slots[i].IsEmpty && slots[i].Unit.hexWidth > 1) return true; } return false; } } private void EnsureSize() { if (slots == null || slots.Length != SlotCount) { Array.Resize(ref slots, SlotCount); } } } }