16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 15:09:19 +02:00

refactoring: cab logic partially separated from cab activation

This commit is contained in:
tmj-fstate
2019-09-25 18:21:42 +02:00
parent 41834c4d4c
commit 2f5b6dee70
2 changed files with 148 additions and 189 deletions

331
Train.cpp
View File

@@ -456,14 +456,14 @@ bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d)
dictionary_source *TTrain::GetTrainState() { dictionary_source *TTrain::GetTrainState() {
auto const *mover = DynamicObject->MoverParameters; if( ( mvOccupied == nullptr )
if( mover == nullptr ) { return nullptr; } || ( mvControlled == nullptr ) ) { return nullptr; }
auto *dict { new dictionary_source }; auto *dict { new dictionary_source };
if( dict == nullptr ) { return nullptr; } if( dict == nullptr ) { return nullptr; }
dict->insert( "name", DynamicObject->asName ); dict->insert( "name", DynamicObject->asName );
dict->insert( "cab", mover->ActiveCab ); dict->insert( "cab", mvOccupied->ActiveCab );
// basic systems state data // basic systems state data
dict->insert( "battery", mvControlled->Battery ); dict->insert( "battery", mvControlled->Battery );
dict->insert( "linebreaker", mvControlled->Mains ); dict->insert( "linebreaker", mvControlled->Mains );
@@ -476,13 +476,13 @@ dictionary_source *TTrain::GetTrainState() {
dict->insert( "lights_front", mvOccupied->iLights[ end::front ] ); dict->insert( "lights_front", mvOccupied->iLights[ end::front ] );
dict->insert( "lights_rear", mvOccupied->iLights[ end::rear ] ); dict->insert( "lights_rear", mvOccupied->iLights[ end::rear ] );
// reverser // reverser
dict->insert( "direction", mover->ActiveDir ); dict->insert( "direction", mvOccupied->ActiveDir );
// throttle // throttle
dict->insert( "mainctrl_pos", mvControlled->MainCtrlPos ); dict->insert( "mainctrl_pos", mvControlled->MainCtrlPos );
dict->insert( "main_ctrl_actual_pos", mvControlled->MainCtrlActualPos ); dict->insert( "main_ctrl_actual_pos", mvControlled->MainCtrlActualPos );
dict->insert( "scndctrl_pos", mvControlled->ScndCtrlPos ); dict->insert( "scndctrl_pos", mvControlled->ScndCtrlPos );
dict->insert( "scnd_ctrl_actual_pos", mvControlled->ScndCtrlActualPos ); dict->insert( "scnd_ctrl_actual_pos", mvControlled->ScndCtrlActualPos );
dict->insert( "new_speed", mover->NewSpeed); dict->insert( "new_speed", mvOccupied->NewSpeed);
// brakes // brakes
dict->insert( "manual_brake", ( mvOccupied->ManualBrakePos > 0 ) ); dict->insert( "manual_brake", ( mvOccupied->ManualBrakePos > 0 ) );
bool const bEP = ( mvControlled->LocHandle->GetCP() > 0.2 ) || ( fEIMParams[ 0 ][ 2 ] > 0.01 ); bool const bEP = ( mvControlled->LocHandle->GetCP() > 0.2 ) || ( fEIMParams[ 0 ][ 2 ] > 0.01 );
@@ -508,10 +508,10 @@ dictionary_source *TTrain::GetTrainState() {
dict->insert( "radio_channel", iRadioChannel ); dict->insert( "radio_channel", iRadioChannel );
dict->insert( "door_lock", mvOccupied->Doors.lock_enabled ); dict->insert( "door_lock", mvOccupied->Doors.lock_enabled );
// movement data // movement data
dict->insert( "velocity", std::abs( mover->Vel ) ); dict->insert( "velocity", std::abs( mvOccupied->Vel ) );
dict->insert( "tractionforce", std::abs( mover->Ft ) ); dict->insert( "tractionforce", std::abs( mvOccupied->Ft ) );
dict->insert( "slipping_wheels", mover->SlippingWheels ); dict->insert( "slipping_wheels", mvOccupied->SlippingWheels );
dict->insert( "sanding", mover->SandDose ); dict->insert( "sanding", mvOccupied->SandDose );
// electric current data // electric current data
dict->insert( "traction_voltage", std::abs( mvControlled->RunningTraction.TractionVoltage ) ); dict->insert( "traction_voltage", std::abs( mvControlled->RunningTraction.TractionVoltage ) );
dict->insert( "voltage", std::abs( mvControlled->Voltage ) ); dict->insert( "voltage", std::abs( mvControlled->Voltage ) );
@@ -571,7 +571,10 @@ dictionary_source *TTrain::GetTrainState() {
dict->insert( ( "slip_" + caridx ), bSlip[ i ] ); dict->insert( ( "slip_" + caridx ), bSlip[ i ] );
} }
// ai state data // ai state data
auto const *driver = DynamicObject->Mechanik; auto const *driver { (
DynamicObject->ctOwner != nullptr ?
DynamicObject->ctOwner :
DynamicObject->Mechanik ) };
dict->insert( "velocity_desired", driver->VelDesired ); dict->insert( "velocity_desired", driver->VelDesired );
dict->insert( "velroad", driver->VelRoad ); dict->insert( "velroad", driver->VelRoad );
@@ -2194,7 +2197,7 @@ void TTrain::OnCommand_pantographcompressorvalvetoggle( TTrain *Train, command_d
if( ( Train->mvControlled->TrainType == dt_EZT ? if( ( Train->mvControlled->TrainType == dt_EZT ?
( Train->mvControlled != Train->mvOccupied ) : ( Train->mvControlled != Train->mvOccupied ) :
( Train->mvOccupied->ActiveCab != 0 ) ) ) { ( Train->iCabn != 0 ) ) ) {
// tylko w maszynowym // tylko w maszynowym
return; return;
} }
@@ -2220,7 +2223,7 @@ void TTrain::OnCommand_pantographcompressoractivate( TTrain *Train, command_data
if( ( Train->mvControlled->TrainType == dt_EZT ? if( ( Train->mvControlled->TrainType == dt_EZT ?
( Train->mvControlled != Train->mvOccupied ) : ( Train->mvControlled != Train->mvOccupied ) :
( Train->mvOccupied->ActiveCab != 0 ) ) ) { ( Train->iCabn != 0 ) ) ) {
// tylko w maszynowym // tylko w maszynowym
return; return;
} }
@@ -3372,7 +3375,7 @@ void TTrain::OnCommand_motordisconnect( TTrain *Train, command_data const &Comma
if( ( Train->mvControlled->TrainType == dt_EZT ? if( ( Train->mvControlled->TrainType == dt_EZT ?
( Train->mvControlled != Train->mvOccupied ) : ( Train->mvControlled != Train->mvOccupied ) :
( Train->mvOccupied->ActiveCab != 0 ) ) ) { ( Train->iCabn != 0 ) ) ) {
// tylko w maszynowym // tylko w maszynowym
return; return;
} }
@@ -3498,14 +3501,11 @@ void TTrain::OnCommand_lightspresetactivateprevious( TTrain *Train, command_data
void TTrain::OnCommand_headlighttoggleleft( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_headlighttoggleleft( TTrain *Train, command_data const &Command ) {
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_left ) == 0 ) { if( ( Train->DynamicObject->iLights[ vehicleend ] & light::headlight_left ) == 0 ) {
// turn on // turn on
OnCommand_headlightenableleft( Train, Command ); OnCommand_headlightenableleft( Train, Command );
} }
@@ -3524,20 +3524,17 @@ void TTrain::OnCommand_headlightenableleft( TTrain *Train, command_data const &C
} }
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside =
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_left ) != 0 ) { return; } // already enabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_left;
// visual feedback // visual feedback
Train->ggLeftLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggLeftLightButton.UpdateValue( 1.0, Train->dsbSwitch );
// implementation
auto const vehicleend { Train->cab_to_end() };
if( ( Train->DynamicObject->iLights[ vehicleend ] & light::headlight_left ) == 0 ) {
Train->DynamicObject->iLights[ vehicleend ] ^= light::headlight_left;
}
// if the light is controlled by 3-way switch, disable marker light // if the light is controlled by 3-way switch, disable marker light
if( Train->ggLeftEndLightButton.SubModel == nullptr ) { if( Train->ggLeftEndLightButton.SubModel == nullptr ) {
Train->DynamicObject->iLights[ vehicleside ] &= ~light::redmarker_left; Train->DynamicObject->iLights[ vehicleend ] &= ~light::redmarker_left;
} }
} }
} }
@@ -3551,14 +3548,11 @@ void TTrain::OnCommand_headlightdisableleft( TTrain *Train, command_data const &
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = int const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_left ) == 0 ) { return; } // already disabled if( ( Train->DynamicObject->iLights[ vehicleend ] & light::headlight_left ) == 0 ) { return; } // already disabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_left; Train->DynamicObject->iLights[ vehicleend ] ^= light::headlight_left;
// visual feedback // visual feedback
Train->ggLeftLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggLeftLightButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
@@ -3566,14 +3560,11 @@ void TTrain::OnCommand_headlightdisableleft( TTrain *Train, command_data const &
void TTrain::OnCommand_headlighttoggleright( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_headlighttoggleright( TTrain *Train, command_data const &Command ) {
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_right ) == 0 ) { if( ( Train->DynamicObject->iLights[ vehicleend ] & light::headlight_right ) == 0 ) {
// turn on // turn on
OnCommand_headlightenableright( Train, Command ); OnCommand_headlightenableright( Train, Command );
} }
@@ -3592,20 +3583,17 @@ void TTrain::OnCommand_headlightenableright( TTrain *Train, command_data const &
} }
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside =
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_right ) != 0 ) { return; } // already enabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_right;
// visual feedback // visual feedback
Train->ggRightLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggRightLightButton.UpdateValue( 1.0, Train->dsbSwitch );
// implementation
auto const vehicleend { Train->cab_to_end() };
if( ( Train->DynamicObject->iLights[ vehicleend ] & light::headlight_right ) == 0 ) {
Train->DynamicObject->iLights[ vehicleend ] ^= light::headlight_right;
}
// if the light is controlled by 3-way switch, disable marker light // if the light is controlled by 3-way switch, disable marker light
if( Train->ggRightEndLightButton.SubModel == nullptr ) { if( Train->ggRightEndLightButton.SubModel == nullptr ) {
Train->DynamicObject->iLights[ vehicleside ] &= ~light::redmarker_right; Train->DynamicObject->iLights[ vehicleend ] &= ~light::redmarker_right;
} }
} }
} }
@@ -3619,14 +3607,11 @@ void TTrain::OnCommand_headlightdisableright( TTrain *Train, command_data const
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_right ) == 0 ) { return; } // already disabled if( ( Train->DynamicObject->iLights[ vehicleend ] & light::headlight_right ) == 0 ) { return; } // already disabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_right; Train->DynamicObject->iLights[ vehicleend ] ^= light::headlight_right;
// visual feedback // visual feedback
Train->ggRightLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggRightLightButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
@@ -3634,14 +3619,11 @@ void TTrain::OnCommand_headlightdisableright( TTrain *Train, command_data const
void TTrain::OnCommand_headlighttoggleupper( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_headlighttoggleupper( TTrain *Train, command_data const &Command ) {
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_upper ) == 0 ) { if( ( Train->DynamicObject->iLights[ vehicleend ] & light::headlight_upper ) == 0 ) {
// turn on // turn on
OnCommand_headlightenableupper( Train, Command ); OnCommand_headlightenableupper( Train, Command );
} }
@@ -3661,14 +3643,11 @@ void TTrain::OnCommand_headlightenableupper( TTrain *Train, command_data const &
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_upper ) != 0 ) { return; } // already enabled if( ( Train->DynamicObject->iLights[ vehicleend ] & light::headlight_upper ) != 0 ) { return; } // already enabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_upper; Train->DynamicObject->iLights[ vehicleend ] ^= light::headlight_upper;
// visual feedback // visual feedback
Train->ggUpperLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggUpperLightButton.UpdateValue( 1.0, Train->dsbSwitch );
} }
@@ -3683,14 +3662,11 @@ void TTrain::OnCommand_headlightdisableupper( TTrain *Train, command_data const
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_upper ) == 0 ) { return; } // already disabled if( ( Train->DynamicObject->iLights[ vehicleend ] & light::headlight_upper ) == 0 ) { return; } // already disabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_upper; Train->DynamicObject->iLights[ vehicleend ] ^= light::headlight_upper;
// visual feedback // visual feedback
Train->ggUpperLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggUpperLightButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
@@ -3700,12 +3676,9 @@ void TTrain::OnCommand_redmarkertoggleleft( TTrain *Train, command_data const &C
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_left ) == 0 ) { if( ( Train->DynamicObject->iLights[ vehicleend ] & light::redmarker_left ) == 0 ) {
// turn on // turn on
OnCommand_redmarkerenableleft( Train, Command ); OnCommand_redmarkerenableleft( Train, Command );
} }
@@ -3725,14 +3698,11 @@ void TTrain::OnCommand_redmarkerenableleft( TTrain *Train, command_data const &C
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_left ) != 0 ) { return; } // already enabled if( ( Train->DynamicObject->iLights[ vehicleend ] & light::redmarker_left ) != 0 ) { return; } // already enabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_left; Train->DynamicObject->iLights[ vehicleend ] ^= light::redmarker_left;
// visual feedback // visual feedback
if( Train->ggLeftEndLightButton.SubModel != nullptr ) { if( Train->ggLeftEndLightButton.SubModel != nullptr ) {
Train->ggLeftEndLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggLeftEndLightButton.UpdateValue( 1.0, Train->dsbSwitch );
@@ -3742,7 +3712,7 @@ void TTrain::OnCommand_redmarkerenableleft( TTrain *Train, command_data const &C
// this is crude, but for now will do // this is crude, but for now will do
Train->ggLeftLightButton.UpdateValue( -1.0, Train->dsbSwitch ); Train->ggLeftLightButton.UpdateValue( -1.0, Train->dsbSwitch );
// if the light is controlled by 3-way switch, disable the headlight // if the light is controlled by 3-way switch, disable the headlight
Train->DynamicObject->iLights[ vehicleside ] &= ~light::headlight_left; Train->DynamicObject->iLights[ vehicleend ] &= ~light::headlight_left;
} }
} }
} }
@@ -3756,14 +3726,11 @@ void TTrain::OnCommand_redmarkerdisableleft( TTrain *Train, command_data const &
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_left ) == 0 ) { return; } // already disabled if( ( Train->DynamicObject->iLights[ vehicleend ] & light::redmarker_left ) == 0 ) { return; } // already disabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_left; Train->DynamicObject->iLights[ vehicleend ] ^= light::redmarker_left;
// visual feedback // visual feedback
if( Train->ggLeftEndLightButton.SubModel != nullptr ) { if( Train->ggLeftEndLightButton.SubModel != nullptr ) {
Train->ggLeftEndLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggLeftEndLightButton.UpdateValue( 0.0, Train->dsbSwitch );
@@ -3780,12 +3747,9 @@ void TTrain::OnCommand_redmarkertoggleright( TTrain *Train, command_data const &
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_right ) == 0 ) { if( ( Train->DynamicObject->iLights[ vehicleend ] & light::redmarker_right ) == 0 ) {
// turn on // turn on
OnCommand_redmarkerenableright( Train, Command ); OnCommand_redmarkerenableright( Train, Command );
} }
@@ -3805,14 +3769,11 @@ void TTrain::OnCommand_redmarkerenableright( TTrain *Train, command_data const &
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_right ) != 0 ) { return; } // already enabled if( ( Train->DynamicObject->iLights[ vehicleend ] & light::redmarker_right ) != 0 ) { return; } // already enabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_right; Train->DynamicObject->iLights[ vehicleend ] ^= light::redmarker_right;
// visual feedback // visual feedback
if( Train->ggRightEndLightButton.SubModel != nullptr ) { if( Train->ggRightEndLightButton.SubModel != nullptr ) {
Train->ggRightEndLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggRightEndLightButton.UpdateValue( 1.0, Train->dsbSwitch );
@@ -3822,7 +3783,7 @@ void TTrain::OnCommand_redmarkerenableright( TTrain *Train, command_data const &
// this is crude, but for now will do // this is crude, but for now will do
Train->ggRightLightButton.UpdateValue( -1.0, Train->dsbSwitch ); Train->ggRightLightButton.UpdateValue( -1.0, Train->dsbSwitch );
// if the light is controlled by 3-way switch, disable the headlight // if the light is controlled by 3-way switch, disable the headlight
Train->DynamicObject->iLights[ vehicleside ] &= ~light::headlight_right; Train->DynamicObject->iLights[ vehicleend ] &= ~light::headlight_right;
} }
} }
} }
@@ -3836,14 +3797,11 @@ void TTrain::OnCommand_redmarkerdisableright( TTrain *Train, command_data const
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
int const vehicleside = auto const vehicleend { Train->cab_to_end() };
( Train->mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_right ) == 0 ) { return; } // already disabled if( ( Train->DynamicObject->iLights[ vehicleend ] & light::redmarker_right ) == 0 ) { return; } // already disabled
Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_right; Train->DynamicObject->iLights[ vehicleend ] ^= light::redmarker_right;
// visual feedback // visual feedback
if( Train->ggRightEndLightButton.SubModel != nullptr ) { if( Train->ggRightEndLightButton.SubModel != nullptr ) {
Train->ggRightEndLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggRightEndLightButton.UpdateValue( 0.0, Train->dsbSwitch );
@@ -3863,23 +3821,22 @@ void TTrain::OnCommand_headlighttogglerearleft( TTrain *Train, command_data cons
return; return;
} }
int const vehicleside =
( Train->mvOccupied->ActiveCab == 1 ?
end::rear :
end::front );
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
auto const vehicleotherend { (
Train->cab_to_end() == end::front ?
end::rear :
end::front ) };
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_right ) == 0 ) { if( ( Train->DynamicObject->iLights[ vehicleotherend ] & light::headlight_right ) == 0 ) {
// turn on // turn on
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_right; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::headlight_right;
// visual feedback // visual feedback
Train->ggRearLeftLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggRearLeftLightButton.UpdateValue( 1.0, Train->dsbSwitch );
} }
else { else {
//turn off //turn off
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_right; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::headlight_right;
// visual feedback // visual feedback
Train->ggRearLeftLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggRearLeftLightButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
@@ -3893,23 +3850,22 @@ void TTrain::OnCommand_headlighttogglerearright( TTrain *Train, command_data con
return; return;
} }
int const vehicleside =
( Train->mvOccupied->ActiveCab == 1 ?
end::rear :
end::front );
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
auto const vehicleotherend { (
Train->cab_to_end() == end::front ?
end::rear :
end::front ) };
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_left ) == 0 ) { if( ( Train->DynamicObject->iLights[ vehicleotherend ] & light::headlight_left ) == 0 ) {
// turn on // turn on
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_left; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::headlight_left;
// visual feedback // visual feedback
Train->ggRearRightLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggRearRightLightButton.UpdateValue( 1.0, Train->dsbSwitch );
} }
else { else {
//turn off //turn off
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_left; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::headlight_left;
// visual feedback // visual feedback
Train->ggRearRightLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggRearRightLightButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
@@ -3923,22 +3879,21 @@ void TTrain::OnCommand_headlighttogglerearupper( TTrain *Train, command_data con
return; return;
} }
int const vehicleside =
( Train->mvOccupied->ActiveCab == 1 ?
end::rear :
end::front );
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_upper ) == 0 ) { auto const vehicleotherend { (
Train->cab_to_end() == end::front ?
end::rear :
end::front ) };
if( ( Train->DynamicObject->iLights[ vehicleotherend ] & light::headlight_upper ) == 0 ) {
// turn on // turn on
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_upper; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::headlight_upper;
// visual feedback // visual feedback
Train->ggRearUpperLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggRearUpperLightButton.UpdateValue( 1.0, Train->dsbSwitch );
} }
else { else {
//turn off //turn off
Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_upper; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::headlight_upper;
// visual feedback // visual feedback
Train->ggRearUpperLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggRearUpperLightButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
@@ -3952,23 +3907,22 @@ void TTrain::OnCommand_redmarkertogglerearleft( TTrain *Train, command_data cons
return; return;
} }
int const vehicleside =
( Train->mvOccupied->ActiveCab == 1 ?
end::rear :
end::front );
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
auto const vehicleotherend { (
Train->cab_to_end() == end::front ?
end::rear :
end::front ) };
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_right ) == 0 ) { if( ( Train->DynamicObject->iLights[ vehicleotherend ] & light::redmarker_right ) == 0 ) {
// turn on // turn on
Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_right; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::redmarker_right;
// visual feedback // visual feedback
Train->ggRearLeftEndLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggRearLeftEndLightButton.UpdateValue( 1.0, Train->dsbSwitch );
} }
else { else {
//turn off //turn off
Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_right; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::redmarker_right;
// visual feedback // visual feedback
Train->ggRearLeftEndLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggRearLeftEndLightButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
@@ -3982,23 +3936,22 @@ void TTrain::OnCommand_redmarkertogglerearright( TTrain *Train, command_data con
return; return;
} }
int const vehicleside =
( Train->mvOccupied->ActiveCab == 1 ?
end::rear :
end::front );
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
auto const vehicleotherend { (
Train->cab_to_end() == end::front ?
end::rear :
end::front ) };
// only reacting to press, so the switch doesn't flip back and forth if key is held down // only reacting to press, so the switch doesn't flip back and forth if key is held down
if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_left ) == 0 ) { if( ( Train->DynamicObject->iLights[ vehicleotherend ] & light::redmarker_left ) == 0 ) {
// turn on // turn on
Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_left; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::redmarker_left;
// visual feedback // visual feedback
Train->ggRearRightEndLightButton.UpdateValue( 1.0, Train->dsbSwitch ); Train->ggRearRightEndLightButton.UpdateValue( 1.0, Train->dsbSwitch );
} }
else { else {
//turn off //turn off
Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_left; Train->DynamicObject->iLights[ vehicleotherend ] ^= light::redmarker_left;
// visual feedback // visual feedback
Train->ggRearRightEndLightButton.UpdateValue( 0.0, Train->dsbSwitch ); Train->ggRearRightEndLightButton.UpdateValue( 0.0, Train->dsbSwitch );
} }
@@ -4614,7 +4567,7 @@ void TTrain::OnCommand_doorpermitleft( TTrain *Train, command_data const &Comman
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
auto const side { ( auto const side { (
Train->mvOccupied->ActiveCab == 1 ? Train->cab_to_end() == end::front ?
side::left : side::left :
side::right ) }; side::right ) };
@@ -4650,7 +4603,7 @@ void TTrain::OnCommand_doorpermitright( TTrain *Train, command_data const &Comma
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
auto const side { ( auto const side { (
Train->mvOccupied->ActiveCab == 1 ? Train->cab_to_end() == end::front ?
side::right : side::right :
side::left ) }; side::left ) };
@@ -4716,7 +4669,7 @@ void TTrain::OnCommand_dooropenleft( TTrain *Train, command_data const &Command
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
Train->mvOccupied->OperateDoors( Train->mvOccupied->OperateDoors(
( Train->mvOccupied->ActiveCab == 1 ? ( Train->cab_to_end() == end::front ?
side::left : side::left :
side::right ), side::right ),
true ); true );
@@ -4762,7 +4715,7 @@ void TTrain::OnCommand_doorcloseleft( TTrain *Train, command_data const &Command
else { else {
// TODO: move door opening/closing to the update, so the switch animation doesn't hinge on door working // TODO: move door opening/closing to the update, so the switch animation doesn't hinge on door working
Train->mvOccupied->OperateDoors( Train->mvOccupied->OperateDoors(
( Train->mvOccupied->ActiveCab == 1 ? ( Train->cab_to_end() == end::front ?
side::left : side::left :
side::right ), side::right ),
false ); false );
@@ -4784,7 +4737,7 @@ void TTrain::OnCommand_doorcloseleft( TTrain *Train, command_data const &Command
Train->mvOccupied->signal_departure( false ); Train->mvOccupied->signal_departure( false );
// now we can actually close the door // now we can actually close the door
Train->mvOccupied->OperateDoors( Train->mvOccupied->OperateDoors(
( Train->mvOccupied->ActiveCab == 1 ? ( Train->cab_to_end() == end::front ?
side::left : side::left :
side::right ), side::right ),
false ); false );
@@ -4881,7 +4834,7 @@ void TTrain::OnCommand_dooropenright( TTrain *Train, command_data const &Command
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
Train->mvOccupied->OperateDoors( Train->mvOccupied->OperateDoors(
( Train->mvOccupied->ActiveCab == 1 ? ( Train->cab_to_end() == end::front ?
side::right : side::right :
side::left ), side::left ),
true ); true );
@@ -4926,7 +4879,7 @@ void TTrain::OnCommand_doorcloseright( TTrain *Train, command_data const &Comman
} }
else { else {
Train->mvOccupied->OperateDoors( Train->mvOccupied->OperateDoors(
( Train->mvOccupied->ActiveCab == 1 ? ( Train->cab_to_end() == end::front ?
side::right : side::right :
side::left ), side::left ),
false ); false );
@@ -4948,7 +4901,7 @@ void TTrain::OnCommand_doorcloseright( TTrain *Train, command_data const &Comman
Train->mvOccupied->signal_departure( false ); Train->mvOccupied->signal_departure( false );
// now we can actually close the door // now we can actually close the door
Train->mvOccupied->OperateDoors( Train->mvOccupied->OperateDoors(
( Train->mvOccupied->ActiveCab == 1 ? ( Train->cab_to_end() == end::front ?
side::right : side::right :
side::left ), side::left ),
false ); false );
@@ -5334,10 +5287,11 @@ void TTrain::OnCommand_radiocall3send( TTrain *Train, command_data const &Comman
void TTrain::OnCommand_cabchangeforward( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_cabchangeforward( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
auto const movedirection { auto const *owner { (
1 * ( Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() == Train->DynamicObject->DirectionGet() ? Train->DynamicObject->ctOwner != nullptr ?
1 : Train->DynamicObject->ctOwner :
-1 ) }; Train->DynamicObject->Mechanik ) };
auto const movedirection { 1 };
if( false == Train->CabChange( movedirection ) ) { if( false == Train->CabChange( movedirection ) ) {
auto const exitdirection { ( auto const exitdirection { (
movedirection > 0 ? movedirection > 0 ?
@@ -5365,10 +5319,11 @@ void TTrain::OnCommand_cabchangeforward( TTrain *Train, command_data const &Comm
void TTrain::OnCommand_cabchangebackward( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_cabchangebackward( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) { if( Command.action == GLFW_PRESS ) {
auto const movedirection { auto const *owner { (
-1 * ( Train->DynamicObject->ctOwner->Vehicle( end::front )->DirectionGet() == Train->DynamicObject->DirectionGet() ? Train->DynamicObject->ctOwner != nullptr ?
1 : Train->DynamicObject->ctOwner :
-1 ) }; Train->DynamicObject->Mechanik ) };
auto const movedirection { -1 };
if( false == Train->CabChange( movedirection ) ) { if( false == Train->CabChange( movedirection ) ) {
// current vehicle doesn't extend any farther in this direction, check if we there's one connected we can move to // current vehicle doesn't extend any farther in this direction, check if we there's one connected we can move to
auto const exitdirection { ( auto const exitdirection { (
@@ -5790,14 +5745,13 @@ bool TTrain::Update( double const Deltatime )
// youBy - prad w drugim czlonie: galaz lub calosc // youBy - prad w drugim czlonie: galaz lub calosc
{ {
TDynamicObject *tmp; TDynamicObject *tmp { nullptr };
tmp = NULL;
if (DynamicObject->NextConnected()) if (DynamicObject->NextConnected())
if ((TestFlag(mvControlled->Couplers[1].CouplingFlag, ctrain_controll)) && if ((TestFlag(mvControlled->Couplers[end::rear].CouplingFlag, ctrain_controll)) &&
(mvOccupied->ActiveCab == 1)) (mvOccupied->ActiveCab == 1))
tmp = DynamicObject->NextConnected(); tmp = DynamicObject->NextConnected();
if (DynamicObject->PrevConnected()) if (DynamicObject->PrevConnected())
if ((TestFlag(mvControlled->Couplers[0].CouplingFlag, ctrain_controll)) && if ((TestFlag(mvControlled->Couplers[end::front].CouplingFlag, ctrain_controll)) &&
(mvOccupied->ActiveCab == -1)) (mvOccupied->ActiveCab == -1))
tmp = DynamicObject->PrevConnected(); tmp = DynamicObject->PrevConnected();
if( tmp ) { if( tmp ) {
@@ -6105,8 +6059,8 @@ bool TTrain::Update( double const Deltatime )
btLampkaRadioStop.Turn( mvOccupied->Radio && mvOccupied->RadioStopFlag ); btLampkaRadioStop.Turn( mvOccupied->Radio && mvOccupied->RadioStopFlag );
btLampkaHamulecReczny.Turn(mvOccupied->ManualBrakePos > 0); btLampkaHamulecReczny.Turn(mvOccupied->ManualBrakePos > 0);
// NBMX wrzesien 2003 - drzwi oraz sygnał odjazdu // NBMX wrzesien 2003 - drzwi oraz sygnał odjazdu
btLampkaDoorLeft.Turn( DynamicObject->Mechanik->IsAnyDoorOpen[ ( mvOccupied->ActiveCab == 1 ? side::left : side::right ) ] ); btLampkaDoorLeft.Turn( DynamicObject->Mechanik->IsAnyDoorOpen[ ( cab_to_end() == end::front ? side::left : side::right ) ] );
btLampkaDoorRight.Turn( DynamicObject->Mechanik->IsAnyDoorOpen[ ( mvOccupied->ActiveCab == 1 ? side::right : side::left ) ] ); btLampkaDoorRight.Turn( DynamicObject->Mechanik->IsAnyDoorOpen[ ( cab_to_end() == end::front ? side::right : side::left ) ] );
btLampkaDoors.Turn( DynamicObject->Mechanik->IsAnyDoorOpen[ side::right ] || DynamicObject->Mechanik->IsAnyDoorOpen[ side::left ] ); btLampkaDoors.Turn( DynamicObject->Mechanik->IsAnyDoorOpen[ side::right ] || DynamicObject->Mechanik->IsAnyDoorOpen[ side::left ] );
btLampkaBlokadaDrzwi.Turn( mvOccupied->Doors.is_locked ); btLampkaBlokadaDrzwi.Turn( mvOccupied->Doors.is_locked );
btLampkaDoorLockOff.Turn( false == mvOccupied->Doors.lock_enabled ); btLampkaDoorLockOff.Turn( false == mvOccupied->Doors.lock_enabled );
@@ -6210,10 +6164,8 @@ bool TTrain::Update( double const Deltatime )
} }
{ // yB - wskazniki drugiego czlonu { // yB - wskazniki drugiego czlonu
TDynamicObject *tmp; //=mvControlled->mvSecond; //Ra 2014-07: trzeba to TDynamicObject *tmp { nullptr }; //=mvControlled->mvSecond; //Ra 2014-07: trzeba to jeszcze wyjąć z kabiny...
// jeszcze wyjąć z kabiny...
// Ra 2014-07: no nie ma potrzeby szukać tego w każdej klatce // Ra 2014-07: no nie ma potrzeby szukać tego w każdej klatce
tmp = NULL;
if ((TestFlag(mvControlled->Couplers[1].CouplingFlag, ctrain_controll)) && if ((TestFlag(mvControlled->Couplers[1].CouplingFlag, ctrain_controll)) &&
(mvOccupied->ActiveCab > 0)) (mvOccupied->ActiveCab > 0))
tmp = DynamicObject->NextConnected(); tmp = DynamicObject->NextConnected();
@@ -6885,7 +6837,11 @@ TTrain::update_sounds( double const Deltatime ) {
// power-reliant sounds // power-reliant sounds
if( mvControlled->Battery || mvControlled->ConverterFlag ) { if( mvControlled->Battery || mvControlled->ConverterFlag ) {
// distance meter alert // distance meter alert
if( m_distancecounter > Dynamic()->ctOwner->fLength ) { auto const *owner { (
DynamicObject->ctOwner != nullptr ?
DynamicObject->ctOwner :
DynamicObject->Mechanik ) };
if( m_distancecounter > owner->fLength ) {
// play assigned sound if the train travelled its full length since meter activation // play assigned sound if the train travelled its full length since meter activation
// TBD: check all combinations of directions and active cab // TBD: check all combinations of directions and active cab
m_distancecounter = -1.f; // turn off the meter after its task is done m_distancecounter = -1.f; // turn off the meter after its task is done
@@ -8016,21 +7972,18 @@ void TTrain::set_cab_controls( int const Cab ) {
// lights // lights
ggLightsButton.PutValue( mvOccupied->LightsPos - 1 ); ggLightsButton.PutValue( mvOccupied->LightsPos - 1 );
int const vehicleside = auto const vehicleend { cab_to_end() };
( mvOccupied->ActiveCab == 1 ?
end::front :
end::rear );
if( ( DynamicObject->iLights[ vehicleside ] & light::headlight_left ) != 0 ) { if( ( DynamicObject->iLights[ vehicleend ] & light::headlight_left ) != 0 ) {
ggLeftLightButton.PutValue( 1.f ); ggLeftLightButton.PutValue( 1.f );
} }
if( ( DynamicObject->iLights[ vehicleside ] & light::headlight_right ) != 0 ) { if( ( DynamicObject->iLights[ vehicleend ] & light::headlight_right ) != 0 ) {
ggRightLightButton.PutValue( 1.f ); ggRightLightButton.PutValue( 1.f );
} }
if( ( DynamicObject->iLights[ vehicleside ] & light::headlight_upper ) != 0 ) { if( ( DynamicObject->iLights[ vehicleend ] & light::headlight_upper ) != 0 ) {
ggUpperLightButton.PutValue( 1.f ); ggUpperLightButton.PutValue( 1.f );
} }
if( ( DynamicObject->iLights[ vehicleside ] & light::redmarker_left ) != 0 ) { if( ( DynamicObject->iLights[ vehicleend ] & light::redmarker_left ) != 0 ) {
if( ggLeftEndLightButton.SubModel != nullptr ) { if( ggLeftEndLightButton.SubModel != nullptr ) {
ggLeftEndLightButton.PutValue( 1.f ); ggLeftEndLightButton.PutValue( 1.f );
} }
@@ -8038,7 +7991,7 @@ void TTrain::set_cab_controls( int const Cab ) {
ggLeftLightButton.PutValue( -1.f ); ggLeftLightButton.PutValue( -1.f );
} }
} }
if( ( DynamicObject->iLights[ vehicleside ] & light::redmarker_right ) != 0 ) { if( ( DynamicObject->iLights[ vehicleend ] & light::redmarker_right ) != 0 ) {
if( ggRightEndLightButton.SubModel != nullptr ) { if( ggRightEndLightButton.SubModel != nullptr ) {
ggRightEndLightButton.PutValue( 1.f ); ggRightEndLightButton.PutValue( 1.f );
} }
@@ -8071,15 +8024,15 @@ void TTrain::set_cab_controls( int const Cab ) {
0.f ) ); 0.f ) );
// doors permits // doors permits
if( ggDoorLeftPermitButton.type() != TGaugeType::push ) { if( ggDoorLeftPermitButton.type() != TGaugeType::push ) {
ggDoorLeftPermitButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::left : side::right ) ].open_permit ? 1.f : 0.f ); ggDoorLeftPermitButton.PutValue( mvOccupied->Doors.instances[ ( cab_to_end() == end::front ? side::left : side::right ) ].open_permit ? 1.f : 0.f );
} }
if( ggDoorRightPermitButton.type() != TGaugeType::push ) { if( ggDoorRightPermitButton.type() != TGaugeType::push ) {
ggDoorRightPermitButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::right : side::left ) ].open_permit ? 1.f : 0.f ); ggDoorRightPermitButton.PutValue( mvOccupied->Doors.instances[ ( cab_to_end() == end::front ? side::right : side::left ) ].open_permit ? 1.f : 0.f );
} }
ggDoorPermitPresetButton.PutValue( mvOccupied->Doors.permit_preset ); ggDoorPermitPresetButton.PutValue( mvOccupied->Doors.permit_preset );
// door controls // door controls
ggDoorLeftButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::left : side::right ) ].is_closed ? 0.f : 1.f ); ggDoorLeftButton.PutValue( mvOccupied->Doors.instances[ ( cab_to_end() == end::front ? side::left : side::right ) ].is_closed ? 0.f : 1.f );
ggDoorRightButton.PutValue( mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::right : side::left ) ].is_closed ? 0.f : 1.f ); ggDoorRightButton.PutValue( mvOccupied->Doors.instances[ ( cab_to_end() == end::front ? side::right : side::left ) ].is_closed ? 0.f : 1.f );
// door lock // door lock
ggDoorSignallingButton.PutValue( ggDoorSignallingButton.PutValue(
mvOccupied->Doors.lock_enabled ? mvOccupied->Doors.lock_enabled ?
@@ -8311,8 +8264,8 @@ bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int co
} }
// TODO: move viable dedicated lights to the automatic light array // TODO: move viable dedicated lights to the automatic light array
std::unordered_map<std::string, bool const *> const autolights = { std::unordered_map<std::string, bool const *> const autolights = {
{ "i-doorpermit_left:", &mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::left : side::right ) ].open_permit }, { "i-doorpermit_left:", &mvOccupied->Doors.instances[ ( cab_to_end() == end::front ? side::left : side::right ) ].open_permit },
{ "i-doorpermit_right:", &mvOccupied->Doors.instances[ ( mvOccupied->ActiveCab == 1 ? side::right : side::left ) ].open_permit }, { "i-doorpermit_right:", &mvOccupied->Doors.instances[ ( cab_to_end() == end::front ? side::right : side::left ) ].open_permit },
{ "i-doorstep:", &mvOccupied->Doors.step_enabled } { "i-doorstep:", &mvOccupied->Doors.step_enabled }
}; };
{ {

View File

@@ -157,6 +157,12 @@ class TTrain {
void update_sounds( double const Deltatime ); void update_sounds( double const Deltatime );
void update_sounds_runningnoise( sound_source &Sound ); void update_sounds_runningnoise( sound_source &Sound );
void update_sounds_radio(); void update_sounds_radio();
inline
end cab_to_end() const {
return (
iCabn == 2 ?
end::rear :
end::front ); }
// command handlers // command handlers
// NOTE: we're currently using universal handlers and static handler map but it may be beneficial to have these implemented on individual class instance basis // NOTE: we're currently using universal handlers and static handler map but it may be beneficial to have these implemented on individual class instance basis