(svn r27729) -Codechange: Do not count static NewGRF when checking for the maximum...
[openttd.git] / src / cargo_type.h
blob7b7168a102addccf63dfeb78ff7923230edcdd0f
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file cargo_type.h Types related to cargoes... */
12 #ifndef CARGO_TYPE_H
13 #define CARGO_TYPE_H
15 #include "core/enum_type.hpp"
17 /**
18 * Cargo slots to indicate a cargo type within a game.
19 * Numbers are re-used between different climates.
20 * @see CargoTypes
22 typedef byte CargoID;
24 /** Available types of cargo */
25 enum CargoTypes {
26 /* Temperate */
27 CT_PASSENGERS = 0,
28 CT_COAL = 1,
29 CT_MAIL = 2,
30 CT_OIL = 3,
31 CT_LIVESTOCK = 4,
32 CT_GOODS = 5,
33 CT_GRAIN = 6,
34 CT_WOOD = 7,
35 CT_IRON_ORE = 8,
36 CT_STEEL = 9,
37 CT_VALUABLES = 10,
39 /* Arctic */
40 CT_WHEAT = 6,
41 CT_HILLY_UNUSED = 8,
42 CT_PAPER = 9,
43 CT_GOLD = 10,
44 CT_FOOD = 11,
46 /* Tropic */
47 CT_RUBBER = 1,
48 CT_FRUIT = 4,
49 CT_MAIZE = 6,
50 CT_COPPER_ORE = 8,
51 CT_WATER = 9,
52 CT_DIAMONDS = 10,
54 /* Toyland */
55 CT_SUGAR = 1,
56 CT_TOYS = 3,
57 CT_BATTERIES = 4,
58 CT_CANDY = 5,
59 CT_TOFFEE = 6,
60 CT_COLA = 7,
61 CT_COTTON_CANDY = 8,
62 CT_BUBBLES = 9,
63 CT_PLASTIC = 10,
64 CT_FIZZY_DRINKS = 11,
66 NUM_CARGO = 32, ///< Maximal number of cargo types in a game.
68 CT_AUTO_REFIT = 0xFD, ///< Automatically choose cargo type when doing auto refitting.
69 CT_NO_REFIT = 0xFE, ///< Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
70 CT_INVALID = 0xFF, ///< Invalid cargo type.
73 /** Class for storing amounts of cargo */
74 struct CargoArray {
75 private:
76 uint amount[NUM_CARGO]; ///< Amount of each type of cargo.
78 public:
79 /** Default constructor. */
80 inline CargoArray()
82 this->Clear();
85 /** Reset all entries. */
86 inline void Clear()
88 memset(this->amount, 0, sizeof(this->amount));
91 /**
92 * Read/write access to an amount of a specific cargo type.
93 * @param cargo Cargo type to access.
95 inline uint &operator[](CargoID cargo)
97 return this->amount[cargo];
101 * Read-only access to an amount of a specific cargo type.
102 * @param cargo Cargo type to access.
104 inline const uint &operator[](CargoID cargo) const
106 return this->amount[cargo];
110 * Get the sum of all cargo amounts.
111 * @return The sum.
113 template <typename T>
114 inline const T GetSum() const
116 T ret = 0;
117 for (size_t i = 0; i < lengthof(this->amount); i++) {
118 ret += this->amount[i];
120 return ret;
124 * Get the amount of cargos that have an amount.
125 * @return The amount.
127 inline byte GetCount() const
129 byte count = 0;
130 for (size_t i = 0; i < lengthof(this->amount); i++) {
131 if (this->amount[i] != 0) count++;
133 return count;
138 /** Types of cargo source and destination */
139 enum SourceType {
140 ST_INDUSTRY, ///< Source/destination is an industry
141 ST_TOWN, ///< Source/destination is a town
142 ST_HEADQUARTERS, ///< Source/destination are company headquarters
144 typedef SimpleTinyEnumT<SourceType, byte> SourceTypeByte; ///< The SourceType packed into a byte for savegame purposes.
146 typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
147 static const SourceID INVALID_SOURCE = 0xFFFF; ///< Invalid/unknown index of source
149 #endif /* CARGO_TYPE_H */