OpenTTD Source: src/vehiclelist.h Source File

OpenTTD Source 15.0-RC2

vehiclelist.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 VEHICLELIST_H
11#define VEHICLELIST_H
12
13#include "company_type.h"
14#include "group_type.h"
15#include "order_type.h"
16#include "station_type.h"
17#include "tile_type.h"
18#include "vehicle_type.h"
19#include "window_type.h"
20
22 enum VehicleListType : uint8_t {
23 VL_STANDARD,
24 VL_SHARED_ORDERS,
25 VL_STATION_LIST,
26 VL_DEPOT_LIST,
27 VL_GROUP_LIST,
28 VLT_END
29};
30
32 struct VehicleListIdentifier {
33 VehicleListType type;
34 VehicleType vtype;
35 CompanyID company;
36 uint32_t index;
37
38 WindowNumber ToWindowNumber() const;
39
40 bool Valid() const { return this->type < VLT_END; }
41
42 constexpr CompanyID ToCompanyID() const { assert(this->type == VL_STANDARD); return CompanyID(this->index); }
43 constexpr DestinationID ToDestinationID() const { assert(this->type == VL_DEPOT_LIST); return DestinationID(this->index); }
44 constexpr GroupID ToGroupID() const { assert(this->type == VL_GROUP_LIST); return GroupID(this->index); }
45 constexpr StationID ToStationID() const { assert(this->type == VL_STATION_LIST); return StationID(this->index); }
46 constexpr VehicleID ToVehicleID() const { assert(this->type == VL_SHARED_ORDERS); return VehicleID(this->index); }
47
48 constexpr void SetIndex(uint32_t index) { this->index = index; }
49 constexpr void SetIndex(ConvertibleThroughBase auto index) { this->index = index.base(); }
50
58 VehicleListIdentifier(VehicleListType type, VehicleType vtype, CompanyID company, uint index = 0) :
59 type(type), vtype(vtype), company(company), index(index) {}
60
61 VehicleListIdentifier(VehicleListType type, VehicleType vtype, CompanyID company, ConvertibleThroughBase auto index) :
62 type(type), vtype(vtype), company(company), index(index.base()) {}
63
64 VehicleListIdentifier() = default;
65};
66
68 typedef std::vector<const Vehicle *> VehicleList;
69
70bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &identifier);
71void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine_list, VehicleList *wagon_list, bool individual_wagons = false);
72uint GetUnitNumberDigits(VehicleList &vehicles);
73
74#endif /* VEHICLELIST_H */
company_type.h
Types related to companies.
ConvertibleThroughBase
A type is considered 'convertible through base()' when it has a 'base()' function that returns someth...
Definition convertible_through_base.hpp:19
group_type.h
Types of a group.
order_type.h
Types related to orders.
station_type.h
Types related to stations.
DestinationID
Definition order_type.h:21
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
VehicleListIdentifier
The information about a vehicle list.
Definition vehiclelist.h:32
VehicleListIdentifier::type
VehicleListType type
The type of vehicle list.
Definition vehiclelist.h:33
VehicleListIdentifier::company
CompanyID company
The company associated with this list.
Definition vehiclelist.h:35
VehicleListIdentifier::ToWindowNumber
WindowNumber ToWindowNumber() const
Pack a VehicleListIdentifier in 32 bits so it can be used as unique WindowNumber.
Definition vehiclelist.cpp:23
VehicleListIdentifier::vtype
VehicleType vtype
The vehicle type associated with this list.
Definition vehiclelist.h:34
VehicleListIdentifier::VehicleListIdentifier
VehicleListIdentifier(VehicleListType type, VehicleType vtype, CompanyID company, uint index=0)
Create a simple vehicle list.
Definition vehiclelist.h:58
VehicleListIdentifier::index
uint32_t index
A vehicle list type specific index.
Definition vehiclelist.h:36
WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:760
tile_type.h
Types related to tiles.
vehicle_type.h
Types related to vehicles.
VehicleID
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF > VehicleID
The type all our vehicle IDs have.
Definition vehicle_type.h:17
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
GetUnitNumberDigits
uint GetUnitNumberDigits(VehicleList &vehicles)
Get the number of digits the biggest unit number of a set of vehicles has.
Definition vehicle_gui.cpp:209
VehicleList
std::vector< const Vehicle * > VehicleList
A list of vehicles.
Definition vehiclelist.h:68
BuildDepotVehicleList
void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine_list, VehicleList *wagon_list, bool individual_wagons=false)
Generate a list of vehicles inside a depot.
Definition vehiclelist.cpp:43
GenerateVehicleSortList
bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &identifier)
Generate a list of vehicles based on window type.
Definition vehiclelist.cpp:70
VehicleListType
VehicleListType
Vehicle List type flags.
Definition vehiclelist.h:22
VL_GROUP_LIST
@ VL_GROUP_LIST
Index is the group.
Definition vehiclelist.h:27
VL_STANDARD
@ VL_STANDARD
Index is the company.
Definition vehiclelist.h:23
VL_STATION_LIST
@ VL_STATION_LIST
Index is the station.
Definition vehiclelist.h:25
VL_DEPOT_LIST
@ VL_DEPOT_LIST
Index is the destination (station for hangar of aircraft, depot for others)
Definition vehiclelist.h:26
VL_SHARED_ORDERS
@ VL_SHARED_ORDERS
Index is the first vehicle of the shared orders.
Definition vehiclelist.h:24
window_type.h
Types related to windows.