4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file cargotype.h Types/functions related to cargoes. */
15 #include "economy_type.h"
16 #include "cargo_type.h"
18 #include "strings_type.h"
19 #include "landscape_type.h"
21 /** Globally unique label of a cargo type. */
22 typedef uint32 CargoLabel
;
24 /** Town growth effect when delivering cargo. */
27 TE_NONE
= TE_BEGIN
, ///< Cargo has no effect.
28 TE_PASSENGERS
, ///< Cargo behaves passenger-like.
29 TE_MAIL
, ///< Cargo behaves mail-like.
30 TE_GOODS
, ///< Cargo behaves goods/candy-like.
31 TE_WATER
, ///< Cargo behaves water-like.
32 TE_FOOD
, ///< Cargo behaves food/fizzy-drinks-like.
33 TE_END
, ///< End of town effects.
34 NUM_TE
= TE_END
, ///< Amount of town effects.
39 CC_NOAVAILABLE
= 0, ///< No cargo class has been specified
40 CC_PASSENGERS
= 1 << 0, ///< Passengers
41 CC_MAIL
= 1 << 1, ///< Mail
42 CC_EXPRESS
= 1 << 2, ///< Express cargo (Goods, Food, Candy, but also possible for passengers)
43 CC_ARMOURED
= 1 << 3, ///< Armoured cargo (Valuables, Gold, Diamonds)
44 CC_BULK
= 1 << 4, ///< Bulk cargo (Coal, Grain etc., Ores, Fruit)
45 CC_PIECE_GOODS
= 1 << 5, ///< Piece goods (Livestock, Wood, Steel, Paper)
46 CC_LIQUID
= 1 << 6, ///< Liquids (Oil, Water, Rubber)
47 CC_REFRIGERATED
= 1 << 7, ///< Refrigerated cargo (Food, Fruit)
48 CC_HAZARDOUS
= 1 << 8, ///< Hazardous cargo (Nuclear Fuel, Explosives, etc.)
49 CC_COVERED
= 1 << 9, ///< Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
50 CC_SPECIAL
= 1 << 15, ///< Special bit used for livery refit tricks instead of normal cargoes.
53 static const byte INVALID_CARGO
= 0xFF; ///< Constant representing invalid cargo
55 /** Specification of a cargo type. */
57 uint8 bitnum
; ///< Cargo bit number, is #INVALID_CARGO for a non-used spec.
58 CargoLabel label
; ///< Unique label of the cargo type.
61 uint8 weight
; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
62 uint16 multiplier
; ///< Capacity multiplier for vehicles. (8 fractional bits)
63 uint16 initial_payment
;
64 uint8 transit_days
[2];
66 bool is_freight
; ///< Cargo type is considered to be freight (affects train freight multiplier).
67 TownEffect town_effect
; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
68 uint16 multipliertowngrowth
; ///< Size of the effect.
69 uint8 callback_mask
; ///< Bitmask of cargo callbacks that have to be called
71 StringID name
; ///< Name of this type of cargo.
72 StringID name_single
; ///< Name of a single entity of this type of cargo.
73 StringID units_volume
; ///< Name of a single unit of cargo of this type.
74 StringID quantifier
; ///< Text for multiple units of cargo of this type.
75 StringID abbrev
; ///< Two letter abbreviation for this cargo type.
77 SpriteID sprite
; ///< Icon to display this cargo type, may be \c 0xFFF (which means to resolve an action123 chain).
79 uint16 classes
; ///< Classes of this cargo type. @see CargoClass
80 const struct GRFFile
*grffile
; ///< NewGRF where #group belongs to.
81 const struct SpriteGroup
*group
;
83 Money current_payment
;
86 * Determines index of this cargospec
87 * @return index (in the CargoSpec::array array)
89 inline CargoID
Index() const
91 return this - CargoSpec::array
;
95 * Tests for validity of this cargospec
96 * @return is this cargospec valid?
97 * @note assert(cs->IsValid()) can be triggered when GRF config is modified
99 inline bool IsValid() const
101 return this->bitnum
!= INVALID_CARGO
;
105 * Total number of cargospecs, both valid and invalid
106 * @return length of CargoSpec::array
108 static inline size_t GetArraySize()
110 return lengthof(CargoSpec::array
);
114 * Retrieve cargo details for the given cargo ID
115 * @param index ID of cargo
116 * @pre index is a valid cargo ID
118 static inline CargoSpec
*Get(size_t index
)
120 assert(index
< lengthof(CargoSpec::array
));
121 return &CargoSpec::array
[index
];
124 SpriteID
GetCargoIcon() const;
127 static CargoSpec array
[NUM_CARGO
]; ///< Array holding all CargoSpecs
129 friend void SetupCargoForClimate(LandscapeID l
);
132 extern uint32 _cargo_mask
;
133 extern uint32 _standard_cargo_mask
;
135 void SetupCargoForClimate(LandscapeID l
);
136 CargoID
GetCargoIDByLabel(CargoLabel cl
);
137 CargoID
GetCargoIDByBitnum(uint8 bitnum
);
139 void InitializeSortedCargoSpecs();
140 extern const CargoSpec
*_sorted_cargo_specs
[NUM_CARGO
];
141 extern uint8 _sorted_cargo_specs_size
;
142 extern uint8 _sorted_standard_cargo_specs_size
;
145 * Does cargo \a c have cargo class \a cc?
146 * @param c Cargo type.
147 * @param cc Cargo class.
148 * @return The type fits in the class.
150 static inline bool IsCargoInClass(CargoID c
, CargoClass cc
)
152 return (CargoSpec::Get(c
)->classes
& cc
) != 0;
155 #define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = NULL, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
156 if ((var = CargoSpec::Get(cargospec_index))->IsValid())
157 #define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
159 #define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, uint, cargo_bits)
162 * Loop header for iterating over cargoes, sorted by name. This includes phony cargoes like regearing cargoes.
163 * @param var Reference getting the cargospec.
166 #define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_cargo_specs_size && (var = _sorted_cargo_specs[index], true) ; index++)
169 * Loop header for iterating over 'real' cargoes, sorted by name. Phony cargoes like regearing cargoes are skipped.
170 * @param var Reference getting the cargospec.
173 #define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_standard_cargo_specs_size && (var = _sorted_cargo_specs[index], true); index++)
175 #endif /* CARGOTYPE_H */