18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-24 08:29:12 +01:00

feat: light programmer positions can switch the cab light (eu07/maszyna#529)

An optional third column in the LightsList rows of the .fiz sets the cab
interior light when the driver moves the light preset selector to that
position: 0 off, 1 on, 3 on dimmed (bit 2 the dimmer). Rows without the
column, or with a negative value, leave the cab light to its own switch,
so the existing tables work as before; a stray note after the two light
columns (e.g. "38 38 / A") is not read as the flag.

The light follows the occupied cab, or all cabs of a JointCabs vehicle,
as with the interior light commands; the dimmer switch is moved along.
The lightsset custom position and the AI leave the cab light alone.

Covered by tests/unit/test_lights_preset_cablight.cpp.

(eu07/maszyna#529)
This commit is contained in:
jerrrrycho
2026-11-07 23:13:00 +01:00
parent 68fdf1efdf
commit d3dd883700
5 changed files with 188 additions and 0 deletions

View File

@@ -10,7 +10,9 @@ http://mozilla.org/MPL/2.0/.
#pragma once
//---------------------------------------------------------------------------
// Q: 20160805 - odlaczenie pliku fizyki .pas od kompilacji
#include <array>
#include <map>
#include <optional>
#include "hamulce.h"
#include "scripting/ladderlogic.h"
@@ -324,6 +326,21 @@ enum light
highbeamlight_right = 1 << 10
};
/// <summary>The cab interior light a position of the light preset selector sets (eu07/maszyna#529).</summary>
struct lights_preset_cablight
{
/// <summary>Bits of the optional third column of a LightsList row.</summary>
enum flag
{
/// <summary>The cab light is on.</summary>
light_on = 1 << 0,
/// <summary>The cab light is dimmed.</summary>
light_dimmed = 1 << 1
};
bool light{false};
bool dim{false};
};
/// <summary>Door operation method (who controls them and how) — mutually exclusive.</summary>
enum control_t
{
@@ -1703,6 +1720,13 @@ class TMoverParameters
int LightsDefPos = 1;
bool LightsWrap = false;
int Lights[2][18]; // pozycje świateł, przód - tył, 1 .. 16 (17 do lightsset)
// the cab interior light each light preset sets, from the optional third column of LightsList (bits of
// lights_preset_cablight::flag); -1: the preset leaves the cab light as it is (eu07/maszyna#529)
std::array<int, 18> LightsCabLight{[] {
std::array<int, 18> positions;
positions.fill(-1);
return positions;
}()};
int ScndInMain{0}; /*zaleznosc bocznika od nastawnika*/
bool MBrake = false; /*Czy jest hamulec reczny*/
double maxTachoSpeed = {0.0}; // maksymalna predkosc na tarczce predkosciomierza analogowego
@@ -2602,6 +2626,8 @@ class TMoverParameters
bool LoadFIZ_Text(std::string const &Text); // the same, from text in the .fiz format
bool CheckLocomotiveParameters(bool ReadyFlag, int Dir);
std::string EngineDescription(int what) const;
// the cab interior light the light preset at given position (1-based, as LightsPos) sets, if it sets one
std::optional<lights_preset_cablight> LightsPresetCabLight(int Position) const;
private:
bool LoadFIZ_Parse(cParser &Parser); // reads the definition from either of the above

View File

@@ -17,6 +17,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/parser.h"
#include "simulation/simulation.h"
#include <charconv>
#include <cmath>
#include <format>
//---------------------------------------------------------------------------
@@ -9493,10 +9494,38 @@ bool TMoverParameters::readLightsList(std::string const &Input)
return false;
}
parser >> Lights[0][idx] >> Lights[1][idx];
// optional third column: the cab interior light the preset sets (eu07/maszyna#529). anything but a whole number
// (some rows carry stray notes after the two columns) leaves the cab light to its own switch
LightsCabLight[idx] = -1;
if (true == parser.getTokens(1, false))
{
std::string cablight;
parser >> cablight;
int flags{-1};
auto const [end, error]{std::from_chars(cablight.data(), cablight.data() + cablight.size(), flags)};
if (error == std::errc{} && end == cablight.data() + cablight.size() && flags >= 0)
{
LightsCabLight[idx] = flags;
}
}
return true;
}
std::optional<lights_preset_cablight> TMoverParameters::LightsPresetCabLight(int const Position) const
{
if (Position < 1 || Position > static_cast<int>(LightsCabLight.size()))
{
return std::nullopt;
}
auto const flags{LightsCabLight[Position - 1]};
if (flags < 0)
{
return std::nullopt;
}
return lights_preset_cablight{(flags & lights_preset_cablight::light_on) != 0, (flags & lights_preset_cablight::light_dimmed) != 0};
}
bool TMoverParameters::readCompressorList(std::string const &Input)
{