summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2005-09-29 19:59:57 +0000
committerpeter1138 <peter1138@openttd.org>2005-09-29 19:59:57 +0000
commite33faa5ed5d015bfdc56bc3a98ac866dbf887daf (patch)
tree3361291e4860244e86ac05a4850f57669b721cc4
parent3a964862f7b14c214a38689ad646924c96a34f95 (diff)
downloadopenttd-e33faa5ed5d015bfdc56bc3a98ac866dbf887daf.tar.xz
(svn r2997) -Codechange: Split road drawing code off from DrawTile_Road into a separate function to be used elsewhere.
-rw-r--r--functions.h1
-rw-r--r--road_cmd.c103
2 files changed, 64 insertions, 40 deletions
diff --git a/functions.h b/functions.h
index 8bbd67ac1..7afcd6244 100644
--- a/functions.h
+++ b/functions.h
@@ -229,6 +229,7 @@ Town *ClosestTownFromTile(TileIndex tile, uint threshold);
void ChangeTownRating(Town *t, int add, int max);
uint GetRoadBitsByTile(TileIndex tile);
+void DrawRoadBits(TileInfo *ti, byte road, byte ground_type, bool snow, bool flat);
int GetTownRadiusGroup(const Town *t, TileIndex tile);
void ShowNetworkChatQueryWindow(byte desttype, byte dest);
void ShowNetworkGiveMoneyWindow(byte player);
diff --git a/road_cmd.c b/road_cmd.c
index 64c8969ee..d5c716c84 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -770,59 +770,82 @@ const byte _road_sloped_sprites[14] = {
0, 0
};
-static void DrawTile_Road(TileInfo *ti)
+/**
+ * Draw ground sprite and road pieces
+ * @param ti TileInfo
+ * @param road RoadBits to draw
+ * @param ground_type Ground type
+ * @param snow Draw snow
+ * @param flat Draw foundation
+ */
+void DrawRoadBits(TileInfo *ti, byte road, byte ground_type, bool snow, bool flat)
{
- uint32 image;
- uint16 m2;
+ const DrawRoadTileStruct *drts;
+ PalSpriteID image = 0;
- if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0
- const DrawRoadTileStruct *drts;
+ if (ti->tileh != 0) {
+ int foundation;
+ if (flat) {
+ foundation = ti->tileh;
+ } else {
+ foundation = GetRoadFoundation(ti->tileh, road);
+ }
+
+ if (foundation != 0)
+ DrawFoundation(ti, foundation);
+ // DrawFoundation() modifies ti.
+ // Default sloped sprites..
if (ti->tileh != 0) {
- int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF);
- if (f) DrawFoundation(ti, f);
-
- // default sloped sprites..
- if (ti->tileh != 0) {
- image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
- } else {
- image = _road_tile_sprites_1[ti->map5 & 0xF];
- }
- } else {
- image = _road_tile_sprites_1[ti->map5 & 0xF];
+ image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
}
+ }
- m2 = GB(_m[ti->tile].m4, 4, 3);
+ if (image == 0)
+ image = _road_tile_sprites_1[road];
- if (m2 == 0) image |= PALETTE_TO_BARE_LAND;
+ if (ground_type == 0)
+ image |= PALETTE_TO_BARE_LAND;
- if (_m[ti->tile].m4 & 0x80) {
- image += 19;
- } else if (m2 > 1 && m2 != 6) {
- image -= 19; /* pavement along the road? */
- }
+ if (snow) {
+ image += 19;
+ } else if (ground_type > 1 && ground_type != 6) {
+ // Pavement tiles.
+ image -= 19;
+ }
- DrawGroundSprite(image);
+ DrawGroundSprite(image);
- if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2)
- return;
+ // Return if full detail is disabled, or we are zoomed fully out.
+ if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2)
+ return;
- if (m2 >= 6) {
- // roadwork
- DrawGroundSprite(0x586 + ((ti->map5&8)!=0 ? 0 : 1));
- return;
- }
+ if (ground_type >= 6) {
+ // Road works
+ DrawGroundSprite(0x586 + (HASBIT(road, 4) ? 0 : 1));
+ return;
+ }
+
+ // Draw extra details.
+ drts = _road_display_table[ground_type][road];
+ while ((image = drts->image) != 0) {
+ int x = ti->x | drts->subcoord_x;
+ int y = ti->y | drts->subcoord_y;
+ byte z = ti->z;
+ if (ti->tileh != 0)
+ z = GetSlopeZ(x, y);
+ AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z);
+ drts++;
+ }
+}
- drts = _road_display_table[m2][ti->map5 & 0xF];
+static void DrawTile_Road(TileInfo *ti)
+{
+ PalSpriteID image;
+ uint16 m2;
- while ((image = drts->image) != 0) {
- int x = ti->x | drts->subcoord_x;
- int y = ti->y | drts->subcoord_y;
- byte z = ti->z;
- if (ti->tileh != 0) z = GetSlopeZ(x, y);
- AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z);
- drts++;
- }
+ if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0
+ DrawRoadBits(ti, GB(ti->map5, 0, 4), GB(_m[ti->tile].m4, 4, 3), HASBIT(_m[ti->tile].m4, 7), false);
} else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing
int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF);
if (f) DrawFoundation(ti, f);