units = new UnitRules($config); } /** @param array $units by unit; `militia` for levied villagers */ public function weight(array $units): float { $total = 0.0; foreach ($units as $unit => $count) { $total += $count * ($unit === 'militia' ? (float) $this->config->get('economy.upkeep.villager', 1) : $this->units->upkeep($unit)); } return $total; } /** Points for what fell. */ public function points(array $lost): int { return (int) round($this->weight($lost)); } /** * Each defender's part of the points, by the weight they had standing. * * @param array $standing defender => weight * @return array */ public static function share(int $points, array $standing): array { $total = array_sum($standing); return $total > 0 ? array_map(fn (float $w) => (int) round($points * $w / $total), $standing) : []; } }