Files
OpenFrontIO/src/core/execution/TribeSpawner.ts
T
PGray be9ea14fe9 refactor: rename Bot to Tribe in internal execution code (#3372)
## Description

Follows up on #3290 which renamed the user-facing "Bots" to "Tribes".
This renames the internal implementation to match:

- `BotExecution` → `TribeExecution`
- `BotSpawner` → `TribeSpawner`
- `BotNames` → `TribeNames` (`BOT_NAME_*` → `TRIBE_NAME_*`)

All callers updated accordingly. `PlayerType.Bot` and `ColoredTeams.Bot`
are intentionally left unchanged as they are serialised wire-format
values.

Closes #3335

## Please complete the following:
- [x] My changes do not break existing functionality
- [x] I have tested my changes

## Please put your Discord username so you can be contacted if a bug or
regression is found:
Just reply here

---------

Co-authored-by: PGray <PGrayCS@users.noreply.github.com>
2026-03-09 21:31:18 -07:00

41 lines
1.3 KiB
TypeScript

import { Game, PlayerInfo, PlayerType } from "../game/Game";
import { PseudoRandom } from "../PseudoRandom";
import { GameID } from "../Schemas";
import { simpleHash } from "../Util";
import { SpawnExecution } from "./SpawnExecution";
import { TRIBE_NAME_PREFIXES, TRIBE_NAME_SUFFIXES } from "./utils/TribeNames";
export class TribeSpawner {
private random: PseudoRandom;
constructor(
private gs: Game,
private gameID: GameID,
) {
// Use a different seed than createGameRunner (which uses simpleHash(gameID))
// to avoid tribe IDs colliding with nation/human IDs from the same PRNG sequence.
this.random = new PseudoRandom(simpleHash(gameID) + 2);
}
spawnTribes(numTribes: number): SpawnExecution[] {
const tribes: SpawnExecution[] = [];
for (let i = 0; i < numTribes; i++) {
tribes.push(this.spawnTribe(this.randomTribeName()));
}
return tribes;
}
spawnTribe(tribeName: string): SpawnExecution {
return new SpawnExecution(
this.gameID,
new PlayerInfo(tribeName, PlayerType.Bot, null, this.random.nextID()),
);
}
private randomTribeName(): string {
const prefixIndex = this.random.nextInt(0, TRIBE_NAME_PREFIXES.length);
const suffixIndex = this.random.nextInt(0, TRIBE_NAME_SUFFIXES.length);
return `${TRIBE_NAME_PREFIXES[prefixIndex]} ${TRIBE_NAME_SUFFIXES[suffixIndex]}`;
}
}