(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
authorcelestar
Sun, 31 Jul 2005 22:53:57 +0000
changeset 2254 72f8883ff3ac
parent 2253 a6d7fb6b0837
child 2255 ddcaf9e333ff
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
openttd.h
rail.h
rail_cmd.c
railtypes.h
station_cmd.c
tunnelbridge_cmd.c
waypoint.c
waypoint.h
--- a/openttd.h	Sun Jul 31 22:30:54 2005 +0000
+++ b/openttd.h	Sun Jul 31 22:53:57 2005 +0000
@@ -465,12 +465,6 @@
 	EXPENSES_OTHER = 12,
 };
 
-// Tile type misc constants, don't know where to put these
-enum {
-	TRACKTYPE_SPRITE_PITCH = 0x52,
-};
-
-
 // special string constants
 enum SpecialStrings {
 
--- a/rail.h	Sun Jul 31 22:30:54 2005 +0000
+++ b/rail.h	Sun Jul 31 22:53:57 2005 +0000
@@ -159,6 +159,16 @@
 
 	/** bitmask to the OTHER railtypes that can be used by an engine of THIS railtype */
 	byte compatible_railtypes;
+
+	/**
+	 * Offset between the current railtype and normal rail. This means that:<p>
+	 * 1) All the sprites in a railset MUST be in the same order. This order
+	 *    is determined by normal rail. Check sprites 1005 and following for this order<p>
+	 * 2) The position where the railtype is loaded must always be the same, otherwise
+	 *    the offset will fail.<p>
+	 * @note: Something more flexible might be desirable in the future.
+	 */
+	SpriteID total_offset;
 } RailtypeInfo;
 
 extern const RailtypeInfo _railtypes[RAILTYPE_END];
--- a/rail_cmd.c	Sun Jul 31 22:30:54 2005 +0000
+++ b/rail_cmd.c	Sun Jul 31 22:53:57 2005 +0000
@@ -1347,14 +1347,14 @@
 	DetTrackDrawProc_Null,
 };
 
-static void DrawSpecialBuilding(uint32 image, uint32 tracktype_offs,
+static void DrawSpecialBuilding(uint32 image, uint32 offset,
                                 TileInfo *ti,
                                 byte x, byte y, byte z,
                                 byte xsize, byte ysize, byte zsize)
 {
 	if (image & PALETTE_MODIFIER_COLOR)
 		image |= _drawtile_track_palette;
-	image += tracktype_offs;
+	image += offset;
 	if (_display_opt & DO_TRANS_BUILDINGS) // show transparent depots
 		MAKE_TRANSPARENT(image);
 	AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z);
@@ -1362,15 +1362,12 @@
 
 static void DrawTile_Track(TileInfo *ti)
 {
-	uint32 tracktype_offs;
 	byte m5;
 	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
 	uint32 image;	//XXX ok why the hell is SpriteID 16 bit when all the drawing routines need 32?
 
 	_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
 
-	tracktype_offs = (_m[ti->tile].m3 & 0xF) * TRACKTYPE_SPRITE_PITCH;
-
 	m5 = (byte)ti->map5;
 	if (!(m5 & RAIL_TYPE_SPECIAL)) {
 		bool special;
@@ -1407,9 +1404,9 @@
 			if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + rti->base_sprites.track_y;
 		}
 
-		if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_BROWN) {
+		if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_BROWN) {
 			image = (image & SPRITE_MASK) | PALETTE_TO_BARE_LAND; // use a brown palette
-		 } else if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT) {
+		 } else if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT) {
 			image += rti->snow_offset;
 		}
 
@@ -1491,7 +1488,7 @@
 
 		if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
 
-		if (IsRailWaypoint(m5) && _m[ti->tile].m3 & 16) {
+		if (IsRailWaypoint(m5) && HASBIT(_m[ti->tile].m3, 4)) {
 			// look for customization
 			StationSpec *stat = GetCustomStation(STAT_CLASS_WAYP, _m[ti->tile].m4);
 
@@ -1500,7 +1497,6 @@
 				// emulate station tile - open with building
 				DrawTileSprites *cust = &stat->renderdata[2 + (m5 & 0x1)];
 				uint32 relocation = GetCustomStationRelocation(stat, ComposeWaypointStation(ti->tile), 0);
-				int railtype=(_m[ti->tile].m3 & 0xF);
 
 				/* We don't touch the 0x8000 bit. In all this
 				 * waypoint code, it is used to indicate that
@@ -1512,7 +1508,7 @@
 				 * up to the GRF file to decide that. */
 
 				image = cust->ground_sprite;
-				image += railtype*((image<_custom_sprites_base)?TRACKTYPE_SPRITE_PITCH:1);
+				image += (image < _custom_sprites_base) ? rti->total_offset : GetRailType(ti->tile);
 
 				DrawGroundSprite(image);
 
@@ -1529,32 +1525,34 @@
 		drss = _track_depot_layout_table[type];
 
 		image = drss++->image;
-		if (image & PALETTE_MODIFIER_COLOR) image = (image & SPRITE_MASK) + tracktype_offs;
+		/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
+	 	 * whether the sprite is railtype dependent. Rewrite this asap */
+		if (image & PALETTE_MODIFIER_COLOR) image = (image & SPRITE_MASK) + rti->total_offset;
 
 		// adjust ground tile for desert
 		// (don't adjust for arctic depots, because snow in depots looks weird)
-		if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type>=4))
-		{
-			if(image!=3981)
-				image += 26; // tile with tracks
+		// type >= 4 means waypoints
+		if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type >= 4)) {
+			if (image != SPR_FLAT_GRASS_TILE)
+				image += rti->snow_offset; // tile with tracks
 			else
-				image = 4550; // flat ground
+				image = SPR_FLAT_SNOWY_TILE; // flat ground
 		}
 
 		DrawGroundSprite(image);
 
 		if (_debug_pbs_level >= 1) {
 			byte pbs = PBSTileReserved(ti->tile);
-			if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite((0x3ED + tracktype_offs) | PALETTE_CRASH);
-			if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite((0x3EE + tracktype_offs) | PALETTE_CRASH);
-			if (pbs & TRACK_BIT_UPPER) DrawGroundSprite((0x3EF + tracktype_offs) | PALETTE_CRASH);
-			if (pbs & TRACK_BIT_LOWER) DrawGroundSprite((0x3F0 + tracktype_offs) | PALETTE_CRASH);
-			if (pbs & TRACK_BIT_LEFT)  DrawGroundSprite((0x3F2 + tracktype_offs) | PALETTE_CRASH);
-			if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite((0x3F1 + tracktype_offs) | PALETTE_CRASH);
+			if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite(rti->base_sprites.single_y | PALETTE_CRASH);
+			if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite(rti->base_sprites.single_x | PALETTE_CRASH);
+			if (pbs & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n | PALETTE_CRASH);
+			if (pbs & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s | PALETTE_CRASH);
+			if (pbs & TRACK_BIT_LEFT)  DrawGroundSprite(rti->base_sprites.single_w | PALETTE_CRASH);
+			if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e | PALETTE_CRASH);
 		}
 
-		while ((image=drss->image) != 0) {
-			DrawSpecialBuilding(image, type < 4 ? tracktype_offs : 0, ti,
+		while ((image = drss->image) != 0) {
+			DrawSpecialBuilding(image, type < 4 ? rti->total_offset : 0, ti,
 			                    drss->subcoord_x, drss->subcoord_y, 0,
 			                    drss->width, drss->height, 0x17);
 			drss++;
@@ -1565,11 +1563,9 @@
 void DrawTrainDepotSprite(int x, int y, int image, int railtype)
 {
 	uint32 ormod, img;
+	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
 	const DrawTrackSeqStruct *dtss;
 
-	/* baseimage */
-	railtype *= TRACKTYPE_SPRITE_PITCH;
-
 	ormod = PLAYER_SPRITE_COLOR(_local_player);
 
 	dtss = _track_depot_layout_table[image];
@@ -1578,14 +1574,16 @@
 	y+=17;
 
 	img = dtss++->image;
-	if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + railtype;
+	/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
+	 * whether the sprite is railtype dependent. Rewrite this asap */
+	if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset;
 	DrawSprite(img, x, y);
 
 	for (; dtss->image != 0; dtss++) {
 		Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
 		image = dtss->image;
 		if (image & PALETTE_MODIFIER_COLOR) image |= ormod;
-		DrawSprite(image + railtype, x + pt.x, y + pt.y);
+		DrawSprite(image + rti->total_offset, x + pt.x, y + pt.y);
 	}
 }
 
--- a/railtypes.h	Sun Jul 31 22:30:54 2005 +0000
+++ b/railtypes.h	Sun Jul 31 22:53:57 2005 +0000
@@ -21,6 +21,7 @@
 		},
 		SPR_RAIL_SNOW_OFFSET,
 		(1 << RAILTYPE_RAIL),
+		0,
 	},
 	{
 		{
@@ -36,6 +37,7 @@
 		},
 		SPR_MONO_SNOW_OFFSET,
 		(1 << RAILTYPE_MONO),
+		82,
 	},
 	{
 		{
@@ -51,6 +53,7 @@
 		},
 		SPR_MGLV_SNOW_OFFSET,
 		(1 << RAILTYPE_MAGLEV),
+		164,
 	},
 };
 
--- a/station_cmd.c	Sun Jul 31 22:30:54 2005 +0000
+++ b/station_cmd.c	Sun Jul 31 22:53:57 2005 +0000
@@ -2137,7 +2137,8 @@
 	const DrawTileSeqStruct *dtss;
 	const DrawTileSprites *t = NULL;
 	byte railtype = _m[ti->tile].m3 & 0xF;
-	int type_offset;
+	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
+	SpriteID offset;
 	uint32 relocation = 0;
 
 	{
@@ -2173,26 +2174,26 @@
 		image |= image_or_modificator;
 
 	// For custom sprites, there's no railtype-based pitching.
-	type_offset = railtype * ((image & SPRITE_MASK) < _custom_sprites_base ? TRACKTYPE_SPRITE_PITCH : 1);
+	offset = (image & SPRITE_MASK) < _custom_sprites_base ? rti->total_offset : railtype;
+	image += offset;
 
 	// station_land array has been increased from 82 elements to 114
 	// but this is something else. If AI builds station with 114 it looks all weird
-	image += type_offset;
 	DrawGroundSprite(image);
 
 	if (_debug_pbs_level >= 1) {
 		byte pbs = PBSTileReserved(ti->tile);
-		if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite((0x3ED + type_offset) | PALETTE_CRASH);
-		if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite((0x3EE + type_offset) | PALETTE_CRASH);
-		if (pbs & TRACK_BIT_UPPER) DrawGroundSprite((0x3EF + type_offset) | PALETTE_CRASH);
-		if (pbs & TRACK_BIT_LOWER) DrawGroundSprite((0x3F0 + type_offset) | PALETTE_CRASH);
-		if (pbs & TRACK_BIT_LEFT)  DrawGroundSprite((0x3F2 + type_offset) | PALETTE_CRASH);
-		if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite((0x3F1 + type_offset) | PALETTE_CRASH);
+		if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite(rti->base_sprites.single_y | PALETTE_CRASH);
+		if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite(rti->base_sprites.single_x | PALETTE_CRASH);
+		if (pbs & TRACK_BIT_UPPER) DrawGroundSprite(rti->base_sprites.single_n | PALETTE_CRASH);
+		if (pbs & TRACK_BIT_LOWER) DrawGroundSprite(rti->base_sprites.single_s | PALETTE_CRASH);
+		if (pbs & TRACK_BIT_LEFT)  DrawGroundSprite(rti->base_sprites.single_w | PALETTE_CRASH);
+		if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e | PALETTE_CRASH);
 	}
 
 	foreach_draw_tile_seq(dtss, t->seq) {
 		image = dtss->image + relocation;
-		image += type_offset;
+		image += offset;
 		if (_display_opt & DO_TRANS_BUILDINGS) {
 			MAKE_TRANSPARENT(image);
 		} else {
@@ -2212,9 +2213,7 @@
 	uint32 ormod, img;
 	const DrawTileSeqStruct *dtss;
 	const DrawTileSprites *t;
-
-	/* baseimage */
-	railtype *= TRACKTYPE_SPRITE_PITCH;
+	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
 
 	ormod = PLAYER_SPRITE_COLOR(_local_player);
 
@@ -2223,11 +2222,11 @@
 	img = t->ground_sprite;
 	if (img & PALETTE_MODIFIER_COLOR)
 		img |= ormod;
-	DrawSprite(img + railtype, x, y);
+	DrawSprite(img + rti->total_offset, x, y);
 
 	foreach_draw_tile_seq(dtss, t->seq) {
 		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
-		DrawSprite((dtss->image | ormod) + railtype, x + pt.x, y + pt.y);
+		DrawSprite((dtss->image | ormod) + rti->total_offset, x + pt.x, y + pt.y);
 	}
 }
 
--- a/tunnelbridge_cmd.c	Sun Jul 31 22:30:54 2005 +0000
+++ b/tunnelbridge_cmd.c	Sun Jul 31 22:53:57 2005 +0000
@@ -1022,7 +1022,6 @@
 		/* railway type */
 		image = GB(_m[ti->tile].m3, 0, 4) * 8;
 
-		/* ice? */
 		if (ice)
 			image += 32;
 
@@ -1085,7 +1084,7 @@
 
 			if (!(ti->map5 & 0x20)) {
 				// draw land under bridge
-				if (ice) image += 2;					// ice too?
+				if (ice) image += 2;
 
 				if (image != 1 || ti->tileh == 0)
 					DrawGroundSprite(_bridge_land_below[image] + _tileh_to_sprite[ti->tileh]);
@@ -1104,11 +1103,12 @@
 				}
 
 				if (!(image&1)) {
+					const RailtypeInfo *rti = GetRailTypeInfo(_m[ti->tile].m3 & 0xF);
 					// railway
 					image = 0x3F3 + (ti->map5 & 1);
 					if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3;
-					image += (_m[ti->tile].m3 & 0xF) * TRACKTYPE_SPRITE_PITCH;
-					if (ice) image += 26; // ice?
+					image += rti->total_offset;
+					if (ice) image += rti->snow_offset;
 				} else {
 					// road
 					image = 1332 + (ti->map5 & 1);
--- a/waypoint.c	Sun Jul 31 22:30:54 2005 +0000
+++ b/waypoint.c	Sun Jul 31 22:53:57 2005 +0000
@@ -360,12 +360,13 @@
 extern uint16 _custom_sprites_base;
 
 /* Draw a waypoint */
-void DrawWaypointSprite(int x, int y, int stat_id, int railtype)
+void DrawWaypointSprite(int x, int y, int stat_id, uint railtype)
 {
 	StationSpec *stat;
 	uint32 relocation;
 	DrawTileSprites *cust;
 	DrawTileSeqStruct const *seq;
+	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
 	uint32 ormod, img;
 
 	ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player));
@@ -378,7 +379,7 @@
 		const DrawTrackSeqStruct *dtss = _track_depot_layout_table[4];
 
 		img = dtss++->image;
-		if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + railtype*TRACKTYPE_SPRITE_PITCH;
+		if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK) + rti->total_offset;
 		DrawSprite(img, x, y);
 
 		for (; dtss->image != 0; dtss++) {
@@ -398,7 +399,7 @@
 	cust = &stat->renderdata[2];
 
 	img = cust->ground_sprite;
-	img += railtype * ((img < _custom_sprites_base) ? TRACKTYPE_SPRITE_PITCH : 1);
+	img += (img < _custom_sprites_base) ? rti->total_offset : railtype;
 
 	if (img & PALETTE_MODIFIER_COLOR) img = (img & SPRITE_MASK);
 	DrawSprite(img, x, y);
--- a/waypoint.h	Sun Jul 31 22:30:54 2005 +0000
+++ b/waypoint.h	Sun Jul 31 22:53:57 2005 +0000
@@ -59,7 +59,7 @@
 Station *ComposeWaypointStation(TileIndex tile);
 Waypoint *GetWaypointByTile(TileIndex tile);
 void ShowRenameWaypointWindow(const Waypoint *cp);
-void DrawWaypointSprite(int x, int y, int image, int railtype);
+void DrawWaypointSprite(int x, int y, int image, uint railtype);
 void UpdateWaypointSign(Waypoint *cp);
 void FixOldWaypoints(void);
 void UpdateAllWaypointSigns(void);