mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-23 16:45:21 +00:00
Fixed pirating not being disabled when a warship's owner has no port in that body of water (#4458)
> **Before opening a PR:** discuss new features on [Discord](https://discord.gg/K9zernJB5z) first, and file bugs or small improvements as [issues](https://github.com/openfrontio/OpenFrontIO/issues/new/choose). You must be assigned to an `approved` issue — unsolicited PRs will be auto-closed. **Add approved & assigned issue number here:** Resolves #4291 ## Description: Fixes pirating not being disabled when a warship's owner has no port in that body of water ## 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: tktk1234567
This commit is contained in:
@@ -248,7 +248,7 @@ export class WarshipExecution implements Execution {
|
||||
);
|
||||
|
||||
// Trade-ship-specific state, lazily computed.
|
||||
let hasPort: boolean | undefined;
|
||||
let hasReachablePort: boolean | undefined;
|
||||
let patrolTile: number | undefined;
|
||||
let patrolRangeSquared: number | undefined;
|
||||
let warshipComponent: number | null | undefined = undefined;
|
||||
@@ -272,13 +272,24 @@ export class WarshipExecution implements Execution {
|
||||
const type = unit.type();
|
||||
|
||||
if (includeTradeShips && type === UnitType.TradeShip) {
|
||||
if (hasPort === undefined) {
|
||||
hasPort = owner.unitCount(UnitType.Port) > 0;
|
||||
if (warshipComponent === undefined) {
|
||||
warshipComponent = mg.getWaterComponent(this.warship.tile());
|
||||
hasReachablePort =
|
||||
warshipComponent !== null &&
|
||||
owner
|
||||
.units(UnitType.Port)
|
||||
.some(
|
||||
(port) =>
|
||||
port.isActive() &&
|
||||
!port.isMarkedForDeletion() &&
|
||||
!port.isUnderConstruction() &&
|
||||
mg.hasWaterComponent(port.tile(), warshipComponent!),
|
||||
);
|
||||
patrolTile = this.warship.warshipState().patrolTile;
|
||||
patrolRangeSquared = config.warshipPatrolRange() ** 2;
|
||||
}
|
||||
if (
|
||||
!hasPort ||
|
||||
!hasReachablePort ||
|
||||
patrolTile === undefined ||
|
||||
unit.isSafeFromPirates() ||
|
||||
unit.targetUnit()?.owner() === owner ||
|
||||
@@ -286,15 +297,6 @@ export class WarshipExecution implements Execution {
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (warshipComponent === undefined) {
|
||||
warshipComponent = mg.getWaterComponent(this.warship.tile());
|
||||
}
|
||||
if (
|
||||
warshipComponent !== null &&
|
||||
!mg.hasWaterComponent(unit.tile(), warshipComponent)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
mg.euclideanDistSquared(patrolTile, unit.tile()) > patrolRangeSquared!
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user