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

Method grow

src/OpenLoco/src/World/Town.cpp:1640–1779  ·  view source on GitHub ↗

* 0x00498116 * Grow * * @param this @ * @param growFlags @ */

Source from the content-addressed store, hash-verified

1638 * @param growFlags @<eax>
1639 */
1640 void Town::grow(TownGrowFlags growFlags)
1641 {
1642 const auto oldUpatingCompany = GameCommands::getUpdatingCompanyId();
1643 GameCommands::setUpdatingCompanyId(CompanyId::neutral);
1644
1645 const auto extent = findRoadExtent(*this);
1646 if (!extent.has_value())
1647 {
1648 if ((growFlags & TownGrowFlags::buildInitialRoad) != TownGrowFlags::none)
1649 {
1650 buildInitialRoad(*this);
1651 }
1652 GameCommands::setUpdatingCompanyId(oldUpatingCompany);
1653 return;
1654 }
1655
1656 auto roadStart = extent->roadStart;
1657 Vehicles::TrackAndDirection::_RoadAndDirection tad(0, 0);
1658 tad._data = extent->tad;
1659 if (prng.randBool())
1660 {
1661 auto& roadSize = World::TrackData::getUnkRoad(tad._data);
1662 roadStart += roadSize.pos;
1663 if (roadSize.rotationEnd < 12)
1664 {
1665 roadStart -= World::Pos3{ kRotationOffset[roadSize.rotationEnd], 0 };
1666 }
1667 tad.setReversed(!tad.isReversed());
1668 }
1669
1670 const auto idealRoadId = getIdealTownRoadId(*this);
1671 if (!idealRoadId.has_value())
1672 {
1673 GameCommands::setUpdatingCompanyId(oldUpatingCompany);
1674 return;
1675 }
1676
1677 auto curRoadPos = roadStart;
1678 bool curOnBridge = extent->isBridge;
1679
1680 for (auto i = 0U; i < 75; ++i)
1681 {
1682 auto res = TownManager::getClosestTownAndDensity(curRoadPos);
1683 if (!res.has_value() || res->first != id())
1684 {
1685 break;
1686 }
1687 const auto curRoadInfo = getRoadInformation(curRoadPos, tad);
1688 if (curRoadInfo.owner != CompanyId::neutral)
1689 {
1690 if ((growFlags & TownGrowFlags::neutralRoadTakeover) != TownGrowFlags::none)
1691 {
1692 if (curOnBridge || hasNearbyBuildings(World::toTileSpace(curRoadPos)))
1693 {
1694 updateAndTakeoverRoad(curRoadPos, tad, curRoadInfo.roadObjId, CompanyId::neutral, curRoadInfo.streetLightStyle.value_or(0U));
1695 break;
1696 }
1697 }

Callers 2

onMouseUpFunction · 0.45
createTownFunction · 0.45

Calls 15

getUpdatingCompanyIdFunction · 0.85
setUpdatingCompanyIdFunction · 0.85
findRoadExtentFunction · 0.85
buildInitialRoadFunction · 0.85
getIdealTownRoadIdFunction · 0.85
getClosestTownAndDensityFunction · 0.85
getRoadInformationFunction · 0.85
hasNearbyBuildingsFunction · 0.85
toTileSpaceFunction · 0.85
updateAndTakeoverRoadFunction · 0.85
getStreetLightStyleFunction · 0.85
constructBuildingFunction · 0.85

Tested by

no test coverage detected