* Compute the appearance probability for an industry during map creation. * @param it Industry type to compute. * @param water Whether to get probability of land-based, water-based, (or both, if std::nullopt), industry types. * @param[out] force_at_least_one Returns whether at least one instance should be forced on map creation. * @return Relative probability for the industry to appear. */
| 2303 | * @return Relative probability for the industry to appear. |
| 2304 | */ |
| 2305 | static uint32_t GetScaledIndustryGenerationProbability(IndustryType it, std::optional<bool> water, bool *force_at_least_one) |
| 2306 | { |
| 2307 | const IndustrySpec *ind_spc = GetIndustrySpec(it); |
| 2308 | if (water.has_value() && ind_spc->behaviour.Test(IndustryBehaviour::BuiltOnWater) != *water) return 0; |
| 2309 | |
| 2310 | uint32_t chance = ind_spc->appear_creation[to_underlying(_settings_game.game_creation.landscape)]; |
| 2311 | if (!ind_spc->enabled || ind_spc->layouts.empty() || |
| 2312 | (_game_mode != GM_EDITOR && _settings_game.difficulty.industry_density == ID_FUND_ONLY) || |
| 2313 | (chance = GetIndustryProbabilityCallback(it, IACT_MAPGENERATION, chance)) == 0) { |
| 2314 | *force_at_least_one = false; |
| 2315 | return 0; |
| 2316 | } else { |
| 2317 | chance *= 16; // to increase precision |
| 2318 | /* We want industries appearing at coast to appear less often on bigger maps, as length of coast increases slower than map area. |
| 2319 | * For simplicity we scale in both cases, though scaling the probabilities of all industries has no effect. */ |
| 2320 | chance = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? Map::ScaleBySize1D(chance) : Map::ScaleBySize(chance); |
| 2321 | |
| 2322 | *force_at_least_one = (chance > 0) && !ind_spc->behaviour.Test(IndustryBehaviour::NoBuildMapCreation) && (_game_mode != GM_EDITOR); |
| 2323 | return chance; |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | /** |
| 2328 | * Compute the probability for constructing a new industry during game play. |
no test coverage detected