*/ public function modes(): array { return array_keys($this->config->get('movement.modes', [])); } public function hasMode(string $mode): bool { return in_array($mode, $this->modes(), true); } public function defaultMode(): string { return $this->config->get('movement.default_mode', 'normal'); } /** @return array{speed: float, visibility: float} */ public function mode(string $mode): array { $values = $this->config->get("movement.modes.$mode") ?? throw new InvalidArgumentException("Unknown travel mode [$mode]."); return ['speed' => (float) $values['speed'], 'visibility' => (float) $values['visibility']]; } /** * Minutes per field of the slowest unit in the group, at world speed 1. * * @param array $units unit => count */ public function slowest(array $units): float { $minutes = 0.0; foreach ($units as $unit => $count) { if ($count > 0) { $minutes = max($minutes, (float) $this->config->get("units.$unit.speed")); } } return $minutes; } /** * Seconds the group takes for $distance fields. * * @param array $units */ public function seconds(array $units, float $distance, string $mode): int { $pace = $this->config->speed() * $this->config->get('movement.unit_speed', 1.0) * $this->mode($mode)['speed']; return max(1, (int) round($this->slowest($units) * $distance * 60 / $pace)); } /** * Seconds before arrival at which the target spots the group: once it comes within * the mode's visibility plus the target's detection radius. An unseen mode shows up * only when it arrives; a group that starts within range is seen at once. */ public function warningSeconds(int $seconds, float $distance, string $mode, float $detection): int { $visibility = $this->mode($mode)['visibility']; if ($visibility <= 0) { return 0; } $range = $visibility + $detection; return $range >= $distance ? $seconds : (int) floor($seconds * $range / $distance); } }