battleship doesn't attack trade ship if destroyer nearby

This commit is contained in:
Evan
2024-12-27 10:01:07 -08:00
parent 5ea10751ea
commit f12fd23e2b
2 changed files with 16 additions and 7 deletions
+6 -6
View File
@@ -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
}
}
+10 -1
View File
@@ -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()) {