mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 14:00:54 +00:00
have warships favor attacking transport ships
This commit is contained in:
@@ -87,11 +87,25 @@ export class WarshipExecution implements Execution {
|
||||
this.target =
|
||||
ships.sort((a, b) => {
|
||||
// First compare by Warship type
|
||||
if (a.type() === UnitType.Warship && b.type() !== UnitType.Warship)
|
||||
if (a.type() === UnitType.Warship && b.type() !== UnitType.Warship) {
|
||||
return -1;
|
||||
if (a.type() !== UnitType.Warship && b.type() === UnitType.Warship)
|
||||
}
|
||||
if (a.type() !== UnitType.Warship && b.type() === UnitType.Warship) {
|
||||
return 1;
|
||||
|
||||
}
|
||||
// Then favor transport ship
|
||||
if (
|
||||
a.type() === UnitType.TransportShip &&
|
||||
b.type() !== UnitType.TransportShip
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
if (
|
||||
a.type() !== UnitType.TransportShip &&
|
||||
b.type() === UnitType.TransportShip
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
// If both are same type, sort by distance
|
||||
return distSortUnit(this.mg, this.warship)(a, b);
|
||||
})[0] ?? null;
|
||||
|
||||
Reference in New Issue
Block a user