Skip to content

Commit c4b8d6b

Browse files
cancel trade if port is captured (no trade inside same country) (openfrontio#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.
1 parent 4c372b3 commit c4b8d6b

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/core/execution/TradeShipExecution.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ export class TradeShipExecution implements Execution {
6565
this.wasCaptured = true;
6666
}
6767

68+
// If a player captures an other player's port while trading we should delete
69+
// the ship.
70+
if (this._dstPort.owner().id() == this.srcPort.owner().id()) {
71+
this.tradeShip.delete(false);
72+
this.active = false;
73+
return;
74+
}
75+
6876
if (
6977
!this.wasCaptured &&
7078
(!this._dstPort.isActive() ||

src/core/game/PlayerImpl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,9 @@ export class PlayerImpl implements Player {
539539
}
540540

541541
canTrade(other: Player): boolean {
542-
return !other.hasEmbargoAgainst(this) && !this.hasEmbargoAgainst(other);
542+
const embargo =
543+
other.hasEmbargoAgainst(this) || this.hasEmbargoAgainst(other);
544+
return !embargo && other.id() != this.id();
543545
}
544546

545547
addEmbargo(other: PlayerID): void {

0 commit comments

Comments
 (0)