From 70c3c43a5ff1473a151c07dd20c57f6aaf9fad61 Mon Sep 17 00:00:00 2001 From: Ilan Schemoul Date: Thu, 13 Mar 2025 22:53:27 +0100 Subject: [PATCH] feat: handle embargo fake human (#240) --- src/core/execution/FakeHumanExecution.ts | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index 097b8950d..41122e374 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -5,6 +5,7 @@ import { Execution, Game, Player, + PlayerID, PlayerInfo, PlayerType, Relation, @@ -40,6 +41,7 @@ export class FakeHumanExecution implements Execution { private lastEnemyUpdateTick: number = 0; private lastEmojiSent = new Map(); + private embargoMalusApplied = new Set(); constructor( gameID: GameID, @@ -57,6 +59,46 @@ export class FakeHumanExecution implements Execution { } } + private updateRelationsFromEmbargos() { + const others = this.mg.players().filter((p) => p.id() != this.player.id()); + + others.forEach((other: Player) => { + const embargoMalus = -20; + if ( + other.hasEmbargoAgainst(this.player) && + !this.embargoMalusApplied.has(other.id()) + ) { + this.player.updateRelation(other, embargoMalus); + this.embargoMalusApplied.add(other.id()); + } else if ( + !other.hasEmbargoAgainst(this.player) && + this.embargoMalusApplied.has(other.id()) + ) { + this.player.updateRelation(other, -embargoMalus); + this.embargoMalusApplied.delete(other.id()); + } + }); + } + + private handleEmbargoesToHostileNations() { + const others = this.mg.players().filter((p) => p.id() != this.player.id()); + + others.forEach((other: Player) => { + /* When player is hostile starts embargo. Do not stop until neutral again */ + if ( + this.player.relation(other) <= Relation.Hostile && + !this.player.hasEmbargoAgainst(other) + ) { + this.player.addEmbargo(other.id()); + } else if ( + this.player.relation(other) >= Relation.Neutral && + this.player.hasEmbargoAgainst(other) + ) { + this.player.stopEmbargo(other.id()); + } + }); + } + tick(ticks: number) { if (this.mg.inSpawnPhase()) { if (ticks % this.random.nextInt(5, 30) == 0) { @@ -96,9 +138,11 @@ export class FakeHumanExecution implements Execution { this.player.setTargetTroopRatio(0.7); } + this.updateRelationsFromEmbargos(); this.handleAllianceRequests(); this.handleEnemies(); this.handleUnits(); + this.handleEmbargoesToHostileNations(); const enemyborder = Array.from(this.player.borderTiles()) .flatMap((t) => this.mg.neighbors(t))