OpenTTD Source 20260711-master-g3fb3006dff
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
9
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
30
35 CompanyID company;
36 uint32_t index;
37
39
40 bool Valid() const { return this->type < VehicleListType::End; }
41
42 constexpr CompanyID ToCompanyID() const { assert(this->type == VehicleListType::Company); return CompanyID(this->index); }
43 constexpr DestinationID ToDestinationID() const { assert(this->type == VehicleListType::Depot); return DestinationID(this->index); }
44 constexpr GroupID ToGroupID() const { assert(this->type == VehicleListType::Group); return GroupID(this->index); }
45 constexpr StationID ToStationID() const { assert(this->type == VehicleListType::Station); return StationID(this->index); }
46 constexpr VehicleID ToVehicleID() const { assert(this->type == VehicleListType::VehicleSharedOrders); 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
60
62 type(type), vtype(vtype), company(company), index(index.base()) {}
63
64 VehicleListIdentifier() = default;
65};
66
68typedef 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 */
Types related to companies.
A type is considered 'convertible through base()' when it has a 'base()' function that returns someth...
Types of a group.
Types related to orders.
Types related to stations.
Group data.
Definition group.h:76
Station data structure.
The information about a vehicle list.
Definition vehiclelist.h:32
VehicleListType type
The type of vehicle list.
Definition vehiclelist.h:33
CompanyID company
The company associated with this list.
Definition vehiclelist.h:35
WindowNumber ToWindowNumber() const
Pack a VehicleListIdentifier in 32 bits so it can be used as unique WindowNumber.
VehicleType vtype
The vehicle type associated with this list.
Definition vehiclelist.h:34
VehicleListIdentifier(VehicleListType type, VehicleType vtype, CompanyID company, uint index=0)
Create a simple vehicle list.
Definition vehiclelist.h:58
uint32_t index
A vehicle list type specific index.
Definition vehiclelist.h:36
Number to differentiate different windows of the same class.
Types related to tiles.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
Types related to vehicles.
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF > VehicleID
The type all our vehicle IDs have.
VehicleType
Available vehicle types.
uint GetUnitNumberDigits(VehicleList &vehicles)
Get the number of digits the biggest unit number of a set of vehicles has.
std::vector< const Vehicle * > VehicleList
A list of vehicles.
Definition vehiclelist.h:68
void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine_list, VehicleList *wagon_list, bool individual_wagons=false)
Generate a list of vehicles inside a depot.
bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &identifier)
Generate a list of vehicles based on window type.
VehicleListType
Vehicle List type flags.
Definition vehiclelist.h:22
@ Group
Index is the group.
Definition vehiclelist.h:27
@ Company
Index is the company.
Definition vehiclelist.h:23
@ Station
Index is the station.
Definition vehiclelist.h:25
@ End
End marker.
Definition vehiclelist.h:28
@ Depot
Index is the destination (station for hangar of aircraft, depot for others).
Definition vehiclelist.h:26
@ VehicleSharedOrders
Index is the first vehicle of the shared orders.
Definition vehiclelist.h:24
Types related to windows.