Multi-cargo ships: Sprite group cargo thresholds refer to entire ship

This commit is contained in:
Jonathan G Rennison
2024-02-01 18:48:07 +00:00
parent 47393b42dc
commit 9f55550417
4 changed files with 15 additions and 2 deletions

View File

@@ -1151,8 +1151,18 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
uint totalsets = in_motion ? (uint)group->loaded.size() : (uint)group->loading.size();
if (totalsets == 0) return nullptr;
if (totalsets == 1) return in_motion ? group->loaded[0] : group->loading[0];
uint set = (v->cargo.StoredCount() * totalsets) / std::max<uint16_t>(1u, v->cargo_cap);
uint stored = v->cargo.StoredCount();
uint capacity = v->cargo_cap;
if (v->type == VEH_SHIP) {
for (const Vehicle *u = v->Next(); u != nullptr; u = u->Next()) {
stored += u->cargo.StoredCount();
capacity += u->cargo_cap;
}
}
uint set = (stored * totalsets) / std::max<uint16_t>(1u, capacity);
set = std::min(set, totalsets - 1);
return in_motion ? group->loaded[set] : group->loading[set];

View File

@@ -72,7 +72,7 @@ extern const GRFFeatureInfo _grf_feature_list[] = {
GRFFeatureInfo("town_zone_callback", 1, GFTOF_TOWN_ZONE_CALLBACK),
GRFFeatureInfo("varaction2_towns_town_xy", 1),
GRFFeatureInfo("more_varaction2_types", 1, GFTOF_MORE_VARACTION2_TYPES),
GRFFeatureInfo("multi_part_ships", 2, GFTOF_MULTI_PART_SHIPS),
GRFFeatureInfo("multi_part_ships", 3, GFTOF_MULTI_PART_SHIPS),
GRFFeatureInfo("more_stations_per_grf", 1),
GRFFeatureInfo(),
};