acceptable masses & speeds update

This commit is contained in:
2023-10-28 13:44:55 +02:00
parent 5ab1963117
commit 8cd43adff3
5 changed files with 36 additions and 39 deletions
+5 -19
View File
@@ -1,6 +1,6 @@
import { EVehicleUseType } from '../enums/EVehicleUseType';
import { ICarWagon, ILocomotive, IStore, TCarWagonGroup, TLocoGroup } from '../types';
import { LocoType, calculateSpeedLimit } from './speedLimitUtils';
import { MassLimitLocoType, SpeedLimitLocoType, calculateMassLimit, calculateSpeedLimit } from './vehicleLimitsUtils';
export function isLocomotive(vehicle: ILocomotive | ICarWagon): vehicle is ILocomotive {
return (vehicle as ILocomotive).power !== undefined;
@@ -106,33 +106,19 @@ export function maxStockSpeed(state: IStore) {
const stockMass = totalMass(state);
const speedLimitByMass = calculateSpeedLimit(locoType as LocoType, stockMass, isTrainPassenger(state));
const speedLimitByMass = calculateSpeedLimit(locoType as SpeedLimitLocoType, stockMass, isTrainPassenger(state));
return speedLimitByMass ? Math.min(stockSpeedLimit, speedLimitByMass) : stockSpeedLimit;
}
export function acceptableMass(state: IStore) {
if (state.stockList.length == 0 || !state.stockList[0].isLoco) return 0;
const activeLocomotiveType = state.stockList[0].type;
if (/^SM/.test(activeLocomotiveType)) return 2400;
const activeLocomotiveType = state.stockList[0].type.split('-')[0];
// Elektryczne EU07 / EP07 / EP08 / ET41
const locoMassLimit = calculateMassLimit(activeLocomotiveType as MassLimitLocoType, isTrainPassenger(state));
// Pasażerski elektr.
if (isTrainPassenger(state)) {
if (/^(EU|EP)/.test(activeLocomotiveType)) return 650;
if (/^ET/.test(activeLocomotiveType)) return 700;
return 0;
}
// Towarowy / inny elektr.
if (/^EU/.test(activeLocomotiveType)) return 2000;
if (/^ET/.test(activeLocomotiveType)) return 4000;
if (/^EP/.test(activeLocomotiveType)) return 650;
return 0;
return locoMassLimit;
}
export function isTrainPassenger(state: IStore) {