mirror of https://github.com/OpenTTD/OpenTTD
(svn r20126) -Fix [FS#3883]: Make railtype Terrain Type variable aware of RAIL_GROUND_HALF_SNOW. That is, resolve the sprites for upper and lower part of the foundation independently.
parent
19fb8ba6f8
commit
72ee11a7c6
|
@ -165,20 +165,20 @@ static TrackBits MaskWireBits(TileIndex t, TrackBits tracks)
|
||||||
/**
|
/**
|
||||||
* Get the base wire sprite to use.
|
* Get the base wire sprite to use.
|
||||||
*/
|
*/
|
||||||
static inline SpriteID GetWireBase(TileIndex tile)
|
static inline SpriteID GetWireBase(TileIndex tile, bool upper_halftile = false)
|
||||||
{
|
{
|
||||||
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
|
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
|
||||||
SpriteID wires = GetCustomRailSprite(rti, tile, RTSG_WIRES);
|
SpriteID wires = GetCustomRailSprite(rti, tile, RTSG_WIRES, upper_halftile);
|
||||||
return wires == 0 ? SPR_WIRE_BASE : wires;
|
return wires == 0 ? SPR_WIRE_BASE : wires;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the base pylon sprite to use.
|
* Get the base pylon sprite to use.
|
||||||
*/
|
*/
|
||||||
static inline SpriteID GetPylonBase(TileIndex tile)
|
static inline SpriteID GetPylonBase(TileIndex tile, bool upper_halftile = false)
|
||||||
{
|
{
|
||||||
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
|
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
|
||||||
SpriteID pylons = GetCustomRailSprite(rti, tile, RTSG_PYLONS);
|
SpriteID pylons = GetCustomRailSprite(rti, tile, RTSG_PYLONS, upper_halftile);
|
||||||
return pylons == 0 ? SPR_PYLON_BASE : pylons;
|
return pylons == 0 ? SPR_PYLON_BASE : pylons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,11 @@ static void DrawCatenaryRailway(const TileInfo *ti)
|
||||||
|
|
||||||
/* Half tile slopes coincide only with horizontal/vertical track.
|
/* Half tile slopes coincide only with horizontal/vertical track.
|
||||||
* Faking a flat slope results in the correct sprites on positions. */
|
* Faking a flat slope results in the correct sprites on positions. */
|
||||||
if (IsHalftileSlope(tileh[TS_HOME])) tileh[TS_HOME] = SLOPE_FLAT;
|
Corner halftile_corner = CORNER_INVALID;
|
||||||
|
if (IsHalftileSlope(tileh[TS_HOME])) {
|
||||||
|
halftile_corner = GetHighestSlopeCorner(tileh[TS_HOME]);
|
||||||
|
tileh[TS_HOME] = SLOPE_FLAT;
|
||||||
|
}
|
||||||
|
|
||||||
TLG tlg = GetTLG(ti->tile);
|
TLG tlg = GetTLG(ti->tile);
|
||||||
byte PCPstatus = 0;
|
byte PCPstatus = 0;
|
||||||
|
@ -295,9 +299,17 @@ static void DrawCatenaryRailway(const TileInfo *ti)
|
||||||
|
|
||||||
AdjustTileh(ti->tile, &tileh[TS_HOME]);
|
AdjustTileh(ti->tile, &tileh[TS_HOME]);
|
||||||
|
|
||||||
SpriteID pylon_base = GetPylonBase(ti->tile);
|
SpriteID pylon_normal = GetPylonBase(ti->tile);
|
||||||
|
SpriteID pylon_halftile = (halftile_corner != CORNER_INVALID) ? GetPylonBase(ti->tile, true) : pylon_normal;
|
||||||
|
|
||||||
for (DiagDirection i = DIAGDIR_BEGIN; i < DIAGDIR_END; i++) {
|
for (DiagDirection i = DIAGDIR_BEGIN; i < DIAGDIR_END; i++) {
|
||||||
|
static const uint edge_corners[] = {
|
||||||
|
1 << CORNER_N | 1 << CORNER_E, // DIAGDIR_NE
|
||||||
|
1 << CORNER_S | 1 << CORNER_E, // DIAGDIR_SE
|
||||||
|
1 << CORNER_S | 1 << CORNER_W, // DIAGDIR_SW
|
||||||
|
1 << CORNER_N | 1 << CORNER_W, // DIAGDIR_NW
|
||||||
|
};
|
||||||
|
SpriteID pylon_base = (halftile_corner != CORNER_INVALID && HasBit(edge_corners[i], halftile_corner)) ? pylon_halftile : pylon_normal;
|
||||||
TileIndex neighbour = ti->tile + TileOffsByDiagDir(i);
|
TileIndex neighbour = ti->tile + TileOffsByDiagDir(i);
|
||||||
Foundation foundation = FOUNDATION_NONE;
|
Foundation foundation = FOUNDATION_NONE;
|
||||||
byte elevation = GetPCPElevation(ti->tile, i);
|
byte elevation = GetPCPElevation(ti->tile, i);
|
||||||
|
@ -426,11 +438,21 @@ static void DrawCatenaryRailway(const TileInfo *ti)
|
||||||
if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
|
if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteID wire_base = GetWireBase(ti->tile);
|
SpriteID wire_normal = GetWireBase(ti->tile);
|
||||||
|
SpriteID wire_halftile = (halftile_corner != CORNER_INVALID) ? GetWireBase(ti->tile, true) : wire_normal;
|
||||||
|
Track halftile_track;
|
||||||
|
switch (halftile_corner) {
|
||||||
|
case CORNER_W: halftile_track = TRACK_LEFT; break;
|
||||||
|
case CORNER_S: halftile_track = TRACK_LOWER; break;
|
||||||
|
case CORNER_E: halftile_track = TRACK_RIGHT; break;
|
||||||
|
case CORNER_N: halftile_track = TRACK_UPPER; break;
|
||||||
|
default: halftile_track = INVALID_TRACK; break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Drawing of pylons is finished, now draw the wires */
|
/* Drawing of pylons is finished, now draw the wires */
|
||||||
Track t;
|
Track t;
|
||||||
FOR_EACH_SET_TRACK(t, wireconfig[TS_HOME]) {
|
FOR_EACH_SET_TRACK(t, wireconfig[TS_HOME]) {
|
||||||
|
SpriteID wire_base = (t == halftile_track) ? wire_halftile : wire_normal;
|
||||||
byte PCPconfig = HasBit(PCPstatus, PCPpositions[t][0]) +
|
byte PCPconfig = HasBit(PCPstatus, PCPpositions[t][0]) +
|
||||||
(HasBit(PCPstatus, PCPpositions[t][1]) << 1);
|
(HasBit(PCPstatus, PCPpositions[t][1]) << 1);
|
||||||
|
|
||||||
|
|
|
@ -280,9 +280,10 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
|
||||||
/** Function used by houses (and soon industries) to get information
|
/** Function used by houses (and soon industries) to get information
|
||||||
* on type of "terrain" the tile it is queries sits on.
|
* on type of "terrain" the tile it is queries sits on.
|
||||||
* @param tile TileIndex of the tile been queried
|
* @param tile TileIndex of the tile been queried
|
||||||
|
* @param upper_halftile If true, query upper halftile in case of rail tiles.
|
||||||
* @return value corresponding to the grf expected format:
|
* @return value corresponding to the grf expected format:
|
||||||
* Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline */
|
* Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline */
|
||||||
uint32 GetTerrainType(TileIndex tile)
|
uint32 GetTerrainType(TileIndex tile, bool upper_halftile)
|
||||||
{
|
{
|
||||||
switch (_settings_game.game_creation.landscape) {
|
switch (_settings_game.game_creation.landscape) {
|
||||||
case LT_TROPIC: return GetTropicZone(tile);
|
case LT_TROPIC: return GetTropicZone(tile);
|
||||||
|
@ -295,7 +296,7 @@ uint32 GetTerrainType(TileIndex tile)
|
||||||
|
|
||||||
case MP_RAILWAY: {
|
case MP_RAILWAY: {
|
||||||
RailGroundType ground = GetRailGroundType(tile);
|
RailGroundType ground = GetRailGroundType(tile);
|
||||||
has_snow = (ground == RAIL_GROUND_ICE_DESERT);
|
has_snow = (ground == RAIL_GROUND_ICE_DESERT || (upper_halftile && ground == RAIL_GROUND_HALF_SNOW));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ extern IndustryTileOverrideManager _industile_mngr;
|
||||||
extern AirportOverrideManager _airport_mngr;
|
extern AirportOverrideManager _airport_mngr;
|
||||||
extern AirportTileOverrideManager _airporttile_mngr;
|
extern AirportTileOverrideManager _airporttile_mngr;
|
||||||
|
|
||||||
uint32 GetTerrainType(TileIndex tile);
|
uint32 GetTerrainType(TileIndex tile, bool upper_halftile = false);
|
||||||
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
|
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
|
||||||
uint32 GetNearbyTileInformation(TileIndex tile);
|
uint32 GetNearbyTileInformation(TileIndex tile);
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ static uint32 RailTypeGetVariable(const ResolverObject *object, byte variable, b
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (variable) {
|
switch (variable) {
|
||||||
case 0x40: return GetTerrainType(tile);
|
case 0x40: return GetTerrainType(tile, object->u.routes.upper_halftile);
|
||||||
case 0x41: return 0;
|
case 0x41: return 0;
|
||||||
case 0x42: return IsLevelCrossingTile(tile) && IsCrossingBarred(tile);
|
case 0x42: return IsLevelCrossingTile(tile) && IsCrossingBarred(tile);
|
||||||
case 0x43:
|
case 0x43:
|
||||||
|
@ -70,7 +70,7 @@ static const SpriteGroup *RailTypeResolveReal(const ResolverObject *object, cons
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile)
|
static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile, bool upper_halftile)
|
||||||
{
|
{
|
||||||
res->GetRandomBits = &RailTypeGetRandomBits;
|
res->GetRandomBits = &RailTypeGetRandomBits;
|
||||||
res->GetTriggers = &RailTypeGetTriggers;
|
res->GetTriggers = &RailTypeGetTriggers;
|
||||||
|
@ -79,6 +79,7 @@ static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile)
|
||||||
res->ResolveReal = &RailTypeResolveReal;
|
res->ResolveReal = &RailTypeResolveReal;
|
||||||
|
|
||||||
res->u.routes.tile = tile;
|
res->u.routes.tile = tile;
|
||||||
|
res->u.routes.upper_halftile = upper_halftile;
|
||||||
|
|
||||||
res->callback = CBID_NO_CALLBACK;
|
res->callback = CBID_NO_CALLBACK;
|
||||||
res->callback_param1 = 0;
|
res->callback_param1 = 0;
|
||||||
|
@ -89,7 +90,7 @@ static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile)
|
||||||
res->count = 0;
|
res->count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg)
|
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, bool upper_halftile)
|
||||||
{
|
{
|
||||||
assert(rtsg < RTSG_END);
|
assert(rtsg < RTSG_END);
|
||||||
|
|
||||||
|
@ -98,7 +99,7 @@ SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSp
|
||||||
const SpriteGroup *group;
|
const SpriteGroup *group;
|
||||||
ResolverObject object;
|
ResolverObject object;
|
||||||
|
|
||||||
NewRailTypeResolver(&object, tile);
|
NewRailTypeResolver(&object, tile, upper_halftile);
|
||||||
|
|
||||||
group = SpriteGroup::Resolve(rti->group[rtsg], &object);
|
group = SpriteGroup::Resolve(rti->group[rtsg], &object);
|
||||||
if (group == NULL || group->GetNumResults() == 0) return 0;
|
if (group == NULL || group->GetNumResults() == 0) return 0;
|
||||||
|
@ -128,5 +129,5 @@ uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
|
||||||
*/
|
*/
|
||||||
void GetRailTypeResolver(ResolverObject *ro, uint index)
|
void GetRailTypeResolver(ResolverObject *ro, uint index)
|
||||||
{
|
{
|
||||||
NewRailTypeResolver(ro, index);
|
NewRailTypeResolver(ro, index, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include "rail.h"
|
#include "rail.h"
|
||||||
|
|
||||||
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg);
|
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, bool upper_halftile = false);
|
||||||
|
|
||||||
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile);
|
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile);
|
||||||
|
|
||||||
|
|
|
@ -343,6 +343,7 @@ struct ResolverObject {
|
||||||
} generic;
|
} generic;
|
||||||
struct {
|
struct {
|
||||||
TileIndex tile;
|
TileIndex tile;
|
||||||
|
bool upper_halftile; ///< Are we resolving sprites for the upper halftile?
|
||||||
} routes;
|
} routes;
|
||||||
struct {
|
struct {
|
||||||
const struct Station *st;
|
const struct Station *st;
|
||||||
|
|
|
@ -1791,8 +1791,9 @@ static void DrawTrackFence_WE_2(const TileInfo *ti, SpriteID base_image)
|
||||||
|
|
||||||
static void DrawTrackDetails(const TileInfo *ti, const RailtypeInfo *rti)
|
static void DrawTrackDetails(const TileInfo *ti, const RailtypeInfo *rti)
|
||||||
{
|
{
|
||||||
/* Base sprite for track fences. */
|
/* Base sprite for track fences.
|
||||||
SpriteID base_image = GetCustomRailSprite(rti, ti->tile, RTSG_FENCES);
|
* Note: Halftile slopes only have fences on the upper part. */
|
||||||
|
SpriteID base_image = GetCustomRailSprite(rti, ti->tile, RTSG_FENCES, IsHalftileSlope(ti->tileh));
|
||||||
if (base_image == 0) base_image = SPR_TRACK_FENCE_FLAT_X;
|
if (base_image == 0) base_image = SPR_TRACK_FENCE_FLAT_X;
|
||||||
|
|
||||||
switch (GetRailGroundType(ti->tile)) {
|
switch (GetRailGroundType(ti->tile)) {
|
||||||
|
@ -1951,6 +1952,8 @@ static void DrawTrackBitsOverlay(TileInfo *ti, TrackBits track, const RailtypeIn
|
||||||
|
|
||||||
if (IsValidCorner(halftile_corner)) {
|
if (IsValidCorner(halftile_corner)) {
|
||||||
DrawFoundation(ti, HalftileFoundation(halftile_corner));
|
DrawFoundation(ti, HalftileFoundation(halftile_corner));
|
||||||
|
overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY, true);
|
||||||
|
ground = GetCustomRailSprite(rti, ti->tile, RTSG_GROUND, true);
|
||||||
|
|
||||||
/* Draw higher halftile-overlay: Use the sloped sprites with three corners raised. They probably best fit the lightning. */
|
/* Draw higher halftile-overlay: Use the sloped sprites with three corners raised. They probably best fit the lightning. */
|
||||||
Slope fake_slope = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner));
|
Slope fake_slope = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner));
|
||||||
|
|
Loading…
Reference in New Issue