Changeset - r3242:4dca345fd1dd
[Not reviewed]
master
0 9 0
tron - 19 years ago 2006-03-17 10:10:31
tron@openttd.org
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
9 files changed with 68 insertions and 51 deletions:
0 comments (0 inline, 0 general)
rail.c
Show inline comments
 
@@ -108,43 +108,39 @@ const Trackdir _reverse_trackdir[] = {
 

	
 
RailType GetTileRailType(TileIndex tile, Trackdir trackdir)
 
{
 
	RailType type = INVALID_RAILTYPE;
 
	DiagDirection exitdir = TrackdirToExitdir(trackdir);
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			/* railway track */
 
			type = _m[tile].m3 & RAILTYPE_MASK;
 
			break;
 
			return GetRailType(tile);
 

	
 
		case MP_STREET:
 
			/* rail/road crossing */
 
			if (IsLevelCrossing(tile))
 
				type = _m[tile].m4 & RAILTYPE_MASK;
 
			if (IsLevelCrossing(tile)) return GetRailTypeCrossing(tile);
 
			break;
 

	
 
		case MP_STATION:
 
			if (IsTrainStationTile(tile))
 
				type = _m[tile].m3 & RAILTYPE_MASK;
 
			if (IsTrainStationTile(tile)) return GetRailType(tile);
 
			break;
 

	
 
		case MP_TUNNELBRIDGE:
 
			if (IsTunnel(tile)) {
 
				if (GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
 
					return _m[tile].m3 & RAILTYPE_MASK;
 
					return GetRailType(tile);
 
				}
 
			} else {
 
				if (IsBridgeRamp(tile)) {
 
					if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
 
						return _m[tile].m3 & RAILTYPE_MASK;
 
						return GetRailType(tile);
 
					}
 
				} else {
 
					if (GetBridgeAxis(tile) == DiagDirToAxis(exitdir)) {
 
						if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
 
							/* on the bridge */
 
							return (_m[tile].m3 >> 4) & RAILTYPE_MASK;
 
							return GetRailTypeOnBridge(tile);
 
						}
 
					} else {
 
						if (IsTransportUnderBridge(tile) &&
 
								GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
 
							/* under the bridge */
 
							return _m[tile].m3 & RAILTYPE_MASK;
 
							return GetRailType(tile);
 
						}
 
					}
 
				}
 
@@ -154,5 +150,5 @@ RailType GetTileRailType(TileIndex tile,
 
		default:
 
			break;
 
	}
 
	return type;
 
	return INVALID_RAILTYPE;
 
}
rail_cmd.c
Show inline comments
 
@@ -317,7 +317,7 @@ int32 CmdBuildSingleRail(int x, int y, u
 
			}
 
			if (m5 & RAIL_TYPE_SPECIAL ||
 
					!IsTileOwner(tile, _current_player) ||
 
					GB(_m[tile].m3, 0, 4) != p1) {
 
					GetRailType(tile) != p1) {
 
				// Get detailed error message
 
				return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			}
 
@@ -944,7 +944,7 @@ static int32 DoConvertRail(TileIndex til
 

	
 
	// change type.
 
	if (exec) {
 
		SB(_m[tile].m3, 0, 4, totype);
 
		SetRailType(tile, totype);
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
rail_map.h
Show inline comments
 
@@ -36,7 +36,6 @@ typedef enum RailTypes {
 
	RAILTYPE_MONO   = 1,
 
	RAILTYPE_MAGLEV = 2,
 
	RAILTYPE_END,
 
	RAILTYPE_MASK   = 0x3,
 
	INVALID_RAILTYPE = 0xFF
 
} RailType;
 

	
 
@@ -45,6 +44,33 @@ static inline RailType GetRailType(TileI
 
	return (RailType)GB(_m[t].m3, 0, 4);
 
}
 

	
 
// TODO remove this by moving to the same bits as GetRailType()
 
static inline RailType GetRailTypeCrossing(TileIndex t)
 
{
 
	return (RailType)GB(_m[t].m4, 0, 4);
 
}
 

	
 
static inline RailType GetRailTypeOnBridge(TileIndex t)
 
{
 
	return (RailType)GB(_m[t].m3, 4, 4);
 
}
 

	
 
static inline void SetRailType(TileIndex t, RailType r)
 
{
 
	SB(_m[t].m3, 0, 4, r);
 
}
 

	
 
// TODO remove this by moving to the same bits as SetRailType()
 
static inline void SetRailTypeCrossing(TileIndex t, RailType r)
 
{
 
	SB(_m[t].m4, 0, 4, r);
 
}
 

	
 
static inline void SetRailTypeOnBridge(TileIndex t, RailType r)
 
{
 
	SB(_m[t].m3, 4, 4, r);
 
}
 

	
 

	
 
/** These are used to specify a single track.
 
 * Can be translated to a trackbit with TrackToTrackbit */
road_cmd.c
Show inline comments
 
@@ -195,7 +195,7 @@ int32 CmdRemoveRoad(int x, int y, uint32
 
					if (flags & DC_EXEC) {
 
						ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
 

	
 
						MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GB(_m[tile].m4, 0, 4));
 
						MakeRailNormal(tile, GetTileOwner(tile), GetCrossingRailBits(tile), GetRailTypeCrossing(tile));
 
						MarkTileDirtyByTile(tile);
 
					}
 
					return cost;
 
@@ -345,7 +345,7 @@ int32 CmdBuildRoad(int x, int y, uint32 
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				MakeRoadCrossing(tile, _current_player, GetTileOwner(tile), roaddir, GB(_m[tile].m3, 0, 4), p2);
 
				MakeRoadCrossing(tile, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), p2);
 
				MarkTileDirtyByTile(tile);
 
			}
 
			return _price.build_road * 2;
 
@@ -428,12 +428,10 @@ int32 DoConvertStreetRail(TileIndex tile
 
	// not owned by me?
 
	if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	// tile is already of requested type?
 
	if (GB(_m[tile].m4, 0, 4) == totype) return CMD_ERROR;
 
	if (GetRailTypeCrossing(tile) == totype) return CMD_ERROR;
 

	
 
	if (exec) {
 
		// change type.
 
		SB(_m[tile].m4, 0, 4, totype);
 
		SetRailTypeCrossing(tile, totype);
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
 
@@ -773,7 +771,7 @@ static void DrawTile_Road(TileInfo *ti)
 
		case ROAD_CROSSING: {
 
			if (ti->tileh != 0) DrawFoundation(ti, ti->tileh);
 

	
 
			image = GetRailTypeInfo(GB(_m[ti->tile].m4, 0, 4))->base_sprites.crossing;
 
			image = GetRailTypeInfo(GetRailTypeCrossing(ti->tile))->base_sprites.crossing;
 

	
 
			if (GB(ti->map5, 3, 1) == 0) image++; /* direction */
 

	
station_cmd.c
Show inline comments
 
@@ -1256,12 +1256,10 @@ int32 DoConvertStationRail(TileIndex til
 
	// tile is not a railroad station?
 
	if (_m[tile].m5 >= 8) return CMD_ERROR;
 

	
 
	// tile is already of requested type?
 
	if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
 
	if (GetRailType(tile) == totype) return CMD_ERROR;
 

	
 
	if (exec) {
 
		// change type.
 
		SB(_m[tile].m3, 0, 4, totype);
 
		SetRailType(tile, totype);
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
 
@@ -1949,7 +1947,7 @@ static void DrawTile_Station(TileInfo *t
 
	uint32 image;
 
	const DrawTileSeqStruct *dtss;
 
	const DrawTileSprites *t = NULL;
 
	RailType railtype = GB(_m[ti->tile].m3, 0, 4);
 
	RailType railtype = GetRailType(ti->tile);
 
	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
 
	SpriteID offset;
 
	uint32 relocation = 0;
train_cmd.c
Show inline comments
 
@@ -2562,7 +2562,7 @@ static bool CheckCompatibleRail(const Ve
 
			return
 
				IsTileOwner(tile, v->owner) && (
 
					!IsFrontEngine(v) ||
 
					IsCompatibleRail(v->u.rail.railtype, GB(_m[tile].m4, 0, 4))
 
					IsCompatibleRail(v->u.rail.railtype, GetRailTypeCrossing(tile))
 
				);
 

	
 
		default:
train_gui.c
Show inline comments
 
@@ -335,7 +335,7 @@ static void ShowBuildTrainWindow(TileInd
 

	
 
	if (tile != 0) {
 
		w->caption_color = GetTileOwner(tile);
 
		WP(w,buildtrain_d).railtype = GB(_m[tile].m3, 0, 4);
 
		WP(w,buildtrain_d).railtype = GetRailType(tile);
 
	} else {
 
		w->caption_color = _local_player;
 
		WP(w,buildtrain_d).railtype = GetBestRailtype(GetPlayer(_local_player));
tunnelbridge_cmd.c
Show inline comments
 
@@ -333,7 +333,7 @@ int32 CmdBuildBridge(int x, int y, uint3
 
				}
 
				transport_under = TRANSPORT_RAIL;
 
				owner_under = GetTileOwner(tile);
 
				rail_under = GB(_m[tile].m3, 0, 4);
 
				rail_under = GetRailType(tile);
 
				break;
 

	
 
			case MP_STREET:
 
@@ -672,7 +672,7 @@ static int32 DoClearBridge(TileIndex til
 
		for (c = tile + delta; c != endtile; c += delta) {
 
			if (IsTransportUnderBridge(c)) {
 
				if (GetTransportTypeUnderBridge(c) == TRANSPORT_RAIL) {
 
					MakeRailNormal(c, GetTileOwner(c), GetRailBitsUnderBridge(c), GB(_m[c].m3, 0, 3));
 
					MakeRailNormal(c, GetTileOwner(c), GetRailBitsUnderBridge(c), GetRailType(tile));
 
				} else {
 
					uint town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0;
 
					MakeRoadNormal(c, GetTileOwner(c), GetRoadBitsUnderBridge(c), town);
 
@@ -721,14 +721,14 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
 
		if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
		if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
 
		if (GetRailType(tile) == totype) return CMD_ERROR;
 

	
 
		endtile = CheckTunnelBusy(tile, &length);
 
		if (endtile == INVALID_TILE) return CMD_ERROR;
 

	
 
		if (exec) {
 
			SB(_m[tile].m3, 0, 4, totype);
 
			SB(_m[endtile].m3, 0, 4, totype);
 
			SetRailType(tile, totype);
 
			SetRailType(endtile, totype);
 
			MarkTileDirtyByTile(tile);
 
			MarkTileDirtyByTile(endtile);
 
		}
 
@@ -741,11 +741,10 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
		if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
 
			return CMD_ERROR;
 

	
 
		// tile is already of requested type?
 
		if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
 
		// change type.
 
		if (GetRailType(tile) == totype) return CMD_ERROR;
 

	
 
		if (exec) {
 
			SB(_m[tile].m3, 0, 4, totype);
 
			SetRailType(tile, totype);
 
			MarkTileDirtyByTile(tile);
 
		}
 
		return _price.build_rail >> 1;
 
@@ -771,11 +770,11 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
			return CMD_ERROR;
 
		}
 

	
 
		if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
 
		if (GetRailType(tile) == totype) return CMD_ERROR;
 

	
 
		if (exec) {
 
			SB(_m[tile].m3, 0, 4, totype);
 
			SB(_m[endtile].m3, 0, 4, totype);
 
			SetRailType(tile, totype);
 
			SetRailType(endtile, totype);
 
			MarkTileDirtyByTile(tile);
 
			MarkTileDirtyByTile(endtile);
 
		}
 
@@ -783,7 +782,7 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
		delta = TileOffsByDir(GetBridgeRampDirection(tile));
 
		for (tile += delta; tile != endtile; tile += delta) {
 
			if (exec) {
 
				SB(_m[tile].m3, 4, 4, totype);
 
				SetRailTypeOnBridge(tile, totype);
 
				MarkTileDirtyByTile(tile);
 
			}
 
			cost += _price.build_rail >> 1;
 
@@ -918,7 +917,7 @@ static void DrawTile_TunnelBridge(TileIn
 

	
 
	if (IsTunnel(ti->tile)) {
 
		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
 
			image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel;
 
			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
 
		} else {
 
			image = SPR_TUNNEL_ENTRY_REAR_ROAD;
 
		}
 
@@ -936,9 +935,9 @@ static void DrawTile_TunnelBridge(TileIn
 
			RailType rt;
 

	
 
			if (IsBridgeRamp(ti->tile)) {
 
				rt = GB(_m[ti->tile].m3, 0, 3);
 
				rt = GetRailType(ti->tile);
 
			} else {
 
				rt = GB(_m[ti->tile].m3, 4, 3);
 
				rt = GetRailTypeOnBridge(ti->tile);
 
			}
 

	
 
			base_offset = GetRailTypeInfo(rt)->bridge_offset;
 
@@ -987,7 +986,7 @@ static void DrawTile_TunnelBridge(TileIn
 
				}
 

	
 
				if (GetTransportTypeUnderBridge(ti->tile) == TRANSPORT_RAIL) {
 
					const RailtypeInfo *rti = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4));
 
					const RailtypeInfo* rti = GetRailTypeInfo(GetRailType(ti->tile));
 

	
 
					if (ti->tileh == 0) {
 
						image = (axis == AXIS_X ? SPR_RAIL_TRACK_Y : SPR_RAIL_TRACK_X);
waypoint.c
Show inline comments
 
@@ -213,7 +213,7 @@ int32 CmdBuildTrainWaypoint(int x, int y
 

	
 
	if (flags & DC_EXEC) {
 
		const StationSpec *spec = NULL;
 
		MakeRailWaypoint(tile, GetTileOwner(tile), axis, GB(_m[tile].m3, 0, 4), wp->index);
 
		MakeRailWaypoint(tile, GetTileOwner(tile), axis, GetRailType(tile), wp->index);
 
		MarkTileDirtyByTile(tile);
 

	
 
		if (GB(p1, 0, 8) < GetNumCustomStations(STAT_CLASS_WAYP))
 
@@ -300,7 +300,7 @@ int32 RemoveTrainWaypoint(TileIndex tile
 
		RedrawWaypointSign(wp);
 

	
 
		if (justremove) {
 
			MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GB(_m[tile].m3, 0, 4));
 
			MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GetRailType(tile));
 
			MarkTileDirtyByTile(tile);
 
		} else {
 
			DoClearSquare(tile);
0 comments (0 inline, 0 general)