reduce number of trade ships by 50%, double gold per trade ship (#1934)

## Description:

v25 increased the number of trade ships from v24, causing lag
complaints. On my chromebook pathfinding is using over 60% of cpu.

So reduced the number of trade ships roughly by half, but double the
gold per trade ship so it should balance out,

World v25: 
* 2 mins: ~ 60 trade ships 
* 5 mins: ~ 140 trade ships

World on this branch:
* 2 mins: ~ 35 trade ships
* 5 mins: ~ 70 trade ships


Also increased the probably of trade ship spawn for players with under 2
tradeships to prevent larger players from starving out smaller players.

## 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
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

evan
This commit is contained in:
evanpelle
2025-08-25 16:13:54 -07:00
committed by GitHub
parent beddcfeef6
commit 0f60825b9f
3 changed files with 26 additions and 9 deletions
+5 -1
View File
@@ -130,7 +130,11 @@ export interface Config {
defaultDonationAmount(sender: Player): number;
unitInfo(type: UnitType): UnitInfo;
tradeShipGold(dist: number, numPorts: number): Gold;
tradeShipSpawnRate(numTradeShips: number, numPlayerPorts: number): number;
tradeShipSpawnRate(
numTradeShips: number,
numPlayerPorts: number,
numPlayerTradeShips: number,
): number;
trainGold(rel: "self" | "friendly" | "other"): Gold;
trainSpawnRate(numPlayerFactories: number): number;
trainStationMinRange(): number;
+19 -7
View File
@@ -355,7 +355,7 @@ export class DefaultConfig implements Config {
}
tradeShipGold(dist: number, numPorts: number): Gold {
const baseGold = Math.floor(50_000 + 50 * dist);
const baseGold = Math.floor(100_000 + 100 * dist);
const numPortBonus = numPorts - 1;
// Hyperbolic decay, midpoint at 5 ports, 3x bonus max.
const bonus = 1 + 2 * (numPortBonus / (numPortBonus + 5));
@@ -363,19 +363,31 @@ export class DefaultConfig implements Config {
}
// Probability of trade ship spawn = 1 / tradeShipSpawnRate
tradeShipSpawnRate(numTradeShips: number, numPlayerPorts: number): number {
tradeShipSpawnRate(
numTradeShips: number,
numPlayerPorts: number,
numPlayerTradeShips: number,
): number {
// Geometric mean of base spawn rate and port multiplier
const combined = Math.sqrt(
this.tradeShipBaseSpawn(numTradeShips) *
this.tradeShipBaseSpawn(numTradeShips, numPlayerTradeShips) *
this.tradeShipPortMultiplier(numPlayerPorts),
);
return Math.floor(12 / combined);
return Math.floor(25 / combined);
}
private tradeShipBaseSpawn(numTradeShips: number): number {
const decayRate = Math.LN2 / 30;
return 1 - sigmoid(numTradeShips, decayRate, 100);
private tradeShipBaseSpawn(
numTradeShips: number,
numPlayerTradeShips: number,
): number {
if (numPlayerTradeShips < 3) {
// If other players have many ports, then they can starve out smaller players.
// So this prevents smaller players from being completely starved out.
return 1;
}
const decayRate = Math.LN2 / 10;
return 1 - sigmoid(numTradeShips, decayRate, 55);
}
private tradeShipPortMultiplier(numPlayerPorts: number): number {
+2 -1
View File
@@ -79,9 +79,10 @@ export class PortExecution implements Execution {
shouldSpawnTradeShip(): boolean {
const numTradeShips = this.mg.unitCount(UnitType.TradeShip);
const numPlayerPorts = this.player.unitCount(UnitType.Port);
const numPlayerTradeShips = this.player.unitCount(UnitType.TradeShip);
const spawnRate = this.mg
.config()
.tradeShipSpawnRate(numTradeShips, numPlayerPorts);
.tradeShipSpawnRate(numTradeShips, numPlayerPorts, numPlayerTradeShips);
for (let i = 0; i < this.port!.level(); i++) {
if (this.random.chance(spawnRate)) {
return true;