OpenTTD Source: src/base_consist.h Source File

OpenTTD Source 15.3

base_consist.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef BASE_CONSIST_H
11#define BASE_CONSIST_H
12
13#include "core/enum_type.hpp"
14#include "order_type.h"
15#include "timer/timer_game_tick.h"
16
18 enum class VehicleFlag : uint8_t {
19 LoadingFinished = 0,
20 CargoUnloading = 1,
21 BuiltAsPrototype = 2,
22 TimetableStarted = 3,
23 AutofillTimetable = 4,
24 AutofillPreserveWaitTime = 5,
25 StopLoading = 6,
26 PathfinderLost = 7,
27 ServiceIntervalIsCustom = 8,
28 ServiceIntervalIsPercent = 9,
29};
30using VehicleFlags = EnumBitSet<VehicleFlag, uint16_t>;
31
33 struct BaseConsist {
34 std::string name{};
35
36 /* Used for timetabling. */
37 TimerGameTick::Ticks current_order_time{};
38 TimerGameTick::Ticks lateness_counter{};
39 TimerGameTick::TickCounter timetable_start{};
40
41 TimerGameTick::TickCounter depot_unbunching_last_departure{};
42 TimerGameTick::TickCounter depot_unbunching_next_departure{};
43 TimerGameTick::Ticks round_trip_time;
44
45 uint16_t service_interval = 0;
46
47 VehicleOrderID cur_real_order_index = 0;
48 VehicleOrderID cur_implicit_order_index = 0;
49
50 VehicleFlags vehicle_flags{};
51
52 virtual ~BaseConsist() = default;
53
54 void CopyConsistPropertiesFrom(const BaseConsist *src);
55 void ResetDepotUnbunching();
56};
57
58#endif /* BASE_CONSIST_H */
VehicleFlag
VehicleFlag
Bit numbers in Vehicle::vehicle_flags.
Definition base_consist.h:18
VehicleFlag::PathfinderLost
@ PathfinderLost
Vehicle's pathfinder is lost.
VehicleFlag::StopLoading
@ StopLoading
Don't load anymore during the next load cycle.
VehicleFlag::AutofillTimetable
@ AutofillTimetable
Whether the vehicle should fill in the timetable automatically.
VehicleFlag::ServiceIntervalIsCustom
@ ServiceIntervalIsCustom
Service interval is custom.
VehicleFlag::ServiceIntervalIsPercent
@ ServiceIntervalIsPercent
Service interval is percent.
VehicleFlag::BuiltAsPrototype
@ BuiltAsPrototype
Vehicle is a prototype (accepted as exclusive preview).
VehicleFlag::LoadingFinished
@ LoadingFinished
Vehicle has finished loading.
VehicleFlag::CargoUnloading
@ CargoUnloading
Vehicle is unloading cargo.
VehicleFlag::TimetableStarted
@ TimetableStarted
Whether the vehicle has started running on the timetable yet.
VehicleFlag::AutofillPreserveWaitTime
@ AutofillPreserveWaitTime
Whether non-destructive auto-fill should preserve waiting times.
EnumBitSet< VehicleFlag, uint16_t >
TimerGameTick::TickCounter
uint64_t TickCounter
The type that the tick counter is stored in.
Definition timer_game_tick.h:25
TimerGameTick::Ticks
int32_t Ticks
The type to store ticks in.
Definition timer_game_tick.h:24
enum_type.hpp
Type (helpers) for enums.
order_type.h
Types related to orders.
VehicleOrderID
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition order_type.h:18
BaseConsist
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition base_consist.h:33
BaseConsist::name
std::string name
Name of vehicle.
Definition base_consist.h:34
BaseConsist::current_order_time
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
Definition base_consist.h:37
BaseConsist::depot_unbunching_next_departure
TimerGameTick::TickCounter depot_unbunching_next_departure
When the vehicle will next try to leave its unbunching depot.
Definition base_consist.h:42
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition base_consist.h:47
BaseConsist::round_trip_time
TimerGameTick::Ticks round_trip_time
How many ticks for a single circumnavigation of the orders.
Definition base_consist.h:43
BaseConsist::vehicle_flags
VehicleFlags vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition base_consist.h:50
BaseConsist::depot_unbunching_last_departure
TimerGameTick::TickCounter depot_unbunching_last_departure
When the vehicle last left its unbunching depot.
Definition base_consist.h:41
BaseConsist::cur_implicit_order_index
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition base_consist.h:48
BaseConsist::timetable_start
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
Definition base_consist.h:39
BaseConsist::lateness_counter
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
Definition base_consist.h:38
BaseConsist::service_interval
uint16_t service_interval
The interval for (automatic) servicing; either in days or %.
Definition base_consist.h:45
BaseConsist::CopyConsistPropertiesFrom
void CopyConsistPropertiesFrom(const BaseConsist *src)
Copy properties of other BaseConsist.
Definition base_consist.cpp:22
BaseConsist::ResetDepotUnbunching
void ResetDepotUnbunching()
Resets all the data used for depot unbunching.
Definition base_consist.cpp:49
timer_game_tick.h
Definition of the tick-based game-timer.