Codechange: Use cached town, station, industry names for list window sorting
[openttd-github.git] / src / cargo_type.h
blob89e6f1380815e995073ba3cfe42bc9cd4cc2f329
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file cargo_type.h Types related to cargoes... */
10 #ifndef CARGO_TYPE_H
11 #define CARGO_TYPE_H
13 #include "core/enum_type.hpp"
15 /**
16 * Cargo slots to indicate a cargo type within a game.
17 * Numbers are re-used between different climates.
18 * @see CargoTypes
20 typedef byte CargoID;
22 /** Available types of cargo */
23 enum CargoType {
24 /* Temperate */
25 CT_PASSENGERS = 0,
26 CT_COAL = 1,
27 CT_MAIL = 2,
28 CT_OIL = 3,
29 CT_LIVESTOCK = 4,
30 CT_GOODS = 5,
31 CT_GRAIN = 6,
32 CT_WOOD = 7,
33 CT_IRON_ORE = 8,
34 CT_STEEL = 9,
35 CT_VALUABLES = 10,
37 /* Arctic */
38 CT_WHEAT = 6,
39 CT_HILLY_UNUSED = 8,
40 CT_PAPER = 9,
41 CT_GOLD = 10,
42 CT_FOOD = 11,
44 /* Tropic */
45 CT_RUBBER = 1,
46 CT_FRUIT = 4,
47 CT_MAIZE = 6,
48 CT_COPPER_ORE = 8,
49 CT_WATER = 9,
50 CT_DIAMONDS = 10,
52 /* Toyland */
53 CT_SUGAR = 1,
54 CT_TOYS = 3,
55 CT_BATTERIES = 4,
56 CT_CANDY = 5,
57 CT_TOFFEE = 6,
58 CT_COLA = 7,
59 CT_COTTON_CANDY = 8,
60 CT_BUBBLES = 9,
61 CT_PLASTIC = 10,
62 CT_FIZZY_DRINKS = 11,
64 NUM_CARGO = 64, ///< Maximal number of cargo types in a game.
66 CT_AUTO_REFIT = 0xFD, ///< Automatically choose cargo type when doing auto refitting.
67 CT_NO_REFIT = 0xFE, ///< Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
68 CT_INVALID = 0xFF, ///< Invalid cargo type.
71 /** Test whether cargo type is not CT_INVALID */
72 inline bool IsCargoTypeValid(CargoType t) { return t != CT_INVALID; }
73 /** Test whether cargo type is not CT_INVALID */
74 inline bool IsCargoIDValid(CargoID t) { return t != CT_INVALID; }
76 typedef uint64 CargoTypes;
78 static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT64_MAX;
80 /** Class for storing amounts of cargo */
81 struct CargoArray {
82 private:
83 uint amount[NUM_CARGO]; ///< Amount of each type of cargo.
85 public:
86 /** Default constructor. */
87 inline CargoArray()
89 this->Clear();
92 /** Reset all entries. */
93 inline void Clear()
95 memset(this->amount, 0, sizeof(this->amount));
98 /**
99 * Read/write access to an amount of a specific cargo type.
100 * @param cargo Cargo type to access.
102 inline uint &operator[](CargoID cargo)
104 return this->amount[cargo];
108 * Read-only access to an amount of a specific cargo type.
109 * @param cargo Cargo type to access.
111 inline const uint &operator[](CargoID cargo) const
113 return this->amount[cargo];
117 * Get the sum of all cargo amounts.
118 * @return The sum.
120 template <typename T>
121 inline const T GetSum() const
123 T ret = 0;
124 for (size_t i = 0; i < lengthof(this->amount); i++) {
125 ret += this->amount[i];
127 return ret;
131 * Get the amount of cargos that have an amount.
132 * @return The amount.
134 inline byte GetCount() const
136 byte count = 0;
137 for (size_t i = 0; i < lengthof(this->amount); i++) {
138 if (this->amount[i] != 0) count++;
140 return count;
145 /** Types of cargo source and destination */
146 enum SourceType : byte {
147 ST_INDUSTRY, ///< Source/destination is an industry
148 ST_TOWN, ///< Source/destination is a town
149 ST_HEADQUARTERS, ///< Source/destination are company headquarters
152 typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
153 static const SourceID INVALID_SOURCE = 0xFFFF; ///< Invalid/unknown index of source
155 #endif /* CARGO_TYPE_H */