$dead * @return array */ public function admit(array $dead, int $freeBeds): array { $share = (float) $this->config->get('combat.hospital.share', 0); $wounded = array_filter(array_map(fn (int $n) => (int) floor($n * $share), $dead)); $total = array_sum($wounded); if ($total <= $freeBeds) { return $wounded; } $exact = array_map(fn (int $n) => $n * max(0, $freeBeds) / $total, $wounded); $fits = array_map(fn (float $n) => (int) floor($n), $exact); $rest = array_map(fn (float $n, int $floor) => $n - $floor, $exact, $fits); $rest = array_combine(array_keys($exact), $rest); arsort($rest); foreach (array_slice(array_keys($rest), 0, max(0, $freeBeds) - array_sum($fits)) as $unit) { $fits[$unit]++; } return array_filter($fits); } /** Seconds from the battle until its wounded stand again, at world speed. */ public function healSeconds(): int { return max(1, (int) ceil($this->config->get('combat.hospital.heal_time', 0) / $this->config->speed())); } }