Fix weight calculation

pull/286/head
Andreas Schmitt 3 years ago
parent 49226eac5d
commit 9a72d741ad

@ -267,7 +267,7 @@ public:
return const_cast<Train *>(const_cast<const Train *>(this)->GetStationLoadingVehicle());
}
inline uint16 GetCargoWeight(uint cargo_amount) const
uint16 GetCargoWeight(uint cargo_amount) const
{
if (cargo_amount > 0) {
return (CargoSpec::Get(this->cargo_type)->weight * cargo_amount * FreightWagonMult(this->cargo_type)) / 16;
@ -277,10 +277,10 @@ public:
}
/**
* Gets the weight of this vehicle when empty.
* @return Empty weight in tonnes.
*/
uint16 GetEmptyWeight() const
* Allows to know the weight value that this vehicle will use (excluding cargo).
* @return Weight value from the engine in tonnes.
*/
uint16 GetWeightWithoutCargo() const
{
uint16 weight = 0;
@ -294,28 +294,16 @@ public:
weight += RailVehInfo(this->gcache.first_engine)->pow_wag_weight;
}
return weight * (this->IsWagon() ? FreightWagonMult(this->cargo_type) : 1);
return weight;
}
/**
* Gets the weight of this vehicle when fully loaded.
* @return Loaded weight in tonnes.
*/
uint16 GetLoadedWeight() const
* Allows to know the weight value that this vehicle will use (cargo only).
* @return Weight value from the engine in tonnes.
*/
uint16 GetCargoWeight() const
{
uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo_cap) / 16;
/* Vehicle weight is not added for articulated parts. */
if (!this->IsArticulatedPart()) {
weight += GetVehicleProperty(this, PROP_TRAIN_WEIGHT, RailVehInfo(this->engine_type)->weight);
}
/* Powered wagons have extra weight added. */
if (HasBit(this->flags, VRF_POWEREDWAGON)) {
weight += RailVehInfo(this->gcache.first_engine)->pow_wag_weight;
}
return weight * (this->IsWagon() ? FreightWagonMult(this->cargo_type) : 1);
return this->GetCargoWeight(this->cargo.StoredCount());
}
protected: // These functions should not be called outside acceleration code.
@ -369,36 +357,6 @@ protected: // These functions should not be called outside acceleration code.
return 0;
}
/**
* Allows to know the weight value that this vehicle will use (excluding cargo).
* @return Weight value from the engine in tonnes.
*/
inline uint16 GetWeightWithoutCargo() const
{
uint16 weight = 0;
/* Vehicle weight is not added for articulated parts. */
if (!this->IsArticulatedPart()) {
weight += GetVehicleProperty(this, PROP_TRAIN_WEIGHT, RailVehInfo(this->engine_type)->weight);
}
/* Powered wagons have extra weight added. */
if (HasBit(this->flags, VRF_POWEREDWAGON)) {
weight += RailVehInfo(this->gcache.first_engine)->pow_wag_weight;
}
return weight;
}
/**
* Allows to know the weight value that this vehicle will use (cargo only).
* @return Weight value from the engine in tonnes.
*/
inline uint16 GetCargoWeight() const
{
return this->GetCargoWeight(this->cargo.StoredCount());
}
/**
* Allows to know the weight value that this vehicle will use.
* @return Weight value from the engine in tonnes.

@ -518,18 +518,20 @@ void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_po
int loaded_max_speed = 0;
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
const Train *train = Train::From(u);
const auto weight_without_cargo = train->GetWeightWithoutCargo();
act_cargo[u->cargo_type] += u->cargo.StoredCount();
max_cargo[u->cargo_type] += u->cargo_cap;
feeder_share += u->cargo.FeederShare();
empty_weight += Train::From(u)->GetEmptyWeight();
loaded_weight += Train::From(u)->GetLoadedWeight();
empty_weight += weight_without_cargo;
loaded_weight += weight_without_cargo + train->GetCargoWeight(train->cargo_cap);
}
const auto rolling_friction = 15 * (512 + v->GetDisplayMaxSpeed()) / 512;
const auto tractive_effort_empty = empty_weight * rolling_friction;
const auto tractive_effort_loaded = loaded_weight * rolling_friction;
const int power = v->gcache.cached_power * 746;
const int max_te = v->gcache.cached_max_te;
const int power = static_cast<int>(v->gcache.cached_power * 746);
const int max_te = static_cast<int>(v->gcache.cached_max_te);
empty_max_speed = std::min(v->GetDisplayMaxSpeed(), (tractive_effort_empty == 0 || tractive_effort_empty > max_te) ? 0 : static_cast<int>((3.6 * power) / tractive_effort_empty));
loaded_max_speed = std::min(v->GetDisplayMaxSpeed(), (tractive_effort_loaded == 0 || tractive_effort_loaded > max_te) ? 0 : static_cast<int>((3.6 * power) / tractive_effort_loaded));

Loading…
Cancel
Save