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_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 */
83 uint amount
[NUM_CARGO
]; ///< Amount of each type of cargo.
86 /** Default constructor. */
92 /** Reset all entries. */
95 memset(this->amount
, 0, sizeof(this->amount
));
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.
120 template <typename T
>
121 inline const T
GetSum() const
124 for (size_t i
= 0; i
< lengthof(this->amount
); i
++) {
125 ret
+= this->amount
[i
];
131 * Get the amount of cargos that have an amount.
132 * @return The amount.
134 inline byte
GetCount() const
137 for (size_t i
= 0; i
< lengthof(this->amount
); i
++) {
138 if (this->amount
[i
] != 0) 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 */