# cargotype.h

Go to the documentation of this file.

    00001 /* $Id: cargotype.h 18413 2009-12-05 21:39:28Z alberth $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    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_NONE,
    00027   TE_PASSENGERS,
    00028   TE_MAIL,
    00029   TE_GOODS,
    00030   TE_WATER,
    00031   TE_FOOD,
    00032 };
    00033
    00035 enum CargoClass {
    00036   CC_NOAVAILABLE  = 0,
    00037   CC_PASSENGERS   = 1 <<  0,
    00038   CC_MAIL         = 1 <<  1,
    00039   CC_EXPRESS      = 1 <<  2,
    00040   CC_ARMOURED     = 1 <<  3,
    00041   CC_BULK         = 1 <<  4,
    00042   CC_PIECE_GOODS  = 1 <<  5,
    00043   CC_LIQUID       = 1 <<  6,
    00044   CC_REFRIGERATED = 1 <<  7,
    00045   CC_HAZARDOUS    = 1 <<  8,
    00046   CC_COVERED      = 1 <<  9,
    00047   CC_SPECIAL      = 1 << 15
    00048 };
    00049
    00050 static const byte INVALID_CARGO = 0xFF;
    00051
    00053 struct CargoSpec {
    00054   uint8 bitnum;
    00055   CargoLabel label;
    00056   uint8 legend_colour;
    00057   uint8 rating_colour;
    00058   uint8 weight;
    00059   uint16 initial_payment;
    00060   uint8 transit_days[2];
    00061
    00062   bool is_freight;
    00063   TownEffect town_effect;
    00064   uint16 multipliertowngrowth;
    00065   uint8 callback_mask;
    00066
    00067   StringID name;
    00068   StringID name_single;
    00069   StringID units_volume;
    00070   StringID quantifier;
    00071   StringID abbrev;
    00072
    00073   SpriteID sprite;
    00074
    00075   uint16 classes;
    00076   const struct GRFFile *grffile;
    00077   const struct SpriteGroup *group;
    00078
    00079   Money current_payment;
    00080
    00085   FORCEINLINE CargoID Index() const
    00086   {
    00087     return this - CargoSpec::array;
    00088   }
    00089
    00095   FORCEINLINE bool IsValid() const
    00096   {
    00097     return this->bitnum != INVALID_CARGO;
    00098   }
    00099
    00104   static FORCEINLINE size_t GetArraySize()
    00105   {
    00106     return lengthof(CargoSpec::array);
    00107   }
    00108
    00114   static FORCEINLINE CargoSpec *Get(size_t index)
    00115   {
    00116     assert(index < lengthof(CargoSpec::array));
    00117     return &CargoSpec::array[index];
    00118   }
    00119
    00120   SpriteID GetCargoIcon() const;
    00121
    00122 private:
    00123   static CargoSpec array[NUM_CARGO];
    00124
    00125   friend void SetupCargoForClimate(LandscapeID l);
    00126 };
    00127
    00128 extern uint32 _cargo_mask;
    00129
    00130 void SetupCargoForClimate(LandscapeID l);
    00131 CargoID GetCargoIDByLabel(CargoLabel cl);
    00132 CargoID GetCargoIDByBitnum(uint8 bitnum);
    00133
    00139 static inline bool IsCargoInClass(CargoID c, CargoClass cc)
    00140 {
    00141   return (CargoSpec::Get(c)->classes & cc) != 0;
    00142 }
    00143
    00144 #define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = NULL, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
    00145     if ((var = CargoSpec::Get(cargospec_index))->IsValid())
    00146 #define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
    00147
    00148 #endif /* CARGOTYPE_H */