Skip to content

Commit bf06598

Browse files
committed
fix: Consider fleet effects in travel jobs
1 parent b541bdd commit bf06598

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/job/job.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class JobService extends MongooseRepository<Job> {
191191
if (!fleet || !ships) {
192192
continue;
193193
}
194-
const slowestShipSpeed = this.systemLogicService.getSlowestShipSpeed(ships, empire);
194+
const slowestShipSpeed = this.systemLogicService.getSlowestShipSpeed(fleet, ships, empire);
195195

196196
let linkTimeSum = 0;
197197
for (let i = 1; i < job.path.length; i++) {

src/system/system-logic.service.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export class SystemLogicService {
261261
}
262262

263263
getTravelTime(paths: SystemDocument[], fleet: FleetDocument, ships: ShipDocument[], empire: EmpireDocument): number {
264-
const slowestShipSpeed = this.getSlowestShipSpeed(ships, empire);
264+
const slowestShipSpeed = this.getSlowestShipSpeed(fleet, ships, empire);
265265
let totalTravelTime = 0;
266266
for (let i = 1; i < paths.length; i++) {
267267
const fromSystem = paths[i - 1];
@@ -283,16 +283,14 @@ export class SystemLogicService {
283283
return linkTime !== undefined ? linkTime / slowestShipSpeed : null;
284284
}
285285

286-
getSlowestShipSpeed(ships: ShipDocument[], empire: EmpireDocument): number {
286+
getSlowestShipSpeed(fleet: FleetDocument, ships: ShipDocument[], empire: EmpireDocument): number {
287287
if (!ships || ships.length === 0) {
288288
throw new NotFoundException('No ships in the fleet.');
289289
}
290290
let slowestSpeed = Infinity;
291-
for (const ship of ships) {
292-
const variableKey = `ships.${ship.type}.speed` as keyof typeof speedVariables;
293-
const speedVariables: Partial<Record<Variable, number>> = {[variableKey]: SHIP_TYPES[ship.type].speed};
294-
calculateVariables(speedVariables, empire);
295-
const calculatedSpeed = speedVariables[variableKey];
291+
const shipTypes = new Set(ships.map(s => s.type));
292+
for (const shipType of shipTypes) {
293+
const calculatedSpeed = calculateVariable(`ships.${shipType}.speed`, empire, fleet);
296294
if (calculatedSpeed !== undefined && calculatedSpeed < slowestSpeed) {
297295
slowestSpeed = calculatedSpeed;
298296
}

0 commit comments

Comments
 (0)