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

Function DrawTile_Trees

src/tree_cmd.cpp:634–703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

632};
633
634static void DrawTile_Trees(TileInfo *ti)
635{
636 switch (GetTreeGround(ti->tile)) {
637 case TREE_GROUND_SHORE: DrawShoreTile(ti->tileh); break;
638 case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break;
639 case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break;
640 default: DrawGroundSprite(_clear_land_sprites_snow_desert[GetTreeDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break;
641 }
642
643 /* Do not draw trees when the invisible trees setting is set */
644 if (IsInvisibilitySet(TO_TREES)) return;
645
646 uint tmp = CountBits(ti->tile.base() + ti->x + ti->y);
647 uint index = GB(tmp, 0, 2) + (GetTreeType(ti->tile) << 2);
648
649 /* different tree styles above one of the grounds */
650 if ((GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT || GetTreeGround(ti->tile) == TREE_GROUND_ROUGH_SNOW) &&
651 GetTreeDensity(ti->tile) >= 2 &&
652 IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) {
653 index += 164 - (TREE_SUB_ARCTIC << 2);
654 }
655
656 assert(index < lengthof(_tree_layout_sprite));
657
658 const PalSpriteID *s = _tree_layout_sprite[index];
659 const TreePos *d = _tree_layout_xy[GB(tmp, 2, 2)];
660
661 /* combine trees into one sprite object */
662 StartSpriteCombine();
663
664 TreeListEnt te[4];
665
666 /* put the trees to draw in a list */
667 uint trees = GetTreeCount(ti->tile);
668
669 for (uint i = 0; i < trees; i++) {
670 SpriteID sprite = s[0].sprite + (i == trees - 1 ? to_underlying(GetTreeGrowth(ti->tile)) : 3);
671 PaletteID pal = s[0].pal;
672
673 te[i].sprite = sprite;
674 te[i].pal = pal;
675 te[i].x = d->x;
676 te[i].y = d->y;
677 s++;
678 d++;
679 }
680
681 /* draw them in a sorted way */
682 int z = ti->z + GetSlopeMaxPixelZ(ti->tileh) / 2;
683
684 for (; trees > 0; trees--) {
685 uint min = te[0].x + te[0].y;
686 uint mi = 0;
687
688 for (uint i = 1; i < trees; i++) {
689 if ((uint)(te[i].x + te[i].y) < min) {
690 min = te[i].x + te[i].y;
691 mi = i;

Callers

nothing calls this directly

Calls 15

GetTreeGroundFunction · 0.85
DrawShoreTileFunction · 0.85
DrawClearLandTileFunction · 0.85
GetTreeDensityFunction · 0.85
DrawHillyLandTileFunction · 0.85
DrawGroundSpriteFunction · 0.85
SlopeToSpriteOffsetFunction · 0.85
IsInvisibilitySetFunction · 0.85
CountBitsFunction · 0.85
GBFunction · 0.85
GetTreeTypeFunction · 0.85
IsInsideMMFunction · 0.85

Tested by

no test coverage detected