From be30a5a4377b0eceb09fd31e48545a50128f604b Mon Sep 17 00:00:00 2001 From: evanpelle Date: Fri, 8 Aug 2025 18:26:23 -0700 Subject: [PATCH 1/2] train gold --- src/core/configuration/Config.ts | 2 +- src/core/configuration/DefaultConfig.ts | 5 +++-- src/core/game/TrainStation.ts | 23 ++++++++++------------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts index 16d6e95849..933bdfa95f 100644 --- a/src/core/configuration/Config.ts +++ b/src/core/configuration/Config.ts @@ -130,7 +130,7 @@ export interface Config { unitInfo(type: UnitType): UnitInfo; tradeShipGold(dist: number, numPorts: number): Gold; tradeShipSpawnRate(numberOfPorts: number): number; - trainGold(): Gold; + trainGold(isFriendly: boolean): Gold; trainSpawnRate(numberOfStations: number): number; trainStationMinRange(): number; trainStationMaxRange(): number; diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 8fab450bff..95af6e07d0 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -328,9 +328,10 @@ export class DefaultConfig implements Config { trainSpawnRate(numberOfStations: number): number { return Math.min(1400, Math.round(40 * Math.pow(numberOfStations, 0.5))); } - trainGold(): Gold { - return BigInt(4_000); + trainGold(isFriendly: boolean): Gold { + return isFriendly ? 100_000n : 25_000n; } + trainStationMinRange(): number { return 15; } diff --git a/src/core/game/TrainStation.ts b/src/core/game/TrainStation.ts index 8eb3baceea..f12125abe9 100644 --- a/src/core/game/TrainStation.ts +++ b/src/core/game/TrainStation.ts @@ -18,19 +18,18 @@ interface TrainStopHandler { * Behavior to be defined */ class CityStopHandler implements TrainStopHandler { - private factor: bigint = BigInt(2); onStop( mg: Game, station: TrainStation, trainExecution: TrainExecution, ): void { const level = BigInt(station.unit.level() + 1); - let goldBonus = (mg.config().trainGold() * level) / this.factor; const stationOwner = station.unit.owner(); const trainOwner = trainExecution.owner(); + const isFriendly = stationOwner.isFriendly(trainOwner); + const goldBonus = mg.config().trainGold(isFriendly) * level; // Share revenue with the station owner if it's not the current player - if (stationOwner.isFriendly(trainOwner)) { - goldBonus += BigInt(1_000); // Bonus for everybody when trading with an ally! + if (isFriendly) { stationOwner.addGold(goldBonus, station.tile()); } trainOwner.addGold(goldBonus, station.tile()); @@ -38,7 +37,6 @@ class CityStopHandler implements TrainStopHandler { } class PortStopHandler implements TrainStopHandler { - private factor: bigint = BigInt(2); constructor(private random: PseudoRandom) {} onStop( mg: Game, @@ -46,12 +44,12 @@ class PortStopHandler implements TrainStopHandler { trainExecution: TrainExecution, ): void { const level = BigInt(station.unit.level() + 1); - let goldBonus = (mg.config().trainGold() * level) / this.factor; const stationOwner = station.unit.owner(); const trainOwner = trainExecution.owner(); - // Share revenue with the station owner if it's not the current player - if (stationOwner.isFriendly(trainOwner)) { - goldBonus += BigInt(1_000); // Bonus for everybody when trading with an ally! + const isFriendly = stationOwner.isFriendly(trainOwner); + const goldBonus = mg.config().trainGold(isFriendly) * level; + + if (isFriendly) { stationOwner.addGold(goldBonus, station.tile()); } trainOwner.addGold(goldBonus, station.tile()); @@ -59,18 +57,17 @@ class PortStopHandler implements TrainStopHandler { } class FactoryStopHandler implements TrainStopHandler { - private factor: bigint = BigInt(2); onStop( mg: Game, station: TrainStation, trainExecution: TrainExecution, ): void { - let goldBonus = mg.config().trainGold(); const stationOwner = station.unit.owner(); const trainOwner = trainExecution.owner(); + const isFriendly = stationOwner.isFriendly(trainOwner); + const goldBonus = mg.config().trainGold(isFriendly); // Share revenue with the station owner if it's not the current player - if (stationOwner.isFriendly(trainOwner)) { - goldBonus += BigInt(1_000); // Bonus for everybody when trading with an ally! + if (isFriendly) { stationOwner.addGold(goldBonus, station.tile()); } trainOwner.addGold(goldBonus, station.tile()); From 0da88fa330a930a9a656de129935fa1c612cf12c Mon Sep 17 00:00:00 2001 From: evanpelle Date: Fri, 8 Aug 2025 18:33:58 -0700 Subject: [PATCH 2/2] train gold --- tests/core/game/TrainStation.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/core/game/TrainStation.test.ts b/tests/core/game/TrainStation.test.ts index fba6d03da7..b0ed061659 100644 --- a/tests/core/game/TrainStation.test.ts +++ b/tests/core/game/TrainStation.test.ts @@ -16,7 +16,8 @@ describe("TrainStation", () => { game = { ticks: jest.fn().mockReturnValue(123), config: jest.fn().mockReturnValue({ - trainGold: () => BigInt(4000), + trainGold: (isFriendly: boolean) => + isFriendly ? BigInt(1000) : BigInt(500), }), addUpdate: jest.fn(), addExecution: jest.fn(), @@ -50,7 +51,7 @@ describe("TrainStation", () => { station.onTrainStop(trainExecution); - expect(unit.owner().addGold).toHaveBeenCalledWith(4000n, unit.tile()); + expect(unit.owner().addGold).toHaveBeenCalledWith(1000n, unit.tile()); }); it("handles allied trade", () => { @@ -60,9 +61,9 @@ describe("TrainStation", () => { station.onTrainStop(trainExecution); - expect(unit.owner().addGold).toHaveBeenCalledWith(5000n, unit.tile()); + expect(unit.owner().addGold).toHaveBeenCalledWith(2000n, unit.tile()); expect(trainExecution.owner().addGold).toHaveBeenCalledWith( - 5000n, + 2000n, unit.tile(), ); });