static void DoTriggerHouse(TileIndex tile, HouseTrigger trigger, byte base_random, bool first) { ResolverObject object; /* We can't trigger a non-existent building... */ assert(IsTileType(tile, MP_HOUSE)); HouseID hid = GetHouseType(tile); HouseSpec *hs = HouseSpec::Get(hid); if (hs->spritegroup == NULL) return; NewHouseResolver(&object, hid, tile, Town::GetByTile(tile)); object.callback = CBID_RANDOM_TRIGGER; object.trigger = trigger; const SpriteGroup *group = SpriteGroup::Resolve(hs->spritegroup, &object); if (group == NULL) return; byte new_random_bits = Random(); byte random_bits = GetHouseRandomBits(tile); random_bits &= ~object.reseed; random_bits |= (first ? new_random_bits : base_random) & object.reseed; SetHouseRandomBits(tile, random_bits); switch (trigger) { case HOUSE_TRIGGER_TILE_LOOP: /* Random value already set. */ break; case HOUSE_TRIGGER_TILE_LOOP_TOP: if (!first) { /* The top tile is marked dirty by the usual TileLoop */ MarkTileDirtyByTile(tile); break; } /* Random value of first tile already set. */ if (hs->building_flags & BUILDING_2_TILES_Y) DoTriggerHouse(TILE_ADDXY(tile, 0, 1), trigger, random_bits, false); if (hs->building_flags & BUILDING_2_TILES_X) DoTriggerHouse(TILE_ADDXY(tile, 1, 0), trigger, random_bits, false); if (hs->building_flags & BUILDING_HAS_4_TILES) DoTriggerHouse(TILE_ADDXY(tile, 1, 1), trigger, random_bits, false); break; } }
/* virtual */ uint32 HouseScopeResolver::GetRandomBits() const { /* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */ assert(IsValidTile(this->tile) && (this->not_yet_constructed || IsTileType(this->tile, MP_HOUSE))); return this->not_yet_constructed ? this->initial_random_bits : GetHouseRandomBits(this->tile); }
static uint32 HouseGetRandomBits(const ResolverObject *object) { const TileIndex tile = object->u.house.tile; return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseRandomBits(tile); }