2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* @file tunnelbridge_cmd.cpp
|
2005-08-01 20:23:38 +00:00
|
|
|
* This file deals with tunnels and bridges (non-gui stuff)
|
2013-01-08 22:46:42 +00:00
|
|
|
* @todo separate this file into two
|
2005-08-01 20:23:38 +00:00
|
|
|
*/
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2010-08-27 22:21:23 +00:00
|
|
|
#include "newgrf_object.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "town.h"
|
2005-11-18 23:41:03 +00:00
|
|
|
#include "train.h"
|
2009-05-22 18:17:20 +00:00
|
|
|
#include "ship.h"
|
2009-05-22 20:22:20 +00:00
|
|
|
#include "roadveh.h"
|
2009-12-02 16:48:55 +00:00
|
|
|
#include "pathfinder/yapf/yapf_cache.h"
|
2006-09-27 18:17:01 +00:00
|
|
|
#include "newgrf_sound.h"
|
2007-09-14 22:27:40 +00:00
|
|
|
#include "autoslope.h"
|
2007-12-16 15:38:51 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2011-02-07 22:38:02 +00:00
|
|
|
#include "clear_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_func.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-01-23 22:34:04 +00:00
|
|
|
#include "tunnelbridge.h"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "cheat_type.h"
|
2008-05-08 16:48:29 +00:00
|
|
|
#include "elrail_func.h"
|
2009-12-01 23:56:04 +00:00
|
|
|
#include "pbs.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "company_base.h"
|
2010-02-07 22:22:54 +00:00
|
|
|
#include "newgrf_railtype.h"
|
2019-04-06 06:46:15 +00:00
|
|
|
#include "newgrf_roadtype.h"
|
2010-11-21 17:42:18 +00:00
|
|
|
#include "object_base.h"
|
2011-01-09 12:17:52 +00:00
|
|
|
#include "water.h"
|
2011-12-03 23:40:13 +00:00
|
|
|
#include "company_gui.h"
|
2019-03-11 10:37:47 +00:00
|
|
|
#include "station_func.h"
|
2021-10-05 20:02:27 +00:00
|
|
|
#include "tunnelbridge_cmd.h"
|
2021-10-29 23:31:46 +00:00
|
|
|
#include "landscape_cmd.h"
|
|
|
|
#include "terraform_cmd.h"
|
2005-08-01 16:31:19 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/bridge_land.h"
|
2007-12-16 15:38:51 +00:00
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2011-05-01 19:14:12 +00:00
|
|
|
BridgeSpec _bridge[MAX_BRIDGES]; ///< The specification of all bridges.
|
|
|
|
TileIndex _build_tunnel_endtile; ///< The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
|
2005-12-15 17:55:59 +00:00
|
|
|
|
2011-05-01 19:14:12 +00:00
|
|
|
/** Z position of the bridge sprites relative to bridge height (downwards) */
|
2010-10-16 15:34:59 +00:00
|
|
|
static const int BRIDGE_Z_START = 3;
|
|
|
|
|
2015-02-22 14:01:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark bridge tiles dirty.
|
|
|
|
* Note: The bridge does not need to exist, everything is passed via parameters.
|
|
|
|
* @param begin Start tile.
|
|
|
|
* @param end End tile.
|
|
|
|
* @param direction Direction from \a begin to \a end.
|
|
|
|
* @param bridge_height Bridge height level.
|
|
|
|
*/
|
|
|
|
void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
|
|
|
|
{
|
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(direction);
|
|
|
|
for (TileIndex t = begin; t != end; t += delta) {
|
|
|
|
MarkTileDirtyByTile(t, bridge_height - TileHeight(t));
|
|
|
|
}
|
|
|
|
MarkTileDirtyByTile(end);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark bridge tiles dirty.
|
|
|
|
* @param tile Bridge head.
|
|
|
|
*/
|
|
|
|
void MarkBridgeDirty(TileIndex tile)
|
|
|
|
{
|
|
|
|
MarkBridgeDirty(tile, GetOtherTunnelBridgeEnd(tile), GetTunnelBridgeDirection(tile), GetBridgeHeight(tile));
|
|
|
|
}
|
|
|
|
|
2008-02-05 04:48:56 +00:00
|
|
|
/** Reset the data been eventually changed by the grf loaded. */
|
|
|
|
void ResetBridges()
|
|
|
|
{
|
|
|
|
/* First, free sprite table data */
|
2008-02-11 04:12:30 +00:00
|
|
|
for (BridgeType i = 0; i < MAX_BRIDGES; i++) {
|
2019-04-10 21:07:06 +00:00
|
|
|
if (_bridge[i].sprite_table != nullptr) {
|
2008-07-15 00:34:34 +00:00
|
|
|
for (BridgePieces j = BRIDGE_PIECE_NORTH; j < BRIDGE_PIECE_INVALID; j++) free(_bridge[i].sprite_table[j]);
|
2008-02-05 04:48:56 +00:00
|
|
|
free(_bridge[i].sprite_table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 22:46:42 +00:00
|
|
|
/* Then, wipe out current bridges */
|
2008-02-05 04:48:56 +00:00
|
|
|
memset(&_bridge, 0, sizeof(_bridge));
|
|
|
|
/* And finally, reinstall default data */
|
|
|
|
memcpy(&_bridge, &_orig_bridge, sizeof(_orig_bridge));
|
|
|
|
}
|
2005-12-15 17:55:59 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Calculate the price factor for building a long bridge.
|
2010-03-20 15:23:26 +00:00
|
|
|
* 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,
|
|
|
|
* @param length Length of the bridge.
|
|
|
|
* @return Price factor for the bridge.
|
2007-04-04 03:21:14 +00:00
|
|
|
*/
|
2010-03-20 15:32:58 +00:00
|
|
|
int CalcBridgeLenCostFactor(int length)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-03-20 15:32:58 +00:00
|
|
|
if (length < 2) return length;
|
2010-03-20 16:45:23 +00:00
|
|
|
|
2010-03-20 15:32:58 +00:00
|
|
|
length -= 2;
|
2010-03-20 16:45:23 +00:00
|
|
|
int sum = 2;
|
|
|
|
for (int delta = 1;; delta++) {
|
|
|
|
for (int count = 0; count < delta; count++) {
|
|
|
|
if (length == 0) return sum;
|
|
|
|
sum += delta;
|
|
|
|
length--;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-02 20:59:54 +00:00
|
|
|
/**
|
|
|
|
* Get the foundation for a bridge.
|
|
|
|
* @param tileh The slope to build the bridge on.
|
2013-01-08 22:46:42 +00:00
|
|
|
* @param axis The axis of the bridge entrance.
|
|
|
|
* @return The foundation required.
|
2011-05-02 20:59:54 +00:00
|
|
|
*/
|
2008-01-21 15:48:00 +00:00
|
|
|
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
|
|
|
|
{
|
2010-03-20 15:30:57 +00:00
|
|
|
if (tileh == SLOPE_FLAT ||
|
|
|
|
((tileh == SLOPE_NE || tileh == SLOPE_SW) && axis == AXIS_X) ||
|
|
|
|
((tileh == SLOPE_NW || tileh == SLOPE_SE) && axis == AXIS_Y)) return FOUNDATION_NONE;
|
2008-01-21 15:48:00 +00:00
|
|
|
|
|
|
|
return (HasSlopeHighestCorner(tileh) ? InclinedFoundation(axis) : FlatteningFoundation(tileh));
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-22 16:08:17 +00:00
|
|
|
/**
|
|
|
|
* Determines if the track on a bridge ramp is flat or goes up/down.
|
|
|
|
*
|
|
|
|
* @param tileh Slope of the tile under the bridge head
|
|
|
|
* @param axis Orientation of bridge
|
|
|
|
* @return true iff the track is flat.
|
|
|
|
*/
|
|
|
|
bool HasBridgeFlatRamp(Slope tileh, Axis axis)
|
|
|
|
{
|
2011-11-04 10:28:31 +00:00
|
|
|
ApplyFoundationToSlope(GetBridgeFoundation(tileh, axis), &tileh);
|
2008-01-22 16:08:17 +00:00
|
|
|
/* If the foundation slope is flat the bridge has a non-flat ramp and vice versa. */
|
|
|
|
return (tileh != SLOPE_FLAT);
|
|
|
|
}
|
|
|
|
|
2008-07-15 00:34:34 +00:00
|
|
|
static inline const PalSpriteID *GetBridgeSpriteTable(int index, BridgePieces table)
|
2005-10-01 17:38:48 +00:00
|
|
|
{
|
2008-02-11 17:35:15 +00:00
|
|
|
const BridgeSpec *bridge = GetBridgeSpec(index);
|
2008-07-15 00:34:34 +00:00
|
|
|
assert(table < BRIDGE_PIECE_INVALID);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (bridge->sprite_table == nullptr || bridge->sprite_table[table] == nullptr) {
|
2005-10-01 17:38:48 +00:00
|
|
|
return _bridge_sprite_table[index][table];
|
|
|
|
} else {
|
|
|
|
return bridge->sprite_table[table];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-08 07:12:33 +00:00
|
|
|
|
2008-01-21 15:48:00 +00:00
|
|
|
/**
|
2018-10-17 19:52:16 +00:00
|
|
|
* Determines the foundation for the bridge head, and tests if the resulting slope is valid.
|
2008-01-21 15:48:00 +00:00
|
|
|
*
|
2018-10-17 19:52:16 +00:00
|
|
|
* @param bridge_piece Direction of the bridge head.
|
2008-01-21 15:48:00 +00:00
|
|
|
* @param axis Axis of the bridge
|
|
|
|
* @param tileh Slope of the tile under the north bridge head; returns slope on top of foundation
|
|
|
|
* @param z TileZ corresponding to tileh, gets modified as well
|
|
|
|
* @return Error or cost for bridge foundation
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2018-10-17 19:52:16 +00:00
|
|
|
static CommandCost CheckBridgeSlope(BridgePieces bridge_piece, Axis axis, Slope *tileh, int *z)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2018-10-17 19:52:16 +00:00
|
|
|
assert(bridge_piece == BRIDGE_PIECE_NORTH || bridge_piece == BRIDGE_PIECE_SOUTH);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-21 15:48:00 +00:00
|
|
|
Foundation f = GetBridgeFoundation(*tileh, axis);
|
2011-11-04 10:28:20 +00:00
|
|
|
*z += ApplyFoundationToSlope(f, tileh);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2018-10-17 19:52:16 +00:00
|
|
|
Slope valid_inclined;
|
|
|
|
if (bridge_piece == BRIDGE_PIECE_NORTH) {
|
|
|
|
valid_inclined = (axis == AXIS_X ? SLOPE_NE : SLOPE_NW);
|
|
|
|
} else {
|
|
|
|
valid_inclined = (axis == AXIS_X ? SLOPE_SW : SLOPE_SE);
|
|
|
|
}
|
2008-01-21 15:48:00 +00:00
|
|
|
if ((*tileh != SLOPE_FLAT) && (*tileh != valid_inclined)) return CMD_ERROR;
|
2006-08-08 07:12:33 +00:00
|
|
|
|
2008-01-21 15:48:00 +00:00
|
|
|
if (f == FOUNDATION_NONE) return CommandCost();
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2009-11-24 22:15:42 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-08-08 07:12:33 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Is a bridge of the specified type and length available?
|
2010-04-04 11:36:42 +00:00
|
|
|
* @param bridge_type Wanted type of bridge.
|
|
|
|
* @param bridge_len Wanted length of the bridge.
|
2018-10-28 02:17:36 +00:00
|
|
|
* @param flags Type of operation.
|
2010-04-04 14:22:55 +00:00
|
|
|
* @return A succeeded (the requested bridge is available) or failed (it cannot be built) command.
|
2010-04-04 11:36:42 +00:00
|
|
|
*/
|
2010-04-04 14:22:55 +00:00
|
|
|
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-06-23 08:38:07 +00:00
|
|
|
if (flags & DC_QUERY_COST) {
|
2011-02-04 15:37:23 +00:00
|
|
|
if (bridge_len <= _settings_game.construction.max_bridge_length) return CommandCost();
|
2010-04-04 14:22:55 +00:00
|
|
|
return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
|
2008-06-23 08:38:07 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-04-04 14:22:55 +00:00
|
|
|
if (bridge_type >= MAX_BRIDGES) return CMD_ERROR;
|
2008-06-23 08:38:07 +00:00
|
|
|
|
|
|
|
const BridgeSpec *b = GetBridgeSpec(bridge_type);
|
2010-04-04 14:22:55 +00:00
|
|
|
if (b->avail_year > _cur_year) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2021-01-08 10:16:18 +00:00
|
|
|
uint max = std::min(b->max_length, _settings_game.construction.max_bridge_length);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-04-04 14:22:55 +00:00
|
|
|
if (b->min_length > bridge_len) return CMD_ERROR;
|
|
|
|
if (bridge_len <= max) return CommandCost();
|
|
|
|
return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 20:12:32 +00:00
|
|
|
/**
|
|
|
|
* Calculate the base cost of clearing a tunnel/bridge per tile.
|
|
|
|
* @param tile Start tile of the tunnel/bridge.
|
|
|
|
* @return How much clearing this tunnel/bridge costs per tile.
|
|
|
|
*/
|
|
|
|
static Money TunnelBridgeClearCost(TileIndex tile, Price base_price)
|
|
|
|
{
|
|
|
|
Money base_cost = _price[base_price];
|
|
|
|
|
|
|
|
/* Add the cost of the transport that is on the tunnel/bridge. */
|
|
|
|
switch (GetTunnelBridgeTransportType(tile)) {
|
|
|
|
case TRANSPORT_ROAD: {
|
|
|
|
RoadType road_rt = GetRoadTypeRoad(tile);
|
|
|
|
RoadType tram_rt = GetRoadTypeTram(tile);
|
|
|
|
|
|
|
|
if (road_rt != INVALID_ROADTYPE) {
|
|
|
|
base_cost += 2 * RoadClearCost(road_rt);
|
|
|
|
}
|
|
|
|
if (tram_rt != INVALID_ROADTYPE) {
|
|
|
|
base_cost += 2 * RoadClearCost(tram_rt);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case TRANSPORT_RAIL: base_cost += RailClearCost(GetRailType(tile)); break;
|
|
|
|
/* Aquaducts have their own clear price. */
|
|
|
|
case TRANSPORT_WATER: base_cost = _price[PR_CLEAR_AQUEDUCT]; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base_cost;
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Build a Bridge
|
2007-04-04 03:21:14 +00:00
|
|
|
* @param flags type of operation
|
2021-11-14 23:03:01 +00:00
|
|
|
* @param tile_end end tile
|
|
|
|
* @param tile_start start tile
|
|
|
|
* @param transport_type transport type.
|
|
|
|
* @param bridge_type bridge type (hi bh)
|
|
|
|
* @param road_rail_type rail type or road types.
|
2009-09-18 14:23:58 +00:00
|
|
|
* @return the cost of this operation or an error
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2021-11-14 23:03:01 +00:00
|
|
|
CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex tile_start, TransportType transport_type, BridgeType bridge_type, byte road_rail_type)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2011-12-19 21:02:33 +00:00
|
|
|
CompanyID company = _current_company;
|
|
|
|
|
2008-02-11 01:06:44 +00:00
|
|
|
RailType railtype = INVALID_RAILTYPE;
|
2019-04-06 06:46:15 +00:00
|
|
|
RoadType roadtype = INVALID_ROADTYPE;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2021-11-14 23:03:01 +00:00
|
|
|
if (!IsValidTile(tile_start)) return_cmd_error(STR_ERROR_BRIDGE_THROUGH_MAP_BORDER);
|
2008-02-11 03:22:44 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* type of bridge */
|
2008-02-11 01:06:44 +00:00
|
|
|
switch (transport_type) {
|
|
|
|
case TRANSPORT_ROAD:
|
2021-11-14 23:03:01 +00:00
|
|
|
roadtype = (RoadType)road_rail_type;
|
2019-04-06 06:46:15 +00:00
|
|
|
if (!ValParamRoadType(roadtype)) return CMD_ERROR;
|
2008-02-11 01:06:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TRANSPORT_RAIL:
|
2021-11-14 23:03:01 +00:00
|
|
|
railtype = (RailType)road_rail_type;
|
2008-02-11 01:06:44 +00:00
|
|
|
if (!ValParamRailtype(railtype)) return CMD_ERROR;
|
|
|
|
break;
|
2008-02-11 03:22:44 +00:00
|
|
|
|
2008-06-11 13:54:01 +00:00
|
|
|
case TRANSPORT_WATER:
|
|
|
|
break;
|
|
|
|
|
2008-02-11 03:22:44 +00:00
|
|
|
default:
|
2009-07-30 19:30:13 +00:00
|
|
|
/* Airports don't have bridges. */
|
2008-02-11 03:22:44 +00:00
|
|
|
return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:02:33 +00:00
|
|
|
if (company == OWNER_DEITY) {
|
|
|
|
if (transport_type != TRANSPORT_ROAD) return CMD_ERROR;
|
|
|
|
const Town *town = CalcClosestTownFromTile(tile_start);
|
|
|
|
|
|
|
|
company = OWNER_TOWN;
|
|
|
|
|
|
|
|
/* If we are not within a town, we are not owned by the town */
|
2019-04-10 21:07:06 +00:00
|
|
|
if (town == nullptr || DistanceSquare(tile_start, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
|
2011-12-19 21:02:33 +00:00
|
|
|
company = OWNER_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-30 19:30:13 +00:00
|
|
|
if (tile_start == tile_end) {
|
2009-08-05 17:59:21 +00:00
|
|
|
return_cmd_error(STR_ERROR_CAN_T_START_AND_END_ON);
|
2009-07-30 19:30:13 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-07-30 19:30:13 +00:00
|
|
|
Axis direction;
|
|
|
|
if (TileX(tile_start) == TileX(tile_end)) {
|
2006-03-08 06:55:33 +00:00
|
|
|
direction = AXIS_Y;
|
2009-07-30 19:30:13 +00:00
|
|
|
} else if (TileY(tile_start) == TileY(tile_end)) {
|
2006-03-08 06:55:33 +00:00
|
|
|
direction = AXIS_X;
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_START_AND_END_MUST_BE_IN);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-07-30 19:30:13 +00:00
|
|
|
if (tile_end < tile_start) Swap(tile_start, tile_end);
|
|
|
|
|
|
|
|
uint bridge_len = GetTunnelBridgeLength(tile_start, tile_end);
|
2008-06-11 13:54:01 +00:00
|
|
|
if (transport_type != TRANSPORT_WATER) {
|
|
|
|
/* set and test bridge length, availability */
|
2010-04-04 14:22:55 +00:00
|
|
|
CommandCost ret = CheckBridgeAvailability(bridge_type, bridge_len, flags);
|
|
|
|
if (ret.Failed()) return ret;
|
2009-12-04 22:02:37 +00:00
|
|
|
} else {
|
2011-02-04 15:37:23 +00:00
|
|
|
if (bridge_len > _settings_game.construction.max_bridge_length) return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
|
2008-06-11 13:54:01 +00:00
|
|
|
}
|
2021-01-06 18:39:20 +00:00
|
|
|
bridge_len += 2; // begin and end tiles/ramps
|
2005-05-09 13:26:15 +00:00
|
|
|
|
2011-11-04 11:30:37 +00:00
|
|
|
int z_start;
|
|
|
|
int z_end;
|
2011-11-04 10:28:20 +00:00
|
|
|
Slope tileh_start = GetTileSlope(tile_start, &z_start);
|
|
|
|
Slope tileh_end = GetTileSlope(tile_end, &z_end);
|
2010-03-10 20:44:04 +00:00
|
|
|
bool pbs_reservation = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2018-10-17 19:52:16 +00:00
|
|
|
CommandCost terraform_cost_north = CheckBridgeSlope(BRIDGE_PIECE_NORTH, direction, &tileh_start, &z_start);
|
|
|
|
CommandCost terraform_cost_south = CheckBridgeSlope(BRIDGE_PIECE_SOUTH, direction, &tileh_end, &z_end);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-12-11 18:28:34 +00:00
|
|
|
/* Aqueducts can't be built of flat land. */
|
|
|
|
if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2009-08-05 17:59:21 +00:00
|
|
|
if (z_start != z_end) return_cmd_error(STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT);
|
2005-03-27 15:56:54 +00:00
|
|
|
|
2010-03-20 16:47:07 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
|
|
|
Owner owner;
|
2013-05-07 13:49:18 +00:00
|
|
|
bool is_new_owner;
|
2019-04-06 06:46:15 +00:00
|
|
|
RoadType road_rt = INVALID_ROADTYPE;
|
|
|
|
RoadType tram_rt = INVALID_ROADTYPE;
|
2007-02-03 21:55:14 +00:00
|
|
|
if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
|
|
|
|
GetOtherBridgeEnd(tile_start) == tile_end &&
|
2007-12-16 15:38:51 +00:00
|
|
|
GetTunnelBridgeTransportType(tile_start) == transport_type) {
|
2007-02-03 21:55:14 +00:00
|
|
|
/* Replace a current bridge. */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2019-04-06 06:46:15 +00:00
|
|
|
switch (transport_type) {
|
|
|
|
case TRANSPORT_RAIL:
|
|
|
|
/* Keep the reservation, the path stays valid. */
|
|
|
|
pbs_reservation = HasTunnelBridgeReservation(tile_start);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRANSPORT_ROAD:
|
|
|
|
/* Do not remove road types when upgrading a bridge */
|
|
|
|
road_rt = GetRoadTypeRoad(tile_start);
|
|
|
|
tram_rt = GetRoadTypeTram(tile_start);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2007-02-03 21:55:14 +00:00
|
|
|
/* If this is a railway bridge, make sure the railtypes match. */
|
|
|
|
if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
2007-02-03 21:55:14 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 06:46:15 +00:00
|
|
|
/* If this is a road bridge, make sure the roadtype matches. */
|
|
|
|
if (transport_type == TRANSPORT_ROAD) {
|
|
|
|
RoadType existing_rt = RoadTypeIsRoad(roadtype) ? road_rt : tram_rt;
|
|
|
|
if (existing_rt != roadtype && existing_rt != INVALID_ROADTYPE) {
|
|
|
|
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 17:56:43 +00:00
|
|
|
/* Do not replace town bridges with lower speed bridges, unless in scenario editor. */
|
2007-02-03 21:55:14 +00:00
|
|
|
if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
|
2013-01-08 17:56:43 +00:00
|
|
|
GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed &&
|
|
|
|
_game_mode != GM_EDITOR) {
|
2007-02-03 21:55:14 +00:00
|
|
|
Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
if (t == nullptr) {
|
2007-02-03 21:55:14 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
} else {
|
|
|
|
SetDParam(0, t->index);
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
|
2007-02-03 21:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-03 21:55:14 +00:00
|
|
|
/* Do not replace the bridge with the same bridge type. */
|
2019-04-06 06:46:15 +00:00
|
|
|
if (!(flags & DC_QUERY_COST) && (bridge_type == GetBridgeType(tile_start)) && (transport_type != TRANSPORT_ROAD || road_rt == roadtype || tram_rt == roadtype)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
2007-02-03 21:55:14 +00:00
|
|
|
}
|
2005-03-27 15:56:54 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Do not allow replacing another company's bridges. */
|
2013-05-06 15:41:34 +00:00
|
|
|
if (!IsTileOwner(tile_start, company) && !IsTileOwner(tile_start, OWNER_TOWN) && !IsTileOwner(tile_start, OWNER_NONE)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
|
2007-02-03 21:55:14 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2021-01-06 20:12:32 +00:00
|
|
|
/* The cost of clearing the current bridge. */
|
|
|
|
cost.AddCost(bridge_len * TunnelBridgeClearCost(tile_start, PR_CLEAR_BRIDGE));
|
2009-07-30 19:30:13 +00:00
|
|
|
owner = GetTileOwner(tile_start);
|
2007-05-26 20:30:40 +00:00
|
|
|
|
2013-05-06 15:41:34 +00:00
|
|
|
/* If bridge belonged to bankrupt company, it has a new owner now */
|
2013-05-07 13:49:18 +00:00
|
|
|
is_new_owner = (owner == OWNER_NONE);
|
|
|
|
if (is_new_owner) owner = company;
|
2007-02-03 21:55:14 +00:00
|
|
|
} else {
|
|
|
|
/* Build a new bridge. */
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
bool allow_on_slopes = (_settings_game.construction.build_on_slopes && transport_type != TRANSPORT_WATER);
|
2008-01-21 15:48:00 +00:00
|
|
|
|
2007-02-03 21:55:14 +00:00
|
|
|
/* Try and clear the start landscape */
|
2021-11-21 22:02:29 +00:00
|
|
|
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_start);
|
2010-01-18 22:57:21 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2007-02-03 21:55:14 +00:00
|
|
|
cost = ret;
|
|
|
|
|
2010-07-24 10:14:39 +00:00
|
|
|
if (terraform_cost_north.Failed() || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2008-01-21 15:48:00 +00:00
|
|
|
cost.AddCost(terraform_cost_north);
|
2007-02-03 21:55:14 +00:00
|
|
|
|
|
|
|
/* Try and clear the end landscape */
|
2021-11-21 22:02:29 +00:00
|
|
|
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_end);
|
2010-01-18 22:57:21 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2007-02-03 21:55:14 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* false - end tile slope check */
|
2010-07-24 10:14:39 +00:00
|
|
|
if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2008-01-21 15:48:00 +00:00
|
|
|
cost.AddCost(terraform_cost_south);
|
2008-06-11 14:13:07 +00:00
|
|
|
|
2009-09-20 23:11:01 +00:00
|
|
|
const TileIndex heads[] = {tile_start, tile_end};
|
2009-07-30 19:30:13 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
2014-09-21 11:24:51 +00:00
|
|
|
if (IsBridgeAbove(heads[i])) {
|
|
|
|
TileIndex north_head = GetNorthernBridgeEnd(heads[i]);
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2014-09-21 11:24:51 +00:00
|
|
|
if (direction == GetBridgeAxis(heads[i])) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2014-09-21 11:24:51 +00:00
|
|
|
if (z_start + 1 == GetBridgeHeight(north_head)) {
|
|
|
|
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-30 19:30:13 +00:00
|
|
|
|
|
|
|
TileIndexDiff delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
|
|
|
for (TileIndex tile = tile_start + delta; tile != tile_end; tile += delta) {
|
2011-11-04 10:28:20 +00:00
|
|
|
if (GetTileMaxZ(tile) > z_start) return_cmd_error(STR_ERROR_BRIDGE_TOO_LOW_FOR_TERRAIN);
|
2009-07-30 19:30:13 +00:00
|
|
|
|
2014-09-21 11:40:11 +00:00
|
|
|
if (z_start >= (GetTileZ(tile) + _settings_game.construction.max_bridge_height)) {
|
|
|
|
/*
|
|
|
|
* Disallow too high bridges.
|
|
|
|
* Properly rendering a map where very high bridges (might) exist is expensive.
|
|
|
|
* See http://www.tt-forums.net/viewtopic.php?f=33&t=40844&start=980#p1131762
|
|
|
|
* for a detailed discussion. z_start here is one heightlevel below the bridge level.
|
|
|
|
*/
|
|
|
|
return_cmd_error(STR_ERROR_BRIDGE_TOO_HIGH_FOR_TERRAIN);
|
|
|
|
}
|
|
|
|
|
2014-09-21 11:24:51 +00:00
|
|
|
if (IsBridgeAbove(tile)) {
|
2009-07-30 19:30:13 +00:00
|
|
|
/* Disallow crossing bridges for the time being */
|
|
|
|
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (GetTileType(tile)) {
|
|
|
|
case MP_WATER:
|
|
|
|
if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_RAILWAY:
|
|
|
|
if (!IsPlainRail(tile)) goto not_valid_below;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_ROAD:
|
|
|
|
if (IsRoadDepot(tile)) goto not_valid_below;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
|
|
|
if (IsTunnel(tile)) break;
|
|
|
|
if (direction == DiagDirToAxis(GetTunnelBridgeDirection(tile))) goto not_valid_below;
|
2011-11-04 10:28:20 +00:00
|
|
|
if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
|
2009-07-30 19:30:13 +00:00
|
|
|
break;
|
|
|
|
|
2010-08-08 10:59:30 +00:00
|
|
|
case MP_OBJECT: {
|
|
|
|
const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
|
2010-08-03 12:07:55 +00:00
|
|
|
if ((spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) == 0) goto not_valid_below;
|
2011-11-04 10:28:20 +00:00
|
|
|
if (GetTileMaxZ(tile) + spec->height > z_start) goto not_valid_below;
|
2009-07-30 19:30:13 +00:00
|
|
|
break;
|
2010-08-03 12:07:55 +00:00
|
|
|
}
|
2009-07-30 19:30:13 +00:00
|
|
|
|
|
|
|
case MP_CLEAR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
not_valid_below:;
|
|
|
|
/* try and clear the middle landscape */
|
2021-11-21 22:02:29 +00:00
|
|
|
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
|
2010-01-18 22:57:21 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2009-07-30 19:30:13 +00:00
|
|
|
cost.AddCost(ret);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2009-07-30 19:51:29 +00:00
|
|
|
/* We do this here because when replacing a bridge with another
|
|
|
|
* type calling SetBridgeMiddle isn't needed. After all, the
|
2013-01-08 22:46:42 +00:00
|
|
|
* tile already has the has_bridge_above bits set. */
|
2009-07-30 19:30:13 +00:00
|
|
|
SetBridgeMiddle(tile, direction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:02:33 +00:00
|
|
|
owner = company;
|
2013-05-07 13:49:18 +00:00
|
|
|
is_new_owner = true;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2005-03-27 15:56:54 +00:00
|
|
|
|
2019-04-06 06:46:15 +00:00
|
|
|
bool hasroad = road_rt != INVALID_ROADTYPE;
|
|
|
|
bool hastram = tram_rt != INVALID_ROADTYPE;
|
|
|
|
if (transport_type == TRANSPORT_ROAD) {
|
|
|
|
if (RoadTypeIsRoad(roadtype)) road_rt = roadtype;
|
|
|
|
if (RoadTypeIsTram(roadtype)) tram_rt = roadtype;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* do the drill? */
|
|
|
|
if (flags & DC_EXEC) {
|
2006-03-15 07:10:41 +00:00
|
|
|
DiagDirection dir = AxisToDiagDir(direction);
|
|
|
|
|
2015-06-21 09:52:30 +00:00
|
|
|
Company *c = Company::GetIfValid(company);
|
2008-02-11 01:06:44 +00:00
|
|
|
switch (transport_type) {
|
|
|
|
case TRANSPORT_RAIL:
|
2013-05-07 13:49:18 +00:00
|
|
|
/* Add to company infrastructure count if required. */
|
2021-01-06 18:39:20 +00:00
|
|
|
if (is_new_owner && c != nullptr) c->infrastructure.rail[railtype] += bridge_len * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
2008-02-21 16:05:33 +00:00
|
|
|
MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype);
|
2008-02-11 01:06:44 +00:00
|
|
|
MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype);
|
2010-03-10 20:44:04 +00:00
|
|
|
SetTunnelBridgeReservation(tile_start, pbs_reservation);
|
|
|
|
SetTunnelBridgeReservation(tile_end, pbs_reservation);
|
2008-02-11 01:06:44 +00:00
|
|
|
break;
|
|
|
|
|
2013-01-13 13:17:12 +00:00
|
|
|
case TRANSPORT_ROAD: {
|
2013-05-07 13:49:18 +00:00
|
|
|
if (is_new_owner) {
|
|
|
|
/* Also give unowned present roadtypes to new owner */
|
2019-04-06 06:46:15 +00:00
|
|
|
if (hasroad && GetRoadOwner(tile_start, RTT_ROAD) == OWNER_NONE) hasroad = false;
|
|
|
|
if (hastram && GetRoadOwner(tile_start, RTT_TRAM) == OWNER_NONE) hastram = false;
|
2013-05-07 13:49:18 +00:00
|
|
|
}
|
2019-04-10 21:07:06 +00:00
|
|
|
if (c != nullptr) {
|
2011-12-03 23:40:18 +00:00
|
|
|
/* Add all new road types to the company infrastructure counter. */
|
2019-04-06 06:46:15 +00:00
|
|
|
if (!hasroad && road_rt != INVALID_ROADTYPE) {
|
2011-12-03 23:40:18 +00:00
|
|
|
/* A full diagonal road tile has two road bits. */
|
2021-01-06 18:39:20 +00:00
|
|
|
c->infrastructure.road[road_rt] += bridge_len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
2019-04-06 06:46:15 +00:00
|
|
|
}
|
|
|
|
if (!hastram && tram_rt != INVALID_ROADTYPE) {
|
|
|
|
/* A full diagonal road tile has two road bits. */
|
2021-01-06 18:39:20 +00:00
|
|
|
c->infrastructure.road[tram_rt] += bridge_len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
2011-12-03 23:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-06 06:46:15 +00:00
|
|
|
Owner owner_road = hasroad ? GetRoadOwner(tile_start, RTT_ROAD) : company;
|
|
|
|
Owner owner_tram = hastram ? GetRoadOwner(tile_start, RTT_TRAM) : company;
|
|
|
|
MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, road_rt, tram_rt);
|
|
|
|
MakeRoadBridgeRamp(tile_end, owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), road_rt, tram_rt);
|
2008-02-11 01:06:44 +00:00
|
|
|
break;
|
2013-01-13 13:17:12 +00:00
|
|
|
}
|
2008-02-11 03:22:44 +00:00
|
|
|
|
2008-06-11 13:54:01 +00:00
|
|
|
case TRANSPORT_WATER:
|
2021-01-06 18:39:20 +00:00
|
|
|
if (is_new_owner && c != nullptr) c->infrastructure.water += bridge_len * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
2008-06-11 13:54:01 +00:00
|
|
|
MakeAqueductBridgeRamp(tile_start, owner, dir);
|
|
|
|
MakeAqueductBridgeRamp(tile_end, owner, ReverseDiagDir(dir));
|
2019-03-11 10:37:47 +00:00
|
|
|
CheckForDockingTile(tile_start);
|
|
|
|
CheckForDockingTile(tile_end);
|
2008-06-11 13:54:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-02-11 03:22:44 +00:00
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
2006-03-15 07:10:41 +00:00
|
|
|
}
|
2009-07-30 19:51:29 +00:00
|
|
|
|
|
|
|
/* Mark all tiles dirty */
|
2015-02-22 14:01:24 +00:00
|
|
|
MarkBridgeDirty(tile_start, tile_end, AxisToDiagDir(direction), z_start);
|
2015-06-21 09:52:30 +00:00
|
|
|
DirtyCompanyInfrastructureWindows(company);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 11:43:36 +00:00
|
|
|
if ((flags & DC_EXEC) && transport_type == TRANSPORT_RAIL) {
|
2007-01-07 16:35:20 +00:00
|
|
|
Track track = AxisToTrack(direction);
|
2011-12-19 21:02:33 +00:00
|
|
|
AddSideToSignalBuffer(tile_start, INVALID_DIAGDIR, company);
|
2007-01-07 16:35:20 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile_start, track);
|
2007-01-07 00:19:57 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2019-12-31 12:43:18 +00:00
|
|
|
/* Human players that build bridges get a selection to choose from (DC_QUERY_COST)
|
|
|
|
* It's unnecessary to execute this command every time for every bridge.
|
|
|
|
* So it is done only for humans and cost is computed in bridge_gui.cpp.
|
|
|
|
* For (non-spectated) AI, Towns this has to be of course calculated. */
|
2011-12-19 21:02:33 +00:00
|
|
|
Company *c = Company::GetIfValid(company);
|
2019-12-31 12:43:18 +00:00
|
|
|
if (!(flags & DC_QUERY_COST) || (c != nullptr && c->is_ai && company != _local_company)) {
|
2010-05-22 14:12:48 +00:00
|
|
|
switch (transport_type) {
|
2019-04-06 06:46:15 +00:00
|
|
|
case TRANSPORT_ROAD:
|
|
|
|
if (road_rt != INVALID_ROADTYPE) {
|
|
|
|
cost.AddCost(bridge_len * 2 * RoadBuildCost(road_rt));
|
|
|
|
}
|
|
|
|
if (tram_rt != INVALID_ROADTYPE) {
|
|
|
|
cost.AddCost(bridge_len * 2 * RoadBuildCost(tram_rt));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-05-22 14:12:48 +00:00
|
|
|
case TRANSPORT_RAIL: cost.AddCost(bridge_len * RailBuildCost(railtype)); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
if (c != nullptr) bridge_len = CalcBridgeLenCostFactor(bridge_len);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-04-25 13:47:13 +00:00
|
|
|
if (transport_type != TRANSPORT_WATER) {
|
|
|
|
cost.AddCost((int64)bridge_len * _price[PR_BUILD_BRIDGE] * GetBridgeSpec(bridge_type)->price >> 8);
|
|
|
|
} else {
|
|
|
|
/* Aqueducts use a separate base cost. */
|
2010-04-25 13:56:51 +00:00
|
|
|
cost.AddCost((int64)bridge_len * _price[PR_BUILD_AQUEDUCT]);
|
2010-04-25 13:47:13 +00:00
|
|
|
}
|
2008-06-11 14:51:31 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Build Tunnel.
|
2007-04-04 03:21:14 +00:00
|
|
|
* @param flags type of operation
|
2021-10-10 00:08:52 +00:00
|
|
|
* @param start_tile start tile of tunnel
|
2021-11-14 23:03:01 +00:00
|
|
|
* @param transport_type transport type
|
|
|
|
* @param road_rail_type railtype or roadtype
|
2009-09-18 14:23:58 +00:00
|
|
|
* @return the cost of this operation or an error
|
2006-02-22 21:09:55 +00:00
|
|
|
*/
|
2021-11-14 23:03:01 +00:00
|
|
|
CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, TransportType transport_type, byte road_rail_type)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2011-12-19 21:02:33 +00:00
|
|
|
CompanyID company = _current_company;
|
|
|
|
|
2010-04-14 20:28:37 +00:00
|
|
|
RailType railtype = INVALID_RAILTYPE;
|
2019-04-06 06:46:15 +00:00
|
|
|
RoadType roadtype = INVALID_ROADTYPE;
|
2006-02-22 21:09:55 +00:00
|
|
|
_build_tunnel_endtile = 0;
|
2010-04-14 20:28:37 +00:00
|
|
|
switch (transport_type) {
|
|
|
|
case TRANSPORT_RAIL:
|
2021-11-14 23:03:01 +00:00
|
|
|
railtype = (RailType)road_rail_type;
|
2010-04-14 20:28:37 +00:00
|
|
|
if (!ValParamRailtype(railtype)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRANSPORT_ROAD:
|
2021-11-14 23:03:01 +00:00
|
|
|
roadtype = (RoadType)road_rail_type;
|
2019-04-06 06:46:15 +00:00
|
|
|
if (!ValParamRoadType(roadtype)) return CMD_ERROR;
|
2010-04-14 20:28:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: return CMD_ERROR;
|
2007-05-20 19:14:08 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-12-19 21:02:33 +00:00
|
|
|
if (company == OWNER_DEITY) {
|
|
|
|
if (transport_type != TRANSPORT_ROAD) return CMD_ERROR;
|
|
|
|
const Town *town = CalcClosestTownFromTile(start_tile);
|
|
|
|
|
|
|
|
company = OWNER_TOWN;
|
|
|
|
|
|
|
|
/* If we are not within a town, we are not owned by the town */
|
2019-04-10 21:07:06 +00:00
|
|
|
if (town == nullptr || DistanceSquare(start_tile, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
|
2011-12-19 21:02:33 +00:00
|
|
|
company = OWNER_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 11:30:37 +00:00
|
|
|
int start_z;
|
|
|
|
int end_z;
|
2011-11-04 10:28:31 +00:00
|
|
|
Slope start_tileh = GetTileSlope(start_tile, &start_z);
|
2009-07-30 19:30:13 +00:00
|
|
|
DiagDirection direction = GetInclinedSlopeDirection(start_tileh);
|
2009-04-21 23:40:56 +00:00
|
|
|
if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE_FOR_TUNNEL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-11-21 18:39:12 +00:00
|
|
|
if (HasTileWaterGround(start_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
2008-01-23 08:28:19 +00:00
|
|
|
|
2021-11-21 22:02:29 +00:00
|
|
|
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, start_tile);
|
2010-01-18 22:57:21 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-15 00:14:57 +00:00
|
|
|
/* XXX - do NOT change 'ret' in the loop, as it is used as the price
|
|
|
|
* for the clearing of the entrance of the tunnel. Assigning it to
|
|
|
|
* cost before the loop will yield different costs depending on start-
|
|
|
|
* position, because of increased-cost-by-length: 'cost += cost >> 3' */
|
2007-06-18 19:53:50 +00:00
|
|
|
|
2009-07-30 19:30:13 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(direction);
|
2007-06-21 17:25:17 +00:00
|
|
|
DiagDirection tunnel_in_way_dir;
|
2008-05-14 18:31:21 +00:00
|
|
|
if (DiagDirToAxis(direction) == AXIS_Y) {
|
2007-06-21 17:25:17 +00:00
|
|
|
tunnel_in_way_dir = (TileX(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SW : DIAGDIR_NE;
|
|
|
|
} else {
|
|
|
|
tunnel_in_way_dir = (TileY(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SE : DIAGDIR_NW;
|
|
|
|
}
|
|
|
|
|
2009-07-30 19:30:13 +00:00
|
|
|
TileIndex end_tile = start_tile;
|
2007-06-27 19:00:14 +00:00
|
|
|
|
2013-01-08 22:46:42 +00:00
|
|
|
/* Tile shift coefficient. Will decrease for very long tunnels to avoid exponential growth of price*/
|
2007-06-27 19:00:14 +00:00
|
|
|
int tiles_coef = 3;
|
2009-07-30 19:30:13 +00:00
|
|
|
/* Number of tiles from start of tunnel */
|
2007-06-27 19:00:14 +00:00
|
|
|
int tiles = 0;
|
2009-07-30 19:30:13 +00:00
|
|
|
/* Number of tiles at which the cost increase coefficient per tile is halved */
|
2007-07-23 16:15:40 +00:00
|
|
|
int tiles_bump = 25;
|
2007-06-27 19:00:14 +00:00
|
|
|
|
2010-03-20 16:47:07 +00:00
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
2009-07-30 19:30:13 +00:00
|
|
|
Slope end_tileh;
|
2006-02-22 21:09:55 +00:00
|
|
|
for (;;) {
|
|
|
|
end_tile += delta;
|
2009-08-05 17:59:21 +00:00
|
|
|
if (!IsValidTile(end_tile)) return_cmd_error(STR_ERROR_TUNNEL_THROUGH_MAP_BORDER);
|
2011-11-04 10:28:31 +00:00
|
|
|
end_tileh = GetTileSlope(end_tile, &end_z);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-22 21:09:55 +00:00
|
|
|
if (start_z == end_z) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-21 17:25:17 +00:00
|
|
|
if (!_cheats.crossing_tunnels.value && IsTunnelInWayDir(end_tile, start_z, tunnel_in_way_dir)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY);
|
2006-02-22 21:09:55 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-27 19:00:14 +00:00
|
|
|
tiles++;
|
2007-07-23 16:15:40 +00:00
|
|
|
if (tiles == tiles_bump) {
|
|
|
|
tiles_coef++;
|
|
|
|
tiles_bump *= 2;
|
|
|
|
}
|
2007-06-27 19:00:14 +00:00
|
|
|
|
2009-11-07 22:47:54 +00:00
|
|
|
cost.AddCost(_price[PR_BUILD_TUNNEL]);
|
2007-06-27 19:00:14 +00:00
|
|
|
cost.AddCost(cost.GetCost() >> tiles_coef); // add a multiplier for longer tunnels
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-15 00:14:57 +00:00
|
|
|
/* Add the cost of the entrance */
|
2009-11-07 22:47:54 +00:00
|
|
|
cost.AddCost(_price[PR_BUILD_TUNNEL]);
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2006-08-15 00:14:57 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* if the command fails from here on we want the end tile to be highlighted */
|
2006-02-22 21:09:55 +00:00
|
|
|
_build_tunnel_endtile = end_tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-02-04 15:37:23 +00:00
|
|
|
if (tiles > _settings_game.construction.max_tunnel_length) return_cmd_error(STR_ERROR_TUNNEL_TOO_LONG);
|
|
|
|
|
2010-11-21 18:39:12 +00:00
|
|
|
if (HasTileWaterGround(end_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
2008-01-23 08:28:19 +00:00
|
|
|
|
2010-11-21 17:42:18 +00:00
|
|
|
/* Clear the tile in any case */
|
2021-11-21 22:02:29 +00:00
|
|
|
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, end_tile);
|
2010-11-21 17:42:18 +00:00
|
|
|
if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
|
|
|
|
cost.AddCost(ret);
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* slope of end tile must be complementary to the slope of the start tile */
|
2006-04-23 13:48:16 +00:00
|
|
|
if (end_tileh != ComplementSlope(start_tileh)) {
|
2010-11-21 17:42:18 +00:00
|
|
|
/* Mark the tile as already cleared for the terraform command.
|
|
|
|
* Do this for all tiles (like trees), not only objects. */
|
|
|
|
ClearedObjectArea *coa = FindClearedObject(end_tile);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (coa == nullptr) {
|
2020-12-14 23:22:04 +00:00
|
|
|
coa = &_cleared_object_areas.emplace_back(ClearedObjectArea{ end_tile, TileArea(end_tile, 1, 1) });
|
2010-11-21 17:42:18 +00:00
|
|
|
}
|
2007-10-05 17:55:12 +00:00
|
|
|
|
2010-11-21 17:42:18 +00:00
|
|
|
/* Hide the tile from the terraforming command */
|
|
|
|
TileIndex old_first_tile = coa->first_tile;
|
|
|
|
coa->first_tile = INVALID_TILE;
|
2018-07-22 12:25:28 +00:00
|
|
|
|
|
|
|
/* CMD_TERRAFORM_LAND may append further items to _cleared_object_areas,
|
|
|
|
* however it will never erase or re-order existing items.
|
2020-12-24 16:10:44 +00:00
|
|
|
* _cleared_object_areas is a value-type self-resizing vector, therefore appending items
|
2018-07-22 12:25:28 +00:00
|
|
|
* may result in a backing-store re-allocation, which would invalidate the coa pointer.
|
|
|
|
* The index of the coa pointer into the _cleared_object_areas vector remains valid,
|
|
|
|
* and can be used safely after the CMD_TERRAFORM_LAND operation.
|
|
|
|
* Deliberately clear the coa pointer to avoid leaving dangling pointers which could
|
|
|
|
* inadvertently be dereferenced.
|
|
|
|
*/
|
2019-02-17 11:20:52 +00:00
|
|
|
ClearedObjectArea *begin = _cleared_object_areas.data();
|
|
|
|
assert(coa >= begin && coa < begin + _cleared_object_areas.size());
|
|
|
|
size_t coa_index = coa - begin;
|
2019-01-05 13:30:59 +00:00
|
|
|
assert(coa_index < UINT_MAX); // more than 2**32 cleared areas would be a bug in itself
|
2019-04-10 21:07:06 +00:00
|
|
|
coa = nullptr;
|
2018-07-22 12:25:28 +00:00
|
|
|
|
2021-11-30 23:44:57 +00:00
|
|
|
ret = std::get<0>(Command<CMD_TERRAFORM_LAND>::Do(flags, end_tile, end_tileh & start_tileh, false));
|
2019-01-05 13:30:59 +00:00
|
|
|
_cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
|
2010-01-18 22:57:21 +00:00
|
|
|
if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
|
2010-11-21 17:42:18 +00:00
|
|
|
cost.AddCost(ret);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-11-07 22:47:54 +00:00
|
|
|
cost.AddCost(_price[PR_BUILD_TUNNEL]);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-05-22 14:12:48 +00:00
|
|
|
/* Pay for the rail/road in the tunnel including entrances */
|
|
|
|
switch (transport_type) {
|
2019-04-06 06:46:15 +00:00
|
|
|
case TRANSPORT_ROAD: cost.AddCost((tiles + 2) * RoadBuildCost(roadtype) * 2); break;
|
2010-05-22 14:12:48 +00:00
|
|
|
case TRANSPORT_RAIL: cost.AddCost((tiles + 2) * RailBuildCost(railtype)); break;
|
2013-11-23 18:13:30 +00:00
|
|
|
default: NOT_REACHED();
|
2010-05-22 14:12:48 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2011-12-19 21:02:33 +00:00
|
|
|
Company *c = Company::GetIfValid(company);
|
2011-12-03 23:40:13 +00:00
|
|
|
uint num_pieces = (tiles + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
2008-02-13 03:21:19 +00:00
|
|
|
if (transport_type == TRANSPORT_RAIL) {
|
2019-04-06 06:46:15 +00:00
|
|
|
if (c != nullptr) c->infrastructure.rail[railtype] += num_pieces;
|
2011-12-19 21:02:33 +00:00
|
|
|
MakeRailTunnel(start_tile, company, direction, railtype);
|
|
|
|
MakeRailTunnel(end_tile, company, ReverseDiagDir(direction), railtype);
|
|
|
|
AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, company);
|
2008-05-14 18:31:21 +00:00
|
|
|
YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
|
2006-03-06 20:55:24 +00:00
|
|
|
} else {
|
2019-04-06 06:46:15 +00:00
|
|
|
if (c != nullptr) c->infrastructure.road[roadtype] += num_pieces * 2; // A full diagonal road has two road bits.
|
|
|
|
RoadType road_rt = RoadTypeIsRoad(roadtype) ? roadtype : INVALID_ROADTYPE;
|
|
|
|
RoadType tram_rt = RoadTypeIsTram(roadtype) ? roadtype : INVALID_ROADTYPE;
|
|
|
|
MakeRoadTunnel(start_tile, company, direction, road_rt, tram_rt);
|
|
|
|
MakeRoadTunnel(end_tile, company, ReverseDiagDir(direction), road_rt, tram_rt);
|
2006-03-06 20:55:24 +00:00
|
|
|
}
|
2011-12-19 21:02:33 +00:00
|
|
|
DirtyCompanyInfrastructureWindows(company);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-22 21:09:55 +00:00
|
|
|
return cost;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Are we allowed to remove the tunnel or bridge at \a tile?
|
2010-03-13 16:38:23 +00:00
|
|
|
* @param tile End point of the tunnel or bridge.
|
|
|
|
* @return A succeeded command if the tunnel or bridge may be removed, a failed command otherwise.
|
|
|
|
*/
|
|
|
|
static inline CommandCost CheckAllowRemoveTunnelBridge(TileIndex tile)
|
2006-10-31 23:04:47 +00:00
|
|
|
{
|
|
|
|
/* Floods can remove anything as well as the scenario editor */
|
2010-03-13 16:38:23 +00:00
|
|
|
if (_current_company == OWNER_WATER || _game_mode == GM_EDITOR) return CommandCost();
|
2009-03-02 22:57:47 +00:00
|
|
|
|
2009-03-10 23:16:45 +00:00
|
|
|
switch (GetTunnelBridgeTransportType(tile)) {
|
|
|
|
case TRANSPORT_ROAD: {
|
2019-04-06 06:46:15 +00:00
|
|
|
RoadType road_rt = GetRoadTypeRoad(tile);
|
|
|
|
RoadType tram_rt = GetRoadTypeTram(tile);
|
2009-03-10 23:16:45 +00:00
|
|
|
Owner road_owner = _current_company;
|
|
|
|
Owner tram_owner = _current_company;
|
2009-03-02 22:57:47 +00:00
|
|
|
|
2019-04-06 06:46:15 +00:00
|
|
|
if (road_rt != INVALID_ROADTYPE) road_owner = GetRoadOwner(tile, RTT_ROAD);
|
|
|
|
if (tram_rt != INVALID_ROADTYPE) tram_owner = GetRoadOwner(tile, RTT_TRAM);
|
2009-03-02 22:57:47 +00:00
|
|
|
|
2009-03-10 23:16:45 +00:00
|
|
|
/* We can remove unowned road and if the town allows it */
|
2013-04-03 20:25:06 +00:00
|
|
|
if (road_owner == OWNER_TOWN && _current_company != OWNER_TOWN && !(_settings_game.construction.extra_dynamite || _cheats.magic_bulldozer.value)) {
|
|
|
|
/* Town does not allow */
|
2010-03-20 17:58:24 +00:00
|
|
|
return CheckTileOwnership(tile);
|
2010-03-07 20:44:05 +00:00
|
|
|
}
|
2009-03-12 11:36:18 +00:00
|
|
|
if (road_owner == OWNER_NONE || road_owner == OWNER_TOWN) road_owner = _current_company;
|
2009-03-10 23:16:45 +00:00
|
|
|
if (tram_owner == OWNER_NONE) tram_owner = _current_company;
|
2009-03-02 22:57:47 +00:00
|
|
|
|
2010-03-13 17:11:28 +00:00
|
|
|
CommandCost ret = CheckOwnership(road_owner, tile);
|
|
|
|
if (ret.Succeeded()) ret = CheckOwnership(tram_owner, tile);
|
|
|
|
return ret;
|
2009-03-10 23:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case TRANSPORT_RAIL:
|
2010-03-20 17:58:24 +00:00
|
|
|
return CheckOwnership(GetTileOwner(tile));
|
2009-03-10 23:16:45 +00:00
|
|
|
|
2011-08-24 12:19:12 +00:00
|
|
|
case TRANSPORT_WATER: {
|
|
|
|
/* Always allow to remove aqueducts without owner. */
|
|
|
|
Owner aqueduct_owner = GetTileOwner(tile);
|
|
|
|
if (aqueduct_owner == OWNER_NONE) aqueduct_owner = _current_company;
|
|
|
|
return CheckOwnership(aqueduct_owner);
|
|
|
|
}
|
|
|
|
|
2009-03-10 23:16:45 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
2006-10-31 23:04:47 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Remove a tunnel from the game, update town rating, etc.
|
2010-03-20 15:23:26 +00:00
|
|
|
* @param tile Tile containing one of the endpoints of the tunnel.
|
|
|
|
* @param flags Command flags.
|
|
|
|
* @return Succeeded or failed command.
|
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-03-13 16:38:23 +00:00
|
|
|
CommandCost ret = CheckAllowRemoveTunnelBridge(tile);
|
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-03-20 16:47:07 +00:00
|
|
|
TileIndex endtile = GetOtherTunnelEnd(tile);
|
2007-12-14 23:21:20 +00:00
|
|
|
|
2010-03-13 16:38:23 +00:00
|
|
|
ret = TunnelBridgeIsFree(tile, endtile);
|
2010-02-28 18:15:19 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_build_tunnel_endtile = endtile;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
Town *t = nullptr;
|
2005-06-04 11:56:32 +00:00
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
|
2008-10-14 18:38:51 +00:00
|
|
|
t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
|
2006-10-31 23:04:47 +00:00
|
|
|
|
|
|
|
/* Check if you are allowed to remove the tunnel owned by a town
|
|
|
|
* Removal depends on difficulty settings */
|
2010-03-13 15:33:07 +00:00
|
|
|
CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE);
|
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 17:47:05 +00:00
|
|
|
/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
|
|
|
|
* you have a "Poor" (0) town rating */
|
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
|
2009-02-11 18:50:47 +00:00
|
|
|
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags);
|
2008-01-09 17:47:05 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 20:12:32 +00:00
|
|
|
Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_TUNNEL);
|
2011-12-03 23:40:13 +00:00
|
|
|
uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles.
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2008-01-15 15:00:01 +00:00
|
|
|
if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
|
|
|
|
/* We first need to request values before calling DoClearSquare */
|
|
|
|
DiagDirection dir = GetTunnelBridgeDirection(tile);
|
2008-08-02 22:55:08 +00:00
|
|
|
Track track = DiagDirToDiagTrack(dir);
|
2008-01-15 15:00:01 +00:00
|
|
|
Owner owner = GetTileOwner(tile);
|
2006-01-22 16:23:05 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
Train *v = nullptr;
|
2009-07-21 22:37:10 +00:00
|
|
|
if (HasTunnelBridgeReservation(tile)) {
|
2008-08-02 22:55:08 +00:00
|
|
|
v = GetTrainForReservation(tile, track);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (v != nullptr) FreeTrainTrackReservation(v);
|
2008-08-02 22:55:08 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 23:40:13 +00:00
|
|
|
if (Company::IsValidID(owner)) {
|
|
|
|
Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
|
|
|
DirtyCompanyInfrastructureWindows(owner);
|
|
|
|
}
|
|
|
|
|
2008-01-15 15:00:01 +00:00
|
|
|
DoClearSquare(tile);
|
|
|
|
DoClearSquare(endtile);
|
2008-01-15 11:45:29 +00:00
|
|
|
|
2008-01-15 15:00:01 +00:00
|
|
|
/* cannot use INVALID_DIAGDIR for signal update because the tunnel doesn't exist anymore */
|
2008-02-21 16:05:33 +00:00
|
|
|
AddSideToSignalBuffer(tile, ReverseDiagDir(dir), owner);
|
|
|
|
AddSideToSignalBuffer(endtile, dir, owner);
|
2008-01-15 11:45:29 +00:00
|
|
|
|
2008-02-21 16:05:33 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
2008-01-15 11:45:29 +00:00
|
|
|
YapfNotifyTrackLayoutChange(endtile, track);
|
2008-08-02 22:55:08 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
if (v != nullptr) TryPathReserve(v);
|
2008-01-15 15:00:01 +00:00
|
|
|
} else {
|
2019-04-06 06:46:15 +00:00
|
|
|
/* A full diagonal road tile has two road bits. */
|
|
|
|
UpdateCompanyRoadInfrastructure(GetRoadTypeRoad(tile), GetRoadOwner(tile, RTT_ROAD), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
|
|
|
|
UpdateCompanyRoadInfrastructure(GetRoadTypeTram(tile), GetRoadOwner(tile, RTT_TRAM), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
|
2011-12-03 23:40:18 +00:00
|
|
|
|
2008-01-15 15:00:01 +00:00
|
|
|
DoClearSquare(tile);
|
|
|
|
DoClearSquare(endtile);
|
2008-01-15 11:45:29 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2021-01-06 20:12:32 +00:00
|
|
|
|
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, len * base_cost);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-06-07 19:35:21 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Remove a bridge from the game, update town rating, etc.
|
2010-03-20 15:23:26 +00:00
|
|
|
* @param tile Tile containing one of the endpoints of the bridge.
|
|
|
|
* @param flags Command flags.
|
|
|
|
* @return Succeeded or failed command.
|
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-03-13 16:38:23 +00:00
|
|
|
CommandCost ret = CheckAllowRemoveTunnelBridge(tile);
|
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-03-20 16:47:07 +00:00
|
|
|
TileIndex endtile = GetOtherBridgeEnd(tile);
|
2006-03-16 06:38:51 +00:00
|
|
|
|
2010-03-13 16:38:23 +00:00
|
|
|
ret = TunnelBridgeIsFree(tile, endtile);
|
2010-02-28 18:15:19 +00:00
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-03-20 16:47:07 +00:00
|
|
|
DiagDirection direction = GetTunnelBridgeDirection(tile);
|
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(direction);
|
2006-03-16 06:30:47 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
Town *t = nullptr;
|
2005-06-04 11:56:32 +00:00
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
|
2008-10-14 18:38:51 +00:00
|
|
|
t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
|
2006-10-31 23:04:47 +00:00
|
|
|
|
|
|
|
/* Check if you are allowed to remove the bridge owned by a town
|
|
|
|
* Removal depends on difficulty settings */
|
2010-03-13 15:33:07 +00:00
|
|
|
CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE);
|
|
|
|
if (ret.Failed()) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 17:47:05 +00:00
|
|
|
/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
|
|
|
|
* you have a "Poor" (0) town rating */
|
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
|
2009-02-11 18:50:47 +00:00
|
|
|
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags);
|
2008-01-09 17:47:05 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 20:12:32 +00:00
|
|
|
Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_BRIDGE);
|
2011-12-03 23:40:13 +00:00
|
|
|
uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles.
|
2010-04-25 20:56:42 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2008-01-15 11:45:29 +00:00
|
|
|
/* read this value before actual removal of bridge */
|
|
|
|
bool rail = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL;
|
2008-01-15 15:00:01 +00:00
|
|
|
Owner owner = GetTileOwner(tile);
|
2011-11-04 13:40:59 +00:00
|
|
|
int height = GetBridgeHeight(tile);
|
2019-04-10 21:07:06 +00:00
|
|
|
Train *v = nullptr;
|
2008-08-02 22:55:08 +00:00
|
|
|
|
2009-07-21 22:37:10 +00:00
|
|
|
if (rail && HasTunnelBridgeReservation(tile)) {
|
2008-08-02 22:55:08 +00:00
|
|
|
v = GetTrainForReservation(tile, DiagDirToDiagTrack(direction));
|
2019-04-10 21:07:06 +00:00
|
|
|
if (v != nullptr) FreeTrainTrackReservation(v);
|
2008-08-02 22:55:08 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-12-03 23:40:13 +00:00
|
|
|
/* Update company infrastructure counts. */
|
|
|
|
if (rail) {
|
|
|
|
if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
2011-12-03 23:40:18 +00:00
|
|
|
} else if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
|
2019-04-06 06:46:15 +00:00
|
|
|
/* A full diagonal road tile has two road bits. */
|
|
|
|
UpdateCompanyRoadInfrastructure(GetRoadTypeRoad(tile), GetRoadOwner(tile, RTT_ROAD), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
|
|
|
|
UpdateCompanyRoadInfrastructure(GetRoadTypeTram(tile), GetRoadOwner(tile, RTT_TRAM), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
|
2011-12-03 23:40:23 +00:00
|
|
|
} else { // Aqueduct
|
|
|
|
if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.water -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
2011-12-03 23:40:13 +00:00
|
|
|
}
|
|
|
|
DirtyCompanyInfrastructureWindows(owner);
|
|
|
|
|
2006-03-15 17:38:00 +00:00
|
|
|
DoClearSquare(tile);
|
|
|
|
DoClearSquare(endtile);
|
2019-03-11 10:37:47 +00:00
|
|
|
|
2008-01-15 11:45:29 +00:00
|
|
|
for (TileIndex c = tile + delta; c != endtile; c += delta) {
|
2008-02-17 21:27:44 +00:00
|
|
|
/* do not let trees appear from 'nowhere' after removing bridge */
|
|
|
|
if (IsNormalRoadTile(c) && GetRoadside(c) == ROADSIDE_TREES) {
|
2011-11-04 13:40:59 +00:00
|
|
|
int minz = GetTileMaxZ(c) + 3;
|
2008-02-17 21:27:44 +00:00
|
|
|
if (height < minz) SetRoadside(c, ROADSIDE_PAVED);
|
|
|
|
}
|
2008-01-15 11:45:29 +00:00
|
|
|
ClearBridgeMiddle(c);
|
2015-02-22 14:01:24 +00:00
|
|
|
MarkTileDirtyByTile(c, height - TileHeight(c));
|
2006-03-15 17:38:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-15 11:45:29 +00:00
|
|
|
if (rail) {
|
2008-01-15 15:00:01 +00:00
|
|
|
/* cannot use INVALID_DIAGDIR for signal update because the bridge doesn't exist anymore */
|
2008-02-21 16:05:33 +00:00
|
|
|
AddSideToSignalBuffer(tile, ReverseDiagDir(direction), owner);
|
|
|
|
AddSideToSignalBuffer(endtile, direction, owner);
|
2008-01-15 11:45:29 +00:00
|
|
|
|
2008-05-14 18:31:21 +00:00
|
|
|
Track track = DiagDirToDiagTrack(direction);
|
2008-02-21 16:05:33 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
2008-01-15 11:45:29 +00:00
|
|
|
YapfNotifyTrackLayoutChange(endtile, track);
|
2008-08-02 22:55:08 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
if (v != nullptr) TryPathReserve(v, true);
|
2008-01-15 11:45:29 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 23:40:13 +00:00
|
|
|
return CommandCost(EXPENSES_CONSTRUCTION, len * base_cost);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Remove a tunnel or a bridge from the game.
|
2010-03-20 15:23:26 +00:00
|
|
|
* @param tile Tile containing one of the endpoints.
|
|
|
|
* @param flags Command flags.
|
|
|
|
* @return Succeeded or failed command.
|
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
static CommandCost ClearTile_TunnelBridge(TileIndex tile, DoCommandFlag flags)
|
2005-06-24 12:38:35 +00:00
|
|
|
{
|
2006-03-12 15:04:03 +00:00
|
|
|
if (IsTunnel(tile)) {
|
2009-04-21 23:40:56 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_DEMOLISH_TUNNEL_FIRST);
|
2004-08-09 17:04:08 +00:00
|
|
|
return DoClearTunnel(tile, flags);
|
2008-01-23 14:51:36 +00:00
|
|
|
} else { // IsBridge(tile)
|
2009-04-21 23:40:56 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
2005-01-21 19:52:32 +00:00
|
|
|
return DoClearBridge(tile, flags);
|
2005-01-23 13:09:35 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-10-16 15:36:13 +00:00
|
|
|
/**
|
|
|
|
* Draw a single pillar sprite.
|
|
|
|
* @param psid Pillarsprite
|
|
|
|
* @param x Pillar X
|
|
|
|
* @param y Pillar Y
|
|
|
|
* @param z Pillar Z
|
|
|
|
* @param w Bounding box size in X direction
|
|
|
|
* @param h Bounding box size in Y direction
|
2010-10-16 15:40:44 +00:00
|
|
|
* @param subsprite Optional subsprite for drawing halfpillars
|
2010-10-16 15:36:13 +00:00
|
|
|
*/
|
2010-10-16 15:40:44 +00:00
|
|
|
static inline void DrawPillar(const PalSpriteID *psid, int x, int y, int z, int w, int h, const SubSprite *subsprite)
|
2010-10-16 15:36:13 +00:00
|
|
|
{
|
|
|
|
static const int PILLAR_Z_OFFSET = TILE_HEIGHT - BRIDGE_Z_START; ///< Start offset of pillar wrt. bridge (downwards)
|
2010-10-16 15:40:44 +00:00
|
|
|
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - PILLAR_Z_OFFSET, z, IsTransparencySet(TO_BRIDGES), 0, 0, -PILLAR_Z_OFFSET, subsprite);
|
2010-10-16 15:36:13 +00:00
|
|
|
}
|
|
|
|
|
2010-10-16 15:36:51 +00:00
|
|
|
/**
|
|
|
|
* Draw two bridge pillars (north and south).
|
|
|
|
* @param z_bottom Bottom Z
|
|
|
|
* @param z_top Top Z
|
|
|
|
* @param psid Pillarsprite
|
|
|
|
* @param x Pillar X
|
|
|
|
* @param y Pillar Y
|
|
|
|
* @param w Bounding box size in X direction
|
|
|
|
* @param h Bounding box size in Y direction
|
|
|
|
* @return Reached Z at the bottom
|
|
|
|
*/
|
|
|
|
static int DrawPillarColumn(int z_bottom, int z_top, const PalSpriteID *psid, int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
int cur_z;
|
|
|
|
for (cur_z = z_top; cur_z >= z_bottom; cur_z -= TILE_HEIGHT) {
|
2019-04-10 21:07:06 +00:00
|
|
|
DrawPillar(psid, x, y, cur_z, w, h, nullptr);
|
2010-10-16 15:36:51 +00:00
|
|
|
}
|
|
|
|
return cur_z;
|
|
|
|
}
|
|
|
|
|
2007-10-14 20:16:44 +00:00
|
|
|
/**
|
|
|
|
* Draws the pillars under high bridges.
|
|
|
|
*
|
|
|
|
* @param psid Image and palette of a bridge pillar.
|
|
|
|
* @param ti #TileInfo of current bridge-middle-tile.
|
|
|
|
* @param axis Orientation of bridge.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param drawfarpillar Whether to draw the pillar at the back
|
2007-10-14 20:16:44 +00:00
|
|
|
* @param x Sprite X position of front pillar.
|
|
|
|
* @param y Sprite Y position of front pillar.
|
|
|
|
* @param z_bridge Absolute height of bridge bottom.
|
|
|
|
*/
|
2009-01-10 00:31:47 +00:00
|
|
|
static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-10-16 15:34:59 +00:00
|
|
|
static const int bounding_box_size[2] = {16, 2}; ///< bounding box size of pillars along bridge direction
|
|
|
|
static const int back_pillar_offset[2] = { 0, 9}; ///< sprite position offset of back facing pillar
|
|
|
|
|
2010-10-16 15:40:44 +00:00
|
|
|
static const int INF = 1000; ///< big number compared to sprite size
|
|
|
|
static const SubSprite half_pillar_sub_sprite[2][2] = {
|
|
|
|
{ { -14, -INF, INF, INF }, { -INF, -INF, -15, INF } }, // X axis, north and south
|
|
|
|
{ { -INF, -INF, 15, INF }, { 16, -INF, INF, INF } }, // Y axis, north and south
|
|
|
|
};
|
2010-10-16 15:35:32 +00:00
|
|
|
|
2010-10-16 15:40:44 +00:00
|
|
|
if (psid->sprite == 0) return;
|
2010-10-16 15:35:32 +00:00
|
|
|
|
|
|
|
/* Determine ground height under pillars */
|
2010-10-16 15:40:44 +00:00
|
|
|
DiagDirection south_dir = AxisToDiagDir(axis);
|
|
|
|
int z_front_north = ti->z;
|
|
|
|
int z_back_north = ti->z;
|
|
|
|
int z_front_south = ti->z;
|
|
|
|
int z_back_south = ti->z;
|
2011-11-04 10:18:13 +00:00
|
|
|
GetSlopePixelZOnEdge(ti->tileh, south_dir, &z_front_south, &z_back_south);
|
|
|
|
GetSlopePixelZOnEdge(ti->tileh, ReverseDiagDir(south_dir), &z_front_north, &z_back_north);
|
2010-10-16 15:40:44 +00:00
|
|
|
|
|
|
|
/* Shared height of pillars */
|
2021-01-08 10:16:18 +00:00
|
|
|
int z_front = std::max(z_front_north, z_front_south);
|
|
|
|
int z_back = std::max(z_back_north, z_back_south);
|
2010-10-16 15:35:32 +00:00
|
|
|
|
|
|
|
/* x and y size of bounding-box of pillars */
|
|
|
|
int w = bounding_box_size[axis];
|
|
|
|
int h = bounding_box_size[OtherAxis(axis)];
|
|
|
|
/* sprite position of back facing pillar */
|
|
|
|
int x_back = x - back_pillar_offset[axis];
|
|
|
|
int y_back = y - back_pillar_offset[OtherAxis(axis)];
|
|
|
|
|
2010-10-16 15:36:51 +00:00
|
|
|
/* Draw front pillars */
|
2010-10-16 15:40:44 +00:00
|
|
|
int bottom_z = DrawPillarColumn(z_front, z_bridge, psid, x, y, w, h);
|
|
|
|
if (z_front_north < z_front) DrawPillar(psid, x, y, bottom_z, w, h, &half_pillar_sub_sprite[axis][0]);
|
|
|
|
if (z_front_south < z_front) DrawPillar(psid, x, y, bottom_z, w, h, &half_pillar_sub_sprite[axis][1]);
|
2008-04-03 19:55:40 +00:00
|
|
|
|
2010-10-16 15:36:51 +00:00
|
|
|
/* Draw back pillars, skip top two parts, which are hidden by the bridge */
|
2010-10-16 15:40:44 +00:00
|
|
|
int z_bridge_back = z_bridge - 2 * (int)TILE_HEIGHT;
|
|
|
|
if (drawfarpillar && (z_back_north <= z_bridge_back || z_back_south <= z_bridge_back)) {
|
|
|
|
bottom_z = DrawPillarColumn(z_back, z_bridge_back, psid, x_back, y_back, w, h);
|
|
|
|
if (z_back_north < z_back) DrawPillar(psid, x_back, y_back, bottom_z, w, h, &half_pillar_sub_sprite[axis][0]);
|
|
|
|
if (z_back_south < z_back) DrawPillar(psid, x_back, y_back, bottom_z, w, h, &half_pillar_sub_sprite[axis][1]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:10:32 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the sprites required for catenary on a road/tram bridge.
|
|
|
|
* @param rti RoadTypeInfo for the road or tram type to get catenary for
|
|
|
|
* @param head_tile Bridge head tile with roadtype information
|
|
|
|
* @param offset Sprite offset identifying flat to sloped bridge tiles
|
|
|
|
* @param head Are we drawing bridge head?
|
|
|
|
* @param[out] spr_back Back catenary sprite to use
|
|
|
|
* @param[out] spr_front Front catenary sprite to use
|
|
|
|
*/
|
|
|
|
static void GetBridgeRoadCatenary(const RoadTypeInfo *rti, TileIndex head_tile, int offset, bool head, SpriteID &spr_back, SpriteID &spr_front)
|
|
|
|
{
|
|
|
|
static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 };
|
|
|
|
static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 };
|
|
|
|
|
|
|
|
/* Simplified from DrawRoadTypeCatenary() to remove all the special cases required for regular ground road */
|
|
|
|
spr_back = GetCustomRoadSprite(rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
|
|
|
spr_front = GetCustomRoadSprite(rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
2020-02-09 19:24:56 +00:00
|
|
|
if (spr_back == 0 && spr_front == 0) {
|
2020-02-09 19:10:32 +00:00
|
|
|
spr_back = SPR_TRAMWAY_BASE + back_offsets[offset];
|
|
|
|
spr_front = SPR_TRAMWAY_BASE + front_offsets[offset];
|
|
|
|
} else {
|
2020-02-09 19:24:56 +00:00
|
|
|
if (spr_back != 0) spr_back += 23 + offset;
|
|
|
|
if (spr_front != 0) spr_front += 23 + offset;
|
2020-02-09 19:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-25 22:07:40 +00:00
|
|
|
/**
|
2019-04-06 06:46:15 +00:00
|
|
|
* Draws the road and trambits over an already drawn (lower end) of a bridge.
|
|
|
|
* @param head_tile bridge head tile with roadtype information
|
|
|
|
* @param x the x of the bridge
|
|
|
|
* @param y the y of the bridge
|
|
|
|
* @param z the z of the bridge
|
|
|
|
* @param offset sprite offset identifying flat to sloped bridge tiles
|
|
|
|
* @param head are we drawing bridge head?
|
2007-05-25 22:07:40 +00:00
|
|
|
*/
|
2019-04-06 06:46:15 +00:00
|
|
|
static void DrawBridgeRoadBits(TileIndex head_tile, int x, int y, int z, int offset, bool head)
|
2007-05-25 22:07:40 +00:00
|
|
|
{
|
2019-04-06 06:46:15 +00:00
|
|
|
RoadType road_rt = GetRoadTypeRoad(head_tile);
|
|
|
|
RoadType tram_rt = GetRoadTypeTram(head_tile);
|
|
|
|
const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
|
|
|
|
const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
|
|
|
|
|
|
|
|
SpriteID seq_back[4] = { 0 };
|
|
|
|
bool trans_back[4] = { false };
|
|
|
|
SpriteID seq_front[4] = { 0 };
|
|
|
|
bool trans_front[4] = { false };
|
|
|
|
|
|
|
|
static const SpriteID overlay_offsets[6] = { 0, 1, 11, 12, 13, 14 };
|
|
|
|
if (head || !IsInvisibilitySet(TO_BRIDGES)) {
|
2019-09-29 20:27:32 +00:00
|
|
|
/* Road underlay takes precedence over tram */
|
2019-04-06 06:46:15 +00:00
|
|
|
trans_back[0] = !head && IsTransparencySet(TO_BRIDGES);
|
|
|
|
if (road_rti != nullptr) {
|
|
|
|
if (road_rti->UsesOverlay()) {
|
|
|
|
seq_back[0] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_BRIDGE, head ? TCX_NORMAL : TCX_ON_BRIDGE) + offset;
|
|
|
|
}
|
|
|
|
} else if (tram_rti != nullptr) {
|
|
|
|
if (tram_rti->UsesOverlay()) {
|
|
|
|
seq_back[0] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_BRIDGE, head ? TCX_NORMAL : TCX_ON_BRIDGE) + offset;
|
|
|
|
} else {
|
|
|
|
seq_back[0] = SPR_TRAMWAY_BRIDGE + offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw road overlay */
|
|
|
|
trans_back[1] = !head && IsTransparencySet(TO_BRIDGES);
|
|
|
|
if (road_rti != nullptr) {
|
|
|
|
if (road_rti->UsesOverlay()) {
|
|
|
|
seq_back[1] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_OVERLAY, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
|
|
|
if (seq_back[1] != 0) seq_back[1] += overlay_offsets[offset];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw tram overlay */
|
|
|
|
trans_back[2] = !head && IsTransparencySet(TO_BRIDGES);
|
|
|
|
if (tram_rti != nullptr) {
|
|
|
|
if (tram_rti->UsesOverlay()) {
|
|
|
|
seq_back[2] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_OVERLAY, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
|
|
|
if (seq_back[2] != 0) seq_back[2] += overlay_offsets[offset];
|
|
|
|
} else if (road_rti != nullptr) {
|
|
|
|
seq_back[2] = SPR_TRAMWAY_OVERLAY + overlay_offsets[offset];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-29 20:27:32 +00:00
|
|
|
/* Road catenary takes precedence over tram */
|
2019-04-06 06:46:15 +00:00
|
|
|
trans_back[3] = IsTransparencySet(TO_CATENARY);
|
|
|
|
trans_front[0] = IsTransparencySet(TO_CATENARY);
|
|
|
|
if (road_rti != nullptr && HasRoadCatenaryDrawn(road_rt)) {
|
2020-02-09 19:10:32 +00:00
|
|
|
GetBridgeRoadCatenary(road_rti, head_tile, offset, head, seq_back[3], seq_front[0]);
|
2019-04-06 06:46:15 +00:00
|
|
|
} else if (tram_rti != nullptr && HasRoadCatenaryDrawn(tram_rt)) {
|
2020-02-09 19:10:32 +00:00
|
|
|
GetBridgeRoadCatenary(tram_rti, head_tile, offset, head, seq_back[3], seq_front[0]);
|
2019-04-06 06:46:15 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-25 22:07:40 +00:00
|
|
|
|
2007-09-19 16:36:42 +00:00
|
|
|
static const uint size_x[6] = { 1, 16, 16, 1, 16, 1 };
|
|
|
|
static const uint size_y[6] = { 16, 1, 1, 16, 1, 16 };
|
|
|
|
static const uint front_bb_offset_x[6] = { 15, 0, 0, 15, 0, 15 };
|
|
|
|
static const uint front_bb_offset_y[6] = { 0, 15, 15, 0, 15, 0 };
|
2007-05-26 10:40:34 +00:00
|
|
|
|
2007-09-19 16:36:42 +00:00
|
|
|
/* The sprites under the vehicles are drawn as SpriteCombine. StartSpriteCombine() has already been called
|
|
|
|
* The bounding boxes here are the same as for bridge front/roof */
|
2019-04-06 06:46:15 +00:00
|
|
|
for (uint i = 0; i < lengthof(seq_back); ++i) {
|
|
|
|
if (seq_back[i] != 0) {
|
|
|
|
AddSortableSpriteToDraw(seq_back[i], PAL_NONE,
|
|
|
|
x, y, size_x[offset], size_y[offset], 0x28, z,
|
|
|
|
trans_back[i]);
|
|
|
|
}
|
2008-04-08 21:28:47 +00:00
|
|
|
}
|
2007-09-19 16:36:42 +00:00
|
|
|
|
|
|
|
/* Start a new SpriteCombine for the front part */
|
|
|
|
EndSpriteCombine();
|
|
|
|
StartSpriteCombine();
|
2007-05-25 22:07:40 +00:00
|
|
|
|
2019-04-06 06:46:15 +00:00
|
|
|
for (uint i = 0; i < lengthof(seq_front); ++i) {
|
|
|
|
if (seq_front[i] != 0) {
|
|
|
|
AddSortableSpriteToDraw(seq_front[i], PAL_NONE,
|
|
|
|
x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z,
|
|
|
|
trans_front[i],
|
|
|
|
front_bb_offset_x[offset], front_bb_offset_y[offset]);
|
|
|
|
}
|
2008-04-08 21:28:47 +00:00
|
|
|
}
|
2007-05-25 22:07:40 +00:00
|
|
|
}
|
|
|
|
|
2005-10-19 08:34:37 +00:00
|
|
|
/**
|
2006-09-04 20:40:33 +00:00
|
|
|
* Draws a tunnel of bridge tile.
|
2013-01-08 22:46:42 +00:00
|
|
|
* For tunnels, this is rather simple, as you only need to draw the entrance.
|
2006-09-04 20:40:33 +00:00
|
|
|
* Bridges are a bit more complex. base_offset is where the sprite selection comes into play
|
|
|
|
* and it works a bit like a bitmask.<p> For bridge heads:
|
2007-04-04 03:21:14 +00:00
|
|
|
* @param ti TileInfo of the structure to draw
|
2006-09-04 20:40:33 +00:00
|
|
|
* <ul><li>Bit 0: direction</li>
|
|
|
|
* <li>Bit 1: northern or southern heads</li>
|
|
|
|
* <li>Bit 2: Set if the bridge head is sloped</li>
|
|
|
|
* <li>Bit 3 and more: Railtype Specific subset</li>
|
|
|
|
* </ul>
|
|
|
|
* Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
static void DrawTile_TunnelBridge(TileInfo *ti)
|
|
|
|
{
|
2008-02-13 03:21:19 +00:00
|
|
|
TransportType transport_type = GetTunnelBridgeTransportType(ti->tile);
|
2008-02-13 03:02:02 +00:00
|
|
|
DiagDirection tunnelbridge_direction = GetTunnelBridgeDirection(ti->tile);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-03-12 15:04:03 +00:00
|
|
|
if (IsTunnel(ti->tile)) {
|
2007-09-19 16:36:42 +00:00
|
|
|
/* Front view of tunnel bounding boxes:
|
|
|
|
*
|
|
|
|
* 122223 <- BB_Z_SEPARATOR
|
|
|
|
* 1 3
|
|
|
|
* 1 3 1,3 = empty helper BB
|
|
|
|
* 1 3 2 = SpriteCombine of tunnel-roof and catenary (tram & elrail)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const int _tunnel_BB[4][12] = {
|
|
|
|
/* tunnnel-roof | Z-separator | tram-catenary
|
|
|
|
* w h bb_x bb_y| x y w h |bb_x bb_y w h */
|
|
|
|
{ 1, 0, -15, -14, 0, 15, 16, 1, 0, 1, 16, 15 }, // NE
|
|
|
|
{ 0, 1, -14, -15, 15, 0, 1, 16, 1, 0, 15, 16 }, // SE
|
|
|
|
{ 1, 0, -15, -14, 0, 15, 16, 1, 0, 1, 16, 15 }, // SW
|
|
|
|
{ 0, 1, -14, -15, 15, 0, 1, 16, 1, 0, 15, 16 }, // NW
|
|
|
|
};
|
2008-02-13 03:02:02 +00:00
|
|
|
const int *BB_data = _tunnel_BB[tunnelbridge_direction];
|
2007-09-19 16:36:42 +00:00
|
|
|
|
|
|
|
bool catenary = false;
|
|
|
|
|
2010-03-20 16:47:07 +00:00
|
|
|
SpriteID image;
|
2012-02-15 21:23:48 +00:00
|
|
|
SpriteID railtype_overlay = 0;
|
2008-02-13 03:21:19 +00:00
|
|
|
if (transport_type == TRANSPORT_RAIL) {
|
2012-02-15 21:23:48 +00:00
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
|
|
|
|
image = rti->base_sprites.tunnel;
|
|
|
|
if (rti->UsesOverlay()) {
|
|
|
|
/* Check if the railtype has custom tunnel portals. */
|
|
|
|
railtype_overlay = GetCustomRailSprite(rti, ti->tile, RTSG_TUNNEL_PORTAL);
|
|
|
|
if (railtype_overlay != 0) image = SPR_RAILTYPE_TUNNEL_BASE; // Draw blank grass tunnel base.
|
|
|
|
}
|
2005-10-13 16:00:14 +00:00
|
|
|
} else {
|
|
|
|
image = SPR_TUNNEL_ENTRY_REAR_ROAD;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2012-02-15 21:23:48 +00:00
|
|
|
if (HasTunnelBridgeSnowOrDesert(ti->tile)) image += railtype_overlay != 0 ? 8 : 32;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-13 03:02:02 +00:00
|
|
|
image += tunnelbridge_direction * 2;
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(image, PAL_NONE);
|
2008-08-02 22:47:34 +00:00
|
|
|
|
2008-02-13 03:21:19 +00:00
|
|
|
if (transport_type == TRANSPORT_ROAD) {
|
2019-04-06 06:46:15 +00:00
|
|
|
RoadType road_rt = GetRoadTypeRoad(ti->tile);
|
|
|
|
RoadType tram_rt = GetRoadTypeTram(ti->tile);
|
|
|
|
const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
|
|
|
|
const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
|
|
|
|
uint sprite_offset = DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? 1 : 0;
|
2022-12-17 14:01:47 +00:00
|
|
|
bool draw_underlay = true;
|
|
|
|
|
|
|
|
/* Road underlay takes precedence over tram */
|
|
|
|
if (road_rti != nullptr) {
|
|
|
|
if (road_rti->UsesOverlay()) {
|
|
|
|
SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_TUNNEL);
|
|
|
|
if (ground != 0) {
|
|
|
|
DrawGroundSprite(ground + tunnelbridge_direction, PAL_NONE);
|
|
|
|
draw_underlay = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tram_rti->UsesOverlay()) {
|
|
|
|
SpriteID ground = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_TUNNEL);
|
|
|
|
if (ground != 0) {
|
|
|
|
DrawGroundSprite(ground + tunnelbridge_direction, PAL_NONE);
|
|
|
|
draw_underlay = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-06 06:46:15 +00:00
|
|
|
|
2022-12-17 14:01:47 +00:00
|
|
|
DrawRoadOverlays(ti, PAL_NONE, road_rti, tram_rti, sprite_offset, sprite_offset, draw_underlay);
|
2019-04-06 06:46:15 +00:00
|
|
|
|
2019-09-29 20:27:32 +00:00
|
|
|
/* Road catenary takes precedence over tram */
|
2019-04-06 06:46:15 +00:00
|
|
|
SpriteID catenary_sprite_base = 0;
|
|
|
|
if (road_rti != nullptr && HasRoadCatenaryDrawn(road_rt)) {
|
|
|
|
catenary_sprite_base = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_CATENARY_FRONT);
|
|
|
|
if (catenary_sprite_base == 0) {
|
|
|
|
catenary_sprite_base = SPR_TRAMWAY_TUNNEL_WIRES;
|
|
|
|
} else {
|
|
|
|
catenary_sprite_base += 19;
|
|
|
|
}
|
|
|
|
} else if (tram_rti != nullptr && HasRoadCatenaryDrawn(tram_rt)) {
|
|
|
|
catenary_sprite_base = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_CATENARY_FRONT);
|
|
|
|
if (catenary_sprite_base == 0) {
|
|
|
|
catenary_sprite_base = SPR_TRAMWAY_TUNNEL_WIRES;
|
|
|
|
} else {
|
|
|
|
catenary_sprite_base += 19;
|
2008-04-03 19:55:40 +00:00
|
|
|
}
|
2007-05-25 22:07:40 +00:00
|
|
|
}
|
2019-04-06 06:46:15 +00:00
|
|
|
|
|
|
|
if (catenary_sprite_base != 0) {
|
|
|
|
catenary = true;
|
|
|
|
StartSpriteCombine();
|
|
|
|
AddSortableSpriteToDraw(catenary_sprite_base + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_CATENARY), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
|
|
|
|
}
|
2010-02-07 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
|
|
|
|
if (rti->UsesOverlay()) {
|
|
|
|
SpriteID surface = GetCustomRailSprite(rti, ti->tile, RTSG_TUNNEL);
|
|
|
|
if (surface != 0) DrawGroundSprite(surface + tunnelbridge_direction, PAL_NONE);
|
|
|
|
}
|
2008-09-11 19:12:31 +00:00
|
|
|
|
2011-12-17 23:14:28 +00:00
|
|
|
/* PBS debugging, draw reserved tracks darker */
|
|
|
|
if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasTunnelBridgeReservation(ti->tile)) {
|
2015-03-28 14:03:26 +00:00
|
|
|
if (rti->UsesOverlay()) {
|
|
|
|
SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY);
|
|
|
|
DrawGroundSprite(overlay + RTO_X + DiagDirToAxis(tunnelbridge_direction), PALETTE_CRASH);
|
|
|
|
} else {
|
|
|
|
DrawGroundSprite(DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH);
|
|
|
|
}
|
2011-12-17 23:14:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-05 11:53:03 +00:00
|
|
|
if (HasRailCatenaryDrawn(GetRailType(ti->tile))) {
|
2010-02-07 22:22:54 +00:00
|
|
|
/* Maybe draw pylons on the entry side */
|
2016-11-05 11:53:03 +00:00
|
|
|
DrawRailCatenary(ti);
|
2010-02-07 22:22:54 +00:00
|
|
|
|
|
|
|
catenary = true;
|
|
|
|
StartSpriteCombine();
|
|
|
|
/* Draw wire above the ramp */
|
2016-11-05 11:53:03 +00:00
|
|
|
DrawRailCatenaryOnTunnel(ti);
|
2010-02-07 22:22:54 +00:00
|
|
|
}
|
2007-05-20 22:43:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2012-02-15 21:23:48 +00:00
|
|
|
if (railtype_overlay != 0 && !catenary) StartSpriteCombine();
|
|
|
|
|
2007-09-19 16:36:42 +00:00
|
|
|
AddSortableSpriteToDraw(image + 1, PAL_NONE, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, BB_data[0], BB_data[1], TILE_HEIGHT, ti->z, false, BB_data[2], BB_data[3], BB_Z_SEPARATOR);
|
2012-02-15 21:23:48 +00:00
|
|
|
/* Draw railtype tunnel portal overlay if defined. */
|
|
|
|
if (railtype_overlay != 0) AddSortableSpriteToDraw(railtype_overlay + tunnelbridge_direction, PAL_NONE, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, BB_data[0], BB_data[1], TILE_HEIGHT, ti->z, false, BB_data[2], BB_data[3], BB_Z_SEPARATOR);
|
2007-09-19 16:36:42 +00:00
|
|
|
|
2012-02-15 21:23:48 +00:00
|
|
|
if (catenary || railtype_overlay != 0) EndSpriteCombine();
|
2007-09-19 16:36:42 +00:00
|
|
|
|
2010-10-30 17:51:07 +00:00
|
|
|
/* Add helper BB for sprite sorting that separates the tunnel from things beside of it. */
|
2009-10-02 15:13:15 +00:00
|
|
|
AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x, ti->y, BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
|
2007-09-19 16:36:42 +00:00
|
|
|
AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x + BB_data[4], ti->y + BB_data[5], BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2008-01-23 14:51:36 +00:00
|
|
|
} else { // IsBridge(ti->tile)
|
2007-01-14 19:57:49 +00:00
|
|
|
const PalSpriteID *psid;
|
2005-10-19 08:34:37 +00:00
|
|
|
int base_offset;
|
2007-12-16 15:38:51 +00:00
|
|
|
bool ice = HasTunnelBridgeSnowOrDesert(ti->tile);
|
2005-10-19 08:34:37 +00:00
|
|
|
|
2008-02-13 03:21:19 +00:00
|
|
|
if (transport_type == TRANSPORT_RAIL) {
|
2006-12-27 12:38:02 +00:00
|
|
|
base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
|
2007-04-04 03:21:14 +00:00
|
|
|
assert(base_offset != 8); // This one is used for roads
|
2006-03-16 15:16:27 +00:00
|
|
|
} else {
|
|
|
|
base_offset = 8;
|
2005-10-19 08:34:37 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-19 08:34:37 +00:00
|
|
|
/* as the lower 3 bits are used for other stuff, make sure they are clear */
|
|
|
|
assert( (base_offset & 0x07) == 0x00);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-02-13 03:02:02 +00:00
|
|
|
DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(tunnelbridge_direction)));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* HACK Wizardry to convert the bridge ramp direction into a sprite offset */
|
2008-02-13 03:02:02 +00:00
|
|
|
base_offset += (6 - tunnelbridge_direction) % 4;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-07-15 00:34:34 +00:00
|
|
|
/* Table number BRIDGE_PIECE_HEAD always refers to the bridge heads for any bridge type */
|
2008-06-11 13:54:01 +00:00
|
|
|
if (transport_type != TRANSPORT_WATER) {
|
2013-11-25 16:26:50 +00:00
|
|
|
if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
|
2008-07-15 00:34:34 +00:00
|
|
|
psid = &GetBridgeSpriteTable(GetBridgeType(ti->tile), BRIDGE_PIECE_HEAD)[base_offset];
|
2008-06-11 13:54:01 +00:00
|
|
|
} else {
|
|
|
|
psid = _aqueduct_sprites + base_offset;
|
|
|
|
}
|
2005-10-19 08:34:37 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (!ice) {
|
2011-01-09 12:17:52 +00:00
|
|
|
TileIndex next = ti->tile + TileOffsByDiagDir(tunnelbridge_direction);
|
|
|
|
if (ti->tileh != SLOPE_FLAT && ti->z == 0 && HasTileWaterClass(next) && GetWaterClass(next) == WATER_CLASS_SEA) {
|
|
|
|
DrawShoreTile(ti->tileh);
|
|
|
|
} else {
|
|
|
|
DrawClearLandTile(ti, 3);
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
2010-07-19 17:00:54 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_SNOW_DESERT_TILE + SlopeToSpriteOffset(ti->tileh), PAL_NONE);
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2005-10-19 08:34:37 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* draw ramp */
|
2007-01-14 19:57:49 +00:00
|
|
|
|
2009-06-07 13:25:21 +00:00
|
|
|
/* Draw Trambits and PBS Reservation as SpriteCombine */
|
|
|
|
if (transport_type == TRANSPORT_ROAD || transport_type == TRANSPORT_RAIL) StartSpriteCombine();
|
2007-09-19 16:36:42 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
|
|
|
|
* it doesn't disappear behind it
|
|
|
|
*/
|
2008-04-03 19:55:40 +00:00
|
|
|
/* Bridge heads are drawn solid no matter how invisibility/transparency is set */
|
|
|
|
AddSortableSpriteToDraw(psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z);
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2008-02-13 03:21:19 +00:00
|
|
|
if (transport_type == TRANSPORT_ROAD) {
|
2019-04-06 06:46:15 +00:00
|
|
|
uint offset = tunnelbridge_direction;
|
|
|
|
int z = ti->z;
|
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
|
|
|
offset = (offset + 1) & 1;
|
|
|
|
z += TILE_HEIGHT;
|
|
|
|
} else {
|
|
|
|
offset += 2;
|
2007-05-25 22:07:40 +00:00
|
|
|
}
|
2019-04-06 06:46:15 +00:00
|
|
|
|
|
|
|
/* DrawBridgeRoadBits() calls EndSpriteCombine() and StartSpriteCombine() */
|
|
|
|
DrawBridgeRoadBits(ti->tile, ti->x, ti->y, z, offset, true);
|
|
|
|
|
2007-09-19 16:36:42 +00:00
|
|
|
EndSpriteCombine();
|
2008-08-25 18:14:19 +00:00
|
|
|
} else if (transport_type == TRANSPORT_RAIL) {
|
2010-02-07 22:22:54 +00:00
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
|
|
|
|
if (rti->UsesOverlay()) {
|
|
|
|
SpriteID surface = GetCustomRailSprite(rti, ti->tile, RTSG_BRIDGE);
|
|
|
|
if (surface != 0) {
|
|
|
|
if (HasBridgeFlatRamp(ti->tileh, DiagDirToAxis(tunnelbridge_direction))) {
|
|
|
|
AddSortableSpriteToDraw(surface + ((DiagDirToAxis(tunnelbridge_direction) == AXIS_X) ? RTBO_X : RTBO_Y), PAL_NONE, ti->x, ti->y, 16, 16, 0, ti->z + 8);
|
|
|
|
} else {
|
|
|
|
AddSortableSpriteToDraw(surface + RTBO_SLOPE + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, 16, 16, 8, ti->z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Don't fallback to non-overlay sprite -- the spec states that
|
|
|
|
* if an overlay is present then the bridge surface must be
|
|
|
|
* present. */
|
2011-12-17 23:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PBS debugging, draw reserved tracks darker */
|
2015-03-28 14:03:26 +00:00
|
|
|
if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasTunnelBridgeReservation(ti->tile)) {
|
|
|
|
if (rti->UsesOverlay()) {
|
|
|
|
SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY);
|
|
|
|
if (HasBridgeFlatRamp(ti->tileh, DiagDirToAxis(tunnelbridge_direction))) {
|
|
|
|
AddSortableSpriteToDraw(overlay + RTO_X + DiagDirToAxis(tunnelbridge_direction), PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + 8);
|
|
|
|
} else {
|
|
|
|
AddSortableSpriteToDraw(overlay + RTO_SLOPE_NE + tunnelbridge_direction, PALETTE_CRASH, ti->x, ti->y, 16, 16, 8, ti->z);
|
|
|
|
}
|
2010-02-07 22:22:54 +00:00
|
|
|
} else {
|
2015-03-28 14:03:26 +00:00
|
|
|
if (HasBridgeFlatRamp(ti->tileh, DiagDirToAxis(tunnelbridge_direction))) {
|
|
|
|
AddSortableSpriteToDraw(DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + 8);
|
|
|
|
} else {
|
|
|
|
AddSortableSpriteToDraw(rti->base_sprites.single_sloped + tunnelbridge_direction, PALETTE_CRASH, ti->x, ti->y, 16, 16, 8, ti->z);
|
|
|
|
}
|
2010-02-07 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-17 23:22:27 +00:00
|
|
|
|
2009-06-07 13:25:21 +00:00
|
|
|
EndSpriteCombine();
|
2016-11-05 11:53:03 +00:00
|
|
|
if (HasRailCatenaryDrawn(GetRailType(ti->tile))) {
|
|
|
|
DrawRailCatenary(ti);
|
2008-08-25 18:14:19 +00:00
|
|
|
}
|
2007-05-25 22:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
|
|
|
}
|
|
|
|
}
|
2006-06-07 19:35:21 +00:00
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Compute bridge piece. Computes the bridge piece to display depending on the position inside the bridge.
|
2008-07-15 00:34:34 +00:00
|
|
|
* bridges pieces sequence (middle parts).
|
|
|
|
* Note that it is not covering the bridge heads, which are always referenced by the same sprite table.
|
|
|
|
* bridge len 1: BRIDGE_PIECE_NORTH
|
|
|
|
* bridge len 2: BRIDGE_PIECE_NORTH BRIDGE_PIECE_SOUTH
|
|
|
|
* bridge len 3: BRIDGE_PIECE_NORTH BRIDGE_PIECE_MIDDLE_ODD BRIDGE_PIECE_SOUTH
|
|
|
|
* bridge len 4: BRIDGE_PIECE_NORTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_SOUTH
|
|
|
|
* bridge len 5: BRIDGE_PIECE_NORTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_MIDDLE_EVEN BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_SOUTH
|
|
|
|
* bridge len 6: BRIDGE_PIECE_NORTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_SOUTH
|
|
|
|
* bridge len 7: BRIDGE_PIECE_NORTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_MIDDLE_ODD BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_SOUTH
|
2006-12-27 12:38:02 +00:00
|
|
|
* #0 - always as first, #1 - always as last (if len>1)
|
|
|
|
* #2,#3 are to pair in order
|
|
|
|
* for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0)
|
|
|
|
* @param north Northernmost tile of bridge
|
|
|
|
* @param south Southernmost tile of bridge
|
|
|
|
* @return Index of bridge piece
|
|
|
|
*/
|
2008-07-15 00:34:34 +00:00
|
|
|
static BridgePieces CalcBridgePiece(uint north, uint south)
|
2006-12-27 12:38:02 +00:00
|
|
|
{
|
|
|
|
if (north == 1) {
|
2008-07-15 00:34:34 +00:00
|
|
|
return BRIDGE_PIECE_NORTH;
|
2006-12-27 12:38:02 +00:00
|
|
|
} else if (south == 1) {
|
2008-07-15 00:34:34 +00:00
|
|
|
return BRIDGE_PIECE_SOUTH;
|
2006-12-27 12:38:02 +00:00
|
|
|
} else if (north < south) {
|
2008-07-15 00:34:34 +00:00
|
|
|
return north & 1 ? BRIDGE_PIECE_INNER_SOUTH : BRIDGE_PIECE_INNER_NORTH;
|
2006-12-27 12:38:02 +00:00
|
|
|
} else if (north > south) {
|
2008-07-15 00:34:34 +00:00
|
|
|
return south & 1 ? BRIDGE_PIECE_INNER_NORTH : BRIDGE_PIECE_INNER_SOUTH;
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
2008-07-15 00:34:34 +00:00
|
|
|
return north & 1 ? BRIDGE_PIECE_MIDDLE_EVEN : BRIDGE_PIECE_MIDDLE_ODD;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-07 19:35:21 +00:00
|
|
|
|
2011-05-02 20:59:54 +00:00
|
|
|
/**
|
|
|
|
* Draw the middle bits of a bridge.
|
|
|
|
* @param ti Tile information of the tile to draw it on.
|
|
|
|
*/
|
2009-01-10 00:31:47 +00:00
|
|
|
void DrawBridgeMiddle(const TileInfo *ti)
|
2006-12-27 12:38:02 +00:00
|
|
|
{
|
2007-09-19 16:36:42 +00:00
|
|
|
/* Sectional view of bridge bounding boxes:
|
|
|
|
*
|
2016-11-05 11:53:03 +00:00
|
|
|
* 1 2 1,2 = SpriteCombine of Bridge front/(back&floor) and RoadCatenary
|
2007-09-19 16:36:42 +00:00
|
|
|
* 1 2 3 = empty helper BB
|
|
|
|
* 1 7 2 4,5 = pillars under higher bridges
|
|
|
|
* 1 6 88888 6 2 6 = elrail-pylons
|
|
|
|
* 1 6 88888 6 2 7 = elrail-wire
|
|
|
|
* 1 6 88888 6 2 <- TILE_HEIGHT 8 = rail-vehicle on bridge
|
|
|
|
* 3333333333333 <- BB_Z_SEPARATOR
|
|
|
|
* <- unused
|
|
|
|
* 4 5 <- BB_HEIGHT_UNDER_BRIDGE
|
|
|
|
* 4 5
|
|
|
|
* 4 5
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (!IsBridgeAbove(ti->tile)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-06-11 17:10:36 +00:00
|
|
|
TileIndex rampnorth = GetNorthernBridgeEnd(ti->tile);
|
|
|
|
TileIndex rampsouth = GetSouthernBridgeEnd(ti->tile);
|
|
|
|
TransportType transport_type = GetTunnelBridgeTransportType(rampsouth);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-06-11 17:10:36 +00:00
|
|
|
Axis axis = GetBridgeAxis(ti->tile);
|
2008-07-15 00:34:34 +00:00
|
|
|
BridgePieces piece = CalcBridgePiece(
|
2008-01-23 22:34:04 +00:00
|
|
|
GetTunnelBridgeLength(ti->tile, rampnorth) + 1,
|
|
|
|
GetTunnelBridgeLength(ti->tile, rampsouth) + 1
|
2006-12-27 12:38:02 +00:00
|
|
|
);
|
2006-03-29 16:30:26 +00:00
|
|
|
|
2008-06-11 17:10:36 +00:00
|
|
|
const PalSpriteID *psid;
|
|
|
|
bool drawfarpillar;
|
2008-06-11 13:54:01 +00:00
|
|
|
if (transport_type != TRANSPORT_WATER) {
|
2008-06-11 17:10:36 +00:00
|
|
|
BridgeType type = GetBridgeType(rampsouth);
|
|
|
|
drawfarpillar = !HasBit(GetBridgeSpec(type)->flags, 0);
|
|
|
|
|
|
|
|
uint base_offset;
|
2008-06-11 13:54:01 +00:00
|
|
|
if (transport_type == TRANSPORT_RAIL) {
|
|
|
|
base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
|
|
|
|
} else {
|
|
|
|
base_offset = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
psid = base_offset + GetBridgeSpriteTable(type, piece);
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
2008-06-11 17:10:36 +00:00
|
|
|
drawfarpillar = true;
|
2008-06-11 13:54:01 +00:00
|
|
|
psid = _aqueduct_sprites;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2008-06-11 17:10:36 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
if (axis != AXIS_X) psid += 4;
|
2006-06-02 13:05:41 +00:00
|
|
|
|
2008-06-11 17:10:36 +00:00
|
|
|
int x = ti->x;
|
|
|
|
int y = ti->y;
|
2011-11-04 10:18:13 +00:00
|
|
|
uint bridge_z = GetBridgePixelHeight(rampsouth);
|
2011-11-04 11:52:19 +00:00
|
|
|
int z = bridge_z - BRIDGE_Z_START;
|
2007-09-19 16:36:42 +00:00
|
|
|
|
2010-10-30 17:51:07 +00:00
|
|
|
/* Add a bounding box that separates the bridge from things below it. */
|
2007-09-19 16:36:42 +00:00
|
|
|
AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, x, y, 16, 16, 1, bridge_z - TILE_HEIGHT + BB_Z_SEPARATOR);
|
|
|
|
|
|
|
|
/* Draw Trambits as SpriteCombine */
|
2010-02-07 22:22:54 +00:00
|
|
|
if (transport_type == TRANSPORT_ROAD || transport_type == TRANSPORT_RAIL) StartSpriteCombine();
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2007-09-19 16:36:42 +00:00
|
|
|
/* Draw floor and far part of bridge*/
|
2008-04-03 19:55:40 +00:00
|
|
|
if (!IsInvisibilitySet(TO_BRIDGES)) {
|
|
|
|
if (axis == AXIS_X) {
|
|
|
|
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
|
|
|
|
} else {
|
|
|
|
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2006-06-02 13:05:41 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
psid++;
|
2006-06-02 13:05:41 +00:00
|
|
|
|
2008-02-13 03:21:19 +00:00
|
|
|
if (transport_type == TRANSPORT_ROAD) {
|
2019-04-06 06:46:15 +00:00
|
|
|
/* DrawBridgeRoadBits() calls EndSpriteCombine() and StartSpriteCombine() */
|
|
|
|
DrawBridgeRoadBits(rampsouth, x, y, bridge_z, axis ^ 1, false);
|
2008-08-25 18:14:19 +00:00
|
|
|
} else if (transport_type == TRANSPORT_RAIL) {
|
2010-02-07 22:22:54 +00:00
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(rampsouth));
|
2012-01-28 18:11:18 +00:00
|
|
|
if (rti->UsesOverlay() && !IsInvisibilitySet(TO_BRIDGES)) {
|
2010-08-09 10:59:30 +00:00
|
|
|
SpriteID surface = GetCustomRailSprite(rti, rampsouth, RTSG_BRIDGE, TCX_ON_BRIDGE);
|
2010-02-07 22:22:54 +00:00
|
|
|
if (surface != 0) {
|
|
|
|
AddSortableSpriteToDraw(surface + axis, PAL_NONE, x, y, 16, 16, 0, bridge_z, IsTransparencySet(TO_BRIDGES));
|
|
|
|
}
|
|
|
|
}
|
2015-03-28 14:04:06 +00:00
|
|
|
|
|
|
|
if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && !IsInvisibilitySet(TO_BRIDGES) && HasTunnelBridgeReservation(rampnorth)) {
|
|
|
|
if (rti->UsesOverlay()) {
|
|
|
|
SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY);
|
|
|
|
AddSortableSpriteToDraw(overlay + RTO_X + axis, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, bridge_z, IsTransparencySet(TO_BRIDGES));
|
|
|
|
} else {
|
|
|
|
AddSortableSpriteToDraw(axis == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, bridge_z, IsTransparencySet(TO_BRIDGES));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-07 22:22:54 +00:00
|
|
|
EndSpriteCombine();
|
|
|
|
|
2016-11-05 11:53:03 +00:00
|
|
|
if (HasRailCatenaryDrawn(GetRailType(rampsouth))) {
|
|
|
|
DrawRailCatenaryOnBridge(ti);
|
2008-08-25 18:14:19 +00:00
|
|
|
}
|
2007-05-25 11:01:44 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* draw roof, the component of the bridge which is logically between the vehicle and the camera */
|
2008-04-03 19:55:40 +00:00
|
|
|
if (!IsInvisibilitySet(TO_BRIDGES)) {
|
|
|
|
if (axis == AXIS_X) {
|
|
|
|
y += 12;
|
|
|
|
if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 4, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 3, BRIDGE_Z_START);
|
|
|
|
} else {
|
|
|
|
x += 12;
|
|
|
|
if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 4, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 3, 0, BRIDGE_Z_START);
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
|
2007-09-19 16:36:42 +00:00
|
|
|
/* Draw TramFront as SpriteCombine */
|
2008-02-13 03:21:19 +00:00
|
|
|
if (transport_type == TRANSPORT_ROAD) EndSpriteCombine();
|
2007-09-19 16:36:42 +00:00
|
|
|
|
2008-04-03 19:55:40 +00:00
|
|
|
/* Do not draw anything more if bridges are invisible */
|
|
|
|
if (IsInvisibilitySet(TO_BRIDGES)) return;
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
psid++;
|
2020-05-16 15:05:37 +00:00
|
|
|
DrawBridgePillars(psid, ti, axis, drawfarpillar, x, y, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2011-11-04 11:36:10 +00:00
|
|
|
static int GetSlopePixelZ_TunnelBridge(TileIndex tile, uint x, uint y)
|
2005-10-19 14:49:46 +00:00
|
|
|
{
|
2011-11-04 11:30:37 +00:00
|
|
|
int z;
|
2011-11-04 10:18:13 +00:00
|
|
|
Slope tileh = GetTilePixelSlope(tile, &z);
|
2006-08-06 16:32:49 +00:00
|
|
|
|
|
|
|
x &= 0xF;
|
|
|
|
y &= 0xF;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-12 05:19:19 +00:00
|
|
|
if (IsTunnel(tile)) {
|
2007-12-16 15:38:51 +00:00
|
|
|
uint pos = (DiagDirToAxis(GetTunnelBridgeDirection(tile)) == AXIS_X ? y : x);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* In the tunnel entrance? */
|
2006-04-12 05:19:19 +00:00
|
|
|
if (5 <= pos && pos <= 10) return z;
|
2008-01-23 14:51:36 +00:00
|
|
|
} else { // IsBridge(tile)
|
2007-12-16 15:38:51 +00:00
|
|
|
DiagDirection dir = GetTunnelBridgeDirection(tile);
|
2006-12-27 12:38:02 +00:00
|
|
|
uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
|
|
|
|
|
2011-11-04 10:18:13 +00:00
|
|
|
z += ApplyPixelFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh);
|
2007-07-26 16:51:10 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* On the bridge ramp? */
|
2006-12-27 12:38:02 +00:00
|
|
|
if (5 <= pos && pos <= 10) {
|
2011-11-04 11:30:37 +00:00
|
|
|
int delta;
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2008-01-22 16:08:17 +00:00
|
|
|
if (tileh != SLOPE_FLAT) return z + TILE_HEIGHT;
|
2006-12-27 12:38:02 +00:00
|
|
|
|
|
|
|
switch (dir) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case DIAGDIR_NE: delta = (TILE_SIZE - 1 - x) / 2; break;
|
|
|
|
case DIAGDIR_SE: delta = y / 2; break;
|
|
|
|
case DIAGDIR_SW: delta = x / 2; break;
|
|
|
|
case DIAGDIR_NW: delta = (TILE_SIZE - 1 - y) / 2; break;
|
2006-04-12 05:19:19 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
return z + 1 + delta;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 10:18:13 +00:00
|
|
|
return z + GetPartialPixelZ(x, y, tileh);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh)
|
2005-11-14 19:48:04 +00:00
|
|
|
{
|
2007-12-16 15:38:51 +00:00
|
|
|
return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(tile)));
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-06-11 16:24:00 +00:00
|
|
|
TransportType tt = GetTunnelBridgeTransportType(tile);
|
|
|
|
|
2006-03-12 15:04:03 +00:00
|
|
|
if (IsTunnel(tile)) {
|
2009-08-05 17:59:21 +00:00
|
|
|
td->str = (tt == TRANSPORT_RAIL) ? STR_LAI_TUNNEL_DESCRIPTION_RAILROAD : STR_LAI_TUNNEL_DESCRIPTION_ROAD;
|
2008-06-11 16:24:00 +00:00
|
|
|
} else { // IsBridge(tile)
|
2009-08-05 17:59:21 +00:00
|
|
|
td->str = (tt == TRANSPORT_WATER) ? STR_LAI_BRIDGE_DESCRIPTION_AQUEDUCT : GetBridgeSpec(GetBridgeType(tile))->transport_name[tt];
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-21 22:15:39 +00:00
|
|
|
td->owner[0] = GetTileOwner(tile);
|
2009-03-02 22:57:47 +00:00
|
|
|
|
|
|
|
Owner road_owner = INVALID_OWNER;
|
|
|
|
Owner tram_owner = INVALID_OWNER;
|
2019-04-06 06:46:15 +00:00
|
|
|
RoadType road_rt = GetRoadTypeRoad(tile);
|
|
|
|
RoadType tram_rt = GetRoadTypeTram(tile);
|
|
|
|
if (road_rt != INVALID_ROADTYPE) {
|
|
|
|
const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
|
|
|
|
td->roadtype = rti->strings.name;
|
|
|
|
td->road_speed = rti->max_speed / 2;
|
|
|
|
road_owner = GetRoadOwner(tile, RTT_ROAD);
|
|
|
|
}
|
|
|
|
if (tram_rt != INVALID_ROADTYPE) {
|
|
|
|
const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
|
|
|
|
td->tramtype = rti->strings.name;
|
|
|
|
td->tram_speed = rti->max_speed / 2;
|
|
|
|
tram_owner = GetRoadOwner(tile, RTT_TRAM);
|
|
|
|
}
|
2009-03-02 22:57:47 +00:00
|
|
|
|
|
|
|
/* Is there a mix of owners? */
|
|
|
|
if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
|
|
|
|
(road_owner != INVALID_OWNER && road_owner != td->owner[0])) {
|
|
|
|
uint i = 1;
|
|
|
|
if (road_owner != INVALID_OWNER) {
|
2009-04-21 23:40:56 +00:00
|
|
|
td->owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
|
2009-03-02 22:57:47 +00:00
|
|
|
td->owner[i] = road_owner;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (tram_owner != INVALID_OWNER) {
|
2009-04-21 23:40:56 +00:00
|
|
|
td->owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
|
2009-03-02 22:57:47 +00:00
|
|
|
td->owner[i] = tram_owner;
|
|
|
|
}
|
|
|
|
}
|
2010-03-16 06:43:41 +00:00
|
|
|
|
|
|
|
if (tt == TRANSPORT_RAIL) {
|
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
|
|
|
|
td->rail_speed = rti->max_speed;
|
2016-12-09 21:27:22 +00:00
|
|
|
td->railtype = rti->strings.name;
|
2010-03-16 06:43:41 +00:00
|
|
|
|
|
|
|
if (!IsTunnel(tile)) {
|
|
|
|
uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
|
|
|
|
if (td->rail_speed == 0 || spd < td->rail_speed) {
|
|
|
|
td->rail_speed = spd;
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 13:50:10 +00:00
|
|
|
} else if (tt == TRANSPORT_ROAD && !IsTunnel(tile)) {
|
2019-04-06 06:46:15 +00:00
|
|
|
uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
|
|
|
|
if (road_rt != INVALID_ROADTYPE && (td->road_speed == 0 || spd < td->road_speed)) td->road_speed = spd;
|
|
|
|
if (tram_rt != INVALID_ROADTYPE && (td->tram_speed == 0 || spd < td->tram_speed)) td->tram_speed = spd;
|
2010-03-16 06:43:41 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoop_TunnelBridge(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-12-16 19:30:42 +00:00
|
|
|
bool snow_or_desert = HasTunnelBridgeSnowOrDesert(tile);
|
2008-05-29 15:13:28 +00:00
|
|
|
switch (_settings_game.game_creation.landscape) {
|
2010-08-09 07:19:44 +00:00
|
|
|
case LT_ARCTIC: {
|
|
|
|
/* As long as we do not have a snow density, we want to use the density
|
2013-01-08 22:46:42 +00:00
|
|
|
* from the entry edge. For tunnels this is the lowest point for bridges the highest point.
|
2010-08-09 07:19:44 +00:00
|
|
|
* (Independent of foundations) */
|
2011-11-04 11:52:19 +00:00
|
|
|
int z = IsBridge(tile) ? GetTileMaxZ(tile) : GetTileZ(tile);
|
2010-08-09 07:19:44 +00:00
|
|
|
if (snow_or_desert != (z > GetSnowLine())) {
|
2007-12-16 19:30:42 +00:00
|
|
|
SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
|
2006-07-22 14:31:56 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-02-13 21:15:00 +00:00
|
|
|
break;
|
2010-08-09 07:19:44 +00:00
|
|
|
}
|
2006-02-13 21:15:00 +00:00
|
|
|
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_TROPIC:
|
2006-12-29 09:10:44 +00:00
|
|
|
if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) {
|
2007-12-16 19:30:42 +00:00
|
|
|
SetTunnelBridgeSnowOrDesert(tile, true);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
2006-02-13 21:15:00 +00:00
|
|
|
break;
|
2007-12-16 19:30:42 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 17:49:50 +00:00
|
|
|
static TrackStatus GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-02-13 03:21:19 +00:00
|
|
|
TransportType transport_type = GetTunnelBridgeTransportType(tile);
|
2019-04-06 06:46:15 +00:00
|
|
|
if (transport_type != mode || (transport_type == TRANSPORT_ROAD && !HasTileRoadType(tile, (RoadTramType)sub_mode))) return 0;
|
2008-02-18 16:11:31 +00:00
|
|
|
|
|
|
|
DiagDirection dir = GetTunnelBridgeDirection(tile);
|
|
|
|
if (side != INVALID_DIAGDIR && side != ReverseDiagDir(dir)) return 0;
|
2008-05-14 18:31:21 +00:00
|
|
|
return CombineTrackStatus(TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir)), TRACKDIR_BIT_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner new_owner)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2011-12-03 23:40:13 +00:00
|
|
|
TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
|
|
|
|
/* Set number of pieces to zero if it's the southern tile as we
|
|
|
|
* don't want to update the infrastructure counts twice. */
|
|
|
|
uint num_pieces = tile < other_end ? (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR : 0;
|
|
|
|
|
2021-04-30 15:01:26 +00:00
|
|
|
for (RoadTramType rtt : _roadtramtypes) {
|
2009-03-02 22:57:47 +00:00
|
|
|
/* Update all roadtypes, no matter if they are present */
|
2019-04-06 06:46:15 +00:00
|
|
|
if (GetRoadOwner(tile, rtt) == old_owner) {
|
|
|
|
RoadType rt = GetRoadType(tile, rtt);
|
|
|
|
if (rt != INVALID_ROADTYPE) {
|
2011-12-03 23:40:18 +00:00
|
|
|
/* Update company infrastructure counts. A full diagonal road tile has two road bits.
|
|
|
|
* No need to dirty windows here, we'll redraw the whole screen anyway. */
|
|
|
|
Company::Get(old_owner)->infrastructure.road[rt] -= num_pieces * 2;
|
|
|
|
if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += num_pieces * 2;
|
|
|
|
}
|
|
|
|
|
2019-04-06 06:46:15 +00:00
|
|
|
SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
|
2009-03-02 22:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!IsTileOwner(tile, old_owner)) return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2011-12-03 23:40:13 +00:00
|
|
|
/* Update company infrastructure counts for rail and water as well.
|
|
|
|
* No need to dirty windows here, we'll redraw the whole screen anyway. */
|
|
|
|
TransportType tt = GetTunnelBridgeTransportType(tile);
|
|
|
|
Company *old = Company::Get(old_owner);
|
|
|
|
if (tt == TRANSPORT_RAIL) {
|
|
|
|
old->infrastructure.rail[GetRailType(tile)] -= num_pieces;
|
|
|
|
if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.rail[GetRailType(tile)] += num_pieces;
|
2011-12-03 23:40:23 +00:00
|
|
|
} else if (tt == TRANSPORT_WATER) {
|
|
|
|
old->infrastructure.water -= num_pieces;
|
|
|
|
if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.water += num_pieces;
|
2011-12-03 23:40:13 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (new_owner != INVALID_OWNER) {
|
|
|
|
SetTileOwner(tile, new_owner);
|
2006-08-28 18:53:03 +00:00
|
|
|
} else {
|
2011-12-03 23:40:13 +00:00
|
|
|
if (tt == TRANSPORT_RAIL) {
|
2011-01-14 13:19:23 +00:00
|
|
|
/* Since all of our vehicles have been removed, it is safe to remove the rail
|
|
|
|
* bridge / tunnel. */
|
2021-11-21 22:02:29 +00:00
|
|
|
[[maybe_unused]] CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile);
|
2011-01-14 13:19:23 +00:00
|
|
|
assert(ret.Succeeded());
|
|
|
|
} else {
|
|
|
|
/* In any other case, we can safely reassign the ownership to OWNER_NONE. */
|
2007-05-28 21:32:26 +00:00
|
|
|
SetTileOwner(tile, OWNER_NONE);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-10 23:14:48 +00:00
|
|
|
/**
|
|
|
|
* Frame when the 'enter tunnel' sound should be played. This is the second
|
|
|
|
* frame on a tile, so the sound is played shortly after entering the tunnel
|
|
|
|
* tile, while the vehicle is still visible.
|
|
|
|
*/
|
|
|
|
static const byte TUNNEL_SOUND_FRAME = 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-11-10 23:14:48 +00:00
|
|
|
/**
|
2010-11-12 19:40:39 +00:00
|
|
|
* Frame when a vehicle should be hidden in a tunnel with a certain direction.
|
2010-11-10 23:14:48 +00:00
|
|
|
* This differs per direction, because of visibility / bounding box issues.
|
|
|
|
* Note that direction, in this case, is the direction leading into the tunnel.
|
2010-11-12 19:40:39 +00:00
|
|
|
* When entering a tunnel, hide the vehicle when it reaches the given frame.
|
|
|
|
* When leaving a tunnel, show the vehicle when it is one frame further
|
2010-11-10 23:14:48 +00:00
|
|
|
* to the 'outside', i.e. at (TILE_SIZE-1) - (frame) + 1
|
|
|
|
*/
|
2010-11-12 19:40:39 +00:00
|
|
|
extern const byte _tunnel_visibility_frame[DIAGDIR_END] = {12, 8, 8, 12};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-12-21 22:50:51 +00:00
|
|
|
static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2011-11-04 10:18:13 +00:00
|
|
|
int z = GetSlopePixelZ(x, y) - v->z_pos;
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2007-11-19 18:58:04 +00:00
|
|
|
if (abs(z) > 2) return VETSB_CANNOT_ENTER;
|
2010-10-22 19:57:56 +00:00
|
|
|
/* Direction into the wormhole */
|
2008-02-13 03:02:02 +00:00
|
|
|
const DiagDirection dir = GetTunnelBridgeDirection(tile);
|
2010-10-22 19:57:56 +00:00
|
|
|
/* Direction of the vehicle */
|
|
|
|
const DiagDirection vdir = DirToDiagDir(v->direction);
|
2010-11-10 23:13:37 +00:00
|
|
|
/* New position of the vehicle on the tile */
|
|
|
|
byte pos = (DiagDirToAxis(vdir) == AXIS_X ? x : y) & TILE_UNIT_MASK;
|
|
|
|
/* Number of units moved by the vehicle since entering the tile */
|
|
|
|
byte frame = (vdir == DIAGDIR_NE || vdir == DIAGDIR_NW) ? TILE_SIZE - 1 - pos : pos;
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2006-03-12 15:04:03 +00:00
|
|
|
if (IsTunnel(tile)) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN) {
|
2009-06-06 16:54:22 +00:00
|
|
|
Train *t = Train::From(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-05-22 22:33:05 +00:00
|
|
|
if (t->track != TRACK_BIT_WORMHOLE && dir == vdir) {
|
2010-11-10 23:14:48 +00:00
|
|
|
if (t->IsFrontEngine() && frame == TUNNEL_SOUND_FRAME) {
|
2009-05-22 22:22:46 +00:00
|
|
|
if (!PlayVehicleSound(t, VSE_TUNNEL) && RailVehInfo(t->engine_type)->engclass == 0) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
|
2006-09-27 18:17:01 +00:00
|
|
|
}
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_CONTINUE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2010-11-12 19:40:39 +00:00
|
|
|
if (frame == _tunnel_visibility_frame[dir]) {
|
2009-05-22 22:22:46 +00:00
|
|
|
t->tile = tile;
|
2009-05-22 22:33:05 +00:00
|
|
|
t->track = TRACK_BIT_WORMHOLE;
|
2009-05-22 22:22:46 +00:00
|
|
|
t->vehstatus |= VS_HIDDEN;
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 19:40:39 +00:00
|
|
|
if (dir == ReverseDiagDir(vdir) && frame == TILE_SIZE - _tunnel_visibility_frame[dir] && z == 0) {
|
2004-08-11 22:07:08 +00:00
|
|
|
/* We're at the tunnel exit ?? */
|
2009-05-22 22:22:46 +00:00
|
|
|
t->tile = tile;
|
2010-10-22 20:04:13 +00:00
|
|
|
t->track = DiagDirToDiagTrackBits(vdir);
|
2009-05-22 22:33:05 +00:00
|
|
|
assert(t->track);
|
2009-05-22 22:22:46 +00:00
|
|
|
t->vehstatus &= ~VS_HIDDEN;
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-03-08 16:27:54 +00:00
|
|
|
} else if (v->type == VEH_ROAD) {
|
2009-06-06 16:54:22 +00:00
|
|
|
RoadVehicle *rv = RoadVehicle::From(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Enter tunnel? */
|
2009-05-22 20:22:20 +00:00
|
|
|
if (rv->state != RVSB_WORMHOLE && dir == vdir) {
|
2010-11-12 19:40:39 +00:00
|
|
|
if (frame == _tunnel_visibility_frame[dir]) {
|
2010-11-10 23:15:48 +00:00
|
|
|
/* Frame should be equal to the next frame number in the RV's movement */
|
|
|
|
assert(frame == rv->frame + 1);
|
2009-05-22 20:22:20 +00:00
|
|
|
rv->tile = tile;
|
|
|
|
rv->state = RVSB_WORMHOLE;
|
|
|
|
rv->vehstatus |= VS_HIDDEN;
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_CONTINUE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-10 23:15:48 +00:00
|
|
|
/* We're at the tunnel exit ?? */
|
2010-11-12 19:40:39 +00:00
|
|
|
if (dir == ReverseDiagDir(vdir) && frame == TILE_SIZE - _tunnel_visibility_frame[dir] && z == 0) {
|
2009-05-22 20:22:20 +00:00
|
|
|
rv->tile = tile;
|
2010-10-22 20:04:13 +00:00
|
|
|
rv->state = DiagDirToDiagTrackdir(vdir);
|
2010-11-10 23:15:48 +00:00
|
|
|
rv->frame = frame;
|
2009-05-22 20:22:20 +00:00
|
|
|
rv->vehstatus &= ~VS_HIDDEN;
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-23 14:51:36 +00:00
|
|
|
} else { // IsBridge(tile)
|
2010-11-10 20:15:48 +00:00
|
|
|
if (v->type != VEH_SHIP) {
|
2006-12-27 12:38:02 +00:00
|
|
|
/* modify speed of vehicle */
|
2008-02-05 05:21:02 +00:00
|
|
|
uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_ROAD) spd *= 2;
|
2010-11-10 20:15:48 +00:00
|
|
|
Vehicle *first = v->First();
|
2021-01-08 10:16:18 +00:00
|
|
|
first->cur_speed = std::min(first->cur_speed, spd);
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 19:57:56 +00:00
|
|
|
if (vdir == dir) {
|
2010-11-10 23:16:28 +00:00
|
|
|
/* Vehicle enters bridge at the last frame inside this tile. */
|
|
|
|
if (frame != TILE_SIZE - 1) return VETSB_CONTINUE;
|
2008-06-11 13:54:01 +00:00
|
|
|
switch (v->type) {
|
2009-05-22 22:22:46 +00:00
|
|
|
case VEH_TRAIN: {
|
2009-06-06 16:54:22 +00:00
|
|
|
Train *t = Train::From(v);
|
2009-05-22 22:33:05 +00:00
|
|
|
t->track = TRACK_BIT_WORMHOLE;
|
2010-03-06 12:50:55 +00:00
|
|
|
ClrBit(t->gv_flags, GVF_GOINGUP_BIT);
|
|
|
|
ClrBit(t->gv_flags, GVF_GOINGDOWN_BIT);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-11 13:54:01 +00:00
|
|
|
|
2010-03-06 12:56:57 +00:00
|
|
|
case VEH_ROAD: {
|
|
|
|
RoadVehicle *rv = RoadVehicle::From(v);
|
|
|
|
rv->state = RVSB_WORMHOLE;
|
|
|
|
/* There are no slopes inside bridges / tunnels. */
|
|
|
|
ClrBit(rv->gv_flags, GVF_GOINGUP_BIT);
|
|
|
|
ClrBit(rv->gv_flags, GVF_GOINGDOWN_BIT);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-11 13:54:01 +00:00
|
|
|
|
|
|
|
case VEH_SHIP:
|
2009-06-06 16:54:22 +00:00
|
|
|
Ship::From(v)->state = TRACK_BIT_WORMHOLE;
|
2008-06-11 13:54:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2010-10-22 19:57:56 +00:00
|
|
|
} else if (vdir == ReverseDiagDir(dir)) {
|
2006-12-27 12:38:02 +00:00
|
|
|
v->tile = tile;
|
2008-06-11 13:54:01 +00:00
|
|
|
switch (v->type) {
|
2009-05-22 22:22:46 +00:00
|
|
|
case VEH_TRAIN: {
|
2009-06-06 16:54:22 +00:00
|
|
|
Train *t = Train::From(v);
|
2009-05-22 22:33:05 +00:00
|
|
|
if (t->track == TRACK_BIT_WORMHOLE) {
|
2010-10-22 20:04:13 +00:00
|
|
|
t->track = DiagDirToDiagTrackBits(vdir);
|
2008-06-11 13:54:01 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-11 13:54:01 +00:00
|
|
|
|
2009-05-22 20:22:20 +00:00
|
|
|
case VEH_ROAD: {
|
2009-06-06 16:54:22 +00:00
|
|
|
RoadVehicle *rv = RoadVehicle::From(v);
|
2009-05-22 20:22:20 +00:00
|
|
|
if (rv->state == RVSB_WORMHOLE) {
|
2010-10-22 20:04:13 +00:00
|
|
|
rv->state = DiagDirToDiagTrackdir(vdir);
|
2009-05-22 20:22:20 +00:00
|
|
|
rv->frame = 0;
|
2008-06-11 13:54:01 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-11 13:54:01 +00:00
|
|
|
|
2009-05-22 20:22:20 +00:00
|
|
|
case VEH_SHIP: {
|
2009-06-06 16:54:22 +00:00
|
|
|
Ship *ship = Ship::From(v);
|
2009-05-22 20:22:20 +00:00
|
|
|
if (ship->state == TRACK_BIT_WORMHOLE) {
|
2010-10-22 20:04:13 +00:00
|
|
|
ship->state = DiagDirToDiagTrackBits(vdir);
|
2008-06-11 13:54:01 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-11 13:54:01 +00:00
|
|
|
|
|
|
|
default: NOT_REACHED();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_CONTINUE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2011-11-04 11:36:10 +00:00
|
|
|
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
|
2007-08-30 17:17:04 +00:00
|
|
|
{
|
2008-06-11 14:51:31 +00:00
|
|
|
if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() && IsBridge(tile) && GetTunnelBridgeTransportType(tile) != TRANSPORT_WATER) {
|
2007-12-16 15:38:51 +00:00
|
|
|
DiagDirection direction = GetTunnelBridgeDirection(tile);
|
2007-09-14 22:27:40 +00:00
|
|
|
Axis axis = DiagDirToAxis(direction);
|
|
|
|
CommandCost res;
|
2011-11-04 11:30:37 +00:00
|
|
|
int z_old;
|
2011-11-04 10:28:20 +00:00
|
|
|
Slope tileh_old = GetTileSlope(tile, &z_old);
|
2007-09-14 22:27:40 +00:00
|
|
|
|
2008-08-25 20:54:34 +00:00
|
|
|
/* Check if new slope is valid for bridges in general (so we can safely call GetBridgeFoundation()) */
|
2007-09-14 22:27:40 +00:00
|
|
|
if ((direction == DIAGDIR_NW) || (direction == DIAGDIR_NE)) {
|
2018-10-17 19:52:16 +00:00
|
|
|
CheckBridgeSlope(BRIDGE_PIECE_SOUTH, axis, &tileh_old, &z_old);
|
|
|
|
res = CheckBridgeSlope(BRIDGE_PIECE_SOUTH, axis, &tileh_new, &z_new);
|
2007-09-14 22:27:40 +00:00
|
|
|
} else {
|
2018-10-17 19:52:16 +00:00
|
|
|
CheckBridgeSlope(BRIDGE_PIECE_NORTH, axis, &tileh_old, &z_old);
|
|
|
|
res = CheckBridgeSlope(BRIDGE_PIECE_NORTH, axis, &tileh_new, &z_new);
|
2007-09-14 22:27:40 +00:00
|
|
|
}
|
|
|
|
|
2008-01-21 15:48:00 +00:00
|
|
|
/* Surface slope is valid and remains unchanged? */
|
2010-01-18 22:57:21 +00:00
|
|
|
if (res.Succeeded() && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
|
2007-09-14 22:27:40 +00:00
|
|
|
}
|
|
|
|
|
2021-11-21 22:02:29 +00:00
|
|
|
return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
|
2007-08-30 17:17:04 +00:00
|
|
|
}
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
|
2009-03-15 00:32:18 +00:00
|
|
|
DrawTile_TunnelBridge, // draw_tile_proc
|
2011-11-04 10:18:13 +00:00
|
|
|
GetSlopePixelZ_TunnelBridge, // get_slope_z_proc
|
2009-03-15 00:32:18 +00:00
|
|
|
ClearTile_TunnelBridge, // clear_tile_proc
|
2019-04-10 21:07:06 +00:00
|
|
|
nullptr, // add_accepted_cargo_proc
|
2009-03-15 00:32:18 +00:00
|
|
|
GetTileDesc_TunnelBridge, // get_tile_desc_proc
|
|
|
|
GetTileTrackStatus_TunnelBridge, // get_tile_track_status_proc
|
2019-04-10 21:07:06 +00:00
|
|
|
nullptr, // click_tile_proc
|
|
|
|
nullptr, // animate_tile_proc
|
2011-11-08 17:37:32 +00:00
|
|
|
TileLoop_TunnelBridge, // tile_loop_proc
|
|
|
|
ChangeTileOwner_TunnelBridge, // change_tile_owner_proc
|
2019-04-10 21:07:06 +00:00
|
|
|
nullptr, // add_produced_cargo_proc
|
2009-03-15 00:32:18 +00:00
|
|
|
VehicleEnter_TunnelBridge, // vehicle_enter_tile_proc
|
|
|
|
GetFoundation_TunnelBridge, // get_foundation_proc
|
|
|
|
TerraformTile_TunnelBridge, // terraform_tile_proc
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|