have warships favor attacking transport ships

This commit is contained in:
Evan
2025-03-03 20:23:27 -08:00
parent 58ed84a63e
commit 3aa375b210
+17 -3
View File
@@ -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;