33 lines
944 B
PHP
33 lines
944 B
PHP
<?php
|
|
|
|
namespace App\Game\Economy;
|
|
|
|
/** Who works where in a village, as computed by Population::workforce(). */
|
|
final class Workforce
|
|
{
|
|
/**
|
|
* @param array<int, int> $assigned building id => villagers working there
|
|
* @param array<int, int> $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,
|
|
) {}
|
|
|
|
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;
|
|
}
|
|
}
|