Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef CARGOTYPE_H
00013 #define CARGOTYPE_H
00014
00015 #include "economy_type.h"
00016 #include "cargo_type.h"
00017 #include "gfx_type.h"
00018 #include "strings_type.h"
00019 #include "landscape_type.h"
00020
00022 typedef uint32 CargoLabel;
00023
00025 enum TownEffect {
00026 TE_BEGIN = 0,
00027 TE_NONE = TE_BEGIN,
00028 TE_PASSENGERS,
00029 TE_MAIL,
00030 TE_GOODS,
00031 TE_WATER,
00032 TE_FOOD,
00033 TE_END,
00034 NUM_TE = TE_END,
00035 };
00036
00038 enum CargoClass {
00039 CC_NOAVAILABLE = 0,
00040 CC_PASSENGERS = 1 << 0,
00041 CC_MAIL = 1 << 1,
00042 CC_EXPRESS = 1 << 2,
00043 CC_ARMOURED = 1 << 3,
00044 CC_BULK = 1 << 4,
00045 CC_PIECE_GOODS = 1 << 5,
00046 CC_LIQUID = 1 << 6,
00047 CC_REFRIGERATED = 1 << 7,
00048 CC_HAZARDOUS = 1 << 8,
00049 CC_COVERED = 1 << 9,
00050 CC_SPECIAL = 1 << 15
00051 };
00052
00053 static const byte INVALID_CARGO = 0xFF;
00054
00056 struct CargoSpec {
00057 uint8 bitnum;
00058 CargoLabel label;
00059 uint8 legend_colour;
00060 uint8 rating_colour;
00061 uint8 weight;
00062 uint16 initial_payment;
00063 uint8 transit_days[2];
00064
00065 bool is_freight;
00066 TownEffect town_effect;
00067 uint16 multipliertowngrowth;
00068 uint8 callback_mask;
00069
00070 StringID name;
00071 StringID name_single;
00072 StringID units_volume;
00073 StringID quantifier;
00074 StringID abbrev;
00075
00076 SpriteID sprite;
00077
00078 uint16 classes;
00079 const struct GRFFile *grffile;
00080 const struct SpriteGroup *group;
00081
00082 Money current_payment;
00083
00088 FORCEINLINE CargoID Index() const
00089 {
00090 return this - CargoSpec::array;
00091 }
00092
00098 FORCEINLINE bool IsValid() const
00099 {
00100 return this->bitnum != INVALID_CARGO;
00101 }
00102
00107 static FORCEINLINE size_t GetArraySize()
00108 {
00109 return lengthof(CargoSpec::array);
00110 }
00111
00117 static FORCEINLINE CargoSpec *Get(size_t index)
00118 {
00119 assert(index < lengthof(CargoSpec::array));
00120 return &CargoSpec::array[index];
00121 }
00122
00123 SpriteID GetCargoIcon() const;
00124
00125 private:
00126 static CargoSpec array[NUM_CARGO];
00127
00128 friend void SetupCargoForClimate(LandscapeID l);
00129 };
00130
00131 extern uint32 _cargo_mask;
00132
00133 void SetupCargoForClimate(LandscapeID l);
00134 CargoID GetCargoIDByLabel(CargoLabel cl);
00135 CargoID GetCargoIDByBitnum(uint8 bitnum);
00136
00137 void InitializeSortedCargoSpecs();
00138 extern const CargoSpec *_sorted_cargo_specs[NUM_CARGO];
00139 extern uint8 _sorted_cargo_specs_size;
00140 extern uint8 _sorted_standard_cargo_specs_size;
00141
00148 static inline bool IsCargoInClass(CargoID c, CargoClass cc)
00149 {
00150 return (CargoSpec::Get(c)->classes & cc) != 0;
00151 }
00152
00153 #define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = NULL, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
00154 if ((var = CargoSpec::Get(cargospec_index))->IsValid())
00155 #define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
00156
00157 #define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, uint, cargo_bits)
00158
00159 #define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_cargo_specs_size; index++)
00160
00161 #define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_standard_cargo_specs_size; index++)
00162
00163 #endif