changeset 8166:8b399c358b85 draft

(svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
author peter1138 <peter1138@openttd.org>
date Mon, 31 Dec 2007 11:13:51 +0000
parents 71a7a069808b
children 9d8b747e8a5f
files src/road_gui.cpp src/station_cmd.cpp
diffstat 2 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -812,13 +812,13 @@
 
 		StationType st = (w->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK;
 
-		StationPickerDrawSprite(103, 35, st, RAILTYPE_BEGIN, ROADTYPE_ROAD, 0);
-		StationPickerDrawSprite(103, 85, st, RAILTYPE_BEGIN, ROADTYPE_ROAD, 1);
-		StationPickerDrawSprite( 35, 85, st, RAILTYPE_BEGIN, ROADTYPE_ROAD, 2);
-		StationPickerDrawSprite( 35, 35, st, RAILTYPE_BEGIN, ROADTYPE_ROAD, 3);
+		StationPickerDrawSprite(103, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 0);
+		StationPickerDrawSprite(103, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 1);
+		StationPickerDrawSprite( 35, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 2);
+		StationPickerDrawSprite( 35, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 3);
 
-		StationPickerDrawSprite(171, 35, st, RAILTYPE_BEGIN, _cur_roadtype, 4);
-		StationPickerDrawSprite(171, 85, st, RAILTYPE_BEGIN, _cur_roadtype, 5);
+		StationPickerDrawSprite(171, 35, st, INVALID_RAILTYPE, _cur_roadtype, 4);
+		StationPickerDrawSprite(171, 85, st, INVALID_RAILTYPE, _cur_roadtype, 5);
 
 		DrawStationCoverageAreaText(2, 146,
 			(w->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY,
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2075,16 +2075,20 @@
 static void DrawTile_Station(TileInfo *ti)
 {
 	const DrawTileSprites *t = NULL;
-	RailType railtype;
 	RoadTypes roadtypes;
+	int32 total_offset;
+	int32 custom_ground_offset;
+
 	if (IsRailwayStation(ti->tile)) {
-		railtype = GetRailType(ti->tile);
+		const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
 		roadtypes = ROADTYPES_NONE;
+		total_offset = rti->total_offset;
+		custom_ground_offset = rti->custom_ground_offset;
 	} else {
 		roadtypes = GetRoadTypes(ti->tile);
-		railtype = RAILTYPE_BEGIN;
+		total_offset = 0;
+		custom_ground_offset = 0;
 	}
-	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
 	uint32 relocation = 0;
 	const Station *st = NULL;
 	const StationSpec *statspec = NULL;
@@ -2131,9 +2135,9 @@
 	SpriteID image = t->ground_sprite;
 	if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
 		image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
-		image += rti->custom_ground_offset;
+		image += custom_ground_offset;
 	} else {
-		image += rti->total_offset;
+		image += total_offset;
 	}
 
 	/* station_land array has been increased from 82 elements to 114
@@ -2154,7 +2158,7 @@
 	foreach_draw_tile_seq(dtss, t->seq) {
 		image = dtss->image;
 		if (relocation == 0 || HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
-			image += rti->total_offset;
+			image += total_offset;
 		} else {
 			image += relocation;
 		}
@@ -2182,12 +2186,17 @@
 
 void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image)
 {
-	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
+	int32 total_offset = 0;
 	SpriteID pal = PLAYER_SPRITE_COLOR(_local_player);
 	const DrawTileSprites *t = &_station_display_datas[st][image];
 
+	if (railtype != INVALID_RAILTYPE) {
+		const RailtypeInfo *rti = GetRailTypeInfo(railtype);
+		total_offset = rti->total_offset;
+	}
+
 	SpriteID img = t->ground_sprite;
-	DrawSprite(img + rti->total_offset, HasBit(img, PALETTE_MODIFIER_COLOR) ? pal : PAL_NONE, x, y);
+	DrawSprite(img + total_offset, HasBit(img, PALETTE_MODIFIER_COLOR) ? pal : PAL_NONE, x, y);
 
 	if (roadtype == ROADTYPE_TRAM) {
 		DrawSprite(SPR_TRAMWAY_TRAM + (t->ground_sprite == SPR_ROAD_PAVED_STRAIGHT_X ? 1 : 0), PAL_NONE, x, y);
@@ -2196,7 +2205,7 @@
 	const DrawTileSeqStruct *dtss;
 	foreach_draw_tile_seq(dtss, t->seq) {
 		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
-		DrawSprite(dtss->image + rti->total_offset, pal, x + pt.x, y + pt.y);
+		DrawSprite(dtss->image + total_offset, pal, x + pt.x, y + pt.y);
 	}
 }