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];