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

train timetable readout for python scripts, timetable ui mode enhancements, minor bug fixes

This commit is contained in:
tmj-fstate
2018-05-17 00:23:20 +02:00
parent 0787be500a
commit 45e751312a
11 changed files with 145 additions and 117 deletions

View File

@@ -5882,22 +5882,27 @@ void TController::DirectionForward(bool forward)
} }
}; };
Mtable::TTrainParameters const *
TController::TrainTimetable() const {
return TrainParams;
}
std::string TController::Relation() std::string TController::Relation()
{ // zwraca relację pociągu { // zwraca relację pociągu
return TrainParams->ShowRelation(); return TrainParams->ShowRelation();
}; };
std::string TController::TrainName() std::string TController::TrainName() const
{ // zwraca numer pociągu { // zwraca numer pociągu
return TrainParams->TrainName; return TrainParams->TrainName;
}; };
int TController::StationCount() int TController::StationCount() const
{ // zwraca ilość stacji (miejsc zatrzymania) { // zwraca ilość stacji (miejsc zatrzymania)
return TrainParams->StationCount; return TrainParams->StationCount;
}; };
int TController::StationIndex() int TController::StationIndex() const
{ // zwraca indeks aktualnej stacji (miejsca zatrzymania) { // zwraca indeks aktualnej stacji (miejsca zatrzymania)
return TrainParams->StationIndex; return TrainParams->StationIndex;
}; };

View File

@@ -314,8 +314,6 @@ private:
void AutoRewident(); // ustawia hamulce w składzie void AutoRewident(); // ustawia hamulce w składzie
double ESMVelocity(bool Main); double ESMVelocity(bool Main);
public: public:
Mtable::TTrainParameters *Timetable() {
return TrainParams; };
void PutCommand(std::string NewCommand, double NewValue1, double NewValue2, const TLocation &NewLocation, TStopReason reason = stopComm); void PutCommand(std::string NewCommand, double NewValue1, double NewValue2, const TLocation &NewLocation, TStopReason reason = stopComm);
bool PutCommand( std::string NewCommand, double NewValue1, double NewValue2, glm::dvec3 const *NewLocation, TStopReason reason = stopComm ); bool PutCommand( std::string NewCommand, double NewValue1, double NewValue2, glm::dvec3 const *NewLocation, TStopReason reason = stopComm );
void UpdateSituation(double dt); // uruchamiac przynajmniej raz na sekundę void UpdateSituation(double dt); // uruchamiac przynajmniej raz na sekundę
@@ -385,13 +383,14 @@ private:
void PhysicsLog(); void PhysicsLog();
std::string StopReasonText(); std::string StopReasonText();
~TController(); ~TController();
std::string NextStop();
void TakeControl(bool yes); void TakeControl(bool yes);
Mtable::TTrainParameters const * TrainTimetable() const;
std::string TrainName() const;
std::string Relation(); std::string Relation();
std::string TrainName(); int StationCount() const;
int StationCount(); int StationIndex() const;
int StationIndex();
bool IsStop(); bool IsStop();
std::string NextStop();
inline inline
bool Primary() const { bool Primary() const {
return ( ( iDrivigFlags & movePrimary ) != 0 ); }; return ( ( iDrivigFlags & movePrimary ) != 0 ); };

View File

@@ -6398,7 +6398,7 @@ void TMoverParameters::dizel_Heat( double const dt ) {
dizel_heat.water_aux.is_warm = ( dizel_heat.water_aux.is_warm = (
( true == dizel_heat.cooling ) ( true == dizel_heat.cooling )
|| ( ( true == Mains ) || ( ( true == Mains )
&& ( BatteryVoltage > 70 ) /* && !bezpompy && !awaria_chlodzenia && !WS10 */ && ( BatteryVoltage > ( 0.75 * NominalBatteryVoltage ) ) /* && !bezpompy && !awaria_chlodzenia && !WS10 */
&& ( dizel_heat.water_aux.config.temp_cooling > 0 ) && ( dizel_heat.water_aux.config.temp_cooling > 0 )
&& ( dizel_heat.temperatura2 > dizel_heat.water_aux.config.temp_cooling - ( dizel_heat.water_aux.is_warm ? 8 : 0 ) ) ) ); && ( dizel_heat.temperatura2 > dizel_heat.water_aux.config.temp_cooling - ( dizel_heat.water_aux.is_warm ? 8 : 0 ) ) ) );
auto const PTC2 { ( dizel_heat.water_aux.is_warm /*or PTC2p*/ ? 1 : 0 ) }; auto const PTC2 { ( dizel_heat.water_aux.is_warm /*or PTC2p*/ ? 1 : 0 ) };
@@ -6426,7 +6426,7 @@ void TMoverParameters::dizel_Heat( double const dt ) {
dizel_heat.water.is_warm = ( dizel_heat.water.is_warm = (
( true == dizel_heat.cooling ) ( true == dizel_heat.cooling )
|| ( ( true == Mains ) || ( ( true == Mains )
&& ( BatteryVoltage > 70 ) /* && !bezpompy && !awaria_chlodzenia && !WS10 */ && ( BatteryVoltage > ( 0.75 * NominalBatteryVoltage ) ) /* && !bezpompy && !awaria_chlodzenia && !WS10 */
&& ( dizel_heat.water.config.temp_cooling > 0 ) && ( dizel_heat.water.config.temp_cooling > 0 )
&& ( dizel_heat.temperatura1 > dizel_heat.water.config.temp_cooling - ( dizel_heat.water.is_warm ? 8 : 0 ) ) ) ); && ( dizel_heat.temperatura1 > dizel_heat.water.config.temp_cooling - ( dizel_heat.water.is_warm ? 8 : 0 ) ) ) );
auto const PTC1 { ( dizel_heat.water.is_warm /*or PTC1p*/ ? 1 : 0 ) }; auto const PTC1 { ( dizel_heat.water.is_warm /*or PTC1p*/ ? 1 : 0 ) };

View File

@@ -23,6 +23,7 @@ http://mozilla.org/MPL/2.0/.
#include "MdlMngr.h" #include "MdlMngr.h"
#include "Timer.h" #include "Timer.h"
#include "Driver.h" #include "Driver.h"
#include "mtable.h"
#include "Console.h" #include "Console.h"
void void
@@ -430,7 +431,7 @@ PyObject *TTrain::GetTrainState() {
auto const &mover = DynamicObject->MoverParameters; auto const &mover = DynamicObject->MoverParameters;
auto *dict = PyDict_New(); auto *dict = PyDict_New();
if( ( dict == nullptr ) if( ( dict == nullptr )
|| ( mover == nullptr ) ) { || ( mover == nullptr ) ) {
return nullptr; return nullptr;
} }
@@ -450,14 +451,14 @@ PyObject *TTrain::GetTrainState() {
PyDict_SetItemString( dict, "scnd_ctrl_actual_pos", PyGetInt( mover->ScndCtrlActualPos ) ); PyDict_SetItemString( dict, "scnd_ctrl_actual_pos", PyGetInt( mover->ScndCtrlActualPos ) );
// brakes // brakes
PyDict_SetItemString( dict, "manual_brake", PyGetBool( mvOccupied->ManualBrakePos > 0 ) ); PyDict_SetItemString( dict, "manual_brake", PyGetBool( 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 );
PyDict_SetItemString( dict, "dir_brake", PyGetBool( bEP ) ); PyDict_SetItemString( dict, "dir_brake", PyGetBool( bEP ) );
bool bPN; bool bPN;
if( ( typeid( *mvControlled->Hamulec ) == typeid( TLSt ) ) if( ( typeid( *mvControlled->Hamulec ) == typeid( TLSt ) )
|| ( typeid( *mvControlled->Hamulec ) == typeid( TEStED ) ) ) { || ( typeid( *mvControlled->Hamulec ) == typeid( TEStED ) ) ) {
TBrake* temp_ham = mvControlled->Hamulec.get(); TBrake* temp_ham = mvControlled->Hamulec.get();
bPN = ( static_cast<TLSt*>( temp_ham )->GetEDBCP()>0.2 ); bPN = ( static_cast<TLSt*>( temp_ham )->GetEDBCP() > 0.2 );
} }
else else
bPN = false; bPN = false;
@@ -472,13 +473,13 @@ PyObject *TTrain::GetTrainState() {
PyDict_SetItemString( dict, "velocity", PyGetFloat( mover->Vel ) ); PyDict_SetItemString( dict, "velocity", PyGetFloat( mover->Vel ) );
PyDict_SetItemString( dict, "tractionforce", PyGetFloat( mover->Ft ) ); PyDict_SetItemString( dict, "tractionforce", PyGetFloat( mover->Ft ) );
PyDict_SetItemString( dict, "slipping_wheels", PyGetBool( mover->SlippingWheels ) ); PyDict_SetItemString( dict, "slipping_wheels", PyGetBool( mover->SlippingWheels ) );
PyDict_SetItemString( dict, "sanding", PyGetBool( mover->SandDose )); PyDict_SetItemString( dict, "sanding", PyGetBool( mover->SandDose ) );
// electric current data // electric current data
PyDict_SetItemString( dict, "traction_voltage", PyGetFloat( mover->RunningTraction.TractionVoltage ) ); PyDict_SetItemString( dict, "traction_voltage", PyGetFloat( mover->RunningTraction.TractionVoltage ) );
PyDict_SetItemString( dict, "voltage", PyGetFloat( mover->Voltage ) ); PyDict_SetItemString( dict, "voltage", PyGetFloat( mover->Voltage ) );
PyDict_SetItemString( dict, "im", PyGetFloat( mover->Im ) ); PyDict_SetItemString( dict, "im", PyGetFloat( mover->Im ) );
PyDict_SetItemString( dict, "fuse", PyGetBool( mover->FuseFlag ) ); PyDict_SetItemString( dict, "fuse", PyGetBool( mover->FuseFlag ) );
PyDict_SetItemString( dict, "epfuse", PyGetBool( mover->EpFuse )); PyDict_SetItemString( dict, "epfuse", PyGetBool( mover->EpFuse ) );
// induction motor state data // induction motor state data
char const *TXTT[ 10 ] = { "fd", "fdt", "fdb", "pd", "pdt", "pdb", "itothv", "1", "2", "3" }; char const *TXTT[ 10 ] = { "fd", "fdt", "fdb", "pd", "pdt", "pdb", "itothv", "1", "2", "3" };
char const *TXTC[ 10 ] = { "fr", "frt", "frb", "pr", "prt", "prb", "im", "vm", "ihv", "uhv" }; char const *TXTC[ 10 ] = { "fr", "frt", "frb", "pr", "prt", "prb", "im", "vm", "ihv", "uhv" };
@@ -487,23 +488,24 @@ PyObject *TTrain::GetTrainState() {
PyDict_SetItemString( dict, ( std::string( "eimp_t_" ) + std::string( TXTT[ j ] ) ).c_str(), PyGetFloatS( fEIMParams[ 0 ][ j ] ) ); PyDict_SetItemString( dict, ( std::string( "eimp_t_" ) + std::string( TXTT[ j ] ) ).c_str(), PyGetFloatS( fEIMParams[ 0 ][ j ] ) );
for( int i = 0; i < 8; ++i ) { for( int i = 0; i < 8; ++i ) {
for( int j = 0; j < 10; ++j ) for( int j = 0; j < 10; ++j )
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_" ) + std::string( TXTC[ j ] ) ).c_str(), PyGetFloatS( fEIMParams[ i + 1 ][ j ] ) ); PyDict_SetItemString( dict, ( "eimp_c" + std::to_string( i + 1 ) + "_" + std::string( TXTC[ j ] ) ).c_str(), PyGetFloatS( fEIMParams[ i + 1 ][ j ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_ms" ) ).c_str(), PyGetBool( bMains[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_cv" ) ).c_str(), PyGetFloatS( fCntVol[ i ] ) ); PyDict_SetItemString( dict, ( "eimp_c" + std::to_string( i + 1 ) + "_ms" ).c_str(), PyGetBool( bMains[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_u" ) + std::to_string( i + 1 ) + std::string( "_pf" ) ).c_str(), PyGetBool( bPants[ i ][ 0 ] ) ); PyDict_SetItemString( dict, ( "eimp_c" + std::to_string( i + 1 ) + "_cv" ).c_str(), PyGetFloatS( fCntVol[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_u" ) + std::to_string( i + 1 ) + std::string( "_pr" ) ).c_str(), PyGetBool( bPants[ i ][ 1 ] ) ); PyDict_SetItemString( dict, ( "eimp_u" + std::to_string( i + 1 ) + "_pf" ).c_str(), PyGetBool( bPants[ i ][ 0 ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_fuse" ) ).c_str(), PyGetBool( bFuse[ i ] ) ); PyDict_SetItemString( dict, ( "eimp_u" + std::to_string( i + 1 ) + "_pr" ).c_str(), PyGetBool( bPants[ i ][ 1 ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_batt" ) ).c_str(), PyGetBool( bBatt[ i ] ) ); PyDict_SetItemString( dict, ( "eimp_c" + std::to_string( i + 1 ) + "_fuse" ).c_str(), PyGetBool( bFuse[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_conv" ) ).c_str(), PyGetBool( bConv[ i ] ) ); PyDict_SetItemString( dict, ( "eimp_c" + std::to_string( i + 1 ) + "_batt" ).c_str(), PyGetBool( bBatt[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_u" ) + std::to_string( i + 1 ) + std::string( "_comp_a" ) ).c_str(), PyGetBool( bComp[ i ][ 0 ] ) ); PyDict_SetItemString( dict, ( "eimp_c" + std::to_string( i + 1 ) + "_conv" ).c_str(), PyGetBool( bConv[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_u" ) + std::to_string( i + 1 ) + std::string( "_comp_w" ) ).c_str(), PyGetBool( bComp[ i ][ 1 ] ) ); PyDict_SetItemString( dict, ( "eimp_u" + std::to_string( i + 1 ) + "_comp_a" ).c_str(), PyGetBool( bComp[ i ][ 0 ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_heat" ) ).c_str(), PyGetBool( bHeat[ i ] ) ); PyDict_SetItemString( dict, ( "eimp_u" + std::to_string( i + 1 ) + "_comp_w" ).c_str(), PyGetBool( bComp[ i ][ 1 ] ) );
PyDict_SetItemString( dict, ( "eimp_c" + std::to_string( i + 1 ) + "_heat" ).c_str(), PyGetBool( bHeat[ i ] ) );
} }
for( int i = 0; i < 20; ++i ) { for( int i = 0; i < 20; ++i ) {
for( int j = 0; j < 3; ++j ) for( int j = 0; j < 3; ++j )
PyDict_SetItemString( dict, ( std::string( "eimp_pn" ) + std::to_string( i + 1 ) + std::string( "_" ) + std::string( TXTP[ j ] ) ).c_str(), PyDict_SetItemString( dict, ( "eimp_pn" + std::to_string( i + 1 ) + "_" + TXTP[ j ] ).c_str(),
PyGetFloatS( fPress[ i ][ j ] ) ); PyGetFloatS( fPress[ i ][ j ] ) );
} }
// multi-unit state data // multi-unit state data
PyDict_SetItemString( dict, "car_no", PyGetInt( iCarNo ) ); PyDict_SetItemString( dict, "car_no", PyGetInt( iCarNo ) );
@@ -511,17 +513,16 @@ PyObject *TTrain::GetTrainState() {
PyDict_SetItemString( dict, "unit_no", PyGetInt( iUnitNo ) ); PyDict_SetItemString( dict, "unit_no", PyGetInt( iUnitNo ) );
for( int i = 0; i < 20; i++ ) { for( int i = 0; i < 20; i++ ) {
PyDict_SetItemString( dict, ( std::string( "doors_" ) + std::to_string( i + 1 ) ).c_str(), PyGetFloatS( bDoors[ i ][ 0 ] ) ); PyDict_SetItemString( dict, ( "doors_" + std::to_string( i + 1 ) ).c_str(), PyGetFloatS( bDoors[ i ][ 0 ] ) );
PyDict_SetItemString( dict, ( std::string( "doors_r_" ) + std::to_string( i + 1 ) ).c_str(), PyGetFloatS( bDoors[ i ][ 1 ] ) ); PyDict_SetItemString( dict, ( "doors_r_" + std::to_string( i + 1 ) ).c_str(), PyGetFloatS( bDoors[ i ][ 1 ] ) );
PyDict_SetItemString( dict, ( std::string( "doors_l_" ) + std::to_string( i + 1 ) ).c_str(), PyGetFloatS( bDoors[ i ][ 2 ] ) ); PyDict_SetItemString( dict, ( "doors_l_" + std::to_string( i + 1 ) ).c_str(), PyGetFloatS( bDoors[ i ][ 2 ] ) );
PyDict_SetItemString( dict, ( std::string( "doors_no_" ) + std::to_string( i + 1 ) ).c_str(), PyGetInt( iDoorNo[ i ] ) ); PyDict_SetItemString( dict, ( "doors_no_" + std::to_string( i + 1 ) ).c_str(), PyGetInt( iDoorNo[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "code_" ) + std::to_string( i + 1 ) ).c_str(), PyGetString( std::string( std::to_string( iUnits[ i ] ) + PyDict_SetItemString( dict, ( "code_" + std::to_string( i + 1 ) ).c_str(), PyGetString( ( std::to_string( iUnits[ i ] ) + cCode[ i ] ).c_str() ) );
cCode[ i ] ).c_str() ) ); PyDict_SetItemString( dict, ( "car_name" + std::to_string( i + 1 ) ).c_str(), PyGetString( asCarName[ i ].c_str() ) );
PyDict_SetItemString( dict, ( std::string( "car_name" ) + std::to_string( i + 1 ) ).c_str(), PyGetString( asCarName[ i ].c_str() ) ); PyDict_SetItemString( dict, ( "slip_" + std::to_string( i + 1 ) ).c_str(), PyGetBool( bSlip[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "slip_" ) + std::to_string( i + 1 )).c_str(), PyGetBool( bSlip[i]) );
} }
// ai state data // ai state data
auto const &driver = DynamicObject->Mechanik; auto const *driver = DynamicObject->Mechanik;
PyDict_SetItemString( dict, "velocity_desired", PyGetFloat( driver->VelDesired ) ); PyDict_SetItemString( dict, "velocity_desired", PyGetFloat( driver->VelDesired ) );
PyDict_SetItemString( dict, "velroad", PyGetFloat( driver->VelRoad ) ); PyDict_SetItemString( dict, "velroad", PyGetFloat( driver->VelRoad ) );
@@ -530,7 +531,27 @@ PyObject *TTrain::GetTrainState() {
PyDict_SetItemString( dict, "velsignalnext", PyGetFloat( driver->VelSignalNext ) ); PyDict_SetItemString( dict, "velsignalnext", PyGetFloat( driver->VelSignalNext ) );
PyDict_SetItemString( dict, "velnext", PyGetFloat( driver->VelNext ) ); PyDict_SetItemString( dict, "velnext", PyGetFloat( driver->VelNext ) );
PyDict_SetItemString( dict, "actualproximitydist", PyGetFloat( driver->ActualProximityDist ) ); PyDict_SetItemString( dict, "actualproximitydist", PyGetFloat( driver->ActualProximityDist ) );
// train data
PyDict_SetItemString( dict, "trainnumber", PyGetString( driver->TrainName().c_str() ) ); PyDict_SetItemString( dict, "trainnumber", PyGetString( driver->TrainName().c_str() ) );
PyDict_SetItemString( dict, "train_stationindex", PyGetInt( driver->StationIndex() ) );
auto const stationcount { driver->StationCount() };
PyDict_SetItemString( dict, "train_stationcount", PyGetInt( stationcount ) );
if( stationcount > 0 ) {
// timetable stations data, if there's any
auto const *timetable { driver->TrainTimetable() };
for( auto stationidx = 1; stationidx <= stationcount; ++stationidx ) {
auto const stationlabel { "train_station" + std::to_string( stationidx ) + "_" };
auto const &timetableline { timetable->TimeTable[ stationidx ] };
PyDict_SetItemString( dict, ( stationlabel + "name" ).c_str(), PyGetString( Bezogonkow( timetableline.StationName ).c_str() ) );
PyDict_SetItemString( dict, ( stationlabel + "fclt" ).c_str(), PyGetString( Bezogonkow( timetableline.StationWare ).c_str() ) );
PyDict_SetItemString( dict, ( stationlabel + "lctn" ).c_str(), PyGetFloat( timetableline.km ) );
PyDict_SetItemString( dict, ( stationlabel + "vmax" ).c_str(), PyGetInt( timetableline.vmax ) );
PyDict_SetItemString( dict, ( stationlabel + "ah" ).c_str(), PyGetInt( timetableline.Ah ) );
PyDict_SetItemString( dict, ( stationlabel + "am" ).c_str(), PyGetInt( timetableline.Am ) );
PyDict_SetItemString( dict, ( stationlabel + "dh" ).c_str(), PyGetInt( timetableline.Dh ) );
PyDict_SetItemString( dict, ( stationlabel + "dm" ).c_str(), PyGetInt( timetableline.Dm ) );
}
}
// world state data // world state data
PyDict_SetItemString( dict, "hours", PyGetInt( simulation::Time.data().wHour ) ); PyDict_SetItemString( dict, "hours", PyGetInt( simulation::Time.data().wHour ) );
PyDict_SetItemString( dict, "minutes", PyGetInt( simulation::Time.data().wMinute ) ); PyDict_SetItemString( dict, "minutes", PyGetInt( simulation::Time.data().wMinute ) );

View File

@@ -201,7 +201,7 @@ WyslijObsadzone()
r.fPar[ 16 * i + 6 ] = vehicle->GetPosition().z; r.fPar[ 16 * i + 6 ] = vehicle->GetPosition().z;
r.iPar[ 16 * i + 7 ] = vehicle->Mechanik->GetAction(); r.iPar[ 16 * i + 7 ] = vehicle->Mechanik->GetAction();
strcpy( r.cString + 64 * i + 32, vehicle->GetTrack()->IsolatedName().c_str() ); strcpy( r.cString + 64 * i + 32, vehicle->GetTrack()->IsolatedName().c_str() );
strcpy( r.cString + 64 * i + 48, vehicle->Mechanik->Timetable()->TrainName.c_str() ); strcpy( r.cString + 64 * i + 48, vehicle->Mechanik->TrainName().c_str() );
i++; i++;
if( i > 30 ) break; if( i > 30 ) break;
} }

View File

@@ -14,26 +14,6 @@ http://mozilla.org/MPL/2.0/.
#include "world.h" #include "world.h"
#include "utilities.h" #include "utilities.h"
double CompareTime(double t1h, double t1m, double t2h, double t2m) /*roznica czasu w minutach*/
// zwraca różnicę czasu
// jeśli pierwsza jest aktualna, a druga rozkładowa, to ujemna oznacza opóżnienie
// na dłuższą metę trzeba uwzględnić datę, jakby opóżnienia miały przekraczać 12h (towarowych)
{
double t;
if ((t2h < 0))
return 0;
else
{
t = (t2h - t1h) * 60 + t2m - t1m; // jeśli t2=00:05, a t1=23:50, to różnica wyjdzie ujemna
if ((t < -720)) // jeśli różnica przekracza 12h na minus
t = t + 1440; // to dodanie doby minut;else
if ((t > 720)) // jeśli przekracza 12h na plus
t = t - 1440; // to odjęcie doby minut
return t;
}
}
double TTrainParameters::CheckTrainLatency() double TTrainParameters::CheckTrainLatency()
{ {
if ((LastStationLatency > 1.0) || (LastStationLatency < 0)) if ((LastStationLatency > 1.0) || (LastStationLatency < 0))
@@ -178,18 +158,7 @@ void TTrainParameters::NewName(std::string const &NewTrainName)
Relation2 = ""; Relation2 = "";
for (int i = 0; i < MaxTTableSize + 1; ++i) for (int i = 0; i < MaxTTableSize + 1; ++i)
{ {
TMTableLine *t = &TimeTable[i]; TimeTable[ i ] = TMTableLine();
t->km = 0;
t->vmax = -1;
t->StationName = "nowhere";
t->StationWare = "";
t->TrackNo = 1;
t->Ah = -1;
t->Am = -1;
t->Dh = -1;
t->Dm = -1;
t->tm = 0;
t->WaitTime = 0;
} }
TTVmax = 100; /*wykasowac*/ TTVmax = 100; /*wykasowac*/
BrakeRatio = 0; BrakeRatio = 0;
@@ -387,15 +356,12 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
{ {
if (s.find(hrsd) != std::string::npos) if (s.find(hrsd) != std::string::npos)
{ {
record->Ah = atoi( record->Ah = atoi( s.substr(0, s.find(hrsd)).c_str()); // godzina przyjazdu
s.substr(0, s.find(hrsd)).c_str()); // godzina przyjazdu record->Am = atoi(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta przyjazdu
record->Am = atoi(s.substr(s.find(hrsd) + 1, s.length())
.c_str()); // minuta przyjazdu
} }
else else
{ {
record->Ah = TimeTable[StationCount - 1] record->Ah = TimeTable[StationCount - 1].Ah; // godzina z poprzedniej pozycji
.Ah; // godzina z poprzedniej pozycji
record->Am = atoi(s.c_str()); // bo tylko minuty podane record->Am = atoi(s.c_str()); // bo tylko minuty podane
} }
} }
@@ -440,29 +406,20 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
{ {
if (s.find(hrsd) != std::string::npos) if (s.find(hrsd) != std::string::npos)
{ {
record->Dh = record->Dh = atoi(s.substr(0, s.find(hrsd)).c_str()); // godzina odjazdu
atoi(s.substr(0, s.find(hrsd)).c_str()); // godzina odjazdu record->Dm = atoi(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta odjazdu
record->Dm = atoi(s.substr(s.find(hrsd) + 1, s.length())
.c_str()); // minuta odjazdu
} }
else else
{ {
record->Dh = TimeTable[StationCount - 1] record->Dh = TimeTable[StationCount - 1].Dh; // godzina z poprzedniej pozycji
.Dh; // godzina z poprzedniej pozycji
record->Dm = atoi(s.c_str()); // bo tylko minuty podane record->Dm = atoi(s.c_str()); // bo tylko minuty podane
} }
} }
else else
{ {
record->Dh = record->Ah; // odjazd o tej samej, co przyjazd (dla record->Dh = record->Ah; // odjazd o tej samej, co przyjazd (dla ostatniego też)
// ostatniego też) record->Dm = record->Am; // bo są używane do wyliczenia opóźnienia po dojechaniu
record->Dm = record->Am; // bo są używane do wyliczenia opóźnienia
// po dojechaniu
} }
if ((record->Ah >= 0))
record->WaitTime = (int)(CompareTime(record->Ah, record->Am,
record->Dh, record->Dm) +
0.1);
do do
{ {
fin >> s; fin >> s;

View File

@@ -36,15 +36,14 @@ struct TMTableLine
int Dh; int Dh;
int Dm; // godz. i min. odjazdu int Dm; // godz. i min. odjazdu
double tm; // czas jazdy do tej stacji w min. (z kolumny) double tm; // czas jazdy do tej stacji w min. (z kolumny)
int WaitTime; // czas postoju (liczony plus 6 sekund)
TMTableLine() TMTableLine()
{ {
km = 0; km = 0;
vmax = -1; vmax = -1;
StationName = "nowhere", StationWare = ""; StationName = "nowhere", StationWare = "";
TrackNo = 1; TrackNo = 1;
Ah, Am, Dh, Dm = -1; Ah = Am = Dh = Dm = -1;
WaitTime, tm = 0; tm = 0;
} }
}; };

View File

@@ -323,7 +323,7 @@ ui_layer::update() {
vehicle->ctOwner ); vehicle->ctOwner );
if( owner == nullptr ){ break; } if( owner == nullptr ){ break; }
auto const table = owner->Timetable(); auto const *table = owner->TrainTimetable();
if( table == nullptr ) { break; } if( table == nullptr ) { break; }
auto const &time = simulation::Time.data(); auto const &time = simulation::Time.data();
@@ -336,7 +336,7 @@ ui_layer::update() {
uitextline1 += " (paused)"; uitextline1 += " (paused)";
} }
uitextline2 = Bezogonkow( owner->Relation(), true ) + " (" + Bezogonkow( owner->Timetable()->TrainName, true ) + ")"; uitextline2 = Bezogonkow( owner->Relation(), true ) + " (" + Bezogonkow( owner->TrainName(), true ) + ")";
auto const nextstation = Bezogonkow( owner->NextStop(), true ); auto const nextstation = Bezogonkow( owner->NextStop(), true );
if( !nextstation.empty() ) { if( !nextstation.empty() ) {
// jeśli jest podana relacja, to dodajemy punkt następnego zatrzymania // jeśli jest podana relacja, to dodajemy punkt następnego zatrzymania
@@ -351,37 +351,62 @@ ui_layer::update() {
} }
else { else {
// header // header
UITable->text_lines.emplace_back( "+----------------------------+-------+-------+-----+", Global.UITextColor ); UITable->text_lines.emplace_back( "+-----+------------------------------------+-------+-----+", Global.UITextColor );
TMTableLine *tableline; TMTableLine const *tableline;
for( int i = owner->iStationStart; i <= std::min( owner->iStationStart + 15, table->StationCount ); ++i ) { for( int i = owner->iStationStart; i <= std::min( owner->iStationStart + 10, table->StationCount ); ++i ) {
// wyświetlenie pozycji z rozkładu // wyświetlenie pozycji z rozkładu
tableline = table->TimeTable + i; // linijka rozkładu tableline = table->TimeTable + i; // linijka rozkładu
std::string station =
( tableline->StationName + " " ).substr( 0, 26 );
std::string arrival =
( tableline->Ah >= 0 ?
to_string( int( 100 + tableline->Ah ) ).substr( 1, 2 ) + ":" + to_string( int( 100 + tableline->Am ) ).substr( 1, 2 ) :
" " );
std::string departure =
( tableline->Dh >= 0 ?
to_string( int( 100 + tableline->Dh ) ).substr( 1, 2 ) + ":" + to_string( int( 100 + tableline->Dm ) ).substr( 1, 2 ) :
" " );
std::string vmax = std::string vmax =
" " " "
+ to_string( tableline->vmax, 0 ); + to_string( tableline->vmax, 0 );
vmax = vmax.substr( vmax.length() - 3, 3 ); // z wyrównaniem do prawej vmax = vmax.substr( vmax.size() - 3, 3 ); // z wyrównaniem do prawej
std::string const station = (
Bezogonkow( tableline->StationName, true )
+ " " )
.substr( 0, 34 );
std::string const location = (
( tableline->km > 0.0 ?
to_string( tableline->km, 2 ) :
"" )
+ " " )
.substr( 0, 34 - tableline->StationWare.size() );
std::string const arrival = (
tableline->Ah >= 0 ?
to_string( int( 100 + tableline->Ah ) ).substr( 1, 2 ) + ":" + to_string( int( 100 + tableline->Am ) ).substr( 1, 2 ) :
" | " );
std::string const departure = (
tableline->Dh >= 0 ?
to_string( int( 100 + tableline->Dh ) ).substr( 1, 2 ) + ":" + to_string( int( 100 + tableline->Dm ) ).substr( 1, 2 ) :
" | " );
auto const candeparture = (
( owner->iStationStart < table->StationIndex )
&& ( i < table->StationIndex )
&& ( ( time.wHour * 60 + time.wMinute ) >= ( tableline->Dh * 60 + tableline->Dm ) ) );
auto traveltime =
" "
+ ( i < 2 ? "" :
tableline->Ah >= 0 ? to_string( CompareTime( table->TimeTable[ i - 1 ].Dh, table->TimeTable[ i - 1 ].Dm, tableline->Ah, tableline->Am ), 0 ) :
to_string( std::max( 0.0, CompareTime( table->TimeTable[ i - 1 ].Dh, table->TimeTable[ i - 1 ].Dm, tableline->Dh, tableline->Dm ) - 0.5 ), 0 ) );
traveltime = traveltime.substr( traveltime.size() - 3, 3 ); // z wyrównaniem do prawej
UITable->text_lines.emplace_back( UITable->text_lines.emplace_back(
Bezogonkow( "| " + station + " | " + arrival + " | " + departure + " | " + vmax + " | " + tableline->StationWare, true ), ( "| " + vmax + " | " + station + " | " + arrival + " | " + traveltime + " |" ),
( ( owner->iStationStart < table->StationIndex ) ( candeparture ?
&& ( i < table->StationIndex ) glm::vec4( 0.0f, 1.0f, 0.0f, 1.0f ) :// czas minął i odjazd był, to nazwa stacji będzie na zielono
&& ( ( time.wHour * 60 + time.wMinute ) >= ( tableline->Dh * 60 + tableline->Dm ) ) ? Global.UITextColor ) );
UITable->text_lines.emplace_back(
( "| | " + location + tableline->StationWare + " | " + departure + " | |" ),
( candeparture ?
glm::vec4( 0.0f, 1.0f, 0.0f, 1.0f ) :// czas minął i odjazd był, to nazwa stacji będzie na zielono glm::vec4( 0.0f, 1.0f, 0.0f, 1.0f ) :// czas minął i odjazd był, to nazwa stacji będzie na zielono
Global.UITextColor ) ); Global.UITextColor ) );
// divider/footer // divider/footer
UITable->text_lines.emplace_back( "+----------------------------+-------+-------+-----+", Global.UITextColor ); UITable->text_lines.emplace_back( "+-----+------------------------------------+-------+-----+", Global.UITextColor );
}
if( owner->iStationStart + 10 < table->StationCount ) {
// if we can't display entire timetable, add a scrolling indicator at the bottom
UITable->text_lines.emplace_back( " ... ", Global.UITextColor );
} }
} }
} }

View File

@@ -58,6 +58,26 @@ std::string Now() {
return converter.str(); return converter.str();
} }
// zwraca różnicę czasu
// jeśli pierwsza jest aktualna, a druga rozkładowa, to ujemna oznacza opóżnienie
// na dłuższą metę trzeba uwzględnić datę, jakby opóżnienia miały przekraczać 12h (towarowych)
double CompareTime(double t1h, double t1m, double t2h, double t2m) {
double t;
if ((t2h < 0))
return 0;
else
{
t = (t2h - t1h) * 60 + t2m - t1m; // jeśli t2=00:05, a t1=23:50, to różnica wyjdzie ujemna
if ((t < -720)) // jeśli różnica przekracza 12h na minus
t = t + 1440; // to dodanie doby minut;else
if ((t > 720)) // jeśli przekracza 12h na plus
t = t - 1440; // to odjęcie doby minut
return t;
}
}
bool SetFlag( int &Flag, int const Value ) { bool SetFlag( int &Flag, int const Value ) {
if( Value > 0 ) { if( Value > 0 ) {

View File

@@ -78,6 +78,8 @@ inline double BorlandTime()
std::string Now(); std::string Now();
double CompareTime( double t1h, double t1m, double t2h, double t2m );
/*funkcje logiczne*/ /*funkcje logiczne*/
inline bool TestFlag( int const Flag, int const Value ) { return ( ( Flag & Value ) == Value ); } inline bool TestFlag( int const Flag, int const Value ) { return ( ( Flag & Value ) == Value ); }
bool SetFlag( int &Flag, int const Value); bool SetFlag( int &Flag, int const Value);

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#define VERSION_MAJOR 18 #define VERSION_MAJOR 18
#define VERSION_MINOR 515 #define VERSION_MINOR 516
#define VERSION_REVISION 0 #define VERSION_REVISION 0