mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 17:46:48 +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.
295 lines
11 KiB
C++
295 lines
11 KiB
C++
/*
|
|
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/.
|
|
*/
|
|
/*
|
|
MaSzyna EU07 locomotive simulator
|
|
Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
|
|
|
|
*/
|
|
|
|
// the doors, the stops and the departure
|
|
|
|
#include "stdafx.h"
|
|
#include "vehicle/Driver.h"
|
|
#include "physics/vehicle.h"
|
|
#include "utilities/Globals.h"
|
|
#include "utilities/translation.h"
|
|
#include "utilities/Logs.h"
|
|
#include "utilities/physicslog.h"
|
|
#include "vehicle/Train.h"
|
|
#include "vehicle/brakereleaser.h"
|
|
#include "vehicle/brakesetting.h"
|
|
#include "vehicle/brakingcurve.h"
|
|
#include "vehicle/fieldshunting.h"
|
|
#include "vehicle/handover.h"
|
|
#include "vehicle/signalpassing.h"
|
|
#include "vehicle/timetableservice.h"
|
|
#include "world/mtable.h"
|
|
#include "world/stationnames.h"
|
|
#include "vehicle/DynObj.h"
|
|
#include "world/Event.h"
|
|
#include "world/MemCell.h"
|
|
#include "world/RoadOrder.h"
|
|
#include "simulation/simulation.h"
|
|
#include "simulation/blackboxrecorder.h"
|
|
#include "simulation/simulationtime.h"
|
|
#include "simulation/simulationtest.h"
|
|
#include "world/Track.h"
|
|
#include "world/station.h"
|
|
#include "input/keyboardinput.h"
|
|
#include <algorithm>
|
|
#include <format>
|
|
#include <ranges>
|
|
#include "vehicle/ai/internal.h"
|
|
|
|
|
|
// otwieranie/zamykanie drzwi w składzie albo (tylko AI) EZT
|
|
void TController::Doors( bool const Open, int const Side ) {
|
|
// otwieranie drzwi
|
|
if( true == Open ) {
|
|
|
|
auto const lewe = pVehicle->DirectionGet() > 0 ? 1 : 2;
|
|
auto const prawe = 3 - lewe;
|
|
// doorsteps as the timetable asks, before the doors open (eu07/maszyna#95)
|
|
if( auto const doorstep { timetable::doorstep( m_stopflags ) };
|
|
doorstep.has_value() && occupied->Doors.step_enabled != *doorstep ) {
|
|
cue_action( *doorstep ? driver_hint::doorstepon : driver_hint::doorstepoff );
|
|
}
|
|
// grant door control permission if it's not automatic
|
|
// TBD: stricter requirements?
|
|
if( true == pVehicle->physics->Doors.permit_needed ) {
|
|
if( Side & prawe ) {
|
|
cue_action( driver_hint::doorrightpermiton );
|
|
}
|
|
if( Side & lewe ) {
|
|
cue_action( driver_hint::doorleftpermiton );
|
|
}
|
|
}
|
|
// consist-wide remote signals to open doors doors
|
|
// NOTE: mixed controls are left up to passengers to open doors by themselves, unless the timetable has
|
|
// the driver open all the doors
|
|
if( true == timetable::opens_doors( *pVehicle->physics, m_stopflags ) ) {
|
|
if( Side & prawe ) {
|
|
cue_action( driver_hint::doorrightopen );
|
|
}
|
|
if( Side & lewe ) {
|
|
cue_action( driver_hint::doorleftopen );
|
|
}
|
|
}
|
|
}
|
|
// zamykanie drzwi
|
|
else {
|
|
// if the doors are already closed and locked then there's nothing to do
|
|
if( false == doors_permit_active()
|
|
&& false == doors_open() ) {
|
|
drivingFlags.doorOpened = false;
|
|
drivingFlags.departureWarned = false;
|
|
return;
|
|
}
|
|
|
|
if (occupied->Doors.has_warning && !drivingFlags.departureWarned)
|
|
{
|
|
if (!occupied->DepartureSignal)
|
|
{
|
|
// Not warned yet, not warning yet - start the warning signal.
|
|
cue_action( driver_hint::departuresignalon ); // załącenie bzyczka
|
|
fActionTime = Random( -0.8, -0.3 ); // 0.3-0.8 second buzzer
|
|
return;
|
|
}
|
|
// Not warned yet, warning now - stop the warning signal and mark it as done.
|
|
cue_action( driver_hint::departuresignaloff );
|
|
fActionTime = Random( -0.2, 0.0 ); // Wait just a bit more before departing
|
|
drivingFlags.departureWarned = true;
|
|
return;
|
|
}
|
|
|
|
if( true == doors_open() && (pVehicle->physics->Doors.close_control == control_t::conductor || pVehicle->physics->Doors.close_control == control_t::driver ||
|
|
pVehicle->physics->Doors.close_control == control_t::mixed) ) {
|
|
// consist-wide remote signals to close doors
|
|
cue_action(driver_hint::doorrightclose);
|
|
cue_action(driver_hint::doorleftclose);
|
|
}
|
|
if( true == doors_permit_active() ) {
|
|
cue_action( driver_hint::doorrightpermitoff );
|
|
cue_action( driver_hint::doorleftpermitoff );
|
|
}
|
|
// if applicable close manually-operated doors in vehicles which may ignore remote signals
|
|
{
|
|
const auto *vehicle = pVehicles[ VehicleEnd::front ]; // pojazd na czole składu
|
|
while( vehicle != nullptr ) {
|
|
// zamykanie drzwi w pojazdach - flaga zezwolenia była by lepsza
|
|
auto const ismanualdoor {
|
|
vehicle->physics->Doors.auto_velocity == -1.f
|
|
&& ( vehicle->physics->Doors.close_control == control_t::passenger
|
|
|| vehicle->physics->Doors.close_control == control_t::mixed ) };
|
|
|
|
if( true == ismanualdoor
|
|
&& ( vehicle->LoadExchangeTime() == 0.f
|
|
|| vehicle->physics->Vel > EU07_AI_MOVEMENT ) ) {
|
|
vehicle->physics->OperateDoors( VehicleSide::right, false, range_t::local );
|
|
vehicle->physics->OperateDoors( VehicleSide::left, false, range_t::local );
|
|
}
|
|
vehicle = vehicle->Next(); // pojazd podłączony z tyłu (patrząc od czoła)
|
|
}
|
|
}
|
|
fActionTime = Random(-3.5, -1.0); // 1.0-3.5 sec wait
|
|
drivingFlags.doorOpened = false; // zostały zamknięte - nie wykonywać drugi raz
|
|
drivingFlags.departureWarned = false;
|
|
}
|
|
}
|
|
|
|
// returns true if any vehicle in the consist has open doors
|
|
bool
|
|
TController::doors_open() const {
|
|
|
|
return IsAnyDoorOpen[VehicleSide::right] || IsAnyDoorOpen[VehicleSide::left];
|
|
}
|
|
|
|
bool
|
|
TController::doors_permit_active() const {
|
|
|
|
return IsAnyDoorPermitActive[VehicleSide::right] || IsAnyDoorPermitActive[VehicleSide::left];
|
|
}
|
|
|
|
void
|
|
TController::announce( announcement_t const Announcement ) {
|
|
|
|
m_lastannouncement = Announcement;
|
|
|
|
if( IsCargoTrain ) {
|
|
// cargo trains aren't likely to have announcement systems, so we can skip the procedure altogether
|
|
return;
|
|
}
|
|
|
|
auto *vehicle { pVehicles[ VehicleEnd::front ] };
|
|
while( vehicle ) {
|
|
vehicle->announce( Announcement );
|
|
vehicle = vehicle->Next();
|
|
}
|
|
}
|
|
|
|
void
|
|
TController::control_doors() {
|
|
|
|
if( false == doors_open() ) { return; }
|
|
// jeżeli jedzie
|
|
// nie zamykać drzwi przy drganiach, bo zatrzymanie na W4 akceptuje niewielkie prędkości
|
|
if( occupied->Vel > EU07_AI_MOVEMENT ) {
|
|
Doors( false );
|
|
return;
|
|
}
|
|
// HACK: crude way to deal with automatic door opening on W4 preventing further ride
|
|
// for human-controlled vehicles with no door control and dynamic brake auto-activating with door open
|
|
// TODO: check if this situation still happens and the hack is still needed
|
|
if( false == AIControllFlag && (mvControlling->EngineType == TEngineType::DieselEngine ? mvControlling->RList[mvControlling->MainCtrlPos].Mn > 0 : mvControlling->MainCtrlPowerPos() > 0) ) {
|
|
// for diesel engines react when engine is put past idle revolutions
|
|
// for others straightforward master controller check
|
|
Doors(false);
|
|
return;
|
|
}
|
|
}
|
|
|
|
void
|
|
TController::check_departure() {
|
|
|
|
if(false == OrderCurrentGet().HasAny( DriverOrder::shunt | DriverOrder::looseShunt | DriverOrder::obeyTrain | DriverOrder::bank | DriverOrder::connect ) ) { return; }
|
|
// odjechać sam może tylko jeśli jest w trybie jazdy
|
|
// automatyczne ruszanie po odstaniu albo spod SBL
|
|
if( VelSignal == 0.0
|
|
&& WaitingTime > 0.0
|
|
&& occupied->RunningTrack.Velmax != 0.0 ) {
|
|
// jeśli stoi, a upłynął czas oczekiwania i tor ma niezerową prędkość
|
|
if( OrderCurrentGet() & (DriverOrder::shunt | DriverOrder::looseShunt | DriverOrder::obeyTrain | DriverOrder::bank)
|
|
&& drivingFlags.stopHere ) {
|
|
// zakaz ruszania z miejsca bez otrzymania wolnej drogi
|
|
WaitingTime = -WaitingExpireTime;
|
|
}
|
|
else {
|
|
if( occupied->CategoryFlag & 1 ) { // jeśli pociąg
|
|
PrepareDirection(); // zmieni ustawiony kierunek
|
|
SetVelocity( 20, 20 ); // jak się nastał, to niech jedzie 20km/h
|
|
WaitingTime = 0.0;
|
|
fWarningDuration = 1.5; // a zatrąbić trochę
|
|
}
|
|
else { // samochód ma stać, aż dostanie odjazd, chyba że stoi przez kolizję
|
|
if( eStopReason == stopBlock
|
|
&& Obstacle.distance > fDriverDist ) {
|
|
PrepareDirection(); // zmieni ustawiony kierunek
|
|
SetVelocity( -1, -1 ); // jak się nastał, to niech jedzie
|
|
WaitingTime = 0.0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if( VelSignal == 0.0 && VelNext > 0.0 && occupied->Vel < 1.0 && (false == iCoupler.Empty() || ( false == drivingFlags.stopHere )) ) {
|
|
// Ra: tu jest coś nie tak, bo bez tego warunku ruszało w manewrowym !!!!
|
|
SetVelocity(VelNext, VelNext, stopSem); // omijanie SBL
|
|
}
|
|
}
|
|
|
|
// verify progress of load exchange
|
|
void
|
|
TController::check_load_exchange() {
|
|
|
|
ExchangeTime = 0.f;
|
|
DoesAnyDoorNeedOpening = false;
|
|
|
|
if( fStopTime > 0 ) { return; }
|
|
|
|
// czas postoju przed dalszą jazdą (np. na przystanku)
|
|
auto *vehicle { pVehicles[ VehicleEnd::front ] };
|
|
while( vehicle != nullptr ) {
|
|
auto const vehicleexchangetime { vehicle->LoadExchangeTime() };
|
|
DoesAnyDoorNeedOpening |= vehicleexchangetime > 0 && vehicle->LoadExchangeSpeed() == 0;
|
|
ExchangeTime = std::max( ExchangeTime, vehicleexchangetime );
|
|
vehicle = vehicle->Next();
|
|
}
|
|
|
|
if( pVehicle->DirectionGet() != m_lastexchangedirection ) {
|
|
// generally means the ai driver moved to the opposite end of the consist
|
|
// TODO: investigate whether user playing with the reverser can mess this up
|
|
auto const left { m_lastexchangedirection > 0 ? 1 : 2 };
|
|
auto const right { 3 - left };
|
|
m_lastexchangeplatforms =
|
|
( ( m_lastexchangeplatforms & left ) != 0 ? right : 0 )
|
|
+ ( ( m_lastexchangeplatforms & right ) != 0 ? left : 0 );
|
|
m_lastexchangedirection = pVehicle->DirectionGet();
|
|
}
|
|
if( false == TrainParams.IsMaintenance()
|
|
&& ( false == drivingFlags.doorOpened
|
|
|| true == DoesAnyDoorNeedOpening ) ) {
|
|
drivingFlags.doorOpened = true; // nie wykonywać drugi raz
|
|
remove_hint( driver_hint::doorleftopen );
|
|
remove_hint( driver_hint::doorrightopen );
|
|
Doors( true, m_lastexchangeplatforms );
|
|
}
|
|
}
|
|
|
|
void
|
|
TController::GuardOpenDoor() {
|
|
if (drivingFlags.guardOpenDoor) {
|
|
auto *vehicle{ pVehicles[VehicleEnd::front] };
|
|
while (vehicle != nullptr && vehicle->physics->Doors.range == 0) {
|
|
vehicle = vehicle->Next();
|
|
}
|
|
if (vehicle != nullptr && vehicle->physics->Doors.range > 0) {
|
|
auto const lewe = vehicle->DirectionGet() > 0 ? 1 : 2;
|
|
auto const prawe = 3 - lewe;
|
|
if (m_lastexchangeplatforms & lewe) {
|
|
vehicle->physics->OperateDoors(VehicleSide::left, true, range_t::local);
|
|
}
|
|
if (m_lastexchangeplatforms & prawe) {
|
|
vehicle->physics->OperateDoors(VehicleSide::right, true, range_t::local);
|
|
}
|
|
}
|
|
else {
|
|
drivingFlags.guardOpenDoor = false;
|
|
}
|
|
}
|
|
}
|