From 22b877e85c7d7d14a16535c756bc49615f4016e7 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Wed, 4 Dec 2024 16:46:27 -0800 Subject: [PATCH] in progress --- TODO.txt | 6 +- src/core/configuration/Config.ts | 1 + src/core/configuration/DefaultConfig.ts | 127 +++++++++++++----------- src/core/configuration/DevConfig.ts | 5 +- 4 files changed, 78 insertions(+), 61 deletions(-) diff --git a/TODO.txt b/TODO.txt index d91f4ff2e..cd48c2bcd 100644 --- a/TODO.txt +++ b/TODO.txt @@ -208,7 +208,8 @@ * bugfix: gameStop not found error DONE 12/3/2024 * log stack traces & display them on screen DONE 12/3/2024 * add radiation from nuke DONE 12/4/2024 -* add cities +* add cities DONE 12/4/2024 +* max price for units * record and replay games for debugging purposes * bugfix: destroyers can't find path to dst and freeze * record single player game stats @@ -232,4 +233,5 @@ * improve front page (make map larger?) * REFACTOR: give terranullius an ID, game.player() returns terranullius -* REFACTOR: ocean is considered TerraNullius ? \ No newline at end of file +* REFACTOR: ocean is considered TerraNullius ? + diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts index 5233148fa..5cb85ad24 100644 --- a/src/core/configuration/Config.ts +++ b/src/core/configuration/Config.ts @@ -64,6 +64,7 @@ export interface Config { defensePostRange(): number defensePostDefenseBonus(): number falloutDefenseModifier(): number + maxUnitCost(): number } export interface Theme { diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 67dc62d99..c77d592c6 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -8,6 +8,10 @@ import { pastelTheme } from "./PastelTheme"; export class DefaultConfig implements Config { + maxUnitCost(): number { + return 99_999_999 + } + cityPopulationIncrease(): number { return 250_000 } @@ -32,66 +36,73 @@ export class DefaultConfig implements Config { tradeShipSpawnRate(): number { return 500 } + unitInfo(type: UnitType): UnitInfo { - switch (type) { - case UnitType.TransportShip: - return { - cost: () => 0, - territoryBound: false - } - case UnitType.Destroyer: - return { - cost: (p: Player) => (p.units(UnitType.Destroyer).length + 1) * 250_000, - territoryBound: false - } - case UnitType.Battleship: - return { - cost: (p: Player) => (p.units(UnitType.Battleship).length + 1) * 500_000, - territoryBound: false - } - case UnitType.Shell: - return { - cost: (p: Player) => 0, - territoryBound: false - } - case UnitType.Port: - return { - cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 250_000, - territoryBound: true - } - case UnitType.AtomBomb: - return { - cost: () => 1_000_000, - territoryBound: false - } - case UnitType.HydrogenBomb: - return { - cost: () => 5_000_000, - territoryBound: false - } - case UnitType.TradeShip: - return { - cost: () => 0, - territoryBound: false - } - case UnitType.MissileSilo: - return { - cost: () => 1_000_000, - territoryBound: true - } - case UnitType.DefensePost: - return { - cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 100_000, - territoryBound: true - } - case UnitType.City: - return { - cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 250_000, - territoryBound: true - } - default: - assertNever(type) + const fn = () => { + switch (type) { + case UnitType.TransportShip: + return { + cost: () => 0, + territoryBound: false + } + case UnitType.Destroyer: + return { + cost: (p: Player) => (p.units(UnitType.Destroyer).length + 1) * 250_000, + territoryBound: false + } + case UnitType.Battleship: + return { + cost: (p: Player) => (p.units(UnitType.Battleship).length + 1) * 500_000, + territoryBound: false + } + case UnitType.Shell: + return { + cost: (p: Player) => 0, + territoryBound: false + } + case UnitType.Port: + return { + cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 250_000, + territoryBound: true + } + case UnitType.AtomBomb: + return { + cost: () => 1_000_000, + territoryBound: false + } + case UnitType.HydrogenBomb: + return { + cost: () => 5_000_000, + territoryBound: false + } + case UnitType.TradeShip: + return { + cost: () => 0, + territoryBound: false + } + case UnitType.MissileSilo: + return { + cost: () => 1_000_000, + territoryBound: true + } + case UnitType.DefensePost: + return { + cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 100_000, + territoryBound: true + } + case UnitType.City: + return { + cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 250_000, + territoryBound: true + } + default: + assertNever(type) + } } + const ui = fn() + const oldCost = ui.cost + ui.cost = (p: Player) => Math.min(this.maxUnitCost(), oldCost(p)) + return ui } defaultDonationAmount(sender: Player): number { return Math.floor(sender.troops() / 3) diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index e5dc3bdda..c5f4be13a 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -5,9 +5,12 @@ export const devConfig = new class extends DefaultConfig { unitInfo(type: UnitType): UnitInfo { const info = super.unitInfo(type) const oldCost = info.cost - info.cost = (p: Player) => oldCost(p) / 100000 + info.cost = (p: Player) => oldCost(p) / 1000 return info } + maxUnitCost(): number { + return 10000 + } percentageTilesOwnedToWin(): number { return 95