From f12fd23e2bd37202da5828a1903126aae3948d53 Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 27 Dec 2024 10:01:07 -0800 Subject: [PATCH] battleship doesn't attack trade ship if destroyer nearby --- src/core/configuration/DevConfig.ts | 12 ++++++------ src/core/execution/BattleshipExecution.ts | 11 ++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index fc94663b8..a604c1411 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -40,11 +40,11 @@ export class DevConfig extends DefaultConfig { // return 5000 // } - // numBots(): number { - // return 1 - // } - // spawnNPCs(): boolean { - // return false - // } + numBots(): number { + return 0 + } + spawnNPCs(): boolean { + return false + } } diff --git a/src/core/execution/BattleshipExecution.ts b/src/core/execution/BattleshipExecution.ts index d2f330c9f..8417f8ba3 100644 --- a/src/core/execution/BattleshipExecution.ts +++ b/src/core/execution/BattleshipExecution.ts @@ -84,7 +84,7 @@ export class BattleshipExecution implements Execution { return } - const ships = this.mg.units(UnitType.TransportShip, UnitType.Destroyer, UnitType.TradeShip, UnitType.Battleship) + let ships = this.mg.units(UnitType.TransportShip, UnitType.Destroyer, UnitType.TradeShip, UnitType.Battleship) .filter(u => manhattanDist(u.tile().cell(), this.battleship.tile().cell()) < 100) .filter(u => u.owner() != this.battleship.owner()) .filter(u => u != this.battleship) @@ -92,6 +92,15 @@ export class BattleshipExecution implements Execution { .filter(u => !this.alreadyTargeted.has(u)) .sort(distSortUnit(this.battleship)); + const friendlyDestroyerNearby = this.battleship.owner().units(UnitType.Destroyer) + .filter(d => manhattanDist(d.tile().cell(), this.battleship.tile().cell()) < 120) + .length > 0 + + if (friendlyDestroyerNearby) { + // Don't attack trade ships to allow friendly destroyer to capture them + ships = ships.filter(s => s.type() != UnitType.TradeShip) + } + if (ships.length > 0) { const toAttack = ships[0] if (!toAttack.hasHealth()) {