18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 20:05:23 +01:00
Files
maszyna/vehicle/crew.h
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

83 lines
3.7 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 <string>
#include <string_view>
namespace physics { class Vehicle; }
// a driver put in a vehicle, or taken off it, while the scenario runs (eu07/maszyna#510): the command of a
// putvalues event
// event <name> putvalues <delay> none 0 0 0 Crew:<vehicle> <cab> <flags> endevent
// with the name of the vehicle in the text, so the event works whatever sets it off (a key, an event
// launcher), the cab in the first value: 1 an AI driver in cab A, -1 in cab B, 0 nobody, and the second value
// reserved (0). "Crew:" with no name is for the vehicle which set the event off.
// here are the parts which need no vehicle of the game: reading the command, deciding what to do about it,
// and the state a train is left in when its driver goes. the game's side of it is in crewchange.h
namespace crew {
// what the text of the command starts with, in this very case (the commands of the events are case sensitive)
inline constexpr std::string_view command_prefix{"Crew:"};
// whether the text of a putvalues event is the crew command
bool is_command(std::string_view Text);
// the command as the event gives it
struct request {
std::string vehicle; // as the scenery keeps the names, in lower case; empty: the vehicle which set the event off
int cab{0}; // 1 a driver in cab A (the front one), -1 in cab B, 0 nobody
bool cab_valid{false}; // the value was one of the three
int flags{0}; // reserved, nothing reads it yet
};
// reads the command from the text of the event and its two values
request parse(std::string_view Text, double Cab, double Flags);
// what the command finds in the vehicle
struct vehicle_state {
bool has_cab{false}; // the type of the vehicle has a driver's cab; a road vehicle or a boat counts as having one
bool has_driver{false};
bool driver_is_ai{false}; // the driver it has is the AI, not a user
bool occupied{false}; // a user sits in the vehicle, whoever drives it
bool consist_driven{false}; // another vehicle of the consist has the driver in charge of it
};
enum class action {
add_front, // an AI driver goes into cab A
add_rear, // an AI driver goes into cab B
remove, // the AI driver is taken off
nothing, // asked to take the driver off a vehicle which has none
refuse_cab, // the cab asked for is none of 1, -1, 0
refuse_user, // a user is in the vehicle, or drives it
refuse_crewed, // asked for a driver where there is one already
refuse_no_cab, // asked for a driver in a vehicle with no cab
refuse_consist_driven // asked for a driver in a consist which another vehicle's driver is in charge of
};
// what to do about the command. a user in the vehicle is never touched: neither replaced nor left without
// the driver the cab of the game works with
action decide(request const &Request, vehicle_state const &State);
// whether the action changes anything
bool changes_crew(action Action);
// the action in words, for the log
std::string_view describe(action Action);
// the state a train is left in when the driver in charge of it goes: what the AI held is let go (as when it
// hands over to a user, see handover.h), the power is off, the driver's brake valve is in the emergency position,
// so a train on the move stops and stays braked, and the cab is neither active nor occupied. the engine, the
// pantographs and the lights stay as they were. Occupied is the vehicle of the driver, Controlling the one whose
// motors it drove (the AI's occupied and mvControlling; the same one in a locomotive)
void secure(physics::Vehicle &Occupied, physics::Vehicle &Controlling);
} // namespace crew