From 138b793f5a19435639dedb1ed348bfc2a710cfd5 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Sun, 26 Jul 2020 13:49:25 +0200 Subject: [PATCH] radio channel selection tweak, minor bug fixes --- Driver.cpp | 6 ++++-- Event.cpp | 14 +++++++++++++- Event.h | 2 ++ audio.cpp | 8 ++++---- driveruipanels.cpp | 4 ++-- gamepadinput.cpp | 4 ++-- ladderlogic.cpp | 4 ++-- mtable.cpp | 15 +++++++++++++-- sound.h | 2 +- translation.cpp | 4 ++-- utilities.cpp | 2 +- utilities.h | 2 +- 12 files changed, 47 insertions(+), 20 deletions(-) diff --git a/Driver.cpp b/Driver.cpp index 186ec9fb..5bd91336 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -4601,10 +4601,12 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N // wybór kanału radiowego (którego powinien używać AI, ręczny maszynista musi go ustawić sam) if (NewValue1 >= 0) { // wartości ujemne są zarezerwowane, -1 = nie zmieniać kanału - iRadioChannel = NewValue1; + if( AIControllFlag ) { + iRadioChannel = NewValue1; + } if( iGuardRadio ) { // kierownikowi też zmienić - iGuardRadio = iRadioChannel; + iGuardRadio = NewValue1; } } // NewValue2 może zawierać dodatkowo oczekiwany kod odpowiedzi, np. dla W29 "nawiązać diff --git a/Event.cpp b/Event.cpp index da9529a7..f7221d29 100644 --- a/Event.cpp +++ b/Event.cpp @@ -730,7 +730,8 @@ putvalues_event::run_() { m_input.data_value_2, loc ); } - else if( m_activator->ctOwner ) { + else if( ( m_activator->ctOwner ) + && ( is_command_for_owner( m_input ) ) ) { // send the command to consist owner, // we're acting on presumption there's hardly ever need to issue command to unmanned vehicle // and the intended recipient moved between vehicles after the event was queued @@ -765,6 +766,17 @@ putvalues_event::export_as_text_( std::ostream &Output ) const { << m_input.data_value_2 << ' '; } +//determines whether provided input should be passed to consist owner +bool +putvalues_event::is_command_for_owner( input_data const &Input ) const { + + if( Input.data_text.rfind( "Load=", 0 ) == std::string::npos ) { return false; } + if( Input.data_text.rfind( "UnLoad=", 0 ) == std::string::npos ) { return false; } + // TBD, TODO: add other exceptions + + return true; +} + // input data access std::string putvalues_event::input_text() const { diff --git a/Event.h b/Event.h index a1db76f7..40066f10 100644 --- a/Event.h +++ b/Event.h @@ -271,6 +271,8 @@ private: void run_() override; // export_as_text() subclass details void export_as_text_( std::ostream &Output ) const override; + //determines whether provided input should be passed to consist owner + bool is_command_for_owner( input_data const &Input ) const; }; diff --git a/audio.cpp b/audio.cpp index 609bcbf2..24e5b9ad 100644 --- a/audio.cpp +++ b/audio.cpp @@ -48,7 +48,7 @@ openal_buffer::openal_buffer( std::string const &Filename ) : } } else { - ErrorLog( "Bad file: failed do load audio file \"" + Filename + "\"", logtype::file ); + ErrorLog( "Bad file: failed to load audio file \"" + Filename + "\"", logtype::file ); } // we're done with the disk data drwav_close( file ); @@ -70,7 +70,7 @@ openal_buffer::openal_buffer( std::string const &Filename ) : } } else { - ErrorLog( "Bad file: failed do load audio file \"" + Filename + "\"", logtype::file ); + ErrorLog( "Bad file: failed to load audio file \"" + Filename + "\"", logtype::file ); } // we're done with the disk data drflac_close( file ); @@ -92,7 +92,7 @@ openal_buffer::openal_buffer( std::string const &Filename ) : } } else { - ErrorLog( "Bad file: failed do load audio file \"" + Filename + "\"", logtype::file ); + ErrorLog( "Bad file: failed to load audio file \"" + Filename + "\"", logtype::file ); } } @@ -194,7 +194,7 @@ buffer_manager::create( std::string const &Filename ) { return emplace( filelookup ); } // if we still didn't find anything, give up - ErrorLog( "Bad file: failed do locate audio file \"" + Filename + "\"", logtype::file ); + ErrorLog( "Bad file: failed to locate audio file \"" + Filename + "\"", logtype::file ); return null_handle; } diff --git a/driveruipanels.cpp b/driveruipanels.cpp index 2e37fa11..e5756a79 100644 --- a/driveruipanels.cpp +++ b/driveruipanels.cpp @@ -383,7 +383,7 @@ timetable_panel::update() { tableline->Dh >= 0 ? to_string( int( 100 + tableline->Dh ) ).substr( 1, 2 ) + ":" + to_minutes_str( tableline->Dm, true, 3 ) : u8" │ " ) }; - auto const candeparture { ( + auto const candepart { ( ( owner->iStationStart < table.StationIndex ) && ( i < table.StationIndex ) && ( ( tableline->Ah < 0 ) // pass-through, always valid @@ -398,7 +398,7 @@ timetable_panel::update() { auto const linecolor { ( ( i != owner->iStationStart ) ? Global.UITextColor : loadchangeinprogress ? loadingcolor : - candeparture ? readycolor : // czas minął i odjazd był, to nazwa stacji będzie na zielono + candepart ? readycolor : // czas minął i odjazd był, to nazwa stacji będzie na zielono isatpassengerstop ? waitcolor : Global.UITextColor ) }; auto const trackcount{ ( tableline->TrackNo == 1 ? u8" ┃ " : u8" ║ " ) }; diff --git a/gamepadinput.cpp b/gamepadinput.cpp index 012bb33e..d520292f 100644 --- a/gamepadinput.cpp +++ b/gamepadinput.cpp @@ -184,7 +184,7 @@ gamepad_input::recall_bindings() { std::string bindingpoint {}; entryparser >> bindingpoint; - auto const splitbindingpoint { split_index( bindingpoint ) }; + auto const splitbindingpoint { split_string_and_number( bindingpoint ) }; if( splitbindingpoint.first == "axis" ) { // one or more sets of: [modeIDX] input type, parameters @@ -204,7 +204,7 @@ gamepad_input::recall_bindings() { std::string key {}; entryparser >> key; // check for potential mode indicator - auto const splitkey { split_index( key ) }; + auto const splitkey { split_string_and_number( key ) }; if( splitkey.first == "mode" ) { // indicate we'll be processing specified mode controlmode = splitkey.second; diff --git a/ladderlogic.cpp b/ladderlogic.cpp index 8c31567d..d2196db5 100644 --- a/ladderlogic.cpp +++ b/ladderlogic.cpp @@ -152,7 +152,7 @@ basic_controller::deserialize_operation( cParser &Input ) -> bool { } if( false == operationparameter.empty() ) { - auto const parameter{ split_index( operationparameter ) }; + auto const parameter{ split_string_and_number( operationparameter ) }; operation.parameter1 = static_cast( parameter.second ); } @@ -379,7 +379,7 @@ basic_controller::log_error( std::string const &Error, int const Line ) const { auto basic_controller::guess_element_type_from_name( std::string const &Name ) const -> basic_element::type_e { - auto const name { split_index( Name ) }; + auto const name { split_string_and_number( Name ) }; if( ( name.first == "t" ) || ( name.first == "ton" ) || ( name.first.find( "timer." ) == 0 ) ) { return basic_element::type_e::timer; diff --git a/mtable.cpp b/mtable.cpp index 71373ff0..9bcecaf5 100644 --- a/mtable.cpp +++ b/mtable.cpp @@ -329,6 +329,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax) { fin >> s; } while (!(s.find("[______________") != std::string::npos || fin.bad())); + auto activeradiochannel{ -1 }; while (!fin.bad() && !EndTable) { ++StationCount; @@ -421,13 +422,23 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax) auto const stationware { Split( record->StationWare, ',' ) }; for( auto const &entry : stationware ) { if( entry[ 0 ] == 'R' ) { - auto const entrysplit { split_index( entry ) }; + auto const entrysplit { split_string_and_number( entry ) }; if( ( entrysplit.first == "R" ) && ( entrysplit.second <= 10 ) ) { - record->radio_channel = entrysplit.second; + auto const radiochannel { entrysplit.second }; + if( ( record->radio_channel == -1 ) + || ( radiochannel != activeradiochannel ) ) { + // if the station has more than one radiochannel listed, + // it generally means we should switch to the one we weren't using so far + // TODO: reverse this behaviour (keep the channel used so far) once W28 signs are included in the system + record->radio_channel = radiochannel; + } } } } + if( record->radio_channel != -1 ) { + activeradiochannel == record->radio_channel; + } } record->TrackNo = atoi(s.c_str()); fin >> s; diff --git a/sound.h b/sound.h index fc4aad08..0bddacca 100644 --- a/sound.h +++ b/sound.h @@ -17,7 +17,7 @@ float const EU07_SOUND_GLOBALRANGE { -1.f }; float const EU07_SOUND_CABCONTROLSCUTOFFRANGE { 7.5f }; float const EU07_SOUND_BRAKINGCUTOFFRANGE { 100.f }; float const EU07_SOUND_RUNNINGNOISECUTOFFRANGE { 200.f }; -float const EU07_SOUND_HANDHELDRADIORANGE { 750.f }; +float const EU07_SOUND_HANDHELDRADIORANGE { 3500.f }; enum class sound_type { single, diff --git a/translation.cpp b/translation.cpp index 32a77a9c..5eed05d5 100644 --- a/translation.cpp +++ b/translation.cpp @@ -71,7 +71,7 @@ init() { ", owned by: ", "none", "Devices: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%s%s\nPower transfers: %.0f@%.0f%s[%.0f]%s%.0f@%.0f :: %.0f@%.0f%s[%.0f]%s%.0f@%.0f", - " radio: ", + " R", " oil pressure: ", "Controllers:\n master: %d(%d), secondary: %s\nEngine output: %.1f, current: %.0f\nRevolutions:\n engine: %.0f, motors: %.0f\n engine fans: %.0f, motor fans: %.0f+%.0f, cooling fans: %.0f+%.0f", " (shunt mode)", @@ -276,7 +276,7 @@ init() { ", wlasciciel: ", "wolny", "Urzadzenia: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%s%s\nTransfer pradow: %.0f@%.0f%s[%.0f]%s%.0f@%.0f :: %.0f@%.0f%s[%.0f]%s%.0f@%.0f", - " radio: ", + " R", " cisn.oleju: ", "Nastawniki:\n glowny: %d(%d), dodatkowy: %s\nMoc silnika: %.1f, prad silnika: %.0f\nObroty:\n silnik: %.0f, motory: %.0f\n went.silnika: %.0f, went.motorow: %.0f+%.0f, went.chlodnicy: %.0f+%.0f", " (tryb manewrowy)", diff --git a/utilities.cpp b/utilities.cpp index 3e62257c..efd100b7 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -201,7 +201,7 @@ std::vector Split(const std::string &s) } std::pair -split_index( std::string const &Key ) { +split_string_and_number( std::string const &Key ) { auto const indexstart{ Key.find_first_of( "-1234567890" ) }; auto const indexend{ Key.find_first_not_of( "-1234567890", indexstart ) }; diff --git a/utilities.h b/utilities.h index e8fd614e..aab00626 100644 --- a/utilities.h +++ b/utilities.h @@ -110,7 +110,7 @@ std::string ExchangeCharInString( std::string const &Source, char const From, ch std::vector &Split(const std::string &s, char delim, std::vector &elems); std::vector Split(const std::string &s, char delim); //std::vector Split(const std::string &s); -std::pair split_index( std::string const &Key ); +std::pair split_string_and_number( std::string const &Key ); std::string to_string(int Value); std::string to_string(unsigned int Value);