MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CanCarryCargo

Method CanCarryCargo

src/engine.cpp:167–190  ·  view source on GitHub ↗

* Determines whether an engine can carry something. * A vehicle cannot carry anything if its capacity is zero, or none of the possible cargoes is available in the climate. * @return true if the vehicle can carry something. */

Source from the content-addressed store, hash-verified

165 * @return true if the vehicle can carry something.
166 */
167bool Engine::CanCarryCargo() const
168{
169 /* For engines that can appear in a consist (i.e. rail vehicles and (articulated) road vehicles), a capacity
170 * of zero is a special case, to define the vehicle to not carry anything. The default cargotype is still used
171 * for livery selection etc.
172 * Note: Only the property is tested. A capacity callback returning 0 does not have the same effect.
173 */
174 switch (this->type) {
175 case VEH_TRAIN:
176 if (this->VehInfo<RailVehicleInfo>().capacity == 0) return false;
177 break;
178
179 case VEH_ROAD:
180 if (this->VehInfo<RoadVehicleInfo>().capacity == 0) return false;
181 break;
182
183 case VEH_SHIP:
184 case VEH_AIRCRAFT:
185 break;
186
187 default: NOT_REACHED();
188 }
189 return IsValidCargoType(this->GetDefaultCargoType());
190}
191
192
193/**

Callers 14

DetermineCapacityMethod · 0.95
AddArticulatedPartsFunction · 0.80
RefitVehicleFunction · 0.80
CmdCloneVehicleFunction · 0.80
GetBestFittingSubTypeFunction · 0.80
BuildRefitListMethod · 0.80
VehicleGetVariableFunction · 0.80
GetPreviewCompanyFunction · 0.80

Calls 3

GetDefaultCargoTypeMethod · 0.95
NOT_REACHEDFunction · 0.85
IsValidCargoTypeFunction · 0.85

Tested by

no test coverage detected