18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 17:25:00 +01:00

Merge remote-tracking branch 'origin/master' into feat/persistent-odometer-store

# Conflicts:
#	vehicle/DynObj.h
This commit is contained in:
jerrrrycho
2026-11-11 08:17:40 +01:00
70 changed files with 11421 additions and 369 deletions

View File

@@ -643,6 +643,9 @@ bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters *
// stykaja sie zderzaki i kompatybilne typy sprzegow, chyba że łączenie na starcie
if (thiscoupler.CouplingFlag == coupling::faux)
{
// a new coupling: the play of the coupling as set up anew, without the stretch of the one before
thiscoupler.physics_state.couple();
othercoupler.physics_state.couple();
// jeśli wcześniej nie było połączone, ustalenie z której strony rysować sprzęg
thiscoupler.Render = true; // tego rysować
othercoupler.Render = false; // a tego nie
@@ -1334,6 +1337,15 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
auto const otherend{Neighbours[End].vehicle_end};
auto const &othercoupler{othervehicle->Couplers[otherend]};
auto const physical{coupler_physics_at(End)};
if (physical && false == coupler_stop_hit(End, *othervehicle, otherend))
{
return;
}
// the share of the energy of the relative motion the hit takes: in the physical model the springs gone solid give
// for good, rather than spring back as the legacy model has it
auto const loss{physical ? coupler_physics::solid_hit_loss(thiscoupler.physics, othercoupler.physics) : (thiscoupler.beta + othercoupler.beta) / 2.0};
// the velocities along this vehicle's axis: the other vehicle's one is turned around when the vehicles face each
// other (touch with the same ends), as in CouplerForce()
auto const otherdirection{DirPatch(End, otherend)};
@@ -1347,12 +1359,12 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
{
case 0:
{
CCF = ComputeCollision(velocity, othervehiclevelocity, TotalMass, othervehicle->TotalMass, (thiscoupler.beta + othercoupler.beta) / 2.0, VirtualCoupling) / dt;
CCF = ComputeCollision(velocity, othervehiclevelocity, TotalMass, othervehicle->TotalMass, loss, VirtualCoupling) / dt;
break; // yB: ej ej ej, a po
}
case 1:
{
CCF = ComputeCollision(othervehiclevelocity, velocity, othervehicle->TotalMass, TotalMass, (thiscoupler.beta + othercoupler.beta) / 2.0, VirtualCoupling) / dt;
CCF = ComputeCollision(othervehiclevelocity, velocity, othervehicle->TotalMass, TotalMass, loss, VirtualCoupling) / dt;
break;
}
default:
@@ -1363,7 +1375,8 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
if (Global.crash_damage)
{
if (-thiscoupler.Dist >= thiscoupler.DmaxB && FuzzyLogic(std::abs(CCF), 5.0 * (thiscoupler.FmaxC + 1.0), p_coupldmg))
// the physical model breaks the coupling and crushes the buffers by the force of the hit (coupler_stop_hit())
if (false == physical && -thiscoupler.Dist >= thiscoupler.DmaxB && FuzzyLogic(std::abs(CCF), 5.0 * (thiscoupler.FmaxC + 1.0), p_coupldmg))
{
// small chance to smash the coupler if it's hit with excessive force
damage_coupler(End);
@@ -1392,18 +1405,21 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
}
}
// adjust velocity and acceleration of affected vehicles
// adjust velocity and acceleration of affected vehicles. the physical model changes the velocities alone: the
// integration of the next step (ComputeMovement()) would carry a quarter of an acceleration spike over into the
// velocity once more, and the vehicles would bounce off the stop faster than they hit it
auto const accelerationspike{physical ? 0.0 : 1.0};
if (false == TestFlag(DamageFlag, dtrain_out))
{
auto const accelerationchange{(velocity - V) / dt};
AccS += accelerationchange;
AccS += accelerationchange * accelerationspike;
V = velocity;
}
if (false == TestFlag(othervehicle->DamageFlag, dtrain_out))
{
auto const othervehiclenewvelocity{othervehiclevelocity * otherdirection}; // back along the other vehicle's axis
auto const othervehicleaccelerationchange{(othervehiclenewvelocity - othervehicle->V) / dt};
othervehicle->AccS += othervehicleaccelerationchange;
othervehicle->AccS += othervehicleaccelerationchange * accelerationspike;
othervehicle->V = othervehiclenewvelocity;
}
}
@@ -1421,39 +1437,72 @@ void TMoverParameters::damage_coupler(int const End)
if (SetFlag(DamageFlag, dtrain_coupling))
EventFlag = true;
if ((thiscoupler.CouplingFlag & coupling::brakehose) == coupling::brakehose)
auto const hosetorn{(thiscoupler.CouplingFlag & coupling::brakehose) == coupling::brakehose};
if (hosetorn)
{
// hamowanie nagle - zerwanie przewodow hamulcowych
AlarmChainFlag = true;
}
thiscoupler.CouplingFlag = 0;
thiscoupler.broken = true;
if (thiscoupler.Connected != nullptr)
{
switch (End)
// break connection with other vehicle, if there's any: on the end it's coupled with, which is the front one too
// for vehicles facing each other
auto &othercoupler{thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr]};
othercoupler.CouplingFlag = coupling::faux;
// the coupling broke between the two, either end can be repaired
othercoupler.broken = true;
if (hosetorn && coupler_physics_at(End))
{
// break connection with other vehicle, if there's any
case 0:
{
thiscoupler.Connected->Couplers[end::rear].CouplingFlag = coupling::faux;
break;
}
case 1:
{
thiscoupler.Connected->Couplers[end::front].CouplingFlag = coupling::faux;
break;
}
default:
{
break;
}
// the brake pipe of the other part of the train vents through the torn hose as well
thiscoupler.Connected->AlarmChainFlag = true;
}
}
WriteLog("Bad driving: " + Name + " broke a coupler");
}
namespace
{
// the coupler as good as new, the vehicle without the coupler damage (and the emergency braking of the torn brake
// hose) once neither of its couplers is broken
void repair(TMoverParameters &Vehicle, TCoupling &Coupler)
{
Coupler.broken = false;
Coupler.stretch_duration = 0.f;
Coupler.physics_state.couple();
if (Vehicle.Couplers[end::front].broken || Vehicle.Couplers[end::rear].broken)
{
return;
}
ClearFlag(Vehicle.DamageFlag, dtrain_coupling);
// either vehicle of the pair may have been braking through the torn hose
Vehicle.AlarmChainFlag = false;
}
} // namespace
bool TMoverParameters::repair_coupler(int const End)
{
auto &thiscoupler{Couplers[End]};
if (false == thiscoupler.broken)
{
return false;
}
repair(*this, thiscoupler);
// the other half of the coupling, which may be the vehicle flagged with the damage
if (auto *other{thiscoupler.Connected}; other != nullptr && other->Couplers[thiscoupler.ConnectedNr].broken)
{
repair(*other, other->Couplers[thiscoupler.ConnectedNr]);
}
WriteLog(std::format("Coupler of {} repaired, at its {} end", Name, End == end::front ? "front" : "rear"));
return true;
}
void TMoverParameters::Derail(DerailReason const Reason)
{
if (SetFlag(DamageFlag, dtrain_out))
@@ -2626,7 +2675,7 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed)
if (true == OK)
{
ScndCtrlResistiveLockCheck(); // e.g. from the last series position on to the resistive parallel ones
SendCtrlToNext("MainCtrl", MainCtrlPos, CabActive); //???
SendCtrlToNext("MainCtrl", MainCtrlPosForCoupled(), CabActive); //???
SendCtrlToNext("ScndCtrl", ScndCtrlPos, CabActive);
}
@@ -2752,7 +2801,7 @@ bool TMoverParameters::DecMainCtrl(int CtrlSpeed)
if (OK)
{
ScndCtrlResistiveLockCheck(); // the shunt drops when the master controller leaves a resistance-free position
/*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPos, CabActive); // hmmmm...???!!!
/*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPosForCoupled(), CabActive); // hmmmm...???!!!
/*OK:=*/SendCtrlToNext("ScndCtrl", ScndCtrlPos, CabActive);
}
}
@@ -2800,7 +2849,7 @@ int TMoverParameters::MainCtrlNoPowerPos() const
}
case 2:
{
return 3;
return 3 + EIMCtrlEmergencyPositions();
}
case 3:
{
@@ -2825,6 +2874,27 @@ int TMoverParameters::MainCtrlPowerPos() const
return MainCtrlPos - MainCtrlNoPowerPos();
}
int TMoverParameters::EIMCtrlEmergencyPositions() const
{
return (EIMCtrlType == 2 && EIMCtrlMainEmergency) ? 1 : 0;
}
bool TMoverParameters::IsMainCtrlEmergencyPos() const
{
return MainCtrlPos < EIMCtrlEmergencyPositions();
}
int TMoverParameters::MainCtrlPosForCoupled() const
{
// the emergency brake itself reaches the train through the brake pipe, vented by the vehicle driven from
return std::max(0, MainCtrlPos - EIMCtrlEmergencyPositions());
}
int TMoverParameters::MainCtrlPosFromCoupled(int const Position) const
{
return Position + EIMCtrlEmergencyPositions();
}
// *************************************************************************************************
// Q: 20160710
// zwiększenie bocznika
@@ -2866,7 +2936,7 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed)
OK = false;
if (OK)
{
/*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPos, CabActive); //???
/*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPosForCoupled(), CabActive); //???
/*OK:=*/SendCtrlToNext("ScndCtrl", ScndCtrlPos, CabActive);
}
}
@@ -2928,7 +2998,7 @@ bool TMoverParameters::DecScndCtrl(int CtrlSpeed)
OK = false;
if (OK)
{
/*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPos, CabActive); //???
/*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPosForCoupled(), CabActive); //???
/*OK:=*/SendCtrlToNext("ScndCtrl", ScndCtrlPos, CabActive);
}
}
@@ -4690,8 +4760,9 @@ void TMoverParameters::UpdatePipePressure(double dt)
// EngDmgFlag 32 (load destroyed) used to trigger this too; dropped, it has nothing to do with
// the emergency brake (a broken coupler sets AlarmChainFlag instead)
if (RadioStopFlag || AlarmChainFlag || (EIMCtrlEmergency && LocalBrakePosA >= 1.0) || SecuritySystem.is_braking() ||
// the emergency brake (a broken coupler sets AlarmChainFlag instead). the Elf's emergency brake position
// vents the pipe only from the vehicle driven from, whatever the controllers of the others show
if (RadioStopFlag || AlarmChainFlag || (EIMCtrlEmergency && LocalBrakePosA >= 1.0) || (IsMainCtrlEmergencyPos() && IsCabMaster()) || SecuritySystem.is_braking() ||
(SpringBrakeDriveEmergencyVel >= 0 && Vel > SpringBrakeDriveEmergencyVel && SpringBrake.IsActive) ||
(0 == CabActive && (InactiveCabFlag & activation::emergencybrake) != 0))
{
@@ -5450,6 +5521,10 @@ double TMoverParameters::Adhesive(double staticfriction) const
// *************************************************************************************************
double TMoverParameters::CouplerForce(int const End, double dt)
{
if (coupler_physics_at(End))
{
return coupler_force_physical(End, dt);
}
auto &thiscoupler{Couplers[End]};
auto *othervehicle{Neighbours[End].vehicle->MoverParameters};
@@ -5563,27 +5638,9 @@ double TMoverParameters::CouplerForce(int const End, double dt)
// zderzenie
thiscoupler.CheckCollision = true;
}
if (-newdistance >= std::min(collisiondistance, dEpsilon) && thiscoupler.type() == TCouplerType::Automatic && thiscoupler.type() == othercoupler.type() && thiscoupler.CouplingFlag == coupling::faux &&
thiscoupler.AutomaticCouplingAllowed &&
othercoupler.AutomaticCouplingAllowed)
if (-newdistance >= std::min(collisiondistance, dEpsilon))
{
// sprzeganie wagonow z samoczynnymi sprzegami
auto couplingtype{thiscoupler.AutomaticCouplingFlag & othercoupler.AutomaticCouplingFlag};
// potentially exclude incompatible control coupling
if (thiscoupler.control_type != othercoupler.control_type)
{
couplingtype &= ~coupling::control;
}
couplingtype = CompatibleCoupling(End, *othervehicle, otherend, couplingtype);
// too fast for the couplers to catch, the vehicles collide instead (and may derail, see CollisionDetect())
auto const safe{AutomaticCouplingSafe(End, *othervehicle, otherend)};
auto const caught{safe && Attach(End, otherend, othervehicle, couplingtype)};
// HACK: we're reusing sound enum to mark whether vehicle was connected to another
AIFlag |= (caught ? sound::attachcoupler : 0);
// coupled, or locked until the vehicles part, so they don't couple as soon as the collision slows them down
thiscoupler.AutomaticCouplingAllowed = safe && false == caught;
othercoupler.AutomaticCouplingAllowed = safe && false == caught;
automatic_coupling(End, *othervehicle, otherend);
}
}
}
@@ -5598,6 +5655,172 @@ double TMoverParameters::CouplerForce(int const End, double dt)
return CF;
}
bool TMoverParameters::coupler_physics_at(int const End) const
{
if (false == Global.coupler_physics)
{
return false;
}
if (Global.coupler_physics_all || CouplerPhysics)
{
return true;
}
// either vehicle of the pair covered takes the pair in, so both of them compute it the same way
auto const *other{Neighbours[End].vehicle};
return other != nullptr && other->MoverParameters->CouplerPhysics;
}
void TMoverParameters::automatic_coupling(int const End, TMoverParameters &Other, int const OtherEnd)
{
auto &thiscoupler{Couplers[End]};
auto &othercoupler{Other.Couplers[OtherEnd]};
if (thiscoupler.type() != TCouplerType::Automatic || thiscoupler.type() != othercoupler.type() || thiscoupler.CouplingFlag != coupling::faux || false == thiscoupler.AutomaticCouplingAllowed ||
false == othercoupler.AutomaticCouplingAllowed)
{
return;
}
// sprzeganie wagonow z samoczynnymi sprzegami
auto couplingtype{thiscoupler.AutomaticCouplingFlag & othercoupler.AutomaticCouplingFlag};
// potentially exclude incompatible control coupling
if (thiscoupler.control_type != othercoupler.control_type)
{
couplingtype &= ~coupling::control;
}
couplingtype = CompatibleCoupling(End, Other, OtherEnd, couplingtype);
// too fast for the couplers to catch, the vehicles collide instead (and may derail, see CollisionDetect())
auto const safe{AutomaticCouplingSafe(End, Other, OtherEnd)};
auto const caught{safe && Attach(End, OtherEnd, &Other, couplingtype)};
// HACK: we're reusing sound enum to mark whether vehicle was connected to another
AIFlag |= (caught ? sound::attachcoupler : 0);
// coupled, or locked until the vehicles part, so they don't couple as soon as the collision slows them down
thiscoupler.AutomaticCouplingAllowed = safe && false == caught;
othercoupler.AutomaticCouplingAllowed = safe && false == caught;
}
namespace
{
// the gap between the ends of a coupled pair, taking up the play of the coupling, opens up enough to jerk the train
constexpr double coupler_stretch_threshold{0.001};
// the sounds of the buffers hitting each other, and of the coupling taking up its play
struct coupler_sound_input
{
double gap{0.0}; // between the ends [m]
double previous_gap{0.0};
double gap_rate{0.0}; // [m/s]
double draw_gear{0.0}; // deflection [m]
double previous_draw_gear{0.0};
bool coupled{false};
bool adapter{false};
bool moving{false};
};
int coupler_sounds(coupler_sound_input const &Input)
{
if (Input.gap < 0.0 && Input.gap < Input.previous_gap && Input.gap_rate < -0.1 && false == Input.adapter)
{
// 090503: dzwieki pracy zderzakow
return std::abs(Input.gap_rate) > 5.0 ? sound::bufferclash | sound::loud : sound::bufferclash;
}
if (Input.coupled && Input.moving && Input.draw_gear > coupler_stretch_threshold && Input.previous_draw_gear <= coupler_stretch_threshold && std::abs(Input.gap_rate) > 0.005)
{
// 090503: dzwieki pracy sprzegu
return std::abs(Input.gap_rate) > 0.035 ? sound::couplerstretch | sound::loud : sound::couplerstretch;
}
return sound::none;
}
} // namespace
double TMoverParameters::coupler_force_physical(int const End, double const dt)
{
auto &thiscoupler{Couplers[End]};
auto *othervehicle{Neighbours[End].vehicle->MoverParameters};
auto const otherend{Neighbours[End].vehicle_end};
auto &othercoupler{othervehicle->Couplers[otherend]};
auto &state{thiscoupler.physics_state};
// the gap as it is now: the distance found at the start of the frame, and the movement of both vehicles since
auto const othervehiclemove{othervehicle->dMoveLen * DirPatch(End, otherend)};
auto const gap{Neighbours[End].distance + (End == end::front ? othervehiclemove - dMoveLen : dMoveLen - othervehiclemove)};
// the gap opens up when the front end falls behind the vehicle ahead of it, or the rear end runs ahead of the one behind
auto const gaprate{CouplerVelocityDifference(End, *othervehicle, otherend) * DirF(End)};
auto const coupled{thiscoupler.CouplingFlag != coupling::faux};
auto const adapter{thiscoupler.has_adapter() || othercoupler.has_adapter()};
if (false == coupled && Neighbours[End].distance > 0.05)
{ // arbitrary distance
// potentially reset auto coupling lock
thiscoupler.AutomaticCouplingAllowed = true;
}
auto const previousgap{state.gap};
auto const previousdrawgear{state.draw_gear.deflection};
auto const result{coupler_physics::update_pair(thiscoupler.physics, othercoupler.physics, state, {gap, gaprate, coupled, adapter, Global.crash_damage})};
SetFlag(thiscoupler.sounds, coupler_sounds({gap, previousgap, gaprate, state.draw_gear.deflection, previousdrawgear, coupled, adapter, Vel > 1.0}));
thiscoupler.CheckCollision = state.stop != 0;
// for the buffers drawn pressed in, see TDynamicObject: twice the deflection of the buffers of this end
thiscoupler.Dist = result.compression > 0.0 ? -2.0 * result.buffers_deflection : std::max(gap, 0.0);
// the link pulled past its yield force, which the AI drivers ease off on
thiscoupler.stretch_duration = result.overloaded ? thiscoupler.stretch_duration + static_cast<float>(dt) : 0.f;
if (result.broken)
{
damage_coupler(End);
}
if (false == coupled && gap < 0.0)
{
auto const collisiondistance{adapter ? std::min(thiscoupler.DmaxB, othercoupler.DmaxB) : thiscoupler.DmaxB + othercoupler.DmaxB};
if (-gap >= std::min(collisiondistance, dEpsilon))
{
automatic_coupling(End, *othervehicle, otherend);
}
}
// tension pulls this vehicle towards the other one
auto const force{result.force * -DirF(End)};
if (thiscoupler.CouplingFlag != coupling::faux)
{
// uzgadnianie prawa Newtona, as in CouplerForce()
othercoupler.CForce = -force * DirPatch(End, otherend);
}
return force;
}
bool TMoverParameters::coupler_stop_hit(int const End, TMoverParameters &Other, int const OtherEnd)
{
auto &thiscoupler{Couplers[End]};
auto &othercoupler{Other.Couplers[OtherEnd]};
auto &state{thiscoupler.physics_state};
// the draw gear went solid with the gap opening up, the buffers with it closing
auto const gaprate{CouplerVelocityDifference(End, Other, OtherEnd) * DirF(End)};
auto const closing{state.stop > 0 ? gaprate : -gaprate};
if (state.stop == 0 || closing <= 0.0)
{
// parting from the stop already, after the hit on the other vehicle's end
return false;
}
if (false == Global.crash_damage)
{
return true;
}
auto const hit{coupler_physics::impact(thiscoupler.physics, othercoupler.physics, state, closing, TotalMass, Other.TotalMass)};
// the other vehicle keeps the state of the pair alike
othercoupler.physics_state.elongation = state.elongation;
if (hit.broken || hit.crushed)
{
damage_coupler(End);
}
// a broken coupling lets the vehicles part
return false == hit.broken;
}
// *************************************************************************************************
// Q: 20160714
// oblicza sile trakcyjna lokomotywy (dla elektrowozu tez calkowity prad)
@@ -7532,10 +7755,16 @@ void TMoverParameters::CheckEIMIC(double dt)
eimic = 0;
break;
case 2:
if (MainCtrlActualPos != MainCtrlPos || LastRelayTime > InitialCtrlDelay)
if (IsMainCtrlEmergencyPos())
{
// hamowanie nagle: pelne hamowanie od razu, przewod glowny oproznia UpdatePipePressure()
eimic = -1.0;
}
else if (MainCtrlActualPos != MainCtrlPos || LastRelayTime > InitialCtrlDelay)
{
double delta = MainCtrlActualPos == MainCtrlPos ? dt * CtrlDelay : 0.01;
switch (MainCtrlPos)
// the positions below are those of the controller without the emergency brake position
switch (MainCtrlPos - EIMCtrlEmergencyPositions())
{
case 0:
case 1:
@@ -10946,6 +11175,82 @@ void TMoverParameters::LoadFIZ_Doors(std::string const &line)
extract_value(DoorsPermitLightBlinking, "DoorsPermitLightBlinking", line, "");
}
namespace
{
// the value of an optional key of the line, or the default without it
double optional_value(std::string const &Line, std::string const &Key, double const Default)
{
auto value{Default};
extract_value(value, Key, Line, "");
return value;
}
// the value of an optional key of the line given in kilo-units, in units; or the default (in units) without it
double optional_kilo_value(std::string const &Line, std::string const &Key, double const Default)
{
auto value{0.0};
return extract_value(value, Key, Line, "") && value > 0.0 ? value * 1000.0 : Default;
}
// the play of a coupling as made, for each kind: a screw coupling is tightened so that the buffers touch, the knuckles of
// an automatic coupler have about a centimetre between them, a chain hangs loose
double default_slack(TCouplerType const Type)
{
switch (Type)
{
case TCouplerType::Automatic:
return 0.005;
case TCouplerType::Chain:
return 0.05;
default:
return 0.0;
}
}
// the parameters of the physical model of the coupling (couplerphysics in eu07.ini, see couplerphysics.h), taken from
// those of the legacy model, and the optional keys of the .fiz for what the legacy model doesn't have:
// Slack [m] the play of the coupling of this end, negative for a screw coupling tightened to press the buffers in
// ProgB, ProgC [-] progression of the buffers and of the draw gear, 0 linear, up to 0.9
// UnloadB, UnloadC [-] force of the unloading curve of the buffers and of the draw gear to that of the loading one
// FyieldC [kN] the force past which the link stretches for good; DbreakC [m] the elongation at which it breaks
// kL [kN/m] stiffness of the steel parts past the travel of the springs; FcrushB [kN] the buffers give under it
// RestitutionSolid [-] coefficient of restitution of a hit on the springs gone solid
coupler_physics::end_parameters coupler_physics_parameters(TCoupling const &Coupler, std::string const &Line)
{
coupler_physics::end_parameters parameters;
parameters.buffers = {Coupler.SpringKB, Coupler.DmaxB, std::clamp(optional_value(Line, "ProgB", 0.5), 0.0, 0.9)};
parameters.draw_gear = {Coupler.SpringKC, Coupler.DmaxC, std::clamp(optional_value(Line, "ProgC", 0.3), 0.0, 0.9)};
// only a screw coupling can be tightened to press the buffers in, and not past their travel
auto const tightest{Coupler.CouplerType == TCouplerType::Screw ? -Coupler.DmaxB : 0.0};
parameters.slack = std::max(optional_value(Line, "Slack", default_slack(Coupler.CouplerType)), tightest);
// the legacy model sprang back at beta of the force it was loaded with
auto const unloading{Coupler.beta > 0.0 && Coupler.beta < 1.0 ? Coupler.beta : 0.5};
parameters.buffers_unloading = std::clamp(optional_value(Line, "UnloadB", unloading), 0.05, 1.0);
parameters.draw_gear_unloading = std::clamp(optional_value(Line, "UnloadC", unloading), 0.05, 1.0);
// as much as the legacy model had
parameters.damping = CouplerTune * (Coupler.FmaxC + Coupler.FmaxB) * std::max(Coupler.beta, 0.0);
// FmaxC is the rated breaking force of the coupling
auto const ultimate{std::max(Coupler.FmaxC, 1.0)};
auto const yield{std::min(optional_kilo_value(Line, "FyieldC", 0.8 * ultimate), ultimate)};
auto const elongation{std::max(optional_value(Line, "DbreakC", 0.02), 0.001)};
parameters.link = {yield, ultimate, std::max((ultimate - yield) / elongation, 1.0), Coupler.CouplerType != TCouplerType::Articulated};
// the steel parts give a few millimetres under the rated force
parameters.link_stiffness = optional_kilo_value(Line, "kL", ultimate / 0.003);
parameters.crush_force = optional_kilo_value(Line, "FcrushB", 2.5 * std::max(Coupler.FmaxB, Coupler.FmaxC));
parameters.solid_restitution = std::clamp(optional_value(Line, "RestitutionSolid", parameters.solid_restitution), 0.05, 0.95);
return parameters;
}
void scale_strength(coupler_physics::link_strength &Link, double const Factor)
{
Link.yield *= Factor;
Link.ultimate *= Factor;
}
} // namespace
void TMoverParameters::LoadFIZ_BuffCoupl(std::string const &line, int const Index)
{
@@ -11024,11 +11329,21 @@ void TMoverParameters::LoadFIZ_BuffCoupl(std::string const &line, int const Inde
thiscoupler->DmaxB = std::max(0.05, thiscoupler->FmaxC / thiscoupler->SpringKB);
}
thiscoupler->physics = coupler_physics_parameters(*thiscoupler, line);
if (Index == 0)
{
// 0 indicates single entry for both couplers
Couplers[1] = Couplers[0];
}
// each coupling as made is a little stronger than its rated force, a different one at each end
for (int end = end::front; end <= end::rear; ++end)
{
if (Index == 0 || end == (Index == 2 ? end::rear : end::front))
{
scale_strength(Couplers[end].physics.link, coupler_physics::strength_scatter(Name, end));
}
}
}
void TMoverParameters::LoadFIZ_TurboPos(std::string const &Input)
@@ -11205,6 +11520,16 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line)
extract_value(LocHandleTimeTraxx, "LocalBrakeTraxx", line, "");
extract_value(EIMCtrlAdditionalZeros, "EIMCtrlAddZeros", line, "");
extract_value(EIMCtrlEmergency, "EIMCtrlEmergency", line, "");
// Elf (EIMCtrlType 2): an emergency brake position below the controller's position 0, which shifts the other positions up by one
extract_value(EIMCtrlMainEmergency, "EIMCtrlMainEmergency", line, "");
if (auto const elfpositions{4 + EIMCtrlEmergencyPositions()}; EIMCtrlEmergencyPositions() > 0 && MainCtrlPosNo < elfpositions)
{
// the old positions in the file: without the fix-up the controller would have no power position, and the
// reverser would stop working at neutral (DirChangeMaxPos read before, in the old positions)
MainCtrlMaxDirChangePos += EIMCtrlEmergencyPositions();
ErrorLog(std::format("Bad fiz: EIMCtrlMainEmergency needs MCPN={} in {}, DirChangeMaxPos taken as {}", elfpositions, TypeName, MainCtrlMaxDirChangePos));
MainCtrlPosNo = elfpositions;
}
extract_value(ScndS, "ScndS", line, ""); // brak pozycji rownoleglej przy niskiej nastawie PSR
extract_value(ScndCtrlResistiveLock, "ScndCtrlResistiveLock", line, ""); // bocznikowanie tylko na pozycjach bezoporowych
@@ -12550,9 +12875,10 @@ bool TMoverParameters::RunCommand(std::string const &Command, double CValue1, do
if (Command == "MainCtrl")
{
if (MainCtrlPosNo >= floor(CValue1))
// sent as MainCtrlPosForCoupled(), passed on unchanged
if (auto const position{MainCtrlPosFromCoupled(static_cast<int>(floor(CValue1)))}; MainCtrlPosNo >= position)
{
MainCtrlPos = static_cast<int>(floor(CValue1));
MainCtrlPos = position;
if (DelayCtrlFlag)
{
if (LastRelayTime >= InitialCtrlDelay && MainCtrlPos == 1)