static void DrawTile_Clear(TileInfo *ti) { switch (GetClearGround(ti->tile)) { case CLEAR_GRASS: DrawClearLandTile(ti, GetClearDensity(ti->tile)); break; case CLEAR_ROUGH: DrawHillyLandTile(ti); break; case CLEAR_ROCKS: DrawGroundSprite((HasGrfMiscBit(GMB_SECOND_ROCKY_TILE_SET) && (TileHash(ti->x, ti->y) & 1) ? SPR_FLAT_ROCKY_LAND_2 : SPR_FLAT_ROCKY_LAND_1) + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; case CLEAR_FIELDS: DrawGroundSprite(_clear_land_sprites_farmland[GetFieldType(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); DrawClearLandFence(ti); break; case CLEAR_SNOW: case CLEAR_DESERT: DrawGroundSprite(_clear_land_sprites_snow_desert[GetClearDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; } DrawBridgeMiddle(ti); }
static void DrawTile_Trees(TileInfo *ti) { switch (GetTreeGround(ti->tile)) { case TREE_GROUND_SHORE: DrawShoreTile(ti->tileh); break; case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break; case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break; default: DrawGroundSprite(_clear_land_sprites_snow_desert[GetTreeDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; } DrawClearLandFence(ti); /* Do not draw trees when the invisible trees setting is set */ if (IsInvisibilitySet(TO_TREES)) return; uint tmp = CountBits(ti->tile + ti->x + ti->y); uint index = GB(tmp, 0, 2) + (GetTreeType(ti->tile) << 2); /* different tree styles above one of the grounds */ if ((GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT || GetTreeGround(ti->tile) == TREE_GROUND_ROUGH_SNOW) && GetTreeDensity(ti->tile) >= 2 && IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) { index += 164 - (TREE_SUB_ARCTIC << 2); } assert(index < lengthof(_tree_layout_sprite)); const PalSpriteID *s = _tree_layout_sprite[index]; const TreePos *d = _tree_layout_xy[GB(tmp, 2, 2)]; /* combine trees into one sprite object */ StartSpriteCombine(); TreeListEnt te[4]; /* put the trees to draw in a list */ uint trees = GetTreeCount(ti->tile); for (uint i = 0; i < trees; i++) { SpriteID sprite = s[0].sprite + (i == trees - 1 ? GetTreeGrowth(ti->tile) : 3); PaletteID pal = s[0].pal; te[i].sprite = sprite; te[i].pal = pal; te[i].x = d->x; te[i].y = d->y; s++; d++; } /* draw them in a sorted way */ byte z = ti->z + GetSlopeMaxZ(ti->tileh) / 2; for (; trees > 0; trees--) { uint min = te[0].x + te[0].y; uint mi = 0; for (uint i = 1; i < trees; i++) { if ((uint)(te[i].x + te[i].y) < min) { min = te[i].x + te[i].y; mi = i; } } AddSortableSpriteToDraw(te[mi].sprite, te[mi].pal, ti->x + te[mi].x, ti->y + te[mi].y, 16 - te[mi].x, 16 - te[mi].y, 0x30, z, IsTransparencySet(TO_TREES), -te[mi].x, -te[mi].y); /* replace the removed one with the last one */ te[mi] = te[trees - 1]; } EndSpriteCombine(); }