18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 16:44:58 +01:00

Merge pull request #267 from MaSzyna-EU07/fix/light-programmer-coupled-side-headlights

Light programmer: switch off the lights at the coupled end, not the opposite one (eu07/maszyna#395)
This commit is contained in:
2026-11-09 12:58:57 +00:00
committed by GitHub
3 changed files with 148 additions and 16 deletions

View File

@@ -15,6 +15,8 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "vehicle/DynObj.h"
#include "vehicle/lightsprogrammer.h"
#include "simulation/simulation.h"
#include "rendering/lightarray.h"
#include "vehicle/Camera.h"
@@ -7372,26 +7374,22 @@ void TDynamicObject::SetLights() {
auto const isfrontcaboccupied { MoverParameters->CabOccupied * DirectionGet() >= 0 };
int const automaticmarkers { MoverParameters->CabActive == 0 && MoverParameters->InactiveCabFlag & activation::redmarkers
? light::redmarker_left + light::redmarker_right : 0 };
int const front { ( isfrontcaboccupied ? end::front : end::rear ) };
int const rear { 1 - front };
auto const lightpos { MoverParameters->LightsPos - 1 };
auto const frontlights { automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ front ][ lightpos ] };
auto const rearlights { automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ rear ][ lightpos ] };
std::array<int, 2> const cablights {
automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ end::front ][ lightpos ],
automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ end::rear ][ lightpos ] };
// the custom position keeps the lights lit at coupled ends as well
auto const ignorecouplings { MoverParameters->LightsPos == 18 };
auto *vehicle { GetFirstDynamic( MoverParameters->CabOccupied >= 0 ? end::front : end::rear, coupling::control ) };
while( vehicle != nullptr ) {
// set lights on given side if there's no coupling with another vehicle, turn them off otherwise
auto const *frontvehicle{(isfrontcaboccupied ? vehicle->Prev(coupling::coupler) : vehicle->Next(coupling::coupler))};
auto const *rearvehicle{(isfrontcaboccupied ? vehicle->Next(coupling::coupler) : vehicle->Prev(coupling::coupler))};
if (MoverParameters->LightsPos == 18)
{
frontvehicle = nullptr;
rearvehicle = nullptr;
}
vehicle->RaLightsSet(
frontvehicle == nullptr ? frontlights : 0,
rearvehicle == nullptr ? rearlights : 0 );
auto const iscoupled { [ vehicle, ignorecouplings ]( end const Side ) {
return false == ignorecouplings
&& ( vehicle->MoverParameters->Couplers[ Side ].CouplingFlag & coupling::coupler ) != 0
&& vehicle->MoverParameters->Neighbours[ Side ].vehicle != nullptr; } };
auto const lights { lights_programmer::vehicle_lights(
cablights, isfrontcaboccupied, vehicle->iDirection, { iscoupled( end::front ), iscoupled( end::rear ) } ) };
vehicle->RaLightsSet( lights.head, lights.rear );
vehicle = isfrontcaboccupied ? vehicle->Next(coupling::control) : vehicle->Prev(coupling::control);
}
};

View File

@@ -0,0 +1,41 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <array>
#include "McZapkie/MOVER.h"
// the lights the light preset selector (programmer) of the occupied cab gives one vehicle of the consist
namespace lights_programmer {
// the lights for the vehicle's two ends, in the terms of TDynamicObject::RaLightsSet(): head is the end
// towards the head of the consist (TDynamicObject::Prev()), rear the end towards its tail (Next())
struct consist_lights {
int head;
int rear;
};
// Cablights: the selector's lights for the occupied cab's front and back (Lights[end::front / end::rear]).
// Cabfacinghead: the occupied cab faces the head of the consist.
// Direction: the vehicle's iDirection, 1 when its end::front is towards the head of the consist.
// Coupled: whether another vehicle is coupled at the vehicle's end::front / end::rear; an end with a coupled
// vehicle stays dark
inline consist_lights vehicle_lights(std::array<int, 2> const &Cablights, bool const Cabfacinghead, int const Direction, std::array<bool, 2> const &Coupled) {
auto const headlights{Cablights[Cabfacinghead ? end::front : end::rear]};
auto const rearlights{Cablights[Cabfacinghead ? end::rear : end::front]};
// the head lights go to the vehicle's end towards the head of the consist whichever way the cab faces,
// so the coupling which keeps them dark is the one at that same end (eu07/maszyna#395)
auto const headend{Direction > 0 ? end::front : end::rear};
auto const rearend{Direction > 0 ? end::rear : end::front};
return {Coupled[headend] ? 0 : headlights, Coupled[rearend] ? 0 : rearlights};
}
} // namespace lights_programmer