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 typedef uint32 CargoMask
;
76 /** Class for storing amounts of cargo */
79 uint amount
[NUM_CARGO
]; ///< Amount of each type of cargo.
82 /** Default constructor. */
88 /** Reset all entries. */
91 memset(this->amount
, 0, sizeof(this->amount
));
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.
116 template <typename T
>
117 inline const T
GetSum() const
120 for (size_t i
= 0; i
< lengthof(this->amount
); i
++) {
121 ret
+= this->amount
[i
];
127 * Get the amount of cargos that have an amount.
128 * @return The amount.
130 inline byte
GetCount() const
133 for (size_t i
= 0; i
< lengthof(this->amount
); i
++) {
134 if (this->amount
[i
] != 0) count
++;
141 /** Types of cargo source and destination */
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 */