OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

cargo_type.h
Go to the documentation of this file.
1 /* $Id: cargo_type.h 23826 2012-01-20 20:18:19Z rubidium $ */
2
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 */
9
12 #ifndef CARGO_TYPE_H
13 #define CARGO_TYPE_H
14
15 #include "core/enum_type.hpp"
16
22 typedef byte CargoID;
23
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,
38
39 /* Arctic */
40 CT_WHEAT = 6,
41 CT_HILLY_UNUSED = 8,
42 CT_PAPER = 9,
43 CT_GOLD = 10,
44 CT_FOOD = 11,
45
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,
53
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,
65
66 NUM_CARGO = 32,
67
68 CT_AUTO_REFIT = 0xFD,
69 CT_NO_REFIT = 0xFE,
70 CT_INVALID = 0xFF,
71 };
72
74 struct CargoArray {
75 private:
76 uint amount[NUM_CARGO];
77
78 public:
80 inline CargoArray()
81 {
82 this->Clear();
83 }
84
86 inline void Clear()
87 {
88 memset(this->amount, 0, sizeof(this->amount));
89 }
90
95 inline uint &operator[](CargoID cargo)
96 {
97 return this->amount[cargo];
98 }
99
104 inline const uint &operator[](CargoID cargo) const
105 {
106 return this->amount[cargo];
107 }
108
113 template <typename T>
114 inline const T GetSum() const
115 {
116 T ret = 0;
117 for (size_t i = 0; i < lengthof(this->amount); i++) {
118 ret += this->amount[i];
119 }
120 return ret;
121 }
122
127 inline byte GetCount() const
128 {
129 byte count = 0;
130 for (size_t i = 0; i < lengthof(this->amount); i++) {
131 if (this->amount[i] != 0) count++;
132 }
133 return count;
134 }
135 };
136
137
139 enum SourceType {
140 ST_INDUSTRY,
141 ST_TOWN,
142 ST_HEADQUARTERS,
143 };
144 typedef SimpleTinyEnumT<SourceType, byte> SourceTypeByte;
145
146 typedef uint16 SourceID;
147 static const SourceID INVALID_SOURCE = 0xFFFF;
148
149 #endif /* CARGO_TYPE_H */