summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/elrail.cpp12
-rw-r--r--src/newgrf_commons.cpp4
-rw-r--r--src/newgrf_commons.h8
-rw-r--r--src/newgrf_railtype.cpp12
-rw-r--r--src/newgrf_railtype.h3
-rw-r--r--src/newgrf_spritegroup.h3
-rw-r--r--src/rail_cmd.cpp6
7 files changed, 28 insertions, 20 deletions
diff --git a/src/elrail.cpp b/src/elrail.cpp
index 409964460..3a2ca3d94 100644
--- a/src/elrail.cpp
+++ b/src/elrail.cpp
@@ -166,20 +166,20 @@ static TrackBits MaskWireBits(TileIndex t, TrackBits tracks)
/**
* Get the base wire sprite to use.
*/
-static inline SpriteID GetWireBase(TileIndex tile, bool upper_halftile = false)
+static inline SpriteID GetWireBase(TileIndex tile, TileContext context = TC_NORMAL)
{
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
- SpriteID wires = GetCustomRailSprite(rti, tile, RTSG_WIRES, upper_halftile);
+ SpriteID wires = GetCustomRailSprite(rti, tile, RTSG_WIRES, context);
return wires == 0 ? SPR_WIRE_BASE : wires;
}
/**
* Get the base pylon sprite to use.
*/
-static inline SpriteID GetPylonBase(TileIndex tile, bool upper_halftile = false)
+static inline SpriteID GetPylonBase(TileIndex tile, TileContext context = TC_NORMAL)
{
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
- SpriteID pylons = GetCustomRailSprite(rti, tile, RTSG_PYLONS, upper_halftile);
+ SpriteID pylons = GetCustomRailSprite(rti, tile, RTSG_PYLONS, context);
return pylons == 0 ? SPR_PYLON_BASE : pylons;
}
@@ -303,7 +303,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
AdjustTileh(ti->tile, &tileh[TS_HOME]);
SpriteID pylon_normal = GetPylonBase(ti->tile);
- SpriteID pylon_halftile = (halftile_corner != CORNER_INVALID) ? GetPylonBase(ti->tile, true) : pylon_normal;
+ SpriteID pylon_halftile = (halftile_corner != CORNER_INVALID) ? GetPylonBase(ti->tile, TC_UPPER_HALFTILE) : pylon_normal;
for (DiagDirection i = DIAGDIR_BEGIN; i < DIAGDIR_END; i++) {
static const uint edge_corners[] = {
@@ -442,7 +442,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
}
SpriteID wire_normal = GetWireBase(ti->tile);
- SpriteID wire_halftile = (halftile_corner != CORNER_INVALID) ? GetWireBase(ti->tile, true) : wire_normal;
+ SpriteID wire_halftile = (halftile_corner != CORNER_INVALID) ? GetWireBase(ti->tile, TC_UPPER_HALFTILE) : wire_normal;
Track halftile_track;
switch (halftile_corner) {
case CORNER_W: halftile_track = TRACK_LEFT; break;
diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp
index 940cdc0de..6fe8e56e4 100644
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -297,7 +297,7 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
* @return value corresponding to the grf expected format:
* Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline
*/
-uint32 GetTerrainType(TileIndex tile, bool upper_halftile)
+uint32 GetTerrainType(TileIndex tile, TileContext context)
{
switch (_settings_game.game_creation.landscape) {
case LT_TROPIC: return GetTropicZone(tile);
@@ -314,7 +314,7 @@ uint32 GetTerrainType(TileIndex tile, bool upper_halftile)
/* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */
if (_generating_world) goto genworld; // we do not care about foundations here
RailGroundType ground = GetRailGroundType(tile);
- has_snow = (ground == RAIL_GROUND_ICE_DESERT || (upper_halftile && ground == RAIL_GROUND_HALF_SNOW));
+ has_snow = (ground == RAIL_GROUND_ICE_DESERT || (context == TC_UPPER_HALFTILE && ground == RAIL_GROUND_HALF_SNOW));
break;
}
diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h
index 0b7ee3d85..9ff994a2e 100644
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -17,6 +17,12 @@
#include "tile_cmd.h"
+/** Contextx for tile accesses */
+enum TileContext {
+ TC_NORMAL, ///< Nothing special.
+ TC_UPPER_HALFTILE, ///< Querying information about the upper part of a tile with halftile foundation.
+};
+
/**
* Maps an entity id stored on the map to a GRF file.
* Entities are objects used ingame (houses, industries, industry tiles) for
@@ -124,7 +130,7 @@ extern IndustryTileOverrideManager _industile_mngr;
extern AirportOverrideManager _airport_mngr;
extern AirportTileOverrideManager _airporttile_mngr;
-uint32 GetTerrainType(TileIndex tile, bool upper_halftile = false);
+uint32 GetTerrainType(TileIndex tile, TileContext context = TC_NORMAL);
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
uint32 GetNearbyTileInformation(TileIndex tile);
diff --git a/src/newgrf_railtype.cpp b/src/newgrf_railtype.cpp
index a4a69a7a4..9f32efeb1 100644
--- a/src/newgrf_railtype.cpp
+++ b/src/newgrf_railtype.cpp
@@ -55,7 +55,7 @@ static uint32 RailTypeGetVariable(const ResolverObject *object, byte variable, b
}
switch (variable) {
- case 0x40: return GetTerrainType(tile, object->u.routes.upper_halftile);
+ case 0x40: return GetTerrainType(tile, object->u.routes.context);
case 0x41: return 0;
case 0x42: return IsLevelCrossingTile(tile) && IsCrossingBarred(tile);
case 0x43:
@@ -76,7 +76,7 @@ static const SpriteGroup *RailTypeResolveReal(const ResolverObject *object, cons
return NULL;
}
-static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile, bool upper_halftile)
+static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile, TileContext context)
{
res->GetRandomBits = &RailTypeGetRandomBits;
res->GetTriggers = &RailTypeGetTriggers;
@@ -85,7 +85,7 @@ static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile, bool
res->ResolveReal = &RailTypeResolveReal;
res->u.routes.tile = tile;
- res->u.routes.upper_halftile = upper_halftile;
+ res->u.routes.context = context;
res->callback = CBID_NO_CALLBACK;
res->callback_param1 = 0;
@@ -96,7 +96,7 @@ static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile, bool
res->count = 0;
}
-SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, bool upper_halftile)
+SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context)
{
assert(rtsg < RTSG_END);
@@ -105,7 +105,7 @@ SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSp
const SpriteGroup *group;
ResolverObject object;
- NewRailTypeResolver(&object, tile, upper_halftile);
+ NewRailTypeResolver(&object, tile, context);
group = SpriteGroup::Resolve(rti->group[rtsg], &object);
if (group == NULL || group->GetNumResults() == 0) return 0;
@@ -135,5 +135,5 @@ uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
*/
void GetRailTypeResolver(ResolverObject *ro, uint index)
{
- NewRailTypeResolver(ro, index, false);
+ NewRailTypeResolver(ro, index, TC_NORMAL);
}
diff --git a/src/newgrf_railtype.h b/src/newgrf_railtype.h
index 24004f915..770bc1b71 100644
--- a/src/newgrf_railtype.h
+++ b/src/newgrf_railtype.h
@@ -13,8 +13,9 @@
#define NEWGRF_RAILTYPE_H
#include "rail.h"
+#include "newgrf_commons.h"
-SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, bool upper_halftile = false);
+SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context = TC_NORMAL);
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile);
diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h
index d1c13ca43..468754244 100644
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -22,6 +22,7 @@
#include "newgrf_callbacks.h"
#include "newgrf_generic.h"
#include "newgrf_storage.h"
+#include "newgrf_commons.h"
/**
* Gets the value of a so-called newgrf "register".
@@ -346,7 +347,7 @@ struct ResolverObject {
} generic;
struct {
TileIndex tile;
- bool upper_halftile; ///< Are we resolving sprites for the upper halftile?
+ TileContext context; ///< Are we resolving sprites for the upper halftile, or on a bridge?
} routes;
struct {
const struct Station *st; ///< Station of the airport for which the callback is run, or NULL for build gui.
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 4f61dfd65..779700c3d 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -1809,7 +1809,7 @@ static void DrawTrackDetails(const TileInfo *ti, const RailtypeInfo *rti)
{
/* Base sprite for track fences.
* Note: Halftile slopes only have fences on the upper part. */
- SpriteID base_image = GetCustomRailSprite(rti, ti->tile, RTSG_FENCES, IsHalftileSlope(ti->tileh));
+ SpriteID base_image = GetCustomRailSprite(rti, ti->tile, RTSG_FENCES, IsHalftileSlope(ti->tileh) ? TC_UPPER_HALFTILE : TC_NORMAL);
if (base_image == 0) base_image = SPR_TRACK_FENCE_FLAT_X;
switch (GetRailGroundType(ti->tile)) {
@@ -1968,8 +1968,8 @@ static void DrawTrackBitsOverlay(TileInfo *ti, TrackBits track, const RailtypeIn
if (IsValidCorner(halftile_corner)) {
DrawFoundation(ti, HalftileFoundation(halftile_corner));
- overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY, true);
- ground = GetCustomRailSprite(rti, ti->tile, RTSG_GROUND, true);
+ overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY, TC_UPPER_HALFTILE);
+ ground = GetCustomRailSprite(rti, ti->tile, RTSG_GROUND, TC_UPPER_HALFTILE);
/* 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));