OpenTTD Source: src/cargotype.h Source File

OpenTTD Source 1.11.0-RC1

cargotype.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 CARGOTYPE_H
11 #define CARGOTYPE_H
12
13 #include "economy_type.h"
14 #include "cargo_type.h"
15 #include "gfx_type.h"
16 #include "strings_type.h"
17 #include "landscape_type.h"
18 #include <vector>
19
21 typedef uint32 CargoLabel;
22
24 enum TownEffect {
25 TE_BEGIN = 0,
26 TE_NONE = TE_BEGIN,
27 TE_PASSENGERS,
28 TE_MAIL,
29 TE_GOODS,
30 TE_WATER,
31 TE_FOOD,
32 TE_END,
33 NUM_TE = TE_END,
34 };
35
37 enum CargoClass {
38 CC_NOAVAILABLE = 0,
39 CC_PASSENGERS = 1 << 0,
40 CC_MAIL = 1 << 1,
41 CC_EXPRESS = 1 << 2,
42 CC_ARMOURED = 1 << 3,
43 CC_BULK = 1 << 4,
44 CC_PIECE_GOODS = 1 << 5,
45 CC_LIQUID = 1 << 6,
46 CC_REFRIGERATED = 1 << 7,
47 CC_HAZARDOUS = 1 << 8,
48 CC_COVERED = 1 << 9,
49 CC_SPECIAL = 1 << 15,
50 };
51
52 static const byte INVALID_CARGO = 0xFF;
53
55 struct CargoSpec {
56 uint8 bitnum;
57 CargoLabel label;
58 uint8 legend_colour;
59 uint8 rating_colour;
60 uint8 weight;
61 uint16 multiplier;
62 uint16 initial_payment;
63 uint8 transit_days[2];
64
65 bool is_freight;
66 TownEffect town_effect;
67 uint16 multipliertowngrowth;
68 uint8 callback_mask;
69
70 StringID name;
71 StringID name_single;
72 StringID units_volume;
73 StringID quantifier;
74 StringID abbrev;
75
76 SpriteID sprite;
77
78 uint16 classes;
79 const struct GRFFile *grffile;
80 const struct SpriteGroup *group;
81
82 Money current_payment;
83
88 inline CargoID Index() const
89 {
90 return this - CargoSpec::array;
91 }
92
98 inline bool IsValid() const
99 {
100 return this->bitnum != INVALID_CARGO;
101 }
102
107 static inline size_t GetArraySize()
108 {
109 return lengthof(CargoSpec::array);
110 }
111
117 static inline CargoSpec *Get(size_t index)
118 {
119 assert(index < lengthof(CargoSpec::array));
120 return &CargoSpec::array[index];
121 }
122
123 SpriteID GetCargoIcon() const;
124
125 private:
126 static CargoSpec array[NUM_CARGO];
127
128 friend void SetupCargoForClimate(LandscapeID l);
129 };
130
131 extern CargoTypes _cargo_mask;
132 extern CargoTypes _standard_cargo_mask;
133
134 void SetupCargoForClimate(LandscapeID l);
135 CargoID GetCargoIDByLabel(CargoLabel cl);
136 CargoID GetCargoIDByBitnum(uint8 bitnum);
137
138 void InitializeSortedCargoSpecs();
139 extern std::vector<const CargoSpec *> _sorted_cargo_specs;
140 extern uint8 _sorted_standard_cargo_specs_size;
141
148 static inline bool IsCargoInClass(CargoID c, CargoClass cc)
149 {
150 return (CargoSpec::Get(c)->classes & cc) != 0;
151 }
152
153 #define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = nullptr, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
154 if ((var = CargoSpec::Get(cargospec_index))->IsValid())
155 #define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
156
157 #define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, CargoTypes, cargo_bits)
158
164 #define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_cargo_specs.size() && (var = _sorted_cargo_specs[index], true) ; index++)
165
171 #define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_standard_cargo_specs_size && (var = _sorted_cargo_specs[index], true); index++)
172
173 #endif /* CARGOTYPE_H */
TE_WATER
@ TE_WATER
Cargo behaves water-like.
Definition: cargotype.h:30
INVALID_CARGO
static const byte INVALID_CARGO
Constant representing invalid cargo.
Definition: cargotype.h:52
CC_HAZARDOUS
@ CC_HAZARDOUS
Hazardous cargo (Nuclear Fuel, Explosives, etc.)
Definition: cargotype.h:47
CargoSpec::callback_mask
uint8 callback_mask
Bitmask of cargo callbacks that have to be called.
Definition: cargotype.h:68
CC_COVERED
@ CC_COVERED
Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
Definition: cargotype.h:48
CargoSpec::label
CargoLabel label
Unique label of the cargo type.
Definition: cargotype.h:57
landscape_type.h
GetCargoIDByBitnum
CargoID GetCargoIDByBitnum(uint8 bitnum)
Find the CargoID of a 'bitnum' value.
Definition: cargotype.cpp:102
CargoSpec::town_effect
TownEffect town_effect
The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
Definition: cargotype.h:66
_cargo_mask
CargoTypes _cargo_mask
Bitmask of cargo types available.
Definition: cargotype.cpp:28
CC_NOAVAILABLE
@ CC_NOAVAILABLE
No cargo class has been specified.
Definition: cargotype.h:38
CC_EXPRESS
@ CC_EXPRESS
Express cargo (Goods, Food, Candy, but also possible for passengers)
Definition: cargotype.h:41
TE_FOOD
@ TE_FOOD
Cargo behaves food/fizzy-drinks-like.
Definition: cargotype.h:31
Pool::PoolItem<&_spritegroup_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:117
InitializeSortedCargoSpecs
void InitializeSortedCargoSpecs()
Initialize the list of sorted cargo specifications.
Definition: cargotype.cpp:169
TE_NONE
@ TE_NONE
Cargo has no effect.
Definition: cargotype.h:26
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:55
CC_LIQUID
@ CC_LIQUID
Liquids (Oil, Water, Rubber)
Definition: cargotype.h:45
CargoSpec::GetCargoIcon
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
Definition: cargotype.cpp:119
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:39
CargoSpec::GetArraySize
static size_t GetArraySize()
Total number of cargospecs, both valid and invalid.
Definition: cargotype.h:107
strings_type.h
CargoLabel
uint32 CargoLabel
Globally unique label of a cargo type.
Definition: cargotype.h:21
CargoSpec::bitnum
uint8 bitnum
Cargo bit number, is INVALID_CARGO for a non-used spec.
Definition: cargotype.h:56
CargoSpec::array
static CargoSpec array[NUM_CARGO]
Array holding all CargoSpecs.
Definition: cargotype.h:126
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
TE_MAIL
@ TE_MAIL
Cargo behaves mail-like.
Definition: cargotype.h:28
TE_PASSENGERS
@ TE_PASSENGERS
Cargo behaves passenger-like.
Definition: cargotype.h:27
GetCargoIDByLabel
CargoID GetCargoIDByLabel(CargoLabel cl)
Get the cargo ID by cargo label.
Definition: cargotype.cpp:85
_sorted_standard_cargo_specs_size
uint8 _sorted_standard_cargo_specs_size
Number of standard cargo specifications stored in the _sorted_cargo_specs array.
Definition: cargotype.cpp:133
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:88
CC_SPECIAL
@ CC_SPECIAL
Special bit used for livery refit tricks instead of normal cargoes.
Definition: cargotype.h:49
NUM_TE
@ NUM_TE
Amount of town effects.
Definition: cargotype.h:33
CargoSpec::units_volume
StringID units_volume
Name of a single unit of cargo of this type.
Definition: cargotype.h:72
CargoSpec::IsValid
bool IsValid() const
Tests for validity of this cargospec.
Definition: cargotype.h:98
CargoSpec::SetupCargoForClimate
friend void SetupCargoForClimate(LandscapeID l)
Set up the default cargo types for the given landscape type.
Definition: cargotype.cpp:39
CC_PIECE_GOODS
@ CC_PIECE_GOODS
Piece goods (Livestock, Wood, Steel, Paper)
Definition: cargotype.h:44
TE_END
@ TE_END
End of town effects.
Definition: cargotype.h:32
cargo_type.h
CC_BULK
@ CC_BULK
Bulk cargo (Coal, Grain etc., Ores, Fruit)
Definition: cargotype.h:43
CargoSpec::multipliertowngrowth
uint16 multipliertowngrowth
Size of the effect.
Definition: cargotype.h:67
CargoSpec::grffile
const struct GRFFile * grffile
NewGRF where #group belongs to.
Definition: cargotype.h:79
CargoSpec::sprite
SpriteID sprite
Icon to display this cargo type, may be 0xFFF (which means to resolve an action123 chain).
Definition: cargotype.h:76
CargoSpec::weight
uint8 weight
Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
Definition: cargotype.h:60
CargoSpec::is_freight
bool is_freight
Cargo type is considered to be freight (affects train freight multiplier).
Definition: cargotype.h:65
TownEffect
TownEffect
Town growth effect when delivering cargo.
Definition: cargotype.h:24
CargoClass
CargoClass
Cargo classes.
Definition: cargotype.h:37
TE_GOODS
@ TE_GOODS
Cargo behaves goods/candy-like.
Definition: cargotype.h:29
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
CC_ARMOURED
@ CC_ARMOURED
Armoured cargo (Valuables, Gold, Diamonds)
Definition: cargotype.h:42
CC_REFRIGERATED
@ CC_REFRIGERATED
Refrigerated cargo (Food, Fruit)
Definition: cargotype.h:46
CargoSpec::quantifier
StringID quantifier
Text for multiple units of cargo of this type.
Definition: cargotype.h:73
CargoSpec::classes
uint16 classes
Classes of this cargo type.
Definition: cargotype.h:78
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:70
CargoSpec::name_single
StringID name_single
Name of a single entity of this type of cargo.
Definition: cargotype.h:71
CargoSpec::abbrev
StringID abbrev
Two letter abbreviation for this cargo type.
Definition: cargotype.h:74
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:132
CargoSpec::multiplier
uint16 multiplier
Capacity multiplier for vehicles. (8 fractional bits)
Definition: cargotype.h:61
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
SetupCargoForClimate
void SetupCargoForClimate(LandscapeID l)
Set up the default cargo types for the given landscape type.
Definition: cargotype.cpp:39
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
LandscapeID
byte LandscapeID
Landscape type.
Definition: landscape_type.h:13
IsCargoInClass
static bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
Definition: cargotype.h:148
economy_type.h
gfx_type.h
CC_MAIL
@ CC_MAIL
Mail.
Definition: cargotype.h:40
SpriteGroup
Definition: newgrf_spritegroup.h:57
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105
_standard_cargo_mask
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
Definition: cargotype.cpp:33