OpenTTD Source: src/cargo_type.h Source File

OpenTTD Source 14.0-beta1

cargo_type.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 <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef CARGO_TYPE_H
11 #define CARGO_TYPE_H
12
13 #include "core/enum_type.hpp"
14
20 typedef byte CargoID;
21
23 enum CargoType {
24 /* Temperate */
25 CT_PASSENGERS = 0,
26 CT_COAL = 1,
27 CT_MAIL = 2,
28 CT_OIL = 3,
29 CT_LIVESTOCK = 4,
30 CT_GOODS = 5,
31 CT_GRAIN = 6,
32 CT_WOOD = 7,
33 CT_IRON_ORE = 8,
34 CT_STEEL = 9,
35 CT_VALUABLES = 10,
36
37 /* Arctic */
38 CT_WHEAT = 6,
39 CT_HILLY_UNUSED = 8,
40 CT_PAPER = 9,
41 CT_GOLD = 10,
42 CT_FOOD = 11,
43
44 /* Tropic */
45 CT_RUBBER = 1,
46 CT_FRUIT = 4,
47 CT_MAIZE = 6,
48 CT_COPPER_ORE = 8,
49 CT_WATER = 9,
50 CT_DIAMONDS = 10,
51
52 /* Toyland */
53 CT_SUGAR = 1,
54 CT_TOYS = 3,
55 CT_BATTERIES = 4,
56 CT_CANDY = 5,
57 CT_TOFFEE = 6,
58 CT_COLA = 7,
59 CT_COTTON_CANDY = 8,
60 CT_BUBBLES = 9,
61 CT_PLASTIC = 10,
62 CT_FIZZY_DRINKS = 11,
63
64 CT_INVALID = 0xFF,
65 };
66
67 static const CargoID NUM_ORIGINAL_CARGO = 12;
68 static const CargoID NUM_CARGO = 64;
69
70 /* CARGO_AUTO_REFIT and CARGO_NO_REFIT are stored in save-games for refit-orders, so should not be changed. */
71 static const CargoID CARGO_AUTO_REFIT = 0xFD;
72 static const CargoID CARGO_NO_REFIT = 0xFE;
73
74 static const CargoID INVALID_CARGO = UINT8_MAX;
75
80 namespace CargoFilterCriteria {
81 static constexpr CargoID CF_ANY = NUM_CARGO;
82 static constexpr CargoID CF_NONE = NUM_CARGO + 1;
83 static constexpr CargoID CF_ENGINES = NUM_CARGO + 2;
84 static constexpr CargoID CF_FREIGHT = NUM_CARGO + 3;
85 };
86
88 inline bool IsValidCargoType(CargoType t) { return t != CT_INVALID; }
90 inline bool IsValidCargoID(CargoID t) { return t != INVALID_CARGO; }
91
92 typedef uint64_t CargoTypes;
93
94 static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT64_MAX;
95
97 struct CargoArray : std::array<uint, NUM_CARGO> {
102 template <typename T>
103 inline const T GetSum() const
104 {
105 return std::reduce(this->begin(), this->end(), T{});
106 }
107
112 inline uint GetCount() const
113 {
114 return std::count_if(this->begin(), this->end(), [](uint amount) { return amount != 0; });
115 }
116 };
117
118
120 enum class SourceType : byte {
121 Industry,
122 Town,
123 Headquarters,
124 };
125
126 typedef uint16_t SourceID;
127 static const SourceID INVALID_SOURCE = 0xFFFF;
128
129 #endif /* CARGO_TYPE_H */
CargoType
CargoType
Available types of cargo.
Definition: cargo_type.h:23
CargoArray::GetSum
const T GetSum() const
Get the sum of all cargo amounts.
Definition: cargo_type.h:103
IsValidCargoType
bool IsValidCargoType(CargoType t)
Test whether cargo type is not CT_INVALID.
Definition: cargo_type.h:88
CARGO_NO_REFIT
static const CargoID CARGO_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-renew).
Definition: cargo_type.h:72
CargoArray::GetCount
uint GetCount() const
Get the amount of cargos that have an amount.
Definition: cargo_type.h:112
CargoFilterCriteria::CF_ENGINES
static constexpr CargoID CF_ENGINES
Show only engines (for rail vehicles only)
Definition: cargo_type.h:83
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:97
CargoFilterCriteria::CF_NONE
static constexpr CargoID CF_NONE
Show only items which do not carry cargo (e.g. train engines)
Definition: cargo_type.h:82
SourceID
uint16_t SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
Definition: cargo_type.h:126
SourceType::Industry
@ Industry
Source/destination is an industry.
SourceType::Town
@ Town
Source/destination is a town.
CARGO_AUTO_REFIT
static const CargoID CARGO_AUTO_REFIT
Automatically choose cargo type when doing auto refitting.
Definition: cargo_type.h:71
SourceType
SourceType
Types of cargo source and destination.
Definition: cargo_type.h:120
INVALID_SOURCE
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
Definition: cargo_type.h:127
SourceType::Headquarters
@ Headquarters
Source/destination are company headquarters.
enum_type.hpp
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:90
NUM_ORIGINAL_CARGO
static const CargoID NUM_ORIGINAL_CARGO
Original number of cargo types.
Definition: cargo_type.h:67
NUM_CARGO
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Definition: cargo_type.h:68
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:64
CargoFilterCriteria::CF_FREIGHT
static constexpr CargoID CF_FREIGHT
Show only vehicles which carry any freight (non-passenger) cargo.
Definition: cargo_type.h:84
CargoFilterCriteria
Special cargo filter criteria.
Definition: cargo_type.h:80
CargoFilterCriteria::CF_ANY
static constexpr CargoID CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
Definition: cargo_type.h:81