summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/industry.h6
-rw-r--r--src/newgrf.cpp18
-rw-r--r--src/table/build_industry.h2
3 files changed, 25 insertions, 1 deletions
diff --git a/src/industry.h b/src/industry.h
index df29a7189..ff5e563b0 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -22,6 +22,11 @@ enum {
INVALID_INDUSTRYTILE = NUM_INDUSTRYTILES, ///< one above amount is considered invalid
};
+enum {
+ CLEAN_RANDOMSOUNDS, ///< Free the dynamically allocated sounds table
+ CLEAN_TILELSAYOUT, ///< Free the dynamically allocated tile layout structure
+};
+
enum IndustryLifeType {
INDUSTRYLIFE_NOT_CLOSABLE, ///< Industry can never close
INDUSTRYLIFE_PRODUCTION, ///< Industry can close and change of production
@@ -135,6 +140,7 @@ struct IndustrySpec {
const uint8 *random_sounds; ///< array of random sounds.
/* Newgrf data */
uint16 callback_flags; ///< Flags telling which grf callback is set
+ uint8 cleanup_flag; ///< flags indicating which data should be freed upon cleaning up
bool enabled; ///< entity still avaible (by default true).newgrf can disable it, though
struct GRFFileProps grf_prop; ///< properties related the the grf file
};
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index cc44682d0..8d50fef12 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -4326,6 +4326,24 @@ static void ResetCustomIndustries()
IndustrySpec *ind = file->industryspec[i];
if (ind != NULL) {
+ /* We need to remove the sounds array */
+ if (HASBIT(ind->cleanup_flag, CLEAN_RANDOMSOUNDS)) {
+ free((void*)ind->random_sounds);
+ }
+
+ /* We need to remove the tiles layouts */
+ if (HASBIT(ind->cleanup_flag, CLEAN_TILELSAYOUT) && ind->table != NULL) {
+ for (int j = 0; j < ind->num_table; j++) {
+ /* remove the individual layouts */
+ if (ind->table[j] != NULL) {
+ free((IndustryTileTable*)ind->table[j]);
+ }
+ }
+ /* remove the layouts pointers */
+ free((IndustryTileTable**)ind->table);
+ ind->table = NULL;
+ }
+
free(ind);
ind = NULL;
}
diff --git a/src/table/build_industry.h b/src/table/build_industry.h
index 6c1072b54..d9acb65ee 100644
--- a/src/table/build_industry.h
+++ b/src/table/build_industry.h
@@ -1135,7 +1135,7 @@ static const uint8 _plastic_mine_sounds[] = { SND_33_PLASTIC_MINE };
c1, c2, c3, proc, p1, r1, p2, r2, m, a1, im1, a2, im2, a3, im3, pr, clim, bev, in, intx, s1, s2, s3) \
{tbl, lengthof(tbl), d, {c1, c2, c3}, proc, {p1, p2}, {r1, r2}, m, \
{a1, a2, a3}, {{im1, 0}, {im2, 0}, {im3, 0}}, pr, clim, bev, col, in, intx, s1, s2, s3, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \
- sndc, snd, 0, true, {0, 0, NULL, NULL, INVALID_INDUSTRYTYPE}}
+ sndc, snd, 0, 0, true, {0, 0, NULL, NULL, INVALID_INDUSTRYTYPE}}
/* Format:
tile table count and sounds table
cost multiplier appear chances(4ingame, 4random) map colour