18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 00:22:42 +01:00
Files
maszyna/vehicle/driverorders.h
T
Hirek b35a6129bc refactor(ai): the orders of the AI are DriverOrder and DriverOrders, not the bits of TOrders
The orders of the AI driver (TOrders) were unscoped bits, summed (an order
carries Change_direction on top of Shunt), masked, and compared as numbers
(order < Obey_train, order >= Shunt).

- vehicle/driverorders.h: enum class DriverOrder (waitForOrders,
  prepareEngine, releaseEngine, changeDirection, connect, disconnect, shunt,
  looseShunt, obeyTrain, bank, jumpToFirstOrder) and DriverOrders, an
  EnumSet of them. A small header, so brakesetting.h names the orders without
  Driver.h.
- the comparisons of the numbers are the sets they meant: the orders from
  shunt up are movingOrders, those from obeyTrain up trainOrders;
  SingleOrder() gives the order to a switch, where a sum of several matches
  no case, as it did
- the texts of the scenery commands (Shunt, Obey_train...) and of the
  translations are unchanged; only the C++ names changed

No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b.
2026-11-28 13:43:45 +01:00

50 lines
2.0 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/.
*/
// the orders of the AI driver: a temporary operation (preparing the engine, changing the direction, coupling) and the
// way it drives (shunting, a train run), which an order can carry together (changeDirection on top of shunt)
#pragma once
#include "utilities/enumset.h"
enum class DriverOrder : unsigned
{
waitForOrders = 0, // czekanie na dostarczenie następnych rozkazów
// operacje tymczasowe
prepareEngine = 1 << 0, // włączenie silnika
releaseEngine = 1 << 1, // wyłączenie silnika
changeDirection = 1 << 2, // zmiana kierunku (bez skanowania sygnalizacji)
connect = 1 << 3, // podłączanie wagonów (z częściowym skanowaniem sygnalizacji)
disconnect = 1 << 4, // odłączanie wagonów (bez skanowania sygnalizacji)
// jazda
shunt = 1 << 5, // tryb manewrowy
looseShunt = 1 << 6, // coupling-free shunting mode
obeyTrain = 1 << 7, // tryb pociągowy
bank = 1 << 8, // assist mode
// others
jumpToFirstOrder = 1 << 9, // zapętlenie do pierwszej pozycji
};
template <> struct IsEnumSetKind<DriverOrder> : std::true_type
{
};
using DriverOrders = EnumSet<DriverOrder>;
// the orders the old numbers of which were from shunt up (32): they move the train, by a way of driving or the jump
inline constexpr DriverOrders movingOrders{DriverOrder::shunt | DriverOrder::looseShunt | DriverOrder::obeyTrain | DriverOrder::bank |
DriverOrder::jumpToFirstOrder};
// the orders the old numbers of which were from obeyTrain up (128): the train runs, not shunting
inline constexpr DriverOrders trainOrders{DriverOrder::obeyTrain | DriverOrder::bank | DriverOrder::jumpToFirstOrder};
// the order as a single value, for a switch: a sum of several of them matches none of the cases
constexpr DriverOrder SingleOrder(DriverOrders const orders)
{
return static_cast<DriverOrder>(orders.Bits());
}