Mercurial > hg > openttd
comparison rail_cmd.c @ 1035:3edb35954288 draft
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
author | tron <tron@openttd.org> |
---|---|
date | Sun, 16 Jan 2005 11:24:58 +0000 |
parents | fc72cf555e80 |
children | ac8157bbbc79 |
comparison
equal
deleted
inserted
replaced
1034:77f146e1aba7 | 1035:3edb35954288 |
---|---|
233 // never allow building on top of steep tiles | 233 // never allow building on top of steep tiles |
234 if (!(tileh & 0x10)) { | 234 if (!(tileh & 0x10)) { |
235 rail_bits |= existing; | 235 rail_bits |= existing; |
236 | 236 |
237 // don't allow building on the lower side of a coast | 237 // don't allow building on the lower side of a coast |
238 if (IS_TILETYPE(tile, MP_WATER) && ~_valid_tileh_slopes[2][tileh] & rail_bits) { | 238 if (IsTileType(tile, MP_WATER) && ~_valid_tileh_slopes[2][tileh] & rail_bits) { |
239 return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); | 239 return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
240 } | 240 } |
241 | 241 |
242 // no special foundation | 242 // no special foundation |
243 if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0) | 243 if ((~_valid_tileh_slopes[0][tileh] & rail_bits) == 0) |
277 if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) | 277 if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) |
278 return CMD_ERROR; | 278 return CMD_ERROR; |
279 | 279 |
280 if (ti.type == MP_TUNNELBRIDGE) { | 280 if (ti.type == MP_TUNNELBRIDGE) { |
281 /* BUILD ON BRIDGE CODE */ | 281 /* BUILD ON BRIDGE CODE */ |
282 if (!EnsureNoVehicleZ(tile, GET_TILEHEIGHT(tile))) | 282 if (!EnsureNoVehicleZ(tile, TileHeight(tile))) |
283 return CMD_ERROR; | 283 return CMD_ERROR; |
284 | 284 |
285 if ((ti.map5 & 0xF8) == 0xC0) { | 285 if ((ti.map5 & 0xF8) == 0xC0) { |
286 if (ti.tileh & 0x10 || rail_bit != (byte)((ti.map5 & 1) ? 1 : 2)) goto need_clear; | 286 if (ti.tileh & 0x10 || rail_bit != (byte)((ti.map5 & 1) ? 1 : 2)) goto need_clear; |
287 | 287 |
436 // allow building rail under bridge | 436 // allow building rail under bridge |
437 if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) | 437 if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) |
438 return CMD_ERROR; | 438 return CMD_ERROR; |
439 | 439 |
440 if (ti.type == MP_TUNNELBRIDGE) { | 440 if (ti.type == MP_TUNNELBRIDGE) { |
441 if (!EnsureNoVehicleZ(tile, GET_TILEHEIGHT(tile))) | 441 if (!EnsureNoVehicleZ(tile, TileHeight(tile))) |
442 return CMD_ERROR; | 442 return CMD_ERROR; |
443 | 443 |
444 if ((ti.map5 & 0xF8) != 0xE0) | 444 if ((ti.map5 & 0xF8) != 0xE0) |
445 return CMD_ERROR; | 445 return CMD_ERROR; |
446 | 446 |
719 uint tileh; | 719 uint tileh; |
720 uint dir; | 720 uint dir; |
721 | 721 |
722 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); | 722 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
723 | 723 |
724 if (!IS_TILETYPE(tile, MP_RAILWAY) || ((dir=0, _map5[tile] != 1) && (dir=1, _map5[tile] != 2))) | 724 if (!IsTileType(tile, MP_RAILWAY) || ((dir = 0, _map5[tile] != 1) && (dir = 1, _map5[tile] != 2))) |
725 return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK); | 725 return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK); |
726 | 726 |
727 if (!CheckTileOwnership(tile)) | 727 if (!CheckTileOwnership(tile)) |
728 return CMD_ERROR; | 728 return CMD_ERROR; |
729 | 729 |
791 static int32 RemoveTrainWaypoint(uint tile, uint32 flags, bool justremove) | 791 static int32 RemoveTrainWaypoint(uint tile, uint32 flags, bool justremove) |
792 { | 792 { |
793 Waypoint *cp; | 793 Waypoint *cp; |
794 | 794 |
795 // make sure it's a waypoint | 795 // make sure it's a waypoint |
796 if (!IS_TILETYPE(tile, MP_RAILWAY) || !IS_RAIL_WAYPOINT(_map5[tile])) | 796 if (!IsTileType(tile, MP_RAILWAY) || !IS_RAIL_WAYPOINT(_map5[tile])) |
797 return CMD_ERROR; | 797 return CMD_ERROR; |
798 | 798 |
799 if (!CheckTileOwnership(tile) && !(_current_player==17)) | 799 if (!CheckTileOwnership(tile) && !(_current_player==17)) |
800 return CMD_ERROR; | 800 return CMD_ERROR; |
801 | 801 |
883 | 883 |
884 if (!EnsureNoVehicle(tile)) | 884 if (!EnsureNoVehicle(tile)) |
885 return CMD_ERROR; | 885 return CMD_ERROR; |
886 | 886 |
887 // must be railway, and not a depot, and it must have a track in the suggested position. | 887 // must be railway, and not a depot, and it must have a track in the suggested position. |
888 if (!IS_TILETYPE(tile, MP_RAILWAY) || (m5=_map5[tile], m5&0x80) || !HASBIT(m5, track)) | 888 if (!IsTileType(tile, MP_RAILWAY) || (m5 = _map5[tile], m5 & 0x80) || !HASBIT(m5, track)) |
889 return CMD_ERROR; | 889 return CMD_ERROR; |
890 | 890 |
891 _error_message = STR_1005_NO_SUITABLE_RAILROAD_TRACK; | 891 _error_message = STR_1005_NO_SUITABLE_RAILROAD_TRACK; |
892 | 892 |
893 // check rail combination | 893 // check rail combination |
1157 for(x=sx; x<=ex; x+=16) { | 1157 for(x=sx; x<=ex; x+=16) { |
1158 for(y=sy; y<=ey; y+=16) { | 1158 for(y=sy; y<=ey; y+=16) { |
1159 uint tile = TILE_FROM_XY(x,y); | 1159 uint tile = TILE_FROM_XY(x,y); |
1160 DoConvertRailProc *p; | 1160 DoConvertRailProc *p; |
1161 | 1161 |
1162 if (IS_TILETYPE(tile, MP_RAILWAY)) p = DoConvertRail; | 1162 if (IsTileType(tile, MP_RAILWAY)) p = DoConvertRail; |
1163 else if (IS_TILETYPE(tile, MP_STATION)) p = DoConvertStationRail; | 1163 else if (IsTileType(tile, MP_STATION)) p = DoConvertStationRail; |
1164 else if (IS_TILETYPE(tile, MP_STREET)) p = DoConvertStreetRail; | 1164 else if (IsTileType(tile, MP_STREET)) p = DoConvertStreetRail; |
1165 else if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) p = DoConvertTunnelBridgeRail; | 1165 else if (IsTileType(tile, MP_TUNNELBRIDGE)) p = DoConvertTunnelBridgeRail; |
1166 else continue; | 1166 else continue; |
1167 | 1167 |
1168 ret = p(tile, p2, false); | 1168 ret = p(tile, p2, false); |
1169 if (ret == CMD_ERROR) continue; | 1169 if (ret == CMD_ERROR) continue; |
1170 cost += ret; | 1170 cost += ret; |
1747 } SetSignalsData; | 1747 } SetSignalsData; |
1748 | 1748 |
1749 static bool SetSignalsEnumProc(uint tile, SetSignalsData *ssd, int track, uint length, byte *state) | 1749 static bool SetSignalsEnumProc(uint tile, SetSignalsData *ssd, int track, uint length, byte *state) |
1750 { | 1750 { |
1751 // the tile has signals? | 1751 // the tile has signals? |
1752 if (IS_TILETYPE(tile, MP_RAILWAY)) { | 1752 if (IsTileType(tile, MP_RAILWAY)) { |
1753 if ((_map5[tile]&RAIL_TYPE_MASK) == RAIL_TYPE_SIGNALS) { | 1753 if ((_map5[tile]&RAIL_TYPE_MASK) == RAIL_TYPE_SIGNALS) { |
1754 if ((_map3_lo[tile] & _signals_table_both[track]) != 0) { | 1754 if ((_map3_lo[tile] & _signals_table_both[track]) != 0) { |
1755 | 1755 |
1756 // is the signal pointing in to the segment existing? | 1756 // is the signal pointing in to the segment existing? |
1757 if ((_map3_lo[tile] & _signals_table[track]) != 0) { | 1757 if ((_map3_lo[tile] & _signals_table[track]) != 0) { |
2038 a2 = RAIL_GROUND_FENCE_VERT2; | 2038 a2 = RAIL_GROUND_FENCE_VERT2; |
2039 } else { | 2039 } else { |
2040 owner = _map_owner[tile]; | 2040 owner = _map_owner[tile]; |
2041 | 2041 |
2042 if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) { | 2042 if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) { |
2043 if (!IS_TILETYPE(tile + TILE_XY(0,-1), MP_RAILWAY) || | 2043 if (!IsTileType(tile + TILE_XY(0,-1), MP_RAILWAY) || |
2044 owner != _map_owner[tile + TILE_XY(0,-1)] || | 2044 owner != _map_owner[tile + TILE_XY(0,-1)] || |
2045 (_map5[tile + TILE_XY(0,-1)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(0,-1)]==RAIL_BIT_LEFT)) | 2045 (_map5[tile + TILE_XY(0,-1)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(0,-1)]==RAIL_BIT_LEFT)) |
2046 a2 = RAIL_GROUND_FENCE_NW; | 2046 a2 = RAIL_GROUND_FENCE_NW; |
2047 } | 2047 } |
2048 | 2048 |
2049 if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_LEFT)) { | 2049 if ( (!(rail&(RAIL_BIT_DIAG2|RAIL_BIT_LOWER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG1)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_LEFT)) { |
2050 if (!IS_TILETYPE(tile + TILE_XY(0,1), MP_RAILWAY) || | 2050 if (!IsTileType(tile + TILE_XY(0,1), MP_RAILWAY) || |
2051 owner != _map_owner[tile + TILE_XY(0,1)] || | 2051 owner != _map_owner[tile + TILE_XY(0,1)] || |
2052 (_map5[tile + TILE_XY(0,1)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(0,1)]==RAIL_BIT_RIGHT)) | 2052 (_map5[tile + TILE_XY(0,1)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(0,1)]==RAIL_BIT_RIGHT)) |
2053 a2 = (a2 == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE; | 2053 a2 = (a2 == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE; |
2054 } | 2054 } |
2055 | 2055 |
2056 if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_LEFT)) { | 2056 if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_LOWER|RAIL_BIT_LEFT)) { |
2057 if (!IS_TILETYPE(tile + TILE_XY(-1,0), MP_RAILWAY) || | 2057 if (!IsTileType(tile + TILE_XY(-1,0), MP_RAILWAY) || |
2058 owner != _map_owner[tile + TILE_XY(-1,0)] || | 2058 owner != _map_owner[tile + TILE_XY(-1,0)] || |
2059 (_map5[tile + TILE_XY(-1,0)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(-1,0)]==RAIL_BIT_RIGHT)) | 2059 (_map5[tile + TILE_XY(-1,0)]==RAIL_BIT_UPPER || _map5[tile + TILE_XY(-1,0)]==RAIL_BIT_RIGHT)) |
2060 a2 = RAIL_GROUND_FENCE_NE; | 2060 a2 = RAIL_GROUND_FENCE_NE; |
2061 } | 2061 } |
2062 | 2062 |
2063 if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_LOWER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) { | 2063 if ( (!(rail&(RAIL_BIT_DIAG1|RAIL_BIT_LOWER|RAIL_BIT_LEFT)) && (rail&RAIL_BIT_DIAG2)) || rail==(RAIL_BIT_UPPER|RAIL_BIT_RIGHT)) { |
2064 if (!IS_TILETYPE(tile + TILE_XY(1,0), MP_RAILWAY) || | 2064 if (!IsTileType(tile + TILE_XY(1,0), MP_RAILWAY) || |
2065 owner != _map_owner[tile + TILE_XY(1,0)] || | 2065 owner != _map_owner[tile + TILE_XY(1,0)] || |
2066 (_map5[tile + TILE_XY(1,0)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(1,0)]==RAIL_BIT_LEFT)) | 2066 (_map5[tile + TILE_XY(1,0)]==RAIL_BIT_LOWER || _map5[tile + TILE_XY(1,0)]==RAIL_BIT_LEFT)) |
2067 a2 = (a2 == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW; | 2067 a2 = (a2 == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW; |
2068 } | 2068 } |
2069 } | 2069 } |