mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-18 14:59:19 +02:00
fix(cab): the line contactors lamp goes out with the pressure switch (eu07/maszyna#470) The lamp of the open line contactors, which tells the start can be made, went out at 1 bar in the brake cylinders, while the pressure switch cuts the start off only at 2 bar (or below 3.6 bar in the main pipe), so with the brakes partly applied the start could be made with the lamp out. With a pressure switch fitted the lamp now follows it; without one it goes out at 1 bar as before. The same holds for the lamp of the second unit, which used to keep its last state between 1 bar and the cut-off. The condition is TMoverParameters::LineContactorsLampLit(). Tests: tests/unit/test_line_contactors.cpp. refactor: Sonar findings of PR 217 - horn_supply::pneumatic shadowed the pneumatic enumerator of the sound flags (cpp:S1117), it's horn_supply::air; the supplies read with using enum (S6177), - CouplerForce(): the automatic coupling refused or caught without another level of nested ifs (S134), the same outcome: too fast, the coupling is locked; caught, coupled and locked; otherwise left to try again, - CompressorCheck(): the power the compressor doesn't draw yet noted without a TODO (S1135), - tests: the previous crash damage setting in an in-class initializer (S3230), the loops which stop early with break rather than in their conditions (S886), the stand-ins of test::pair in a std::vector rather than an array (S5945), units in the comments of the example without /* */ (S1103). test: the cases the changes of the branch left without a test - Cntrl.: BDelay1 to BDelay4 reach the brake delays (now through std::format), the default start types of the ground and converter overload relays of a multiple unit and of other vehicles (out of the nested conditionals), - the compressor: fed from the low voltage it waits from the low voltage coming on; the pressure switch stops it above the cut-out pressure, without one the excess air is vented (the vented fraction rewritten), - the horns: a vehicle without any air sounds as before, the threshold pressure, an electric horn on 110 V, - the positions of a cab control below zero, and a control without position sounds. refactor(cab): the kind of the train heating switch as a flag Read once with the vehicle definition, rather than compared as text in each of the switch commands. feat(cab): train heating switch springing back (MaSzyna-EU07/maszyna#85) TrainHeating=[toggle]|impulse in the Switches: section of the vehicle definition makes the train heating switch an unstable one: it goes up to switch the heating on, down to switch it off, and back to the middle once let go, instead of staying where it was put. The position of such a switch isn't set from the heating state when the cab is entered. Tests: tests/unit/test_switches.cpp. feat(sound): mirror sounds (MaSzyna-EU07/maszyna#84, eu07/maszyna#322) The sound definitions of a vehicle (.mmd) take mirroropen: and mirrorclose:, played as a mirror sets off unfolding or folding, and the locations section mirrors: <offset>... end, the offsets along the vehicle of the mirror pairs, as for the doors (negative ahead of the centre), each pair at the sides of the vehicle. As the animation, only the mirrors at the occupied cab sound. The start of a move is mirror_moves::motion in vehicle/mirrors.h. Tests: tests/unit/test_mirrors.cpp. feat(cab): joint oil and fuel pump switch (MaSzyna-EU07/maszyna#81) A cab control oilfuelpump_sw: switches both the oil and the fuel pump at once, with the new command oilfuelpumptoggle (no key by default). As a two-state switch it turns both pumps off when both are on and both on otherwise; as an impulse switch it's held to start them, like the separate pump switches. Its position follows the pumps when the cab is entered. refactor(editor): text fields filled without strncpy (MaSzyna-EU07/maszyna#112) The last three strncpy calls Sonar flags (cpp:S5816), in the road and track editors, copy the text into the ImGui field buffers with std::string::copy and terminate it right after; the text gets cut to the buffer as before. 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.
387 lines
14 KiB
C++
387 lines
14 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/.
|
|
*/
|
|
/*
|
|
MaSzyna EU07 locomotive simulator
|
|
Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "utilities/translation.h"
|
|
#include "utilities/Logs.h"
|
|
#include "utilities/Globals.h"
|
|
#include "MOVER.h"
|
|
|
|
void locale::init()
|
|
{
|
|
std::fstream stream("lang/" + Global.asLang + ".po", std::ios_base::in | std::ios_base::binary);
|
|
|
|
if (!stream.is_open()) {
|
|
WriteLog("translation: cannot open lang file: lang/" + Global.asLang + ".po");
|
|
return;
|
|
}
|
|
|
|
crashreport_add_info("translation", Global.asLang);
|
|
|
|
while (parse_translation(stream));
|
|
|
|
// texts of the scenery editor, kept apart from the translation of the simulator
|
|
std::fstream editor("lang/editor_" + Global.asLang + ".po", std::ios_base::in | std::ios_base::binary);
|
|
if (editor.is_open())
|
|
while (parse_translation(editor));
|
|
|
|
WriteLog("translation: " + std::to_string(lang_mapping.size()) + " strings loaded");
|
|
}
|
|
|
|
const std::string& locale::lookup_s(const std::string &msg, bool constant)
|
|
{
|
|
if (constant) {
|
|
auto it = pointer_cache.find(&msg);
|
|
if (it != pointer_cache.end())
|
|
return *(const std::string *)it->second;
|
|
}
|
|
|
|
auto it = lang_mapping.find(msg);
|
|
if (it != lang_mapping.end()) {
|
|
if (constant)
|
|
pointer_cache.emplace(&msg, &it->second);
|
|
return it->second;
|
|
}
|
|
|
|
if (constant)
|
|
pointer_cache.emplace(&msg, &msg);
|
|
return msg;
|
|
}
|
|
|
|
const char* locale::lookup_c(const char *msg, bool constant)
|
|
{
|
|
if (constant) {
|
|
auto it = pointer_cache.find(msg);
|
|
if (it != pointer_cache.end())
|
|
return (const char*)it->second;
|
|
}
|
|
|
|
auto it = lang_mapping.find(std::string(msg));
|
|
if (it != lang_mapping.end()) {
|
|
if (constant)
|
|
pointer_cache.emplace(msg, it->second.c_str());
|
|
return it->second.c_str();
|
|
}
|
|
|
|
if (constant)
|
|
pointer_cache.emplace(msg, msg);
|
|
return msg;
|
|
}
|
|
|
|
bool locale::parse_translation(std::istream &stream)
|
|
{
|
|
std::string line;
|
|
|
|
std::string msgid;
|
|
std::string msgstr;
|
|
std::string msgctxt;
|
|
char last = 'x';
|
|
|
|
while (std::getline(stream, line)) {
|
|
if (line.size() > 0 && line[0] == '#')
|
|
continue;
|
|
|
|
if (line.starts_with("msgid"))
|
|
last = 'i';
|
|
else if (line.starts_with("msgstr"))
|
|
last = 's';
|
|
else if (line.starts_with("msgctxt"))
|
|
last = 'c';
|
|
|
|
if (line.size() > 1 && last != 'x') {
|
|
if (last == 'i')
|
|
msgid += parse_c_literal(line);
|
|
else if (last == 's')
|
|
msgstr += parse_c_literal(line);
|
|
else if (last == 'c')
|
|
msgctxt += parse_c_literal(line);
|
|
}
|
|
else {
|
|
if (!msgid.empty() && !msgstr.empty()) {
|
|
// TODO: context support is incomplete
|
|
if (!msgctxt.empty())
|
|
lang_mapping.emplace(msgctxt + "\x1d" + msgid, msgstr);
|
|
else
|
|
lang_mapping.emplace(msgid, msgstr);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
std::string locale::parse_c_literal(const std::string &str)
|
|
{
|
|
std::istringstream stream(str);
|
|
std::string out;
|
|
|
|
bool active = false;
|
|
bool escape = false;
|
|
|
|
char c;
|
|
while ((c = stream.get()) != std::char_traits<char>::eof()) {
|
|
if (!escape && c == '"')
|
|
active = !active;
|
|
else if (active && !escape && c == '\\')
|
|
escape = true;
|
|
else if (active && escape) {
|
|
if (c == 'r')
|
|
out += '\r';
|
|
else if (c == 'n')
|
|
out += '\n';
|
|
else if (c == 't')
|
|
out += '\t';
|
|
else if (c == '\\')
|
|
out += '\\';
|
|
else if (c == '?')
|
|
out += '?';
|
|
else if (c == '\'')
|
|
out += '\'';
|
|
else if (c == '"')
|
|
out += '"';
|
|
else if (c == 'x') {
|
|
char n1 = stream.get() - 48;
|
|
char n2 = stream.get() - 48;
|
|
if (n1 > 9)
|
|
n1 -= 7;
|
|
if (n1 > 16)
|
|
n1 -= 32;
|
|
if (n2 > 9)
|
|
n2 -= 7;
|
|
if (n2 > 16)
|
|
n2 -= 32;
|
|
out += n1 << 4 | n2;
|
|
}
|
|
escape = false;
|
|
}
|
|
else if (active)
|
|
out += c;
|
|
}
|
|
|
|
return out;
|
|
}
|
|
|
|
std::string locale::label_cab_control(std::string const &Label)
|
|
{
|
|
if( Label.empty() ) { return ""; }
|
|
|
|
static std::unordered_map<std::string, std::string> cabcontrols_labels = {
|
|
{ "mainctrl:", STRN("master controller") },
|
|
{ "jointctrl:", STRN("master controller") },
|
|
{ "scndctrl:", STRN("second controller") },
|
|
{ "shuntmodepower:", STRN("shunt mode power") },
|
|
{ "tempomat_sw:", STRN("cruise control") },
|
|
{ "tempomatoff_sw:", STRN("cruise control") },
|
|
{ "speedinc_bt:", STRN("cruise control (speed)") },
|
|
{ "speeddec_bt:", STRN("cruise control (speed)") },
|
|
{ "speedctrlpowerinc_bt:", STRN("cruise control (power)") },
|
|
{ "speedctrlpowerdec_bt:", STRN("cruise control (power)") },
|
|
{ "speedbutton0:", STRN("cruise control (speed)") },
|
|
{ "speedbutton1:", STRN("cruise control (speed)") },
|
|
{ "speedbutton2:", STRN("cruise control (speed)") },
|
|
{ "speedbutton3:", STRN("cruise control (speed)") },
|
|
{ "speedbutton4:", STRN("cruise control (speed)") },
|
|
{ "speedbutton5:", STRN("cruise control (speed)") },
|
|
{ "speedbutton6:", STRN("cruise control (speed)") },
|
|
{ "speedbutton7:", STRN("cruise control (speed)") },
|
|
{ "speedbutton8:", STRN("cruise control (speed)") },
|
|
{ "speedbutton9:", STRN("cruise control (speed)") },
|
|
{ "distancecounter_sw:", STRN("distance counter") },
|
|
{ "dirkey:", STRN("reverser") },
|
|
{ "dirbackward_bt:", STRN("reverser") },
|
|
{ "dirforward_bt:", STRN("reverser") },
|
|
{ "dirneutral_bt:", STRN("reverser") },
|
|
{ "brakectrl:", STRN("train brake") },
|
|
{ "localbrake:", STRN("independent brake") },
|
|
{ "manualbrake:", STRN("manual brake") },
|
|
{ "alarmchain:", STRN("emergency brake") },
|
|
{ "brakeprofile_sw:", STRN("brake acting speed") },
|
|
{ "brakeprofileg_sw:", STRN("brake acting speed: cargo") },
|
|
{ "brakeprofiler_sw:", STRN("brake acting speed: rapid") },
|
|
{ "brakeopmode_sw", STRN("brake operation mode") },
|
|
{ "maxcurrent_sw:", STRN("motor overload relay threshold") },
|
|
{ "waterpump_sw:", STRN("water pump") },
|
|
{ "waterpumpbreaker_sw:", STRN("water pump breaker") },
|
|
{ "waterheater_sw:", STRN("water heater") },
|
|
{ "waterheaterbreaker_sw:", STRN("water heater breaker") },
|
|
{ "watercircuitslink_sw:", STRN("water circuits link") },
|
|
{ "fuelpump_sw:", STRN("fuel pump") },
|
|
{ "oilpump_sw:", STRN("oil pump") },
|
|
{ "oilfuelpump_sw:", STRN("oil and fuel pumps") },
|
|
{ "motorblowersfront_sw:", STRN("motor blowers A") },
|
|
{ "motorblowersrear_sw:", STRN("motor blowers B") },
|
|
{ "motorblowersalloff_sw:", STRN("all motor blowers") },
|
|
{ "coolingfans_sw:", STRN("cooling fans") },
|
|
{ "main_off_bt:", STRN("line breaker") },
|
|
{ "main_on_bt:", STRN("line breaker") },
|
|
{ "security_reset_bt:", STRN("alerter") },
|
|
{ "shp_reset_bt:", STRN("shp") },
|
|
{ "releaser_bt:", STRN("independent brake releaser") },
|
|
{ "sand_bt:", STRN("sandbox") },
|
|
{ "antislip_bt:", STRN("wheelspin brake") },
|
|
{ "horn_bt:", STRN("horn") },
|
|
{ "hornlow_bt:", STRN("low tone horn") },
|
|
{ "hornhigh_bt:", STRN("high tone horn") },
|
|
{ "whistle_bt:", STRN("whistle") },
|
|
{ "fuse_bt:", STRN("motor overload relay reset") },
|
|
{ "converterfuse_bt:", STRN("converter overload relay reset") },
|
|
{ "stlinoff_bt:", STRN("motor connectors") },
|
|
{ "doorleftpermit_sw:", STRN("left door (permit)") },
|
|
{ "doorrightpermit_sw:", STRN("right door (permit)") },
|
|
{ "doorpermitpreset_sw:", STRN("door (permit)") },
|
|
{ "door_left_sw:", STRN("left door") },
|
|
{ "door_right_sw:", STRN("right door") },
|
|
{ "doorlefton_sw:", STRN("left door (open)") },
|
|
{ "doorrighton_sw:", STRN("right door (open)") },
|
|
{ "doorleftoff_sw:", STRN("left door (close)") },
|
|
{ "doorrightoff_sw:", STRN("right door (close)") },
|
|
{ "doorallon_sw:", STRN("all doors (open)") },
|
|
{ "dooralloff_sw:", STRN("all doors (close)") },
|
|
{ "doorstep_sw:", STRN("doorstep") },
|
|
{ "doormode_sw", STRN("door control mode") },
|
|
{ "departure_signal_bt:", STRN("departure signal") },
|
|
{ "upperlight_sw:", STRN("upper headlight") },
|
|
{ "leftlight_sw:", STRN("left headlight") },
|
|
{ "rightlight_sw:", STRN("right headlight") },
|
|
{ "dimheadlights_sw:", STRN("headlights dimmer") },
|
|
{ "moderndimmer_sw:", STRN("headlights dimmer") },
|
|
{ "leftend_sw:", STRN("left marker light") },
|
|
{ "rightend_sw:", STRN("right marker light") },
|
|
{ "lights_sw:", STRN("light pattern") },
|
|
{ "rearupperlight_sw:", STRN("rear upper headlight") },
|
|
{ "rearleftlight_sw:", STRN("rear left headlight") },
|
|
{ "rearrightlight_sw:", STRN("rear right headlight") },
|
|
{ "rearleftend_sw:", STRN("rear left marker light") },
|
|
{ "rearrightend_sw:", STRN("rear right marker light") },
|
|
{ "compressor_sw:", STRN("compressor") },
|
|
{ "compressorlocal_sw:", STRN("local compressor") },
|
|
{ "converter_sw:", STRN("converter") },
|
|
{ "converterlocal_sw:", STRN("local converter") },
|
|
{ "converteroff_sw:", STRN("converter") },
|
|
{ "main_sw:", STRN("line breaker") },
|
|
{ "radio_sw:", STRN("radio") },
|
|
{ "radiochannel_sw:", STRN("radio channel") },
|
|
{ "radiochannelprev_sw:", STRN("radio channel") },
|
|
{ "radiochannelnext_sw:", STRN("radio channel") },
|
|
{ "radiotest_sw:", STRN("radiostop test") },
|
|
{ "radiostop_sw:", STRN("radiostop") },
|
|
{ "radiocall3_sw:", STRN("radio call 3") },
|
|
{ "radiovolume_sw:", STRN("radio volume") },
|
|
{ "radiovolumenext_sw:", STRN("radio volume") },
|
|
{ "radiovolumeprev_sw:", STRN("radio volume") },
|
|
{ "pantfront_sw:", STRN("pantograph A") },
|
|
{ "pantrear_sw:", STRN("pantograph B") },
|
|
{ "pantfrontoff_sw:", STRN("pantograph A") },
|
|
{ "pantrearoff_sw:", STRN("pantograph B") },
|
|
{ "pantalloff_sw:", STRN("all pantographs") },
|
|
{ "pantselected_sw:", STRN("selected pantograph") },
|
|
{ "pantselectedoff_sw:", STRN("selected pantograph") },
|
|
{ "pantselect_sw:", STRN("selected pantograph") },
|
|
{ "pantvalves_sw:", STRN("selected pantograph") },
|
|
{ "pantvalvesoff_bt:", STRN("all pantographs down") },
|
|
{ "pantvalvesupdate_bt:", STRN("selected pantographs up") },
|
|
{ "pantcompressor_sw:", STRN("pantograph compressor") },
|
|
{ "pantcompressorvalve_sw:", STRN("pantograph 3 way valve") },
|
|
{ "trainheating_sw:", STRN("heating") },
|
|
{ "signalling_sw:", STRN("braking indicator") },
|
|
{ "door_signalling_sw:", STRN("door locking") },
|
|
{ "nextcurrent_sw:", STRN("current indicator source") },
|
|
{ "instrumentlight_sw:", STRN("instrument light") },
|
|
{ "dashboardlight_sw:", STRN("dashboard light") },
|
|
{ "timetablelight_sw:", STRN("timetable light") },
|
|
{ "cablight_sw:", STRN("interior light") },
|
|
{ "cablightdim_sw:", STRN("interior light dimmer") },
|
|
{ "compartmentlights_sw:", STRN("compartment lights") },
|
|
{ "compartmentlightsoff_sw:", STRN("compartment lights") },
|
|
{ "compartmentlightson_sw:", STRN("compartment lights") },
|
|
{ "couplingdisconnect_sw:", STRN("coupling") },
|
|
{ "battery_sw:", STRN("battery") },
|
|
{ "batteryon_sw:", STRN("battery") },
|
|
{ "batteryoff_sw:", STRN("battery") },
|
|
{ "epbrake_bt:", STRN("ep brake") },
|
|
{ "relayreset1_bt:", STRN("relay reset") },
|
|
{ "relayreset2_bt:", STRN("relay reset") },
|
|
{ "relayreset3_bt:", STRN("relay reset") },
|
|
{ "springbrakeoff_bt:", STRN("spring brake") },
|
|
{ "springbrakeon_bt:", STRN("spring brake") },
|
|
{ "springbraketoggle_bt:", STRN("spring brake") },
|
|
{ "universalbrake1_bt:", STRN("train brake") },
|
|
{ "universalbrake2_bt:", STRN("train brake") },
|
|
{ "universalbrake3_bt:", STRN("train brake") },
|
|
{"universal0:", STRN("interactive part")},
|
|
{"universal1:", STRN("interactive part")},
|
|
{"universal2:", STRN("interactive part")},
|
|
{"universal3:", STRN("interactive part")},
|
|
{"universal4:", STRN("interactive part")},
|
|
{"universal5:", STRN("interactive part")},
|
|
{"universal6:", STRN("interactive part")},
|
|
{"universal7:", STRN("interactive part")},
|
|
{"universal8:", STRN("interactive part")},
|
|
{"universal9:", STRN("interactive part")},
|
|
{"universal10:", STRN("interactive part")},
|
|
{"universal11:", STRN("interactive part")},
|
|
{"universal12:", STRN("interactive part")},
|
|
{"universal13:", STRN("interactive part")},
|
|
{"universal14:", STRN("interactive part")},
|
|
{"universal15:", STRN("interactive part")},
|
|
{"universal16:", STRN("interactive part")},
|
|
{"universal17:", STRN("interactive part")},
|
|
{"universal18:", STRN("interactive part")},
|
|
{"universal19:", STRN("interactive part")},
|
|
{"universal20:", STRN("interactive part")},
|
|
{"universal21:", STRN("interactive part")},
|
|
{"universal22:", STRN("interactive part")},
|
|
{"universal23:", STRN("interactive part")},
|
|
{"universal24:", STRN("interactive part")},
|
|
{"universal25:", STRN("interactive part")},
|
|
{"universal26:", STRN("interactive part")},
|
|
{"universal27:", STRN("interactive part")},
|
|
{"universal28:", STRN("interactive part")},
|
|
{"universal29:", STRN("interactive part")},
|
|
{ "wipers_sw:", STRN("wipers mode selector") },
|
|
};
|
|
|
|
auto const it = cabcontrols_labels.find( Label );
|
|
return it != cabcontrols_labels.end() ? lookup_s(it->second) : "";
|
|
}
|
|
|
|
const std::string& locale::coupling_name(int c)
|
|
{
|
|
static std::unordered_map<coupling, std::string> coupling_names =
|
|
{
|
|
{ coupling::faux, STRN("faux") },
|
|
{ coupling::coupler, STRN("coupler") },
|
|
{ coupling::brakehose, STRN("brake hose") },
|
|
{ coupling::control, STRN("control") },
|
|
{ coupling::highvoltage, STRN("high voltage") },
|
|
{ coupling::gangway, STRN("gangway") },
|
|
{ coupling::mainhose, STRN("main hose") },
|
|
{ coupling::heating, STRN("heating") },
|
|
{ coupling::permanent, STRN("permanent") },
|
|
{ coupling::power24v, STRN("power 24V") },
|
|
{ coupling::power110v, STRN("power 110V") },
|
|
{ coupling::power3x400v, STRN("power 3x400V") },
|
|
};
|
|
|
|
static std::string unknown(STRN("unknown"));
|
|
|
|
auto it = coupling_names.find(static_cast<coupling>(c));
|
|
if (it != coupling_names.end())
|
|
return lookup_s(it->second);
|
|
else
|
|
return lookup_s(unknown);
|
|
}
|
|
|
|
locale Translations;
|