tron@2186: /* $Id$ */ tron@2186: belugas@6117: /** @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" rubidium@7266: #include "strings.h" tron@2163: #include "functions.h" tron@679: #include "map.h" maedhros@6343: #include "landscape.h" tron@1209: #include "tile.h" tron@3154: #include "tunnel_map.h" celestar@5385: #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" rubidium@7582: #include "autoslope.h" belugas@7849: #include "transparency.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@5668: { 0, 0, 16, 80, 32, 0xA24, PAL_NONE , STR_5012_WOODEN , NULL, 0 }, peter1138@5668: { 0, 0, 2, 112, 48, 0xA26, PALETTE_TO_STRUCT_RED , STR_5013_CONCRETE , NULL, 0 }, peter1138@5668: { 1930, 0, 5, 144, 64, 0xA25, PAL_NONE , STR_500F_GIRDER_STEEL , NULL, 0 }, peter1138@5668: { 0, 2, 10, 168, 80, 0xA22, PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 }, peter1138@5668: { 1930, 3, 16, 185, 96, 0xA22, PAL_NONE , STR_500E_SUSPENSION_STEEL , NULL, 0 }, peter1138@5668: { 1930, 3, 16, 192, 112, 0xA22, PALETTE_TO_STRUCT_YELLOW , STR_500E_SUSPENSION_STEEL , NULL, 0 }, peter1138@5668: { 1930, 3, 7, 224, 160, 0xA23, PAL_NONE , STR_5010_CANTILEVER_STEEL , NULL, 0 }, peter1138@5668: { 1930, 3, 8, 232, 208, 0xA23, PALETTE_TO_STRUCT_BROWN , STR_5010_CANTILEVER_STEEL , NULL, 0 }, peter1138@5668: { 1930, 3, 9, 248, 240, 0xA23, PALETTE_TO_STRUCT_RED , STR_5010_CANTILEVER_STEEL , NULL, 0 }, peter1138@5668: { 1930, 0, 2, 240, 256, 0xA27, PAL_NONE , STR_500F_GIRDER_STEEL , NULL, 0 }, peter1138@5668: { 1995, 2, 16, 255, 320, 0xA28, PAL_NONE , STR_5014_TUBULAR_STEEL , NULL, 0 }, peter1138@5668: { 2005, 2, 32, 380, 512, 0xA28, PALETTE_TO_STRUCT_YELLOW , STR_5014_TUBULAR_STEEL , NULL, 0 }, peter1138@5668: { 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: belugas@6422: /** calculate the price factor for building a long bridge. belugas@6422: * 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, belugas@6422: */ 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@6248: enum BridgeFoundation { belugas@6422: /* 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), belugas@6422: /* 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), belugas@6422: /* 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@6248: }; 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)) rubidium@6943: 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)); rubidium@6950: 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)); rubidium@6950: if (HASBIT(valid, tileh)) return CommandCost(_price.terraform); tron@2639: truelight@0: return CMD_ERROR; truelight@0: } truelight@0: rubidium@6943: 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)); rubidium@6950: 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)); rubidium@6950: 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 belugas@6422: * @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) rubidium@6661: * - p2 = (bit 8-..) - rail type or road types. rubidium@6661: * - p2 = (bit 15 ) - set means road bridge. truelight@0: */ rubidium@6943: CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { maedhros@5930: uint bridge_type; tron@3180: RailType railtype; rubidium@6661: 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; rubidium@6943: CommandCost cost, terraformcost, ret; pasky@1585: bool allow_on_slopes; maedhros@5930: bool replace_bridge = false; maedhros@5930: 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: belugas@6422: /* type of bridge */ tron@3180: if (HASBIT(p2, 15)) { tron@5852: railtype = INVALID_RAILTYPE; // road bridge rubidium@6663: roadtypes = (RoadTypes)GB(p2, 8, 3); truelight@7857: if (!AreValidRoadTypes(roadtypes) || !HasRoadTypesAvail(_current_player, roadtypes)) return CMD_ERROR; truelight@0: } else { tron@3180: if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR; rubidium@5587: railtype = (RailType)GB(p2, 8, 8); rubidium@6663: 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@6106: if (y > sy) Swap(y, sy); truelight@0: } else if (y == sy) { tron@3157: direction = AXIS_X; tron@6106: 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); rubidium@7739: if (IsWaterTile(tile_start) || IsWaterTile(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; rubidium@7403: if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) z_start += TILE_HEIGHT; truelight@0: tron@4246: if (IsSteepSlope(tileh_end)) z_end += TILE_HEIGHT; rubidium@7403: if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) z_end += TILE_HEIGHT; truelight@0: rubidium@7682: if (z_start != z_end) return_cmd_error(STR_BRIDGEHEADS_NOT_SAME_HEIGHT); pasky@1585: truelight@2422: allow_on_slopes = (!_is_old_ai_player truelight@7845: && _patches.build_on_slopes); pasky@1585: maedhros@5930: TransportType transport_type = railtype == INVALID_RAILTYPE ? TRANSPORT_ROAD : TRANSPORT_RAIL; truelight@0: maedhros@5930: if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) && maedhros@5930: GetOtherBridgeEnd(tile_start) == tile_end && maedhros@5930: GetBridgeTransportType(tile_start) == transport_type) { maedhros@5930: /* Replace a current bridge. */ truelight@193: maedhros@5930: /* If this is a railway bridge, make sure the railtypes match. */ maedhros@5930: if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) { maedhros@5930: return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); maedhros@5930: } truelight@0: maedhros@5930: /* Do not replace town bridges with lower speed bridges. */ maedhros@5930: if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) && maedhros@5930: _bridge[bridge_type].speed < _bridge[GetBridgeType(tile_start)].speed) { maedhros@5930: Town *t = ClosestTownFromTile(tile_start, UINT_MAX); maedhros@5930: maedhros@5930: if (t == NULL) { maedhros@5930: return CMD_ERROR; maedhros@5930: } else { maedhros@5930: SetDParam(0, t->index); maedhros@5930: return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); maedhros@5930: } maedhros@5930: } maedhros@5930: maedhros@5930: /* Do not replace the bridge with the same bridge type. */ maedhros@5930: if (!(flags & DC_QUERY_COST) && bridge_type == GetBridgeType(tile_start)) { maedhros@5930: return_cmd_error(STR_1007_ALREADY_BUILT); maedhros@5930: } maedhros@5930: maedhros@5930: /* Do not allow replacing another player's bridges. */ maedhros@5930: if (!IsTileOwner(tile_start, _current_player) && !IsTileOwner(tile_start, OWNER_TOWN)) { maedhros@5930: return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER); maedhros@5930: } maedhros@5930: rubidium@6950: cost.AddCost((bridge_len + 1) * _price.clear_bridge); // The cost of clearing the current bridge. maedhros@5930: replace_bridge = true; maedhros@5930: replaced_bridge_type = GetBridgeType(tile_start); rubidium@6708: rubidium@6708: /* Do not remove road types when upgrading a bridge */ rubidium@6708: roadtypes |= GetRoadTypes(tile_start); maedhros@5930: } else { maedhros@5930: /* Build a new bridge. */ maedhros@5930: maedhros@5930: /* Try and clear the start landscape */ maedhros@5930: ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR); maedhros@5930: if (CmdFailed(ret)) return ret; maedhros@5930: cost = ret; maedhros@5930: maedhros@5930: terraformcost = CheckBridgeSlopeNorth(direction, tileh_start); rubidium@6950: if (CmdFailed(terraformcost) || (terraformcost.GetCost() != 0 && !allow_on_slopes)) maedhros@5930: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); rubidium@6950: cost.AddCost(terraformcost); maedhros@5930: maedhros@5930: /* Try and clear the end landscape */ maedhros@5930: ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR); maedhros@5930: if (CmdFailed(ret)) return ret; rubidium@6950: cost.AddCost(ret); maedhros@5930: belugas@6422: /* false - end tile slope check */ maedhros@5930: terraformcost = CheckBridgeSlopeSouth(direction, tileh_end); rubidium@6950: if (CmdFailed(terraformcost) || (terraformcost.GetCost() != 0 && !allow_on_slopes)) maedhros@5930: return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); rubidium@6950: cost.AddCost(terraformcost); maedhros@5930: } maedhros@5930: maedhros@5930: if (!replace_bridge) { celestar@5385: TileIndex Heads[] = {tile_start, tile_end}; celestar@5385: int i; celestar@5385: celestar@5385: for (i = 0; i < 2; i++) { celestar@5385: if (MayHaveBridgeAbove(Heads[i])) { celestar@5385: if (IsBridgeAbove(Heads[i])) { celestar@5385: TileIndex north_head = GetNorthernBridgeEnd(Heads[i]); celestar@5385: celestar@5385: if (direction == GetBridgeAxis(Heads[i])) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); celestar@5385: celestar@5385: if (z_start + TILE_HEIGHT == GetBridgeHeight(north_head)) { celestar@5385: return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); celestar@5385: } celestar@5385: } celestar@5385: } celestar@5385: } celestar@5385: } truelight@0: truelight@0: /* do the drill? */ truelight@0: if (flags & DC_EXEC) { tron@3209: DiagDirection dir = AxisToDiagDir(direction); maedhros@5930: Owner owner = (replace_bridge && IsTileOwner(tile_start, OWNER_TOWN)) ? OWNER_TOWN : _current_player; truelight@0: tron@5852: if (railtype != INVALID_RAILTYPE) { maedhros@5930: MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype); maedhros@5930: MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype); tron@3209: } else { rubidium@6661: MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir, roadtypes); rubidium@6661: 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@5385: for (tile = tile_start + delta; tile != tile_end; tile += delta) { tron@3178: uint z; truelight@0: rubidium@7682: if (GetTileSlope(tile, &z) != SLOPE_FLAT && z >= z_start) return_cmd_error(STR_BRIDGE_TOO_LOW_FOR_TERRAIN); truelight@0: maedhros@5930: if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && !replace_bridge) { celestar@5385: /* Disallow crossing bridges for the time being */ celestar@5385: return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); tron@3183: } truelight@0: tron@3178: switch (GetTileType(tile)) { tron@3065: case MP_WATER: rubidium@7758: if (!EnsureNoVehicleOnGround(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@5385: if (!IsPlainRailTile(tile)) goto not_valid_below; tron@3065: break; tron@3065: rubidium@7370: case MP_ROAD: celestar@5385: if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) goto not_valid_below; celestar@5385: break; celestar@5385: celestar@5385: case MP_TUNNELBRIDGE: celestar@5385: if (IsTunnel(tile)) break; maedhros@5930: if (replace_bridge) break; celestar@5385: if (direction == DiagDirToAxis(GetBridgeRampDirection(tile))) goto not_valid_below; celestar@5385: if (z_start < GetBridgeHeight(tile)) goto not_valid_below; celestar@5385: break; celestar@5385: celestar@5385: case MP_UNMOVABLE: celestar@5385: if (!IsOwnedLand(tile)) goto not_valid_below; celestar@5385: break; celestar@5385: celestar@5385: case MP_CLEAR: maedhros@5930: 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; rubidium@6950: cost.AddCost(ret); tron@3065: break; truelight@0: } truelight@0: truelight@0: if (flags & DC_EXEC) { celestar@5385: SetBridgeMiddle(tile, direction); tron@3178: MarkTileDirtyByTile(tile); truelight@0: } truelight@0: } truelight@0: Darkvater@5554: if (flags & DC_EXEC) { Darkvater@5561: Track track = AxisToTrack(direction); Darkvater@5561: SetSignalsOnBothDir(tile_start, track); Darkvater@5561: YapfNotifyTrackLayoutChange(tile_start, track); Darkvater@5554: } 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: rubidium@6950: 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. belugas@6484: * @param start_tile start tile of tunnel belugas@6422: * @param flags type of operation rubidium@6661: * @param p1 railtype or roadtypes. bit 9 set means road tunnel tron@2639: * @param p2 unused truelight@0: */ rubidium@6943: 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; rubidium@6943: CommandCost cost; rubidium@6943: CommandCost ret; truelight@0: tron@3063: _build_tunnel_endtile = 0; rubidium@6663: if (!HASBIT(p1, 9)) { rubidium@6661: if (!ValParamRailtype(p1)) return CMD_ERROR; truelight@7857: } else { truelight@7857: const RoadTypes rts = (RoadTypes)GB(p1, 0, 3); truelight@7857: if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_player, rts)) return CMD_ERROR; rubidium@6661: } 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' */ rubidium@6950: Darkvater@4559: delta = TileOffsByDiagDir(direction); rubidium@7002: DiagDirection tunnel_in_way_dir; rubidium@7002: if (OtherAxis(DiagDirToAxis(direction)) == AXIS_X) { rubidium@7002: tunnel_in_way_dir = (TileX(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SW : DIAGDIR_NE; rubidium@7002: } else { rubidium@7002: tunnel_in_way_dir = (TileY(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SE : DIAGDIR_NW; rubidium@7002: } rubidium@7002: tron@3063: end_tile = start_tile; rubidium@7095: rubidium@7095: /** Tile shift coeficient. Will decrease for very long tunnels to avoid exponential growth of price*/ rubidium@7095: int tiles_coef = 3; rubidium@7095: /** Number of tiles from start of tunnel */ rubidium@7095: int tiles = 0; truelight@7308: /** Number of tiles at which the cost increase coefficient per tile is halved */ truelight@7308: int tiles_bump = 25; rubidium@7095: 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: rubidium@7002: 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: rubidium@7095: tiles++; truelight@7308: if (tiles == tiles_bump) { truelight@7308: tiles_coef++; truelight@7308: tiles_bump *= 2; truelight@7308: } rubidium@7095: rubidium@6950: cost.AddCost(_price.build_tunnel); rubidium@7095: cost.AddCost(cost.GetCost() >> tiles_coef); // add a multiplier for longer tunnels truelight@0: } truelight@0: Darkvater@4273: /* Add the cost of the entrance */ rubidium@6950: cost.AddCost(_price.build_tunnel); rubidium@6950: cost.AddCost(ret); Darkvater@4273: belugas@6422: /* if the command fails from here on we want the end tile to be highlighted */ tron@3063: _build_tunnel_endtile = end_tile; tron@3063: belugas@6422: /* slope of end tile must be complementary to the slope of the start tile */ tron@3636: if (end_tileh != ComplementSlope(start_tileh)) { rubidium@7677: /* Check if there is a structure on the terraformed tile. Do not add the cost, that will be done by the terraforming */ rubidium@7677: ret = DoCommand(end_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR); rubidium@7677: if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND); rubidium@7042: rubidium@7677: ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND); rubidium@7677: 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: } rubidium@6950: cost.AddCost(_price.build_tunnel); rubidium@6950: cost.AddCost(ret); tron@3063: tron@3063: if (flags & DC_EXEC) { tron@3154: if (GB(p1, 9, 1) == TRANSPORT_RAIL) { rubidium@5587: MakeRailTunnel(start_tile, _current_player, direction, (RailType)GB(p1, 0, 4)); rubidium@5587: 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 { rubidium@6663: MakeRoadTunnel(start_tile, _current_player, direction, (RoadTypes)GB(p1, 0, 3)); rubidium@6663: 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@6259: _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: rubidium@6943: 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) { belugas@6422: /* We first need to request the direction before calling DoClearSquare belugas@6422: * else the direction is always 0.. dah!! ;) */ tron@3157: DiagDirection dir = GetTunnelDirection(tile); tron@4158: Track track; peter1138@2870: belugas@6422: /* 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: } rubidium@6950: return CommandCost(_price.clear_tunnel * (length + 1)); truelight@0: } truelight@0: tron@3977: celestar@5385: static bool IsVehicleOnBridge(TileIndex starttile, TileIndex endtile, uint z) tron@3779: { celestar@5385: const Vehicle *v; celestar@5385: FOR_ALL_VEHICLES(v) { celestar@5385: if ((v->tile == starttile || v->tile == endtile) && v->z_pos == z) { celestar@5385: _error_message = VehicleInTheWayErrMsg(v); celestar@5385: return true; celestar@5385: } celestar@5385: } celestar@5385: return false; tron@3779: } tron@3779: rubidium@6943: 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); rubidium@6537: byte bridge_height = GetBridgeHeight(tile); tron@3228: rubidium@6537: if (FindVehicleOnTileZ(tile, bridge_height) != NULL || rubidium@6537: FindVehicleOnTileZ(endtile, bridge_height) != NULL || rubidium@6537: IsVehicleOnBridge(tile, endtile, bridge_height)) { celestar@5385: return CMD_ERROR; celestar@5385: } 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: belugas@6422: /* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until belugas@6422: * 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@5385: ClearBridgeMiddle(c); celestar@5385: 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: rubidium@6950: return CommandCost((DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge); truelight@0: } truelight@0: rubidium@6943: 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@6368: /** celestar@6368: * Switches the rail type for a tunnel or a bridgehead. As the railtype celestar@6368: * on the bridge are determined by the one of the bridgehead, this celestar@6368: * functions converts the railtype on the entire bridge. celestar@6368: * @param tile The tile on which the railtype is to be convert. celestar@6368: * @param totype The railtype we want to convert to celestar@6368: * @param exec Switches between test and execute mode celestar@6368: * @return The cost and state of the operation celestar@6368: * @retval CMD_ERROR An error occured during the operation. celestar@6368: */ rubidium@6943: CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec) truelight@0: { tron@3184: if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) { tron@4000: uint length; rubidium@7539: TileIndex endtile; truelight@193: rubidium@7539: /* If not coverting rail <-> el. rail, any vehicle cannot be in tunnel */ rubidium@7539: if (!IsCompatibleRail(GetRailType(tile), totype)) { rubidium@7539: endtile = CheckTunnelBusy(tile, &length); rubidium@7539: if (endtile == INVALID_TILE) return CMD_ERROR; rubidium@7539: } else { rubidium@7539: endtile = GetOtherTunnelEnd(tile); rubidium@7539: length = DistanceManhattan(tile, endtile); rubidium@7539: } truelight@0: truelight@0: if (exec) { tron@3242: SetRailType(tile, totype); tron@3242: SetRailType(endtile, totype); truelight@0: MarkTileDirtyByTile(tile); truelight@0: MarkTileDirtyByTile(endtile); KUDr@3900: rubidium@7539: Track track = AxisToTrack(DiagDirToAxis(GetTunnelDirection(tile))); rubidium@7539: KUDr@3900: YapfNotifyTrackLayoutChange(tile, track); tron@4158: YapfNotifyTrackLayoutChange(endtile, track); rubidium@7539: rubidium@7539: VehicleFromPos(tile, &tile, UpdateTrainPowerProc); rubidium@7539: VehicleFromPos(endtile, &endtile, UpdateTrainPowerProc); truelight@0: } rubidium@7539: maedhros@7730: return CommandCost((length + 1) * (RailBuildCost(totype) / 2)); celestar@5385: } else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) { rubidium@7539: TileIndex endtile = GetOtherBridgeEnd(tile); rubidium@6537: byte bridge_height = GetBridgeHeight(tile); truelight@0: rubidium@7539: if (!IsCompatibleRail(GetRailType(tile), totype) && rubidium@7539: (FindVehicleOnTileZ(tile, bridge_height) != NULL || rubidium@6537: FindVehicleOnTileZ(endtile, bridge_height) != NULL || rubidium@7539: IsVehicleOnBridge(tile, endtile, bridge_height))) { celestar@5385: return CMD_ERROR; celestar@1073: } celestar@1073: tron@3218: if (exec) { tron@3242: SetRailType(tile, totype); tron@3242: SetRailType(endtile, totype); tron@3218: MarkTileDirtyByTile(tile); tron@3218: MarkTileDirtyByTile(endtile); KUDr@3900: rubidium@7539: Track track = AxisToTrack(DiagDirToAxis(GetBridgeRampDirection(tile))); rubidium@7539: TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile)); rubidium@7539: tron@3977: YapfNotifyTrackLayoutChange(tile, track); tron@4158: YapfNotifyTrackLayoutChange(endtile, track); celestar@5385: rubidium@7539: VehicleFromPos(tile, &tile, UpdateTrainPowerProc); rubidium@7539: VehicleFromPos(endtile, &endtile, UpdateTrainPowerProc); rubidium@7539: celestar@5385: for (tile += delta; tile != endtile; tile += delta) { celestar@5385: MarkTileDirtyByTile(tile); // TODO encapsulate this into a function truelight@0: } tron@3213: } truelight@0: maedhros@7730: return CommandCost((DistanceManhattan(tile, endtile) + 1) * (RailBuildCost(totype) / 2)); tron@4000: } else { truelight@0: return CMD_ERROR; tron@4000: } truelight@0: } truelight@0: truelight@0: rubidium@7728: /** rubidium@7728: * Draws the pillars under high bridges. rubidium@7728: * rubidium@7728: * @param psid Image and palette of a bridge pillar. rubidium@7728: * @param ti #TileInfo of current bridge-middle-tile. rubidium@7728: * @param axis Orientation of bridge. rubidium@7728: * @param type Bridge type. rubidium@7728: * @param x Sprite X position of front pillar. rubidium@7728: * @param y Sprite Y position of front pillar. rubidium@7728: * @param z_bridge Absolute height of bridge bottom. rubidium@7728: */ rubidium@7728: static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, uint type, int x, int y, int z_bridge) truelight@0: { peter1138@5668: SpriteID image = psid->sprite; truelight@0: if (image != 0) { celestar@5385: bool drawfarpillar = !HASBIT(GetBridgeFlags(type), 0); truelight@0: rubidium@7728: /* "side" specifies the side the pillars stand on. rubidium@7728: * The length of the pillars is then set to the height of the bridge over the corners of this edge. rubidium@7728: * rubidium@7728: * axis==AXIS_X axis==AXIS_Y rubidium@7728: * side==false SW NW rubidium@7728: * side==true NE SE rubidium@7728: * rubidium@7728: * I have no clue, why this was done this way. rubidium@7728: */ rubidium@7728: bool side = HASBIT(image, 0); celestar@2262: rubidium@7728: /* "dir" means the edge the pillars stand on */ rubidium@7728: DiagDirection dir = AxisToDiagDir(axis); rubidium@7728: if (side != (axis == AXIS_Y)) dir = ReverseDiagDir(dir); truelight@0: rubidium@7728: /* Determine ground height under pillars */ rubidium@7728: int front_height = ti->z; rubidium@7728: int back_height = ti->z; rubidium@7728: GetSlopeZOnEdge(ti->tileh, dir, &front_height, &back_height); rubidium@7728: rubidium@7728: /* x and y size of bounding-box of pillars */ rubidium@7728: int w = (axis == AXIS_X ? 16 : 2); rubidium@7728: int h = (axis == AXIS_X ? 2 : 16); rubidium@7728: /* sprite position of back facing pillar */ rubidium@7728: int x_back = x - (axis == AXIS_X ? 0 : 9); rubidium@7728: int y_back = y - (axis == AXIS_X ? 9 : 0); rubidium@7728: rubidium@7728: for (int cur_z = z_bridge; cur_z >= front_height || cur_z >= back_height; cur_z -= TILE_HEIGHT) { rubidium@7728: /* Draw front facing pillar */ rubidium@7728: if (cur_z >= front_height) { belugas@7849: AddSortableSpriteToDraw(image, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5); tron@2952: } Darkvater@3556: rubidium@7728: /* Draw back facing pillar, but not the highest part directly under the bridge-floor */ rubidium@7728: if (drawfarpillar && cur_z >= back_height && cur_z < z_bridge - TILE_HEIGHT) { belugas@7849: AddSortableSpriteToDraw(image, psid->pal, x_back, y_back, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5); tron@2952: } truelight@0: } truelight@0: } truelight@0: } truelight@0: rubidium@7335: Foundation GetBridgeFoundation(Slope tileh, Axis axis) tron@2639: { rubidium@7335: if (HASBIT(BRIDGE_NO_FOUNDATION, tileh)) return FOUNDATION_NONE; rubidium@7335: if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) return FlatteningFoundation(tileh); rubidium@7335: return InclinedFoundation(axis); truelight@0: } truelight@0: celestar@2536: /** rubidium@6691: * Draws the trambits over an already drawn (lower end) of a bridge. rubidium@6691: * @param x the x of the bridge rubidium@6691: * @param y the y of the bridge rubidium@6691: * @param z the z of the bridge rubidium@6691: * @param offset number representing whether to level or sloped and the direction rubidium@6691: * @param overlay do we want to still see the road? rubidium@6691: */ rubidium@6691: static void DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay) rubidium@6691: { rubidium@6691: static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } }; rubidium@7249: static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 }; rubidium@6691: static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 }; rubidium@6691: rubidium@7601: static const uint size_x[6] = { 1, 16, 16, 1, 16, 1 }; rubidium@7601: static const uint size_y[6] = { 16, 1, 1, 16, 1, 16 }; rubidium@7601: static const uint front_bb_offset_x[6] = { 15, 0, 0, 15, 0, 15 }; rubidium@7601: static const uint front_bb_offset_y[6] = { 0, 15, 15, 0, 15, 0 }; rubidium@6699: rubidium@7601: /* The sprites under the vehicles are drawn as SpriteCombine. StartSpriteCombine() has already been called rubidium@7601: * The bounding boxes here are the same as for bridge front/roof */ belugas@7849: AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, x, y, size_x[offset], size_y[offset], 0x28, z, IsTransparencySet(TO_BRIDGES)); rubidium@6691: belugas@7849: AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset], PAL_NONE, x, y, size_x[offset], size_y[offset], 0x28, z, IsTransparencySet(TO_BUILDINGS)); rubidium@7601: rubidium@7601: /* Start a new SpriteCombine for the front part */ rubidium@7601: EndSpriteCombine(); rubidium@7601: StartSpriteCombine(); rubidium@7601: rubidium@6691: /* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */ belugas@7849: AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE, x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z, IsTransparencySet(TO_BUILDINGS), front_bb_offset_x[offset], front_bb_offset_y[offset]); rubidium@6691: } rubidium@6691: rubidium@6691: /** 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: belugas@6422: * @param ti TileInfo of the structure to draw rubidium@4549: *