summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/newgrf.cpp9
-rw-r--r--src/newgrf_airport.cpp4
-rw-r--r--src/newgrf_canal.cpp2
-rw-r--r--src/newgrf_cargo.cpp4
-rw-r--r--src/newgrf_engine.cpp6
-rw-r--r--src/newgrf_generic.cpp2
-rw-r--r--src/newgrf_railtype.cpp4
-rw-r--r--src/newgrf_roadtype.cpp4
-rw-r--r--src/newgrf_spritegroup.cpp6
-rw-r--r--src/newgrf_spritegroup.h7
-rw-r--r--src/newgrf_station.cpp8
11 files changed, 21 insertions, 35 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 19cc436dd..1d30cb2d7 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -5181,23 +5181,18 @@ static void NewSpriteGroup(ByteReader *buf)
group->nfo_line = _cur.nfo_line;
act_group = group;
- group->num_loaded = num_loaded;
- group->num_loading = num_loading;
- if (num_loaded > 0) group->loaded = CallocT<const SpriteGroup*>(num_loaded);
- if (num_loading > 0) group->loading = CallocT<const SpriteGroup*>(num_loading);
-
grfmsg(6, "NewSpriteGroup: New SpriteGroup 0x%02X, %u loaded, %u loading",
setid, num_loaded, num_loading);
for (uint i = 0; i < num_loaded; i++) {
uint16 spriteid = buf->ReadWord();
- group->loaded[i] = CreateGroupFromGroupID(feature, setid, type, spriteid);
+ group->loaded.push_back(CreateGroupFromGroupID(feature, setid, type, spriteid));
grfmsg(8, "NewSpriteGroup: + rg->loaded[%i] = subset %u", i, spriteid);
}
for (uint i = 0; i < num_loading; i++) {
uint16 spriteid = buf->ReadWord();
- group->loading[i] = CreateGroupFromGroupID(feature, setid, type, spriteid);
+ group->loading.push_back(CreateGroupFromGroupID(feature, setid, type, spriteid));
grfmsg(8, "NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
}
diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp
index 61ad46ac0..86b65fd0e 100644
--- a/src/newgrf_airport.cpp
+++ b/src/newgrf_airport.cpp
@@ -223,8 +223,8 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
{
/* Airport action 2s should always have only 1 "loaded" state, but some
* times things don't follow the spec... */
- if (group->num_loaded > 0) return group->loaded[0];
- if (group->num_loading > 0) return group->loading[0];
+ if (!group->loaded.empty()) return group->loaded[0];
+ if (!group->loading.empty()) return group->loading[0];
return nullptr;
}
diff --git a/src/newgrf_canal.cpp b/src/newgrf_canal.cpp
index 7295e5551..6b3c9b3d4 100644
--- a/src/newgrf_canal.cpp
+++ b/src/newgrf_canal.cpp
@@ -111,7 +111,7 @@ struct CanalResolverObject : public ResolverObject {
/* virtual */ const SpriteGroup *CanalResolverObject::ResolveReal(const RealSpriteGroup *group) const
{
- if (group->num_loaded == 0) return nullptr;
+ if (group->loaded.empty()) return nullptr;
return group->loaded[0];
}
diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp
index c2859b71e..105a2b252 100644
--- a/src/newgrf_cargo.cpp
+++ b/src/newgrf_cargo.cpp
@@ -29,8 +29,8 @@ struct CargoResolverObject : public ResolverObject {
{
/* Cargo action 2s should always have only 1 "loaded" state, but some
* times things don't follow the spec... */
- if (group->num_loaded > 0) return group->loaded[0];
- if (group->num_loading > 0) return group->loading[0];
+ if (!group->loaded.empty()) return group->loaded[0];
+ if (!group->loading.empty()) return group->loading[0];
return nullptr;
}
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index cd1214855..e028b7a7d 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -992,14 +992,14 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
const Vehicle *v = this->self_scope.v;
if (v == nullptr) {
- if (group->num_loading > 0) return group->loading[0];
- if (group->num_loaded > 0) return group->loaded[0];
+ if (!group->loading.empty()) return group->loading[0];
+ if (!group->loaded.empty()) return group->loaded[0];
return nullptr;
}
bool in_motion = !v->First()->current_order.IsType(OT_LOADING);
- uint totalsets = in_motion ? group->num_loaded : group->num_loading;
+ uint totalsets = in_motion ? (uint)group->loaded.size() : (uint)group->loading.size();
if (totalsets == 0) return nullptr;
diff --git a/src/newgrf_generic.cpp b/src/newgrf_generic.cpp
index 6538b79b6..0a138f1d6 100644
--- a/src/newgrf_generic.cpp
+++ b/src/newgrf_generic.cpp
@@ -150,7 +150,7 @@ void AddGenericCallback(uint8 feature, const GRFFile *file, const SpriteGroup *g
/* virtual */ const SpriteGroup *GenericResolverObject::ResolveReal(const RealSpriteGroup *group) const
{
- if (group->num_loaded == 0) return nullptr;
+ if (group->loaded.empty()) return nullptr;
return group->loaded[0];
}
diff --git a/src/newgrf_railtype.cpp b/src/newgrf_railtype.cpp
index 326ee80ba..407acc984 100644
--- a/src/newgrf_railtype.cpp
+++ b/src/newgrf_railtype.cpp
@@ -60,8 +60,8 @@
/* virtual */ const SpriteGroup *RailTypeResolverObject::ResolveReal(const RealSpriteGroup *group) const
{
- if (group->num_loading > 0) return group->loading[0];
- if (group->num_loaded > 0) return group->loaded[0];
+ if (!group->loading.empty()) return group->loading[0];
+ if (!group->loaded.empty()) return group->loaded[0];
return nullptr;
}
diff --git a/src/newgrf_roadtype.cpp b/src/newgrf_roadtype.cpp
index 025d03bb6..9243bf77e 100644
--- a/src/newgrf_roadtype.cpp
+++ b/src/newgrf_roadtype.cpp
@@ -60,8 +60,8 @@
/* virtual */ const SpriteGroup *RoadTypeResolverObject::ResolveReal(const RealSpriteGroup *group) const
{
- if (group->num_loading > 0) return group->loading[0];
- if (group->num_loaded > 0) return group->loaded[0];
+ if (!group->loading.empty()) return group->loading[0];
+ if (!group->loaded.empty()) return group->loaded[0];
return nullptr;
}
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index 871108ec4..fb0d65c31 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -53,12 +53,6 @@ TemporaryStorageArray<int32, 0x110> _temp_store;
}
}
-RealSpriteGroup::~RealSpriteGroup()
-{
- free(this->loaded);
- free(this->loading);
-}
-
DeterministicSpriteGroup::~DeterministicSpriteGroup()
{
free(this->adjusts);
diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h
index 80f70df55..a931597a0 100644
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -78,7 +78,6 @@ public:
* groups. */
struct RealSpriteGroup : SpriteGroup {
RealSpriteGroup() : SpriteGroup(SGT_REAL) {}
- ~RealSpriteGroup();
/* Loaded = in motion, loading = not moving
* Each group contains several spritesets, for various loading stages */
@@ -87,10 +86,8 @@ struct RealSpriteGroup : SpriteGroup {
* with small amount of cargo whilst loading is for stations with a lot
* of da stuff. */
- byte num_loaded; ///< Number of loaded groups
- byte num_loading; ///< Number of loading groups
- const SpriteGroup **loaded; ///< List of loaded groups (can be SpriteIDs or Callback results)
- const SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results)
+ std::vector<const SpriteGroup *> loaded; ///< List of loaded groups (can be SpriteIDs or Callback results)
+ std::vector<const SpriteGroup *> loading; ///< List of loading groups (can be SpriteIDs or Callback results)
protected:
const SpriteGroup *Resolve(ResolverObject &object) const;
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index fa3f831aa..9aa3ad43b 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -523,13 +523,13 @@ uint32 Waypoint::GetNewGRFVariable(const ResolverObject &object, byte variable,
cargo = std::min(0xfffu, cargo);
if (cargo > this->station_scope.statspec->cargo_threshold) {
- if (group->num_loading > 0) {
- uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * group->num_loading) / (4096 - 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];
}
} else {
- if (group->num_loaded > 0) {
- uint set = (cargo * group->num_loaded) / (this->station_scope.statspec->cargo_threshold + 1);
+ if (!group->loaded.empty()) {
+ uint set = (cargo * (uint)group->loaded.size()) / (this->station_scope.statspec->cargo_threshold + 1);
return group->loaded[set];
}
}