17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-01 09:12:08 +01:00
Files
maszyna/vehicle/gaugepositions.h
jerrrrycho ec345f94cb fix: automatic coupler crashes, horns, compressor start delay, radio and cab lever sounds
- automatic couplers don't catch above the safe collision speed (#86): with crash damage on they couple at a
  closing speed of 15 km/h at most, a faster hit locks the coupling until the vehicles part and the collision
  runs its course. On the way: CollisionVelocity() read a head-on 10 + 10 km/h as 14.1 km/h (quaternions turn
  by half the angle), it's now taken from the touching ends; CollisionDetect() took the other vehicle's speed
  the wrong way round for vehicles facing each other. Head-on hits now derail sooner, at the intended limit,
- a single horn lever can't sound both tones at once (eu07/maszyna#392),
- a skid ends once the vehicle stops on locked wheels (eu07/maszyna#479),
- electronic destination signs are blanked at the end of the timetable (eu07/maszyna#446),
- horns need the air or the voltage to sound (eu07/maszyna#290, #76): HornType=[Pneumatic]|Electric and
  Horn3Type in Cntrl.; a pneumatic horn needs 0.2 MPa in the main reservoir (or the main pipe without one),
  an electric one the low voltage; the lever stays where it was put,
- compressor start delay (#67): CompressorStartDelay [s] in Brake., counted from the compressor getting its
  power, after the engine starts say; none by default,
- the channel and volume buttons of a radio without power do nothing (eu07/maszyna#429); the power check of
  the radio is TMoverParameters::RadioPowered(),
- a lever moved smoothly sounds the positions it passes (#83).

Sonar findings in the functions changed: nesting, nested conditionals, commented-out code, std::format,
references to const. Unit tests: test::pair for two vehicles running into each other, test_couplers,
test_horn, test_wheelslip, test_compressor, test_radio, test_gauge_positions.
2026-10-17 14:41:59 +02:00

36 lines
1.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/.
*/
#pragma once
#include <map>
// positions of a cab control which have sounds of their own
namespace gauge_positions {
// the entry of the last position of Positions the control reached on its way from the Previous to the Desired value,
// both in hundredths of a position, or Positions.end() if it reached none: a lever moved smoothly passes the
// positions rather than stops at them, and should sound each one it gets to
template <typename Value_>
typename std::map<int, Value_>::iterator last_reached(std::map<int, Value_> &Positions, int const Previous, int const Desired) {
auto reached{Positions.end()};
for (auto position{Positions.begin()}; position != Positions.end(); ++position) {
auto const at{position->first * 100};
if (Desired > Previous && at > Previous && at <= Desired) {
reached = position; // moving up, the last one in the ascending order is the one reached last
}
else if (Desired < Previous && at < Previous && at >= Desired) {
return position; // moving down, the first one is
}
}
return reached;
}
} // namespace gauge_positions