Changeset - r15743:4f6cef458ee3
[Not reviewed]
master
0 7 0
frosch - 14 years ago 2010-08-09 07:10:42
frosch@openttd.org
(svn r20420) -Codechange: Add TileContext enum instead of using a bool.
7 files changed with 28 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/elrail.cpp
Show inline comments
 
@@ -163,26 +163,26 @@ static TrackBits MaskWireBits(TileIndex 
 
	return (tracks & mask) != TRACK_BIT_NONE ? tracks & mask : 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;
 
}
 

	
 
/**
 
 * Corrects the tileh for certain tile types. Returns an effective tileh for the track on the tile.
 
 * @param tile The tile to analyse
 
@@ -300,13 +300,13 @@ static void DrawCatenaryRailway(const Ti
 
	/* If a track bit is present that is not in the main direction, the track is level */
 
	isflat[TS_HOME] = ((trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0);
 

	
 
	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[] = {
 
			1 << CORNER_N | 1 << CORNER_E, // DIAGDIR_NE
 
			1 << CORNER_S | 1 << CORNER_E, // DIAGDIR_SE
 
			1 << CORNER_S | 1 << CORNER_W, // DIAGDIR_SW
 
@@ -439,13 +439,13 @@ static void DrawCatenaryRailway(const Ti
 
		uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
 

	
 
		if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
 
	}
 

	
 
	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;
 
		case CORNER_S: halftile_track = TRACK_LOWER; break;
 
		case CORNER_E: halftile_track = TRACK_RIGHT; break;
 
		case CORNER_N: halftile_track = TRACK_UPPER; break;
src/newgrf_commons.cpp
Show inline comments
 
@@ -294,13 +294,13 @@ void IndustryTileOverrideManager::SetEnt
 
 * on type of "terrain" the tile it is queries sits on.
 
 * @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:
 
 *         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);
 
		case LT_ARCTIC: {
 
			bool has_snow;
 
			switch (GetTileType(tile)) {
 
@@ -311,13 +311,13 @@ uint32 GetTerrainType(TileIndex tile, bo
 
					break;
 

	
 
				case MP_RAILWAY: {
 
					/* 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;
 
				}
 

	
 
				case MP_ROAD:
 
					/* 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
src/newgrf_commons.h
Show inline comments
 
@@ -14,12 +14,18 @@
 

	
 
#ifndef NEWGRF_COMMONS_H
 
#define NEWGRF_COMMONS_H
 

	
 
#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
 
 * which we need to correlate the ids from the grf files with the ones in the
 
 * the savegames themselves.
 
 * An array of EntityIDMapping structs is saved with the savegame so
 
@@ -121,13 +127,13 @@ public:
 
extern HouseOverrideManager _house_mngr;
 
extern IndustryOverrideManager _industry_mngr;
 
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);
 

	
 
/** Data related to the handling of grf files. */
 
struct GRFFilePropsBase {
 
	/** Set all data constructor for the props. */
src/newgrf_railtype.cpp
Show inline comments
 
@@ -52,13 +52,13 @@ static uint32 RailTypeGetVariable(const 
 
			case 0x42: return 0;
 
			case 0x43: return _date;
 
		}
 
	}
 

	
 
	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:
 
			if (IsRailDepotTile(tile)) return Depot::GetByTile(tile)->build_date;
 
			return _date;
 
	}
 
@@ -73,42 +73,42 @@ static const SpriteGroup *RailTypeResolv
 
{
 
	if (group->num_loading > 0) return group->loading[0];
 
	if (group->num_loaded  > 0) return group->loaded[0];
 
	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;
 
	res->SetTriggers   = &RailTypeSetTriggers;
 
	res->GetVariable   = &RailTypeGetVariable;
 
	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;
 
	res->callback_param2 = 0;
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
	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);
 

	
 
	if (rti->group[rtsg] == NULL) return 0;
 

	
 
	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;
 

	
 
	return group->GetResult();
 
}
 
@@ -132,8 +132,8 @@ uint8 GetReverseRailTypeTranslation(Rail
 
 * Resolve a railtypes's spec and such so we can get a variable.
 
 * @param ro    The resolver object to fill.
 
 * @param index The rail tile to get the data from.
 
 */
 
void GetRailTypeResolver(ResolverObject *ro, uint index)
 
{
 
	NewRailTypeResolver(ro, index, false);
 
	NewRailTypeResolver(ro, index, TC_NORMAL);
 
}
src/newgrf_railtype.h
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file newgrf_railtype.h NewGRF handling of rail types. */
 

	
 
#ifndef NEWGRF_RAILTYPE_H
 
#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);
 

	
 
#endif /* NEWGRF_RAILTYPE_H */
src/newgrf_spritegroup.h
Show inline comments
 
@@ -19,12 +19,13 @@
 
#include "core/pool_type.hpp"
 
#include "house_type.h"
 

	
 
#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".
 
 * @param i index of the register
 
 * @pre i < 0x110
 
 * @return the value of the register
 
@@ -343,13 +344,13 @@ struct ResolverObject {
 
			AIConstructionEvent event;
 
			uint8 count;
 
			uint8 station_size;
 
		} 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.
 
			byte airport_id;               ///< Type of airport for which the callback is run
 
			byte layout;                   ///< Layout of the airport to build.
 
			TileIndex tile;                ///< Tile for the callback, only valid for airporttile callbacks.
src/rail_cmd.cpp
Show inline comments
 
@@ -1806,13 +1806,13 @@ static void DrawTrackFence_WE_2(const Ti
 

	
 

	
 
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)) {
 
		case RAIL_GROUND_FENCE_NW:     DrawTrackFence_NW(ti, base_image);    break;
 
		case RAIL_GROUND_FENCE_SE:     DrawTrackFence_SE(ti, base_image);    break;
 
		case RAIL_GROUND_FENCE_SENW:   DrawTrackFence_NW_SE(ti, base_image); break;
 
@@ -1965,14 +1965,14 @@ static void DrawTrackBitsOverlay(TileInf
 
		if (pbs & TRACK_BIT_RIGHT) DrawTrackSprite(overlay + RTO_E, PALETTE_CRASH, ti, SLOPE_E);
 
		if (pbs & TRACK_BIT_LEFT)  DrawTrackSprite(overlay + RTO_W, PALETTE_CRASH, ti, SLOPE_W);
 
	}
 

	
 
	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));
 

	
 
		SpriteID image;
 
		switch (rgt) {
0 comments (0 inline, 0 general)