mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 15:45:23 +01:00
feat: separate engine start switches for the vehicles in multiple (eu07/maszyna#80)
In vehicles like the ST43, the SP32 or the SN61 every engine of a train in
multiple has its own start and stop buttons in the cab. Until now the cab's
line breaker / engine start switch (main_sw, main_on_bt, main_off_bt) always
started and stopped the engines of all the vehicles under its control.
- .fiz, Engine: JointEngineStart=Yes|No (default Yes, as before). With No
the cab's main_* work the cab's own vehicle only, and an engine stopping on
its own (stalled, out of fuel) stops only its own vehicle instead of every
engine in the train.
- .mmd: mainb_sw, mainb_on_bt, mainb_off_bt work the second vehicle with an
engine under the cab's control, mainc_sw, mainc_on_bt, mainc_off_bt the
third one. They count along the control cable from the cab's vehicle,
behind the cab first. Like main_*, the start switch has to be held for the
vehicle's IniCDelay with the vehicle ready (MainSwitchCheck); an impulse
switch of an electric locomotive with series motors closes on release.
- New commands, added at the end of the command list: linebreakertoggleb,
linebreakeropenb, linebreakercloseb, linebreakertogglec, linebreakeropenc,
linebreakerclosec. No default keys.
- The logic is in vehicle/enginestart.{h,cpp} (core library), tested in
tests/unit/test_engine_start.cpp.
Nothing changes for existing vehicles: the new key and the new cab controls
are optional, and without them the code does what it did before.
Game data (SVN, not changed here, to be done separately; the code works
without it): for the SN61 (dynamic/pkp/sn61_v2), whose cab models already
have the buttons start02/stop02/start03/stop03,
- sn61.fiz, sn61-86.fiz, sn61_v1.fiz and the other SN61 .fiz: add
JointEngineStart=No to the Engine: line;
- sn61.mmd.inc (and the other SN61 includes): after main_on_bt add
mainb_off_bt: { stop02 mov -0.005 0 0.1 ... }
mainb_on_bt: { start02 mov -0.005 0 0.1 ... }
mainc_off_bt: { stop03 mov -0.005 0 0.1 ... }
mainc_on_bt: { start03 mov -0.005 0 0.1 ... }
with the sounds of main_off_bt / main_on_bt.
The tooltips "line breaker B" / "line breaker C" are new strings for lang/*.po.
This commit is contained in:
107
vehicle/enginestart.cpp
Normal file
107
vehicle/enginestart.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
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/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "vehicle/enginestart.h"
|
||||
|
||||
#include "McZapkie/MOVER.h"
|
||||
#include "utilities/utilities.h"
|
||||
|
||||
namespace engine_start {
|
||||
|
||||
namespace {
|
||||
|
||||
// whether the vehicle has an engine the cab can start, the same test the tachometers of the vehicles in multiple make
|
||||
bool has_engine(TMoverParameters const &Vehicle) {
|
||||
return Vehicle.Power > 0.01;
|
||||
}
|
||||
|
||||
// walks from Start through its coupler Side along the control cable, and returns the Number-th vehicle with an engine
|
||||
// other than Skipped it meets; Number is lowered by the ones it met when it doesn't get that far
|
||||
TMoverParameters *find_along(TMoverParameters const &Start, int Side, TMoverParameters const &Skipped, int &Number) {
|
||||
auto const *vehicle{&Start};
|
||||
// a train can't loop back on itself, the limit only guards against a broken chain of couplers
|
||||
for (auto steps = 0; steps < 1000; ++steps) {
|
||||
auto const &coupler{vehicle->Couplers[Side]};
|
||||
if (coupler.Connected == nullptr || false == TestFlag(coupler.CouplingFlag, coupling::control)) {
|
||||
return nullptr;
|
||||
}
|
||||
// onwards through the other end of the next vehicle, whichever way round it stands
|
||||
Side = 1 - coupler.ConnectedNr;
|
||||
vehicle = coupler.Connected;
|
||||
if (vehicle == &Skipped || false == has_engine(*vehicle)) {
|
||||
continue;
|
||||
}
|
||||
if (--Number == 0) {
|
||||
return coupler.Connected;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TMoverParameters *engine(TMoverParameters const &Occupied, TMoverParameters &Controlled, int Number) {
|
||||
if (Number < 1) {
|
||||
return nullptr;
|
||||
}
|
||||
if (Number == 1) {
|
||||
return &Controlled;
|
||||
}
|
||||
// the cab's own vehicle is the first one
|
||||
auto others{Number - 1};
|
||||
// behind the cab is the rear end of a vehicle driven from its front cab, and the other way round
|
||||
int const behind{Occupied.CabOccupied < 0 ? end::front : end::rear};
|
||||
if (auto *found{find_along(Occupied, behind, Controlled, others)}; found != nullptr) {
|
||||
return found;
|
||||
}
|
||||
return find_along(Occupied, 1 - behind, Controlled, others);
|
||||
}
|
||||
|
||||
void remote_switch::update(TMoverParameters *Engine, bool const Closeheld, bool const Openheld, double const Deltatime, bool const Closesonrelease) {
|
||||
if (Engine != m_engine) {
|
||||
// another vehicle under the switch, after a change in the train
|
||||
m_engine = Engine;
|
||||
m_heldtime = 0.0;
|
||||
m_ready = false;
|
||||
}
|
||||
if (Engine == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (Openheld || is_running(*Engine)) {
|
||||
// the switch opening the circuit is held down, or there's nothing left to start
|
||||
m_heldtime = 0.0;
|
||||
m_ready = false;
|
||||
return;
|
||||
}
|
||||
if (Closeheld && Engine->MainSwitchCheck()) {
|
||||
m_heldtime += Deltatime;
|
||||
}
|
||||
if (m_heldtime > Engine->InitialCtrlDelay) {
|
||||
m_ready = true;
|
||||
}
|
||||
if (m_ready && false == (Closesonrelease && Closeheld)) {
|
||||
Engine->MainSwitch(true, range_t::local);
|
||||
m_ready = false;
|
||||
m_heldtime = 0.0;
|
||||
}
|
||||
if (false == Closeheld) {
|
||||
m_heldtime = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
bool remote_switch::open(TMoverParameters &Engine) {
|
||||
return Engine.MainSwitch(false, range_t::local);
|
||||
}
|
||||
|
||||
bool remote_switch::is_running(TMoverParameters const &Engine) {
|
||||
return Engine.Mains || Engine.dizel_startup;
|
||||
}
|
||||
|
||||
} // namespace engine_start
|
||||
Reference in New Issue
Block a user