cargo_type.h

Go to the documentation of this file.
00001 /* $Id$ */
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 CARGO_TYPE_H
00013 #define CARGO_TYPE_H
00014 
00015 #include "core/enum_type.hpp"
00016 
00022 typedef byte CargoID;
00023 
00025 enum CargoTypes {
00026   /* Temperate */
00027   CT_PASSENGERS   =  0,
00028   CT_COAL         =  1,
00029   CT_MAIL         =  2,
00030   CT_OIL          =  3,
00031   CT_LIVESTOCK    =  4,
00032   CT_GOODS        =  5,
00033   CT_GRAIN        =  6,
00034   CT_WOOD         =  7,
00035   CT_IRON_ORE     =  8,
00036   CT_STEEL        =  9,
00037   CT_VALUABLES    = 10,
00038 
00039   /* Arctic */
00040   CT_WHEAT        =  6,
00041   CT_HILLY_UNUSED =  8,
00042   CT_PAPER        =  9,
00043   CT_GOLD         = 10,
00044   CT_FOOD         = 11,
00045 
00046   /* Tropic */
00047   CT_RUBBER       =  1,
00048   CT_FRUIT        =  4,
00049   CT_MAIZE        =  6,
00050   CT_COPPER_ORE   =  8,
00051   CT_WATER        =  9,
00052   CT_DIAMONDS     = 10,
00053 
00054   /* Toyland */
00055   CT_SUGAR        =  1,
00056   CT_TOYS         =  3,
00057   CT_BATTERIES    =  4,
00058   CT_CANDY        =  5,
00059   CT_TOFFEE       =  6,
00060   CT_COLA         =  7,
00061   CT_COTTON_CANDY =  8,
00062   CT_BUBBLES      =  9,
00063   CT_PLASTIC      = 10,
00064   CT_FIZZY_DRINKS = 11,
00065 
00066   NUM_CARGO       = 32,   
00067 
00068   CT_AUTO_REFIT   = 0xFD, 
00069   CT_NO_REFIT     = 0xFE, 
00070   CT_INVALID      = 0xFF, 
00071 };
00072 
00074 struct CargoArray {
00075 private:
00076   uint amount[NUM_CARGO]; 
00077 
00078 public:
00080   inline CargoArray()
00081   {
00082     this->Clear();
00083   }
00084 
00086   inline void Clear()
00087   {
00088     memset(this->amount, 0, sizeof(this->amount));
00089   }
00090 
00095   inline uint &operator[](CargoID cargo)
00096   {
00097     return this->amount[cargo];
00098   }
00099 
00104   inline const uint &operator[](CargoID cargo) const
00105   {
00106     return this->amount[cargo];
00107   }
00108 
00113   template <typename T>
00114   inline const T GetSum() const
00115   {
00116     T ret = 0;
00117     for (size_t i = 0; i < lengthof(this->amount); i++) {
00118       ret += this->amount[i];
00119     }
00120     return ret;
00121   }
00122 
00127   inline byte GetCount() const
00128   {
00129     byte count = 0;
00130     for (size_t i = 0; i < lengthof(this->amount); i++) {
00131       if (this->amount[i] != 0) count++;
00132     }
00133     return count;
00134   }
00135 };
00136 
00137 
00139 enum SourceType {
00140   ST_INDUSTRY,     
00141   ST_TOWN,         
00142   ST_HEADQUARTERS, 
00143 };
00144 typedef SimpleTinyEnumT<SourceType, byte> SourceTypeByte; 
00145 
00146 typedef uint16 SourceID; 
00147 static const SourceID INVALID_SOURCE = 0xFFFF; 
00148 
00149 #endif /* CARGO_TYPE_H */