mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:20:47 +00:00
Fix nations spawn (#2672)
## Description: Returned code that spawns nations around predefined coordinates from the map manifest. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: nikolaj_mykola
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
PlayerID,
|
||||
PlayerType,
|
||||
Relation,
|
||||
TerrainType,
|
||||
Tick,
|
||||
Unit,
|
||||
UnitType,
|
||||
@@ -100,8 +101,16 @@ export class NationExecution implements Execution {
|
||||
}
|
||||
|
||||
if (this.mg.inSpawnPhase()) {
|
||||
// select a tile near the position defined in the map manifest for the current nation
|
||||
const rl = this.randomSpawnLand();
|
||||
|
||||
if (rl === null) {
|
||||
console.warn(`cannot spawn ${this.nation.playerInfo.name}`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.mg.addExecution(
|
||||
new SpawnExecution(this.gameID, this.nation.playerInfo),
|
||||
new SpawnExecution(this.gameID, this.nation.playerInfo, rl),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -222,6 +231,31 @@ export class NationExecution implements Execution {
|
||||
}
|
||||
}
|
||||
|
||||
private randomSpawnLand(): TileRef | null {
|
||||
const delta = 25;
|
||||
let tries = 0;
|
||||
while (tries < 50) {
|
||||
tries++;
|
||||
const cell = this.nation.spawnCell;
|
||||
const x = this.random.nextInt(cell.x - delta, cell.x + delta);
|
||||
const y = this.random.nextInt(cell.y - delta, cell.y + delta);
|
||||
if (!this.mg.isValidCoord(x, y)) {
|
||||
continue;
|
||||
}
|
||||
const tile = this.mg.ref(x, y);
|
||||
if (this.mg.isLand(tile) && !this.mg.hasOwner(tile)) {
|
||||
if (
|
||||
this.mg.terrainType(tile) === TerrainType.Mountain &&
|
||||
this.random.chance(2)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private updateRelationsFromEmbargos() {
|
||||
const player = this.player;
|
||||
if (player === null) return;
|
||||
|
||||
Reference in New Issue
Block a user