mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Pass SpriteGroup as reference to ResolveReal.
parent
7c946d97da
commit
e90b68d504
|
@ -998,13 +998,13 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
|||
}
|
||||
|
||||
|
||||
/* virtual */ const SpriteGroup *VehicleResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
||||
/* virtual */ const SpriteGroup *VehicleResolverObject::ResolveReal(const RealSpriteGroup &group) const
|
||||
{
|
||||
const Vehicle *v = this->self_scope.v;
|
||||
|
||||
if (v == nullptr) {
|
||||
if (!group->loading.empty()) return group->loading[0];
|
||||
if (!group->loaded.empty()) return group->loaded[0];
|
||||
if (!group.loading.empty()) return group.loading[0];
|
||||
if (!group.loaded.empty()) return group.loaded[0];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -1012,14 +1012,14 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
|||
bool not_loading = (order.GetUnloadType() & OUFB_NO_UNLOAD) && (order.GetLoadType() & OLFB_NO_LOAD);
|
||||
bool in_motion = !order.IsType(OT_LOADING) || not_loading;
|
||||
|
||||
uint totalsets = in_motion ? (uint)group->loaded.size() : (uint)group->loading.size();
|
||||
uint totalsets = static_cast<uint>(in_motion ? group.loaded.size() : group.loading.size());
|
||||
|
||||
if (totalsets == 0) return nullptr;
|
||||
|
||||
uint set = (v->cargo.StoredCount() * totalsets) / std::max<uint16_t>(1u, v->cargo_cap);
|
||||
set = std::min(set, totalsets - 1);
|
||||
|
||||
return in_motion ? group->loaded[set] : group->loading[set];
|
||||
return in_motion ? group.loaded[set] : group.loading[set];
|
||||
}
|
||||
|
||||
GrfSpecFeature VehicleResolverObject::GetFeature() const
|
||||
|
|
|
@ -64,7 +64,7 @@ struct VehicleResolverObject : public SpecializedResolverObject<VehicleRandomTri
|
|||
|
||||
ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0) override;
|
||||
|
||||
const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
|
||||
const SpriteGroup *ResolveReal(const RealSpriteGroup &group) const override;
|
||||
|
||||
GrfSpecFeature GetFeature() const override;
|
||||
uint32_t GetDebugID() const override;
|
||||
|
|
|
@ -120,10 +120,10 @@ static inline uint32_t GetVariable(const ResolverObject &object, ScopeResolver *
|
|||
* @param group Group to get.
|
||||
* @return The available sprite group.
|
||||
*/
|
||||
/* virtual */ const SpriteGroup *ResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
||||
/* virtual */ const SpriteGroup *ResolverObject::ResolveReal(const RealSpriteGroup &group) const
|
||||
{
|
||||
if (!group->loaded.empty()) return group->loaded[0];
|
||||
if (!group->loading.empty()) return group->loading[0];
|
||||
if (!group.loaded.empty()) return group.loaded[0];
|
||||
if (!group.loading.empty()) return group.loading[0];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject &object) const
|
|||
|
||||
const SpriteGroup *RealSpriteGroup::Resolve(ResolverObject &object) const
|
||||
{
|
||||
return object.ResolveReal(this);
|
||||
return object.ResolveReal(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -370,7 +370,7 @@ public:
|
|||
return result != nullptr ? result->GetCallbackResult() : CALLBACK_FAILED;
|
||||
}
|
||||
|
||||
virtual const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
|
||||
virtual const SpriteGroup *ResolveReal(const RealSpriteGroup &group) const;
|
||||
|
||||
virtual ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0);
|
||||
|
||||
|
|
|
@ -519,10 +519,10 @@ uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, uint8_t variable, [
|
|||
return UINT_MAX;
|
||||
}
|
||||
|
||||
/* virtual */ const SpriteGroup *StationResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
||||
/* virtual */ const SpriteGroup *StationResolverObject::ResolveReal(const RealSpriteGroup &group) const
|
||||
{
|
||||
if (this->station_scope.st == nullptr || !Station::IsExpected(this->station_scope.st)) {
|
||||
if (!group->loading.empty()) return group->loading[0];
|
||||
if (!group.loading.empty()) return group.loading[0];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -554,18 +554,18 @@ uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, uint8_t variable, [
|
|||
cargo = std::min(0xfffu, cargo);
|
||||
|
||||
if (cargo > this->station_scope.statspec->cargo_threshold) {
|
||||
if (!group->loading.empty()) {
|
||||
uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * (uint)group->loading.size()) / (4096 - this->station_scope.statspec->cargo_threshold);
|
||||
return group->loading[set];
|
||||
if (!group.loading.empty()) {
|
||||
uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * static_cast<uint>(group.loading.size())) / (4096 - this->station_scope.statspec->cargo_threshold);
|
||||
return group.loading[set];
|
||||
}
|
||||
} else {
|
||||
if (!group->loaded.empty()) {
|
||||
uint set = (cargo * (uint)group->loaded.size()) / (this->station_scope.statspec->cargo_threshold + 1);
|
||||
return group->loaded[set];
|
||||
if (!group.loaded.empty()) {
|
||||
uint set = (cargo * static_cast<uint>(group.loaded.size())) / (this->station_scope.statspec->cargo_threshold + 1);
|
||||
return group.loaded[set];
|
||||
}
|
||||
}
|
||||
|
||||
if (!group->loading.empty()) return group->loading[0];
|
||||
if (!group.loading.empty()) return group.loading[0];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ struct StationResolverObject : public SpecializedResolverObject<StationRandomTri
|
|||
}
|
||||
}
|
||||
|
||||
const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
|
||||
const SpriteGroup *ResolveReal(const RealSpriteGroup &group) const override;
|
||||
|
||||
GrfSpecFeature GetFeature() const override;
|
||||
uint32_t GetDebugID() const override;
|
||||
|
|
Loading…
Reference in New Issue