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 multiplier;
00063 uint16 initial_payment;
00064 uint8 transit_days[2];
00065
00066 bool is_freight;
00067 TownEffect town_effect;
00068 uint16 multipliertowngrowth;
00069 uint8 callback_mask;
00070
00071 StringID name;
00072 StringID name_single;
00073 StringID units_volume;
00074 StringID quantifier;
00075 StringID abbrev;
00076
00077 SpriteID sprite;
00078
00079 uint16 classes;
00080 const struct GRFFile *grffile;
00081 const struct SpriteGroup *group;
00082
00083 Money current_payment;
00084
00089 inline CargoID Index() const
00090 {
00091 return this - CargoSpec::array;
00092 }
00093
00099 inline bool IsValid() const
00100 {
00101 return this->bitnum != INVALID_CARGO;
00102 }
00103
00108 static inline size_t GetArraySize()
00109 {
00110 return lengthof(CargoSpec::array);
00111 }
00112
00118 static inline CargoSpec *Get(size_t index)
00119 {
00120 assert(index < lengthof(CargoSpec::array));
00121 return &CargoSpec::array[index];
00122 }
00123
00124 SpriteID GetCargoIcon() const;
00125
00126 private:
00127 static CargoSpec array[NUM_CARGO];
00128
00129 friend void SetupCargoForClimate(LandscapeID l);
00130 };
00131
00132 extern uint32 _cargo_mask;
00133
00134 void SetupCargoForClimate(LandscapeID l);
00135 CargoID GetCargoIDByLabel(CargoLabel cl);
00136 CargoID GetCargoIDByBitnum(uint8 bitnum);
00137
00138 void InitializeSortedCargoSpecs();
00139 extern const CargoSpec *_sorted_cargo_specs[NUM_CARGO];
00140 extern uint8 _sorted_cargo_specs_size;
00141 extern uint8 _sorted_standard_cargo_specs_size;
00142
00149 static inline bool IsCargoInClass(CargoID c, CargoClass cc)
00150 {
00151 return (CargoSpec::Get(c)->classes & cc) != 0;
00152 }
00153
00154 #define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = NULL, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
00155 if ((var = CargoSpec::Get(cargospec_index))->IsValid())
00156 #define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
00157
00158 #define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, uint, cargo_bits)
00159
00160 #define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_cargo_specs_size; index++)
00161
00162 #define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; var = _sorted_cargo_specs[index], index < _sorted_standard_cargo_specs_size; index++)
00163
00164 #endif