Changeset - r8458:f7e90b7c0926
[Not reviewed]
master
0 5 0
frosch - 17 years ago 2008-01-31 17:46:08
frosch@openttd.org
(svn r12028) -Codechange: Split common part of station var 0x67, house var 0x62, indtile var 0x60 and industry var 0x62 to 'newgrf_commons.cpp'.
5 files changed with 25 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/newgrf_commons.cpp
Show inline comments
 
@@ -282,6 +282,22 @@ TileIndex GetNearbyTile(byte parameter, 
 
	/* Swap width and height depending on axis for railway stations */
 
	if (IsRailwayStationTile(tile) && GetRailStationAxis(tile) == AXIS_X) Swap(x, y);
 

	
 
	/* Make sure we never roam outside of the map */
 
	return TILE_MASK(tile + TileDiffXY(x, y));
 
}
 

	
 
/**
 
 * Common part of station var 0x67 , house var 0x62, indtile var 0x60, industry var 0x62.
 
 *
 
 * @param tile the tile of interest.
 
 * @return 0czzbbss: c = TileType; zz = TileZ; bb: 7-3 zero, 4-2 TerrainType, 1 water/shore, 0 zero; ss = TileSlope
 
 */
 
uint32 GetNearbyTileInformation(TileIndex tile)
 
{
 
	TileType tile_type = GetTileType(tile);
 

	
 
	uint z;
 
	Slope tileh = GetTileSlope(tile, &z);
 
	byte terrain_type = GetTerrainType(tile) << 2 | (tile_type == MP_WATER ? 1 : 0) << 1;
 
	return tile_type << 24 | z << 16 | terrain_type << 8 | tileh;
 
}
src/newgrf_commons.h
Show inline comments
 
@@ -90,8 +90,9 @@ public:
 
extern HouseOverrideManager _house_mngr;
 
extern IndustryOverrideManager _industry_mngr;
 
extern IndustryTileOverrideManager _industile_mngr;
 

	
 
uint32 GetTerrainType(TileIndex tile);
 
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
 
uint32 GetNearbyTileInformation(TileIndex tile);
 

	
 
#endif /* NEWGRF_COMMONS_H */
src/newgrf_house.cpp
Show inline comments
 
@@ -167,20 +167,14 @@ static uint32 GetGRFParameter(HouseID ho
 
	if (parameter >= file->param_end) return 0;
 
	return file->param[parameter];
 
}
 

	
 
uint32 GetNearbyTileInformation(byte parameter, TileIndex tile)
 
{
 
	uint32 tile_type;
 

	
 
	tile = GetNearbyTile(parameter, tile);
 
	tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1;
 

	
 
	uint z;
 
	Slope tileh = GetTileSlope(tile, &z);
 
	return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | tileh;
 
	return GetNearbyTileInformation(tile);
 
}
 

	
 
/**
 
 * HouseGetVariable():
 
 *
 
 * Used by the resolver to get values for feature 07 deterministic spritegroups.
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -42,22 +42,16 @@ static uint32 GetGRFParameter(IndustryGf
 
 * @param tile TileIndex from which the callback was initiated
 
 * @param index of the industry been queried for
 
 * @return a construction of bits obeying the newgrf format
 
 */
 
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index)
 
{
 
	byte tile_type;
 
	bool is_same_industry;
 
	if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
 
	bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
 

	
 
	if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
 
	is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
 
	tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1 | (is_same_industry ? 1 : 0);
 

	
 
	uint z;
 
	Slope tileh = GetTileSlope(tile, &z);
 
	return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | tileh;
 
	return GetNearbyTileInformation(tile) | (is_same_industry ? 1 : 0) << 8;
 
}
 

	
 
/** This is the position of the tile relative to the northernmost tile of the industry.
 
 * Format: 00yxYYXX
 
 * Variable  Content
 
 * x         the x offset from the northernmost tile
src/newgrf_station.cpp
Show inline comments
 
@@ -423,18 +423,17 @@ static uint32 StationGetVariable(const R
 
		/* Variables which use the parameter */
 
		/* Variables 0x60 to 0x65 are handled separately below */
 
		case 0x67: { // Land info of nearby tiles
 
			Axis axis = GetRailStationAxis(tile);
 

	
 
			if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
 
			byte tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1;
 

	
 
			uint z;
 
			Slope tileh = GetTileSlope(tile, &z);
 
			bool swap = (axis == AXIS_Y && HasBit(tileh, 0) != HasBit(tileh, 2));
 
			return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | (tileh ^ (swap ? 5 : 0));
 
			Slope tileh = GetTileSlope(tile, NULL);
 
			bool swap = (axis == AXIS_Y && HasBit(tileh, SLOPE_W) != HasBit(tileh, SLOPE_E));
 

	
 
			return GetNearbyTileInformation(tile) ^ (swap ? SLOPE_EW : 0);
 
		}
 

	
 
		case 0x68: { // Station info of nearby tiles
 
			TileIndex nearby_tile = GetNearbyTile(parameter, tile);
 

	
 
			if (!IsRailwayStationTile(nearby_tile)) return 0xFFFFFFFF;
0 comments (0 inline, 0 general)