18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 14:07:06 +01:00
Files
maszyna/world/station.cpp
T
Hirek d0387753f8 refactor(physics): TMoverParameters becomes physics::Vehicle, the mover is gone
The physics of a vehicle loses the name it had from the Pascal of 2001. Done by
tools/rename/mover_to_physics.py, committed with it:

  physics/mover.h                  physics/vehicle.h
  TMoverParameters                 physics::Vehicle (in namespace physics)
  TDynamicObject::MoverParameters  physics
  mvOccupied, mvControlled         occupied, controlled (TTrain, TController)
  mvSecond, mvThird                secondUnit, thirdUnit
  mvPantographUnit                 pantographUnit
  mover, Mover, movers             physics, Physics, vehicles (locals, params)
  m_mover, othermover, currentMover, from_movers, renderMoverEventSounds
                                   m_physics, otherPhysics, currentPhysics,
                                   from_vehicles, renderPhysicsEventSounds

The code and the comments are renamed, the string literals are not: no text
the game shows, logs or looks up has changed (none had the names). The movers
of the editor, the tracks a slide moves, keep their name.

By hand: two member functions of TDynamicObject (gather_off_track_terrain,
begin_off_track) had a local mover aliasing their own MoverParameters, which
the rename made physics { *physics }; the alias is gone, they use physics->.
No other function has a renamed local meeting a renamed member (checked over
all the functions of the code before the rename).

For the branches made before it: run the script on the branch (python
tools/rename/mover_to_physics.py, from the root of the repository) before
merging it with this one, and the names don't conflict. It can be run again;
the second time it changes nothing.

The class is the same as it was; breaking it into its parts (braking,
electrics, controls, load) and making its data private are the next stages.

No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
2026-11-28 23:56:46 +01:00

90 lines
3.4 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 "world/station.h"
#include "utilities/utilities.h"
#include "vehicle/DynObj.h"
#include "world/mtable.h"
#include "physics/vehicle.h"
namespace simulation {
basic_station Station;
}
// exchanges load with consist attached to specified vehicle, operating on specified schedule
double
basic_station::update_load( TDynamicObject *First, Mtable::TTrainParameters &Schedule, int const Platform ) const {
// TODO: filter out maintenance stops when determining first and last stop
auto const firststop { Schedule.StationIndex == 1 };
auto const laststop { Schedule.StationIndex == Schedule.StationCount };
// HACK: determine whether current station is a (small) stop from the presence of "po" at the name end
auto const stationname { Schedule.TimeTable[ Schedule.StationIndex ].StationName };
auto const stationequipment { Schedule.TimeTable[ Schedule.StationIndex ].StationWare };
auto const trainstop {stationname.ends_with("po") || contains( stationequipment, "po" ) };
auto const maintenancestop { ( contains( stationequipment, "pt" ) ) };
// train stops exchange smaller groups than regular stations
// NOTE: this is crude and unaccurate, but for now will do
auto const stationsizemodifier { ( trainstop ? 1.0 : 2.0 ) };
// go through all vehicles and update their load
// NOTE: for the time being we limit ourselves to passenger-carrying cars only
auto exchangetime { 0.f };
auto *vehicle { First };
while( vehicle != nullptr ) {
auto &parameters { *vehicle->physics };
if( parameters.Doors.range == 0.f ) { goto next; }
if( parameters.LoadType.name.empty() ) {
// (try to) set the cargo type for empty cars
parameters.LoadAmount = 0.f; // safety measure against edge cases
parameters.AssignLoad( "passengers" );
parameters.ComputeMass();
}
if( parameters.LoadType.name == "passengers" ) {
// NOTE: for the time being we're doing simple, random load change calculation
// TODO: exchange driven by station parameters and time of the day
auto unloadcount = static_cast<int>(
parameters.DamageFlag.HasAll(VehicleDamage::derailed) ? parameters.LoadAmount :
laststop ? parameters.LoadAmount :
firststop ? 0 :
maintenancestop ? 0 :
std::min<float>(
parameters.LoadAmount,
static_cast<float>(Random( parameters.MaxLoad * 0.15f * stationsizemodifier )) ) );
auto loadcount = static_cast<int>(
parameters.DamageFlag.HasAll(VehicleDamage::derailed) ? 0 :
laststop ? 0 :
maintenancestop ? 0 :
Random( parameters.MaxLoad * 0.15f * stationsizemodifier ) );
if( true == firststop ) {
// larger group at the initial station
loadcount *= 2;
}
if( unloadcount > 0 || loadcount > 0 ) {
vehicle->LoadExchange( unloadcount, loadcount, Platform );
exchangetime = std::max( exchangetime, vehicle->LoadExchangeTime() );
}
}
next:
vehicle = vehicle->Next();
}
return exchangetime;
}