favor transport ships, no reload penalty (#1153)

## Description:

People were able to get transport ships across by distracting enemy
warships with their own warship. This change has warships prioritize
enemy transport ships over warships. It also allows warships to reload
instantly after shooting a transport ship. This prevent cheesing where
players send out many transport ships with little to no troops to
distract the warship.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

<DISCORD USERNAME>
This commit is contained in:
evanpelle
2025-06-12 10:13:44 -07:00
committed by GitHub
parent 814e4d9934
commit 22caa9c5d2
+17 -14
View File
@@ -120,19 +120,7 @@ export class WarshipExecution implements Execution {
const { unit: unitA, distSquared: distA } = a;
const { unit: unitB, distSquared: distB } = b;
// Prioritize Warships
if (
unitA.type() === UnitType.Warship &&
unitB.type() !== UnitType.Warship
)
return -1;
if (
unitA.type() !== UnitType.Warship &&
unitB.type() === UnitType.Warship
)
return 1;
// Then favor Transport Ships over Trade Ships
// Prioritize Transport Ships above all other units
if (
unitA.type() === UnitType.TransportShip &&
unitB.type() !== UnitType.TransportShip
@@ -144,6 +132,18 @@ export class WarshipExecution implements Execution {
)
return 1;
// Then prioritize Warships.
if (
unitA.type() === UnitType.Warship &&
unitB.type() !== UnitType.Warship
)
return -1;
if (
unitA.type() !== UnitType.Warship &&
unitB.type() === UnitType.Warship
)
return 1;
// If both are the same type, sort by distance (lower `distSquared` means closer)
return distA - distB;
})[0]?.unit;
@@ -152,7 +152,10 @@ export class WarshipExecution implements Execution {
private shootTarget() {
const shellAttackRate = this.mg.config().warshipShellAttackRate();
if (this.mg.ticks() - this.lastShellAttack > shellAttackRate) {
this.lastShellAttack = this.mg.ticks();
if (this.warship.targetUnit()?.type() !== UnitType.TransportShip) {
// Warships don't need to reload when attacking transport ships.
this.lastShellAttack = this.mg.ticks();
}
this.mg.addExecution(
new ShellExecution(
this.warship.tile(),