mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 03:37:09 +01:00
fbb9dc1e89
end and side were unscoped enums: front, rear, left and right sat in the
global namespace (the test PCH had to leave mover.h out for it), and an end
went into any int, a side into an end, without a word from the compiler. They
become enum class VehicleEnd and VehicleSide (physics/vehicletypes.h); the
names follow the rule for types, and leave "end" and "side" to the many
locals of that name. The numbers stay: front 0, rear 1, right 0, left 1.
- ByEnd<T> / BySide<T>: two values indexed by the enum, and by a number
where a loop or a format counts them. The arrays of the ends and the sides
are these now: Couplers, Neighbours, Pantographs, MotorBlowers, Lights,
iLights, Doors.instances, pVehicles, IsAnyDoor*, m_lighthints, vCoulpler,
m_couplersounds, m_mirrormotion, iInventory, and the voltages of the
couplers
- VehicleEnds / VehicleSides to go through them, Opposite() in place of
1 - end, NumberOf() where a number is needed
- the couplers and the collisions take the ends they work on as VehicleEnd:
CouplerForce, CouplerVelocityDifference, CollisionDetect, crush_hit,
CompatibleCoupling and the rest of their family, DirF, DirPatch, and of
the vehicle couple, uncouple, the adapters, off_track_gap, has_signal_on;
Attach, Dettach and DettachStatus have overloads by the ends
- neighbour_data::FacingEnd() and TCoupling::ConnectedEnd() give the end of
the other vehicle as VehicleEnd; the fields stay numbers, as they hold -1
and 2 for "none" in places
The walks along the consist (FirstFind, Neighbour, the AI's coupling and
uncoupling) still carry the ends as numbers; where one of them meets a typed
end, NumberOf() and EndOf() say so, and keep the number as it was.
Kept as it was, and worth a look: TDynamicObject::SetLights() switches the
headlights A/B off by CabActive with the cases end::front and end::rear, that
is CabActive 0 and 1, while CabActive is 1 or -1 for the cabs; the cases are
NumberOf(VehicleEnd::front / rear) now, the same numbers.
No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b. betterRenderer/, not built, has had only end:: and side:: renamed.
62 lines
2.5 KiB
C++
62 lines
2.5 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
#include "vehicle.h"
|
|
|
|
// characterisation of what the game's panels read of a vehicle besides the gauges recorded in the traces: the
|
|
// description of its damage on the driver's panel (driveruipanels.cpp)
|
|
|
|
using test::definition;
|
|
using test::vehicle;
|
|
|
|
TEST_CASE("queries: the damage of a vehicle as the driver's panel describes it") {
|
|
vehicle locomotive{definition::fiz("4e_v1/4e")};
|
|
vehicle wagon{definition::fiz("3wl_v2/3wl")};
|
|
// a powered locomotive and a wagon read some of the flags differently
|
|
locomotive->Power = 2000.0;
|
|
REQUIRE(wagon->Power < 0.1);
|
|
|
|
struct damage {
|
|
DamageSet flag;
|
|
char const *locomotive;
|
|
char const *wagon;
|
|
};
|
|
for (auto const &[flag, locomotivetext, wagontext] : {
|
|
damage{{}, "OK", "OK"},
|
|
damage{VehicleDamage::thinWheel, "Thin wheel", "Load shifted"},
|
|
damage{VehicleDamage::wheelWear, "Wheel wear", "Wheel wear"},
|
|
damage{VehicleDamage::bearing, "Bearing damaged", "Bearing damaged"},
|
|
damage{VehicleDamage::coupling, "Coupler broken", "Coupler broken"},
|
|
damage{VehicleDamage::loadDamage, "Ventilator damaged", "Load damaged"},
|
|
damage{VehicleDamage::loadDestroyed, "Engine damaged", "LOAD DESTROYED"},
|
|
damage{VehicleDamage::axle, "Axle broken", "Axle broken"},
|
|
damage{VehicleDamage::derailed, "DERAILED", "DERAILED"},
|
|
// the last flag of the list wins
|
|
damage{VehicleDamage::bearing | VehicleDamage::axle, "Axle broken", "Axle broken"},
|
|
damage{DamageSet::FromBits(255), "WRECKED", "WRECKED"},
|
|
}) {
|
|
CAPTURE(flag);
|
|
locomotive->DamageFlag = flag;
|
|
wagon->DamageFlag = flag;
|
|
CHECK(locomotive->EngineDescription(0) == locomotivetext);
|
|
CHECK(wagon->EngineDescription(0) == wagontext);
|
|
}
|
|
// flat wheels count as worn ones
|
|
wagon->DamageFlag = {};
|
|
wagon->WheelFlat = 6.0;
|
|
CHECK(wagon->EngineDescription(0) == "Wheel wear");
|
|
// nothing else is described
|
|
CHECK(wagon->EngineDescription(1) == "Invalid qualifier");
|
|
}
|
|
|
|
TEST_CASE("queries: the ammeters of a vehicle without power show the current of the ones it controls") {
|
|
vehicle unpowered{definition::fiz("en57_v1/6ba_840")};
|
|
vehicle powered{definition::fiz("en57_v1/5bgb")};
|
|
unpowered->Attach(VehicleEnd::rear, VehicleEnd::front, &powered.mover(), Coupling::control, true, false);
|
|
powered->Power = 600.0;
|
|
powered->Itot = 321.7;
|
|
unpowered->Power = 0.0;
|
|
CHECK(unpowered->ShowCurrent(0) == doctest::Approx(321.0)); // whole amperes
|
|
powered->Power = 0.0;
|
|
CHECK(unpowered->ShowCurrent(0) == doctest::Approx(0.0));
|
|
}
|