2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 01:48:53 +00:00
|
|
|
/** @file tunnelbridge_cmd.cpp
|
2005-08-01 20:23:38 +00:00
|
|
|
* This file deals with tunnels and bridges (non-gui stuff)
|
|
|
|
* @todo seperate this file into two
|
|
|
|
*/
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-03-13 12:55:20 +00:00
|
|
|
#include "bridge_map.h"
|
2006-03-12 20:59:56 +00:00
|
|
|
#include "rail_map.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "road_map.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2007-07-16 09:16:58 +00:00
|
|
|
#include "strings.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2006-03-06 20:55:24 +00:00
|
|
|
#include "tunnel_map.h"
|
2006-12-27 12:38:02 +00:00
|
|
|
#include "unmovable_map.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "vehicle.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "town.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2005-08-01 20:23:38 +00:00
|
|
|
#include "bridge.h"
|
2005-11-18 23:41:03 +00:00
|
|
|
#include "train.h"
|
2006-03-12 20:59:56 +00:00
|
|
|
#include "water_map.h"
|
2006-05-27 16:12:16 +00:00
|
|
|
#include "yapf/yapf.h"
|
2006-08-14 14:21:15 +00:00
|
|
|
#include "date.h"
|
2006-09-27 18:17:01 +00:00
|
|
|
#include "newgrf_sound.h"
|
2007-09-14 22:27:40 +00:00
|
|
|
#include "autoslope.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-08-01 16:31:19 +00:00
|
|
|
#include "table/bridge_land.h"
|
|
|
|
|
2005-10-01 17:38:48 +00:00
|
|
|
const Bridge orig_bridge[] = {
|
2005-08-01 20:23:38 +00:00
|
|
|
/*
|
2006-08-16 11:39:55 +00:00
|
|
|
year of availablity
|
|
|
|
| minimum length
|
|
|
|
| | maximum length
|
|
|
|
| | | price
|
|
|
|
| | | | maximum speed
|
|
|
|
| | | | | sprite to use in GUI string with description
|
|
|
|
| | | | | | | */
|
2007-01-14 19:57:49 +00:00
|
|
|
{ 0, 0, 16, 80, 32, 0xA24, PAL_NONE , STR_5012_WOODEN , NULL, 0 },
|
|
|
|
{ 0, 0, 2, 112, 48, 0xA26, PALETTE_TO_STRUCT_RED , STR_5013_CONCRETE , NULL, 0 },
|
|
|
|
{ 1930, 0, 5, 144, 64, 0xA25, PAL_NONE , STR_500F_GIRDER_STEEL , NULL, 0 },
|
|
|
|
{ 0, 2, 10, 168, 80, 0xA22, PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 },
|
|
|
|
{ 1930, 3, 16, 185, 96, 0xA22, PAL_NONE , STR_500E_SUSPENSION_STEEL , NULL, 0 },
|
|
|
|
{ 1930, 3, 16, 192, 112, 0xA22, PALETTE_TO_STRUCT_YELLOW , STR_500E_SUSPENSION_STEEL , NULL, 0 },
|
|
|
|
{ 1930, 3, 7, 224, 160, 0xA23, PAL_NONE , STR_5010_CANTILEVER_STEEL , NULL, 0 },
|
|
|
|
{ 1930, 3, 8, 232, 208, 0xA23, PALETTE_TO_STRUCT_BROWN , STR_5010_CANTILEVER_STEEL , NULL, 0 },
|
|
|
|
{ 1930, 3, 9, 248, 240, 0xA23, PALETTE_TO_STRUCT_RED , STR_5010_CANTILEVER_STEEL , NULL, 0 },
|
|
|
|
{ 1930, 0, 2, 240, 256, 0xA27, PAL_NONE , STR_500F_GIRDER_STEEL , NULL, 0 },
|
|
|
|
{ 1995, 2, 16, 255, 320, 0xA28, PAL_NONE , STR_5014_TUBULAR_STEEL , NULL, 0 },
|
|
|
|
{ 2005, 2, 32, 380, 512, 0xA28, PALETTE_TO_STRUCT_YELLOW , STR_5014_TUBULAR_STEEL , NULL, 0 },
|
|
|
|
{ 2010, 2, 32, 510, 608, 0xA28, PALETTE_TO_STRUCT_GREY , STR_BRIDGE_TUBULAR_SILICON , NULL, 0 }
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-12-15 17:55:59 +00:00
|
|
|
Bridge _bridge[MAX_BRIDGES];
|
|
|
|
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/** calculate the price factor for building a long bridge.
|
|
|
|
* 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,
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
int CalcBridgeLenCostFactor(int x)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
int n;
|
|
|
|
int r;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (x < 2) return x;
|
|
|
|
x -= 2;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (n = 0, r = 2;; n++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (x <= n) return r + x * n;
|
|
|
|
r += n * n;
|
|
|
|
x -= n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
#define M(x) (1 << (x))
|
2007-03-07 12:11:48 +00:00
|
|
|
enum BridgeFoundation {
|
2007-04-04 03:21:14 +00:00
|
|
|
/* foundation, whole tile is leveled up --> 3 corners raised */
|
2006-04-23 13:48:16 +00:00
|
|
|
BRIDGE_FULL_LEVELED_FOUNDATION = M(SLOPE_WSE) | M(SLOPE_NWS) | M(SLOPE_ENW) | M(SLOPE_SEN),
|
2007-04-04 03:21:14 +00:00
|
|
|
/* foundation, tile is partly leveled up --> 1 corner raised */
|
2006-04-23 13:48:16 +00:00
|
|
|
BRIDGE_PARTLY_LEVELED_FOUNDATION = M(SLOPE_W) | M(SLOPE_S) | M(SLOPE_E) | M(SLOPE_N),
|
2007-04-04 03:21:14 +00:00
|
|
|
/* no foundations (X,Y direction) */
|
2006-04-23 13:48:16 +00:00
|
|
|
BRIDGE_NO_FOUNDATION = M(SLOPE_FLAT) | M(SLOPE_SW) | M(SLOPE_SE) | M(SLOPE_NW) | M(SLOPE_NE),
|
|
|
|
BRIDGE_HORZ_RAMP = (BRIDGE_PARTLY_LEVELED_FOUNDATION | BRIDGE_NO_FOUNDATION) & ~M(SLOPE_FLAT)
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-23 13:48:16 +00:00
|
|
|
#undef M
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-01 17:38:48 +00:00
|
|
|
static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table)
|
|
|
|
{
|
|
|
|
const Bridge *bridge = &_bridge[index];
|
|
|
|
assert(table < 7);
|
|
|
|
if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) {
|
|
|
|
return _bridge_sprite_table[index][table];
|
|
|
|
} else {
|
|
|
|
return bridge->sprite_table[table];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-15 16:07:00 +00:00
|
|
|
static inline byte GetBridgeFlags(int index) { return _bridge[index].flags;}
|
2005-08-01 20:23:38 +00:00
|
|
|
|
2006-08-08 07:12:33 +00:00
|
|
|
|
|
|
|
/** Check the slope at the bridge ramps in three easy steps:
|
|
|
|
* - valid slopes without foundation
|
|
|
|
* - valid slopes with foundation
|
|
|
|
* - rest is invalid
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2006-08-08 07:12:33 +00:00
|
|
|
#define M(x) (1 << (x))
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost CheckBridgeSlopeNorth(Axis axis, Slope tileh)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-08 07:12:33 +00:00
|
|
|
uint32 valid;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-08-08 07:12:33 +00:00
|
|
|
valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW));
|
2007-06-18 19:53:50 +00:00
|
|
|
if (HASBIT(valid, tileh)) return CommandCost();
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-08-08 07:12:33 +00:00
|
|
|
valid =
|
2006-08-10 14:44:32 +00:00
|
|
|
BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) | M(SLOPE_STEEP_N) |
|
|
|
|
(axis == AXIS_X ? M(SLOPE_E) | M(SLOPE_STEEP_E) : M(SLOPE_W) | M(SLOPE_STEEP_W));
|
2007-06-18 19:53:50 +00:00
|
|
|
if (HASBIT(valid, tileh)) return CommandCost(_price.terraform);
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-08-08 07:12:33 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope tileh)
|
2006-08-08 07:12:33 +00:00
|
|
|
{
|
|
|
|
uint32 valid;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-08 07:12:33 +00:00
|
|
|
valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE));
|
2007-06-18 19:53:50 +00:00
|
|
|
if (HASBIT(valid, tileh)) return CommandCost();
|
2006-08-08 07:12:33 +00:00
|
|
|
|
|
|
|
valid =
|
2006-08-10 14:44:32 +00:00
|
|
|
BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) | M(SLOPE_STEEP_S) |
|
|
|
|
(axis == AXIS_X ? M(SLOPE_W) | M(SLOPE_STEEP_W) : M(SLOPE_E) | M(SLOPE_STEEP_E));
|
2007-06-18 19:53:50 +00:00
|
|
|
if (HASBIT(valid, tileh)) return CommandCost(_price.terraform);
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2006-08-08 07:12:33 +00:00
|
|
|
#undef M
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
uint32 GetBridgeLength(TileIndex begin, TileIndex end)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
int x1 = TileX(begin);
|
|
|
|
int y1 = TileY(begin);
|
|
|
|
int x2 = TileX(end);
|
|
|
|
int y2 = TileY(end);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
return abs(x2 + y2 - x1 - y1) - 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-08-01 20:23:38 +00:00
|
|
|
const Bridge *b = &_bridge[bridge_type];
|
2005-11-14 19:48:04 +00:00
|
|
|
uint max; // max possible length of a bridge (with patch 100)
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 13:26:15 +00:00
|
|
|
if (bridge_type >= MAX_BRIDGES) return false;
|
2005-08-01 20:23:38 +00:00
|
|
|
if (b->avail_year > _cur_year) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-08-01 20:23:38 +00:00
|
|
|
max = b->max_length;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (max >= 16 && _patches.longbridges) max = 100;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
return b->min_length <= bridge_len && bridge_len <= max;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-07 10:26:12 +00:00
|
|
|
/** Build a Bridge
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param end_tile end tile
|
2007-04-04 03:21:14 +00:00
|
|
|
* @param flags type of operation
|
2005-05-07 10:26:12 +00:00
|
|
|
* @param p1 packed start tile coords (~ dx)
|
|
|
|
* @param p2 various bitstuffed elements
|
|
|
|
* - p2 = (bit 0- 7) - bridge type (hi bh)
|
2007-05-20 19:14:08 +00:00
|
|
|
* - p2 = (bit 8-..) - rail type or road types.
|
|
|
|
* - p2 = (bit 15 ) - set means road bridge.
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-02-03 21:55:14 +00:00
|
|
|
uint bridge_type;
|
2006-03-11 17:06:16 +00:00
|
|
|
RailType railtype;
|
2007-05-20 19:14:08 +00:00
|
|
|
RoadTypes roadtypes;
|
2006-05-16 12:04:53 +00:00
|
|
|
uint x;
|
|
|
|
uint y;
|
|
|
|
uint sx;
|
|
|
|
uint sy;
|
2006-03-23 06:30:39 +00:00
|
|
|
TileIndex tile_start;
|
|
|
|
TileIndex tile_end;
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope tileh_start;
|
|
|
|
Slope tileh_end;
|
2006-03-23 06:30:39 +00:00
|
|
|
uint z_start;
|
|
|
|
uint z_end;
|
2006-03-10 17:01:51 +00:00
|
|
|
TileIndex tile;
|
|
|
|
TileIndexDiff delta;
|
2005-11-14 19:48:04 +00:00
|
|
|
uint bridge_len;
|
2006-03-08 06:55:33 +00:00
|
|
|
Axis direction;
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost cost, terraformcost, ret;
|
2005-03-27 15:56:54 +00:00
|
|
|
bool allow_on_slopes;
|
2007-02-03 21:55:14 +00:00
|
|
|
bool replace_bridge = false;
|
|
|
|
uint replaced_bridge_type;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* unpack parameters */
|
2005-07-20 15:29:28 +00:00
|
|
|
bridge_type = GB(p2, 0, 8);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-01-30 17:18:45 +00:00
|
|
|
if (p1 >= MapSize()) return CMD_ERROR;
|
2005-05-07 10:26:12 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* type of bridge */
|
2006-03-11 17:06:16 +00:00
|
|
|
if (HASBIT(p2, 15)) {
|
2007-01-27 10:08:08 +00:00
|
|
|
railtype = INVALID_RAILTYPE; // road bridge
|
2007-05-20 22:43:26 +00:00
|
|
|
roadtypes = (RoadTypes)GB(p2, 8, 3);
|
|
|
|
if (!AreValidRoadTypes(roadtypes)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-03-11 17:06:16 +00:00
|
|
|
if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR;
|
2007-01-10 18:56:51 +00:00
|
|
|
railtype = (RailType)GB(p2, 8, 8);
|
2007-05-20 22:43:26 +00:00
|
|
|
roadtypes = ROADTYPES_NONE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 12:36:04 +00:00
|
|
|
x = TileX(end_tile);
|
|
|
|
y = TileY(end_tile);
|
|
|
|
sx = TileX(p1);
|
|
|
|
sy = TileY(p1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* check if valid, and make sure that (x,y) are smaller than (sx,sy) */
|
|
|
|
if (x == sx) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (y == sy) return_cmd_error(STR_5008_CANNOT_START_AND_END_ON);
|
2006-03-08 06:55:33 +00:00
|
|
|
direction = AXIS_Y;
|
2007-02-22 08:43:02 +00:00
|
|
|
if (y > sy) Swap(y, sy);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (y == sy) {
|
2006-03-08 06:55:33 +00:00
|
|
|
direction = AXIS_X;
|
2007-02-22 08:43:02 +00:00
|
|
|
if (x > sx) Swap(x, sx);
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 13:26:15 +00:00
|
|
|
/* set and test bridge length, availability */
|
2006-06-10 08:37:41 +00:00
|
|
|
bridge_len = sx + sy - x - y - 1;
|
2005-05-09 13:26:15 +00:00
|
|
|
if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* retrieve landscape height and ensure it's on land */
|
2006-04-10 12:36:04 +00:00
|
|
|
tile_start = TileXY(x, y);
|
|
|
|
tile_end = TileXY(sx, sy);
|
2006-06-10 08:37:41 +00:00
|
|
|
if (IsClearWaterTile(tile_start) || IsClearWaterTile(tile_end)) {
|
|
|
|
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-23 06:30:39 +00:00
|
|
|
tileh_start = GetTileSlope(tile_start, &z_start);
|
|
|
|
tileh_end = GetTileSlope(tile_end, &z_end);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-10 14:44:32 +00:00
|
|
|
if (IsSteepSlope(tileh_start)) z_start += TILE_HEIGHT;
|
2007-08-03 23:18:56 +00:00
|
|
|
if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) z_start += TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-10 14:44:32 +00:00
|
|
|
if (IsSteepSlope(tileh_end)) z_end += TILE_HEIGHT;
|
2007-08-03 23:18:56 +00:00
|
|
|
if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) z_end += TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-23 06:30:39 +00:00
|
|
|
if (z_start != z_end) return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED);
|
2005-03-27 15:56:54 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Towns are not allowed to use bridges on slopes. */
|
2005-09-13 12:19:27 +00:00
|
|
|
allow_on_slopes = (!_is_old_ai_player
|
2005-05-09 13:26:15 +00:00
|
|
|
&& _current_player != OWNER_TOWN && _patches.build_on_slopes);
|
2005-03-27 15:56:54 +00:00
|
|
|
|
2007-02-03 21:55:14 +00:00
|
|
|
TransportType transport_type = railtype == INVALID_RAILTYPE ? TRANSPORT_ROAD : TRANSPORT_RAIL;
|
2005-03-27 15:56:54 +00:00
|
|
|
|
2007-02-03 21:55:14 +00:00
|
|
|
if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
|
|
|
|
GetOtherBridgeEnd(tile_start) == tile_end &&
|
|
|
|
GetBridgeTransportType(tile_start) == transport_type) {
|
|
|
|
/* Replace a current bridge. */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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) {
|
|
|
|
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not replace town bridges with lower speed bridges. */
|
|
|
|
if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
|
|
|
|
_bridge[bridge_type].speed < _bridge[GetBridgeType(tile_start)].speed) {
|
|
|
|
Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
|
|
|
|
|
|
|
|
if (t == NULL) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
} else {
|
|
|
|
SetDParam(0, t->index);
|
|
|
|
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
|
|
|
|
}
|
|
|
|
}
|
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. */
|
|
|
|
if (!(flags & DC_QUERY_COST) && bridge_type == GetBridgeType(tile_start)) {
|
|
|
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
|
|
|
}
|
2005-03-27 15:56:54 +00:00
|
|
|
|
2007-02-03 21:55:14 +00:00
|
|
|
/* Do not allow replacing another player's bridges. */
|
|
|
|
if (!IsTileOwner(tile_start, _current_player) && !IsTileOwner(tile_start, OWNER_TOWN)) {
|
|
|
|
return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost((bridge_len + 1) * _price.clear_bridge); // The cost of clearing the current bridge.
|
2007-02-03 21:55:14 +00:00
|
|
|
replace_bridge = true;
|
|
|
|
replaced_bridge_type = GetBridgeType(tile_start);
|
2007-05-26 20:30:40 +00:00
|
|
|
|
|
|
|
/* Do not remove road types when upgrading a bridge */
|
|
|
|
roadtypes |= GetRoadTypes(tile_start);
|
2007-02-03 21:55:14 +00:00
|
|
|
} else {
|
|
|
|
/* Build a new bridge. */
|
|
|
|
|
|
|
|
/* Try and clear the start landscape */
|
|
|
|
ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
if (CmdFailed(ret)) return ret;
|
|
|
|
cost = ret;
|
|
|
|
|
|
|
|
terraformcost = CheckBridgeSlopeNorth(direction, tileh_start);
|
2007-06-18 19:53:50 +00:00
|
|
|
if (CmdFailed(terraformcost) || (terraformcost.GetCost() != 0 && !allow_on_slopes))
|
2007-02-03 21:55:14 +00:00
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(terraformcost);
|
2007-02-03 21:55:14 +00:00
|
|
|
|
|
|
|
/* Try and clear the end landscape */
|
|
|
|
ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
if (CmdFailed(ret)) 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 */
|
2007-02-03 21:55:14 +00:00
|
|
|
terraformcost = CheckBridgeSlopeSouth(direction, tileh_end);
|
2007-06-18 19:53:50 +00:00
|
|
|
if (CmdFailed(terraformcost) || (terraformcost.GetCost() != 0 && !allow_on_slopes))
|
2007-02-03 21:55:14 +00:00
|
|
|
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(terraformcost);
|
2007-02-03 21:55:14 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-03 21:55:14 +00:00
|
|
|
if (!replace_bridge) {
|
2006-12-27 12:38:02 +00:00
|
|
|
TileIndex Heads[] = {tile_start, tile_end};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (MayHaveBridgeAbove(Heads[i])) {
|
|
|
|
if (IsBridgeAbove(Heads[i])) {
|
|
|
|
TileIndex north_head = GetNorthernBridgeEnd(Heads[i]);
|
|
|
|
|
|
|
|
if (direction == GetBridgeAxis(Heads[i])) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
|
|
|
|
if (z_start + TILE_HEIGHT == GetBridgeHeight(north_head)) {
|
|
|
|
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-27 15:56:54 +00:00
|
|
|
|
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);
|
2007-02-03 21:55:14 +00:00
|
|
|
Owner owner = (replace_bridge && IsTileOwner(tile_start, OWNER_TOWN)) ? OWNER_TOWN : _current_player;
|
2006-03-15 07:10:41 +00:00
|
|
|
|
2007-01-27 10:08:08 +00:00
|
|
|
if (railtype != INVALID_RAILTYPE) {
|
2007-02-03 21:55:14 +00:00
|
|
|
MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype);
|
|
|
|
MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype);
|
2006-03-15 07:10:41 +00:00
|
|
|
} else {
|
2007-05-20 19:14:08 +00:00
|
|
|
MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir, roadtypes);
|
|
|
|
MakeRoadBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), roadtypes);
|
2006-03-15 07:10:41 +00:00
|
|
|
}
|
2006-03-23 06:30:39 +00:00
|
|
|
MarkTileDirtyByTile(tile_start);
|
|
|
|
MarkTileDirtyByTile(tile_end);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-03-10 17:01:51 +00:00
|
|
|
delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
2006-12-27 12:38:02 +00:00
|
|
|
for (tile = tile_start + delta; tile != tile_end; tile += delta) {
|
2006-03-10 17:01:51 +00:00
|
|
|
uint z;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (GetTileSlope(tile, &z) != SLOPE_FLAT && z >= z_start) return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-03 21:55:14 +00:00
|
|
|
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && !replace_bridge) {
|
2006-12-27 12:38:02 +00:00
|
|
|
/* Disallow crossing bridges for the time being */
|
|
|
|
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
2006-03-12 12:19:25 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-10 17:01:51 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2006-02-22 21:35:45 +00:00
|
|
|
case MP_WATER:
|
2006-03-12 12:19:25 +00:00
|
|
|
if (!EnsureNoVehicle(tile)) return_cmd_error(STR_980E_SHIP_IN_THE_WAY);
|
2006-06-10 08:37:41 +00:00
|
|
|
if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below;
|
2006-02-22 21:35:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_RAILWAY:
|
2006-12-27 12:38:02 +00:00
|
|
|
if (!IsPlainRailTile(tile)) goto not_valid_below;
|
2006-02-22 21:35:45 +00:00
|
|
|
break;
|
|
|
|
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2006-12-27 12:38:02 +00:00
|
|
|
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) goto not_valid_below;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
|
|
|
if (IsTunnel(tile)) break;
|
2007-02-03 21:55:14 +00:00
|
|
|
if (replace_bridge) break;
|
2006-12-27 12:38:02 +00:00
|
|
|
if (direction == DiagDirToAxis(GetBridgeRampDirection(tile))) goto not_valid_below;
|
|
|
|
if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_UNMOVABLE:
|
|
|
|
if (!IsOwnedLand(tile)) goto not_valid_below;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_CLEAR:
|
2007-02-03 21:55:14 +00:00
|
|
|
if (!replace_bridge && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
2006-02-22 21:35:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-08-09 17:04:08 +00:00
|
|
|
not_valid_below:;
|
2006-02-22 21:35:45 +00:00
|
|
|
/* try and clear the middle landscape */
|
2006-04-10 07:15:58 +00:00
|
|
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2006-03-12 12:19:25 +00:00
|
|
|
if (CmdFailed(ret)) return ret;
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(ret);
|
2006-02-22 21:35:45 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-12-27 12:38:02 +00:00
|
|
|
SetBridgeMiddle(tile, direction);
|
2006-03-10 17:01:51 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-07 00:19:57 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2007-01-07 16:35:20 +00:00
|
|
|
Track track = AxisToTrack(direction);
|
|
|
|
SetSignalsOnBothDir(tile_start, track);
|
|
|
|
YapfNotifyTrackLayoutChange(tile_start, track);
|
2007-01-07 00:19:57 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-28 18:53:03 +00:00
|
|
|
/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
|
|
|
|
* It's unnecessary to execute this command every time for every bridge. So it is done only
|
|
|
|
* and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
|
|
|
|
*/
|
2004-09-10 19:02:27 +00:00
|
|
|
if (!(flags & DC_QUERY_COST)) {
|
2005-08-01 20:23:38 +00:00
|
|
|
const Bridge *b = &_bridge[bridge_type];
|
|
|
|
|
2006-08-28 18:53:03 +00:00
|
|
|
bridge_len += 2; // begin and end tiles/ramps
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-14 22:31:18 +00:00
|
|
|
if (IsValidPlayer(_current_player) && !_is_old_ai_player)
|
2004-08-09 17:04:08 +00:00
|
|
|
bridge_len = CalcBridgeLenCostFactor(bridge_len);
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost((int64)bridge_len * _price.build_bridge * b->price >> 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-22 21:09:55 +00:00
|
|
|
/** Build Tunnel.
|
2007-04-18 00:41:09 +00:00
|
|
|
* @param start_tile start tile of tunnel
|
2007-04-04 03:21:14 +00:00
|
|
|
* @param flags type of operation
|
2007-05-20 19:14:08 +00:00
|
|
|
* @param p1 railtype or roadtypes. bit 9 set means road tunnel
|
2006-02-22 21:09:55 +00:00
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-02-22 21:09:55 +00:00
|
|
|
TileIndexDiff delta;
|
2005-05-09 16:37:40 +00:00
|
|
|
TileIndex end_tile;
|
2006-02-22 21:09:55 +00:00
|
|
|
DiagDirection direction;
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope start_tileh;
|
|
|
|
Slope end_tileh;
|
2006-02-22 21:09:55 +00:00
|
|
|
uint start_z;
|
|
|
|
uint end_z;
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost cost;
|
|
|
|
CommandCost ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-22 21:09:55 +00:00
|
|
|
_build_tunnel_endtile = 0;
|
2007-05-20 22:43:26 +00:00
|
|
|
if (!HASBIT(p1, 9)) {
|
2007-05-20 19:14:08 +00:00
|
|
|
if (!ValParamRailtype(p1)) return CMD_ERROR;
|
2007-05-20 22:43:26 +00:00
|
|
|
} else if (!AreValidRoadTypes((RoadTypes)GB(p1, 0, 3))) {
|
2007-05-20 19:14:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-22 21:09:55 +00:00
|
|
|
start_tileh = GetTileSlope(start_tile, &start_z);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-22 21:09:55 +00:00
|
|
|
switch (start_tileh) {
|
2006-04-23 13:48:16 +00:00
|
|
|
case SLOPE_SW: direction = DIAGDIR_SW; break;
|
|
|
|
case SLOPE_SE: direction = DIAGDIR_SE; break;
|
|
|
|
case SLOPE_NW: direction = DIAGDIR_NW; break;
|
|
|
|
case SLOPE_NE: direction = DIAGDIR_NE; break;
|
2006-02-22 21:09:55 +00:00
|
|
|
default: return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
ret = DoCommand(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2006-02-22 21:09:55 +00:00
|
|
|
if (CmdFailed(ret)) 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
|
|
|
|
2006-09-05 23:21:41 +00:00
|
|
|
delta = TileOffsByDiagDir(direction);
|
2007-06-21 17:25:17 +00:00
|
|
|
DiagDirection tunnel_in_way_dir;
|
|
|
|
if (OtherAxis(DiagDirToAxis(direction)) == AXIS_X) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-02-22 21:09:55 +00:00
|
|
|
end_tile = start_tile;
|
2007-06-27 19:00:14 +00:00
|
|
|
|
|
|
|
/** Tile shift coeficient. Will decrease for very long tunnels to avoid exponential growth of price*/
|
|
|
|
int tiles_coef = 3;
|
|
|
|
/** Number of tiles from start of tunnel */
|
|
|
|
int tiles = 0;
|
2007-07-23 16:15:40 +00:00
|
|
|
/** Number of tiles at which the cost increase coefficient per tile is halved */
|
|
|
|
int tiles_bump = 25;
|
2007-06-27 19:00:14 +00:00
|
|
|
|
2006-02-22 21:09:55 +00:00
|
|
|
for (;;) {
|
|
|
|
end_tile += delta;
|
|
|
|
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)) {
|
2006-03-07 07:51:05 +00:00
|
|
|
return_cmd_error(STR_5003_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
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(_price.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 */
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(_price.build_tunnel);
|
|
|
|
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
|
|
|
|
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)) {
|
2007-09-15 09:39:23 +00:00
|
|
|
/*
|
|
|
|
* A lot of things can be autosloped, but then there is still a structure with
|
|
|
|
* on top of a tunnel entrance which is bad. Therefor we disallow those.
|
|
|
|
* Furthermore half road bits (not tram bits) can always be removed, so we
|
|
|
|
* need to preserve that behaviour here too.
|
2007-06-24 16:44:06 +00:00
|
|
|
*/
|
2007-09-15 09:39:23 +00:00
|
|
|
switch (GetTileType(end_tile)) {
|
|
|
|
default: return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
|
2007-06-24 16:44:06 +00:00
|
|
|
|
2007-09-15 09:39:23 +00:00
|
|
|
/* Tiles that can be (safely) "auto" terraformed for tunnels */
|
|
|
|
case MP_ROAD:
|
|
|
|
if (GetRoadTileType(end_tile) != ROAD_TILE_NORMAL || // Depots and crossings can't be removed
|
|
|
|
(GetRoadTypes(end_tile) & ROADTYPES_TRAMHWAY) != 0 || // Half tram bits must not be removed
|
|
|
|
COUNTBITS(GetRoadBits(end_tile, ROADTYPE_ROAD)) > 1) { // Non-half road bits must not be removed either
|
|
|
|
return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
|
|
|
|
}
|
|
|
|
/* FALL THROUGH */
|
|
|
|
case MP_CLEAR:
|
|
|
|
case MP_TREES:
|
|
|
|
ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
|
|
|
|
if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
|
|
|
|
break;
|
|
|
|
}
|
2006-02-22 21:09:55 +00:00
|
|
|
} else {
|
2006-04-10 07:15:58 +00:00
|
|
|
ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
2006-02-22 21:09:55 +00:00
|
|
|
if (CmdFailed(ret)) return ret;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
cost.AddCost(_price.build_tunnel);
|
|
|
|
cost.AddCost(ret);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-03-06 20:55:24 +00:00
|
|
|
if (GB(p1, 9, 1) == TRANSPORT_RAIL) {
|
2007-01-10 18:56:51 +00:00
|
|
|
MakeRailTunnel(start_tile, _current_player, direction, (RailType)GB(p1, 0, 4));
|
|
|
|
MakeRailTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4));
|
2006-05-27 16:12:16 +00:00
|
|
|
UpdateSignalsOnSegment(start_tile, direction);
|
2006-07-22 08:59:52 +00:00
|
|
|
YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction)));
|
2006-03-06 20:55:24 +00:00
|
|
|
} else {
|
2007-05-20 22:43:26 +00:00
|
|
|
MakeRoadTunnel(start_tile, _current_player, direction, (RoadTypes)GB(p1, 0, 3));
|
|
|
|
MakeRoadTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 3));
|
2006-03-06 20:55:24 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2005-03-06 12:31:07 +00:00
|
|
|
TileIndex CheckTunnelBusy(TileIndex tile, uint *length)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-07 10:41:45 +00:00
|
|
|
uint z = GetTileZ(tile);
|
2006-03-06 20:55:24 +00:00
|
|
|
DiagDirection dir = GetTunnelDirection(tile);
|
2006-09-05 23:21:41 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(dir);
|
2005-03-06 12:31:07 +00:00
|
|
|
uint len = 0;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex starttile = tile;
|
2004-08-09 17:04:08 +00:00
|
|
|
Vehicle *v;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-16 11:24:58 +00:00
|
|
|
do {
|
|
|
|
tile += delta;
|
|
|
|
len++;
|
|
|
|
} while (
|
2006-03-12 15:04:03 +00:00
|
|
|
!IsTunnelTile(tile) ||
|
2006-03-06 20:55:24 +00:00
|
|
|
ReverseDiagDir(GetTunnelDirection(tile)) != dir ||
|
2005-01-16 11:24:58 +00:00
|
|
|
GetTileZ(tile) != z
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-06 12:31:07 +00:00
|
|
|
v = FindVehicleBetween(starttile, tile, z);
|
|
|
|
if (v != NULL) {
|
2007-03-08 16:27:54 +00:00
|
|
|
_error_message = v->type == VEH_TRAIN ?
|
2005-03-06 12:31:07 +00:00
|
|
|
STR_5000_TRAIN_IN_TUNNEL : STR_5001_ROAD_VEHICLE_IN_TUNNEL;
|
|
|
|
return INVALID_TILE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-03-06 12:31:07 +00:00
|
|
|
if (length != NULL) *length = len;
|
2004-08-09 17:04:08 +00:00
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
|
2006-10-31 23:04:47 +00:00
|
|
|
static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile)
|
|
|
|
{
|
|
|
|
/* Floods can remove anything as well as the scenario editor */
|
|
|
|
if (_current_player == OWNER_WATER || _game_mode == GM_EDITOR) return true;
|
|
|
|
/* Obviously if the bridge/tunnel belongs to us, or no-one, we can remove it */
|
|
|
|
if (CheckTileOwnership(tile) || IsTileOwner(tile, OWNER_NONE)) return true;
|
|
|
|
/* Otherwise we can only remove town-owned stuff with extra patch-settings, or cheat */
|
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && (_patches.extra_dynamite || _cheats.magic_bulldozer.value)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost DoClearTunnel(TileIndex tile, uint32 flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-10-31 23:04:47 +00:00
|
|
|
Town *t = NULL;
|
2005-05-09 16:37:40 +00:00
|
|
|
TileIndex endtile;
|
2005-03-06 12:31:07 +00:00
|
|
|
uint length;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2006-10-31 23:04:47 +00:00
|
|
|
if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
endtile = CheckTunnelBusy(tile, &length);
|
2005-03-06 12:31:07 +00:00
|
|
|
if (endtile == INVALID_TILE) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_build_tunnel_endtile = endtile;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-06-04 11:56:32 +00:00
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
|
2006-10-31 23:04:47 +00:00
|
|
|
t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating
|
|
|
|
|
|
|
|
/* Check if you are allowed to remove the tunnel owned by a town
|
|
|
|
* Removal depends on difficulty settings */
|
2006-02-02 07:15:46 +00:00
|
|
|
if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, t->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2007-04-04 03:21:14 +00:00
|
|
|
/* We first need to request the direction before calling DoClearSquare
|
|
|
|
* else the direction is always 0.. dah!! ;) */
|
2006-03-08 06:55:33 +00:00
|
|
|
DiagDirection dir = GetTunnelDirection(tile);
|
2006-07-22 08:59:52 +00:00
|
|
|
Track track;
|
2006-01-22 16:23:05 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Adjust the town's player rating. Do this before removing the tile owner info. */
|
2006-01-22 16:23:05 +00:00
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
|
|
|
|
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DoClearSquare(tile);
|
|
|
|
DoClearSquare(endtile);
|
2006-03-09 12:32:25 +00:00
|
|
|
UpdateSignalsOnSegment(tile, ReverseDiagDir(dir));
|
|
|
|
UpdateSignalsOnSegment(endtile, dir);
|
2006-07-22 08:59:52 +00:00
|
|
|
track = AxisToTrack(DiagDirToAxis(dir));
|
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
|
|
|
YapfNotifyTrackLayoutChange(endtile, track);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost(_price.clear_tunnel * (length + 1));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-06-07 19:35:21 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
static bool IsVehicleOnBridge(TileIndex starttile, TileIndex endtile, uint z)
|
2006-05-07 11:55:28 +00:00
|
|
|
{
|
2006-12-27 12:38:02 +00:00
|
|
|
const Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if ((v->tile == starttile || v->tile == endtile) && v->z_pos == z) {
|
|
|
|
_error_message = VehicleInTheWayErrMsg(v);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2006-05-07 11:55:28 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost DoClearBridge(TileIndex tile, uint32 flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-16 06:30:47 +00:00
|
|
|
DiagDirection direction;
|
|
|
|
TileIndexDiff delta;
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex endtile;
|
2006-10-31 23:04:47 +00:00
|
|
|
Town *t = NULL;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2006-10-31 23:04:47 +00:00
|
|
|
if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-16 06:38:51 +00:00
|
|
|
endtile = GetOtherBridgeEnd(tile);
|
2007-04-27 20:01:25 +00:00
|
|
|
byte bridge_height = GetBridgeHeight(tile);
|
2006-03-16 06:38:51 +00:00
|
|
|
|
2007-04-27 20:01:25 +00:00
|
|
|
if (FindVehicleOnTileZ(tile, bridge_height) != NULL ||
|
|
|
|
FindVehicleOnTileZ(endtile, bridge_height) != NULL ||
|
|
|
|
IsVehicleOnBridge(tile, endtile, bridge_height)) {
|
2006-12-27 12:38:02 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-16 06:30:47 +00:00
|
|
|
direction = GetBridgeRampDirection(tile);
|
2006-09-05 23:21:41 +00:00
|
|
|
delta = TileOffsByDiagDir(direction);
|
2006-03-16 06:30:47 +00:00
|
|
|
|
2005-06-04 11:56:32 +00:00
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
|
2006-10-31 23:04:47 +00:00
|
|
|
t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating
|
|
|
|
|
|
|
|
/* Check if you are allowed to remove the bridge owned by a town
|
|
|
|
* Removal depends on difficulty settings */
|
|
|
|
if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) {
|
|
|
|
SetDParam(0, t->index);
|
|
|
|
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-03-15 17:38:00 +00:00
|
|
|
TileIndex c;
|
2006-07-22 08:59:52 +00:00
|
|
|
Track track;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 03:21:14 +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 */
|
2005-06-04 11:56:32 +00:00
|
|
|
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
|
2005-01-14 09:20:12 +00:00
|
|
|
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-15 17:38:00 +00:00
|
|
|
DoClearSquare(tile);
|
|
|
|
DoClearSquare(endtile);
|
|
|
|
for (c = tile + delta; c != endtile; c += delta) {
|
2006-12-27 12:38:02 +00:00
|
|
|
ClearBridgeMiddle(c);
|
|
|
|
MarkTileDirtyByTile(c);
|
2006-03-15 17:38:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-16 06:30:47 +00:00
|
|
|
UpdateSignalsOnSegment(tile, ReverseDiagDir(direction));
|
|
|
|
UpdateSignalsOnSegment(endtile, direction);
|
2006-07-22 08:59:52 +00:00
|
|
|
track = AxisToTrack(DiagDirToAxis(direction));
|
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
|
|
|
YapfNotifyTrackLayoutChange(endtile, track);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost((DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
|
2005-06-24 12:38:35 +00:00
|
|
|
{
|
2006-03-12 15:04:03 +00:00
|
|
|
if (IsTunnel(tile)) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
|
2004-08-09 17:04:08 +00:00
|
|
|
return DoClearTunnel(tile, flags);
|
2006-03-16 15:16:27 +00:00
|
|
|
} else if (IsBridge(tile)) { // XXX Is this necessary?
|
2005-11-14 19:48:04 +00:00
|
|
|
if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
|
2005-01-21 19:52:32 +00:00
|
|
|
return DoClearBridge(tile, flags);
|
2005-01-23 13:09:35 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 19:52:32 +00:00
|
|
|
return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-24 09:12:03 +00:00
|
|
|
/**
|
|
|
|
* Switches the rail type for a tunnel or a bridgehead. As the railtype
|
|
|
|
* on the bridge are determined by the one of the bridgehead, this
|
|
|
|
* functions converts the railtype on the entire bridge.
|
|
|
|
* @param tile The tile on which the railtype is to be convert.
|
|
|
|
* @param totype The railtype we want to convert to
|
|
|
|
* @param exec Switches between test and execute mode
|
|
|
|
* @return The cost and state of the operation
|
|
|
|
* @retval CMD_ERROR An error occured during the operation.
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-12 15:04:03 +00:00
|
|
|
if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
|
2006-06-10 08:37:41 +00:00
|
|
|
uint length;
|
2007-09-08 09:52:02 +00:00
|
|
|
TileIndex endtile;
|
2006-06-10 08:37:41 +00:00
|
|
|
|
2007-09-08 09:52:02 +00:00
|
|
|
/* If not coverting rail <-> el. rail, any vehicle cannot be in tunnel */
|
|
|
|
if (!IsCompatibleRail(GetRailType(tile), totype)) {
|
|
|
|
endtile = CheckTunnelBusy(tile, &length);
|
|
|
|
if (endtile == INVALID_TILE) return CMD_ERROR;
|
|
|
|
} else {
|
|
|
|
endtile = GetOtherTunnelEnd(tile);
|
|
|
|
length = DistanceManhattan(tile, endtile);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (exec) {
|
2006-03-17 10:10:31 +00:00
|
|
|
SetRailType(tile, totype);
|
|
|
|
SetRailType(endtile, totype);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(endtile);
|
2006-05-27 16:12:16 +00:00
|
|
|
|
2007-09-08 09:52:02 +00:00
|
|
|
Track track = AxisToTrack(DiagDirToAxis(GetTunnelDirection(tile)));
|
|
|
|
|
2006-05-27 16:12:16 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
2006-07-22 08:59:52 +00:00
|
|
|
YapfNotifyTrackLayoutChange(endtile, track);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-08 09:52:02 +00:00
|
|
|
VehicleFromPos(tile, &tile, UpdateTrainPowerProc);
|
|
|
|
VehicleFromPos(endtile, &endtile, UpdateTrainPowerProc);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-08 09:52:02 +00:00
|
|
|
return CommandCost((length + 1) * (_price.build_rail >> 1));
|
|
|
|
} else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
|
|
|
|
TileIndex endtile = GetOtherBridgeEnd(tile);
|
2007-04-27 20:01:25 +00:00
|
|
|
byte bridge_height = GetBridgeHeight(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-08 09:52:02 +00:00
|
|
|
if (!IsCompatibleRail(GetRailType(tile), totype) &&
|
|
|
|
(FindVehicleOnTileZ(tile, bridge_height) != NULL ||
|
2007-04-27 20:01:25 +00:00
|
|
|
FindVehicleOnTileZ(endtile, bridge_height) != NULL ||
|
2007-09-08 09:52:02 +00:00
|
|
|
IsVehicleOnBridge(tile, endtile, bridge_height))) {
|
2006-12-27 12:38:02 +00:00
|
|
|
return CMD_ERROR;
|
2005-01-20 09:12:20 +00:00
|
|
|
}
|
|
|
|
|
2006-03-15 19:53:25 +00:00
|
|
|
if (exec) {
|
2006-03-17 10:10:31 +00:00
|
|
|
SetRailType(tile, totype);
|
|
|
|
SetRailType(endtile, totype);
|
2006-03-15 19:53:25 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
MarkTileDirtyByTile(endtile);
|
2006-05-27 16:12:16 +00:00
|
|
|
|
2007-09-08 09:52:02 +00:00
|
|
|
Track track = AxisToTrack(DiagDirToAxis(GetBridgeRampDirection(tile)));
|
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
|
|
|
|
|
2006-06-07 19:35:21 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, track);
|
2006-07-22 08:59:52 +00:00
|
|
|
YapfNotifyTrackLayoutChange(endtile, track);
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2007-09-08 09:52:02 +00:00
|
|
|
VehicleFromPos(tile, &tile, UpdateTrainPowerProc);
|
|
|
|
VehicleFromPos(endtile, &endtile, UpdateTrainPowerProc);
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
for (tile += delta; tile != endtile; tile += delta) {
|
|
|
|
MarkTileDirtyByTile(tile); // TODO encapsulate this into a function
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-03-15 16:09:23 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-09-08 09:52:02 +00:00
|
|
|
return CommandCost((DistanceManhattan(tile, endtile) + 1) * (_price.build_rail >> 1));
|
2006-06-10 08:37:41 +00:00
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
2006-06-10 08:37:41 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, uint type, int x, int y, int z)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image = psid->sprite;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (image != 0) {
|
2006-12-27 12:38:02 +00:00
|
|
|
bool drawfarpillar = !HASBIT(GetBridgeFlags(type), 0);
|
2006-04-15 16:07:00 +00:00
|
|
|
int back_height, front_height;
|
|
|
|
int i = z;
|
2004-08-09 17:04:08 +00:00
|
|
|
const byte *p;
|
|
|
|
|
|
|
|
static const byte _tileh_bits[4][8] = {
|
2006-07-30 07:42:37 +00:00
|
|
|
{ 2, 1, 8, 4, 16, 2, 0, 9 },
|
|
|
|
{ 1, 8, 4, 2, 2, 16, 9, 0 },
|
|
|
|
{ 4, 8, 1, 2, 16, 2, 0, 9 },
|
|
|
|
{ 2, 4, 8, 1, 2, 16, 9, 0 }
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-03-16 15:16:27 +00:00
|
|
|
p = _tileh_bits[(image & 1) * 2 + (axis == AXIS_X ? 0 : 1)];
|
2006-04-23 19:35:36 +00:00
|
|
|
front_height = ti->z + (ti->tileh & p[0] ? TILE_HEIGHT : 0);
|
|
|
|
back_height = ti->z + (ti->tileh & p[1] ? TILE_HEIGHT : 0);
|
2005-08-01 20:23:38 +00:00
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
if (IsSteepSlope(ti->tileh)) {
|
2006-04-23 19:35:36 +00:00
|
|
|
if (!(ti->tileh & p[2])) front_height += TILE_HEIGHT;
|
|
|
|
if (!(ti->tileh & p[3])) back_height += TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 19:35:36 +00:00
|
|
|
for (; z >= front_height || z >= back_height; z -= TILE_HEIGHT) {
|
2006-07-30 07:42:37 +00:00
|
|
|
/* HACK set height of the BB of pillars to 1, because the origin of the
|
|
|
|
* sprites is at the top
|
|
|
|
*/
|
2006-04-15 16:07:00 +00:00
|
|
|
if (z >= front_height) { // front facing pillar
|
2007-09-19 16:36:42 +00:00
|
|
|
AddSortableSpriteToDraw(image, psid->pal, x, y, p[4], p[5], BB_HEIGHT_UNDER_BRIDGE - 5, z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, -5);
|
2006-02-01 07:36:15 +00:00
|
|
|
}
|
2006-04-15 16:07:00 +00:00
|
|
|
|
2006-04-23 19:35:36 +00:00
|
|
|
if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar
|
2007-09-19 16:36:42 +00:00
|
|
|
AddSortableSpriteToDraw(image, psid->pal, x - p[6], y - p[7], p[4], p[5], BB_HEIGHT_UNDER_BRIDGE - 5, z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, -5);
|
2006-02-01 07:36:15 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
|
2005-11-14 19:48:04 +00:00
|
|
|
{
|
2007-07-26 16:51:10 +00:00
|
|
|
if (HASBIT(BRIDGE_NO_FOUNDATION, tileh)) return FOUNDATION_NONE;
|
|
|
|
if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) return FlatteningFoundation(tileh);
|
|
|
|
return InclinedFoundation(axis);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-25 22:07:40 +00:00
|
|
|
/**
|
|
|
|
* Draws the trambits over an already drawn (lower end) of a bridge.
|
|
|
|
* @param x the x of the bridge
|
|
|
|
* @param y the y of the bridge
|
|
|
|
* @param z the z of the bridge
|
|
|
|
* @param offset number representing whether to level or sloped and the direction
|
|
|
|
* @param overlay do we want to still see the road?
|
|
|
|
*/
|
|
|
|
static void DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay)
|
|
|
|
{
|
|
|
|
static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } };
|
2007-07-13 15:12:36 +00:00
|
|
|
static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 };
|
2007-05-25 22:07:40 +00:00
|
|
|
static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 };
|
|
|
|
|
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 */
|
|
|
|
AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, x, y, size_x[offset], size_y[offset], 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES));
|
|
|
|
|
|
|
|
AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset], PAL_NONE, x, y, size_x[offset], size_y[offset], 0x28, z, HASBIT(_transparent_opt, TO_BUILDINGS));
|
|
|
|
|
|
|
|
/* Start a new SpriteCombine for the front part */
|
|
|
|
EndSpriteCombine();
|
|
|
|
StartSpriteCombine();
|
2007-05-25 22:07:40 +00:00
|
|
|
|
|
|
|
/* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */
|
2007-09-19 16:36:42 +00:00
|
|
|
AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE, x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z, HASBIT(_transparent_opt, TO_BUILDINGS), front_bb_offset_x[offset], front_bb_offset_y[offset]);
|
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.
|
|
|
|
* For tunnels, this is rather simple, as you only needa draw the entrance.
|
|
|
|
* 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)
|
|
|
|
{
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image;
|
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
|
|
|
|
};
|
|
|
|
static const int *BB_data = _tunnel_BB[GetTunnelDirection(ti->tile)];
|
|
|
|
|
|
|
|
bool catenary = false;
|
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
|
2006-03-17 10:10:31 +00:00
|
|
|
image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
|
2005-10-13 16:00:14 +00:00
|
|
|
} else {
|
|
|
|
image = SPR_TUNNEL_ENTRY_REAR_ROAD;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-29 09:10:44 +00:00
|
|
|
if (HasTunnelSnowOrDesert(ti->tile)) image += 32;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
image += GetTunnelDirection(ti->tile) * 2;
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(image, PAL_NONE);
|
2007-05-25 22:07:40 +00:00
|
|
|
if (GetTunnelTransportType(ti->tile) == TRANSPORT_ROAD) {
|
|
|
|
DiagDirection dir = GetTunnelDirection(ti->tile);
|
|
|
|
RoadTypes rts = GetRoadTypes(ti->tile);
|
|
|
|
|
|
|
|
if (HASBIT(rts, ROADTYPE_TRAM)) {
|
|
|
|
static const SpriteID tunnel_sprites[2][4] = { { 28, 78, 79, 27 }, { 5, 76, 77, 4 } };
|
|
|
|
|
|
|
|
DrawGroundSprite(SPR_TRAMWAY_BASE + tunnel_sprites[rts - ROADTYPES_TRAM][dir], PAL_NONE);
|
2007-09-19 16:36:42 +00:00
|
|
|
|
|
|
|
catenary = true;
|
|
|
|
StartSpriteCombine();
|
|
|
|
AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + dir, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, HASBIT(_transparent_opt, TO_BUILDINGS), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
|
2007-05-25 22:07:40 +00:00
|
|
|
}
|
|
|
|
} else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
|
2007-05-20 22:43:26 +00:00
|
|
|
DrawCatenary(ti);
|
2007-09-19 16:36:42 +00:00
|
|
|
|
|
|
|
catenary = true;
|
|
|
|
StartSpriteCombine();
|
|
|
|
DrawCatenaryOnTunnel(ti);
|
2007-05-20 22:43:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (catenary) EndSpriteCombine();
|
|
|
|
|
|
|
|
/* Add helper BB for sprite sorting, that separate the tunnel from things beside of it */
|
|
|
|
AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x , ti->y , BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
|
|
|
|
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);
|
2006-03-16 15:16:27 +00:00
|
|
|
} else if (IsBridge(ti->tile)) { // XXX is this necessary?
|
2007-01-14 19:57:49 +00:00
|
|
|
const PalSpriteID *psid;
|
2005-10-19 08:34:37 +00:00
|
|
|
int base_offset;
|
2006-12-29 09:10:44 +00:00
|
|
|
bool ice = HasBridgeSnowOrDesert(ti->tile);
|
2005-10-19 08:34:37 +00:00
|
|
|
|
2006-03-16 15:16:27 +00:00
|
|
|
if (GetBridgeTransportType(ti->tile) == 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
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetBridgeRampDirection(ti->tile))));
|
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 */
|
2006-12-27 12:38:02 +00:00
|
|
|
base_offset += (6 - GetBridgeRampDirection(ti->tile)) % 4;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
|
2006-03-29 16:30:26 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
/* Table number 6 always refers to the bridge heads for any bridge type */
|
2007-01-14 19:57:49 +00:00
|
|
|
psid = &GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset];
|
2005-10-19 08:34:37 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (!ice) {
|
|
|
|
DrawClearLandTile(ti, 3);
|
|
|
|
} else {
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[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
|
|
|
|
2007-09-19 16:36:42 +00:00
|
|
|
/* Draw Trambits as SpriteCombine */
|
|
|
|
if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) StartSpriteCombine();
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
AddSortableSpriteToDraw(
|
2007-07-26 14:07:11 +00:00
|
|
|
psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z, HASBIT(_transparent_opt, TO_BRIDGES)
|
2006-12-27 12:38:02 +00:00
|
|
|
);
|
|
|
|
|
2007-05-25 22:07:40 +00:00
|
|
|
if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
|
|
|
|
RoadTypes rts = GetRoadTypes(ti->tile);
|
|
|
|
|
|
|
|
if (HASBIT(rts, ROADTYPE_TRAM)) {
|
|
|
|
uint offset = GetBridgeRampDirection(ti->tile);
|
2007-05-26 21:34:38 +00:00
|
|
|
uint z = ti->z;
|
2007-05-25 22:07:40 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
|
|
|
offset = (offset + 1) & 1;
|
2007-05-26 21:34:38 +00:00
|
|
|
z += TILE_HEIGHT;
|
2007-05-25 22:07:40 +00:00
|
|
|
} else {
|
|
|
|
offset += 2;
|
|
|
|
}
|
2007-09-19 16:36:42 +00:00
|
|
|
/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
|
2007-05-26 21:34:38 +00:00
|
|
|
DrawBridgeTramBits(ti->x, ti->y, z, offset, HASBIT(rts, ROADTYPE_ROAD));
|
2007-05-25 22:07:40 +00:00
|
|
|
}
|
2007-09-19 16:36:42 +00:00
|
|
|
EndSpriteCombine();
|
2007-05-25 22:07:40 +00:00
|
|
|
} else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
|
|
|
|
DrawCatenary(ti);
|
|
|
|
}
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
DrawBridgeMiddle(ti);
|
2007-06-24 20:06:10 +00:00
|
|
|
} else {
|
|
|
|
NOT_REACHED();
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-07 19:35:21 +00:00
|
|
|
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
/** Compute bridge piece. Computes the bridge piece to display depending on the position inside the bridge.
|
|
|
|
* bridges pieces sequence (middle parts)
|
|
|
|
* bridge len 1: 0
|
|
|
|
* bridge len 2: 0 1
|
|
|
|
* bridge len 3: 0 4 1
|
|
|
|
* bridge len 4: 0 2 3 1
|
|
|
|
* bridge len 5: 0 2 5 3 1
|
|
|
|
* bridge len 6: 0 2 3 2 3 1
|
|
|
|
* bridge len 7: 0 2 3 4 2 3 1
|
|
|
|
* #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
|
|
|
|
*/
|
|
|
|
static uint CalcBridgePiece(uint north, uint south)
|
|
|
|
{
|
|
|
|
if (north == 1) {
|
|
|
|
return 0;
|
|
|
|
} else if (south == 1) {
|
|
|
|
return 1;
|
|
|
|
} else if (north < south) {
|
|
|
|
return north & 1 ? 3 : 2;
|
|
|
|
} else if (north > south) {
|
|
|
|
return south & 1 ? 2 : 3;
|
|
|
|
} else {
|
|
|
|
return north & 1 ? 5 : 4;
|
|
|
|
}
|
|
|
|
}
|
2006-06-07 19:35:21 +00:00
|
|
|
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
void DrawBridgeMiddle(const TileInfo* ti)
|
|
|
|
{
|
2007-09-19 16:36:42 +00:00
|
|
|
/* Sectional view of bridge bounding boxes:
|
|
|
|
*
|
|
|
|
* 1 2 1,2 = SpriteCombine of Bridge front/(back&floor) and TramCatenary
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Z position of the bridge sprites relative to bridge height (downwards) */
|
|
|
|
static const int BRIDGE_Z_START = 3;
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
const PalSpriteID* psid;
|
2006-12-27 12:38:02 +00:00
|
|
|
uint base_offset;
|
|
|
|
TileIndex rampnorth;
|
|
|
|
TileIndex rampsouth;
|
|
|
|
Axis axis;
|
|
|
|
uint piece;
|
|
|
|
uint type;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
uint z;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (!IsBridgeAbove(ti->tile)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
rampnorth = GetNorthernBridgeEnd(ti->tile);
|
|
|
|
rampsouth = GetSouthernBridgeEnd(ti->tile);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
axis = GetBridgeAxis(ti->tile);
|
|
|
|
piece = CalcBridgePiece(
|
|
|
|
DistanceManhattan(ti->tile, rampnorth),
|
|
|
|
DistanceManhattan(ti->tile, rampsouth)
|
|
|
|
);
|
|
|
|
type = GetBridgeType(rampsouth);
|
2006-03-29 16:30:26 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (GetBridgeTransportType(rampsouth) == TRANSPORT_RAIL) {
|
|
|
|
base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
|
|
|
|
} else {
|
|
|
|
base_offset = 8;
|
|
|
|
}
|
2006-06-02 13:05:41 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
psid = base_offset + GetBridgeSpriteTable(type, piece);
|
|
|
|
if (axis != AXIS_X) psid += 4;
|
2006-06-02 13:05:41 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
x = ti->x;
|
|
|
|
y = ti->y;
|
2007-05-25 22:07:40 +00:00
|
|
|
uint bridge_z = GetBridgeHeight(rampsouth);
|
2007-09-19 16:36:42 +00:00
|
|
|
z = bridge_z - BRIDGE_Z_START;
|
|
|
|
|
|
|
|
/* Add a bounding box, that separates the bridge from things below it. */
|
|
|
|
AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, x, y, 16, 16, 1, bridge_z - TILE_HEIGHT + BB_Z_SEPARATOR);
|
|
|
|
|
|
|
|
/* Draw Trambits as SpriteCombine */
|
|
|
|
if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) StartSpriteCombine();
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2007-09-19 16:36:42 +00:00
|
|
|
/* Draw floor and far part of bridge*/
|
2006-12-27 12:38:02 +00:00
|
|
|
if (axis == AXIS_X) {
|
2007-09-19 16:36:42 +00:00
|
|
|
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 0, BRIDGE_Z_START);
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
2007-09-19 16:36:42 +00:00
|
|
|
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, HASBIT(_transparent_opt, 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
|
|
|
|
2007-05-25 22:07:40 +00:00
|
|
|
if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) {
|
|
|
|
RoadTypes rts = GetRoadTypes(rampsouth);
|
|
|
|
|
|
|
|
if (HASBIT(rts, ROADTYPE_TRAM)) {
|
2007-09-19 16:36:42 +00:00
|
|
|
/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
|
2007-05-25 22:07:40 +00:00
|
|
|
DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HASBIT(rts, ROADTYPE_ROAD));
|
2007-09-19 16:36:42 +00:00
|
|
|
} else {
|
|
|
|
EndSpriteCombine();
|
|
|
|
StartSpriteCombine();
|
2007-05-25 22:07:40 +00:00
|
|
|
}
|
|
|
|
} else if (GetRailType(rampsouth) == RAILTYPE_ELECTRIC) {
|
2007-05-25 11:01:44 +00:00
|
|
|
DrawCatenary(ti);
|
|
|
|
}
|
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* draw roof, the component of the bridge which is logically between the vehicle and the camera */
|
2006-12-27 12:38:02 +00:00
|
|
|
if (axis == AXIS_X) {
|
|
|
|
y += 12;
|
2007-09-19 16:36:42 +00:00
|
|
|
if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 4, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES), 0, 3, BRIDGE_Z_START);
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
|
|
|
x += 12;
|
2007-09-19 16:36:42 +00:00
|
|
|
if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 4, 16, 0x28, z, HASBIT(_transparent_opt, 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 */
|
|
|
|
if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) EndSpriteCombine();
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
psid++;
|
2006-12-27 12:38:02 +00:00
|
|
|
if (ti->z + 5 == z) {
|
2007-04-04 03:21:14 +00:00
|
|
|
/* draw poles below for small bridges */
|
2007-01-14 19:57:49 +00:00
|
|
|
if (psid->sprite != 0) {
|
2007-07-26 14:07:11 +00:00
|
|
|
SpriteID image = psid->sprite;
|
|
|
|
SpriteID pal = psid->pal;
|
2007-04-05 07:49:04 +00:00
|
|
|
if (HASBIT(_transparent_opt, TO_BRIDGES)) {
|
2007-01-14 19:57:49 +00:00
|
|
|
SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
|
|
|
|
pal = PALETTE_TO_TRANSPARENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawGroundSpriteAt(image, pal, x, y, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
} else if (_patches.bridge_pillars) {
|
2007-04-04 03:21:14 +00:00
|
|
|
/* draw pillars below for high bridges */
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawBridgePillars(psid, ti, axis, type, x, y, z);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2006-08-06 16:32:49 +00:00
|
|
|
static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
|
2005-10-19 14:49:46 +00:00
|
|
|
{
|
2006-08-06 16:32:49 +00:00
|
|
|
uint z;
|
|
|
|
Slope tileh = GetTileSlope(tile, &z);
|
|
|
|
|
|
|
|
x &= 0xF;
|
|
|
|
y &= 0xF;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-12 05:19:19 +00:00
|
|
|
if (IsTunnel(tile)) {
|
|
|
|
uint pos = (DiagDirToAxis(GetTunnelDirection(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;
|
|
|
|
} else {
|
2006-12-27 12:38:02 +00:00
|
|
|
DiagDirection dir = GetBridgeRampDirection(tile);
|
|
|
|
uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
z += ApplyFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh);
|
|
|
|
|
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) {
|
|
|
|
uint delta;
|
|
|
|
|
|
|
|
if (HASBIT(BRIDGE_HORZ_RAMP, tileh)) return z + TILE_HEIGHT;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-12 05:19:19 +00:00
|
|
|
return z + GetPartialZ(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-07-26 16:51:10 +00:00
|
|
|
return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
|
|
|
static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = {
|
|
|
|
STR_501F_WOODEN_RAIL_BRIDGE,
|
|
|
|
STR_5020_CONCRETE_RAIL_BRIDGE,
|
|
|
|
STR_501C_STEEL_GIRDER_RAIL_BRIDGE,
|
|
|
|
STR_501E_REINFORCED_CONCRETE_SUSPENSION,
|
|
|
|
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE,
|
|
|
|
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE,
|
|
|
|
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
|
|
|
|
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
|
|
|
|
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
|
|
|
|
STR_501C_STEEL_GIRDER_RAIL_BRIDGE,
|
|
|
|
STR_5027_TUBULAR_RAIL_BRIDGE,
|
|
|
|
STR_5027_TUBULAR_RAIL_BRIDGE,
|
|
|
|
STR_5027_TUBULAR_RAIL_BRIDGE,
|
2006-08-22 14:38:37 +00:00
|
|
|
0, 0, 0,
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
STR_5025_WOODEN_ROAD_BRIDGE,
|
|
|
|
STR_5026_CONCRETE_ROAD_BRIDGE,
|
|
|
|
STR_5022_STEEL_GIRDER_ROAD_BRIDGE,
|
|
|
|
STR_5024_REINFORCED_CONCRETE_SUSPENSION,
|
|
|
|
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE,
|
|
|
|
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE,
|
|
|
|
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
|
|
|
|
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
|
|
|
|
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
|
|
|
|
STR_5022_STEEL_GIRDER_ROAD_BRIDGE,
|
|
|
|
STR_5028_TUBULAR_ROAD_BRIDGE,
|
|
|
|
STR_5028_TUBULAR_ROAD_BRIDGE,
|
|
|
|
STR_5028_TUBULAR_ROAD_BRIDGE,
|
2006-08-22 14:38:37 +00:00
|
|
|
0, 0, 0,
|
2004-08-09 17:04:08 +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
|
|
|
{
|
2006-03-12 15:04:03 +00:00
|
|
|
if (IsTunnel(tile)) {
|
2006-03-06 20:55:24 +00:00
|
|
|
td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ?
|
|
|
|
STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-03-16 15:16:27 +00:00
|
|
|
td->str = _bridge_tile_str[GetBridgeTransportType(tile) << 4 | GetBridgeType(tile)];
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-06-04 11:56:32 +00:00
|
|
|
td->owner = GetTileOwner(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void AnimateTile_TunnelBridge(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoop_TunnelBridge(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-12-29 09:10:44 +00:00
|
|
|
bool snow_or_desert = IsTunnelTile(tile) ? HasTunnelSnowOrDesert(tile) : HasBridgeSnowOrDesert(tile);
|
2006-02-13 21:15:00 +00:00
|
|
|
switch (_opt.landscape) {
|
2007-03-22 03:42:43 +00:00
|
|
|
case LT_ARCTIC:
|
2007-03-20 13:47:00 +00:00
|
|
|
if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) {
|
2006-12-29 09:10:44 +00:00
|
|
|
if (IsTunnelTile(tile)) {
|
|
|
|
SetTunnelSnowOrDesert(tile, !snow_or_desert);
|
|
|
|
} else {
|
|
|
|
SetBridgeSnowOrDesert(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;
|
|
|
|
|
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) {
|
|
|
|
if (IsTunnelTile(tile)) {
|
|
|
|
SetTunnelSnowOrDesert(tile, true);
|
|
|
|
} else {
|
|
|
|
SetBridgeSnowOrDesert(tile, true);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
2006-02-13 21:15:00 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void ClickTile_TunnelBridge(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-24 22:41:50 +00:00
|
|
|
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-12 15:04:03 +00:00
|
|
|
if (IsTunnel(tile)) {
|
2006-06-09 15:27:17 +00:00
|
|
|
if (GetTunnelTransportType(tile) != mode) return 0;
|
2007-05-24 22:41:50 +00:00
|
|
|
if (GetTunnelTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
|
2006-07-22 08:59:52 +00:00
|
|
|
return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(tile))) * 0x101;
|
2006-06-09 15:27:17 +00:00
|
|
|
} else {
|
2006-12-27 12:38:02 +00:00
|
|
|
if (GetBridgeTransportType(tile) != mode) return 0;
|
2007-05-24 22:41:50 +00:00
|
|
|
if (GetBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
|
2006-12-27 12:38:02 +00:00
|
|
|
return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(tile))) * 0x101;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-04 11:56:32 +00:00
|
|
|
if (!IsTileOwner(tile, old_player)) return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-10-14 15:49:43 +00:00
|
|
|
if (new_player != PLAYER_SPECTATOR) {
|
2005-06-04 12:13:24 +00:00
|
|
|
SetTileOwner(tile, new_player);
|
2006-08-28 18:53:03 +00:00
|
|
|
} else {
|
2007-05-28 21:32:26 +00:00
|
|
|
if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
|
|
|
|
/* When clearing the bridge/tunnel failed there are still vehicles on/in
|
|
|
|
* the bridge/tunnel. As all *our* vehicles are already removed, they
|
|
|
|
* must be of another owner. Therefor this must be a road bridge/tunnel.
|
|
|
|
* In that case we can safely reassign the ownership to OWNER_NONE. */
|
|
|
|
assert((IsTunnel(tile) ? GetTunnelTransportType(tile) : GetBridgeTransportType(tile)) == TRANSPORT_ROAD);
|
|
|
|
SetTileOwner(tile, OWNER_NONE);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-22 14:38:37 +00:00
|
|
|
static const byte _tunnel_fractcoord_1[4] = {0x8E, 0x18, 0x81, 0xE8};
|
|
|
|
static const byte _tunnel_fractcoord_2[4] = {0x81, 0x98, 0x87, 0x38};
|
|
|
|
static const byte _tunnel_fractcoord_3[4] = {0x82, 0x88, 0x86, 0x48};
|
|
|
|
static const byte _exit_tunnel_track[4] = {1, 2, 1, 2};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-13 22:27:27 +00:00
|
|
|
/** Get the trackdir of the exit of a tunnel */
|
|
|
|
static const Trackdir _road_exit_tunnel_state[DIAGDIR_END] = {
|
|
|
|
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4};
|
|
|
|
|
2006-08-22 14:38:37 +00:00
|
|
|
static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29};
|
|
|
|
static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25};
|
|
|
|
static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45};
|
|
|
|
static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-12-27 12:38:02 +00:00
|
|
|
int z = GetSlopeZ(x, y) - v->z_pos;
|
|
|
|
|
2007-02-13 10:26:53 +00:00
|
|
|
if (myabs(z) > 2) return VETSB_CANNOT_ENTER;
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2006-03-12 15:04:03 +00:00
|
|
|
if (IsTunnel(tile)) {
|
2006-02-06 09:18:04 +00:00
|
|
|
byte fc;
|
2006-03-06 20:28:28 +00:00
|
|
|
DiagDirection dir;
|
|
|
|
DiagDirection vdir;
|
2006-02-06 09:18:04 +00:00
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN) {
|
2006-02-01 06:32:03 +00:00
|
|
|
fc = (x & 0xF) + (y << 4);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
dir = GetTunnelDirection(tile);
|
2006-03-06 20:28:28 +00:00
|
|
|
vdir = DirToDiagDir(v->direction);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-13 10:46:45 +00:00
|
|
|
if (v->u.rail.track != TRACK_BIT_WORMHOLE && dir == vdir) {
|
2005-11-18 23:41:03 +00:00
|
|
|
if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) {
|
2007-03-04 22:14:32 +00:00
|
|
|
if (!PlayVehicleSound(v, VSE_TUNNEL) && RailVehInfo(v->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
|
|
|
}
|
|
|
|
if (fc == _tunnel_fractcoord_2[dir]) {
|
|
|
|
v->tile = tile;
|
2007-01-10 18:56:51 +00:00
|
|
|
v->u.rail.track = TRACK_BIT_WORMHOLE;
|
2004-08-09 17:04:08 +00:00
|
|
|
v->vehstatus |= VS_HIDDEN;
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-06 20:28:28 +00:00
|
|
|
if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) {
|
2004-08-11 22:07:08 +00:00
|
|
|
/* We're at the tunnel exit ?? */
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tile = tile;
|
2007-01-10 18:56:51 +00:00
|
|
|
v->u.rail.track = (TrackBits)_exit_tunnel_track[dir];
|
2005-02-06 22:36:08 +00:00
|
|
|
assert(v->u.rail.track);
|
2004-08-09 17:04:08 +00:00
|
|
|
v->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) {
|
2006-02-01 06:32:03 +00:00
|
|
|
fc = (x & 0xF) + (y << 4);
|
2006-03-06 20:55:24 +00:00
|
|
|
dir = GetTunnelDirection(tile);
|
2006-03-06 20:28:28 +00:00
|
|
|
vdir = DirToDiagDir(v->direction);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 03:21:14 +00:00
|
|
|
/* Enter tunnel? */
|
2007-02-13 22:27:27 +00:00
|
|
|
if (v->u.road.state != RVSB_WORMHOLE && dir == vdir) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (fc == _tunnel_fractcoord_4[dir] ||
|
|
|
|
fc == _tunnel_fractcoord_5[dir]) {
|
|
|
|
v->tile = tile;
|
2007-02-13 22:27:27 +00:00
|
|
|
v->u.road.state = RVSB_WORMHOLE;
|
2004-09-10 19:02:27 +00:00
|
|
|
v->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-06 20:28:28 +00:00
|
|
|
if (dir == ReverseDiagDir(vdir) && (
|
2006-02-01 06:32:03 +00:00
|
|
|
/* We're at the tunnel exit ?? */
|
|
|
|
fc == _tunnel_fractcoord_6[dir] ||
|
|
|
|
fc == _tunnel_fractcoord_7[dir]
|
|
|
|
) &&
|
2004-08-09 17:04:08 +00:00
|
|
|
z == 0) {
|
|
|
|
v->tile = tile;
|
|
|
|
v->u.road.state = _road_exit_tunnel_state[dir];
|
|
|
|
v->u.road.frame = _road_exit_tunnel_frame[dir];
|
|
|
|
v->vehstatus &= ~VS_HIDDEN;
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-16 15:16:27 +00:00
|
|
|
} else if (IsBridge(tile)) { // XXX is this necessary?
|
2006-12-27 12:38:02 +00:00
|
|
|
DiagDirection dir;
|
|
|
|
|
2007-09-09 11:23:49 +00:00
|
|
|
if (v->IsPrimaryVehicle()) {
|
2006-12-27 12:38:02 +00:00
|
|
|
/* modify speed of vehicle */
|
|
|
|
uint16 spd = _bridge[GetBridgeType(tile)].speed;
|
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_ROAD) spd *= 2;
|
2006-12-27 12:38:02 +00:00
|
|
|
if (v->cur_speed > spd) v->cur_speed = spd;
|
|
|
|
}
|
|
|
|
|
|
|
|
dir = GetBridgeRampDirection(tile);
|
|
|
|
if (DirToDiagDir(v->direction) == dir) {
|
|
|
|
switch (dir) {
|
|
|
|
default: NOT_REACHED();
|
2007-02-13 10:26:53 +00:00
|
|
|
case DIAGDIR_NE: if ((x & 0xF) != 0) return VETSB_CONTINUE; break;
|
|
|
|
case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
|
|
|
|
case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
|
|
|
|
case DIAGDIR_NW: if ((y & 0xF) != 0) return VETSB_CONTINUE; break;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN) {
|
2007-01-10 18:56:51 +00:00
|
|
|
v->u.rail.track = TRACK_BIT_WORMHOLE;
|
2006-12-27 12:38:02 +00:00
|
|
|
CLRBIT(v->u.rail.flags, VRF_GOINGUP);
|
|
|
|
CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
|
|
|
|
} else {
|
2007-02-13 22:27:27 +00:00
|
|
|
v->u.road.state = RVSB_WORMHOLE;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2006-12-27 12:38:02 +00:00
|
|
|
} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
|
|
|
|
v->tile = tile;
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN) {
|
2007-02-13 10:46:45 +00:00
|
|
|
if (v->u.rail.track == TRACK_BIT_WORMHOLE) {
|
2007-01-10 18:56:51 +00:00
|
|
|
v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-02-13 22:27:27 +00:00
|
|
|
if (v->u.road.state == RVSB_WORMHOLE) {
|
2006-12-27 12:38:02 +00:00
|
|
|
v->u.road.state = _road_exit_tunnel_state[dir];
|
|
|
|
v->u.road.frame = 0;
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_ENTERED_WORMHOLE;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2007-02-13 10:26:53 +00:00
|
|
|
return VETSB_CONTINUE;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-08-30 17:17:04 +00:00
|
|
|
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
|
|
|
|
{
|
2007-09-14 22:27:40 +00:00
|
|
|
if (_patches.build_on_slopes && AutoslopeEnabled() && IsBridge(tile)) {
|
|
|
|
DiagDirection direction = GetBridgeRampDirection(tile);
|
|
|
|
Axis axis = DiagDirToAxis(direction);
|
|
|
|
CommandCost res;
|
|
|
|
|
|
|
|
/* Check if new slope is valid for bridges in general (so we can savely call GetBridgeFoundation()) */
|
|
|
|
if ((direction == DIAGDIR_NW) || (direction == DIAGDIR_NE)) {
|
|
|
|
res = CheckBridgeSlopeSouth(axis, tileh_new);
|
|
|
|
} else {
|
|
|
|
res = CheckBridgeSlopeNorth(axis, tileh_new);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CmdFailed(res)) {
|
|
|
|
uint z_old;
|
|
|
|
Slope tileh_old = GetTileSlope(tile, &z_old);
|
|
|
|
|
|
|
|
z_old += ApplyFoundationToSlope(GetBridgeFoundation(tileh_old, axis), &tileh_old);
|
|
|
|
z_new += ApplyFoundationToSlope(GetBridgeFoundation(tileh_new, axis), &tileh_new);
|
|
|
|
|
|
|
|
/* Surface slope remains unchanged? */
|
|
|
|
if ((z_old == z_new) && (tileh_old == tileh_new)) return _price.terraform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-30 17:17:04 +00:00
|
|
|
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
|
|
}
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
|
2006-08-22 14:38:37 +00:00
|
|
|
DrawTile_TunnelBridge, /* draw_tile_proc */
|
|
|
|
GetSlopeZ_TunnelBridge, /* get_slope_z_proc */
|
|
|
|
ClearTile_TunnelBridge, /* clear_tile_proc */
|
|
|
|
GetAcceptedCargo_TunnelBridge, /* get_accepted_cargo_proc */
|
|
|
|
GetTileDesc_TunnelBridge, /* get_tile_desc_proc */
|
|
|
|
GetTileTrackStatus_TunnelBridge, /* get_tile_track_status_proc */
|
|
|
|
ClickTile_TunnelBridge, /* click_tile_proc */
|
|
|
|
AnimateTile_TunnelBridge, /* animate_tile_proc */
|
|
|
|
TileLoop_TunnelBridge, /* tile_loop_clear */
|
|
|
|
ChangeTileOwner_TunnelBridge, /* change_tile_owner_clear */
|
|
|
|
NULL, /* get_produced_cargo_proc */
|
|
|
|
VehicleEnter_TunnelBridge, /* vehicle_enter_tile_proc */
|
2007-07-26 16:51:10 +00:00
|
|
|
GetFoundation_TunnelBridge, /* get_foundation_proc */
|
2007-08-30 17:17:04 +00:00
|
|
|
TerraformTile_TunnelBridge, /* terraform_tile_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|