| 1158 | } |
| 1159 | |
| 1160 | static void ProduceIndustryGoods(Industry *i) |
| 1161 | { |
| 1162 | const IndustrySpec *indsp = GetIndustrySpec(i->type); |
| 1163 | |
| 1164 | /* play a sound? */ |
| 1165 | if ((i->counter & 0x3F) == 0) { |
| 1166 | uint32_t r; |
| 1167 | if (Chance16R(1, 14, r) && !indsp->random_sounds.empty() && _settings_client.sound.ambient) { |
| 1168 | if (std::any_of(std::begin(i->produced), std::end(i->produced), [](const auto &p) { return p.history[LAST_MONTH].production > 0; })) { |
| 1169 | /* Play sound since last month had production */ |
| 1170 | SndPlayTileFx( |
| 1171 | static_cast<SoundFx>(indsp->random_sounds[((r >> 16) * indsp->random_sounds.size()) >> 16]), |
| 1172 | i->location.tile); |
| 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | i->counter--; |
| 1178 | |
| 1179 | /* If using an industry callback, scale the callback interval by cargo scale percentage. */ |
| 1180 | if (indsp->callback_mask.Test(IndustryCallbackMask::Production256Ticks)) { |
| 1181 | if (i->counter % ScaleByInverseCargoScale(Ticks::INDUSTRY_PRODUCE_TICKS, false) == 0) { |
| 1182 | IndustryProductionCallback(i, 1); |
| 1183 | ProduceIndustryGoodsHelper(i, false); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | /* |
| 1188 | * All other production and special effects happen every 256 ticks, and cargo production is just scaled by the cargo scale percentage. |
| 1189 | * This keeps a slow trickle of production to avoid confusion at low scale factors when the industry seems to be doing nothing for a long period of time. |
| 1190 | */ |
| 1191 | if ((i->counter % Ticks::INDUSTRY_PRODUCE_TICKS) == 0) { |
| 1192 | /* Handle non-callback cargo production. */ |
| 1193 | if (!indsp->callback_mask.Test(IndustryCallbackMask::Production256Ticks)) ProduceIndustryGoodsHelper(i, true); |
| 1194 | |
| 1195 | IndustryBehaviours indbehav = indsp->behaviour; |
| 1196 | |
| 1197 | if (indbehav.Test(IndustryBehaviour::PlantFields)) { |
| 1198 | uint16_t cb_res = CALLBACK_FAILED; |
| 1199 | if (indsp->callback_mask.Test(IndustryCallbackMask::SpecialEffect)) { |
| 1200 | cb_res = GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->location.tile); |
| 1201 | } |
| 1202 | |
| 1203 | bool plant; |
| 1204 | if (cb_res != CALLBACK_FAILED) { |
| 1205 | plant = ConvertBooleanCallback(indsp->grf_prop.grffile, CBID_INDUSTRY_SPECIAL_EFFECT, cb_res); |
| 1206 | } else { |
| 1207 | plant = Chance16(1, 8); |
| 1208 | } |
| 1209 | |
| 1210 | if (plant) PlantRandomFarmField(i); |
| 1211 | } |
| 1212 | if (indbehav.Test(IndustryBehaviour::CutTrees)) { |
| 1213 | uint16_t cb_res = CALLBACK_FAILED; |
| 1214 | if (indsp->callback_mask.Test(IndustryCallbackMask::SpecialEffect)) { |
| 1215 | cb_res = GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 1, i, i->type, i->location.tile); |
| 1216 | } |
| 1217 |
no test coverage detected