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/>.
8 /** @file cargo_type.h Types related to cargoes... */
13 #include "core/enum_type.hpp"
16 * Cargo slots to indicate a cargo type within a game.
17 * Numbers are re-used between different climates.
22 /** Available types of cargo */
64 NUM_ORIGINAL_CARGO
= 12,
65 NUM_CARGO
= 64, ///< Maximal number of cargo types in a game.
67 CT_AUTO_REFIT
= 0xFD, ///< Automatically choose cargo type when doing auto refitting.
68 CT_NO_REFIT
= 0xFE, ///< Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
69 CT_INVALID
= 0xFF, ///< Invalid cargo type.
72 /** Test whether cargo type is not CT_INVALID */
73 inline bool IsCargoTypeValid(CargoType t
) { return t
!= CT_INVALID
; }
74 /** Test whether cargo type is not CT_INVALID */
75 inline bool IsCargoIDValid(CargoID t
) { return t
!= CT_INVALID
; }
77 typedef uint64 CargoTypes
;
79 static const CargoTypes ALL_CARGOTYPES
= (CargoTypes
)UINT64_MAX
;
81 /** Class for storing amounts of cargo */
84 uint amount
[NUM_CARGO
]; ///< Amount of each type of cargo.
87 /** Default constructor. */
93 /** Reset all entries. */
96 memset(this->amount
, 0, sizeof(this->amount
));
100 * Read/write access to an amount of a specific cargo type.
101 * @param cargo Cargo type to access.
103 inline uint
&operator[](CargoID cargo
)
105 return this->amount
[cargo
];
109 * Read-only access to an amount of a specific cargo type.
110 * @param cargo Cargo type to access.
112 inline const uint
&operator[](CargoID cargo
) const
114 return this->amount
[cargo
];
118 * Get the sum of all cargo amounts.
121 template <typename T
>
122 inline const T
GetSum() const
125 for (size_t i
= 0; i
< lengthof(this->amount
); i
++) {
126 ret
+= this->amount
[i
];
132 * Get the amount of cargos that have an amount.
133 * @return The amount.
135 inline byte
GetCount() const
138 for (size_t i
= 0; i
< lengthof(this->amount
); i
++) {
139 if (this->amount
[i
] != 0) count
++;
146 /** Types of cargo source and destination */
147 enum SourceType
: byte
{
148 ST_INDUSTRY
, ///< Source/destination is an industry
149 ST_TOWN
, ///< Source/destination is a town
150 ST_HEADQUARTERS
, ///< Source/destination are company headquarters
153 typedef uint16 SourceID
; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
154 static const SourceID INVALID_SOURCE
= 0xFFFF; ///< Invalid/unknown index of source
156 #endif /* CARGO_TYPE_H */