1
0
Fork 0

(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()

release/0.5
tron 2006-03-17 10:10:31 +00:00
parent d8677f1afa
commit 89090790c2
9 changed files with 68 additions and 51 deletions

26
rail.c
View File

@ -108,43 +108,39 @@ const Trackdir _reverse_trackdir[] = {
RailType GetTileRailType(TileIndex tile, Trackdir trackdir) RailType GetTileRailType(TileIndex tile, Trackdir trackdir)
{ {
RailType type = INVALID_RAILTYPE;
DiagDirection exitdir = TrackdirToExitdir(trackdir); DiagDirection exitdir = TrackdirToExitdir(trackdir);
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_RAILWAY: case MP_RAILWAY:
/* railway track */ return GetRailType(tile);
type = _m[tile].m3 & RAILTYPE_MASK;
break;
case MP_STREET: case MP_STREET:
/* rail/road crossing */ /* rail/road crossing */
if (IsLevelCrossing(tile)) if (IsLevelCrossing(tile)) return GetRailTypeCrossing(tile);
type = _m[tile].m4 & RAILTYPE_MASK;
break; break;
case MP_STATION: case MP_STATION:
if (IsTrainStationTile(tile)) if (IsTrainStationTile(tile)) return GetRailType(tile);
type = _m[tile].m3 & RAILTYPE_MASK;
break; break;
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if (IsTunnel(tile)) { if (IsTunnel(tile)) {
if (GetTunnelTransportType(tile) == TRANSPORT_RAIL) { if (GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
return _m[tile].m3 & RAILTYPE_MASK; return GetRailType(tile);
} }
} else { } else {
if (IsBridgeRamp(tile)) { if (IsBridgeRamp(tile)) {
if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) { if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
return _m[tile].m3 & RAILTYPE_MASK; return GetRailType(tile);
} }
} else { } else {
if (GetBridgeAxis(tile) == DiagDirToAxis(exitdir)) { if (GetBridgeAxis(tile) == DiagDirToAxis(exitdir)) {
if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) { if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
/* on the bridge */ return GetRailTypeOnBridge(tile);
return (_m[tile].m3 >> 4) & RAILTYPE_MASK;
} }
} else { } else {
if (IsTransportUnderBridge(tile) && if (IsTransportUnderBridge(tile) &&
GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) { GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
/* under the bridge */ return GetRailType(tile);
return _m[tile].m3 & RAILTYPE_MASK;
} }
} }
} }
@ -154,5 +150,5 @@ RailType GetTileRailType(TileIndex tile, Trackdir trackdir)
default: default:
break; break;
} }
return type; return INVALID_RAILTYPE;
} }

View File

@ -317,7 +317,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} }
if (m5 & RAIL_TYPE_SPECIAL || if (m5 & RAIL_TYPE_SPECIAL ||
!IsTileOwner(tile, _current_player) || !IsTileOwner(tile, _current_player) ||
GB(_m[tile].m3, 0, 4) != p1) { GetRailType(tile) != p1) {
// Get detailed error message // Get detailed error message
return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); return DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
} }
@ -944,7 +944,7 @@ static int32 DoConvertRail(TileIndex tile, uint totype, bool exec)
// change type. // change type.
if (exec) { if (exec) {
SB(_m[tile].m3, 0, 4, totype); SetRailType(tile, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }

View File

@ -36,7 +36,6 @@ typedef enum RailTypes {
RAILTYPE_MONO = 1, RAILTYPE_MONO = 1,
RAILTYPE_MAGLEV = 2, RAILTYPE_MAGLEV = 2,
RAILTYPE_END, RAILTYPE_END,
RAILTYPE_MASK = 0x3,
INVALID_RAILTYPE = 0xFF INVALID_RAILTYPE = 0xFF
} RailType; } RailType;
@ -45,6 +44,33 @@ static inline RailType GetRailType(TileIndex t)
return (RailType)GB(_m[t].m3, 0, 4); 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. /** These are used to specify a single track.
* Can be translated to a trackbit with TrackToTrackbit */ * Can be translated to a trackbit with TrackToTrackbit */

View File

@ -195,7 +195,7 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); 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); MarkTileDirtyByTile(tile);
} }
return cost; return cost;
@ -345,7 +345,7 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} }
if (flags & DC_EXEC) { 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); MarkTileDirtyByTile(tile);
} }
return _price.build_road * 2; return _price.build_road * 2;
@ -428,12 +428,10 @@ int32 DoConvertStreetRail(TileIndex tile, uint totype, bool exec)
// not owned by me? // not owned by me?
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
// tile is already of requested type? if (GetRailTypeCrossing(tile) == totype) return CMD_ERROR;
if (GB(_m[tile].m4, 0, 4) == totype) return CMD_ERROR;
if (exec) { if (exec) {
// change type. SetRailTypeCrossing(tile, totype);
SB(_m[tile].m4, 0, 4, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
@ -773,7 +771,7 @@ static void DrawTile_Road(TileInfo *ti)
case ROAD_CROSSING: { case ROAD_CROSSING: {
if (ti->tileh != 0) DrawFoundation(ti, ti->tileh); 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 */ if (GB(ti->map5, 3, 1) == 0) image++; /* direction */

View File

@ -1256,12 +1256,10 @@ int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec)
// tile is not a railroad station? // tile is not a railroad station?
if (_m[tile].m5 >= 8) return CMD_ERROR; if (_m[tile].m5 >= 8) return CMD_ERROR;
// tile is already of requested type? if (GetRailType(tile) == totype) return CMD_ERROR;
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
if (exec) { if (exec) {
// change type. SetRailType(tile, totype);
SB(_m[tile].m3, 0, 4, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
@ -1949,7 +1947,7 @@ static void DrawTile_Station(TileInfo *ti)
uint32 image; uint32 image;
const DrawTileSeqStruct *dtss; const DrawTileSeqStruct *dtss;
const DrawTileSprites *t = NULL; const DrawTileSprites *t = NULL;
RailType railtype = GB(_m[ti->tile].m3, 0, 4); RailType railtype = GetRailType(ti->tile);
const RailtypeInfo *rti = GetRailTypeInfo(railtype); const RailtypeInfo *rti = GetRailTypeInfo(railtype);
SpriteID offset; SpriteID offset;
uint32 relocation = 0; uint32 relocation = 0;

View File

@ -2562,7 +2562,7 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
return return
IsTileOwner(tile, v->owner) && ( IsTileOwner(tile, v->owner) && (
!IsFrontEngine(v) || !IsFrontEngine(v) ||
IsCompatibleRail(v->u.rail.railtype, GB(_m[tile].m4, 0, 4)) IsCompatibleRail(v->u.rail.railtype, GetRailTypeCrossing(tile))
); );
default: default:

View File

@ -335,7 +335,7 @@ static void ShowBuildTrainWindow(TileIndex tile)
if (tile != 0) { if (tile != 0) {
w->caption_color = GetTileOwner(tile); w->caption_color = GetTileOwner(tile);
WP(w,buildtrain_d).railtype = GB(_m[tile].m3, 0, 4); WP(w,buildtrain_d).railtype = GetRailType(tile);
} else { } else {
w->caption_color = _local_player; w->caption_color = _local_player;
WP(w,buildtrain_d).railtype = GetBestRailtype(GetPlayer(_local_player)); WP(w,buildtrain_d).railtype = GetBestRailtype(GetPlayer(_local_player));

View File

@ -333,7 +333,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} }
transport_under = TRANSPORT_RAIL; transport_under = TRANSPORT_RAIL;
owner_under = GetTileOwner(tile); owner_under = GetTileOwner(tile);
rail_under = GB(_m[tile].m3, 0, 4); rail_under = GetRailType(tile);
break; break;
case MP_STREET: case MP_STREET:
@ -672,7 +672,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
for (c = tile + delta; c != endtile; c += delta) { for (c = tile + delta; c != endtile; c += delta) {
if (IsTransportUnderBridge(c)) { if (IsTransportUnderBridge(c)) {
if (GetTransportTypeUnderBridge(c) == TRANSPORT_RAIL) { 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 { } else {
uint town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0; uint town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0;
MakeRoadNormal(c, GetTileOwner(c), GetRoadBitsUnderBridge(c), town); MakeRoadNormal(c, GetTileOwner(c), GetRoadBitsUnderBridge(c), town);
@ -721,14 +721,14 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) { if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
if (!CheckTileOwnership(tile)) return CMD_ERROR; 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); endtile = CheckTunnelBusy(tile, &length);
if (endtile == INVALID_TILE) return CMD_ERROR; if (endtile == INVALID_TILE) return CMD_ERROR;
if (exec) { if (exec) {
SB(_m[tile].m3, 0, 4, totype); SetRailType(tile, totype);
SB(_m[endtile].m3, 0, 4, totype); SetRailType(endtile, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile); MarkTileDirtyByTile(endtile);
} }
@ -741,11 +741,10 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))) if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
return CMD_ERROR; return CMD_ERROR;
// tile is already of requested type? if (GetRailType(tile) == totype) return CMD_ERROR;
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
// change type.
if (exec) { if (exec) {
SB(_m[tile].m3, 0, 4, totype); SetRailType(tile, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
return _price.build_rail >> 1; return _price.build_rail >> 1;
@ -771,11 +770,11 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
return CMD_ERROR; return CMD_ERROR;
} }
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; if (GetRailType(tile) == totype) return CMD_ERROR;
if (exec) { if (exec) {
SB(_m[tile].m3, 0, 4, totype); SetRailType(tile, totype);
SB(_m[endtile].m3, 0, 4, totype); SetRailType(endtile, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile); MarkTileDirtyByTile(endtile);
} }
@ -783,7 +782,7 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
delta = TileOffsByDir(GetBridgeRampDirection(tile)); delta = TileOffsByDir(GetBridgeRampDirection(tile));
for (tile += delta; tile != endtile; tile += delta) { for (tile += delta; tile != endtile; tile += delta) {
if (exec) { if (exec) {
SB(_m[tile].m3, 4, 4, totype); SetRailTypeOnBridge(tile, totype);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
cost += _price.build_rail >> 1; cost += _price.build_rail >> 1;
@ -918,7 +917,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
if (IsTunnel(ti->tile)) { if (IsTunnel(ti->tile)) {
if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) { 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 { } else {
image = SPR_TUNNEL_ENTRY_REAR_ROAD; image = SPR_TUNNEL_ENTRY_REAR_ROAD;
} }
@ -936,9 +935,9 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
RailType rt; RailType rt;
if (IsBridgeRamp(ti->tile)) { if (IsBridgeRamp(ti->tile)) {
rt = GB(_m[ti->tile].m3, 0, 3); rt = GetRailType(ti->tile);
} else { } else {
rt = GB(_m[ti->tile].m3, 4, 3); rt = GetRailTypeOnBridge(ti->tile);
} }
base_offset = GetRailTypeInfo(rt)->bridge_offset; base_offset = GetRailTypeInfo(rt)->bridge_offset;
@ -987,7 +986,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
} }
if (GetTransportTypeUnderBridge(ti->tile) == TRANSPORT_RAIL) { 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) { if (ti->tileh == 0) {
image = (axis == AXIS_X ? SPR_RAIL_TRACK_Y : SPR_RAIL_TRACK_X); image = (axis == AXIS_X ? SPR_RAIL_TRACK_Y : SPR_RAIL_TRACK_X);

View File

@ -213,7 +213,7 @@ int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
const StationSpec *spec = NULL; 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); MarkTileDirtyByTile(tile);
if (GB(p1, 0, 8) < GetNumCustomStations(STAT_CLASS_WAYP)) if (GB(p1, 0, 8) < GetNumCustomStations(STAT_CLASS_WAYP))
@ -300,7 +300,7 @@ int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove)
RedrawWaypointSign(wp); RedrawWaypointSign(wp);
if (justremove) { if (justremove) {
MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GB(_m[tile].m3, 0, 4)); MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GetRailType(tile));
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} else { } else {
DoClearSquare(tile); DoClearSquare(tile);