From f85dfe4798d85d216b613288ddcb71bd5f595786 Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 18 Sep 2026 05:44:58 +0000 Subject: [PATCH] Add pirate class and separation config --- src/pirate-ai.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/pirate-ai.js diff --git a/src/pirate-ai.js b/src/pirate-ai.js new file mode 100644 index 0000000..4878337 --- /dev/null +++ b/src/pirate-ai.js @@ -0,0 +1,76 @@ +export const PIRATE_CLASSES = { + raider: { + key: 'raider', + label: 'RAIDER', + hull: 80, + speed: 148, + turnRate: 70, + reloadMs: 1280, + damage: 4, + preferredRange: 300, + retreatRange: 175, + broadsideRange: 380, + broadsideError: 34, + displaySize: 70, + }, + frigate: { + key: 'frigate', + label: 'FRIGATE', + hull: 120, + speed: 118, + turnRate: 52, + reloadMs: 1650, + damage: 6, + preferredRange: 335, + retreatRange: 210, + broadsideRange: 420, + broadsideError: 38, + displaySize: 78, + }, + captain: { + key: 'captain', + label: 'CAPTAIN', + hull: 180, + speed: 102, + turnRate: 44, + reloadMs: 1450, + damage: 8, + preferredRange: 365, + retreatRange: 225, + broadsideRange: 470, + broadsideError: 32, + displaySize: 88, + }, +}; + +export const pirateClassForWave = (wave, index, count) => { + if (wave >= 4 && wave % 2 === 0 && index === count - 1) return PIRATE_CLASSES.captain; + if (wave >= 2 && (wave + index) % 3 === 0) return PIRATE_CLASSES.raider; + return PIRATE_CLASSES.frigate; +}; + +export const separationVector = (ship, ships, radius = 125) => { + let x = 0; + let y = 0; + + for (const other of ships) { + if (!other || other === ship || !other.active) continue; + + const dx = other.x - ship.x; + const dy = other.y - ship.y; + const distance = Math.hypot(dx, dy); + if (distance <= 0 || distance >= radius) continue; + + const strength = (radius - distance) / radius; + x -= (dx / distance) * strength; + y -= (dy / distance) * strength; + } + + const magnitude = Math.hypot(x, y); + if (magnitude > 1) { + x /= magnitude; + y /= magnitude; + } + + return { x, y }; +};