mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 17:26:42 +00:00
Nations can spawn cities without a port (#1072)
## Description: Allow nations to spawn cities even if they do not have a port. ## 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 - [ ] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> Co-authored-by: evanpelle <evanpelle@gmail.com>
This commit is contained in:
@@ -433,44 +433,44 @@ export class FakeHumanExecution implements Execution {
|
||||
private handleUnits() {
|
||||
const player = this.player;
|
||||
if (player === null) return;
|
||||
const ports = player.units(UnitType.Port);
|
||||
if (ports.length === 0 && player.gold() > this.cost(UnitType.Port)) {
|
||||
const oceanTiles = Array.from(player.borderTiles()).filter((t) =>
|
||||
this.mg.isOceanShore(t),
|
||||
);
|
||||
if (oceanTiles.length > 0) {
|
||||
const buildTile = this.random.randElement(oceanTiles);
|
||||
this.mg.addExecution(
|
||||
new ConstructionExecution(player, buildTile, UnitType.Port),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.maybeSpawnStructure(UnitType.City, 2);
|
||||
if (this.maybeSpawnWarship()) {
|
||||
return;
|
||||
}
|
||||
this.maybeSpawnStructure(UnitType.MissileSilo, 1);
|
||||
return (
|
||||
this.maybeSpawnStructure(UnitType.Port, 1) ||
|
||||
this.maybeSpawnStructure(UnitType.City, 2) ||
|
||||
this.maybeSpawnWarship() ||
|
||||
this.maybeSpawnStructure(UnitType.MissileSilo, 1)
|
||||
);
|
||||
}
|
||||
|
||||
private maybeSpawnStructure(type: UnitType, maxNum: number) {
|
||||
private maybeSpawnStructure(type: UnitType, maxNum: number): boolean {
|
||||
if (this.player === null) throw new Error("not initialized");
|
||||
const units = this.player.units(type);
|
||||
if (units.length >= maxNum) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (this.player.gold() < this.cost(type)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
const tile = this.randTerritoryTile(this.player);
|
||||
const tile = this.structureSpawnTile(type);
|
||||
if (tile === null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
const canBuild = this.player.canBuild(type, tile);
|
||||
if (canBuild === false) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
this.mg.addExecution(new ConstructionExecution(this.player, tile, type));
|
||||
return true;
|
||||
}
|
||||
|
||||
private structureSpawnTile(type: UnitType): TileRef | null {
|
||||
if (this.player === null) throw new Error("not initialized");
|
||||
const tiles =
|
||||
type === UnitType.Port
|
||||
? Array.from(this.player.borderTiles()).filter((t) =>
|
||||
this.mg.isOceanShore(t),
|
||||
)
|
||||
: Array.from(this.player.tiles());
|
||||
return this.random.randElement(tiles);
|
||||
}
|
||||
|
||||
private maybeSpawnWarship(): boolean {
|
||||
|
||||
Reference in New Issue
Block a user