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

fix: keep the odometers of the vehicles with a driver's cab only

every vehicle which ran got a line in the store, the wagons of the AI's trains in every scenario too. the store
records a vehicle with a driver's brake valve (BrakeHandle in the .fiz), which can show its odometer; the locomotives
and units the AI runs before a player's cab loads them still get in with their replaceable made up states. the
states already in the file stay as they are
This commit is contained in:
jerrrrycho
2026-11-09 16:12:13 +01:00
parent 729f15e878
commit acf0716a9c
5 changed files with 73 additions and 2 deletions

View File

@@ -8817,7 +8817,7 @@ vehicle_table::save_odometers() {
auto &odometers { odometer::states() };
for( auto const *vehicle : m_items ) {
if( vehicle->MoverParameters != nullptr ) {
odometers.record( vehicle->name(), vehicle->MoverParameters->Odometer );
odometer::record( odometers, vehicle->name(), vehicle->MoverParameters->HasDriverCab(), vehicle->MoverParameters->Odometer );
}
}
odometer::save();
@@ -8970,7 +8970,7 @@ vehicle_table::erase_disabled() {
// the distance the vehicle ran goes in the odometer store now, it doesn't depend on the vehicle being
// kept on the list until the next save (eu07/maszyna#72)
if( vehicle->MoverParameters != nullptr ) {
odometer::states().record( vehicle->name(), vehicle->MoverParameters->Odometer );
odometer::record( odometer::states(), vehicle->name(), vehicle->MoverParameters->HasDriverCab(), vehicle->MoverParameters->Odometer );
}
if( vehicle->MyTrack != nullptr
&& true == vehicle->MyTrack->RemoveDynamicObject(vehicle) ) {

View File

@@ -158,6 +158,12 @@ void store::record(std::string const &Vehicle, reading const &Odometer) {
m_modified = true;
}
void record(store &States, std::string const &Vehicle, bool const Drivercab, reading const &Odometer) {
if (false == Drivercab)
return;
States.record(Vehicle, Odometer);
}
void store::merge(store const &Other) {
for (auto const &[name, other] : Other.m_states) {
auto const [lookup, added] {m_states.try_emplace(name, other)};

View File

@@ -84,6 +84,13 @@ private:
bool m_modified{false};
};
// records the state of a vehicle in the store when it's one the store keeps: a vehicle with a driver's cab
// (TMoverParameters::HasDriverCab()), which can show its odometer on the cab's counter or a python screen. that
// includes the locomotives and units the AI runs before a player's cab loads them, their made up states stay
// replaceable by the cab's counter. the wagons, which make most of the AI's trains, aren't recorded; the states the
// store already holds for any of them stay as they are
void record(store &States, std::string const &Vehicle, bool Drivercab, reading const &Odometer);
// state kept in the file of the python screens before (<vehicle directory>/kilometry/<name>_przebieg.txt,
// where the screens dropped the last character of the vehicle name), when it holds a number
std::optional<double> read_legacy(std::istream &Input);