mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 21:45:22 +00:00
battleship doesn't attack trade ship if destroyer nearby
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user