From 67445d8d4d82ed655c1bb829072ce58992ffb622 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Thu, 10 Jul 2025 11:41:08 -0700 Subject: [PATCH] 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 --- src/core/execution/PortExecution.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/core/execution/PortExecution.ts b/src/core/execution/PortExecution.ts index 1f5e10d64..a7d070562 100644 --- a/src/core/execution/PortExecution.ts +++ b/src/core/execution/PortExecution.ts @@ -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; + } }