1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 01:12:39 +01:00

Codechange: Use vector for industry random sounds. (#12606)

Use a vector to store the list of random sounds played for an industry.

The removes manual memory allocation, flags to control memory management, a separate count member, and a try/catch block.
This commit is contained in:
Peter Nelson
2024-05-01 20:55:00 +01:00
committed by GitHub
parent 7147fe9e7a
commit f146680121
4 changed files with 52 additions and 75 deletions

View File

@@ -1166,11 +1166,11 @@ static void ProduceIndustryGoods(Industry *i)
/* play a sound? */
if ((i->counter & 0x3F) == 0) {
uint32_t r;
if (Chance16R(1, 14, r) && indsp->number_of_sounds != 0 && _settings_client.sound.ambient) {
if (Chance16R(1, 14, r) && !indsp->random_sounds.empty() && _settings_client.sound.ambient) {
if (std::any_of(std::begin(i->produced), std::end(i->produced), [](const auto &p) { return p.history[LAST_MONTH].production > 0; })) {
/* Play sound since last month had production */
SndPlayTileFx(
(SoundFx)(indsp->random_sounds[((r >> 16) * indsp->number_of_sounds) >> 16]),
static_cast<SoundFx>(indsp->random_sounds[((r >> 16) * indsp->random_sounds.size()) >> 16]),
i->location.tile);
}
}
@@ -3170,13 +3170,6 @@ bool IndustrySpec::UsesOriginalEconomy() const
HasBit(this->callback_mask, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CHANGE) || HasBit(this->callback_mask, CBM_IND_PROD_CHANGE_BUILD); // production change callbacks
}
IndustrySpec::~IndustrySpec()
{
if (HasBit(this->cleanup_flag, CLEAN_RANDOMSOUNDS)) {
free(this->random_sounds);
}
}
static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
{
if (AutoslopeEnabled()) {