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

Function DoTriggerHouseRandomisation

src/newgrf_house.cpp:662–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

660}
661
662static void DoTriggerHouseRandomisation(TileIndex tile, HouseRandomTrigger trigger, uint8_t base_random, bool first)
663{
664 /* We can't trigger a non-existent building... */
665 assert(IsTileType(tile, MP_HOUSE));
666
667 HouseID hid = GetHouseType(tile);
668 HouseSpec *hs = HouseSpec::Get(hid);
669
670 if (!hs->grf_prop.HasSpriteGroups()) return;
671
672 HouseResolverObject object(hid, tile, Town::GetByTile(tile), CBID_RANDOM_TRIGGER);
673 auto waiting_random_triggers = GetHouseRandomTriggers(tile);
674 waiting_random_triggers.Set(trigger);
675 SetHouseRandomTriggers(tile, waiting_random_triggers); // store now for var 5F
676 object.SetWaitingRandomTriggers(waiting_random_triggers);
677
678 object.ResolveRerandomisation();
679
680 /* Store remaining triggers. */
681 waiting_random_triggers.Reset(object.GetUsedRandomTriggers());
682 SetHouseRandomTriggers(tile, waiting_random_triggers);
683
684 /* Rerandomise bits. Scopes other than SELF are invalid for houses. For bug-to-bug-compatibility with TTDP we ignore the scope. */
685 uint8_t new_random_bits = Random();
686 uint8_t random_bits = GetHouseRandomBits(tile);
687 uint32_t reseed = object.GetReseedSum();
688 random_bits &= ~reseed;
689 random_bits |= (first ? new_random_bits : base_random) & reseed;
690 SetHouseRandomBits(tile, random_bits);
691
692 switch (trigger) {
693 case HouseRandomTrigger::TileLoop:
694 /* Random value already set. */
695 break;
696
697 case HouseRandomTrigger::TileLoopNorth:
698 if (!first) {
699 /* The top tile is marked dirty by the usual TileLoop */
700 MarkTileDirtyByTile(tile);
701 break;
702 }
703 /* Random value of first tile already set. */
704 if (hs->building_flags.Any(BUILDING_2_TILES_Y)) DoTriggerHouseRandomisation(TileAddXY(tile, 0, 1), trigger, random_bits, false);
705 if (hs->building_flags.Any(BUILDING_2_TILES_X)) DoTriggerHouseRandomisation(TileAddXY(tile, 1, 0), trigger, random_bits, false);
706 if (hs->building_flags.Any(BUILDING_HAS_4_TILES)) DoTriggerHouseRandomisation(TileAddXY(tile, 1, 1), trigger, random_bits, false);
707 break;
708 }
709}
710
711void TriggerHouseRandomisation(TileIndex t, HouseRandomTrigger trigger)
712{

Callers 1

Calls 15

IsTileTypeFunction · 0.85
GetHouseTypeFunction · 0.85
GetHouseRandomTriggersFunction · 0.85
SetHouseRandomTriggersFunction · 0.85
GetHouseRandomBitsFunction · 0.85
SetHouseRandomBitsFunction · 0.85
TileAddXYFunction · 0.85
HasSpriteGroupsMethod · 0.80
GetUsedRandomTriggersMethod · 0.80
GetReseedSumMethod · 0.80

Tested by

no test coverage detected