MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetIndustryGamePlayProbability

Function GetIndustryGamePlayProbability

src/industry_cmd.cpp:2333–2351  ·  view source on GitHub ↗

* Compute the probability for constructing a new industry during game play. * @param it Industry type to compute. * @param[out] min_number Minimal number of industries that should exist at the map. * @return Relative probability for the industry to appear. */

Source from the content-addressed store, hash-verified

2331 * @return Relative probability for the industry to appear.
2332 */
2333static uint16_t GetIndustryGamePlayProbability(IndustryType it, uint8_t *min_number)
2334{
2335 if (_settings_game.difficulty.industry_density == ID_FUND_ONLY) {
2336 *min_number = 0;
2337 return 0;
2338 }
2339
2340 const IndustrySpec *ind_spc = GetIndustrySpec(it);
2341 uint8_t chance = ind_spc->appear_ingame[to_underlying(_settings_game.game_creation.landscape)];
2342 if (!ind_spc->enabled || ind_spc->layouts.empty() ||
2343 (ind_spc->behaviour.Test(IndustryBehaviour::Before1950) && TimerGameCalendar::year > 1950) ||
2344 (ind_spc->behaviour.Test(IndustryBehaviour::After1960) && TimerGameCalendar::year < 1960) ||
2345 (chance = GetIndustryProbabilityCallback(it, IACT_RANDOMCREATION, chance)) == 0) {
2346 *min_number = 0;
2347 return 0;
2348 }
2349 *min_number = ind_spc->behaviour.Test(IndustryBehaviour::CanCloseLastInstance) ? 1 : 0;
2350 return chance;
2351}
2352
2353/**
2354 * Get wanted number of industries on the map.

Callers 1

GetIndustryTypeDataMethod · 0.85

Calls 5

GetIndustrySpecFunction · 0.85
to_underlyingFunction · 0.85
TestMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected