$assigned building id => villagers working there * @param array $required building id => villagers it needs */ public function __construct( public readonly float $foodBudget, public readonly int $villagers, 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); } /** 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; } }