From 807151b72346094fc311a787183a508b33276397 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Wed, 19 Nov 2025 10:58:49 -0800 Subject: [PATCH] Revert "Improve random spawn (#2465)" This reverts commit 2b2200c80894d1db9c50b518e85d776b371a31c9. --- src/core/configuration/Config.ts | 1 - src/core/configuration/DefaultConfig.ts | 3 --- src/core/execution/BotSpawner.ts | 30 +++++------------------ src/core/execution/ExecutionManager.ts | 4 +-- src/core/execution/FakeHumanExecution.ts | 19 -------------- src/core/execution/SpawnExecution.ts | 5 ---- src/core/execution/utils/PlayerSpawner.ts | 17 ++++++++----- src/core/game/Game.ts | 2 -- src/core/game/PlayerImpl.ts | 9 ------- 9 files changed, 19 insertions(+), 71 deletions(-) diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts index 02dd57b00..f1f1b03c6 100644 --- a/src/core/configuration/Config.ts +++ b/src/core/configuration/Config.ts @@ -153,7 +153,6 @@ export interface Config { defensePostRange(): number; SAMCooldown(): number; SiloCooldown(): number; - minDistanceBetweenPlayers(): number; defensePostDefenseBonus(): number; defensePostSpeedBonus(): number; falloutDefenseModifier(percentOfFallout: number): number; diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 2a64a4876..df84be07f 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -618,9 +618,6 @@ export class DefaultConfig implements Config { temporaryEmbargoDuration(): Tick { return 300 * 10; // 5 minutes. } - minDistanceBetweenPlayers(): number { - return 30; - } percentageTilesOwnedToWin(): number { if (this._gameConfig.gameMode === GameMode.Team) { diff --git a/src/core/execution/BotSpawner.ts b/src/core/execution/BotSpawner.ts index e1712f99e..134a7c666 100644 --- a/src/core/execution/BotSpawner.ts +++ b/src/core/execution/BotSpawner.ts @@ -40,33 +40,15 @@ export class BotSpawner { if (!this.gs.isLand(tile)) { return null; } - - const isOtherPlayerSpawnedNearby = this.gs.allPlayers().some((player) => { - const spawnTile = player.spawnTile(); - - if (spawnTile === undefined) { - return false; + for (const spawn of this.bots) { + if (this.gs.manhattanDist(spawn.tile, tile) < 30) { + return null; } - - return ( - this.gs.manhattanDist(spawnTile, tile) < - this.gs.config().minDistanceBetweenPlayers() - ); - }); - - if (isOtherPlayerSpawnedNearby) { - return null; } - - const playerInfo = new PlayerInfo( - botName, - PlayerType.Bot, - null, - this.random.nextID(), + return new SpawnExecution( + new PlayerInfo(botName, PlayerType.Bot, null, this.random.nextID()), + tile, ); - this.gs.addPlayer(playerInfo).setSpawnTile(tile); - - return new SpawnExecution(playerInfo, tile); } private randomBotName(): string { diff --git a/src/core/execution/ExecutionManager.ts b/src/core/execution/ExecutionManager.ts index e58906921..4a8e5df91 100644 --- a/src/core/execution/ExecutionManager.ts +++ b/src/core/execution/ExecutionManager.ts @@ -128,11 +128,11 @@ export class Executor { } } - spawnBots(numBots: number): SpawnExecution[] { + spawnBots(numBots: number): Execution[] { return new BotSpawner(this.mg, this.gameID).spawnBots(numBots); } - spawnPlayers(): SpawnExecution[] { + spawnPlayers(): Execution[] { return new PlayerSpawner(this.mg, this.gameID).spawnPlayers(); } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index ec8c690eb..4051339fc 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -159,7 +159,6 @@ export class FakeHumanExecution implements Execution { console.warn(`cannot spawn ${this.nation.playerInfo.name}`); return; } - this.mg.addPlayer(this.nation.playerInfo).setSpawnTile(rl); this.mg.addExecution(new SpawnExecution(this.nation.playerInfo, rl)); return; } @@ -644,24 +643,6 @@ export class FakeHumanExecution implements Execution { continue; } const tile = this.mg.ref(x, y); - - const isOtherPlayerSpawnedNearby = this.mg.allPlayers().some((player) => { - const spawnTile = player.spawnTile(); - - if (spawnTile === undefined) { - return false; - } - - return ( - this.mg.manhattanDist(spawnTile, tile) < - this.mg.config().minDistanceBetweenPlayers() - ); - }); - - if (isOtherPlayerSpawnedNearby) { - continue; - } - if (this.mg.isLand(tile) && !this.mg.hasOwner(tile)) { if ( this.mg.terrainType(tile) === TerrainType.Mountain && diff --git a/src/core/execution/SpawnExecution.ts b/src/core/execution/SpawnExecution.ts index 3d3764ed0..57baff6ee 100644 --- a/src/core/execution/SpawnExecution.ts +++ b/src/core/execution/SpawnExecution.ts @@ -48,11 +48,6 @@ export class SpawnExecution implements Execution { this.mg.addExecution(new BotExecution(player)); } } - - if (player.spawnTile() === undefined) { - player.setSpawnTile(this.tile); - } - player.setHasSpawned(true); } diff --git a/src/core/execution/utils/PlayerSpawner.ts b/src/core/execution/utils/PlayerSpawner.ts index f6bbf3a79..29c0fe1a6 100644 --- a/src/core/execution/utils/PlayerSpawner.ts +++ b/src/core/execution/utils/PlayerSpawner.ts @@ -9,6 +9,7 @@ export class PlayerSpawner { private random: PseudoRandom; private players: SpawnExecution[] = []; private static readonly MAX_SPAWN_TRIES = 10_000; + private static readonly MIN_SPAWN_DISTANCE = 30; constructor( private gm: Game, @@ -40,13 +41,18 @@ export class PlayerSpawner { continue; } - const isOtherPlayerSpawnedNearby = this.players.some( - (spawn) => + let tooCloseToOtherPlayer = false; + for (const spawn of this.players) { + if ( this.gm.manhattanDist(spawn.tile, tile) < - this.gm.config().minDistanceBetweenPlayers(), - ); + PlayerSpawner.MIN_SPAWN_DISTANCE + ) { + tooCloseToOtherPlayer = true; + break; + } + } - if (isOtherPlayerSpawnedNearby) { + if (tooCloseToOtherPlayer) { continue; } @@ -69,7 +75,6 @@ export class PlayerSpawner { continue; } - player.setSpawnTile(spawnLand); this.players.push(new SpawnExecution(player.info(), spawnLand)); } diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 33f01e6df..2d868b799 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -547,8 +547,6 @@ export interface Player { hasSpawned(): boolean; setHasSpawned(hasSpawned: boolean): void; - setSpawnTile(spawnTile: TileRef): void; - spawnTile(): TileRef | undefined; // Territory tiles(): ReadonlySet; diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 67083f656..f85cc7aab 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -102,7 +102,6 @@ export class PlayerImpl implements Player { public _outgoingLandAttacks: Attack[] = []; private _hasSpawned = false; - private _spawnTile: TileRef | undefined; private _isDisconnected = false; constructor( @@ -348,14 +347,6 @@ export class PlayerImpl implements Player { this._hasSpawned = hasSpawned; } - setSpawnTile(spawnTile: TileRef): void { - this._spawnTile = spawnTile; - } - - spawnTile(): TileRef | undefined { - return this._spawnTile; - } - incomingAllianceRequests(): AllianceRequest[] { return this.mg.allianceRequests.filter((ar) => ar.recipient() === this); }