mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Factor cargotype weight conversion magic numbers
parent
019dcb7b7b
commit
89cf0d5da8
|
@ -590,7 +590,7 @@ static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine
|
||||||
/* Wagon weight - (including cargo) */
|
/* Wagon weight - (including cargo) */
|
||||||
uint weight = e->GetDisplayWeight();
|
uint weight = e->GetDisplayWeight();
|
||||||
SetDParam(0, weight);
|
SetDParam(0, weight);
|
||||||
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
|
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->WeightOfNUnitsInTrain(te.capacity) : 0);
|
||||||
SetDParam(1, cargo_weight + weight);
|
SetDParam(1, cargo_weight + weight);
|
||||||
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
|
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
|
||||||
y += FONT_HEIGHT_NORMAL;
|
y += FONT_HEIGHT_NORMAL;
|
||||||
|
@ -684,7 +684,7 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
|
||||||
/* Road vehicle weight - (including cargo) */
|
/* Road vehicle weight - (including cargo) */
|
||||||
int16 weight = e->GetDisplayWeight();
|
int16 weight = e->GetDisplayWeight();
|
||||||
SetDParam(0, weight);
|
SetDParam(0, weight);
|
||||||
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
|
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->WeightOfNUnits(te.capacity) : 0);
|
||||||
SetDParam(1, cargo_weight + weight);
|
SetDParam(1, cargo_weight + weight);
|
||||||
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
|
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
|
||||||
y += FONT_HEIGHT_NORMAL;
|
y += FONT_HEIGHT_NORMAL;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "newgrf_cargo.h"
|
#include "newgrf_cargo.h"
|
||||||
#include "string_func.h"
|
#include "string_func.h"
|
||||||
#include "strings_func.h"
|
#include "strings_func.h"
|
||||||
|
#include "settings_type.h"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
@ -209,3 +210,8 @@ void InitializeSortedCargoSpecs()
|
||||||
_sorted_standard_cargo_specs = { _sorted_cargo_specs.data(), nb_standard_cargo };
|
_sorted_standard_cargo_specs = { _sorted_cargo_specs.data(), nb_standard_cargo };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64 CargoSpec::WeightOfNUnitsInTrain(uint32 n) const
|
||||||
|
{
|
||||||
|
if (this->is_freight) n *= _settings_game.vehicle.freight_trains;
|
||||||
|
return this->WeightOfNUnits(n);
|
||||||
|
}
|
||||||
|
|
|
@ -123,6 +123,13 @@ struct CargoSpec {
|
||||||
|
|
||||||
SpriteID GetCargoIcon() const;
|
SpriteID GetCargoIcon() const;
|
||||||
|
|
||||||
|
inline uint64 WeightOfNUnits(uint32 n) const
|
||||||
|
{
|
||||||
|
return n * this->weight / 16u;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 WeightOfNUnitsInTrain(uint32 n) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterator to iterate all valid CargoSpec
|
* Iterator to iterate all valid CargoSpec
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -178,7 +178,7 @@ protected: // These functions should not be called outside acceleration code.
|
||||||
*/
|
*/
|
||||||
inline uint16 GetWeight() const
|
inline uint16 GetWeight() const
|
||||||
{
|
{
|
||||||
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.StoredCount()) / 16;
|
uint16 weight = CargoSpec::Get(this->cargo_type)->WeightOfNUnits(this->cargo.StoredCount());
|
||||||
|
|
||||||
/* Vehicle weight is not added for articulated parts. */
|
/* Vehicle weight is not added for articulated parts. */
|
||||||
if (!this->IsArticulatedPart()) {
|
if (!this->IsArticulatedPart()) {
|
||||||
|
|
|
@ -85,5 +85,5 @@
|
||||||
/* static */ int64 ScriptCargo::GetWeight(CargoID cargo_type, uint32 amount)
|
/* static */ int64 ScriptCargo::GetWeight(CargoID cargo_type, uint32 amount)
|
||||||
{
|
{
|
||||||
if (!IsValidCargo(cargo_type)) return -1;
|
if (!IsValidCargo(cargo_type)) return -1;
|
||||||
return ::CargoSpec::Get(cargo_type)->weight * static_cast<int64>(amount) / 16;
|
return ::CargoSpec::Get(cargo_type)->WeightOfNUnits(amount);
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ protected: // These functions should not be called outside acceleration code.
|
||||||
*/
|
*/
|
||||||
inline uint16 GetWeight() const
|
inline uint16 GetWeight() const
|
||||||
{
|
{
|
||||||
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.StoredCount() * FreightWagonMult(this->cargo_type)) / 16;
|
uint16 weight = CargoSpec::Get(this->cargo_type)->WeightOfNUnitsInTrain(this->cargo.StoredCount());
|
||||||
|
|
||||||
/* Vehicle weight is not added for articulated parts. */
|
/* Vehicle weight is not added for articulated parts. */
|
||||||
if (!this->IsArticulatedPart()) {
|
if (!this->IsArticulatedPart()) {
|
||||||
|
|
Loading…
Reference in New Issue