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

Function BuildTownHouse

src/town_cmd.cpp:2775–2806  ·  view source on GitHub ↗

* Build a house at this tile. * @param t The town the house will belong to. * @param tile The tile to try building on. * @param hs The @a HouseSpec of the house. * @param house The @a HouseID of the house. * @param random_bits The random data to be associated with the house. * @param house_completed Should the house be placed already complete, instead of under construction? * @param is_prot

Source from the content-addressed store, hash-verified

2773 * @param is_protected Whether the house is protected from the town upgrading it.
2774 */
2775static void BuildTownHouse(Town *t, TileIndex tile, const HouseSpec *hs, HouseID house, uint8_t random_bits, bool house_completed, bool is_protected)
2776{
2777 /* build the house */
2778 t->cache.num_houses++;
2779
2780 uint8_t construction_counter = 0;
2781 uint8_t construction_stage = 0;
2782
2783 if (_generating_world || _game_mode == GM_EDITOR || house_completed) {
2784 uint32_t construction_random = Random();
2785
2786 construction_stage = TOWN_HOUSE_COMPLETED;
2787 if (_generating_world && !hs->extra_flags.Test(HouseExtraFlag::BuildingIsHistorical) && Chance16(1, 7)) construction_stage = GB(construction_random, 0, 2);
2788
2789 if (construction_stage == TOWN_HOUSE_COMPLETED) {
2790 ChangePopulation(t, hs->population);
2791 } else {
2792 construction_counter = GB(construction_random, 2, 2);
2793 }
2794 }
2795
2796 MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits, is_protected);
2797 UpdateTownRadius(t);
2798 UpdateTownGrowthRate(t);
2799
2800 BuildingFlags size = hs->building_flags;
2801
2802 TriggerHouseAnimation_ConstructionStageChanged(tile, true);
2803 if (size.Any(BUILDING_2_TILES_Y)) TriggerHouseAnimation_ConstructionStageChanged(tile + TileDiffXY(0, 1), true);
2804 if (size.Any(BUILDING_2_TILES_X)) TriggerHouseAnimation_ConstructionStageChanged(tile + TileDiffXY(1, 0), true);
2805 if (size.Any(BUILDING_HAS_4_TILES)) TriggerHouseAnimation_ConstructionStageChanged(tile + TileDiffXY(1, 1), true);
2806}
2807
2808/**
2809 * Tries to build a house at this tile.

Callers 2

TryBuildTownHouseFunction · 0.85
CmdPlaceHouseFunction · 0.85

Calls 11

Chance16Function · 0.85
GBFunction · 0.85
ChangePopulationFunction · 0.85
MakeTownHouseFunction · 0.85
UpdateTownRadiusFunction · 0.85
UpdateTownGrowthRateFunction · 0.85
TileDiffXYFunction · 0.85
TestMethod · 0.80
AnyMethod · 0.80
RandomFunction · 0.50

Tested by

no test coverage detected