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/>.
8 /** @file cargotype.h Types/functions related to cargoes. */
13 #include "economy_type.h"
14 #include "cargo_type.h"
16 #include "strings_type.h"
17 #include "landscape_type.h"
20 /** Globally unique label of a cargo type. */
21 typedef uint32 CargoLabel
;
23 /** Town growth effect when delivering cargo. */
26 TE_NONE
= TE_BEGIN
, ///< Cargo has no effect.
27 TE_PASSENGERS
, ///< Cargo behaves passenger-like.
28 TE_MAIL
, ///< Cargo behaves mail-like.
29 TE_GOODS
, ///< Cargo behaves goods/candy-like.
30 TE_WATER
, ///< Cargo behaves water-like.
31 TE_FOOD
, ///< Cargo behaves food/fizzy-drinks-like.
32 TE_END
, ///< End of town effects.
33 NUM_TE
= TE_END
, ///< Amount of town effects.
38 CC_NOAVAILABLE
= 0, ///< No cargo class has been specified
39 CC_PASSENGERS
= 1 << 0, ///< Passengers
40 CC_MAIL
= 1 << 1, ///< Mail
41 CC_EXPRESS
= 1 << 2, ///< Express cargo (Goods, Food, Candy, but also possible for passengers)
42 CC_ARMOURED
= 1 << 3, ///< Armoured cargo (Valuables, Gold, Diamonds)
43 CC_BULK
= 1 << 4, ///< Bulk cargo (Coal, Grain etc., Ores, Fruit)
44 CC_PIECE_GOODS
= 1 << 5, ///< Piece goods (Livestock, Wood, Steel, Paper)
45 CC_LIQUID
= 1 << 6, ///< Liquids (Oil, Water, Rubber)
46 CC_REFRIGERATED
= 1 << 7, ///< Refrigerated cargo (Food, Fruit)
47 CC_HAZARDOUS
= 1 << 8, ///< Hazardous cargo (Nuclear Fuel, Explosives, etc.)
48 CC_COVERED
= 1 << 9, ///< Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
49 CC_SPECIAL
= 1 << 15, ///< Special bit used for livery refit tricks instead of normal cargoes.
52 static const byte INVALID_CARGO
= 0xFF; ///< Constant representing invalid cargo
54 /** Specification of a cargo type. */
56 uint8 bitnum
; ///< Cargo bit number, is #INVALID_CARGO for a non-used spec.
57 CargoLabel label
; ///< Unique label of the cargo type.
60 uint8 weight
; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
61 uint16 multiplier
; ///< Capacity multiplier for vehicles. (8 fractional bits)
62 uint16 initial_payment
;
63 uint8 transit_days
[2];
65 bool is_freight
; ///< Cargo type is considered to be freight (affects train freight multiplier).
66 TownEffect town_effect
; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
67 uint16 multipliertowngrowth
; ///< Size of the effect.
68 uint8 callback_mask
; ///< Bitmask of cargo callbacks that have to be called
70 StringID name
; ///< Name of this type of cargo.
71 StringID name_single
; ///< Name of a single entity of this type of cargo.
72 StringID units_volume
; ///< Name of a single unit of cargo of this type.
73 StringID quantifier
; ///< Text for multiple units of cargo of this type.
74 StringID abbrev
; ///< Two letter abbreviation for this cargo type.
76 SpriteID sprite
; ///< Icon to display this cargo type, may be \c 0xFFF (which means to resolve an action123 chain).
78 uint16 classes
; ///< Classes of this cargo type. @see CargoClass
79 const struct GRFFile
*grffile
; ///< NewGRF where #group belongs to.
80 const struct SpriteGroup
*group
;
82 Money current_payment
;
85 * Determines index of this cargospec
86 * @return index (in the CargoSpec::array array)
88 inline CargoID
Index() const
90 return this - CargoSpec::array
;
94 * Tests for validity of this cargospec
95 * @return is this cargospec valid?
96 * @note assert(cs->IsValid()) can be triggered when GRF config is modified
98 inline bool IsValid() const
100 return this->bitnum
!= INVALID_CARGO
;
104 * Total number of cargospecs, both valid and invalid
105 * @return length of CargoSpec::array
107 static inline size_t GetArraySize()
109 return lengthof(CargoSpec::array
);
113 * Retrieve cargo details for the given cargo ID
114 * @param index ID of cargo
115 * @pre index is a valid cargo ID
117 static inline CargoSpec
*Get(size_t index
)
119 assert(index
< lengthof(CargoSpec::array
));
120 return &CargoSpec::array
[index
];
123 SpriteID
GetCargoIcon() const;
126 static CargoSpec array
[NUM_CARGO
]; ///< Array holding all CargoSpecs
128 friend void SetupCargoForClimate(LandscapeID l
);
131 extern CargoTypes _cargo_mask
;
132 extern CargoTypes _standard_cargo_mask
;
134 void SetupCargoForClimate(LandscapeID l
);
135 CargoID
GetCargoIDByLabel(CargoLabel cl
);
136 CargoID
GetCargoIDByBitnum(uint8 bitnum
);
138 void InitializeSortedCargoSpecs();
139 extern std::vector
<const CargoSpec
*> _sorted_cargo_specs
;
140 extern uint8 _sorted_standard_cargo_specs_size
;
143 * Does cargo \a c have cargo class \a cc?
144 * @param c Cargo type.
145 * @param cc Cargo class.
146 * @return The type fits in the class.
148 static inline bool IsCargoInClass(CargoID c
, CargoClass cc
)
150 return (CargoSpec::Get(c
)->classes
& cc
) != 0;
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)
157 #define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, CargoTypes, cargo_bits)
160 * Loop header for iterating over cargoes, sorted by name. This includes phony cargoes like regearing cargoes.
161 * @param var Reference getting the cargospec.
164 #define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_cargo_specs.size() && (var = _sorted_cargo_specs[index], true) ; index++)
167 * Loop header for iterating over 'real' cargoes, sorted by name. Phony cargoes like regearing cargoes are skipped.
168 * @param var Reference getting the cargospec.
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++)
173 #endif /* CARGOTYPE_H */