MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / constructBuilding

Function constructBuilding

src/OpenLoco/src/World/Town.cpp:1405–1450  ·  view source on GitHub ↗

0x00498320

Source from the content-addressed store, hash-verified

1403
1404 // 0x00498320
1405 static void constructBuilding(Town& town, const World::Pos3 pos, const Vehicles::TrackAndDirection::_RoadAndDirection tad, const TownGrowFlags growFlags)
1406 {
1407 auto* surface = TileManager::get(pos).surface();
1408 if (pos.z < surface->baseHeight())
1409 {
1410 return;
1411 }
1412
1413 const auto nextToData = TrackData::getRoadUnkNextTo(tad._data);
1414
1415 const auto randItem = (nextToData.size() * (town.prng.randNext() & 0xFFU)) / 256;
1416 const auto& nextTo = nextToData[randItem];
1417 auto buildingPos = pos + World::Pos3(Math::Vector::rotate(nextTo.pos, tad.cardinalDirection()), nextTo.pos.z);
1418 const auto buildingRot = (nextTo.rotation + tad.cardinalDirection()) & 0x3;
1419 // TODO: Urgh dirty, use a normal randBool
1420 bool isLarge = false;
1421 if (town.prng.srand_0() & (1U << 31))
1422 {
1423 isLarge = true;
1424 buildingPos.x += k4FF704[buildingRot].x;
1425 buildingPos.y += k4FF704[buildingRot].y;
1426 }
1427
1428 bool allowBuildingUpdate = false;
1429 // TODO: Even more dirty
1430 if ((growFlags & TownGrowFlags::alwaysUpdateBuildings) != TownGrowFlags::none || (isLarge && !(town.prng.srand_0() & 0x7C000000)))
1431 {
1432 allowBuildingUpdate = true;
1433 }
1434
1435 const auto maxHeight = getMaxHeightOfNewBuilding(buildingPos, isLarge, allowBuildingUpdate);
1436 if (maxHeight == 0)
1437 {
1438 return;
1439 }
1440
1441 auto args = generateNewBuildingArgs(town.id(), buildingPos, maxHeight, buildingRot, isLarge, false);
1442 if (args.has_value())
1443 {
1444 if ((growFlags & TownGrowFlags::buildImmediately) != TownGrowFlags::none)
1445 {
1446 args->buildImmediately = true;
1447 }
1448 GameCommands::doCommand(args.value(), GameCommands::Flags::apply);
1449 }
1450 }
1451
1452 template<size_t searchSize>
1453 constexpr auto kSquareSearchRange = []() {

Callers 1

growMethod · 0.85

Calls 14

getRoadUnkNextToFunction · 0.85
generateNewBuildingArgsFunction · 0.85
surfaceMethod · 0.80
baseHeightMethod · 0.80
srand_0Method · 0.80
valueMethod · 0.80
getFunction · 0.70
rotateFunction · 0.50
doCommandFunction · 0.50
sizeMethod · 0.45
randNextMethod · 0.45

Tested by

no test coverage detected