diff options
author | frosch <frosch@openttd.org> | 2012-01-28 12:11:23 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2012-01-28 12:11:23 +0000 |
commit | 1777809e1416be9c837c6f349813d54bc4bf855e (patch) | |
tree | 3ba1ef6ca21593492d6d0ed57c7cb973e8940b53 /src | |
parent | 90c53046c77101c3b6d7ad8e77f79c3cf5ee8da0 (diff) | |
download | openttd-1777809e1416be9c837c6f349813d54bc4bf855e.tar.xz |
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 31 | ||||
-rw-r--r-- | src/engine_type.h | 1 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index 1e3c0f387..b9479d82f 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -210,6 +210,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const 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 != NULL) ? v->cargo_type : default_cargo; @@ -217,16 +218,16 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const *mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v); } - /* Check the refit capacity callback if we are not in the default configuration. - * Note: This might change to become more consistent/flexible/sane, esp. when default cargo is first refittable. */ + /* Check the refit capacity callback if we are not in the default configuration, or if we are using the new multiplier algorithm. */ if (HasBit(this->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) && - (default_cargo != cargo_type || (v != NULL && v->cargo_subtype != 0))) { + (new_multipliers || default_cargo != cargo_type || (v != NULL && v->cargo_subtype != 0))) { uint16 callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, this->index, v); if (callback != CALLBACK_FAILED) return callback; } /* Get capacity according to property resp. CB */ uint capacity; + uint extra_mail_cap = 0; switch (this->type) { case VEH_TRAIN: capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity, v); @@ -246,21 +247,31 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const case VEH_AIRCRAFT: capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity, v); if (!IsCargoInClass(cargo_type, CC_PASSENGERS)) { - capacity += GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v); + extra_mail_cap = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v); } - if (cargo_type == CT_MAIL) return capacity; + if (!new_multipliers && cargo_type == CT_MAIL) return capacity + extra_mail_cap; default_cargo = CT_PASSENGERS; // Always use 'passengers' wrt. cargo multipliers break; default: NOT_REACHED(); } - /* Apply multipliers depending on cargo- and vehicletype. - * Note: This might change to become more consistent/flexible. */ - if (this->type != VEH_SHIP && default_cargo != cargo_type) { - uint16 default_multiplier = CargoSpec::Get(default_cargo)->multiplier; + if (!new_multipliers) { + /* Use the passenger multiplier for mail as well */ + capacity += extra_mail_cap; + extra_mail_cap = 0; + } + + /* Apply multipliers depending on cargo- and vehicletype. */ + if (new_multipliers || (this->type != VEH_SHIP && default_cargo != cargo_type)) { + uint16 default_multiplier = new_multipliers ? 0x100 : CargoSpec::Get(default_cargo)->multiplier; uint16 cargo_multiplier = CargoSpec::Get(cargo_type)->multiplier; - capacity = (capacity * cargo_multiplier + default_multiplier / 2) / default_multiplier; + capacity *= cargo_multiplier; + if (extra_mail_cap > 0) { + uint mail_multiplier = CargoSpec::Get(CT_MAIL)->multiplier; + capacity += (default_multiplier * extra_mail_cap * cargo_multiplier + mail_multiplier / 2) / mail_multiplier; + } + capacity = (capacity + default_multiplier / 2) / default_multiplier; } return capacity; diff --git a/src/engine_type.h b/src/engine_type.h index d4a553839..2ce1f80e9 100644 --- a/src/engine_type.h +++ b/src/engine_type.h @@ -156,6 +156,7 @@ enum EngineMiscFlags { EF_RAIL_IS_MU = 2, ///< Rail vehicle is a multiple-unit (DMU/EMU) EF_RAIL_FLIPS = 3, ///< Rail vehicle can be flipped in the depot EF_AUTO_REFIT = 4, ///< Automatic refitting is allowed + EF_NO_DEFAULT_CARGO_MULTIPLIER = 5, ///< Use the new capacity algorithm. The default cargotype of the vehicle does not affect capacity multipliers. CB 15 is also called in purchase list. }; /** |