Mercurial > hg > openttd
changeset 15528:8e6b5d370794 draft
(svn r20187) -Codechange: move _tileh_to_sprite into a function in a more logical place and with a more descriptive name
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 19 Jul 2010 17:00:54 +0000 |
parents | 87b3b2d2fdf1 |
children | 152dcc71db0d |
files | src/clear_cmd.cpp src/landscape.cpp src/rail_cmd.cpp src/slope_func.h src/tree_cmd.cpp src/tunnelbridge_cmd.cpp src/variables.h src/viewport.cpp |
diffstat | 8 files changed, 25 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/clear_cmd.cpp +++ b/src/clear_cmd.cpp @@ -50,13 +50,13 @@ void DrawClearLandTile(const TileInfo *ti, byte set) { - DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19, PAL_NONE); + DrawGroundSprite(SPR_FLAT_BARE_LAND + SlopeToSpriteOffset(ti->tileh) + set * 19, PAL_NONE); } void DrawHillyLandTile(const TileInfo *ti) { if (ti->tileh != SLOPE_FLAT) { - DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh], PAL_NONE); + DrawGroundSprite(SPR_FLAT_ROUGH_LAND + SlopeToSpriteOffset(ti->tileh), PAL_NONE); } else { DrawGroundSprite(_landscape_clear_sprites_rough[GB(ti->x ^ ti->y, 4, 3)], PAL_NONE); } @@ -92,16 +92,16 @@ break; case CLEAR_ROCKS: - DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh], PAL_NONE); + DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; case CLEAR_FIELDS: - DrawGroundSprite(_clear_land_sprites_farmland[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); + DrawGroundSprite(_clear_land_sprites_farmland[GetFieldType(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; case CLEAR_SNOW: case CLEAR_DESERT: - DrawGroundSprite(_clear_land_sprites_snow_desert[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE); + DrawGroundSprite(_clear_land_sprites_snow_desert[GetClearDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; }
--- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -63,8 +63,8 @@ &_tile_type_unmovable_procs, ///< Callback functions for MP_UNMOVABLE tiles }; -/* landscape slope => sprite */ -const byte _tileh_to_sprite[32] = { +/** landscape slope => sprite */ +extern const byte _slope_to_sprite_offset[32] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 17, 0, 15, 18, 0, };
--- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1876,7 +1876,7 @@ default: image = SPR_FLAT_GRASS_TILE; break; } - image += _tileh_to_sprite[ti->tileh]; + image += SlopeToSpriteOffset(ti->tileh); DrawGroundSprite(image, PAL_NONE); } @@ -1966,7 +1966,7 @@ default: image = SPR_FLAT_GRASS_TILE; break; } - image += _tileh_to_sprite[fake_slope]; + image += SlopeToSpriteOffset(fake_slope); DrawGroundSprite(image, PAL_NONE, &(_halftile_sub_sprite[halftile_corner])); @@ -2038,7 +2038,7 @@ case RAIL_GROUND_ICE_DESERT: image = SPR_FLAT_SNOW_DESERT_TILE; break; default: image = SPR_FLAT_GRASS_TILE; break; } - image += _tileh_to_sprite[ti->tileh]; + image += SlopeToSpriteOffset(ti->tileh); } } else { if (ti->tileh != SLOPE_FLAT) {
--- a/src/slope_func.h +++ b/src/slope_func.h @@ -397,4 +397,16 @@ return (Foundation)(FOUNDATION_RAIL_W + corner); } +/** + * Returns the #Sprite offset for a given #Slope. + * + * @param s The #Slope to get the offset for. + * @return The sprite offset for this #Slope. + */ +static inline uint SlopeToSpriteOffset(Slope s) +{ + extern const byte _slope_to_sprite_offset[32]; + return _slope_to_sprite_offset[s]; +} + #endif /* SLOPE_FUNC_H */
--- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -457,7 +457,7 @@ 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)] + _tileh_to_sprite[ti->tileh], PAL_NONE); break; + default: DrawGroundSprite(_clear_land_sprites_snow_desert[GetTreeDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; } DrawClearLandFence(ti);
--- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1060,7 +1060,7 @@ if (!ice) { DrawClearLandTile(ti, 3); } else { - DrawGroundSprite(SPR_FLAT_SNOW_DESERT_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE); + DrawGroundSprite(SPR_FLAT_SNOW_DESERT_TILE + SlopeToSpriteOffset(ti->tileh), PAL_NONE); } /* draw ramp */