1
0
Fork 0

Add: ScriptCargo::GetWeight to get cargo weights

pull/10027/head
SamuXarick 2022-06-22 11:34:25 +01:00 committed by Michael Lutz
parent 3d45bc4abe
commit 8d0d45c431
4 changed files with 20 additions and 0 deletions

View File

@ -17,6 +17,8 @@
* *
* This version is not yet released. The following changes are not set in stone yet. * This version is not yet released. The following changes are not set in stone yet.
* *
* API additions:
* \li AICargo::GetWeight
* \li AIIndustryType::ResolveNewGRFID * \li AIIndustryType::ResolveNewGRFID
* \li AIObjectType::ResolveNewGRFID * \li AIObjectType::ResolveNewGRFID
* *

View File

@ -17,6 +17,8 @@
* *
* This version is not yet released. The following changes are not set in stone yet. * This version is not yet released. The following changes are not set in stone yet.
* *
* API additions:
* \li GSCargo::GetWeight
* \li GSIndustryType::ResolveNewGRFID * \li GSIndustryType::ResolveNewGRFID
* \li GSObjectType::ResolveNewGRFID * \li GSObjectType::ResolveNewGRFID
* *

View File

@ -81,3 +81,9 @@
if (!ScriptCargo::IsValidCargo(cargo_type)) return INVALID_DISTRIBUTION_TYPE; if (!ScriptCargo::IsValidCargo(cargo_type)) return INVALID_DISTRIBUTION_TYPE;
return (ScriptCargo::DistributionType)_settings_game.linkgraph.GetDistributionType(cargo_type); return (ScriptCargo::DistributionType)_settings_game.linkgraph.GetDistributionType(cargo_type);
} }
/* static */ int64 ScriptCargo::GetWeight(CargoID cargo_type, uint32 amount)
{
if (!IsValidCargo(cargo_type)) return -1;
return ::CargoSpec::Get(cargo_type)->weight * static_cast<int64>(amount) / 16;
}

View File

@ -153,6 +153,16 @@ public:
* @return The cargo distribution type for the given cargo. * @return The cargo distribution type for the given cargo.
*/ */
static DistributionType GetDistributionType(CargoID cargo_type); static DistributionType GetDistributionType(CargoID cargo_type);
/**
* Get the weight in tonnes for the given amount of
* cargo for the specified type.
* @param cargo_type The cargo to check on.
* @param amount The quantity of cargo.
* @pre ScriptCargo::IsValidCargo(cargo_type).
* @return The weight in tonnes for that quantity of cargo.
*/
static int64 GetWeight(CargoID cargo_type, uint32 amount);
}; };
#endif /* SCRIPT_CARGO_HPP */ #endif /* SCRIPT_CARGO_HPP */