mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 08:17:09 +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.
170 lines
5.8 KiB
C++
170 lines
5.8 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
#include "vehicle.h"
|
|
|
|
#include "vehicle/handover.h"
|
|
|
|
using test::definition;
|
|
using test::vehicle;
|
|
|
|
// what the human driver gets when taking a vehicle over from the AI (Q key). the AI operates some controls
|
|
// directly and only the AI ever released them, so the player inherited e.g. a horn blowing forever.
|
|
|
|
namespace {
|
|
|
|
int const pc1{light::headlight_left | light::headlight_upper | light::headlight_right};
|
|
int const allheadlights{pc1 | light::redmarker_left | light::redmarker_right};
|
|
|
|
vehicle cab_vehicle() {
|
|
vehicle cab{definition::load("cab_vehicle")};
|
|
cab->DirActive = 1; // the AI drives: reverser set
|
|
return cab;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("handover: the horn the AI was sounding goes quiet (eu07/maszyna#511)") {
|
|
auto cab{cab_vehicle()};
|
|
SUBCASE("low tone") { cab->WarningSignal = 1; }
|
|
SUBCASE("high tone") { cab->WarningSignal = 2; }
|
|
SUBCASE("both tones") { cab->WarningSignal = 1 | 2; }
|
|
REQUIRE(cab->WarningSignal != 0);
|
|
|
|
handover::release_ai_controls(cab.physics(), cab.physics());
|
|
|
|
CHECK(cab->WarningSignal == 0);
|
|
}
|
|
|
|
TEST_CASE("handover: sanding the AI started stops") {
|
|
auto cab{cab_vehicle()};
|
|
cab->Sandbox(true); // the way the AI sands, bypassing the sanding button
|
|
REQUIRE(cab->SandDose);
|
|
|
|
handover::release_ai_controls(cab.physics(), cab.physics());
|
|
|
|
CHECK_FALSE(cab->SandDose);
|
|
}
|
|
|
|
TEST_CASE("handover: sanding the player or the automatic system asked for goes on") {
|
|
auto cab{cab_vehicle()};
|
|
SUBCASE("sanding button held") { cab->SandboxManual(true); }
|
|
SUBCASE("automatic sanding") {
|
|
cab->SandboxAutoAllow(true);
|
|
cab->SandboxAuto(true);
|
|
}
|
|
REQUIRE(cab->SandDose);
|
|
|
|
handover::release_ai_controls(cab.physics(), cab.physics());
|
|
|
|
CHECK(cab->SandDose);
|
|
}
|
|
|
|
TEST_CASE("handover: the departure signal the AI was giving stops") {
|
|
auto cab{cab_vehicle()};
|
|
cab->signal_departure(true);
|
|
REQUIRE(cab->DepartureSignal);
|
|
|
|
handover::release_ai_controls(cab.physics(), cab.physics());
|
|
|
|
CHECK_FALSE(cab->DepartureSignal);
|
|
}
|
|
|
|
TEST_CASE("handover: the brake releaser the AI was holding lets go") {
|
|
auto cab{cab_vehicle()};
|
|
cab->BrakeReleaser(1);
|
|
REQUIRE(cab->brakes.distributor->Releaser());
|
|
|
|
handover::release_ai_controls(cab.physics(), cab.physics());
|
|
|
|
CHECK_FALSE(cab->brakes.distributor->Releaser());
|
|
}
|
|
|
|
TEST_CASE("handover: nothing the AI didn't latch changes") {
|
|
auto cab{cab_vehicle()};
|
|
|
|
handover::release_ai_controls(cab.physics(), cab.physics());
|
|
|
|
CHECK(cab->WarningSignal == 0);
|
|
CHECK_FALSE(cab->SandDose);
|
|
CHECK_FALSE(cab->DepartureSignal);
|
|
CHECK_FALSE(cab->brakes.distributor->Releaser());
|
|
}
|
|
|
|
TEST_CASE("handover: the light selector moves to the position giving the head lights the AI has set") {
|
|
auto cab{cab_vehicle()};
|
|
REQUIRE(cab->LightsPos == 1); // untouched selector: lights off
|
|
|
|
SUBCASE("Pc1") {
|
|
CHECK(handover::light_selector_position(cab.physics(), NumberOf(VehicleEnd::front), pc1, allheadlights) == 2);
|
|
}
|
|
SUBCASE("lights off") {
|
|
CHECK(handover::light_selector_position(cab.physics(), NumberOf(VehicleEnd::front), 0, allheadlights) == 1);
|
|
}
|
|
SUBCASE("vehicle without the upper headlight, which the AI's Pc1 can't light") {
|
|
auto const inventory{allheadlights & ~light::headlight_upper};
|
|
CHECK(handover::light_selector_position(cab.physics(), NumberOf(VehicleEnd::front), pc1 & inventory, inventory) == 2);
|
|
}
|
|
SUBCASE("no position matches: the selector stays") {
|
|
CHECK(handover::light_selector_position(cab.physics(), NumberOf(VehicleEnd::front), light::headlight_left, allheadlights) == 1);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("handover: the light selector stays within its table") {
|
|
auto cab{cab_vehicle()};
|
|
|
|
SUBCASE("selector bigger than the table, as a vehicle definition can declare") {
|
|
// only the positions the table holds are looked at, the rest can't match
|
|
for (auto &table : cab->Lights) {
|
|
std::fill(std::begin(table) + cab->LightsPosNo, std::end(table), 0);
|
|
}
|
|
cab->LightsPosNo = 100;
|
|
CHECK(handover::light_selector_position(cab.physics(), NumberOf(VehicleEnd::front), pc1, allheadlights) == 2);
|
|
CHECK(handover::light_selector_position(cab.physics(), NumberOf(VehicleEnd::front), light::headlight_left, allheadlights) == 1);
|
|
}
|
|
SUBCASE("table other than the front or rear one: the selector stays") {
|
|
CHECK(handover::light_selector_position(cab.physics(), -1, pc1, allheadlights) == 1);
|
|
CHECK(handover::light_selector_position(cab.physics(), 2, pc1, allheadlights) == 1);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("handover: the light selector already matching the lights stays") {
|
|
auto cab{cab_vehicle()};
|
|
cab->LightsPos = 2; // Pc1
|
|
|
|
CHECK(handover::light_selector_position(cab.physics(), NumberOf(VehicleEnd::front), pc1, allheadlights) == 2);
|
|
}
|
|
|
|
TEST_CASE("handover: the headlight dimmer leaves the off position when the head lights are lit") {
|
|
auto cab{cab_vehicle()};
|
|
REQUIRE(cab->enableModernDimmer);
|
|
REQUIRE(cab->dimPositions.size() == 5);
|
|
cab->modernDimmerPosition = 2; // off, left there by the player before the AI took over
|
|
|
|
SUBCASE("to the default position") {
|
|
CHECK(handover::dimmer_position(cab.physics(), true) == 3);
|
|
}
|
|
SUBCASE("to the first regular position, when the default one is off as well") {
|
|
cab->modernDimmerDefaultPosition = 2;
|
|
CHECK(handover::dimmer_position(cab.physics(), true) == 3);
|
|
}
|
|
SUBCASE("unless the head lights are off anyway") {
|
|
CHECK(handover::dimmer_position(cab.physics(), false) == 2);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("handover: the headlight dimmer in any other position stays") {
|
|
auto cab{cab_vehicle()};
|
|
for (auto const position : {0, 1, 3, 4}) {
|
|
CAPTURE(position);
|
|
cab->modernDimmerPosition = position;
|
|
CHECK(handover::dimmer_position(cab.physics(), true) == position);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("handover: a vehicle without the modern dimmer keeps its dimmer state") {
|
|
vehicle wagon{definition::load("wagon")};
|
|
REQUIRE_FALSE(wagon->enableModernDimmer);
|
|
|
|
CHECK(handover::dimmer_position(wagon.physics(), true) == wagon->modernDimmerPosition);
|
|
}
|