diff options
author | frosch <frosch@openttd.org> | 2011-11-09 16:38:50 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-11-09 16:38:50 +0000 |
commit | 026317bb444c1165ba96904f8e5a300b1a657539 (patch) | |
tree | 103adbbc8acf8129b9b1d030304950f06d9a6a8b | |
parent | e4011426f2a4ae1ccbbced0cc45d22bce2502fe9 (diff) | |
download | openttd-026317bb444c1165ba96904f8e5a300b1a657539.tar.xz |
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
-rw-r--r-- | src/aircraft_cmd.cpp | 2 | ||||
-rw-r--r-- | src/engine.cpp | 68 | ||||
-rw-r--r-- | src/engine_base.h | 2 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 2 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 2 | ||||
-rw-r--r-- | src/train_cmd.cpp | 2 | ||||
-rw-r--r-- | src/vehicle.cpp | 65 | ||||
-rw-r--r-- | src/vehicle_cmd.cpp | 2 | ||||
-rw-r--r-- | src/vehicle_func.h | 2 |
9 files changed, 74 insertions, 73 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 7308392d2..861a88a08 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -306,7 +306,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine * v->InvalidateNewGRFCacheOfChain(); - v->cargo_cap = GetVehicleCapacity(v, &u->cargo_cap); + v->cargo_cap = e->DetermineCapacity(v, &u->cargo_cap); v->InvalidateNewGRFCacheOfChain(); diff --git a/src/engine.cpp b/src/engine.cpp index f0839aea7..bd0f9c317 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -196,6 +196,72 @@ bool Engine::CanCarryCargo() const return this->GetDefaultCargoType() != CT_INVALID; } + +/** + * Determines capacity of a given vehicle from scratch. + * For aircraft the main capacity is determined. Mail might be present as well. + * @note Keep this function consistent with Engine::GetDisplayDefaultCapacity(). + * @param v Vehicle of interest + * @param mail_capacity returns secondary cargo (mail) capacity of aircraft + * @return Capacity + */ +uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const +{ + assert(this->index == v->engine_type); + if (mail_capacity != NULL) *mail_capacity = 0; + + if (!this->CanCarryCargo()) return 0; + + if (mail_capacity != NULL && this->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { + *mail_capacity = GetVehicleProperty(v, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity); + } + CargoID default_cargo = this->GetDefaultCargoType(); + + /* 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. */ + if (HasBit(this->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) && + (default_cargo != v->cargo_type || 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; + switch (this->type) { + case VEH_TRAIN: capacity = GetVehicleProperty(v, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity); break; + case VEH_ROAD: capacity = GetVehicleProperty(v, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity); break; + case VEH_SHIP: capacity = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity); break; + case VEH_AIRCRAFT: capacity = GetVehicleProperty(v, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity); 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) { + if (this->type == VEH_AIRCRAFT) { + if (!IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { + capacity += GetVehicleProperty(v, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity); + } + if (v->cargo_type == CT_MAIL) return capacity; + } else { + switch (default_cargo) { + case CT_PASSENGERS: break; + case CT_MAIL: + case CT_GOODS: capacity *= 2; break; + default: capacity *= 4; break; + } + } + switch (v->cargo_type) { + case CT_PASSENGERS: break; + case CT_MAIL: + case CT_GOODS: capacity /= 2; break; + default: capacity /= 4; break; + } + } + + return capacity; +} + /** * Determines the default cargo capacity of an engine for display purposes. * @@ -203,7 +269,7 @@ bool Engine::CanCarryCargo() const * For multiheaded engines this is the capacity of both heads. * For articulated engines use GetCapacityOfArticulatedParts * - * @note Keep this function consistent with GetVehicleCapacity(). + * @note Keep this function consistent with Engine::DetermineCapacity(). * @param mail_capacity returns secondary cargo (mail) capacity of aircraft * @return The default capacity * @see GetDefaultCargoType diff --git a/src/engine_base.h b/src/engine_base.h index f118b8387..9a6930868 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -83,6 +83,8 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { return this->info.cargo_type; } + uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity = NULL) const; + bool CanCarryCargo() const; uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const; Money GetRunningCost() const; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 3fe5ce84e..ff18089a5 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -290,7 +290,7 @@ CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engin /* Call various callbacks after the whole consist has been constructed */ for (RoadVehicle *u = v; u != NULL; u = u->Next()) { - u->cargo_cap = GetVehicleCapacity(u); + u->cargo_cap = u->GetEngine()->DetermineCapacity(u); v->InvalidateNewGRFCache(); u->InvalidateNewGRFCache(); } diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index fe9367881..66f7746ad 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -675,7 +675,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, u v->InvalidateNewGRFCacheOfChain(); - v->cargo_cap = GetVehicleCapacity(v); + v->cargo_cap = e->DetermineCapacity(v); v->InvalidateNewGRFCacheOfChain(); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 8d9b4fe42..2ba40618e 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -216,7 +216,7 @@ void Train::ConsistChanged(bool same_length) } } - u->cargo_cap = GetVehicleCapacity(u); + u->cargo_cap = e_u->DetermineCapacity(u); u->vcache.cached_cargo_age_period = GetVehicleProperty(u, PROP_TRAIN_CARGO_AGE_PERIOD, e_u->info.cargo_age_period); /* check the vehicle length (callback) */ diff --git a/src/vehicle.cpp b/src/vehicle.cpp index b181038bd..dd7186fc6 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1794,71 +1794,6 @@ PaletteID GetVehiclePalette(const Vehicle *v) } /** - * Determines capacity of a given vehicle from scratch. - * For aircraft the main capacity is determined. Mail might be present as well. - * @note Keep this function consistent with Engine::GetDisplayDefaultCapacity(). - * @param v Vehicle of interest - * @param mail_capacity returns secondary cargo (mail) capacity of aircraft - * @return Capacity - */ -uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity) -{ - if (mail_capacity != NULL) *mail_capacity = 0; - const Engine *e = v->GetEngine(); - - if (!e->CanCarryCargo()) return 0; - - if (mail_capacity != NULL && e->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { - *mail_capacity = GetVehicleProperty(v, PROP_AIRCRAFT_MAIL_CAPACITY, e->u.air.mail_capacity); - } - CargoID default_cargo = e->GetDefaultCargoType(); - - /* 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. */ - if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) && - (default_cargo != v->cargo_type || v->cargo_subtype != 0)) { - uint16 callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v); - if (callback != CALLBACK_FAILED) return callback; - } - - /* Get capacity according to property resp. CB */ - uint capacity; - switch (e->type) { - case VEH_TRAIN: capacity = GetVehicleProperty(v, PROP_TRAIN_CARGO_CAPACITY, e->u.rail.capacity); break; - case VEH_ROAD: capacity = GetVehicleProperty(v, PROP_ROADVEH_CARGO_CAPACITY, e->u.road.capacity); break; - case VEH_SHIP: capacity = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, e->u.ship.capacity); break; - case VEH_AIRCRAFT: capacity = GetVehicleProperty(v, PROP_AIRCRAFT_PASSENGER_CAPACITY, e->u.air.passenger_capacity); break; - default: NOT_REACHED(); - } - - /* Apply multipliers depending on cargo- and vehicletype. - * Note: This might change to become more consistent/flexible. */ - if (e->type != VEH_SHIP) { - if (e->type == VEH_AIRCRAFT) { - if (!IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { - capacity += GetVehicleProperty(v, PROP_AIRCRAFT_MAIL_CAPACITY, e->u.air.mail_capacity); - } - if (v->cargo_type == CT_MAIL) return capacity; - } else { - switch (default_cargo) { - case CT_PASSENGERS: break; - case CT_MAIL: - case CT_GOODS: capacity *= 2; break; - default: capacity *= 4; break; - } - } - switch (v->cargo_type) { - case CT_PASSENGERS: break; - case CT_MAIL: - case CT_GOODS: capacity /= 2; break; - default: capacity /= 4; break; - } - } - - return capacity; -} - -/** * Delete all implicit orders which were not reached. */ void Vehicle::DeleteUnreachedImplicitOrders() diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 089fb0ec4..4293e5f75 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -324,7 +324,7 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles, } uint16 mail_capacity = 0; - uint amount = GetVehicleCapacity(v, &mail_capacity); + uint amount = e->DetermineCapacity(v, &mail_capacity); total_capacity += amount; /* mail_capacity will always be zero if the vehicle is not an aircraft. */ total_mail_capacity += mail_capacity; diff --git a/src/vehicle_func.h b/src/vehicle_func.h index 972cfa2b4..b8caaf298 100644 --- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -112,8 +112,6 @@ const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, En SpriteID GetEnginePalette(EngineID engine_type, CompanyID company); SpriteID GetVehiclePalette(const Vehicle *v); -uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity = NULL); - extern const uint32 _veh_build_proc_table[]; extern const uint32 _veh_sell_proc_table[]; extern const uint32 _veh_refit_proc_table[]; |