update train meta

This commit is contained in:
evanpelle
2025-08-13 11:25:45 -07:00
parent f1891c5bea
commit 756780f945
4 changed files with 19 additions and 24 deletions
+1 -1
View File
@@ -132,7 +132,7 @@ export interface Config {
tradeShipGold(dist: number, numPorts: number): Gold;
tradeShipSpawnRate(numTradeShips: number, numPlayerPorts: number): number;
trainGold(isFriendly: boolean): Gold;
trainSpawnRate(numberOfStations: number): number;
trainSpawnRate(numPlayerFactories: number): number;
trainStationMinRange(): number;
trainStationMaxRange(): number;
railroadMaxSize(): number;
+3 -3
View File
@@ -328,11 +328,11 @@ export class DefaultConfig implements Config {
infiniteTroops(): boolean {
return this._gameConfig.infiniteTroops;
}
trainSpawnRate(numberOfStations: number): number {
return Math.min(3000, Math.round(80 * Math.pow(numberOfStations, 0.5)));
trainSpawnRate(numPlayerFactories: number): number {
return 200 * numPlayerFactories ** 0.5;
}
trainGold(isFriendly: boolean): Gold {
return isFriendly ? 50_000n : 10_000n;
return isFriendly ? 250_000n : 50_000n;
}
trainStationMinRange(): number {
+6 -4
View File
@@ -1,4 +1,4 @@
import { Execution, Game, Unit } from "../game/Game";
import { Execution, Game, Unit, UnitType } from "../game/Game";
import { TrainStation } from "../game/TrainStation";
import { PseudoRandom } from "../PseudoRandom";
import { TrainExecution } from "./TrainExecution";
@@ -48,8 +48,10 @@ export class TrainStationExecution implements Execution {
this.spawnTrain(this.station, ticks);
}
private shouldSpawnTrain(clusterSize: number): boolean {
const spawnRate = this.mg.config().trainSpawnRate(clusterSize);
private shouldSpawnTrain(): boolean {
const spawnRate = this.mg
.config()
.trainSpawnRate(this.unit.owner().unitCount(UnitType.Factory));
for (let i = 0; i < this.unit!.level(); i++) {
if (this.random.chance(spawnRate)) {
return true;
@@ -73,7 +75,7 @@ export class TrainStationExecution implements Execution {
if (availableForTrade.size === 0) {
return;
}
if (!this.shouldSpawnTrain(availableForTrade.size)) {
if (!this.shouldSpawnTrain()) {
return;
}
+9 -16
View File
@@ -23,13 +23,12 @@ class CityStopHandler implements TrainStopHandler {
station: TrainStation,
trainExecution: TrainExecution,
): void {
const level = BigInt(station.unit.level() + 1);
const stationOwner = station.unit.owner();
const trainOwner = trainExecution.owner();
const isFriendly = stationOwner.isFriendly(trainOwner);
const goldBonus = mg.config().trainGold(isFriendly) * level;
const goldBonus = mg.config().trainGold(isFriendly);
// Share revenue with the station owner if it's not the current player
if (isFriendly) {
if (trainOwner !== stationOwner) {
stationOwner.addGold(goldBonus, station.tile());
}
trainOwner.addGold(goldBonus, station.tile());
@@ -43,7 +42,7 @@ class PortStopHandler implements TrainStopHandler {
station: TrainStation,
trainExecution: TrainExecution,
): void {
const level = BigInt(station.unit.level() + 1);
const level = BigInt(station.unit.level());
const stationOwner = station.unit.owner();
const trainOwner = trainExecution.owner();
const isFriendly = stationOwner.isFriendly(trainOwner);
@@ -61,17 +60,7 @@ class FactoryStopHandler implements TrainStopHandler {
mg: Game,
station: TrainStation,
trainExecution: TrainExecution,
): void {
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 (isFriendly) {
stationOwner.addGold(goldBonus, station.tile());
}
trainOwner.addGold(goldBonus, station.tile());
}
): void {}
}
export function createTrainStopHandlers(
@@ -226,7 +215,11 @@ export class Cluster {
availableForTrade(player: Player): Set<TrainStation> {
const tradingStations = new Set<TrainStation>();
for (const station of this.stations) {
if (station.tradeAvailable(player)) {
if (
(station.unit.type() === UnitType.City ||
station.unit.type() === UnitType.Port) &&
station.tradeAvailable(player)
) {
tradingStations.add(station);
}
}