|
@@ -163,49 +163,49 @@ uint32 Engine::GetGRFID() const
|
|
|
* @return true if the vehicle can carry something.
|
|
|
*/
|
|
|
bool Engine::CanCarryCargo() const
|
|
|
{
|
|
|
/* For engines that can appear in a consist (i.e. rail vehicles and (articulated) road vehicles), a capacity
|
|
|
* of zero is a special case, to define the vehicle to not carry anything. The default cargotype is still used
|
|
|
* for livery selection etc.
|
|
|
* Note: Only the property is tested. A capacity callback returning 0 does not have the same effect.
|
|
|
*/
|
|
|
switch (this->type) {
|
|
|
case VEH_TRAIN:
|
|
|
if (this->u.rail.capacity == 0) return false;
|
|
|
break;
|
|
|
|
|
|
case VEH_ROAD:
|
|
|
if (this->u.road.capacity == 0) return false;
|
|
|
break;
|
|
|
|
|
|
case VEH_SHIP:
|
|
|
case VEH_AIRCRAFT:
|
|
|
break;
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
}
|
|
|
return this->GetDefaultCargoType() != CT_INVALID;
|
|
|
return IsValidCargoID(this->GetDefaultCargoType());
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Determines capacity of a given vehicle from scratch.
|
|
|
* For aircraft the main capacity is determined. Mail might be present as well.
|
|
|
* @param v Vehicle of interest; nullptr in purchase list
|
|
|
* @param mail_capacity returns secondary cargo (mail) capacity of aircraft
|
|
|
* @return Capacity
|
|
|
*/
|
|
|
uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const
|
|
|
{
|
|
|
assert(v == nullptr || this->index == v->engine_type);
|
|
|
if (mail_capacity != nullptr) *mail_capacity = 0;
|
|
|
|
|
|
if (!this->CanCarryCargo()) return 0;
|
|
|
|
|
|
bool new_multipliers = HasBit(this->info.misc_flags, EF_NO_DEFAULT_CARGO_MULTIPLIER);
|
|
|
CargoID default_cargo = this->GetDefaultCargoType();
|
|
|
CargoID cargo_type = (v != nullptr) ? v->cargo_type : default_cargo;
|
|
|
|
|
|
if (mail_capacity != nullptr && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CC_PASSENGERS)) {
|
|
|
*mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
|
|
|
}
|
|
@@ -1235,49 +1235,49 @@ bool IsEngineBuildable(EngineID engine,
|
|
|
* Note: Likely you want to use IsArticulatedVehicleRefittable().
|
|
|
* @param engine index of the engine to check.
|
|
|
* @return true if the engine is refittable.
|
|
|
*/
|
|
|
bool IsEngineRefittable(EngineID engine)
|
|
|
{
|
|
|
const Engine *e = Engine::GetIfValid(engine);
|
|
|
|
|
|
/* check if it's an engine that is in the engine array */
|
|
|
if (e == nullptr) return false;
|
|
|
|
|
|
if (!e->CanCarryCargo()) return false;
|
|
|
|
|
|
const EngineInfo *ei = &e->info;
|
|
|
if (ei->refit_mask == 0) return false;
|
|
|
|
|
|
/* Are there suffixes?
|
|
|
* Note: This does not mean the suffixes are actually available for every consist at any time. */
|
|
|
if (HasBit(ei->callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) return true;
|
|
|
|
|
|
/* Is there any cargo except the default cargo? */
|
|
|
CargoID default_cargo = e->GetDefaultCargoType();
|
|
|
CargoTypes default_cargo_mask = 0;
|
|
|
SetBit(default_cargo_mask, default_cargo);
|
|
|
return default_cargo != CT_INVALID && ei->refit_mask != default_cargo_mask;
|
|
|
return IsValidCargoID(default_cargo) && ei->refit_mask != default_cargo_mask;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Check for engines that have an appropriate availability.
|
|
|
*/
|
|
|
void CheckEngines()
|
|
|
{
|
|
|
TimerGameCalendar::Date min_date = INT32_MAX;
|
|
|
|
|
|
for (const Engine *e : Engine::Iterate()) {
|
|
|
if (!e->IsEnabled()) continue;
|
|
|
|
|
|
/* Don't consider train wagons, we need a powered engine available. */
|
|
|
if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
|
|
|
|
|
|
/* We have an available engine... yay! */
|
|
|
if ((e->flags & ENGINE_AVAILABLE) != 0 && e->company_avail != 0) return;
|
|
|
|
|
|
/* Okay, try to find the earliest date. */
|
|
|
min_date = std::min(min_date, e->info.base_intro);
|
|
|
}
|
|
|
|
|
|
if (min_date < INT32_MAX) {
|
|
|
SetDParam(0, min_date);
|