port execution bugfixes (#1400)

## Description:

fixes 2 bugs with port execution:

1. scale tradeship spawn chance with port level
2. pass in number of tradeships instead of total number of ports to the
config

## 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
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## 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-07-10 11:41:08 -07:00
committed by GitHub
parent f95f76a01a
commit 67445d8d4d
+15 -7
View File
@@ -5,10 +5,10 @@ import { TradeShipExecution } from "./TradeShipExecution";
export class PortExecution implements Execution {
private active = true;
private mg: Game | null = null;
private mg: Game;
private port: Unit | null = null;
private random: PseudoRandom | null = null;
private checkOffset: number | null = null;
private random: PseudoRandom;
private checkOffset: number;
constructor(
private player: Player,
@@ -52,10 +52,7 @@ export class PortExecution implements Execution {
return;
}
const totalNbOfPorts = this.mg.units(UnitType.Port).length;
if (
!this.random.chance(this.mg.config().tradeShipSpawnRate(totalNbOfPorts))
) {
if (!this.shouldSpawnTradeShip()) {
return;
}
@@ -76,4 +73,15 @@ export class PortExecution implements Execution {
activeDuringSpawnPhase(): boolean {
return false;
}
shouldSpawnTradeShip(): boolean {
const numTradeShips = this.mg.units(UnitType.TradeShip).length;
const spawnRate = this.mg.config().tradeShipSpawnRate(numTradeShips);
for (let i = 0; i < this.port!.level(); i++) {
if (this.random.chance(spawnRate)) {
return true;
}
}
return false;
}
}