summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/newgrf.cpp7
-rw-r--r--src/newgrf_spritegroup.cpp9
-rw-r--r--src/newgrf_spritegroup.h4
3 files changed, 6 insertions, 14 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index ba5c098a2..0377c0bc5 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -5128,11 +5128,10 @@ static void NewSpriteGroup(ByteReader *buf)
group->triggers = GB(triggers, 0, 7);
group->cmp_mode = HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
group->lowest_randbit = buf->ReadByte();
- group->num_groups = buf->ReadByte();
- group->groups = CallocT<const SpriteGroup*>(group->num_groups);
- for (uint i = 0; i < group->num_groups; i++) {
- group->groups[i] = GetGroupFromGroupID(setid, type, buf->ReadWord());
+ byte num_groups = buf->ReadByte();
+ for (uint i = 0; i < num_groups; i++) {
+ group->groups.push_back(GetGroupFromGroupID(setid, type, buf->ReadWord()));
}
break;
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index 058baf334..eef531fb2 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -53,11 +53,6 @@ TemporaryStorageArray<int32, 0x110> _temp_store;
}
}
-RandomizedSpriteGroup::~RandomizedSpriteGroup()
-{
- free(this->groups);
-}
-
static inline uint32 GetVariable(const ResolverObject &object, ScopeResolver *scope, byte variable, uint32 parameter, bool *available)
{
uint32 value;
@@ -272,11 +267,11 @@ const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject &object) const
if (res) {
object.used_triggers |= match;
- object.reseed[this->var_scope] |= (this->num_groups - 1) << this->lowest_randbit;
+ object.reseed[this->var_scope] |= (this->groups.size() - 1) << this->lowest_randbit;
}
}
- uint32 mask = (this->num_groups - 1) << this->lowest_randbit;
+ uint32 mask = ((uint)this->groups.size() - 1) << this->lowest_randbit;
byte index = (scope->GetRandomBits() & mask) >> this->lowest_randbit;
return SpriteGroup::Resolve(this->groups[index], object, false);
diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h
index e91987dbb..b17266761 100644
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -189,7 +189,6 @@ enum RandomizedSpriteGroupCompareMode {
struct RandomizedSpriteGroup : SpriteGroup {
RandomizedSpriteGroup() : SpriteGroup(SGT_RANDOMIZED) {}
- ~RandomizedSpriteGroup();
VarSpriteGroupScope var_scope; ///< Take this object:
@@ -198,9 +197,8 @@ struct RandomizedSpriteGroup : SpriteGroup {
byte count;
byte lowest_randbit; ///< Look for this in the per-object randomized bitmask:
- byte num_groups; ///< must be power of 2
- const SpriteGroup **groups; ///< Take the group with appropriate index:
+ std::vector<const SpriteGroup *> groups; ///< Take the group with appropriate index:
protected:
const SpriteGroup *Resolve(ResolverObject &object) const;