$assigned building id => villagers working there * @param array $required building id => villagers it needs */ public function __construct( /** Heads the farms feed, nominally. */ public readonly float $foodBudget, public readonly int $villagers, /** Heads that eat: villagers, soldiers, stationed support, units in training, the wounded. */ public readonly float $upkeep, public readonly array $assigned, public readonly array $required, /** Villagers drafted by a levy, at most all of them. */ public readonly int $militia = 0, ) {} /** Villagers not drafted by a levy: the ones recruiting can train. */ public function undrafted(): int { return $this->villagers - $this->militia; } public function workers(): int { return array_sum($this->assigned); } /** * Villagers free to staff a new building level: not drafted, not needed by the * buildings standing, not reserved by queued orders ($reserved). Never below 0. */ public function idle(int $reserved = 0): int { return max(0, $this->undrafted() - array_sum($this->required) - $reserved); } /** Staffing ratio 0..1; a building that needs nobody counts as fully staffed. */ public function ratio(int $buildingId): float { $required = $this->required[$buildingId] ?? 0; return $required === 0 ? 1.0 : ($this->assigned[$buildingId] ?? 0) / $required; } }