18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 15:17:08 +01:00
Files
maszyna/tests/unit/test_queries.cpp
T
Hirek d0387753f8 refactor(physics): TMoverParameters becomes physics::Vehicle, the mover is gone
The physics of a vehicle loses the name it had from the Pascal of 2001. Done by
tools/rename/mover_to_physics.py, committed with it:

  physics/mover.h                  physics/vehicle.h
  TMoverParameters                 physics::Vehicle (in namespace physics)
  TDynamicObject::MoverParameters  physics
  mvOccupied, mvControlled         occupied, controlled (TTrain, TController)
  mvSecond, mvThird                secondUnit, thirdUnit
  mvPantographUnit                 pantographUnit
  mover, Mover, movers             physics, Physics, vehicles (locals, params)
  m_mover, othermover, currentMover, from_movers, renderMoverEventSounds
                                   m_physics, otherPhysics, currentPhysics,
                                   from_vehicles, renderPhysicsEventSounds

The code and the comments are renamed, the string literals are not: no text
the game shows, logs or looks up has changed (none had the names). The movers
of the editor, the tracks a slide moves, keep their name.

By hand: two member functions of TDynamicObject (gather_off_track_terrain,
begin_off_track) had a local mover aliasing their own MoverParameters, which
the rename made physics { *physics }; the alias is gone, they use physics->.
No other function has a renamed local meeting a renamed member (checked over
all the functions of the code before the rename).

For the branches made before it: run the script on the branch (python
tools/rename/mover_to_physics.py, from the root of the repository) before
merging it with this one, and the names don't conflict. It can be run again;
the second time it changes nothing.

The class is the same as it was; breaking it into its parts (braking,
electrics, controls, load) and making its data private are the next stages.

No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
2026-11-28 23:56:46 +01:00

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.physics(), 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));
}