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

Function CreateNewIndustry

src/industry_cmd.cpp:2285–2296  ·  view source on GitHub ↗

* Create a new industry of random layout. * @param tile The location to build the industry. * @param type The industry type to build. * @param creation_type The circumstances the industry is created under. * @return the created industry or nullptr if it failed. */

Source from the content-addressed store, hash-verified

2283 * @return the created industry or nullptr if it failed.
2284 */
2285static Industry *CreateNewIndustry(TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type)
2286{
2287 const IndustrySpec *indspec = GetIndustrySpec(type);
2288
2289 uint32_t seed = Random();
2290 uint32_t seed2 = Random();
2291 Industry *i = nullptr;
2292 size_t layout_index = RandomRange((uint32_t)indspec->layouts.size());
2293 [[maybe_unused]] CommandCost ret = CreateNewIndustryHelper(tile, type, DoCommandFlag::Execute, indspec, layout_index, seed, GB(seed2, 0, 16), OWNER_NONE, creation_type, &i);
2294 assert(i != nullptr || ret.Failed());
2295 return i;
2296}
2297
2298/**
2299 * Compute the appearance probability for an industry during map creation.

Callers 1

PlaceIndustryFunction · 0.85

Calls 7

GetIndustrySpecFunction · 0.85
RandomRangeFunction · 0.85
CreateNewIndustryHelperFunction · 0.85
GBFunction · 0.85
FailedMethod · 0.80
RandomFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected