OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef CARGO_TYPE_H
11#define CARGO_TYPE_H
12
13#include "core/label_type.hpp"
14#include "core/enum_type.hpp"
15
18
22enum CargoType : uint8_t {};
24
25
30
31/* Temperate */
32static constexpr CargoLabel CT_PASSENGERS{"PASS"};
33static constexpr CargoLabel CT_COAL{"COAL"};
34static constexpr CargoLabel CT_MAIL{"MAIL"};
35static constexpr CargoLabel CT_OIL{"OIL_"};
36static constexpr CargoLabel CT_LIVESTOCK{"LVST"};
37static constexpr CargoLabel CT_GOODS{"GOOD"};
38static constexpr CargoLabel CT_GRAIN{"GRAI"};
39static constexpr CargoLabel CT_WOOD{"WOOD"};
40static constexpr CargoLabel CT_IRON_ORE{"IORE"};
41static constexpr CargoLabel CT_STEEL{"STEL"};
42static constexpr CargoLabel CT_VALUABLES{"VALU"};
43
44/* Arctic */
45static constexpr CargoLabel CT_WHEAT{"WHEA"};
46static constexpr CargoLabel CT_PAPER{"PAPR"};
47static constexpr CargoLabel CT_GOLD{"GOLD"};
48static constexpr CargoLabel CT_FOOD{"FOOD"};
49
50/* Tropic */
51static constexpr CargoLabel CT_RUBBER{"RUBR"};
52static constexpr CargoLabel CT_FRUIT{"FRUT"};
53static constexpr CargoLabel CT_MAIZE{"MAIZ"};
54static constexpr CargoLabel CT_COPPER_ORE{"CORE"};
55static constexpr CargoLabel CT_WATER{"WATR"};
56static constexpr CargoLabel CT_DIAMONDS{"DIAM"};
57
58/* Toyland */
59static constexpr CargoLabel CT_SUGAR{"SUGR"};
60static constexpr CargoLabel CT_TOYS{"TOYS"};
61static constexpr CargoLabel CT_BATTERIES{"BATT"};
62static constexpr CargoLabel CT_CANDY{"SWET"};
63static constexpr CargoLabel CT_TOFFEE{"TOFF"};
64static constexpr CargoLabel CT_COLA{"COLA"};
65static constexpr CargoLabel CT_COTTON_CANDY{"CTCD"};
66static constexpr CargoLabel CT_BUBBLES{"BUBL"};
67static constexpr CargoLabel CT_PLASTIC{"PLST"};
68static constexpr CargoLabel CT_FIZZY_DRINKS{"FZDR"};
70
72static constexpr CargoLabel CT_NONE = CT_PASSENGERS;
73
74static constexpr CargoLabel CT_INVALID{"\xFF\xFF\xFF\xFF"};
75
76static constexpr CargoType NUM_ORIGINAL_CARGO{12};
77static constexpr CargoType NUM_CARGO{64};
78
79/* CARGO_AUTO_REFIT and CARGO_NO_REFIT are stored in save-games for refit-orders, so should not be changed. */
80static constexpr CargoType CARGO_AUTO_REFIT{0xFD};
81static constexpr CargoType CARGO_NO_REFIT{0xFE};
82
83static constexpr CargoType INVALID_CARGO{UINT8_MAX};
84
91
97 static constexpr CargoType CF_ANY{NUM_CARGO};
98 static constexpr CargoType CF_NONE{NUM_CARGO + 1};
99 static constexpr CargoType CF_ENGINES{NUM_CARGO + 2};
100 static constexpr CargoType CF_FREIGHT{NUM_CARGO + 3};
101
102 static constexpr CargoType CF_NO_RATING{NUM_CARGO + 4};
103 static constexpr CargoType CF_SELECT_ALL{NUM_CARGO + 5};
104 static constexpr CargoType CF_EXPAND_LIST{NUM_CARGO + 6};
105};
106
112inline bool IsValidCargoType(CargoType cargo) { return cargo != INVALID_CARGO; }
113
116
117static constexpr CargoTypes ALL_CARGOTYPES{UINT64_MAX};
118
120struct CargoArray : std::array<uint, NUM_CARGO> {
125 template <typename T>
126 inline const T GetSum() const
127 {
128 return std::reduce(this->begin(), this->end(), T{});
129 }
130
135 inline uint GetCount() const
136 {
137 return std::ranges::count_if(*this, [](uint amount) { return amount != 0; });
138 }
139};
140
141#endif /* CARGO_TYPE_H */
static constexpr CargoLabel CT_INVALID
Invalid cargo type.
Definition cargo_type.h:74
Label< struct CargoLabelTag > CargoLabel
Globally unique label of a cargo type.
Definition cargo_type.h:17
static constexpr CargoLabel CT_PLASTIC
Cargo label for plastic.
Definition cargo_type.h:67
static constexpr CargoLabel CT_WATER
Cargo label for water.
Definition cargo_type.h:55
static constexpr CargoType INVALID_CARGO
Invalid marker for cargoes.
Definition cargo_type.h:83
static constexpr CargoLabel CT_RUBBER
Cargo label for rubber.
Definition cargo_type.h:51
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:112
static constexpr CargoType CARGO_AUTO_REFIT
Automatically choose cargo type when doing auto refitting.
Definition cargo_type.h:80
static constexpr CargoLabel CT_NONE
Dummy label for engines that carry no cargo; they actually carry 0 passengers.
Definition cargo_type.h:72
static constexpr CargoLabel CT_BUBBLES
Cargo label for bubbles.
Definition cargo_type.h:66
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
Definition cargo_type.h:115
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:77
static constexpr CargoLabel CT_GRAIN
Cargo label for grain.
Definition cargo_type.h:38
static constexpr CargoLabel CT_IRON_ORE
Cargo label for iron ore.
Definition cargo_type.h:40
static constexpr CargoLabel CT_COAL
Cargo label for coal.
Definition cargo_type.h:33
static constexpr CargoLabel CT_FOOD
Cargo label for food.
Definition cargo_type.h:48
static constexpr CargoType NUM_ORIGINAL_CARGO
Original number of cargo types.
Definition cargo_type.h:76
static constexpr CargoLabel CT_MAIL
Cargo label for mail.
Definition cargo_type.h:34
static constexpr CargoLabel CT_TOYS
Cargo label for toys.
Definition cargo_type.h:60
static constexpr CargoLabel CT_WOOD
Cargo label for wood.
Definition cargo_type.h:39
MixedCargoType
Mixed cargo types for definitions with cargo that can vary depending on climate.
Definition cargo_type.h:86
@ MCT_GRAIN_WHEAT_MAIZE
Cargo can be grain, wheat or maize.
Definition cargo_type.h:88
@ MCT_LIVESTOCK_FRUIT
Cargo can be livestock or fruit.
Definition cargo_type.h:87
@ MCT_VALUABLES_GOLD_DIAMONDS
Cargo can be valuables, gold or diamonds.
Definition cargo_type.h:89
static constexpr CargoLabel CT_WHEAT
Cargo label for wheat.
Definition cargo_type.h:45
static constexpr CargoLabel CT_CANDY
Cargo label for candies/sweets.
Definition cargo_type.h:62
static constexpr CargoLabel CT_GOODS
Cargo label for goods.
Definition cargo_type.h:37
static constexpr CargoLabel CT_PASSENGERS
Cargo label for passengers.
Definition cargo_type.h:32
static constexpr CargoLabel CT_MAIZE
Cargo label for maize.
Definition cargo_type.h:53
static constexpr CargoLabel CT_PAPER
Cargo label for paper.
Definition cargo_type.h:46
static constexpr CargoType CARGO_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-renew).
Definition cargo_type.h:81
static constexpr CargoLabel CT_LIVESTOCK
Cargo label for livestock.
Definition cargo_type.h:36
CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
static constexpr CargoLabel CT_VALUABLES
Cargo label for valuables.
Definition cargo_type.h:42
static constexpr CargoLabel CT_BATTERIES
Cargo label for batteries.
Definition cargo_type.h:61
static constexpr CargoLabel CT_TOFFEE
Cargo label for toffee.
Definition cargo_type.h:63
static constexpr CargoLabel CT_OIL
Cargo label for oil.
Definition cargo_type.h:35
static constexpr CargoLabel CT_GOLD
Cargo label for gold.
Definition cargo_type.h:47
static constexpr CargoLabel CT_FRUIT
Cargo label for fruits.
Definition cargo_type.h:52
static constexpr CargoLabel CT_SUGAR
Cargo label for sugar.
Definition cargo_type.h:59
static constexpr CargoLabel CT_FIZZY_DRINKS
Cargo label for fizzy drinks.
Definition cargo_type.h:68
static constexpr CargoLabel CT_DIAMONDS
Cargo label for diamonds.
Definition cargo_type.h:56
static constexpr CargoLabel CT_STEEL
Cargo label for steel.
Definition cargo_type.h:41
static constexpr CargoLabel CT_COLA
Cargo label for cola.
Definition cargo_type.h:64
static constexpr CargoLabel CT_COPPER_ORE
Cargo label for copper ore.
Definition cargo_type.h:54
static constexpr CargoLabel CT_COTTON_CANDY
Cargo label for cotton candies.
Definition cargo_type.h:65
Enum-as-bit-set wrapper.
#define T
Climate temperate.
Definition engines.h:91
Type (helpers) for enums.
#define DECLARE_INCREMENT_DECREMENT_OPERATORS(enum_type)
For some enums it is useful to have pre/post increment/decrement operators.
Definition enum_type.hpp:86
A type for 4 character labels/tags/ids in files that should be read/shown as is.
Special cargo filter criteria.
Definition cargo_type.h:96
static constexpr CargoType CF_FREIGHT
Show only vehicles which carry any freight (non-passenger) cargo.
Definition cargo_type.h:100
static constexpr CargoType CF_NONE
Show only items which do not carry cargo (e.g. train engines).
Definition cargo_type.h:98
static constexpr CargoType CF_ENGINES
Show only engines (for rail vehicles only).
Definition cargo_type.h:99
static constexpr CargoType CF_EXPAND_LIST
Expand list to show all items (station list).
Definition cargo_type.h:104
static constexpr CargoType CF_ANY
Show all items independent of carried cargo (i.e. no filtering).
Definition cargo_type.h:97
static constexpr CargoType CF_NO_RATING
Show items with no rating (station list).
Definition cargo_type.h:102
static constexpr CargoType CF_SELECT_ALL
Select all items (station list).
Definition cargo_type.h:103
Class for storing amounts of cargo.
Definition cargo_type.h:120
uint GetCount() const
Get the amount of cargos that have an amount.
Definition cargo_type.h:135
const T GetSum() const
Get the sum of all cargo amounts.
Definition cargo_type.h:126
A four character label/tag/id.