Add pirate class and separation config
This commit is contained in:
parent
640fbd8577
commit
f85dfe4798
76
src/pirate-ai.js
Normal file
76
src/pirate-ai.js
Normal file
@ -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 };
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user