changeset 15753:052ed430fe94 draft

(svn r20420) -Codechange: Add TileContext enum instead of using a bool.
author frosch <frosch@openttd.org>
date Mon, 09 Aug 2010 07:10:42 +0000
parents e8add3288198
children d18c11abfdb3
files src/elrail.cpp src/newgrf_commons.cpp src/newgrf_commons.h src/newgrf_railtype.cpp src/newgrf_railtype.h src/newgrf_spritegroup.h src/rail_cmd.cpp
diffstat 7 files changed, 28 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/elrail.cpp
+++ b/src/elrail.cpp
@@ -166,20 +166,20 @@
 /**
  * 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 @@
 	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 @@
 	}
 
 	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;
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -297,7 +297,7 @@
  * @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 @@
 					/* 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;
 				}
 
--- 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 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);
 
--- a/src/newgrf_railtype.cpp
+++ b/src/newgrf_railtype.cpp
@@ -55,7 +55,7 @@
 	}
 
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
  */
 void GetRailTypeResolver(ResolverObject *ro, uint index)
 {
-	NewRailTypeResolver(ro, index, false);
+	NewRailTypeResolver(ro, index, TC_NORMAL);
 }
--- 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);
 
--- 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 @@
 		} 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.
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -1809,7 +1809,7 @@
 {
 	/* 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 @@
 
 	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));