mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 11:56:50 +01:00
04f76951f5
TMoverParameters held some 80 fields of the diesel engine and its hydraulic
transmission among its other 600, named dizel_*, hydro_TC_* and hydro_R_*.
They are now three structures of physics/components/dieselengine.h, with
English names:
- DieselEngine diesel: the definition (maxMoment, maxRevolutions,
minRevolutions, the governor, the clutch, the fuel consumption, the tables)
and the state (fill, clutchState, clutchPressure, torque, power, the start
up, the fuel consumed) and its heat (EngineHeat, heat_data before)
- TorqueConverter torqueConverter: present, the ratios, the lockup, the
fill rates, the table, and its state (fill, lockedUp, torqueRatio, the
revolutions in and out)
- Retarder retarder: present, its placement, torque, power, fill rates,
clutch, and its state
The .fiz keywords, the keys of the dictionaries of the Python screens and the
names of the golden channels (dizel_fill...) are unchanged; only the C++
names changed. The functions of the engine (dizel_Update, dizel_Momentum...)
stay members of TMoverParameters for now.
No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b.
110 lines
3.2 KiB
C++
110 lines
3.2 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/.
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "vehicle/enginestart.h"
|
|
|
|
#include "physics/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 const Side, TMoverParameters const &Skipped, int &Number) {
|
|
auto const *vehicle{&Start};
|
|
auto side{Side};
|
|
// 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 == coupler.CouplingFlag.HasAll(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;
|
|
}
|
|
--Number;
|
|
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.diesel.startupRequested;
|
|
}
|
|
|
|
} // namespace engine_start
|