/**
 * Get the default cargoes and refits of an articulated vehicle.
 * The refits are linked to a cargo rather than an articulated part to prevent a long list of parts.
 * @param engine Model to investigate.
 * @param[out] cargoes Total amount of units that can be transported, summed by cargo.
 * @param[out] refits Whether a (possibly partial) refit for each cargo is possible.
 */
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, uint32 *refits)
{
	cargoes->Clear();
	*refits = 0;

	const Engine *e = Engine::Get(engine);

	CargoID cargo_type;
	uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
	if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
		(*cargoes)[cargo_type] += cargo_capacity;
		if (IsEngineRefittable(engine)) SetBit(*refits, cargo_type);
	}

	if (!e->IsGroundVehicle() || !HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return;

	for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
		EngineID artic_engine = GetNextArticulatedPart(i, engine);
		if (artic_engine == INVALID_ENGINE) break;

		cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
		if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
			(*cargoes)[cargo_type] += cargo_capacity;
			if (IsEngineRefittable(artic_engine)) SetBit(*refits, cargo_type);
		}
	}
}
Exemplo n.º 2
0
/**
 * Returns all cargos a vehicle can carry.
 * @param engine the EngineID of iterest
 * @param include_initial_cargo_type if true the default cargo type of the vehicle is included; if false only the refit_mask
 * @return bit set of CargoIDs
 */
static inline uint32 GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
{
	uint32 cargos = 0;
	CargoID initial_cargo_type;

	if (GetVehicleDefaultCapacity(engine, &initial_cargo_type) > 0) {
		const EngineInfo *ei = EngInfo(engine);
		cargos = ei->refit_mask;
		if (include_initial_cargo_type && initial_cargo_type < NUM_CARGO) SetBit(cargos, initial_cargo_type);
	}

	return cargos;
}
Exemplo n.º 3
0
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
{
	CargoArray capacity;
	const Engine *e = Engine::Get(engine);

	CargoID cargo_type;
	uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
	if (cargo_type < NUM_CARGO) capacity[cargo_type] = cargo_capacity;

	if (e->type != VEH_TRAIN && e->type != VEH_ROAD) return capacity;

	if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return capacity;

	for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
		EngineID artic_engine = GetNextArticPart(i, engine);
		if (artic_engine == INVALID_ENGINE) break;

		cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
		if (cargo_type < NUM_CARGO) capacity[cargo_type] += cargo_capacity;
	}

	return capacity;
}