Skip to content

Commit 082c480

Browse files
committed
Call handleStructures more often
1 parent fd008e8 commit 082c480

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/core/execution/NationExecution.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ export class NationExecution implements Execution {
9595
}
9696

9797
if (ticks % this.attackRate !== this.attackTick) {
98+
// Call handleStructures twice between regular attack ticks (at 1/3 and 2/3 of the interval)
99+
// Otherwise it is possible that we earn more gold than we can spend
100+
// The alternative is placing multiple structures in handleStructures, but that causes problems
101+
if (
102+
this.behaviorsInitialized &&
103+
this.player !== null &&
104+
this.player.isAlive()
105+
) {
106+
const offset = ticks % this.attackRate;
107+
const oneThird =
108+
(this.attackTick + Math.floor(this.attackRate / 3)) % this.attackRate;
109+
const twoThirds =
110+
(this.attackTick + Math.floor((this.attackRate * 2) / 3)) %
111+
this.attackRate;
112+
if (offset === oneThird || offset === twoThirds) {
113+
this.structureBehavior.handleStructures();
114+
}
115+
}
98116
return;
99117
}
100118

@@ -141,7 +159,7 @@ export class NationExecution implements Execution {
141159
this.allianceBehavior.handleAllianceRequests();
142160
this.allianceBehavior.handleAllianceExtensionRequests();
143161
this.mirvBehavior.considerMIRV();
144-
this.structureBehavior.handleUnits();
162+
this.structureBehavior.handleStructures();
145163
this.warshipBehavior.maybeSpawnWarship();
146164
this.handleEmbargoesToHostileNations();
147165
this.attackBehavior.maybeAttack();

src/core/execution/nation/NationStructureBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class NationStructureBehavior {
8383
private player: Player,
8484
) {}
8585

86-
handleUnits(): boolean {
86+
handleStructures(): boolean {
8787
const cityCount = this.player.unitsOwned(UnitType.City);
8888
const hasCoastalTiles = this.hasCoastalTiles();
8989

0 commit comments

Comments
 (0)