feat: handle embargo fake human (#240)

This commit is contained in:
Ilan Schemoul
2025-03-13 22:53:27 +01:00
committed by GitHub
parent 7ec3f0c81f
commit 70c3c43a5f
+44
View File
@@ -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<Player, Tick>();
private embargoMalusApplied = new Set<PlayerID>();
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))