mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-27 14:54:20 +00:00
Disable nukes option (#237)
This makes it possible to disable all nukes as well as missile silos from the game in privat lobbies and singleplayer games
This commit is contained in:
@@ -108,6 +108,7 @@ const GameConfigSchema = z.object({
|
||||
difficulty: z.nativeEnum(Difficulty),
|
||||
gameType: z.nativeEnum(GameType),
|
||||
disableNPCs: z.boolean(),
|
||||
disableNukes: z.boolean(),
|
||||
bots: z.number().int().min(0).max(400),
|
||||
infiniteGold: z.boolean(),
|
||||
infiniteTroops: z.boolean(),
|
||||
|
||||
@@ -55,6 +55,7 @@ export interface Config {
|
||||
percentageTilesOwnedToWin(): number;
|
||||
numBots(): number;
|
||||
spawnNPCs(): boolean;
|
||||
disableNukes(): boolean;
|
||||
bots(): number;
|
||||
infiniteGold(): boolean;
|
||||
infiniteTroops(): boolean;
|
||||
|
||||
@@ -148,6 +148,9 @@ export class DefaultConfig implements Config {
|
||||
spawnNPCs(): boolean {
|
||||
return !this._gameConfig.disableNPCs;
|
||||
}
|
||||
disableNukes(): boolean {
|
||||
return this._gameConfig.disableNukes;
|
||||
}
|
||||
bots(): number {
|
||||
return this._gameConfig.bots;
|
||||
}
|
||||
|
||||
@@ -358,12 +358,14 @@ export class FakeHumanExecution implements Execution {
|
||||
if (this.maybeSpawnWarship()) {
|
||||
return;
|
||||
}
|
||||
this.maybeSpawnStructure(
|
||||
UnitType.MissileSilo,
|
||||
1,
|
||||
(t) =>
|
||||
new ConstructionExecution(this.player.id(), t, UnitType.MissileSilo),
|
||||
);
|
||||
if (!this.mg.config().disableNukes()) {
|
||||
this.maybeSpawnStructure(
|
||||
UnitType.MissileSilo,
|
||||
1,
|
||||
(t) =>
|
||||
new ConstructionExecution(this.player.id(), t, UnitType.MissileSilo),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private maybeSpawnStructure(
|
||||
|
||||
@@ -673,6 +673,21 @@ export class PlayerImpl implements Player {
|
||||
}
|
||||
|
||||
canBuild(unitType: UnitType, targetTile: TileRef): TileRef | false {
|
||||
// prevent the building of nukes and nuke related buildings
|
||||
if (this.mg.config().disableNukes()) {
|
||||
if (
|
||||
unitType === UnitType.MissileSilo ||
|
||||
unitType === UnitType.MIRV ||
|
||||
unitType === UnitType.AtomBomb ||
|
||||
unitType === UnitType.HydrogenBomb ||
|
||||
unitType === UnitType.SAMLauncher ||
|
||||
unitType === UnitType.SAMMissile ||
|
||||
unitType === UnitType.MIRVWarhead
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const cost = this.mg.unitInfo(unitType).cost(this);
|
||||
if (!this.isAlive() || this.gold() < cost) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user