From 20755795ea279ad2a249f38cc8470544a7374c8d Mon Sep 17 00:00:00 2001 From: milek7 Date: Tue, 2 Apr 2019 21:53:19 +0200 Subject: [PATCH] separate shp buzzer, other changes --- DynObj.cpp | 60 ++++++++++++++++++++++++++++----------- McZapkie/MOVER.h | 1 + McZapkie/Mover.cpp | 17 +++++++---- Train.cpp | 25 ++++++++++++++-- Train.h | 1 + command.cpp | 1 + command.h | 1 + simulation.cpp | 24 +++++++++------- translation.cpp | 4 ++- translation.h | 1 + widgets/vehicleparams.cpp | 5 ++++ 11 files changed, 105 insertions(+), 35 deletions(-) diff --git a/DynObj.cpp b/DynObj.cpp index c608242f..00793650 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -2002,23 +2002,51 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" smBuforPrawy[ i ]->WillBeAnimated(); } } - // McZapkie-250202 end. - Track->AddDynamicObject(this); // wstawiamy do toru na pozycję 0, a potem przesuniemy - // McZapkie: zmieniono na ilosc osi brane z chk - // iNumAxles=(MoverParameters->NAxles>3 ? 4 : 2 ); - iNumAxles = 2; - // McZapkie-090402: odleglosc miedzy czopami skretu lub osiami - fAxleDist = clamp( - std::max( MoverParameters->BDist, MoverParameters->ADist ), - 0.2, //żeby się dało wektory policzyć - MoverParameters->Dim.L - 0.2 ); // nie mogą być za daleko bo będzie "walenie w mur" - place_on_track(Track, fDist, Reversed); + for( auto &axle : m_axlesounds ) { + // wyszukiwanie osi (0 jest na końcu, dlatego dodajemy długość?) + axle.distance = ( + Reversed ? + -axle.offset : + ( axle.offset + MoverParameters->Dim.L ) ) + fDist; + } + // McZapkie-250202 end. + Track->AddDynamicObject(this); // wstawiamy do toru na pozycję 0, a potem przesuniemy initial_track = MyTrack; - // Ra: ustawienie pozycji do obliczania sprzęgów - MoverParameters->Loc = { - -vPosition.x, - vPosition.z, - vPosition.y }; // normalnie przesuwa ComputeMovement() w Update() + // McZapkie: zmieniono na ilosc osi brane z chk + // iNumAxles=(MoverParameters->NAxles>3 ? 4 : 2 ); + iNumAxles = 2; + // McZapkie-090402: odleglosc miedzy czopami skretu lub osiami + fAxleDist = clamp( + std::max( MoverParameters->BDist, MoverParameters->ADist ), + 0.2, //żeby się dało wektory policzyć + MoverParameters->Dim.L - 0.2 ); // nie mogą być za daleko bo będzie "walenie w mur" + double fAxleDistHalf = fAxleDist * 0.5; + // przesuwanie pojazdu tak, aby jego początek był we wskazanym miejcu + fDist -= 0.5 * MoverParameters->Dim.L; // dodajemy pół długości pojazdu, bo ustawiamy jego środek (zliczanie na minus) + switch (iNumAxles) { + // Ra: pojazdy wstawiane są na tor początkowy, a potem przesuwane + case 2: // ustawianie osi na torze + Axle0.Init(Track, this, iDirection ? 1 : -1); + Axle0.Move((iDirection ? fDist : -fDist) + fAxleDistHalf, false); + Axle1.Init(Track, this, iDirection ? 1 : -1); + Axle1.Move((iDirection ? fDist : -fDist) - fAxleDistHalf, false); // false, żeby nie generować eventów + break; + case 4: + Axle0.Init(Track, this, iDirection ? 1 : -1); + Axle0.Move((iDirection ? fDist : -fDist) + (fAxleDistHalf + MoverParameters->ADist * 0.5), false); + Axle1.Init(Track, this, iDirection ? 1 : -1); + Axle1.Move((iDirection ? fDist : -fDist) - (fAxleDistHalf + MoverParameters->ADist * 0.5), false); + // Axle2.Init(Track,this,iDirection?1:-1); + // Axle2.Move((iDirection?fDist:-fDist)-(fAxleDistHalf-MoverParameters->ADist*0.5),false); + // Axle3.Init(Track,this,iDirection?1:-1); + // Axle3.Move((iDirection?fDist:-fDist)+(fAxleDistHalf-MoverParameters->ADist*0.5),false); + break; + } + // potrzebne do wyliczenia aktualnej pozycji; nie może być zero, bo nie przeliczy pozycji + // teraz jeszcze trzeba przypisać pojazdy do nowego toru, bo przesuwanie początkowe osi nie + // zrobiło tego + Move( 0.0001 ); + ABuCheckMyTrack(); // zmiana toru na ten, co oś Axle0 (oś z przodu) // ABuWozki 060504 if (mdModel) // jeśli ma w czym szukać { diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index b4cb2bcd..8bf60705 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -613,6 +613,7 @@ public: bool is_vigilance_blinking() const; bool is_cabsignal_blinking() const; bool is_beeping() const; + bool is_cabsignal_beeping() const; bool is_braking() const; bool is_engine_blocked() const; bool radiostop_available() const; diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index fc59a727..ab71f186 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -161,7 +161,11 @@ bool TSecuritySystem::is_cabsignal_blinking() const { } bool TSecuritySystem::is_beeping() const { - return alert_timer > SoundSignalDelay; + return alert_timer > SoundSignalDelay && (!separate_acknowledge || is_vigilance_blinking()); +} + +bool TSecuritySystem::is_cabsignal_beeping() const { + return alert_timer > SoundSignalDelay && is_cabsignal_blinking(); } bool TSecuritySystem::is_braking() const { @@ -1141,6 +1145,8 @@ void TMoverParameters::CollisionDetect(int CouplerN, double dt) if ((coupler.CouplingFlag & ctrain_pneumatic) == ctrain_pneumatic) AlarmChainFlag = true; // hamowanie nagle - zerwanie przewodow hamulcowych + // M7TMP: disable coupler breaking because consist cannot be teleported to starting place in one piece + /* coupler.CouplingFlag = 0; switch (CouplerN) // wyzerowanie flag podlaczenia ale ciagle sa wirtualnie polaczone @@ -1152,6 +1158,7 @@ void TMoverParameters::CollisionDetect(int CouplerN, double dt) coupler.Connected->Couplers[0].CouplingFlag = 0; break; } + */ WriteLog( "Bad driving: " + Name + " broke a coupler" ); } } @@ -3023,14 +3030,12 @@ bool TMoverParameters::RadiostopSwitch(bool Switch) bool TMoverParameters::AlarmChainSwitch( bool const State ) { - bool stateswitched { false }; - - if( AlarmChainFlag != State ) { + if( AlarmChainFlag != State ) { // simple routine for the time being AlarmChainFlag = State; - stateswitched = true; + return true; } - return stateswitched; + return false; } // ************************************************************************************************* diff --git a/Train.cpp b/Train.cpp index 40b28436..6f31481d 100644 --- a/Train.cpp +++ b/Train.cpp @@ -6429,6 +6429,18 @@ TTrain::update_sounds( double const Deltatime ) { } } + if (mvOccupied->SecuritySystem.is_cabsignal_beeping()) { + if (!dsbCabsignalBuzzer.is_playing()) { + dsbCabsignalBuzzer + .pitch( dsbCabsignalBuzzer.m_frequencyoffset + dsbCabsignalBuzzer.m_frequencyfactor ) + .gain( dsbCabsignalBuzzer.m_amplitudeoffset + dsbCabsignalBuzzer.m_amplitudefactor ) + .play( sound_flags::looping ); + } + } + else if (dsbCabsignalBuzzer.is_playing()) { + dsbCabsignalBuzzer.stop(); + } + update_sounds_radio(); if( fTachoCount >= 3.f ) { @@ -6613,10 +6625,16 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName) } else if (token == "buzzer:") { - // bzyczek shp: + // bzyczek czuwaka: dsbBuzzer.deserialize( parser, sound_type::single ); dsbBuzzer.owner( DynamicObject ); } + else if (token == "cabsignalbuzzer:") + { + // bzyczek shp: + dsbCabsignalBuzzer.deserialize( parser, sound_type::single ); + dsbCabsignalBuzzer.owner( DynamicObject ); + } else if( token == "radiostop:" ) { // radiostop m_radiostop.deserialize( parser, sound_type::single ); @@ -6753,7 +6771,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) &dsbSwitch, &dsbPneumaticSwitch, &rsHiss, &rsHissU, &rsHissE, &rsHissX, &rsHissT, &rsSBHiss, &rsSBHissU, &rsFadeSound, &rsRunningNoise, &rsHuntingNoise, - &dsbHasler, &dsbBuzzer, &dsbSlipAlarm, &m_radiosound, &m_radiostop + &dsbHasler, &dsbBuzzer, &dsbCabsignalBuzzer, &dsbSlipAlarm, &m_radiosound, &m_radiostop }; for( auto sound : sounds ) { sound->offset( nullvector ); @@ -7039,6 +7057,9 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) if( dsbBuzzer.offset() == nullvector ) { dsbBuzzer.offset( btLampkaCzuwaka.model_offset() ); } + if( dsbCabsignalBuzzer.offset() == nullvector ) { + dsbCabsignalBuzzer.offset( btLampkaCzuwaka.model_offset() ); + } // radio has two potential items which can provide the position if( m_radiosound.offset() == nullvector ) { m_radiosound.offset( btLampkaRadio.model_offset() ); diff --git a/Train.h b/Train.h index 7350f7bd..e0c08119 100644 --- a/Train.h +++ b/Train.h @@ -619,6 +619,7 @@ public: // reszta może by?publiczna sound_source dsbHasler { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE }; sound_source dsbBuzzer { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE }; + sound_source dsbCabsignalBuzzer { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE }; sound_source dsbSlipAlarm { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE }; // Bombardier 011010: alarm przy poslizgu dla 181/182 sound_source m_radiosound { sound_placement::internal, 2 * EU07_SOUND_CABCONTROLSCUTOFFRANGE }; // cached template for radio messages std::vector>> m_radiomessages; // list of currently played radio messages diff --git a/command.cpp b/command.cpp index 01334508..103ef323 100644 --- a/command.cpp +++ b/command.cpp @@ -252,6 +252,7 @@ commanddescription_sequence Commands_descriptions = { { "deletemodel", command_target::simulation, command_mode::oneoff }, { "trainsetmove", command_target::simulation, command_mode::oneoff }, { "consistteleport", command_target::simulation, command_mode::oneoff }, + { "pullalarmchain", command_target::simulation, command_mode::oneoff }, { "notifyquit", command_target::simulation, command_mode::oneoff }, }; diff --git a/command.h b/command.h index 98b9e200..05e715bf 100644 --- a/command.h +++ b/command.h @@ -246,6 +246,7 @@ enum class user_command { deletemodel, dynamicmove, consistteleport, + pullalarmchain, quitsimulation, diff --git a/simulation.cpp b/simulation.cpp index 0f835f95..62a56953 100644 --- a/simulation.cpp +++ b/simulation.cpp @@ -203,28 +203,26 @@ void state_manager::process_commands() { TDynamicObject *vehicle = found_vehicle; while (vehicle) { - vehicle->MoverParameters->DamageFlag = 0; - vehicle->MoverParameters->EngDmgFlag = 0; - vehicle->MoverParameters->V = 0.0; - vehicle->MoverParameters->DistCounter = 0.0; - vehicle->MoverParameters->WheelFlat = 0.0; - vehicle = vehicle->Next(); + if (vehicle->Next()) + vehicle = vehicle->Next(); + else + break; } - vehicle = found_vehicle; while (vehicle) { vehicle->MoverParameters->DamageFlag = 0; vehicle->MoverParameters->EngDmgFlag = 0; vehicle->MoverParameters->V = 0.0; vehicle->MoverParameters->DistCounter = 0.0; vehicle->MoverParameters->WheelFlat = 0.0; + vehicle->MoverParameters->AlarmChainFlag = false; vehicle = vehicle->Prev(); } } if (commanddata.command == user_command::fillcompressor) { - TDynamicObject *found_vehicle = simulation::Vehicles.find(commanddata.payload); - found_vehicle->MoverParameters->CompressedVolume = 8.0f * found_vehicle->MoverParameters->VeselVolume; + TDynamicObject *vehicle = simulation::Vehicles.find(commanddata.payload); + vehicle->MoverParameters->CompressedVolume = 8.0f * vehicle->MoverParameters->VeselVolume; } if (commanddata.command == user_command::dynamicmove) { @@ -254,12 +252,18 @@ void state_manager::process_commands() { double offset = 0.0; while (vehicle) { - vehicle->place_on_track(track, offset, false); offset += vehicle->MoverParameters->Dim.L; + vehicle->place_on_track(track, offset, false); vehicle = vehicle->Prev(); } } + if (commanddata.command == user_command::pullalarmchain) { + TDynamicObject *vehicle = simulation::Vehicles.find(commanddata.payload); + if (vehicle) + vehicle->MoverParameters->AlarmChainSwitch(true); + } + if (commanddata.command == user_command::quitsimulation) { Application.queue_quit(); } diff --git a/translation.cpp b/translation.cpp index dd5d9d7a..6dab8493 100644 --- a/translation.cpp +++ b/translation.cpp @@ -118,7 +118,8 @@ init() { "Radiostop", "Reset position", "Stop and repair", - "Refill main pipe", + "Refill main tank", + "Rupture main pipe", "Move +500m", "Move -500m", @@ -326,6 +327,7 @@ init() { u8"Zresetuj pozycję", u8"Zatrzymaj i napraw", u8"Napełnij ZG", + u8"Zerwij PG", u8"Przesuń +500m", u8"Przesuń -500m", diff --git a/translation.h b/translation.h index 653e2c52..1e0bd426 100644 --- a/translation.h +++ b/translation.h @@ -108,6 +108,7 @@ enum string { vehicleparams_resetposition, vehicleparams_reset, vehicleparams_resetpipe, + vehicleparams_rupturepipe, vehicleparams_move500f, vehicleparams_move500b, diff --git a/widgets/vehicleparams.cpp b/widgets/vehicleparams.cpp index 02fb6c32..4c37b6c3 100644 --- a/widgets/vehicleparams.cpp +++ b/widgets/vehicleparams.cpp @@ -197,12 +197,17 @@ void ui::vehicleparams_panel::render_contents() if (ImGui::Button(LOC_STR(vehicleparams_resetposition))) { std::string payload = vehicle_ptr->name() + '%' + vehicle_ptr->initial_track->name(); m_relay.post(user_command::consistteleport, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &payload); + m_relay.post(user_command::resetconsist, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); } if (ImGui::Button(LOC_STR(vehicleparams_resetpipe))) m_relay.post(user_command::fillcompressor, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); ImGui::SameLine(); + if (ImGui::Button(LOC_STR(vehicleparams_rupturepipe))) + m_relay.post(user_command::pullalarmchain, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); + ImGui::SameLine(); + ImGui::Button(LOC_STR(cab_releaser_bt)); if (ImGui::IsItemClicked()) m_relay.post(user_command::consistreleaser, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name());