mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 15:17:08 +01:00
16568d5695
The rest of the braking of physics::Vehicle moves into brakes, with English
names (physics/components/braking.h):
the valves Hamulec distributor, Handle driverValve,
LocHandle independentValve
the definition BrakeSystem kind, BrakeSubsystem subsystem, BrakeValve /
BrakeValveSize / BrakeValveParams distributorType / Size /
Parameters, BrakeHandle / BrakeLocHandle driverValveType /
independentValveType, the Handle_* driverValveSettings,
LocalBrake localKind, MaxBrakePress maxCylinderPressure,
LoadFlag loadSetting, P2FTrans pressureToForce, NBpA
blocksPerAxle, High/Low/DeltaPipePress pipeHigh/LowPressure
/ pipePressureRange, CntrlPipePress controlReservoirPressure,
Spg pipeSection, RapidMult / RapidVel rapidRatio / rapidSpeed,
BrakeDelay delays, BrakeCtrlPosNo handlePositions, ...
cylinders BrakeCylNo / Radius / Dist / Mult / Spring, BrakeSlckAdj,
BrakeRigEff: count, radius, stroke, leverRatio, springForce,
slackAdjusterForce, riggingEfficiency
emergencyValve EmergencyValveOn / Off / Open / Area / Flow
pipeLock LockPipeOn / Off, HandleUnlock, LockPipe, UnlockPipe
the state BrakePress cylinderPressure, LocBrakePress
independentCylinderPressure, EqvtPipePress
equivalentPipePressure, Volume reservoirAir, dpBrake / dpPipe /
dpMainValve / dpLocalValve brakeFlow / pipeFlow /
driverValveFlow / independentValveFlow, BrakeCtrlPos(R, 2)
handlePosition(Real), handleCapPosition, fBrakeCtrlPos
handlePositionSmooth, LocalBrakePosA(EIM) independentPosition
(Eim), BrakeStatus status, AlarmChainFlag alarmChain,
BrakeDelayFlag / BrakeDelays delaySetting / availableDelays,
BrakeOpModeFlag / BrakeOpModes operatingMode /
availableOperatingModes, UnitBrakeForce unitForce, ...
Renamed in the files of the vehicle itself, and elsewhere only where reached
through -> or .: the driver keeps its own BrakeSystem, the editor its Handle,
the radio its Volume, and the brake valve classes (brakes.*, oerlikonest.*)
their fields of the same names. The C arrays (MaxBrakePress, BrakeCylMult,
the universal buttons) are std::arrays of the same values; the bits of status,
delaySetting and operatingMode stay ints for now.
No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
135 lines
4.0 KiB
C++
135 lines
4.0 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "vehicle/crew.h"
|
|
|
|
#include "physics/vehicle.h"
|
|
#include "vehicle/handover.h"
|
|
|
|
namespace crew {
|
|
|
|
namespace {
|
|
|
|
// the scenery parser folds the ASCII letters of the names only, and so does this
|
|
char lower_ascii(char const Character) {
|
|
return Character >= 'A' && Character <= 'Z' ? static_cast<char>(Character - 'A' + 'a') : Character;
|
|
}
|
|
|
|
// the controllers of the vehicle to the positions giving no power, and the vehicles it controls told so
|
|
void cut_power(physics::Vehicle &Vehicle) {
|
|
Vehicle.MainCtrlPos = Vehicle.MainCtrlNoPowerPos();
|
|
Vehicle.ScndCtrlPos = 0;
|
|
// what the integrated handle and the cruise control asked for last stays in force until somebody drives
|
|
Vehicle.eimic = 0.0;
|
|
Vehicle.eimic_real = 0.0;
|
|
Vehicle.SpeedCtrlValue = 0.0;
|
|
Vehicle.SpeedCtrlUnit.IsActive = false;
|
|
Vehicle.SendCtrlToNext(VehicleCommand::mainController, Vehicle.MainCtrlPosForCoupled(), Vehicle.CabActive);
|
|
Vehicle.SendCtrlToNext(VehicleCommand::secondaryController, Vehicle.ScndCtrlPos, Vehicle.CabActive);
|
|
Vehicle.SendCtrlToNext(VehicleCommand::integratedController, 0.0, Vehicle.CabActive);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
bool is_command(std::string_view const Text) {
|
|
return Text.starts_with(command_prefix);
|
|
}
|
|
|
|
request parse(std::string_view const Text, double const Cab, double const Flags) {
|
|
request result;
|
|
if (false == is_command(Text)) {
|
|
return result;
|
|
}
|
|
result.vehicle = Text.substr(command_prefix.size());
|
|
std::ranges::transform(result.vehicle, result.vehicle.begin(), lower_ascii);
|
|
result.cab_valid = Cab == 1.0 || Cab == -1.0 || Cab == 0.0;
|
|
if (result.cab_valid) {
|
|
result.cab = static_cast<int>(Cab);
|
|
}
|
|
result.flags = static_cast<int>(std::clamp(Flags, -65535.0, 65535.0));
|
|
return result;
|
|
}
|
|
|
|
action decide(request const &Request, vehicle_state const &State) {
|
|
using enum action;
|
|
if (false == Request.cab_valid) {
|
|
return refuse_cab;
|
|
}
|
|
if (State.occupied || (State.has_driver && false == State.driver_is_ai)) {
|
|
return refuse_user;
|
|
}
|
|
if (Request.cab == 0) {
|
|
return State.has_driver ? remove : nothing;
|
|
}
|
|
if (State.has_driver) {
|
|
return refuse_crewed;
|
|
}
|
|
if (false == State.has_cab) {
|
|
return refuse_no_cab;
|
|
}
|
|
if (State.consist_driven) {
|
|
return refuse_consist_driven;
|
|
}
|
|
return Request.cab > 0 ? add_front : add_rear;
|
|
}
|
|
|
|
bool changes_crew(action const Action) {
|
|
return Action == action::add_front || Action == action::add_rear || Action == action::remove;
|
|
}
|
|
|
|
std::string_view describe(action const Action) {
|
|
using enum action;
|
|
switch (Action) {
|
|
case add_front:
|
|
return "an AI driver takes cab A";
|
|
case add_rear:
|
|
return "an AI driver takes cab B";
|
|
case remove:
|
|
return "the AI driver leaves";
|
|
case nothing:
|
|
return "no driver to take off";
|
|
case refuse_cab:
|
|
return "refused, the cab has to be 1, -1 or 0";
|
|
case refuse_user:
|
|
return "refused, a user is in the vehicle";
|
|
case refuse_crewed:
|
|
return "refused, the vehicle has a driver already";
|
|
case refuse_no_cab:
|
|
return "refused, the vehicle has no cab";
|
|
case refuse_consist_driven:
|
|
return "refused, the consist has a driver in charge in another vehicle";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
void secure(physics::Vehicle &Occupied, physics::Vehicle &Controlling) {
|
|
handover::release_ai_controls(Occupied, Controlling);
|
|
cut_power(Controlling);
|
|
if (&Occupied != &Controlling) {
|
|
cut_power(Occupied);
|
|
}
|
|
// the emergency position vents the brake pipe whatever the brake mode, and with nobody in the cab too
|
|
Occupied.BrakeLevelSet(Occupied.brakes.driverValve->GetPos(bh_EB));
|
|
// a vehicle with no train brake (a car, a draisine) gets the brake its driver stops it with, in full
|
|
if (Occupied.brakes.kind == TBrakeSystem::Individual) {
|
|
if (Occupied.brakes.localKind == TLocalBrake::ManualBrake) {
|
|
Occupied.IncManualBrakeLevel(ManualBrakePosNo);
|
|
}
|
|
else {
|
|
Occupied.IncLocalBrakeLevel(LocalBrakePosNo);
|
|
}
|
|
}
|
|
Occupied.CabDeactivisation();
|
|
Occupied.CabOccupied = 0;
|
|
}
|
|
|
|
} // namespace crew
|