@@ -261,7 +261,7 @@ export class SystemLogicService {
261
261
}
262
262
263
263
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 ) ;
265
265
let totalTravelTime = 0 ;
266
266
for ( let i = 1 ; i < paths . length ; i ++ ) {
267
267
const fromSystem = paths [ i - 1 ] ;
@@ -283,16 +283,14 @@ export class SystemLogicService {
283
283
return linkTime !== undefined ? linkTime / slowestShipSpeed : null ;
284
284
}
285
285
286
- getSlowestShipSpeed ( ships : ShipDocument [ ] , empire : EmpireDocument ) : number {
286
+ getSlowestShipSpeed ( fleet : FleetDocument , ships : ShipDocument [ ] , empire : EmpireDocument ) : number {
287
287
if ( ! ships || ships . length === 0 ) {
288
288
throw new NotFoundException ( 'No ships in the fleet.' ) ;
289
289
}
290
290
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 ) ;
296
294
if ( calculatedSpeed !== undefined && calculatedSpeed < slowestSpeed ) {
297
295
slowestSpeed = calculatedSpeed ;
298
296
}
0 commit comments