0x00498320
| 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 = []() { |
no test coverage detected