tron@2186: /* $Id$ */ tron@2186: celestar@2262: /** @file tunnelbridge_cmd.c celestar@2262: * This file deals with tunnels and bridges (non-gui stuff) celestar@2262: * @todo seperate this file into two celestar@2262: */ celestar@2262: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@1363: #include "table/sprites.h" tron@507: #include "table/strings.h" tron@2163: #include "functions.h" tron@679: #include "map.h" tron@1209: #include "tile.h" truelight@0: #include "vehicle.h" truelight@0: #include "viewport.h" truelight@0: #include "command.h" truelight@0: #include "player.h" truelight@0: #include "town.h" tron@337: #include "sound.h" tron@2159: #include "variables.h" celestar@2262: #include "bridge.h" bjarni@2676: #include "train.h" truelight@0: ludde@2261: #include "table/bridge_land.h" ludde@2261: ludde@2261: extern const byte _track_sloped_sprites[14]; ludde@2261: extern const SpriteID _water_shore_sprites[15]; ludde@2261: tron@1977: extern void DrawCanalWater(TileIndex tile); truelight@0: peter1138@2478: const Bridge orig_bridge[] = { celestar@2262: /* bjarni@2293: year of availablity celestar@2262: | minimum length celestar@2262: | | maximum length celestar@2262: | | | price celestar@2262: | | | | maximum speed celestar@2262: | | | | | sprite to use in GUI string with description celestar@2262: | | | | | | | */ peter1138@2478: { 0, 0, 16, 80, 32, 0xA24 , STR_5012_WOODEN , NULL, 0 }, peter1138@2478: { 0, 0, 2, 112, 48, 0xA26 | PALETTE_TO_STRUCT_RED , STR_5013_CONCRETE , NULL, 0 }, peter1138@2478: { 10, 0, 5, 144, 64, 0xA25 , STR_500F_GIRDER_STEEL , NULL, 0 }, peter1138@2478: { 0, 2, 10, 168, 80, 0xA22 | PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 }, peter1138@2478: { 10, 3, 16, 185, 96, 0xA22 , STR_500E_SUSPENSION_STEEL , NULL, 0 }, peter1138@2478: { 10, 3, 16, 192, 112, 0xA22 | PALETTE_TO_STRUCT_YELLOW , STR_500E_SUSPENSION_STEEL , NULL, 0 }, peter1138@2478: { 10, 3, 7, 224, 160, 0xA23 , STR_5010_CANTILEVER_STEEL , NULL, 0 }, peter1138@2478: { 10, 3, 8, 232, 208, 0xA23 | PALETTE_TO_STRUCT_BROWN , STR_5010_CANTILEVER_STEEL , NULL, 0 }, peter1138@2478: { 10, 3, 9, 248, 240, 0xA23 | PALETTE_TO_STRUCT_RED , STR_5010_CANTILEVER_STEEL , NULL, 0 }, peter1138@2478: { 10, 0, 2, 240, 256, 0xA27 , STR_500F_GIRDER_STEEL , NULL, 0 }, peter1138@2478: { 75, 2, 16, 255, 320, 0xA28 , STR_5014_TUBULAR_STEEL , NULL, 0 }, peter1138@2478: { 85, 2, 32, 380, 512, 0xA28 | PALETTE_TO_STRUCT_YELLOW , STR_5014_TUBULAR_STEEL , NULL, 0 }, peter1138@2478: { 90, 2, 32, 510, 608, 0xA28 | PALETTE_TO_STRUCT_GREY , STR_BRIDGE_TUBULAR_SILICON , NULL, 0 } truelight@0: }; truelight@0: tron@2763: Bridge _bridge[MAX_BRIDGES]; tron@2763: tron@2763: truelight@0: // calculate the price factor for building a long bridge. truelight@0: // basically the cost delta is 1,1, 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6, 7,7,7,7,7,7,7, 8,8,8,8,8,8,8,8, truelight@0: int CalcBridgeLenCostFactor(int x) truelight@0: { tron@2639: int n; tron@2639: int r; tron@2639: truelight@0: if (x < 2) return x; truelight@0: x -= 2; tron@2639: for (n = 0, r = 2;; n++) { truelight@0: if (x <= n) return r + x * n; truelight@0: r += n * n; truelight@0: x -= n; truelight@0: } truelight@0: } truelight@0: truelight@0: enum { truelight@0: // foundation, whole tile is leveled up (tileh's 7, 11, 13, 14) --> 3 corners raised truelight@0: BRIDGE_FULL_LEVELED_FOUNDATION = 1 << 7 | 1 << 11 | 1 << 13 | 1 << 14, truelight@0: // foundation, tile is partly leveled up (tileh's 1, 2, 4, 8) --> 1 corner raised truelight@0: BRIDGE_PARTLY_LEVELED_FOUNDATION = 1 << 1 | 1 << 2 | 1 << 4 | 1 << 8, truelight@0: // no foundations (X,Y direction) (tileh's 0, 3, 6, 9, 12) truelight@0: BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12, truelight@0: }; truelight@0: peter1138@2478: static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table) peter1138@2478: { peter1138@2478: const Bridge *bridge = &_bridge[index]; peter1138@2478: assert(table < 7); peter1138@2478: if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) { peter1138@2478: return _bridge_sprite_table[index][table]; peter1138@2478: } else { peter1138@2478: return bridge->sprite_table[table]; peter1138@2478: } peter1138@2478: } peter1138@2478: celestar@2262: /** celestar@2262: * Determines which piece of a bridge is contained in the current tile celestar@2262: * @param tile The tile to analyze celestar@2262: * @return the piece celestar@2262: */ celestar@2262: static inline int GetBridgePiece(TileIndex tile) celestar@2262: { celestar@2262: return GB(_m[tile].m2, 0, 4); celestar@2262: } celestar@2262: celestar@2262: /** celestar@2262: * Determines the type of bridge on a tile celestar@2262: * @param tile The tile to analyze celestar@2262: * @return The bridge type celestar@2262: */ celestar@2262: static inline int GetBridgeType(TileIndex tile) celestar@2262: { celestar@2262: return GB(_m[tile].m2, 4, 4); celestar@2262: } celestar@2262: celestar@2262: /** check if bridge can be built on slope truelight@0: * direction 0 = X-axis, direction 1 = Y-axis truelight@0: * is_start_tile = false <-- end tile truelight@0: * is_start_tile = true <-- start tile truelight@0: */ truelight@0: static uint32 CheckBridgeSlope(uint direction, uint tileh, bool is_start_tile) truelight@0: { tron@2639: if (IsSteepTileh(tileh)) return CMD_ERROR; truelight@0: tron@2639: if (is_start_tile) { tron@2639: /* check slope at start tile tron@2639: - no extra cost tron@2639: - direction X: tiles 0, 12 tron@2639: - direction Y: tiles 0, 9 tron@2639: */ tron@2639: if ((direction ? 0x201 : 0x1001) & (1 << tileh)) return 0; truelight@0: tron@2639: // disallow certain start tiles to avoid certain crooked bridges tron@2639: if (tileh == 2) return CMD_ERROR; tron@2639: } else { tron@2639: /* check slope at end tile tron@2639: - no extra cost tron@2639: - direction X: tiles 0, 3 tron@2639: - direction Y: tiles 0, 6 tron@2639: */ tron@2639: if ((direction? 0x41 : 0x9) & (1 << tileh)) return 0; truelight@0: tron@2639: // disallow certain end tiles to avoid certain crooked bridges tron@2639: if (tileh == 8) return CMD_ERROR; tron@2639: } truelight@0: tron@2639: /* disallow common start/end tiles to avoid certain crooked bridges e.g. tron@2639: * start-tile: X 2,1 Y 2,4 (2 was disabled before) tron@2639: * end-tile: X 8,4 Y 8,1 (8 was disabled before) tron@2639: */ tron@2639: if ((tileh == 1 && is_start_tile != (bool)direction) || tron@2639: (tileh == 4 && is_start_tile == (bool)direction)) { tron@2639: return CMD_ERROR; truelight@0: } truelight@0: tron@2639: // slope foundations tron@2639: if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh) || BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << tileh)) tron@2639: return _price.terraform; tron@2639: truelight@0: return CMD_ERROR; truelight@0: } truelight@0: truelight@0: uint32 GetBridgeLength(TileIndex begin, TileIndex end) truelight@0: { tron@2639: int x1 = TileX(begin); tron@2639: int y1 = TileY(begin); tron@2639: int x2 = TileX(end); tron@2639: int y2 = TileY(end); truelight@193: tron@2639: return abs(x2 + y2 - x1 - y1) - 1; truelight@0: } truelight@0: tron@2639: bool CheckBridge_Stuff(byte bridge_type, uint bridge_len) truelight@0: { celestar@2262: const Bridge *b = &_bridge[bridge_type]; tron@2639: uint max; // max possible length of a bridge (with patch 100) truelight@0: Darkvater@1781: if (bridge_type >= MAX_BRIDGES) return false; celestar@2262: if (b->avail_year > _cur_year) return false; truelight@0: celestar@2262: max = b->max_length; tron@2639: if (max >= 16 && _patches.longbridges) max = 100; truelight@0: tron@2639: return b->min_length <= bridge_len && bridge_len <= max; truelight@0: } truelight@0: Darkvater@1775: /** Build a Bridge Darkvater@1775: * @param x,y end tile coord Darkvater@1775: * @param p1 packed start tile coords (~ dx) Darkvater@1775: * @param p2 various bitstuffed elements Darkvater@1775: * - p2 = (bit 0- 7) - bridge type (hi bh) Darkvater@1775: * - p2 = (bit 8-..) - rail type. bit15 ((x>>8)&0x80) means road bridge. truelight@0: */ truelight@0: int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2) truelight@0: { truelight@0: int bridge_type; truelight@0: byte rail_or_road, railtype, m5; truelight@0: int sx,sy; truelight@0: TileInfo ti_start, ti_end, ti; /* OPT: only 2 of those are ever used */ tron@2639: uint bridge_len; tron@2639: uint odd_middle_part; truelight@0: uint direction; tron@2639: uint i; truelight@0: int32 cost, terraformcost, ret; pasky@1585: bool allow_on_slopes; truelight@0: truelight@0: SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); truelight@193: truelight@0: /* unpack parameters */ tron@2140: bridge_type = GB(p2, 0, 8); tron@2140: railtype = GB(p2, 8, 8); truelight@193: tron@2934: if (p1 >= MapSize()) return CMD_ERROR; Darkvater@1775: truelight@0: // type of bridge Darkvater@1775: if (HASBIT(railtype, 7)) { // bit 15 of original p2 param truelight@0: railtype = 0; truelight@0: rail_or_road = 2; truelight@0: } else { Darkvater@1775: if (!ValParamRailtype(railtype)) return CMD_ERROR; truelight@0: rail_or_road = 0; truelight@0: } truelight@0: tron@926: sx = TileX(p1) * 16; tron@926: sy = TileY(p1) * 16; truelight@0: truelight@0: direction = 0; truelight@0: truelight@0: /* check if valid, and make sure that (x,y) are smaller than (sx,sy) */ truelight@0: if (x == sx) { tron@2639: if (y == sy) return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); truelight@0: direction = 1; truelight@0: if (y > sy) { truelight@0: intswap(y,sy); truelight@0: intswap(x,sx); truelight@0: } truelight@0: } else if (y == sy) { truelight@0: if (x > sx) { truelight@0: intswap(y,sy); truelight@0: intswap(x,sx); truelight@0: } tron@2639: } else { truelight@0: return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); tron@2639: } truelight@0: Darkvater@1781: /* set and test bridge length, availability */ Darkvater@1781: bridge_len = ((sx + sy - x - y) >> 4) - 1; Darkvater@1781: if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE); Darkvater@1781: truelight@0: /* retrieve landscape height and ensure it's on land */ tron@2951: if (( tron@2951: FindLandscapeHeight(&ti_end, sx, sy), tron@2951: ti_end.type == MP_WATER && ti_end.map5 == 0 tron@2951: ) || ( tron@2951: FindLandscapeHeight(&ti_start, x, y), tron@2951: ti_start.type == MP_WATER && ti_start.map5 == 0 tron@2951: )) { truelight@0: return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH); tron@2951: } truelight@0: truelight@0: if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_start.tileh)) { truelight@0: ti_start.z += 8; truelight@0: ti_start.tileh = 0; truelight@0: } truelight@0: truelight@0: if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_end.tileh)) { truelight@0: ti_end.z += 8; truelight@0: ti_end.tileh = 0; truelight@0: } truelight@0: truelight@0: if (ti_start.z != ti_end.z) truelight@0: return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); truelight@0: pasky@1585: pasky@1585: // Towns are not allowed to use bridges on slopes. truelight@2422: allow_on_slopes = (!_is_old_ai_player Darkvater@1781: && _current_player != OWNER_TOWN && _patches.build_on_slopes); pasky@1585: pasky@1585: /* Try and clear the start landscape */ pasky@1585: Darkvater@1775: if (CmdFailed(ret = DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) truelight@0: return CMD_ERROR; truelight@0: cost = ret; truelight@0: pasky@1585: // true - bridge-start-tile, false - bridge-end-tile pasky@1585: terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true); peter1138@2737: if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes)) truelight@0: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); truelight@0: cost += terraformcost; truelight@0: pasky@1585: /* Try and clear the end landscape */ pasky@1585: tron@2639: ret = DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); tron@2639: if (CmdFailed(ret)) return CMD_ERROR; truelight@0: cost += ret; truelight@193: pasky@1585: // false - end tile slope check pasky@1585: terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false); peter1138@2737: if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes)) pasky@1585: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); pasky@1585: cost += terraformcost; truelight@0: truelight@0: truelight@0: /* do the drill? */ truelight@0: if (flags & DC_EXEC) { truelight@0: /* build the start tile */ truelight@0: ModifyTile(ti_start.tile, truelight@0: MP_SETTYPE(MP_TUNNELBRIDGE) | truelight@0: MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, truelight@0: (bridge_type << 4), /* map2 */ truelight@0: railtype, /* map3_lo */ truelight@0: 0x80 | direction | rail_or_road /* map5 */ truelight@0: ); truelight@0: truelight@0: /* build the end tile */ truelight@0: ModifyTile(ti_end.tile, truelight@0: MP_SETTYPE(MP_TUNNELBRIDGE) | truelight@0: MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, truelight@0: (bridge_type << 4), /* map2 */ truelight@0: railtype, /* map3_lo */ truelight@0: 0x80 | 0x20 | direction | rail_or_road /* map5 */ truelight@0: ); truelight@0: } truelight@0: Darkvater@1781: // position of middle part of the odd bridge (larger than MAX(i) otherwise) Darkvater@1781: odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len; truelight@0: Darkvater@1781: for (i = 0; i != bridge_len; i++) { Darkvater@1781: if (direction != 0) { Darkvater@1781: y += 16; tron@2639: } else { Darkvater@1781: x += 16; tron@2639: } truelight@0: truelight@0: FindLandscapeHeight(&ti, x, y); truelight@0: truelight@0: _error_message = STR_5009_LEVEL_LAND_OR_WATER_REQUIRED; tron@2639: if (ti.tileh != 0 && ti.z >= ti_start.z) return CMD_ERROR; truelight@0: truelight@193: // Find ship below tron@2639: if (ti.type == MP_WATER && !EnsureNoVehicle(ti.tile)) { truelight@0: _error_message = STR_980E_SHIP_IN_THE_WAY; truelight@0: return CMD_ERROR; truelight@0: } truelight@0: truelight@0: if (ti.type == MP_WATER) { tron@1091: if (ti.map5 > 1) goto not_valid_below; truelight@0: m5 = 0xC8; truelight@0: } else if (ti.type == MP_RAILWAY) { truelight@0: if (direction == 0) { truelight@0: if (ti.map5 != 2) goto not_valid_below; truelight@0: } else { truelight@0: if (ti.map5 != 1) goto not_valid_below; truelight@0: } truelight@0: m5 = 0xE0; truelight@0: } else if (ti.type == MP_STREET) { truelight@0: if (direction == 0) { truelight@0: if (ti.map5 != 5) goto not_valid_below; truelight@0: } else { truelight@0: if (ti.map5 != 10) goto not_valid_below; truelight@0: } truelight@0: m5 = 0xE8; truelight@0: } else { truelight@0: not_valid_below:; truelight@0: /* try and clear the middle landscape */ tron@2639: ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); tron@2639: if (CmdFailed(ret)) return CMD_ERROR; truelight@0: cost += ret; truelight@0: m5 = 0xC0; truelight@0: } truelight@0: truelight@0: /* do middle part of bridge */ truelight@0: if (flags & DC_EXEC) { tron@2049: _m[ti.tile].m5 = (byte)(m5 | direction | rail_or_road); tron@1059: SetTileType(ti.tile, MP_TUNNELBRIDGE); truelight@0: truelight@0: //bridges pieces sequence (middle parts) truelight@193: // bridge len 1: 0 truelight@0: // bridge len 2: 0 1 truelight@0: // bridge len 3: 0 4 1 truelight@0: // bridge len 4: 0 2 3 1 truelight@0: // bridge len 5: 0 2 5 3 1 truelight@0: // bridge len 6: 0 2 3 2 3 1 truelight@0: // bridge len 7: 0 2 3 4 2 3 1 tron@2639: // #0 - always as first, #1 - always as last (if len>1) truelight@0: // #2,#3 are to pair in order truelight@0: // for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0) truelight@0: tron@2639: if (i == 0) { // first tile truelight@193: m5 = 0; tron@2639: } else if (i == bridge_len - 1) { // last tile truelight@0: m5 = 1; tron@2639: } else if (i == odd_middle_part) { // we are on the middle of odd bridge: #5 on even pos, #4 on odd tron@2639: m5 = 5 - (i % 2); tron@2639: } else { truelight@0: // generate #2 and #3 in turns [i%2==0], after the middle of odd bridge truelight@193: // this sequence swaps [... XOR (i>odd_middle_part)], truelight@0: // for even bridges XOR does not apply as odd_middle_part==bridge_len tron@2639: m5 = 2 + ((i % 2 == 0) ^ (i > odd_middle_part)); truelight@0: } truelight@0: tron@2049: _m[ti.tile].m2 = (bridge_type << 4) | m5; tron@2150: SB(_m[ti.tile].m3, 4, 4, railtype); truelight@0: truelight@0: MarkTileDirtyByTile(ti.tile); truelight@0: } truelight@0: } truelight@0: tron@2639: SetSignalsOnBothDir(ti_start.tile, (direction & 1) ? 1 : 0); truelight@0: truelight@0: /* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST) truelight@0: It's unnecessary to execute this command every time for every bridge. So it is done only truelight@0: and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated truelight@0: */ truelight@193: if (!(flags & DC_QUERY_COST)) { celestar@2262: const Bridge *b = &_bridge[bridge_type]; celestar@2262: truelight@0: bridge_len += 2; // begin and end tiles/ramps truelight@0: truelight@2422: if (_current_player < MAX_PLAYERS && !_is_old_ai_player) truelight@0: bridge_len = CalcBridgeLenCostFactor(bridge_len); truelight@0: tron@3033: cost += (int64)bridge_len * _price.build_bridge * b->price >> 8; truelight@0: } truelight@0: truelight@0: return cost; truelight@0: } truelight@0: tron@1977: static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir) truelight@0: { tron@1977: TileIndexDiff delta = TileOffsByDir(dir); tron@3055: uint height; truelight@0: truelight@0: do { truelight@0: tile -= delta; tron@3055: height = GetTileZ(tile); tron@3056: } while (z < height); truelight@0: tron@3056: if (z == height && tron@3055: IsTileType(tile, MP_TUNNELBRIDGE) && tron@3055: GB(_m[tile].m5, 4, 4) == 0 && tron@3055: GB(_m[tile].m5, 0, 2) == dir) { truelight@0: _error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY; truelight@0: return false; truelight@0: } truelight@0: truelight@0: return true; truelight@0: } truelight@0: tron@1977: bool CheckTunnelInWay(TileIndex tile, int z) truelight@0: { truelight@0: return DoCheckTunnelInWay(tile,z,0) && truelight@0: DoCheckTunnelInWay(tile,z,1) && truelight@0: DoCheckTunnelInWay(tile,z,2) && truelight@0: DoCheckTunnelInWay(tile,z,3); truelight@0: } truelight@0: truelight@0: Darkvater@1782: /** Build Tunnel. Darkvater@1782: * @param x,y start tile coord of tunnel Darkvater@1784: * @param p1 railtype, 0x200 for road tunnel tron@2639: * @param p2 unused truelight@0: */ truelight@0: int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2) truelight@0: { tron@3063: TileIndexDiff delta; tron@3063: TileIndex start_tile; tron@3063: TileIndex end_tile; tron@3063: DiagDirection direction; tron@3063: uint start_tileh; tron@3063: uint end_tileh; tron@3063: uint start_z; tron@3063: uint end_z; tron@3063: int32 cost; tron@3063: int32 ret; truelight@0: tron@3063: _build_tunnel_endtile = 0; truelight@0: Darkvater@1784: if (p1 != 0x200 && !ValParamRailtype(p1)) return CMD_ERROR; Darkvater@1782: tron@3063: start_tile = TileVirtXY(x, y); tron@3063: start_tileh = GetTileSlope(start_tile, &start_z); truelight@0: tron@3063: switch (start_tileh) { tron@3063: case 3: direction = DIAGDIR_SW; break; tron@3063: case 6: direction = DIAGDIR_SE; break; tron@3063: case 9: direction = DIAGDIR_NW; break; tron@3063: case 12: direction = DIAGDIR_NE; break; tron@3063: default: return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL); tron@2639: } truelight@0: tron@3063: ret = DoCommandByTile(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); tron@3063: if (CmdFailed(ret)) return ret; tron@3063: cost = _price.build_tunnel + ret; truelight@0: tron@3063: delta = TileOffsByDir(direction); tron@3063: end_tile = start_tile; tron@3063: for (;;) { tron@3063: end_tile += delta; tron@3063: end_tileh = GetTileSlope(end_tile, &end_z); truelight@0: tron@3063: if (start_z == end_z) break; tron@3063: tron@3063: if (!_cheats.crossing_tunnels.value && !CheckTunnelInWay(end_tile, start_z)) { tron@3063: return CMD_ERROR; tron@3063: } tron@3063: tron@3063: cost += _price.build_tunnel; tron@3063: cost += cost >> 3; tron@3063: if (cost >= 400000000) cost = 400000000; truelight@0: } truelight@0: tron@3063: // if the command fails from here on we want the end tile to be highlighted tron@3063: _build_tunnel_endtile = end_tile; tron@3063: tron@3063: // slope of end tile must be complementary to the slope of the start tile tron@3063: if (end_tileh != (15 ^ start_tileh)) { tron@3063: ret = DoCommandByTile(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND); tron@3063: if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND); tron@3063: } else { tron@3063: ret = DoCommandByTile(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); tron@3063: if (CmdFailed(ret)) return ret; tron@3063: cost += ret; tron@3063: } tron@3063: cost += _price.build_tunnel; tron@3063: tron@3063: if (flags & DC_EXEC) { tron@3063: SetTileType(start_tile, MP_TUNNELBRIDGE); tron@3063: SetTileOwner(start_tile, _current_player); tron@3063: _m[start_tile].m3 = GB(p1, 0, 4); // rail type (if any) tron@3063: _m[start_tile].m5 = (GB(p1, 9, 1) << 2) | direction; // transport type and entrance direction tron@3063: tron@3063: SetTileType(end_tile, MP_TUNNELBRIDGE); tron@3063: SetTileOwner(end_tile, _current_player); tron@3063: _m[end_tile].m3 = GB(p1, 0, 4); // rail type (if any) tron@3063: _m[end_tile].m5 = (GB(p1, 9, 1) << 2) | (direction ^ 2); // transport type and entrance direction tron@3063: tron@3063: if (GB(p1, 9, 1) == 0) UpdateSignalsOnSegment(start_tile, direction << 1); tron@3063: } tron@3063: tron@3063: return cost; truelight@0: } truelight@0: tron@1430: TileIndex CheckTunnelBusy(TileIndex tile, uint *length) truelight@0: { tron@1335: uint z = GetTileZ(tile); tron@2049: byte m5 = _m[tile].m5; tron@900: int delta = TileOffsByDir(m5 & 3); tron@1430: uint len = 0; tron@1977: TileIndex starttile = tile; truelight@0: Vehicle *v; truelight@193: tron@1035: do { tron@1035: tile += delta; tron@1035: len++; tron@1035: } while ( tron@1035: !IsTileType(tile, MP_TUNNELBRIDGE) || tron@2493: GB(_m[tile].m5, 4, 4) != 0 || tron@2150: (_m[tile].m5 ^ 2) != m5 || tron@1035: GetTileZ(tile) != z tron@1035: ); truelight@0: tron@1430: v = FindVehicleBetween(starttile, tile, z); tron@1430: if (v != NULL) { tron@1430: _error_message = v->type == VEH_Train ? tron@1430: STR_5000_TRAIN_IN_TUNNEL : STR_5001_ROAD_VEHICLE_IN_TUNNEL; tron@1430: return INVALID_TILE; truelight@0: } truelight@193: tron@1430: if (length != NULL) *length = len; truelight@0: return tile; truelight@0: } truelight@0: tron@1977: static int32 DoClearTunnel(TileIndex tile, uint32 flags) truelight@0: { truelight@0: Town *t; Darkvater@1782: TileIndex endtile; tron@1430: uint length; Darkvater@1782: static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3}; truelight@0: truelight@0: SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); truelight@0: truelight@0: // in scenario editor you can always destroy tunnels truelight@0: if (_game_mode != GM_EDITOR && !CheckTileOwnership(tile)) { tron@1901: if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN)) truelight@0: return CMD_ERROR; truelight@0: } truelight@0: truelight@0: endtile = CheckTunnelBusy(tile, &length); tron@1430: if (endtile == INVALID_TILE) return CMD_ERROR; truelight@0: truelight@0: _build_tunnel_endtile = endtile; truelight@193: truelight@0: t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty truelight@0: // check if you're allowed to remove the tunnel owned by a town truelight@0: // removal allowal depends on difficulty settings tron@1901: if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { tron@2958: if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) { tron@534: SetDParam(0, t->index); truelight@0: return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); truelight@0: } truelight@0: } truelight@0: truelight@0: if (flags & DC_EXEC) { darkvater@38: // We first need to request the direction before calling DoClearSquare darkvater@38: // else the direction is always 0.. dah!! ;) tron@2493: byte tile_dir = GB(_m[tile].m5, 0, 2); tron@2493: byte endtile_dir = GB(_m[endtile].m5, 0, 2); peter1138@2870: peter1138@2870: // Adjust the town's player rating. Do this before removing the tile owner info. peter1138@2870: if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) peter1138@2870: ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); peter1138@2870: truelight@0: DoClearSquare(tile); truelight@0: DoClearSquare(endtile); darkvater@38: UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]); darkvater@38: UpdateSignalsOnSegment(endtile, _updsignals_tunnel_dir[endtile_dir]); truelight@0: } tron@2639: return _price.clear_tunnel * (length + 1); truelight@0: } truelight@0: tron@1977: static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile) truelight@0: { tron@2493: int direction = GB(_m[tile].m5, 0, 1); tron@1977: TileIndex start; truelight@0: truelight@0: // find start of bridge tron@2952: for (;;) { tron@2049: if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0x80) truelight@0: break; tron@1981: tile += direction ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); truelight@0: } truelight@0: truelight@0: start = tile; truelight@0: truelight@0: // find end of bridge tron@2952: for (;;) { tron@2049: if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xE0) == 0xA0) truelight@0: break; tron@1981: tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); truelight@0: } truelight@0: truelight@0: *endtile = tile; truelight@0: truelight@0: return start; truelight@0: } truelight@0: tron@1977: static int32 DoClearBridge(TileIndex tile, uint32 flags) truelight@0: { tron@1977: TileIndex endtile; truelight@0: Vehicle *v; truelight@0: Town *t; truelight@0: int direction; truelight@193: truelight@0: SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); truelight@0: tron@2493: direction = GB(_m[tile].m5, 0, 1); truelight@0: truelight@0: /* delete stuff under the middle part if there's a transport route there..? */ tron@2049: if ((_m[tile].m5 & 0xE0) == 0xE0) { truelight@0: int32 cost; truelight@0: truelight@0: // check if we own the tile below the bridge.. tron@1041: if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))) truelight@0: return CMD_ERROR; truelight@193: tron@2049: cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail; truelight@0: truelight@0: if (flags & DC_EXEC) { tron@2049: _m[tile].m5 = _m[tile].m5 & ~0x38; tron@1902: SetTileOwner(tile, OWNER_NONE); truelight@0: MarkTileDirtyByTile(tile); truelight@0: } truelight@0: return cost; truelight@193: truelight@0: /* delete canal under bridge */ tron@2049: } else if ((_m[tile].m5 & 0xC8) == 0xC8 && TilePixelHeight(tile) != 0) { truelight@0: int32 cost; truelight@193: truelight@0: // check for vehicles under bridge tron@2639: if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR; truelight@0: cost = _price.clear_water; truelight@0: if (flags & DC_EXEC) { tron@2049: _m[tile].m5 = _m[tile].m5 & ~0x38; tron@1902: SetTileOwner(tile, OWNER_NONE); truelight@0: MarkTileDirtyByTile(tile); truelight@0: } truelight@0: return cost; truelight@0: } truelight@0: truelight@0: tile = FindEdgesOfBridge(tile, &endtile); truelight@0: truelight@0: // floods, scenario editor can always destroy bridges truelight@0: if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) { tron@1901: if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN)) truelight@0: return CMD_ERROR; truelight@0: } truelight@0: tron@2639: if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) return CMD_ERROR; truelight@0: truelight@0: /* Make sure there's no vehicle on the bridge truelight@0: Omit tile and endtile, since these are already checked, thus solving the problem truelight@0: of bridges over water, or higher bridges, where z is not increased, eg level bridge truelight@0: */ tron@1981: tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); tron@1981: endtile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); darkvater@1082: /* Bridges on slopes might have their Z-value offset..correct this */ tron@2639: v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile)); tron@2639: if (v != NULL) { truelight@193: VehicleInTheWayErrMsg(v); truelight@0: return CMD_ERROR; truelight@0: } truelight@0: truelight@0: /* Put the tiles back to start/end position */ tron@1981: tile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); tron@1981: endtile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); truelight@0: truelight@193: truelight@0: t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty truelight@193: // check if you're allowed to remove the bridge owned by a town. truelight@0: // removal allowal depends on difficulty settings tron@1901: if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { tron@2958: if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) return CMD_ERROR; truelight@0: } truelight@0: truelight@0: if (flags & DC_EXEC) { truelight@0: byte m5; truelight@0: uint c = tile; truelight@0: uint16 new_data; truelight@0: celestar@1005: //checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until truelight@0: // you have a "Poor" (0) town rating tron@1901: if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) celestar@1005: ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); truelight@0: truelight@0: do { tron@2049: m5 = _m[c].m5; truelight@0: truelight@0: if (m5 & 0x40) { truelight@0: if (m5 & 0x20) { truelight@0: static const uint16 _new_data_table[] = {0x1002, 0x1001, 0x2005, 0x200A, 0, 0, 0, 0}; tron@2639: new_data = _new_data_table[((m5 & 0x18) >> 2) | (m5 & 1)]; truelight@0: } else { tron@2635: if (GB(m5, 3, 2) == 0) goto clear_it; tron@1091: new_data = (GetTileSlope(c, NULL) == 0) ? 0x6000 : 0x6001; truelight@0: } truelight@0: tron@1059: SetTileType(c, new_data >> 12); tron@2049: _m[c].m5 = (byte)new_data; tron@2049: _m[c].m2 = 0; tron@2049: _m[c].m4 &= 0x0F; truelight@0: truelight@0: MarkTileDirtyByTile(c); truelight@0: truelight@0: } else { truelight@0: clear_it:; truelight@0: DoClearSquare(c); truelight@0: } tron@1981: c += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); truelight@0: } while (c <= endtile); truelight@0: truelight@0: SetSignalsOnBothDir(tile, direction); truelight@0: SetSignalsOnBothDir(endtile, direction); truelight@0: } truelight@0: tron@2931: if (direction) { tron@2931: return (TileY(endtile) - TileY(tile) + 1) * _price.clear_bridge; tron@2931: } else { tron@2931: return (TileX(endtile) - TileX(tile) + 1) * _price.clear_bridge; tron@2931: } truelight@0: } truelight@0: tron@1977: static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags) tron@1977: { tron@2049: byte m5 = _m[tile].m5; truelight@0: truelight@0: if ((m5 & 0xF0) == 0) { tron@2639: if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST); truelight@0: return DoClearTunnel(tile, flags); truelight@0: } else if (m5 & 0x80) { tron@2639: if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); darkvater@1082: return DoClearBridge(tile, flags); tron@1109: } tron@1109: darkvater@1082: return CMD_ERROR; truelight@0: } truelight@0: tron@1977: int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec) truelight@0: { Darkvater@1782: TileIndex endtile; tron@1430: uint length; truelight@0: Vehicle *v; truelight@0: tron@2049: if ((_m[tile].m5 & 0xFC) == 0x00) { truelight@0: // railway tunnel truelight@0: if (!CheckTileOwnership(tile)) return CMD_ERROR; truelight@0: tron@2493: if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; truelight@193: truelight@0: endtile = CheckTunnelBusy(tile, &length); tron@1430: if (endtile == INVALID_TILE) return CMD_ERROR; truelight@0: truelight@0: if (exec) { tron@2493: SB(_m[tile].m3, 0, 4, totype); tron@2493: SB(_m[endtile].m3, 0, 4, totype); truelight@0: MarkTileDirtyByTile(tile); truelight@0: MarkTileDirtyByTile(endtile); truelight@0: } truelight@0: return (length + 1) * (_price.build_rail >> 1); tron@2049: } else if ((_m[tile].m5 & 0xF8) == 0xE0) { truelight@0: // bridge middle part with rail below truelight@0: // only check for train under bridge tron@1041: if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))) truelight@0: return CMD_ERROR; truelight@0: truelight@0: // tile is already of requested type? tron@2493: if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; truelight@0: // change type. truelight@0: if (exec) { tron@2493: SB(_m[tile].m3, 0, 4, totype); truelight@0: MarkTileDirtyByTile(tile); truelight@0: } truelight@0: return _price.build_rail >> 1; tron@2639: } else if ((_m[tile].m5 & 0xC6) == 0x80) { Darkvater@1782: TileIndex starttile; truelight@0: int32 cost; celestar@1073: uint z = TilePixelHeight(tile); celestar@1073: celestar@1073: z += 8; truelight@0: truelight@0: if (!CheckTileOwnership(tile)) return CMD_ERROR; truelight@0: truelight@0: // railway bridge truelight@0: starttile = tile = FindEdgesOfBridge(tile, &endtile); truelight@0: // Make sure there's no vehicle on the bridge tron@2639: v = FindVehicleBetween(tile, endtile, z); tron@2639: if (v != NULL) { truelight@193: VehicleInTheWayErrMsg(v); truelight@0: return CMD_ERROR; truelight@0: } truelight@0: celestar@1073: if (!EnsureNoVehicle(starttile) || !EnsureNoVehicle(endtile)) { celestar@1073: _error_message = STR_8803_TRAIN_IN_THE_WAY; celestar@1073: return CMD_ERROR; celestar@1073: } celestar@1073: tron@2493: if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; truelight@0: cost = 0; truelight@0: do { truelight@0: if (exec) { truelight@0: if (tile == starttile || tile == endtile) { tron@2493: SB(_m[tile].m3, 0, 4, totype); truelight@0: } else { tron@2493: SB(_m[tile].m3, 4, 4, totype); truelight@0: } truelight@0: MarkTileDirtyByTile(tile); truelight@0: } tron@2639: cost += _price.build_rail >> 1; tron@2493: tile += GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); truelight@0: } while (tile <= endtile); truelight@0: truelight@0: return cost; truelight@193: } else truelight@0: return CMD_ERROR; truelight@0: } truelight@0: truelight@0: truelight@0: // fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile. tron@1095: static uint GetBridgeHeight(const TileInfo *ti) truelight@0: { tron@1981: TileIndexDiff delta; tron@1192: TileIndex tile = ti->tile; truelight@0: truelight@0: // find the end tile of the bridge. tron@2493: delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); truelight@0: do { tron@2049: assert((_m[tile].m5 & 0xC0) == 0xC0); // bridge and middle part truelight@0: tile += delta; tron@2049: } while (_m[tile].m5 & 0x40); // while bridge middle parts truelight@0: tron@1192: /* Return the height there (the height of the NORTH CORNER) tron@1192: * If the end of the bridge is on a tileh 7 (all raised, except north corner), tron@1192: * the z coordinate is 1 height level too low. Compensate for that */ tron@1192: return TilePixelHeight(tile) + (GetTileSlope(tile, NULL) == 7 ? 8 : 0); truelight@0: } truelight@0: truelight@0: static const byte _bridge_foundations[2][16] = { truelight@0: // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 truelight@0: {1,16,18,3,20,5,0,7,22,0,10,11,12,13,14}, truelight@0: {1,15,17,0,19,5,6,7,21,9,10,11, 0,13,14}, truelight@0: }; truelight@0: truelight@0: extern const byte _road_sloped_sprites[14]; truelight@0: Darkvater@2436: static void DrawBridgePillars(const TileInfo *ti, int x, int y, int z) truelight@0: { celestar@2536: const PalSpriteID *b; celestar@2536: PalSpriteID image; truelight@0: int piece; truelight@0: celestar@2262: b = _bridge_poles_table[GetBridgeType(ti->tile)]; truelight@0: truelight@0: // Draw first piece truelight@0: // (necessary for cantilever bridges) celestar@2262: tron@2642: image = b[12 + GB(ti->map5, 0, 1)]; celestar@2262: piece = GetBridgePiece(ti->tile); celestar@2262: tron@333: if (image != 0 && piece != 0) { celestar@2148: if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); tron@333: DrawGroundSpriteAt(image, x, y, z); tron@333: } truelight@0: tron@2642: image = b[GB(ti->map5, 0, 1) * 6 + piece]; truelight@0: truelight@0: if (image != 0) { truelight@0: int back_height, front_height, i=z; truelight@0: const byte *p; truelight@0: truelight@0: static const byte _tileh_bits[4][8] = { truelight@0: {2,1,8,4, 16,11,0,9}, truelight@0: {1,8,4,2, 11,16,9,0}, truelight@0: {4,8,1,2, 16,11,0,9}, truelight@0: {2,4,8,1, 11,16,9,0}, truelight@0: }; truelight@0: celestar@2148: if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); tron@333: truelight@0: p = _tileh_bits[(image & 1) * 2 + (ti->map5&0x01)]; truelight@0: front_height = ti->z + ((ti->tileh & p[0])?8:0); truelight@0: back_height = ti->z + ((ti->tileh & p[1])?8:0); celestar@2262: celestar@2085: if (IsSteepTileh(ti->tileh)) { truelight@0: if (!(ti->tileh & p[2])) front_height += 8; truelight@0: if (!(ti->tileh & p[3])) back_height += 8; truelight@0: } truelight@0: tron@2952: for (; z >= front_height || z >= back_height; z = z - 8) { tron@2952: if (z >= front_height) { tron@2952: // front facing pillar tron@2952: AddSortableSpriteToDraw(image, x,y, p[4], p[5], 0x28, z); tron@2952: } tron@2952: if (z >= back_height && z < i - 8) { tron@2952: // back facing pillar tron@2952: AddSortableSpriteToDraw(image, x - p[6], y - p[7], p[4], p[5], 0x28, z); tron@2952: } truelight@0: } truelight@0: } truelight@0: } truelight@0: tron@2639: uint GetBridgeFoundation(uint tileh, byte direction) tron@2639: { truelight@0: int i; truelight@0: // normal level sloped building (7, 11, 13, 14) tron@3017: if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) return tileh; truelight@0: truelight@0: // inclined sloped building tron@3017: if (( tron@3017: (i = 0, tileh == 1) || tron@3017: (i += 2, tileh == 2) || tron@3017: (i += 2, tileh == 4) || tron@3017: (i += 2, tileh == 8) tron@3017: ) && ( tron@3017: direction == 0 || tron@3017: (i++, direction == 1) tron@3017: )) { truelight@0: return i + 15; tron@3017: } truelight@0: truelight@0: return 0; truelight@0: } truelight@0: celestar@2536: /** celestar@2536: * Draws a tunnel of bridge tile. celestar@2536: * For tunnels, this is rather simple, as you only needa draw the entrance. celestar@2536: * Bridges are a bit more complex. base_offset is where the sprite selection comes into play celestar@2536: * and it works a bit like a bitmask.

For bridge heads: celestar@2536: *

celestar@2536: * For middle parts: celestar@2536: * celestar@2536: * Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3 celestar@2536: */ truelight@0: static void DrawTile_TunnelBridge(TileInfo *ti) truelight@0: { truelight@0: uint32 image; celestar@2536: const PalSpriteID *b; tron@2049: bool ice = _m[ti->tile].m4 & 0x80; truelight@193: truelight@193: // draw tunnel? tron@2150: if ((ti->map5 & 0xF0) == 0) { tron@2511: if (GB(ti->map5, 2, 2) == 0) { /* Rail tunnel? */ tron@2511: image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel; tron@2511: } else { tron@2511: image = SPR_TUNNEL_ENTRY_REAR_ROAD; tron@2511: } truelight@0: tron@2511: if (ice) image += 32; truelight@0: tron@2140: image += GB(ti->map5, 0, 2) * 2; truelight@0: DrawGroundSprite(image); truelight@0: truelight@0: AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z); truelight@0: // draw bridge? tron@2644: } else if (ti->map5 & 0x80) { celestar@2536: RailType rt; celestar@2536: int base_offset; truelight@0: celestar@2536: if (HASBIT(ti->map5, 1)) { /* This is a road bridge */ celestar@2536: base_offset = 8; celestar@2536: } else { /* Rail bridge */ celestar@2536: if (HASBIT(ti->map5, 6)) { /* The bits we need depend on the fact whether it is a bridge head or not */ celestar@2536: rt = GB(_m[ti->tile].m3, 4, 3); celestar@2536: } else { celestar@2536: rt = GB(_m[ti->tile].m3, 0, 3); celestar@2536: } truelight@0: celestar@2536: base_offset = GetRailTypeInfo(rt)->bridge_offset; celestar@2536: assert(base_offset != 8); /* This one is used for roads */ celestar@2536: } celestar@2536: celestar@2536: /* as the lower 3 bits are used for other stuff, make sure they are clear */ celestar@2536: assert( (base_offset & 0x07) == 0x00); truelight@0: truelight@0: if (!(ti->map5 & 0x40)) { // bridge ramps truelight@0: if (!(BRIDGE_NO_FOUNDATION & (1 << ti->tileh))) { // no foundations for 0, 3, 6, 9, 12 truelight@0: int f = GetBridgeFoundation(ti->tileh, ti->map5 & 0x1); // pass direction truelight@0: if (f) DrawFoundation(ti, f); truelight@193: truelight@0: // default sloped sprites.. tron@2517: if (ti->tileh != 0) image = SPR_RAIL_TRACK_Y + _track_sloped_sprites[ti->tileh - 1]; truelight@0: } truelight@0: celestar@2536: /* Cope for the direction of the bridge */ celestar@2536: if (HASBIT(ti->map5, 0)) base_offset++; truelight@193: celestar@2536: if (ti->map5 & 0x20) base_offset += 2; // which side celestar@2536: if (ti->tileh == 0) base_offset += 4; // sloped bridge head celestar@2536: celestar@2536: /* Table number 6 always refers to the bridge heads for any bridge type */ celestar@2536: image = GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset]; truelight@0: truelight@0: if (!ice) { truelight@0: DrawClearLandTile(ti, 3); truelight@0: } else { tron@2517: DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh]); truelight@0: } truelight@0: truelight@0: // draw ramp celestar@2148: if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); truelight@0: AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z); truelight@0: } else { truelight@0: // bridge middle part. truelight@0: uint z; truelight@0: int x,y; truelight@0: tron@2140: image = GB(ti->map5, 3, 2); // type of stuff under bridge (only defined for 0,1) celestar@2536: /** @todo So why do we even WASTE that one bit?! (map5, bit 4) */ truelight@0: assert(image <= 1); truelight@0: truelight@0: if (!(ti->map5 & 0x20)) { truelight@0: // draw land under bridge celestar@2254: if (ice) image += 2; tron@1091: tron@3017: if (image != 1 || ti->tileh == 0) { tron@1091: DrawGroundSprite(_bridge_land_below[image] + _tileh_to_sprite[ti->tileh]); tron@3017: } else { tron@1091: DrawGroundSprite(_water_shore_sprites[ti->tileh]); tron@3017: } truelight@0: truelight@0: // draw canal water? truelight@0: if (ti->map5 & 8 && ti->z != 0) DrawCanalWater(ti->tile); truelight@0: } else { truelight@0: // draw transport route under bridge truelight@193: truelight@0: // draw foundation? truelight@0: if (ti->tileh) { truelight@0: int f = _bridge_foundations[ti->map5&1][ti->tileh]; truelight@0: if (f) DrawFoundation(ti, f); truelight@0: } truelight@0: truelight@0: if (!(image&1)) { tron@2493: const RailtypeInfo *rti = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4)); truelight@0: // railway tron@2535: image = SPR_RAIL_TRACK_Y + (ti->map5 & 1); tron@2535: if (ti->tileh != 0) image = SPR_RAIL_TRACK_Y + _track_sloped_sprites[ti->tileh - 1]; celestar@2254: image += rti->total_offset; celestar@2254: if (ice) image += rti->snow_offset; truelight@0: } else { truelight@0: // road tron@2535: image = SPR_ROAD_Y + (ti->map5 & 1); truelight@0: if (ti->tileh != 0) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; celestar@2536: if (ice) image += 19; truelight@0: } truelight@0: DrawGroundSprite(image); truelight@0: } celestar@2536: celestar@2536: /* Cope for the direction of the bridge */ celestar@2536: if (HASBIT(ti->map5, 0)) base_offset += 4; celestar@2536: celestar@2536: /* base_offset needs to be 0 due to the structure of the sprite table see table/bridge_land.h */ celestar@2536: assert( (base_offset & 0x03) == 0x00); truelight@0: // get bridge sprites celestar@2536: b = GetBridgeSpriteTable(GetBridgeType(ti->tile), GetBridgePiece(ti->tile)) + base_offset; truelight@0: truelight@0: z = GetBridgeHeight(ti) + 5; truelight@193: celestar@2536: // draw rail or road component truelight@0: image = b[0]; celestar@2148: if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); truelight@0: AddSortableSpriteToDraw(image, ti->x, ti->y, (ti->map5&1)?11:16, (ti->map5&1)?16:11, 1, z); truelight@0: truelight@0: x = ti->x; truelight@0: y = ti->y; truelight@0: image = b[1]; celestar@2148: if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); truelight@0: celestar@2536: // draw roof, the component of the bridge which is logically between the vehicle and the camera tron@3017: if (ti->map5 & 1) { truelight@0: x += 12; celestar@2187: if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 1, 16, 0x28, z); truelight@0: } else { truelight@0: y += 12; celestar@2187: if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x,y, 16, 1, 0x28, z); truelight@0: } truelight@193: tron@3017: if (ti->z + 5 == z) { truelight@0: // draw poles below for small bridges truelight@0: image = b[2]; tron@3017: if (image != 0) { celestar@2148: if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); truelight@0: DrawGroundSpriteAt(image, x, y, z); truelight@0: } truelight@0: } else if (_patches.bridge_pillars) { truelight@0: // draw pillars below for high bridges truelight@0: DrawBridgePillars(ti, x, y, z); truelight@0: } truelight@0: } truelight@0: } truelight@0: } truelight@0: tron@2537: static uint GetSlopeZ_TunnelBridge(const TileInfo* ti) tron@2537: { truelight@0: uint z = ti->z; truelight@0: uint x = ti->x & 0xF; truelight@0: uint y = ti->y & 0xF; tron@2537: uint tileh = ti->tileh; truelight@0: truelight@0: // swap directions if Y tunnel/bridge to let the code handle the X case only. hackykid@1884: if (ti->map5 & 1) uintswap(x,y); truelight@0: truelight@0: // to the side of the tunnel/bridge? truelight@0: if (IS_INT_INSIDE(y, 5, 10+1)) { truelight@0: // tunnel? tron@2639: if ((ti->map5 & 0xF0) == 0) return z; truelight@0: truelight@193: // bridge? tron@2639: if (ti->map5 & 0x80) { truelight@0: // bridge ending? truelight@0: if (!(ti->map5 & 0x40)) { tron@2537: if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) // 7, 11, 13, 14 truelight@0: z += 8; truelight@0: truelight@0: // no ramp for bridge ending tron@2537: if ((BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << tileh) || BRIDGE_NO_FOUNDATION & (1 << tileh)) && tileh != 0) { truelight@0: return z + 8; truelight@0: } else if (!(ti->map5 & 0x20)) { // northern / southern ending truelight@0: // ramp tron@3017: return z + (x >> 1) + 1; truelight@0: } else { truelight@0: // ramp in opposite dir tron@3017: return z + ((x ^ 0xF) >> 1); truelight@0: } truelight@193: truelight@0: // bridge middle part truelight@0: } else { truelight@0: // build on slopes? tron@2537: if (tileh != 0) z += 8; truelight@0: truelight@0: // keep the same elevation because we're on the bridge? tron@2639: if (_get_z_hint >= z + 8) return _get_z_hint; truelight@193: truelight@0: // actually on the bridge, but not yet in the shared area. tron@2639: if (!IS_INT_INSIDE(x, 5, 10 + 1)) return GetBridgeHeight(ti) + 8; truelight@0: truelight@0: // in the shared area, assume that we're below the bridge, cause otherwise the hint would've caught it. truelight@0: // if rail or road below then it means it's possibly build on slope below the bridge. truelight@0: if (ti->map5 & 0x20) { tron@2537: uint f = _bridge_foundations[ti->map5 & 1][tileh]; truelight@0: // make sure that the slope is not inclined foundation truelight@0: if (IS_BYTE_INSIDE(f, 1, 15)) return z; truelight@193: Darkvater@2436: // change foundation type? XXX - should be const; accessor function! tron@2537: if (f != 0) tileh = _inclined_tileh[f - 15]; truelight@0: } truelight@193: truelight@0: // no transport route, fallback to default truelight@0: } truelight@0: } truelight@0: } else { truelight@0: // if it's a bridge middle with transport route below, then we need to compensate for build on slopes tron@2639: if ((ti->map5 & (0x80 | 0x40 | 0x20)) == (0x80 | 0x40 | 0x20)) { truelight@0: uint f; tron@2537: if (tileh != 0) z += 8; tron@2639: f = _bridge_foundations[ti->map5 & 1][tileh]; truelight@0: if (IS_BYTE_INSIDE(f, 1, 15)) return z; tron@2537: if (f != 0) tileh = _inclined_tileh[f - 15]; truelight@0: } truelight@0: } truelight@0: truelight@0: // default case tron@2639: return GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh) + ti->z; truelight@0: } truelight@0: tron@2639: static uint GetSlopeTileh_TunnelBridge(const TileInfo* ti) tron@2639: { dominik@39: // not accurate, but good enough for slope graphics drawing dominik@39: return 0; dominik@39: } dominik@39: dominik@39: tron@1977: static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac) truelight@0: { truelight@0: /* not used */ truelight@0: } truelight@0: truelight@0: static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = { truelight@0: STR_501F_WOODEN_RAIL_BRIDGE, truelight@0: STR_5020_CONCRETE_RAIL_BRIDGE, truelight@0: STR_501C_STEEL_GIRDER_RAIL_BRIDGE, truelight@0: STR_501E_REINFORCED_CONCRETE_SUSPENSION, truelight@0: STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, truelight@0: STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, truelight@0: STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, truelight@0: STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, truelight@0: STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, truelight@0: STR_501C_STEEL_GIRDER_RAIL_BRIDGE, truelight@0: STR_5027_TUBULAR_RAIL_BRIDGE, truelight@0: STR_5027_TUBULAR_RAIL_BRIDGE, truelight@0: STR_5027_TUBULAR_RAIL_BRIDGE, truelight@0: 0,0,0, truelight@0: truelight@0: STR_5025_WOODEN_ROAD_BRIDGE, truelight@0: STR_5026_CONCRETE_ROAD_BRIDGE, truelight@0: STR_5022_STEEL_GIRDER_ROAD_BRIDGE, truelight@0: STR_5024_REINFORCED_CONCRETE_SUSPENSION, truelight@0: STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, truelight@0: STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, truelight@0: STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, truelight@0: STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, truelight@0: STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, truelight@0: STR_5022_STEEL_GIRDER_ROAD_BRIDGE, truelight@0: STR_5028_TUBULAR_ROAD_BRIDGE, truelight@0: STR_5028_TUBULAR_ROAD_BRIDGE, truelight@0: STR_5028_TUBULAR_ROAD_BRIDGE, truelight@0: 0,0,0, truelight@0: }; truelight@0: tron@1977: static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td) truelight@0: { tron@2049: if ((_m[tile].m5 & 0x80) == 0) { tron@2260: td->str = tron@2260: (GB(_m[tile].m5, 2, 2) == 0) ? STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL; truelight@0: } else { tron@2140: td->str = _bridge_tile_str[GB(_m[tile].m5, 1, 2) << 4 | GB(_m[tile].m2, 4, 4)]; truelight@0: truelight@0: /* scan to the end of the bridge, that's where the owner is stored */ tron@2049: if (_m[tile].m5 & 0x40) { tron@2493: TileIndexDiff delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); tron@1981: tron@2049: do tile += delta; while (_m[tile].m5 & 0x40); truelight@0: } truelight@0: } tron@1901: td->owner = GetTileOwner(tile); truelight@0: } truelight@0: truelight@0: tron@1977: static void AnimateTile_TunnelBridge(TileIndex tile) truelight@0: { truelight@0: /* not used */ truelight@0: } truelight@0: tron@1977: static void TileLoop_TunnelBridge(TileIndex tile) truelight@0: { tron@3017: switch (_opt.landscape) { tron@3017: case LT_HILLY: tron@3017: if (GetTileZ(tile) > _opt.snow_line) { tron@3017: if (!(_m[tile].m4 & 0x80)) { tron@3017: _m[tile].m4 |= 0x80; tron@3017: MarkTileDirtyByTile(tile); tron@3017: } tron@3017: } else { tron@3017: if (_m[tile].m4 & 0x80) { tron@3017: _m[tile].m4 &= ~0x80; tron@3017: MarkTileDirtyByTile(tile); tron@3017: } tron@3017: } tron@3017: break; tron@3017: tron@3017: case LT_DESERT: tron@3017: if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) { tron@2049: _m[tile].m4 |= 0x80; truelight@0: MarkTileDirtyByTile(tile); truelight@0: } tron@3017: break; truelight@0: } truelight@0: truelight@0: // if it's a bridge with water below, call tileloop_water on it. tron@2049: if ((_m[tile].m5 & 0xF8) == 0xC8) TileLoop_Water(tile); truelight@0: } truelight@0: tron@1977: static void ClickTile_TunnelBridge(TileIndex tile) truelight@0: { truelight@0: /* not used */ truelight@0: } truelight@0: truelight@0: tron@1977: static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode) truelight@0: { truelight@0: uint32 result; tron@2049: byte m5 = _m[tile].m5; truelight@0: truelight@0: if ((m5 & 0xF0) == 0) { truelight@159: /* This is a tunnel */ tron@2635: if (GB(m5, 2, 2) == mode) { truelight@159: /* Tranport in the tunnel is compatible */ truelight@0: return m5&1 ? 0x202 : 0x101; truelight@0: } truelight@0: } else if (m5 & 0x80) { truelight@159: /* This is a bridge */ truelight@0: result = 0; tron@2635: if (GB(m5, 1, 2) == mode) { truelight@159: /* Transport over the bridge is compatible */ tron@2639: result = m5 & 1 ? 0x202 : 0x101; truelight@0: } truelight@0: if (m5 & 0x40) { truelight@159: /* Bridge middle part */ truelight@159: if (!(m5 & 0x20)) { truelight@159: /* Clear ground or water underneath */ tron@2639: if ((m5 & 0x18) != 8) { truelight@159: /* Clear ground */ truelight@0: return result; tron@2639: } else { tron@2639: if (mode != TRANSPORT_WATER) return result; tron@2639: } truelight@159: } else { truelight@159: /* Transport underneath */ tron@2639: if (GB(m5, 3, 2) != mode) { truelight@159: /* Incompatible transport underneath */ truelight@159: return result; tron@2639: } truelight@0: } truelight@159: /* If we've not returned yet, there is a compatible truelight@159: * transport or water beneath, so we can add it to truelight@159: * result */ truelight@159: /* Why is this xor'd ? Can't it just be or'd? */ tron@2639: result ^= m5 & 1 ? 0x101 : 0x202; truelight@0: } truelight@0: return result; truelight@159: } else { truelight@159: assert(0); /* This should never occur */ truelight@0: } truelight@0: return 0; truelight@0: } truelight@0: Darkvater@2436: static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player) truelight@0: { tron@1901: if (!IsTileOwner(tile, old_player)) return; truelight@193: tron@2502: if (new_player != OWNER_SPECTATOR) { tron@1902: SetTileOwner(tile, new_player); truelight@0: } else { tron@2639: if ((_m[tile].m5 & 0xC0) == 0xC0) { truelight@0: // the stuff BELOW the middle part is owned by the deleted player. tron@2049: if (!(_m[tile].m5 & (1 << 4 | 1 << 3))) { truelight@0: // convert railway into grass. tron@2049: _m[tile].m5 &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore.. truelight@0: } else { truelight@0: // for road, change the owner of the road to local authority tron@1902: SetTileOwner(tile, OWNER_NONE); truelight@0: } truelight@0: } else { truelight@0: DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: static const byte _tunnel_fractcoord_1[4] = {0x8E,0x18,0x81,0xE8}; truelight@0: static const byte _tunnel_fractcoord_2[4] = {0x81,0x98,0x87,0x38}; truelight@0: static const byte _tunnel_fractcoord_3[4] = {0x82,0x88,0x86,0x48}; truelight@0: static const byte _exit_tunnel_track[4] = {1,2,1,2}; truelight@0: truelight@0: static const byte _road_exit_tunnel_state[4] = {8, 9, 0, 1}; truelight@0: static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4}; truelight@0: truelight@0: static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29}; truelight@0: static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25}; truelight@0: static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45}; truelight@0: static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49}; truelight@0: tron@1977: static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) truelight@0: { truelight@0: int dir, vdir; truelight@0: tron@2493: if (GB(_m[tile].m5, 4, 4) == 0) { tron@2989: int z = GetSlopeZ(x, y) - v->z_pos; tron@2989: byte fc; tron@2989: tron@2951: if (myabs(z) > 2) return 8; truelight@0: truelight@0: if (v->type == VEH_Train) { tron@2951: fc = (x & 0xF) + (y << 4); truelight@193: tron@2493: dir = GB(_m[tile].m5, 0, 2); truelight@0: vdir = v->direction >> 1; truelight@0: truelight@0: if (v->u.rail.track != 0x40 && dir == vdir) { bjarni@2676: if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) { truelight@0: if (v->spritenum < 4) tron@541: SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); truelight@0: return 0; truelight@0: } truelight@0: if (fc == _tunnel_fractcoord_2[dir]) { truelight@0: v->tile = tile; truelight@0: v->u.rail.track = 0x40; truelight@0: v->vehstatus |= VS_HIDDEN; truelight@0: return 4; truelight@0: } truelight@0: } truelight@0: truelight@0: if (dir == (vdir^2) && fc == _tunnel_fractcoord_3[dir] && z == 0) { darkvater@22: /* We're at the tunnel exit ?? */ truelight@0: v->tile = tile; truelight@0: v->u.rail.track = _exit_tunnel_track[dir]; matthijs@1330: assert(v->u.rail.track); truelight@0: v->vehstatus &= ~VS_HIDDEN; truelight@0: return 4; truelight@0: } truelight@0: } else if (v->type == VEH_Road) { tron@2951: fc = (x & 0xF) + (y << 4); tron@2493: dir = GB(_m[tile].m5, 0, 2); truelight@0: vdir = v->direction >> 1; truelight@0: truelight@0: // Enter tunnel? truelight@0: if (v->u.road.state != 0xFF && dir == vdir) { truelight@0: if (fc == _tunnel_fractcoord_4[dir] || truelight@0: fc == _tunnel_fractcoord_5[dir]) { truelight@0: v->tile = tile; truelight@0: v->u.road.state = 0xFF; truelight@193: v->vehstatus |= VS_HIDDEN; truelight@0: return 4; truelight@0: } else { truelight@0: return 0; truelight@0: } truelight@0: } truelight@0: tron@2951: if (dir == (vdir ^ 2) && ( tron@2951: /* We're at the tunnel exit ?? */ tron@2951: fc == _tunnel_fractcoord_6[dir] || tron@2951: fc == _tunnel_fractcoord_7[dir] tron@2951: ) && truelight@0: z == 0) { truelight@0: v->tile = tile; truelight@0: v->u.road.state = _road_exit_tunnel_state[dir]; truelight@0: v->u.road.frame = _road_exit_tunnel_frame[dir]; truelight@0: v->vehstatus &= ~VS_HIDDEN; truelight@0: return 4; truelight@0: } truelight@0: } tron@2049: } else if (_m[tile].m5 & 0x80) { bjarni@2676: if (v->type == VEH_Road || (v->type == VEH_Train && IsFrontEngine(v))) { tron@1335: uint h; tron@1335: tron@3017: // Compensate for possible foundation tron@3017: if (GetTileSlope(tile, &h) != 0) h += 8; tron@2049: if (!(_m[tile].m5 & 0x40) || // start/end tile of bridge tron@334: myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge truelight@0: /* modify speed of vehicle */ celestar@2262: uint16 spd = _bridge[GetBridgeType(tile)].speed; tron@2639: if (v->type == VEH_Road) spd *= 2; tron@3017: if (v->cur_speed > spd) v->cur_speed = spd; truelight@0: } truelight@0: } truelight@0: } truelight@0: return 0; truelight@0: } truelight@0: tron@1587: TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v) truelight@0: { tron@1587: TileIndex tile; tron@1981: TileIndexDiff delta = (v->direction & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); tron@1587: byte z = v->z_pos; truelight@0: tron@1587: for (tile = v->tile;; tile += delta) { tron@2493: if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0 && tron@1587: GetTileZ(tile) == z) truelight@0: break; truelight@0: } truelight@0: return tile; truelight@0: } truelight@0: truelight@0: const TileTypeProcs _tile_type_tunnelbridge_procs = { truelight@0: DrawTile_TunnelBridge, /* draw_tile_proc */ truelight@0: GetSlopeZ_TunnelBridge, /* get_slope_z_proc */ truelight@0: ClearTile_TunnelBridge, /* clear_tile_proc */ truelight@0: GetAcceptedCargo_TunnelBridge, /* get_accepted_cargo_proc */ truelight@0: GetTileDesc_TunnelBridge, /* get_tile_desc_proc */ truelight@0: GetTileTrackStatus_TunnelBridge,/* get_tile_track_status_proc */ truelight@0: ClickTile_TunnelBridge, /* click_tile_proc */ truelight@0: AnimateTile_TunnelBridge, /* animate_tile_proc */ truelight@0: TileLoop_TunnelBridge, /* tile_loop_clear */ truelight@0: ChangeTileOwner_TunnelBridge, /* change_tile_owner_clear */ truelight@0: NULL, /* get_produced_cargo_proc */ truelight@0: VehicleEnter_TunnelBridge, /* vehicle_enter_tile_proc */ truelight@0: NULL, /* vehicle_leave_tile_proc */ dominik@39: GetSlopeTileh_TunnelBridge, /* get_slope_tileh_proc */ truelight@0: };