summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2005-07-31 22:53:57 +0000
committercelestar <celestar@openttd.org>2005-07-31 22:53:57 +0000
commitfcf5ace08fa0cdbb3c5a7d8f9457dcdb61741481 (patch)
treec9a9a1e3f27f68a40f4993b7913fab6b2142b6f2
parent132ce0a598eecf344c1489063fada0a824be89ad (diff)
downloadopenttd-fcf5ace08fa0cdbb3c5a7d8f9457dcdb61741481.tar.xz
(svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
-rw-r--r--openttd.h6
-rw-r--r--rail.h10
-rw-r--r--rail_cmd.c56
-rw-r--r--railtypes.h3
-rw-r--r--station_cmd.c29
-rw-r--r--tunnelbridge_cmd.c8
-rw-r--r--waypoint.c7
-rw-r--r--waypoint.h2
8 files changed, 63 insertions, 58 deletions
diff --git a/openttd.h b/openttd.h
index 485b8e8c3..5b84d0017 100644
--- a/openttd.h
+++ b/openttd.h
@@ -465,12 +465,6 @@ enum {
EXPENSES_OTHER = 12,
};
-// Tile type misc constants, don't know where to put these
-enum {
- TRACKTYPE_SPRITE_PITCH = 0x52,
-};
-
-
// special string constants
enum SpecialStrings {
diff --git a/rail.h b/rail.h
index 631d35e4b..753e7d001 100644
--- a/rail.h
+++ b/rail.h
@@ -159,6 +159,16 @@ typedef struct RailtypeInfo {
/** 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];
diff --git a/rail_cmd.c b/rail_cmd.c
index 05367a8b2..8de198392 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -1347,14 +1347,14 @@ DetailedTrackProc * const _detailed_track_proc[16] = {
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 DrawSpecialBuilding(uint32 image, uint32 tracktype_offs,
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 @@ static void DrawTile_Track(TileInfo *ti)
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 @@ static void DrawTile_Track(TileInfo *ti)
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 @@ static void DrawTile_Track(TileInfo *ti)
// 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 @@ static void DrawTile_Track(TileInfo *ti)
* 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 @@ static void DrawTile_Track(TileInfo *ti)
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 @@ static void DrawTile_Track(TileInfo *ti)
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 @@ void DrawTrainDepotSprite(int x, int y, int image, int railtype)
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);
}
}
diff --git a/railtypes.h b/railtypes.h
index d89832bc5..d86d1a450 100644
--- a/railtypes.h
+++ b/railtypes.h
@@ -21,6 +21,7 @@ const RailtypeInfo _railtypes[RAILTYPE_END] = {
},
SPR_RAIL_SNOW_OFFSET,
(1 << RAILTYPE_RAIL),
+ 0,
},
{
{
@@ -36,6 +37,7 @@ const RailtypeInfo _railtypes[RAILTYPE_END] = {
},
SPR_MONO_SNOW_OFFSET,
(1 << RAILTYPE_MONO),
+ 82,
},
{
{
@@ -51,6 +53,7 @@ const RailtypeInfo _railtypes[RAILTYPE_END] = {
},
SPR_MGLV_SNOW_OFFSET,
(1 << RAILTYPE_MAGLEV),
+ 164,
},
};
diff --git a/station_cmd.c b/station_cmd.c
index 7e88c284b..d35626b1a 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -2137,7 +2137,8 @@ static void DrawTile_Station(TileInfo *ti)
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 @@ static void DrawTile_Station(TileInfo *ti)
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 @@ void StationPickerDrawSprite(int x, int y, int railtype, int image)
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 @@ void StationPickerDrawSprite(int x, int y, int railtype, int image)
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);
}
}
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 317a91132..5fc6b2d7c 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -1022,7 +1022,6 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
/* railway type */
image = GB(_m[ti->tile].m3, 0, 4) * 8;
- /* ice? */
if (ice)
image += 32;
@@ -1085,7 +1084,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
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 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
}
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);
diff --git a/waypoint.c b/waypoint.c
index 1e27cc26e..8fd330e43 100644
--- a/waypoint.c
+++ b/waypoint.c
@@ -360,12 +360,13 @@ Station *ComposeWaypointStation(TileIndex tile)
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 @@ void DrawWaypointSprite(int x, int y, int stat_id, int railtype)
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 @@ void DrawWaypointSprite(int x, int y, int stat_id, int railtype)
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);
diff --git a/waypoint.h b/waypoint.h
index a7f7cc6ad..57b280b7e 100644
--- a/waypoint.h
+++ b/waypoint.h
@@ -59,7 +59,7 @@ int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove);
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);