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/>.
10 /** @file cargo_type.h Types related to cargoes... */
15 #include "core/enum_type.hpp"
18 * Cargo slots to indicate a cargo type within a game.
19 * Numbers are re-used between different climates.
24 /** Available types of cargo */
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 */
76 uint amount
[NUM_CARGO
]; ///< Amount of each type of cargo.
79 /** Default constructor. */
85 /** Reset all entries. */
88 memset(this->amount
, 0, sizeof(this->amount
));
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.
113 template <typename T
>
114 inline const T
GetSum() const
117 for (size_t i
= 0; i
< lengthof(this->amount
); i
++) {
118 ret
+= this->amount
[i
];
124 * Get the amount of cargos that have an amount.
125 * @return The amount.
127 inline byte
GetCount() const
130 for (size_t i
= 0; i
< lengthof(this->amount
); i
++) {
131 if (this->amount
[i
] != 0) count
++;
138 /** Types of cargo source and destination */
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 */