cargotype.h

Go to the documentation of this file.
00001 /* $Id: cargotype.h 24915 2013-01-14 21:16:56Z smatz $ */
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_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 extern uint32 _standard_cargo_mask;
00134 
00135 void SetupCargoForClimate(LandscapeID l);
00136 CargoID GetCargoIDByLabel(CargoLabel cl);
00137 CargoID GetCargoIDByBitnum(uint8 bitnum);
00138 
00139 void InitializeSortedCargoSpecs();
00140 extern const CargoSpec *_sorted_cargo_specs[NUM_CARGO];
00141 extern uint8 _sorted_cargo_specs_size;
00142 extern uint8 _sorted_standard_cargo_specs_size;
00143 
00150 static inline bool IsCargoInClass(CargoID c, CargoClass cc)
00151 {
00152   return (CargoSpec::Get(c)->classes & cc) != 0;
00153 }
00154 
00155 #define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = NULL, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
00156     if ((var = CargoSpec::Get(cargospec_index))->IsValid())
00157 #define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
00158 
00159 #define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, uint, cargo_bits)
00160 
00166 #define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_cargo_specs_size && (var = _sorted_cargo_specs[index], true) ; index++)
00167 
00173 #define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_standard_cargo_specs_size && (var = _sorted_cargo_specs[index], true); index++)
00174 
00175 #endif /* CARGOTYPE_H */