Translations update
[openttd/fttd.git] / src / cargo_type.h
blobfbe966f798a38f89b057ef7b5a7c770c38cee6a0
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 typedef uint32 CargoMask;
76 /** Class for storing amounts of cargo */
77 struct CargoArray {
78 private:
79 uint amount[NUM_CARGO]; ///< Amount of each type of cargo.
81 public:
82 /** Default constructor. */
83 inline CargoArray()
85 this->Clear();
88 /** Reset all entries. */
89 inline void Clear()
91 memset(this->amount, 0, sizeof(this->amount));
94 /**
95 * Read/write access to an amount of a specific cargo type.
96 * @param cargo Cargo type to access.
98 inline uint &operator[](CargoID cargo)
100 return this->amount[cargo];
104 * Read-only access to an amount of a specific cargo type.
105 * @param cargo Cargo type to access.
107 inline const uint &operator[](CargoID cargo) const
109 return this->amount[cargo];
113 * Get the sum of all cargo amounts.
114 * @return The sum.
116 template <typename T>
117 inline const T GetSum() const
119 T ret = 0;
120 for (size_t i = 0; i < lengthof(this->amount); i++) {
121 ret += this->amount[i];
123 return ret;
127 * Get the amount of cargos that have an amount.
128 * @return The amount.
130 inline byte GetCount() const
132 byte count = 0;
133 for (size_t i = 0; i < lengthof(this->amount); i++) {
134 if (this->amount[i] != 0) count++;
136 return count;
141 /** Types of cargo source and destination */
142 enum SourceType {
143 ST_INDUSTRY, ///< Source/destination is an industry
144 ST_TOWN, ///< Source/destination is a town
145 ST_HEADQUARTERS, ///< Source/destination are company headquarters
147 typedef SimpleTinyEnumT<SourceType, byte> SourceTypeByte; ///< The SourceType packed into a byte for savegame purposes.
149 typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
150 static const SourceID INVALID_SOURCE = 0xFFFF; ///< Invalid/unknown index of source
152 #endif /* CARGO_TYPE_H */