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