mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 18:47:06 +01:00
d0387753f8
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.
97 lines
3.7 KiB
C++
97 lines
3.7 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
#include "vehicle.h"
|
|
|
|
// the cab interior light set by the positions of the light preset selector: an optional third column of LightsList,
|
|
// 1 the cab light on, 2 dimmed, 0 off; a row without it leaves the cab light to its own switch (eu07/maszyna#529)
|
|
|
|
using test::definition;
|
|
using test::vehicle;
|
|
|
|
namespace {
|
|
|
|
auto const shunting{light::headlight_left | light::headlight_right};
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("lights preset cab light: a table without the column sets no position's cab light") {
|
|
vehicle wagon{definition::load("wagon")
|
|
.set("LightsList", "Size", 2)
|
|
.set("LightsList", "Default", 1)
|
|
.set("LightsList", "rows", {{0, 0}, {shunting, shunting}})};
|
|
|
|
REQUIRE(wagon->LightsPosNo == 2);
|
|
CHECK(wagon->Lights[VehicleEnd::front][1] == shunting);
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(1).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(2).has_value());
|
|
}
|
|
|
|
TEST_CASE("lights preset cab light: the third column turns the cab light off, on, or on dimmed") {
|
|
// off - shunting - shunting with the cab lit - shunting with the cab lit dimmed - shunting leaving the cab light
|
|
vehicle wagon{definition::load("wagon")
|
|
.set("LightsList", "Size", 5)
|
|
.set("LightsList", "Default", 1)
|
|
.set("LightsList", "rows", {{0, 0, 0}, {shunting, shunting}, {shunting, shunting, 1}, {shunting, shunting, 3}, {shunting, 0, -1}})};
|
|
|
|
REQUIRE(wagon->LightsPosNo == 5);
|
|
// the light columns read as before
|
|
CHECK(wagon->Lights[VehicleEnd::front][2] == shunting);
|
|
CHECK(wagon->Lights[VehicleEnd::rear][2] == shunting);
|
|
CHECK(wagon->Lights[VehicleEnd::rear][4] == 0);
|
|
|
|
auto const off{wagon->LightsPresetCabLight(1)};
|
|
REQUIRE(off.has_value());
|
|
CHECK_FALSE(off->light);
|
|
CHECK_FALSE(off->dim);
|
|
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(2).has_value());
|
|
|
|
auto const lit{wagon->LightsPresetCabLight(3)};
|
|
REQUIRE(lit.has_value());
|
|
CHECK(lit->light);
|
|
CHECK_FALSE(lit->dim);
|
|
|
|
auto const dimmed{wagon->LightsPresetCabLight(4)};
|
|
REQUIRE(dimmed.has_value());
|
|
CHECK(dimmed->light);
|
|
CHECK(dimmed->dim);
|
|
|
|
// a negative value is the same as no value
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(5).has_value());
|
|
}
|
|
|
|
TEST_CASE("lights preset cab light: positions outside the table, and the lightsset custom one, set nothing") {
|
|
vehicle wagon{definition::load("wagon")
|
|
.set("LightsList", "Size", 1)
|
|
.set("LightsList", "Default", 1)
|
|
.set("LightsList", "rows", {{shunting, shunting, 1}})};
|
|
|
|
CHECK(wagon->LightsPresetCabLight(1).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(0).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(2).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(18).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(19).has_value());
|
|
}
|
|
|
|
TEST_CASE("lights preset cab light: a stray note after the two columns is not read as the cab light") {
|
|
// some vehicles of the game carry rows like "38 38 / A"
|
|
auto text{definition::load("wagon")
|
|
.set("LightsList", "Size", 2)
|
|
.set("LightsList", "Default", 1)
|
|
.set("LightsList", "rows", {{0, 0}, {38, 38}})
|
|
.text()};
|
|
auto const list{text.find("LightsList")};
|
|
REQUIRE(list != std::string::npos);
|
|
auto const row{text.find("38", list)};
|
|
REQUIRE(row != std::string::npos);
|
|
auto const rowend{text.find('\n', row)};
|
|
REQUIRE(rowend != std::string::npos);
|
|
text.insert(rowend, " / A");
|
|
physics::Vehicle wagon(0.0, "wagon", "test", 0);
|
|
REQUIRE(wagon.LoadFIZ_Text(text));
|
|
REQUIRE(wagon.LightsPosNo == 2);
|
|
CHECK(wagon.Lights[VehicleEnd::front][1] == 38);
|
|
CHECK(wagon.Lights[VehicleEnd::rear][1] == 38);
|
|
CHECK_FALSE(wagon.LightsPresetCabLight(2).has_value());
|
|
}
|