Fix nations not spawning in singleplayer when player picks fast

NationExecution gated its first SpawnExecution by the same
attackRate/attackTick throttle used for AI actions, so a nation
could wait up to ~100 ticks before scheduling its spawn. In
singleplayer the human's spawn ends the spawn phase immediately,
stranding any nation that hadn't yet reached its attackTick — on
the next tick its NationExecution sees inSpawnPhase()=false and
isAlive()=false (no tiles), and deactivates itself.

First spawn now fires on tick 1, gated by a one-shot flag to
avoid queuing duplicates. The attackRate cadence is preserved for
subsequent re-spawns so nations still hop locations during the
spawn phase.
This commit is contained in:
evanpelle
2026-05-18 17:39:27 -07:00
parent 62e15d2794
commit 0eb8578996
+12 -1
View File
@@ -28,6 +28,7 @@ export class NationExecution implements Execution {
private active = true;
private random: PseudoRandom;
private behaviorsInitialized = false;
private spawnExecAdded = false;
private emojiBehavior!: NationEmojiBehavior;
private mirvBehavior!: NationMIRVBehavior;
private attackBehavior!: AiAttackBehavior;
@@ -104,7 +105,14 @@ export class NationExecution implements Execution {
}
if (this.mg.inSpawnPhase()) {
if (ticks % this.attackRate !== this.attackTick) {
if (this.player.hasSpawned()) {
// Already on the map — periodically re-spawn so the nation
// visibly hops to different locations during the spawn phase.
if (ticks % this.attackRate !== this.attackTick) {
return;
}
} else if (this.spawnExecAdded) {
// First SpawnExecution already queued, wait for it to land.
return;
}
// Place nations without a spawn cell (Dynamically created for HumansVsNations) randomly by SpawnExecution
@@ -112,6 +120,7 @@ export class NationExecution implements Execution {
this.mg.addExecution(
new SpawnExecution(this.gameID, this.nation.playerInfo),
);
this.spawnExecAdded = true;
return;
}
@@ -131,6 +140,7 @@ export class NationExecution implements Execution {
this.mg.addExecution(
new SpawnExecution(this.gameID, this.nation.playerInfo),
);
this.spawnExecAdded = true;
return;
}
}
@@ -147,6 +157,7 @@ export class NationExecution implements Execution {
this.mg.addExecution(
new SpawnExecution(this.gameID, this.nation.playerInfo, rl),
);
this.spawnExecAdded = true;
return;
}