2026-10-28 18:17:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Game\Economy;
|
|
|
|
|
|
2026-11-03 08:38:17 +00:00
|
|
|
/**
|
|
|
|
|
* Who works where in a village, as computed by Population::workforce(). The budget and
|
|
|
|
|
* the upkeep are heads (food per hour at world speed 1), not the food rate.
|
|
|
|
|
*/
|
2026-10-28 18:17:34 +00:00
|
|
|
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(
|
2026-11-03 08:38:17 +00:00
|
|
|
/** Heads the farms feed, nominally. */
|
2026-10-28 18:17:34 +00:00
|
|
|
public readonly float $foodBudget,
|
|
|
|
|
public readonly int $villagers,
|
2026-11-03 08:38:17 +00:00
|
|
|
/** Heads that eat: villagers, soldiers, stationed support, units in training, the wounded. */
|
2026-10-28 18:17:34 +00:00
|
|
|
public readonly float $upkeep,
|
|
|
|
|
public readonly array $assigned,
|
|
|
|
|
public readonly array $required,
|
2026-10-28 20:55:44 +00:00
|
|
|
/** Villagers drafted by a levy, at most all of them. */
|
|
|
|
|
public readonly int $militia = 0,
|
2026-10-28 18:17:34 +00:00
|
|
|
) {}
|
|
|
|
|
|
2026-10-28 20:55:44 +00:00
|
|
|
/** Villagers not drafted by a levy: the ones recruiting can train. */
|
|
|
|
|
public function undrafted(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->villagers - $this->militia;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-28 18:17:34 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|