mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 15:00:43 +00:00
perf: PortExecution only check to spawn trade ships every 10 ticks.
This commit is contained in:
@@ -211,12 +211,12 @@ export class DefaultConfig implements Config {
|
||||
return 10000 + 150 * Math.pow(dist, 1.1);
|
||||
}
|
||||
tradeShipSpawnRate(numberOfPorts: number): number {
|
||||
if (numberOfPorts <= 3) return 180;
|
||||
if (numberOfPorts <= 5) return 250;
|
||||
if (numberOfPorts <= 8) return 350;
|
||||
if (numberOfPorts <= 10) return 400;
|
||||
if (numberOfPorts <= 12) return 450;
|
||||
return 500;
|
||||
if (numberOfPorts <= 3) return 18;
|
||||
if (numberOfPorts <= 5) return 25;
|
||||
if (numberOfPorts <= 8) return 35;
|
||||
if (numberOfPorts <= 10) return 40;
|
||||
if (numberOfPorts <= 12) return 45;
|
||||
return 50;
|
||||
}
|
||||
|
||||
unitInfo(type: UnitType): UnitInfo {
|
||||
|
||||
@@ -17,6 +17,7 @@ export class PortExecution implements Execution {
|
||||
private mg: Game;
|
||||
private port: Unit;
|
||||
private random: PseudoRandom;
|
||||
private checkOffset: number;
|
||||
|
||||
constructor(
|
||||
private _owner: PlayerID,
|
||||
@@ -31,6 +32,7 @@ export class PortExecution implements Execution {
|
||||
}
|
||||
this.mg = mg;
|
||||
this.random = new PseudoRandom(mg.ticks());
|
||||
this.checkOffset = mg.ticks() % 10;
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
@@ -55,6 +57,11 @@ export class PortExecution implements Execution {
|
||||
this._owner = this.port.owner().id();
|
||||
}
|
||||
|
||||
// Only check every 10 ticks for performance.
|
||||
if ((this.mg.ticks() + this.checkOffset) % 10 != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const totalNbOfPorts = this.mg.units(UnitType.Port).length;
|
||||
if (
|
||||
!this.random.chance(this.mg.config().tradeShipSpawnRate(totalNbOfPorts))
|
||||
|
||||
Reference in New Issue
Block a user