tron@2186: /* $Id$ */ tron@2186: belugas@6443: /** @file tunnelbridge_cmd.cpp 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@3189: #include "bridge_map.h" tron@3187: #include "rail_map.h" tron@3144: #include "road_map.h" tron@1363: #include "table/sprites.h" tron@507: #include "table/strings.h" tron@2163: #include "functions.h" tron@679: #include "map.h" maedhros@6669: #include "landscape.h" tron@1209: #include "tile.h" tron@3154: #include "tunnel_map.h" celestar@5573: #include "unmovable_map.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" tron@3187: #include "water_map.h" KUDr@3900: #include "yapf/yapf.h" rubidium@4261: #include "date.h" peter1138@4656: #include "newgrf_sound.h" truelight@0: ludde@2261: #include "table/bridge_land.h" ludde@2261: peter1138@2478: const Bridge orig_bridge[] = { celestar@2262: /* rubidium@4293: year of availablity rubidium@4293: | minimum length rubidium@4293: | | maximum length rubidium@4293: | | | price rubidium@4293: | | | | maximum speed rubidium@4293: | | | | | sprite to use in GUI string with description rubidium@4293: | | | | | | | */ peter1138@5919: { 0, 0, 16, 80, 32, 0xA24, PAL_NONE , STR_5012_WOODEN , NULL, 0 }, peter1138@5919: { 0, 0, 2, 112, 48, 0xA26, PALETTE_TO_STRUCT_RED , STR_5013_CONCRETE , NULL, 0 }, peter1138@5919: { 1930, 0, 5, 144, 64, 0xA25, PAL_NONE , STR_500F_GIRDER_STEEL , NULL, 0 }, peter1138@5919: { 0, 2, 10, 168, 80, 0xA22, PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 }, peter1138@5919: { 1930, 3, 16, 185, 96, 0xA22, PAL_NONE , STR_500E_SUSPENSION_STEEL , NULL, 0 }, peter1138@5919: { 1930, 3, 16, 192, 112, 0xA22, PALETTE_TO_STRUCT_YELLOW , STR_500E_SUSPENSION_STEEL , NULL, 0 }, peter1138@5919: { 1930, 3, 7, 224, 160, 0xA23, PAL_NONE , STR_5010_CANTILEVER_STEEL , NULL, 0 }, peter1138@5919: { 1930, 3, 8, 232, 208, 0xA23, PALETTE_TO_STRUCT_BROWN , STR_5010_CANTILEVER_STEEL , NULL, 0 }, peter1138@5919: { 1930, 3, 9, 248, 240, 0xA23, PALETTE_TO_STRUCT_RED , STR_5010_CANTILEVER_STEEL , NULL, 0 }, peter1138@5919: { 1930, 0, 2, 240, 256, 0xA27, PAL_NONE , STR_500F_GIRDER_STEEL , NULL, 0 }, peter1138@5919: { 1995, 2, 16, 255, 320, 0xA28, PAL_NONE , STR_5014_TUBULAR_STEEL , NULL, 0 }, peter1138@5919: { 2005, 2, 32, 380, 512, 0xA28, PALETTE_TO_STRUCT_YELLOW , STR_5014_TUBULAR_STEEL , NULL, 0 }, peter1138@5919: { 2010, 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: richk@6719: /** calculate the price factor for building a long bridge. richk@6719: * 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, richk@6719: */ 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: tron@3636: #define M(x) (1 << (x)) rubidium@6574: enum BridgeFoundation { richk@6719: /* foundation, whole tile is leveled up --> 3 corners raised */ tron@3636: BRIDGE_FULL_LEVELED_FOUNDATION = M(SLOPE_WSE) | M(SLOPE_NWS) | M(SLOPE_ENW) | M(SLOPE_SEN), richk@6719: /* foundation, tile is partly leveled up --> 1 corner raised */ tron@3636: BRIDGE_PARTLY_LEVELED_FOUNDATION = M(SLOPE_W) | M(SLOPE_S) | M(SLOPE_E) | M(SLOPE_N), richk@6719: /* no foundations (X,Y direction) */ tron@3636: BRIDGE_NO_FOUNDATION = M(SLOPE_FLAT) | M(SLOPE_SW) | M(SLOPE_SE) | M(SLOPE_NW) | M(SLOPE_NE), tron@3636: BRIDGE_HORZ_RAMP = (BRIDGE_PARTLY_LEVELED_FOUNDATION | BRIDGE_NO_FOUNDATION) & ~M(SLOPE_FLAT) rubidium@6574: }; tron@3636: #undef M 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: Darkvater@3556: static inline byte GetBridgeFlags(int index) { return _bridge[index].flags;} celestar@2262: truelight@0: tron@4239: /** Check the slope at the bridge ramps in three easy steps: tron@4239: * - valid slopes without foundation tron@4239: * - valid slopes with foundation tron@4239: * - rest is invalid tron@4239: */ tron@4239: #define M(x) (1 << (x)) richk@6720: static CommandCost CheckBridgeSlopeNorth(Axis axis, Slope tileh) tron@4239: { tron@4239: uint32 valid; truelight@0: tron@4239: valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW)); richk@6720: if (HASBIT(valid, tileh)) return CommandCost(); truelight@0: tron@4239: valid = tron@4246: BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) | M(SLOPE_STEEP_N) | tron@4246: (axis == AXIS_X ? M(SLOPE_E) | M(SLOPE_STEEP_E) : M(SLOPE_W) | M(SLOPE_STEEP_W)); richk@6720: if (HASBIT(valid, tileh)) return CommandCost(_price.terraform); tron@2639: truelight@0: return CMD_ERROR; truelight@0: } truelight@0: richk@6720: static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope tileh) tron@4239: { tron@4239: uint32 valid; tron@4239: tron@4239: valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE)); richk@6720: if (HASBIT(valid, tileh)) return CommandCost(); tron@4239: tron@4239: valid = tron@4246: BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) | M(SLOPE_STEEP_S) | tron@4246: (axis == AXIS_X ? M(SLOPE_W) | M(SLOPE_STEEP_W) : M(SLOPE_E) | M(SLOPE_STEEP_E)); richk@6720: if (HASBIT(valid, tileh)) return CommandCost(_price.terraform); tron@4239: tron@4239: return CMD_ERROR; tron@4239: } tron@4239: #undef M tron@4239: tron@4239: 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 tron@3491: * @param end_tile end tile richk@6719: * @param flags type of operation 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) richk@6719: * - p2 = (bit 8-..) - rail type or road types. richk@6719: * - p2 = (bit 15 ) - set means road bridge. truelight@0: */ richk@6720: CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { maedhros@6181: uint bridge_type; tron@3180: RailType railtype; richk@6719: RoadTypes roadtypes; celestar@3853: uint x; celestar@3853: uint y; celestar@3853: uint sx; celestar@3853: uint sy; tron@3301: TileIndex tile_start; tron@3301: TileIndex tile_end; tron@3636: Slope tileh_start; tron@3636: Slope tileh_end; tron@3301: uint z_start; tron@3301: uint z_end; tron@3178: TileIndex tile; tron@3178: TileIndexDiff delta; tron@2639: uint bridge_len; tron@3157: Axis direction; richk@6720: CommandCost cost, terraformcost, ret; pasky@1585: bool allow_on_slopes; maedhros@6181: bool replace_bridge = false; maedhros@6181: uint replaced_bridge_type; truelight@0: truelight@0: SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); truelight@193: truelight@0: /* unpack parameters */ tron@2140: bridge_type = GB(p2, 0, 8); truelight@193: tron@2934: if (p1 >= MapSize()) return CMD_ERROR; Darkvater@1775: richk@6719: /* type of bridge */ tron@3180: if (HASBIT(p2, 15)) { tron@6103: railtype = INVALID_RAILTYPE; // road bridge richk@6719: roadtypes = (RoadTypes)GB(p2, 8, 3); richk@6719: if (!AreValidRoadTypes(roadtypes)) return CMD_ERROR; truelight@0: } else { tron@3180: if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR; rubidium@5838: railtype = (RailType)GB(p2, 8, 8); richk@6719: roadtypes = ROADTYPES_NONE; truelight@0: } truelight@0: tron@3493: x = TileX(end_tile); tron@3493: y = TileY(end_tile); tron@3493: sx = TileX(p1); tron@3493: sy = TileY(p1); 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); tron@3157: direction = AXIS_Y; tron@6432: if (y > sy) Swap(y, sy); truelight@0: } else if (y == sy) { tron@3157: direction = AXIS_X; tron@6432: if (x > sx) Swap(x, sx); 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 */ tron@4000: bridge_len = sx + sy - x - y - 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@3493: tile_start = TileXY(x, y); tron@3493: tile_end = TileXY(sx, sy); tron@4000: if (IsClearWaterTile(tile_start) || IsClearWaterTile(tile_end)) { tron@4000: return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH); tron@4000: } truelight@0: tron@3301: tileh_start = GetTileSlope(tile_start, &z_start); tron@3301: tileh_end = GetTileSlope(tile_end, &z_end); tron@3301: tron@4246: if (IsSteepSlope(tileh_start)) z_start += TILE_HEIGHT; tron@3636: if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) { tron@3645: z_start += TILE_HEIGHT; tron@3636: tileh_start = SLOPE_FLAT; truelight@0: } truelight@0: tron@4246: if (IsSteepSlope(tileh_end)) z_end += TILE_HEIGHT; tron@3636: if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) { tron@3645: z_end += TILE_HEIGHT; tron@3636: tileh_end = SLOPE_FLAT; truelight@0: } truelight@0: tron@3301: if (z_start != z_end) return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); pasky@1585: richk@6719: /* 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: maedhros@6181: TransportType transport_type = railtype == INVALID_RAILTYPE ? TRANSPORT_ROAD : TRANSPORT_RAIL; truelight@0: maedhros@6181: if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) && maedhros@6181: GetOtherBridgeEnd(tile_start) == tile_end && maedhros@6181: GetBridgeTransportType(tile_start) == transport_type) { maedhros@6181: /* Replace a current bridge. */ truelight@193: maedhros@6181: /* If this is a railway bridge, make sure the railtypes match. */ maedhros@6181: if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) { maedhros@6181: return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); maedhros@6181: } truelight@0: maedhros@6181: /* Do not replace town bridges with lower speed bridges. */ maedhros@6181: if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) && maedhros@6181: _bridge[bridge_type].speed < _bridge[GetBridgeType(tile_start)].speed) { maedhros@6181: Town *t = ClosestTownFromTile(tile_start, UINT_MAX); maedhros@6181: maedhros@6181: if (t == NULL) { maedhros@6181: return CMD_ERROR; maedhros@6181: } else { maedhros@6181: SetDParam(0, t->index); maedhros@6181: return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); maedhros@6181: } maedhros@6181: } maedhros@6181: maedhros@6181: /* Do not replace the bridge with the same bridge type. */ maedhros@6181: if (!(flags & DC_QUERY_COST) && bridge_type == GetBridgeType(tile_start)) { maedhros@6181: return_cmd_error(STR_1007_ALREADY_BUILT); maedhros@6181: } maedhros@6181: maedhros@6181: /* Do not allow replacing another player's bridges. */ maedhros@6181: if (!IsTileOwner(tile_start, _current_player) && !IsTileOwner(tile_start, OWNER_TOWN)) { maedhros@6181: return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER); maedhros@6181: } maedhros@6181: richk@6720: cost.AddCost((bridge_len + 1) * _price.clear_bridge); // The cost of clearing the current bridge. maedhros@6181: replace_bridge = true; maedhros@6181: replaced_bridge_type = GetBridgeType(tile_start); richk@6719: richk@6719: /* Do not remove road types when upgrading a bridge */ richk@6719: roadtypes |= GetRoadTypes(tile_start); maedhros@6181: } else { maedhros@6181: /* Build a new bridge. */ maedhros@6181: maedhros@6181: /* Try and clear the start landscape */ maedhros@6181: ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR); maedhros@6181: if (CmdFailed(ret)) return ret; maedhros@6181: cost = ret; maedhros@6181: maedhros@6181: terraformcost = CheckBridgeSlopeNorth(direction, tileh_start); richk@6720: if (CmdFailed(terraformcost) || (terraformcost.GetCost() != 0 && !allow_on_slopes)) maedhros@6181: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); richk@6720: cost.AddCost(terraformcost); maedhros@6181: maedhros@6181: /* Try and clear the end landscape */ maedhros@6181: ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR); maedhros@6181: if (CmdFailed(ret)) return ret; richk@6720: cost.AddCost(ret); maedhros@6181: richk@6719: /* false - end tile slope check */ maedhros@6181: terraformcost = CheckBridgeSlopeSouth(direction, tileh_end); richk@6720: if (CmdFailed(terraformcost) || (terraformcost.GetCost() != 0 && !allow_on_slopes)) maedhros@6181: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); richk@6720: cost.AddCost(terraformcost); maedhros@6181: } maedhros@6181: maedhros@6181: if (!replace_bridge) { celestar@5573: TileIndex Heads[] = {tile_start, tile_end}; celestar@5573: int i; celestar@5573: celestar@5573: for (i = 0; i < 2; i++) { celestar@5573: if (MayHaveBridgeAbove(Heads[i])) { celestar@5573: if (IsBridgeAbove(Heads[i])) { celestar@5573: TileIndex north_head = GetNorthernBridgeEnd(Heads[i]); celestar@5573: celestar@5573: if (direction == GetBridgeAxis(Heads[i])) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); celestar@5573: celestar@5573: if (z_start + TILE_HEIGHT == GetBridgeHeight(north_head)) { celestar@5573: return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); celestar@5573: } celestar@5573: } celestar@5573: } celestar@5573: } celestar@5573: } truelight@0: truelight@0: /* do the drill? */ truelight@0: if (flags & DC_EXEC) { tron@3209: DiagDirection dir = AxisToDiagDir(direction); maedhros@6181: Owner owner = (replace_bridge && IsTileOwner(tile_start, OWNER_TOWN)) ? OWNER_TOWN : _current_player; truelight@0: tron@6103: if (railtype != INVALID_RAILTYPE) { maedhros@6181: MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype); maedhros@6181: MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype); tron@3209: } else { richk@6719: MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir, roadtypes); richk@6719: MakeRoadBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), roadtypes); tron@3209: } tron@3301: MarkTileDirtyByTile(tile_start); tron@3301: MarkTileDirtyByTile(tile_end); truelight@0: } truelight@0: tron@3178: delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); celestar@5573: for (tile = tile_start + delta; tile != tile_end; tile += delta) { tron@3178: uint z; truelight@0: celestar@5573: if (GetTileSlope(tile, &z) != SLOPE_FLAT && z >= z_start) return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); truelight@0: maedhros@6181: if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && !replace_bridge) { celestar@5573: /* Disallow crossing bridges for the time being */ celestar@5573: return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); tron@3183: } truelight@0: tron@3178: switch (GetTileType(tile)) { tron@3065: case MP_WATER: tron@3183: if (!EnsureNoVehicle(tile)) return_cmd_error(STR_980E_SHIP_IN_THE_WAY); tron@4000: if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below; tron@3065: break; truelight@0: tron@3065: case MP_RAILWAY: celestar@5573: if (!IsPlainRailTile(tile)) goto not_valid_below; tron@3065: break; tron@3065: tron@3065: case MP_STREET: celestar@5573: if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) goto not_valid_below; celestar@5573: break; celestar@5573: celestar@5573: case MP_TUNNELBRIDGE: celestar@5573: if (IsTunnel(tile)) break; maedhros@6181: if (replace_bridge) break; celestar@5573: if (direction == DiagDirToAxis(GetBridgeRampDirection(tile))) goto not_valid_below; celestar@5573: if (z_start < GetBridgeHeight(tile)) goto not_valid_below; celestar@5573: break; celestar@5573: celestar@5573: case MP_UNMOVABLE: celestar@5573: if (!IsOwnedLand(tile)) goto not_valid_below; celestar@5573: break; celestar@5573: celestar@5573: case MP_CLEAR: maedhros@6181: if (!replace_bridge && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); tron@3065: break; tron@3065: tron@3065: default: truelight@0: not_valid_below:; tron@3065: /* try and clear the middle landscape */ tron@3491: ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); tron@3183: if (CmdFailed(ret)) return ret; richk@6720: cost.AddCost(ret); tron@3065: break; truelight@0: } truelight@0: truelight@0: if (flags & DC_EXEC) { celestar@5573: SetBridgeMiddle(tile, direction); tron@3178: MarkTileDirtyByTile(tile); truelight@0: } truelight@0: } truelight@0: Darkvater@5805: if (flags & DC_EXEC) { Darkvater@5812: Track track = AxisToTrack(direction); Darkvater@5812: SetSignalsOnBothDir(tile_start, track); Darkvater@5812: YapfNotifyTrackLayoutChange(tile_start, track); Darkvater@5805: } truelight@0: rubidium@4434: /* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST) rubidium@4434: * It's unnecessary to execute this command every time for every bridge. So it is done only rubidium@4434: * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated rubidium@4434: */ truelight@193: if (!(flags & DC_QUERY_COST)) { celestar@2262: const Bridge *b = &_bridge[bridge_type]; celestar@2262: rubidium@4434: bridge_len += 2; // begin and end tiles/ramps truelight@0: Darkvater@4850: if (IsValidPlayer(_current_player) && !_is_old_ai_player) truelight@0: bridge_len = CalcBridgeLenCostFactor(bridge_len); truelight@0: richk@6720: cost.AddCost((int64)bridge_len * _price.build_bridge * b->price >> 8); truelight@0: } truelight@0: truelight@0: return cost; truelight@0: } truelight@0: truelight@0: Darkvater@1782: /** Build Tunnel. richk@6719: * @param start_tile start tile of tunnel richk@6719: * @param flags type of operation richk@6719: * @param p1 railtype or roadtypes. bit 9 set means road tunnel tron@2639: * @param p2 unused truelight@0: */ richk@6720: CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { tron@3063: TileIndexDiff delta; tron@3063: TileIndex end_tile; tron@3063: DiagDirection direction; tron@3636: Slope start_tileh; tron@3636: Slope end_tileh; tron@3063: uint start_z; tron@3063: uint end_z; richk@6720: CommandCost cost; richk@6720: CommandCost ret; truelight@0: tron@3063: _build_tunnel_endtile = 0; richk@6719: if (!HASBIT(p1, 9)) { richk@6719: if (!ValParamRailtype(p1)) return CMD_ERROR; richk@6719: } else if (!AreValidRoadTypes((RoadTypes)GB(p1, 0, 3))) { richk@6719: return CMD_ERROR; richk@6719: } Darkvater@1782: tron@3063: start_tileh = GetTileSlope(start_tile, &start_z); truelight@0: tron@3063: switch (start_tileh) { tron@3636: case SLOPE_SW: direction = DIAGDIR_SW; break; tron@3636: case SLOPE_SE: direction = DIAGDIR_SE; break; tron@3636: case SLOPE_NW: direction = DIAGDIR_NW; break; tron@3636: case SLOPE_NE: direction = DIAGDIR_NE; break; tron@3063: default: return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL); tron@2639: } truelight@0: tron@3491: ret = DoCommand(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); tron@3063: if (CmdFailed(ret)) return ret; truelight@0: Darkvater@4273: /* XXX - do NOT change 'ret' in the loop, as it is used as the price Darkvater@4273: * for the clearing of the entrance of the tunnel. Assigning it to Darkvater@4273: * cost before the loop will yield different costs depending on start- Darkvater@4273: * position, because of increased-cost-by-length: 'cost += cost >> 3' */ richk@6720: Darkvater@4559: delta = TileOffsByDiagDir(direction); richk@6720: DiagDirection tunnel_in_way_dir; richk@6720: if (OtherAxis(DiagDirToAxis(direction)) == AXIS_X) { richk@6720: tunnel_in_way_dir = (TileX(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SW : DIAGDIR_NE; richk@6720: } else { richk@6720: tunnel_in_way_dir = (TileY(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SE : DIAGDIR_NW; richk@6720: } richk@6720: tron@3063: end_tile = start_tile; richk@6720: richk@6720: /** Tile shift coeficient. Will decrease for very long tunnels to avoid exponential growth of price*/ richk@6720: int tiles_coef = 3; richk@6720: /** Number of tiles from start of tunnel */ richk@6720: int tiles = 0; richk@6720: 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: richk@6720: if (!_cheats.crossing_tunnels.value && IsTunnelInWayDir(end_tile, start_z, tunnel_in_way_dir)) { tron@3156: return_cmd_error(STR_5003_ANOTHER_TUNNEL_IN_THE_WAY); tron@3063: } tron@3063: richk@6720: tiles++; richk@6720: if (tiles == 25 || tiles == 50 || tiles == 100 || tiles == 200 || tiles == 400 || tiles == 800) tiles_coef++; richk@6720: richk@6720: cost.AddCost(_price.build_tunnel); richk@6720: cost.AddCost(cost.GetCost() >> tiles_coef); // add a multiplier for longer tunnels truelight@0: } truelight@0: Darkvater@4273: /* Add the cost of the entrance */ richk@6720: cost.AddCost(_price.build_tunnel); richk@6720: cost.AddCost(ret); Darkvater@4273: richk@6719: /* if the command fails from here on we want the end tile to be highlighted */ tron@3063: _build_tunnel_endtile = end_tile; tron@3063: richk@6719: /* slope of end tile must be complementary to the slope of the start tile */ tron@3636: if (end_tileh != ComplementSlope(start_tileh)) { richk@6720: /* Some (rail) track bits might be terraformed into the correct direction, richk@6720: * but that would still leave tracks on foundation. Therefor excavation will richk@6720: * always fail for rail tiles. On the other hand, for road tiles it might richk@6720: * succeed when there is only one road bit on the tile, but then that road richk@6720: * bit is removed leaving a clear tile. richk@6720: * This therefor preserves the behaviour that half road tiles are always removable. richk@6720: */ richk@6720: if (IsTileType(end_tile, MP_RAILWAY)) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); richk@6720: tron@3491: ret = DoCommand(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@3491: ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); tron@3063: if (CmdFailed(ret)) return ret; tron@3063: } richk@6720: cost.AddCost(_price.build_tunnel); richk@6720: cost.AddCost(ret); tron@3063: tron@3063: if (flags & DC_EXEC) { tron@3154: if (GB(p1, 9, 1) == TRANSPORT_RAIL) { rubidium@5838: MakeRailTunnel(start_tile, _current_player, direction, (RailType)GB(p1, 0, 4)); rubidium@5838: MakeRailTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4)); KUDr@3900: UpdateSignalsOnSegment(start_tile, direction); tron@4158: YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction))); tron@3154: } else { richk@6719: MakeRoadTunnel(start_tile, _current_player, direction, (RoadTypes)GB(p1, 0, 3)); richk@6719: MakeRoadTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 3)); tron@3154: } 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@3154: DiagDirection dir = GetTunnelDirection(tile); Darkvater@4559: TileIndexDiff delta = TileOffsByDiagDir(dir); 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@3184: !IsTunnelTile(tile) || tron@3154: ReverseDiagDir(GetTunnelDirection(tile)) != dir || tron@1035: GetTileZ(tile) != z tron@1035: ); truelight@0: tron@1430: v = FindVehicleBetween(starttile, tile, z); tron@1430: if (v != NULL) { rubidium@6585: _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: Darkvater@5009: static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile) Darkvater@5009: { Darkvater@5009: /* Floods can remove anything as well as the scenario editor */ Darkvater@5009: if (_current_player == OWNER_WATER || _game_mode == GM_EDITOR) return true; Darkvater@5009: /* Obviously if the bridge/tunnel belongs to us, or no-one, we can remove it */ Darkvater@5009: if (CheckTileOwnership(tile) || IsTileOwner(tile, OWNER_NONE)) return true; Darkvater@5009: /* Otherwise we can only remove town-owned stuff with extra patch-settings, or cheat */ Darkvater@5009: if (IsTileOwner(tile, OWNER_TOWN) && (_patches.extra_dynamite || _cheats.magic_bulldozer.value)) return true; Darkvater@5009: return false; Darkvater@5009: } Darkvater@5009: richk@6720: static CommandCost DoClearTunnel(TileIndex tile, uint32 flags) truelight@0: { Darkvater@5009: Town *t = NULL; Darkvater@1782: TileIndex endtile; tron@1430: uint length; truelight@0: truelight@0: SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); truelight@0: Darkvater@5009: if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; 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: tron@1901: if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { Darkvater@5009: t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating Darkvater@5009: Darkvater@5009: /* Check if you are allowed to remove the tunnel owned by a town Darkvater@5009: * Removal depends on difficulty settings */ 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) { richk@6719: /* We first need to request the direction before calling DoClearSquare richk@6719: * else the direction is always 0.. dah!! ;) */ tron@3157: DiagDirection dir = GetTunnelDirection(tile); tron@4158: Track track; peter1138@2870: richk@6719: /* 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); tron@3172: UpdateSignalsOnSegment(tile, ReverseDiagDir(dir)); tron@3172: UpdateSignalsOnSegment(endtile, dir); tron@4158: track = AxisToTrack(DiagDirToAxis(dir)); tron@4158: YapfNotifyTrackLayoutChange(tile, track); tron@4158: YapfNotifyTrackLayoutChange(endtile, track); truelight@0: } richk@6720: return CommandCost(_price.clear_tunnel * (length + 1)); truelight@0: } truelight@0: tron@3977: celestar@5573: static bool IsVehicleOnBridge(TileIndex starttile, TileIndex endtile, uint z) tron@3779: { celestar@5573: const Vehicle *v; celestar@5573: FOR_ALL_VEHICLES(v) { celestar@5573: if ((v->tile == starttile || v->tile == endtile) && v->z_pos == z) { celestar@5573: _error_message = VehicleInTheWayErrMsg(v); celestar@5573: return true; celestar@5573: } celestar@5573: } celestar@5573: return false; tron@3779: } tron@3779: richk@6720: static CommandCost DoClearBridge(TileIndex tile, uint32 flags) truelight@0: { tron@3227: DiagDirection direction; tron@3227: TileIndexDiff delta; tron@1977: TileIndex endtile; Darkvater@5009: Town *t = NULL; truelight@193: truelight@0: SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); truelight@0: Darkvater@5009: if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; truelight@0: tron@3228: endtile = GetOtherBridgeEnd(tile); richk@6719: byte bridge_height = GetBridgeHeight(tile); tron@3228: richk@6719: if (FindVehicleOnTileZ(tile, bridge_height) != NULL || richk@6719: FindVehicleOnTileZ(endtile, bridge_height) != NULL || richk@6719: IsVehicleOnBridge(tile, endtile, bridge_height)) { celestar@5573: return CMD_ERROR; celestar@5573: } truelight@0: tron@3227: direction = GetBridgeRampDirection(tile); Darkvater@4559: delta = TileOffsByDiagDir(direction); tron@3227: tron@1901: if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { Darkvater@5009: t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating Darkvater@5009: Darkvater@5009: /* Check if you are allowed to remove the bridge owned by a town Darkvater@5009: * Removal depends on difficulty settings */ Darkvater@5009: if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) { Darkvater@5009: SetDParam(0, t->index); Darkvater@5009: return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); Darkvater@5009: } truelight@0: } truelight@0: truelight@0: if (flags & DC_EXEC) { tron@3217: TileIndex c; tron@4158: Track track; truelight@0: richk@6719: /* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until richk@6719: * 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: tron@3217: DoClearSquare(tile); tron@3217: DoClearSquare(endtile); tron@3217: for (c = tile + delta; c != endtile; c += delta) { celestar@5573: ClearBridgeMiddle(c); celestar@5573: MarkTileDirtyByTile(c); tron@3217: } truelight@0: tron@3227: UpdateSignalsOnSegment(tile, ReverseDiagDir(direction)); tron@3227: UpdateSignalsOnSegment(endtile, direction); tron@4158: track = AxisToTrack(DiagDirToAxis(direction)); tron@4158: YapfNotifyTrackLayoutChange(tile, track); tron@4158: YapfNotifyTrackLayoutChange(endtile, track); truelight@0: } truelight@0: richk@6720: return CommandCost((DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge); truelight@0: } truelight@0: richk@6720: static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags) tron@1977: { tron@3184: if (IsTunnel(tile)) { tron@2639: if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST); truelight@0: return DoClearTunnel(tile, flags); tron@3234: } else if (IsBridge(tile)) { // XXX Is this necessary? 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: celestar@6694: /** celestar@6694: * Switches the rail type for a tunnel or a bridgehead. As the railtype celestar@6694: * on the bridge are determined by the one of the bridgehead, this celestar@6694: * functions converts the railtype on the entire bridge. celestar@6694: * @param tile The tile on which the railtype is to be convert. celestar@6694: * @param totype The railtype we want to convert to celestar@6694: * @param exec Switches between test and execute mode celestar@6694: * @return The cost and state of the operation celestar@6694: * @retval CMD_ERROR An error occured during the operation. celestar@6694: */ richk@6720: CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec) truelight@0: { Darkvater@1782: TileIndex endtile; truelight@0: tron@3184: if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) { tron@4000: uint length; tron@4000: truelight@0: if (!CheckTileOwnership(tile)) return CMD_ERROR; truelight@0: tron@3242: if (GetRailType(tile) == totype) return CMD_ERROR; truelight@193: richk@6719: /* 'hidden' elrails can't be downgraded to normal rail when elrails are disabled */ KUDr@5116: if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR; KUDr@5116: truelight@0: endtile = CheckTunnelBusy(tile, &length); tron@1430: if (endtile == INVALID_TILE) return CMD_ERROR; truelight@0: truelight@0: if (exec) { tron@4158: Track track; tron@3242: SetRailType(tile, totype); tron@3242: SetRailType(endtile, totype); truelight@0: MarkTileDirtyByTile(tile); truelight@0: MarkTileDirtyByTile(endtile); KUDr@3900: tron@4158: track = AxisToTrack(DiagDirToAxis(GetTunnelDirection(tile))); KUDr@3900: YapfNotifyTrackLayoutChange(tile, track); tron@4158: YapfNotifyTrackLayoutChange(endtile, track); truelight@0: } richk@6720: return CommandCost((length + 1) * (_price.build_rail / 2)); celestar@5573: } else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) { truelight@0: truelight@0: if (!CheckTileOwnership(tile)) return CMD_ERROR; truelight@0: tron@3215: endtile = GetOtherBridgeEnd(tile); richk@6719: byte bridge_height = GetBridgeHeight(tile); truelight@0: richk@6719: if (FindVehicleOnTileZ(tile, bridge_height) != NULL || richk@6719: FindVehicleOnTileZ(endtile, bridge_height) != NULL || richk@6719: IsVehicleOnBridge(tile, endtile, bridge_height)) { celestar@5573: return CMD_ERROR; celestar@1073: } celestar@1073: tron@3242: if (GetRailType(tile) == totype) return CMD_ERROR; tron@3213: tron@3218: if (exec) { celestar@5573: TileIndexDiff delta; tron@4158: Track track; celestar@5573: tron@3242: SetRailType(tile, totype); tron@3242: SetRailType(endtile, totype); tron@3218: MarkTileDirtyByTile(tile); tron@3218: MarkTileDirtyByTile(endtile); KUDr@3900: tron@4158: track = AxisToTrack(DiagDirToAxis(GetBridgeRampDirection(tile))); tron@3977: YapfNotifyTrackLayoutChange(tile, track); tron@4158: YapfNotifyTrackLayoutChange(endtile, track); celestar@5573: celestar@5573: delta = TileOffsByDiagDir(GetBridgeRampDirection(tile)); celestar@5573: for (tile += delta; tile != endtile; tile += delta) { celestar@5573: MarkTileDirtyByTile(tile); // TODO encapsulate this into a function truelight@0: } tron@3213: } truelight@0: richk@6720: return CommandCost((DistanceManhattan(tile, endtile) + 1) * (_price.build_rail / 2)); tron@4000: } else { truelight@0: return CMD_ERROR; tron@4000: } truelight@0: } truelight@0: truelight@0: peter1138@5919: static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, uint type, int x, int y, int z) truelight@0: { peter1138@5919: SpriteID image = psid->sprite; truelight@0: if (image != 0) { celestar@5573: bool drawfarpillar = !HASBIT(GetBridgeFlags(type), 0); Darkvater@3556: int back_height, front_height; Darkvater@3556: int i = z; truelight@0: const byte *p; peter1138@5919: SpriteID pal; truelight@0: truelight@0: static const byte _tileh_bits[4][8] = { tron@4191: { 2, 1, 8, 4, 16, 2, 0, 9 }, tron@4191: { 1, 8, 4, 2, 2, 16, 9, 0 }, tron@4191: { 4, 8, 1, 2, 16, 2, 0, 9 }, tron@4191: { 2, 4, 8, 1, 2, 16, 9, 0 } truelight@0: }; truelight@0: richk@6719: if (HASBIT(_transparent_opt, TO_BRIDGES)) { peter1138@5919: SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); peter1138@5919: pal = PALETTE_TO_TRANSPARENT; peter1138@5919: } else { peter1138@5919: pal = psid->pal; peter1138@5919: } tron@333: tron@3234: p = _tileh_bits[(image & 1) * 2 + (axis == AXIS_X ? 0 : 1)]; tron@3645: front_height = ti->z + (ti->tileh & p[0] ? TILE_HEIGHT : 0); tron@3645: back_height = ti->z + (ti->tileh & p[1] ? TILE_HEIGHT : 0); celestar@2262: tron@3636: if (IsSteepSlope(ti->tileh)) { tron@3645: if (!(ti->tileh & p[2])) front_height += TILE_HEIGHT; tron@3645: if (!(ti->tileh & p[3])) back_height += TILE_HEIGHT; truelight@0: } truelight@0: tron@3645: for (; z >= front_height || z >= back_height; z -= TILE_HEIGHT) { tron@4191: /* HACK set height of the BB of pillars to 1, because the origin of the tron@4191: * sprites is at the top tron@4191: */ Darkvater@3556: if (z >= front_height) { // front facing pillar peter1138@5919: AddSortableSpriteToDraw(image, pal, x, y, p[4], p[5], 1, z); tron@2952: } Darkvater@3556: tron@3645: if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar peter1138@5919: AddSortableSpriteToDraw(image, pal, x - p[6], y - p[7], p[4], p[5], 1, z); tron@2952: } truelight@0: } truelight@0: } truelight@0: } truelight@0: tron@3636: uint GetBridgeFoundation(Slope tileh, Axis axis) tron@2639: { tron@3878: uint i; tron@3878: tron@3636: if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) return tileh; truelight@0: richk@6719: /* inclined sloped building */ tron@3878: switch (tileh) { tron@4246: case SLOPE_W: tron@4246: case SLOPE_STEEP_W: i = 0; break; tron@4246: case SLOPE_S: tron@4246: case SLOPE_STEEP_S: i = 2; break; tron@4246: case SLOPE_E: tron@4246: case SLOPE_STEEP_E: i = 4; break; tron@4246: case SLOPE_N: tron@4246: case SLOPE_STEEP_N: i = 6; break; tron@4246: default: return 0; tron@3017: } tron@3878: if (axis != AXIS_X) ++i; tron@3878: return i + 15; truelight@0: } truelight@0: celestar@2536: /** richk@6719: * Draws the trambits over an already drawn (lower end) of a bridge. richk@6719: * @param x the x of the bridge richk@6719: * @param y the y of the bridge richk@6719: * @param z the z of the bridge richk@6719: * @param offset number representing whether to level or sloped and the direction richk@6719: * @param overlay do we want to still see the road? richk@6719: */ richk@6719: static void DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay) richk@6719: { richk@6719: static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } }; richk@6720: static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 }; richk@6719: static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 }; richk@6719: richk@6719: static const uint size_x[6] = { 11, 16, 16, 16, 16, 16 }; richk@6719: static const uint size_y[6] = { 16, 11, 16, 16, 16, 16 }; richk@6719: richk@6719: AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, x, y, size_x[offset], size_y[offset], offset >= 2 ? 1 : 0, z); richk@6719: richk@6719: SpriteID front = SPR_TRAMWAY_BASE + front_offsets[offset]; richk@6719: SpriteID back = SPR_TRAMWAY_BASE + back_offsets[offset]; richk@6719: SpriteID pal = PAL_NONE; richk@6719: if (HASBIT(_transparent_opt, TO_BUILDINGS)) { richk@6719: SETBIT(front, PALETTE_MODIFIER_TRANSPARENT); richk@6719: SETBIT(back, PALETTE_MODIFIER_TRANSPARENT); richk@6719: pal = PALETTE_TO_TRANSPARENT; richk@6719: } richk@6719: richk@6719: AddSortableSpriteToDraw(back, pal, x, y, size_x[offset], size_y[offset], 0, z); richk@6719: /* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */ richk@6719: AddSortableSpriteToDraw(front, pal, x, y, size_x[offset], size_y[offset], offset >= 2 ? 0x30 : 0x10, z); richk@6719: } richk@6719: richk@6719: /** rubidium@4549: * Draws a tunnel of bridge tile. rubidium@4549: * For tunnels, this is rather simple, as you only needa draw the entrance. rubidium@4549: * Bridges are a bit more complex. base_offset is where the sprite selection comes into play rubidium@4549: * and it works a bit like a bitmask.
For bridge heads: richk@6719: * @param ti TileInfo of the structure to draw rubidium@4549: *