(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part

pull/155/head
tron 18 years ago
parent 3fd42fab5d
commit c515c34008

@ -47,4 +47,51 @@ static inline void SetRoadUnderBridge(TileIndex t, Owner o)
SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD);
}
static inline void MakeBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, TransportType tt)
{
uint northsouth = (d == DIAGDIR_NE || d == DIAGDIR_NW);
SetTileType(t, MP_TUNNELBRIDGE);
SetTileOwner(t, o);
_m[t].m2 = bridgetype << 4;
_m[t].m4 = 0;
_m[t].m5 = 1 << 7 | 0 << 6 | northsouth << 5 | tt << 1 | DiagDirToAxis(d);
}
static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d)
{
MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD);
_m[t].m3 = 0;
}
static inline void MakeRailBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, RailType r)
{
MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL);
_m[t].m3 = r;
}
static inline void MakeBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a, TransportType tt)
{
SetTileType(t, MP_TUNNELBRIDGE);
SetTileOwner(t, OWNER_NONE);
_m[t].m2 = bridgetype << 4 | piece;
_m[t].m3 = 0;
_m[t].m4 = 0;
_m[t].m5 = 1 << 7 | 1 << 6 | 0 << 5 | 0 << 3 | tt << 1 | a;
}
static inline void MakeRoadBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a)
{
MakeBridgeMiddle(t, bridgetype, piece, a, TRANSPORT_ROAD);
}
static inline void MakeRailBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a, RailType r)
{
MakeBridgeMiddle(t, bridgetype, piece, a, TRANSPORT_RAIL);
SB(_m[t].m3, 4, 4, r);
}
#endif

@ -102,4 +102,14 @@ static inline Axis DiagDirToAxis(DiagDirection d)
return (Axis)(d & 1);
}
/*
* Converts an Axis to a DiagDirection
* Points always in the positive direction, i.e. S[EW]
*/
static inline DiagDirection AxisToDiagDir(Axis a)
{
return (DiagDirection)(2 - a);
}
#endif

@ -309,23 +309,17 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* do the drill? */
if (flags & DC_EXEC) {
/* build the start tile */
ModifyTile(ti_start.tile,
MP_SETTYPE(MP_TUNNELBRIDGE) |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
(bridge_type << 4), /* map2 */
railtype, /* map3_lo */
0x80 | direction | transport << 1 /* map5 */
);
/* build the end tile */
ModifyTile(ti_end.tile,
MP_SETTYPE(MP_TUNNELBRIDGE) |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
(bridge_type << 4), /* map2 */
railtype, /* map3_lo */
0x80 | 0x20 | direction | transport << 1 /* map5 */
);
DiagDirection dir = AxisToDiagDir(direction);
if (transport == TRANSPORT_RAIL) {
MakeRailBridgeRamp(ti_start.tile, _current_player, bridge_type, dir, railtype);
MakeRailBridgeRamp(ti_end.tile, _current_player, bridge_type, ReverseDiagDir(dir), railtype);
} else {
MakeRoadBridgeRamp(ti_start.tile, _current_player, bridge_type, dir);
MakeRoadBridgeRamp(ti_end.tile, _current_player, bridge_type, ReverseDiagDir(dir));
}
MarkTileDirtyByTile(ti_start.tile);
MarkTileDirtyByTile(ti_end.tile);
}
// position of middle part of the odd bridge (larger than MAX(i) otherwise)
@ -380,12 +374,9 @@ not_valid_below:;
break;
}
/* do middle part of bridge */
if (flags & DC_EXEC) {
uint piece;
SetTileType(tile, MP_TUNNELBRIDGE);
//bridges pieces sequence (middle parts)
// bridge len 1: 0
// bridge len 2: 0 1
@ -411,9 +402,11 @@ not_valid_below:;
piece = 2 + ((i % 2 == 0) ^ (i > odd_middle_part));
}
_m[tile].m2 = (bridge_type << 4) | piece;
SB(_m[tile].m3, 4, 4, railtype);
_m[tile].m5 = 0xC0 | transport << 1 | direction;
if (transport == TRANSPORT_RAIL) {
MakeRailBridgeMiddle(tile, bridge_type, piece, direction, railtype);
} else {
MakeRoadBridgeMiddle(tile, bridge_type, piece, direction);
}
switch (transport_under) {
case TRANSPORT_RAIL: SetRailUnderBridge(tile, owner_under, rail_under); break;
case TRANSPORT_ROAD: SetRoadUnderBridge(tile, owner_under); break;

Loading…
Cancel
Save