cancel trade if port is captured (no trade inside same country) (#194)

If the port of destination and of source have same owner it means a
player captures port of another player, we cease all trade that happens
inside same country.
Also added a check in the canTrade code to be more reliable and correct
even outside of the specific case of capturing a port.
This commit is contained in:
Ilan Schemoul
2025-03-11 20:33:45 +01:00
committed by Evan
parent aef0b73c48
commit 99e8c03870
2 changed files with 11 additions and 1 deletions
+8
View File
@@ -65,6 +65,14 @@ export class TradeShipExecution implements Execution {
this.wasCaptured = true;
}
// If a player captures an other player's port while trading we should delete
// the ship.
if (this._dstPort.owner().id() == this.srcPort.owner().id()) {
this.tradeShip.delete(false);
this.active = false;
return;
}
if (
!this.wasCaptured &&
(!this._dstPort.isActive() ||
+3 -1
View File
@@ -539,7 +539,9 @@ export class PlayerImpl implements Player {
}
canTrade(other: Player): boolean {
return !other.hasEmbargoAgainst(this) && !this.hasEmbargoAgainst(other);
const embargo =
other.hasEmbargoAgainst(this) || this.hasEmbargoAgainst(other);
return !embargo && other.id() != this.id();
}
addEmbargo(other: PlayerID): void {