tunnelbridge_cmd.c
author tron
Sun, 23 Apr 2006 19:35:36 +0000
changeset 3645 7f950533d510
parent 3636 a36cc46e754d
child 3657 eb28d97d3d18
permissions -rw-r--r--
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
     3
/** @file tunnelbridge_cmd.c
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
     4
 * This file deals with tunnels and bridges (non-gui stuff)
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
     5
 * @todo seperate this file into two
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
     6
 */
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
     7
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1884
diff changeset
     9
#include "openttd.h"
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
    10
#include "bridge_map.h"
3187
6f83f483fed0 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
    11
#include "rail_map.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3069
diff changeset
    12
#include "road_map.h"
1363
775a7ee52369 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1335
diff changeset
    13
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
    14
#include "table/strings.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
    15
#include "functions.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 541
diff changeset
    16
#include "map.h"
1209
2e00193652b2 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1192
diff changeset
    17
#include "tile.h"
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
    18
#include "tunnel_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "town.h"
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 334
diff changeset
    24
#include "sound.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    25
#include "variables.h"
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
    26
#include "bridge.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2663
diff changeset
    27
#include "train.h"
3187
6f83f483fed0 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
    28
#include "water_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
    30
#include "table/bridge_land.h"
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
    31
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
    32
extern const byte _track_sloped_sprites[14];
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
    33
extern const SpriteID _water_shore_sprites[15];
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
    34
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
    35
extern void DrawCanalWater(TileIndex tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
2478
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    37
const Bridge orig_bridge[] = {
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
    38
/*
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2262
diff changeset
    39
	   year of availablity
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
    40
	   |  minimum length
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
    41
	   |  |   maximum length
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
    42
	   |  |   |    price
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
    43
	   |  |   |    |    maximum speed
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
    44
	   |  |   |    |    |  sprite to use in GUI                string with description
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
    45
	   |  |   |    |    |  |                                   |                            */
2478
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    46
	{  0, 0, 16,  80,  32, 0xA24                             , STR_5012_WOODEN             , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    47
	{  0, 0,  2, 112,  48, 0xA26 | PALETTE_TO_STRUCT_RED     , STR_5013_CONCRETE           , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    48
	{ 10, 0,  5, 144,  64, 0xA25                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    49
	{  0, 2, 10, 168,  80, 0xA22 | PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    50
	{ 10, 3, 16, 185,  96, 0xA22                             , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    51
	{ 10, 3, 16, 192, 112, 0xA22 | PALETTE_TO_STRUCT_YELLOW  , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    52
	{ 10, 3,  7, 224, 160, 0xA23                             , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    53
	{ 10, 3,  8, 232, 208, 0xA23 | PALETTE_TO_STRUCT_BROWN   , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    54
	{ 10, 3,  9, 248, 240, 0xA23 | PALETTE_TO_STRUCT_RED     , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    55
	{ 10, 0,  2, 240, 256, 0xA27                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    56
	{ 75, 2, 16, 255, 320, 0xA28                             , STR_5014_TUBULAR_STEEL      , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    57
	{ 85, 2, 32, 380, 512, 0xA28 | PALETTE_TO_STRUCT_YELLOW  , STR_5014_TUBULAR_STEEL      , NULL, 0 },
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    58
	{ 90, 2, 32, 510, 608, 0xA28 | PALETTE_TO_STRUCT_GREY    , STR_BRIDGE_TUBULAR_SILICON  , NULL, 0 }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
2763
a4d065e3261b (svn r3308) BAD
tron
parents: 2737
diff changeset
    61
Bridge _bridge[MAX_BRIDGES];
a4d065e3261b (svn r3308) BAD
tron
parents: 2737
diff changeset
    62
a4d065e3261b (svn r3308) BAD
tron
parents: 2737
diff changeset
    63
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
// calculate the price factor for building a long bridge.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
// 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,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
int CalcBridgeLenCostFactor(int x)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    68
	int n;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    69
	int r;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    70
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	if (x < 2) return x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	x -= 2;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    73
	for (n = 0, r = 2;; n++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
		if (x <= n) return r + x * n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
		r += n * n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
		x -= n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    80
#define M(x) (1 << (x))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
enum {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    82
	// foundation, whole tile is leveled up --> 3 corners raised
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    83
	BRIDGE_FULL_LEVELED_FOUNDATION = M(SLOPE_WSE) | M(SLOPE_NWS) | M(SLOPE_ENW) | M(SLOPE_SEN),
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    84
	// foundation, tile is partly leveled up --> 1 corner raised
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    85
	BRIDGE_PARTLY_LEVELED_FOUNDATION = M(SLOPE_W) | M(SLOPE_S) | M(SLOPE_E) | M(SLOPE_N),
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    86
	// no foundations (X,Y direction)
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    87
	BRIDGE_NO_FOUNDATION = M(SLOPE_FLAT) | M(SLOPE_SW) | M(SLOPE_SE) | M(SLOPE_NW) | M(SLOPE_NE),
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    88
	BRIDGE_HORZ_RAMP = (BRIDGE_PARTLY_LEVELED_FOUNDATION | BRIDGE_NO_FOUNDATION) & ~M(SLOPE_FLAT)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
};
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    90
#undef M
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
2478
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    92
static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table)
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    93
{
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    94
	const Bridge *bridge = &_bridge[index];
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    95
	assert(table < 7);
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    96
	if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) {
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    97
		return _bridge_sprite_table[index][table];
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    98
	} else {
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
    99
		return bridge->sprite_table[table];
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   100
	}
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   101
}
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   102
3556
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
   103
static inline byte GetBridgeFlags(int index) { return _bridge[index].flags;}
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   104
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   105
/**	check if bridge can be built on slope
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
 *	direction 0 = X-axis, direction 1 = Y-axis
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
 *	is_start_tile = false		<-- end tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
 *	is_start_tile = true		<-- start tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
 */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   110
static uint32 CheckBridgeSlope(Axis direction, Slope tileh, bool is_start_tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   112
	if (IsSteepSlope(tileh)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   114
	if (is_start_tile) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   115
		/* check slope at start tile
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   116
				- no extra cost
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   117
		*/
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   118
#define M(x) (1 << (x))
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   119
		if (HASBIT(M(SLOPE_FLAT) | (direction == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW)), tileh)) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   121
		// disallow certain start tiles to avoid certain crooked bridges
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   122
		if (tileh == SLOPE_S) return CMD_ERROR;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   123
	} else {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   124
		/*	check slope at end tile
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   125
				- no extra cost
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   126
		*/
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   127
		if (HASBIT(M(SLOPE_FLAT) | (direction == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE)), tileh)) return 0;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   128
#undef M
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   130
		// disallow certain end tiles to avoid certain crooked bridges
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   131
		if (tileh == SLOPE_N) return CMD_ERROR;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   132
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   134
	/*	disallow common start/end tiles to avoid certain crooked bridges e.g.
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   135
	 *	start-tile:	X 2,1 Y 2,4 (2 was disabled before)
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   136
	 *	end-tile:		X 8,4 Y 8,1 (8 was disabled before)
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   137
	 */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   138
	if ((tileh == SLOPE_W && is_start_tile != (direction != AXIS_X)) ||
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   139
			(tileh == SLOPE_E && is_start_tile == (direction != AXIS_X))) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   140
		return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   143
	// slope foundations
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   144
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION | BRIDGE_PARTLY_LEVELED_FOUNDATION, tileh))
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   145
		return _price.terraform;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   146
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
uint32 GetBridgeLength(TileIndex begin, TileIndex end)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   152
	int x1 = TileX(begin);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   153
	int y1 = TileY(begin);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   154
	int x2 = TileX(end);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   155
	int y2 = TileY(end);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   156
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   157
	return abs(x2 + y2 - x1 - y1) - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   160
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
{
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   162
	const Bridge *b = &_bridge[bridge_type];
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   163
	uint max; // max possible length of a bridge (with patch 100)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
1781
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   165
	if (bridge_type >= MAX_BRIDGES) return false;
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   166
	if (b->avail_year > _cur_year) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   168
	max = b->max_length;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   169
	if (max >= 16 && _patches.longbridges) max = 100;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   171
	return b->min_length <= bridge_len && bridge_len <= max;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   174
/** Build a Bridge
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   175
 * @param end_tile end tile
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   176
 * @param p1 packed start tile coords (~ dx)
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   177
 * @param p2 various bitstuffed elements
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   178
 * - p2 = (bit 0- 7) - bridge type (hi bh)
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   179
 * - p2 = (bit 8-..) - rail type. bit15 ((x>>8)&0x80) means road bridge.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   181
int32 CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	int bridge_type;
3180
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3178
diff changeset
   184
	TransportType transport;
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3178
diff changeset
   185
	RailType railtype;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   186
	int x;
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   187
	int y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	int sx,sy;
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   189
	TileIndex tile_start;
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   190
	TileIndex tile_end;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   191
	Slope tileh_start;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   192
	Slope tileh_end;
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   193
	uint z_start;
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   194
	uint z_end;
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   195
	TileIndex tile;
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   196
	TileIndexDiff delta;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   197
	uint bridge_len;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   198
	uint odd_middle_part;
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   199
	Axis direction;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   200
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	int32 cost, terraformcost, ret;
1585
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   202
	bool allow_on_slopes;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   205
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	/* unpack parameters */
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   207
	bridge_type = GB(p2, 0, 8);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   208
2934
3f29a7212713 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2931
diff changeset
   209
	if (p1 >= MapSize()) return CMD_ERROR;
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   210
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	// type of bridge
3180
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3178
diff changeset
   212
	if (HASBIT(p2, 15)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
		railtype = 0;
3180
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3178
diff changeset
   214
		transport = TRANSPORT_ROAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	} else {
3180
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3178
diff changeset
   216
		if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR;
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3178
diff changeset
   217
		railtype = GB(p2, 8, 8);
9c87ee130147 (svn r3820) Be a bit more strict with types: use special types instead of generic byte and don't fill arbitrary data into inappropriate types
tron
parents: 3178
diff changeset
   218
		transport = TRANSPORT_RAIL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   221
	x = TileX(end_tile);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   222
	y = TileY(end_tile);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   223
	sx = TileX(p1);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   224
	sy = TileY(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	/* check if valid, and make sure that (x,y) are smaller than (sx,sy) */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	if (x == sx) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   228
		if (y == sy) return_cmd_error(STR_5008_CANNOT_START_AND_END_ON);
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   229
		direction = AXIS_Y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
		if (y > sy) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
			intswap(y,sy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
			intswap(x,sx);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	} else if (y == sy) {
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   235
		direction = AXIS_X;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
		if (x > sx) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
			intswap(y,sy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
			intswap(x,sx);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
		}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   240
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
		return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   242
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
1781
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   244
	/* set and test bridge length, availability */
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   245
	bridge_len = (sx + sy - x - y) - 1;
1781
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   246
	if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   247
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	/* retrieve landscape height and ensure it's on land */
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   249
	tile_start = TileXY(x, y);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   250
	tile_end = TileXY(sx, sy);
3535
aaec72f71226 (svn r4392) -Codechange: Use water map accessors in bridge code
celestar
parents: 3534
diff changeset
   251
	if (IsClearWaterTile(tile_start) || IsClearWaterTile(tile_end)) return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   253
	tileh_start = GetTileSlope(tile_start, &z_start);
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   254
	tileh_end = GetTileSlope(tile_end, &z_end);
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   255
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   256
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   257
		z_start += TILE_HEIGHT;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   258
		tileh_start = SLOPE_FLAT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   261
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   262
		z_end += TILE_HEIGHT;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   263
		tileh_end = SLOPE_FLAT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   266
	if (z_start != z_end) return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED);
1585
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   267
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   268
	// Towns are not allowed to use bridges on slopes.
2422
897a01f7c624 (svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents: 2314
diff changeset
   269
	allow_on_slopes = (!_is_old_ai_player
1781
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   270
	                   && _current_player != OWNER_TOWN && _patches.build_on_slopes);
1585
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   271
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   272
	/* Try and clear the start landscape */
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   273
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   274
	ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   275
	if (CmdFailed(ret)) return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
	cost = ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
1585
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   278
	// true - bridge-start-tile, false - bridge-end-tile
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   279
	terraformcost = CheckBridgeSlope(direction, tileh_start, true);
2737
fb1556b8f5e0 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2676
diff changeset
   280
	if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	cost += terraformcost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
1585
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   284
	/* Try and clear the end landscape */
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   285
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   286
	ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   287
	if (CmdFailed(ret)) return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	cost += ret;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   289
1585
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   290
	// false - end tile slope check
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   291
	terraformcost = CheckBridgeSlope(direction, tileh_end, false);
2737
fb1556b8f5e0 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2676
diff changeset
   292
	if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes))
1585
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   293
		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   294
	cost += terraformcost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	/* do the drill? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	if (flags & DC_EXEC) {
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   299
		DiagDirection dir = AxisToDiagDir(direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   301
		if (transport == TRANSPORT_RAIL) {
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   302
			MakeRailBridgeRamp(tile_start, _current_player, bridge_type, dir, railtype);
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   303
			MakeRailBridgeRamp(tile_end,   _current_player, bridge_type, ReverseDiagDir(dir), railtype);
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   304
		} else {
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   305
			MakeRoadBridgeRamp(tile_start, _current_player, bridge_type, dir);
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   306
			MakeRoadBridgeRamp(tile_end,   _current_player, bridge_type, ReverseDiagDir(dir));
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   307
		}
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   308
		MarkTileDirtyByTile(tile_start);
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   309
		MarkTileDirtyByTile(tile_end);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
1781
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   312
	// position of middle part of the odd bridge (larger than MAX(i) otherwise)
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   313
	odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   315
	tile = tile_start;
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   316
	delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
1781
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   317
	for (i = 0; i != bridge_len; i++) {
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   318
		TransportType transport_under;
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
   319
		Owner owner_under = OWNER_NONE;
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
   320
		RailType rail_under = INVALID_RAILTYPE;
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   321
		uint z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   323
		tile += delta;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   325
		if (GetTileSlope(tile, &z) != SLOPE_FLAT && z >= z_start) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   326
			return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED);
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   327
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   329
		switch (GetTileType(tile)) {
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   330
			case MP_WATER:
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   331
				if (!EnsureNoVehicle(tile)) return_cmd_error(STR_980E_SHIP_IN_THE_WAY);
3535
aaec72f71226 (svn r4392) -Codechange: Use water map accessors in bridge code
celestar
parents: 3534
diff changeset
   332
				if (!(IsWater(tile) || IsCoast(tile))) goto not_valid_below;
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   333
				transport_under = TRANSPORT_WATER;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   334
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   336
			case MP_RAILWAY:
3267
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3243
diff changeset
   337
				if (GetRailTileType(tile) != RAIL_TYPE_NORMAL ||
feff95208a9f (svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents: 3243
diff changeset
   338
						GetTrackBits(tile) != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   339
					goto not_valid_below;
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   340
				}
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   341
				transport_under = TRANSPORT_RAIL;
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
   342
				owner_under = GetTileOwner(tile);
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   343
				rail_under = GetRailType(tile);
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   344
				break;
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   345
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   346
			case MP_STREET:
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   347
				if (GetRoadType(tile) != ROAD_NORMAL ||
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   348
						GetRoadBits(tile) != (direction == AXIS_X ? ROAD_Y : ROAD_X)) {
3069
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3065
diff changeset
   349
					goto not_valid_below;
9a1fd047b595 (svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents: 3065
diff changeset
   350
				}
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   351
				transport_under = TRANSPORT_ROAD;
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
   352
				owner_under = GetTileOwner(tile);
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   353
				break;
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   354
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   355
			default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
not_valid_below:;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   357
				/* try and clear the middle landscape */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   358
				ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   359
				if (CmdFailed(ret)) return ret;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   360
				cost += ret;
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   361
				transport_under = INVALID_TRANSPORT;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   362
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
		if (flags & DC_EXEC) {
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   366
			uint piece;
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   367
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
			//bridges pieces sequence (middle parts)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   369
			// bridge len 1: 0
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
			// bridge len 2: 0 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
			// bridge len 3: 0 4 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
			// bridge len 4: 0 2 3 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
			// bridge len 5: 0 2 5 3 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
			// bridge len 6: 0 2 3 2 3 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			// bridge len 7: 0 2 3 4 2 3 1
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   376
			// #0 - always as first, #1 - always as last (if len>1)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
			// #2,#3 are to pair in order
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
			// for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   380
			if (i == 0) { // first tile
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   381
				piece = 0;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   382
			} else if (i == bridge_len - 1) { // last tile
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   383
				piece = 1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   384
			} else if (i == odd_middle_part) { // we are on the middle of odd bridge: #5 on even pos, #4 on odd
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   385
				piece = 5 - (i % 2);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   386
			} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
					// generate #2 and #3 in turns [i%2==0], after the middle of odd bridge
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   388
					// this sequence swaps [... XOR (i>odd_middle_part)],
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
					// for even bridges XOR does not apply as odd_middle_part==bridge_len
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   390
					piece = 2 + ((i % 2 == 0) ^ (i > odd_middle_part));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   393
			if (transport == TRANSPORT_RAIL) {
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   394
				MakeRailBridgeMiddle(tile, bridge_type, piece, direction, railtype);
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   395
			} else {
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   396
				MakeRoadBridgeMiddle(tile, bridge_type, piece, direction);
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   397
			}
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   398
			switch (transport_under) {
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
   399
				case TRANSPORT_RAIL:  SetRailUnderBridge(tile, owner_under, rail_under); break;
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
   400
				case TRANSPORT_ROAD:  SetRoadUnderBridge(tile, owner_under); break;
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
   401
				case TRANSPORT_WATER: SetWaterUnderBridge(tile); break;
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
   402
				default:              SetClearUnderBridge(tile); break;
3188
d1316a266fa8 (svn r3838) Demystify building bridge middle parts a bit by removing some magic numbers and generic names
tron
parents: 3187
diff changeset
   403
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   405
			MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   409
	SetSignalsOnBothDir(tile_start, direction == AXIS_X ? TRACK_X : TRACK_Y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
	/*	for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
			It's unnecessary to execute this command every time for every bridge. So it is done only
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
			and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
	*/
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   415
	if (!(flags & DC_QUERY_COST)) {
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   416
		const Bridge *b = &_bridge[bridge_type];
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   417
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
		bridge_len += 2;	// begin and end tiles/ramps
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
2422
897a01f7c624 (svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents: 2314
diff changeset
   420
		if (_current_player < MAX_PLAYERS && !_is_old_ai_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
			bridge_len = CalcBridgeLenCostFactor(bridge_len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3017
diff changeset
   423
		cost += (int64)bridge_len * _price.build_bridge * b->price >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   430
/** Build Tunnel.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   431
 * @param tile start tile of tunnel
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
   432
 * @param p1 railtype, 0x200 for road tunnel
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   433
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   435
int32 CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
{
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   437
	TileIndexDiff delta;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   438
	TileIndex end_tile;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   439
	DiagDirection direction;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   440
	Slope start_tileh;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   441
	Slope end_tileh;
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   442
	uint start_z;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   443
	uint end_z;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   444
	int32 cost;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   445
	int32 ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   447
	_build_tunnel_endtile = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
   449
	if (p1 != 0x200 && !ValParamRailtype(p1)) return CMD_ERROR;
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   450
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   451
	start_tileh = GetTileSlope(start_tile, &start_z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   453
	switch (start_tileh) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   454
		case SLOPE_SW: direction = DIAGDIR_SW; break;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   455
		case SLOPE_SE: direction = DIAGDIR_SE; break;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   456
		case SLOPE_NW: direction = DIAGDIR_NW; break;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   457
		case SLOPE_NE: direction = DIAGDIR_NE; break;
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   458
		default: return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   459
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   461
	ret = DoCommand(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   462
	if (CmdFailed(ret)) return ret;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   463
	cost = _price.build_tunnel + ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   465
	delta = TileOffsByDir(direction);
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   466
	end_tile = start_tile;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   467
	for (;;) {
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   468
		end_tile += delta;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   469
		end_tileh = GetTileSlope(end_tile, &end_z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   471
		if (start_z == end_z) break;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   472
3156
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
   473
		if (!_cheats.crossing_tunnels.value && IsTunnelInWay(end_tile, start_z)) {
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
   474
			return_cmd_error(STR_5003_ANOTHER_TUNNEL_IN_THE_WAY);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   475
		}
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   476
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   477
		cost += _price.build_tunnel;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   478
		cost += cost >> 3;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   479
		if (cost >= 400000000) cost = 400000000;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   482
	// if the command fails from here on we want the end tile to be highlighted
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   483
	_build_tunnel_endtile = end_tile;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   484
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   485
	// slope of end tile must be complementary to the slope of the start tile
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   486
	if (end_tileh != ComplementSlope(start_tileh)) {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   487
		ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   488
		if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   489
	} else {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   490
		ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   491
		if (CmdFailed(ret)) return ret;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   492
	}
3064
960264bcce6f (svn r3653) -Fix: You didn't pay for terraforming at the end tile when building a tunnel
tron
parents: 3063
diff changeset
   493
	cost += _price.build_tunnel + ret;
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   494
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   495
	if (flags & DC_EXEC) {
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   496
		if (GB(p1, 9, 1) == TRANSPORT_RAIL) {
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   497
			MakeRailTunnel(start_tile, _current_player, direction,                 GB(p1, 0, 4));
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   498
			MakeRailTunnel(end_tile,   _current_player, ReverseDiagDir(direction), GB(p1, 0, 4));
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   499
		} else {
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   500
			MakeRoadTunnel(start_tile, _current_player, direction);
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   501
			MakeRoadTunnel(end_tile,   _current_player, ReverseDiagDir(direction));
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   502
		}
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   503
3172
ade284ef48ed (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents: 3157
diff changeset
   504
		if (GB(p1, 9, 1) == 0) UpdateSignalsOnSegment(start_tile, direction);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   505
	}
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   506
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   507
	return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   510
TileIndex CheckTunnelBusy(TileIndex tile, uint *length)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
{
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1330
diff changeset
   512
	uint z = GetTileZ(tile);
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   513
	DiagDirection dir = GetTunnelDirection(tile);
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   514
	TileIndexDiff delta = TileOffsByDir(dir);
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   515
	uint len = 0;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   516
	TileIndex starttile = tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	Vehicle *v;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   518
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1005
diff changeset
   519
	do {
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1005
diff changeset
   520
		tile += delta;
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1005
diff changeset
   521
		len++;
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1005
diff changeset
   522
	} while (
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
   523
		!IsTunnelTile(tile) ||
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   524
		ReverseDiagDir(GetTunnelDirection(tile)) != dir ||
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1005
diff changeset
   525
		GetTileZ(tile) != z
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1005
diff changeset
   526
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   528
	v = FindVehicleBetween(starttile, tile, z);
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   529
	if (v != NULL) {
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   530
		_error_message = v->type == VEH_Train ?
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   531
			STR_5000_TRAIN_IN_TUNNEL : STR_5001_ROAD_VEHICLE_IN_TUNNEL;
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   532
		return INVALID_TILE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   534
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   535
	if (length != NULL) *length = len;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
	return tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   539
static int32 DoClearTunnel(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	Town *t;
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   542
	TileIndex endtile;
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   543
	uint length;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
	// in scenario editor you can always destroy tunnels
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
	if (_game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   549
		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
	endtile = CheckTunnelBusy(tile, &length);
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   554
	if (endtile == INVALID_TILE) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
	_build_tunnel_endtile = endtile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   557
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
	// check if you're allowed to remove the tunnel owned by a town
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
	// removal allowal depends on difficulty settings
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   561
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
   562
		if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 511
diff changeset
   563
			SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
	if (flags & DC_EXEC) {
38
d20549a6ea13 (svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents: 22
diff changeset
   569
		// We first need to request the direction before calling DoClearSquare
d20549a6ea13 (svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents: 22
diff changeset
   570
		//  else the direction is always 0.. dah!! ;)
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   571
		DiagDirection dir = GetTunnelDirection(tile);
2870
0dc0bcee256a (svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents: 2843
diff changeset
   572
0dc0bcee256a (svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents: 2843
diff changeset
   573
		// Adjust the town's player rating. Do this before removing the tile owner info.
0dc0bcee256a (svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents: 2843
diff changeset
   574
		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
0dc0bcee256a (svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents: 2843
diff changeset
   575
			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
0dc0bcee256a (svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents: 2843
diff changeset
   576
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
		DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
		DoClearSquare(endtile);
3172
ade284ef48ed (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents: 3157
diff changeset
   579
		UpdateSignalsOnSegment(tile, ReverseDiagDir(dir));
ade284ef48ed (svn r3803) Change the second parameter of UpdateSignalsOnSegment() from Direction to DiagDirection as that's what it really operates on
tron
parents: 3157
diff changeset
   580
		UpdateSignalsOnSegment(endtile, dir);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   582
	return _price.clear_tunnel * (length + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   586
static int32 DoClearBridge(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
{
3227
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   588
	DiagDirection direction;
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   589
	TileIndexDiff delta;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   590
	TileIndex endtile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
	Town *t;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   593
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
3226
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   596
	if (IsBridgeMiddle(tile)) {
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   597
		if (IsTransportUnderBridge(tile)) {
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   598
			/* delete transport route under the bridge */
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   599
			int32 cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
3226
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   601
			// check if we own the tile below the bridge..
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   602
			if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))))
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   603
				return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   604
3226
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   605
			if (GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   606
				cost = _price.remove_rail;
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   607
			} else {
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   608
				cost = _price.remove_road * 2;
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   609
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
3226
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   611
			if (flags & DC_EXEC) {
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   612
				SetClearUnderBridge(tile);
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   613
				MarkTileDirtyByTile(tile);
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   614
			}
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   615
			return cost;
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   616
		} else if (IsWaterUnderBridge(tile) && TilePixelHeight(tile) != 0) {
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   617
			/* delete canal under bridge */
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   618
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   619
			// check for vehicles under bridge
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   620
			if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR;
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   621
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   622
			if (flags & DC_EXEC) {
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   623
				SetClearUnderBridge(tile);
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   624
				MarkTileDirtyByTile(tile);
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   625
			}
75a5a742135e (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable
tron
parents: 3225
diff changeset
   626
			return _price.clear_water;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
		}
3228
72f4272b56d8 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   628
72f4272b56d8 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   629
		tile = GetSouthernBridgeEnd(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
	// floods, scenario editor can always destroy bridges
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   634
		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
3228
72f4272b56d8 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   638
	endtile = GetOtherBridgeEnd(tile);
72f4272b56d8 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   639
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   640
	if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
3227
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   642
	direction = GetBridgeRampDirection(tile);
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   643
	delta = TileOffsByDir(direction);
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   644
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	/*	Make sure there's no vehicle on the bridge
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
			Omit tile and endtile, since these are already checked, thus solving the problem
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
			of bridges over water, or higher bridges, where z is not increased, eg level bridge
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
	*/
1082
a83d7ac6fecb (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1073
diff changeset
   649
	/* Bridges on slopes might have their Z-value offset..correct this */
3227
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   650
	v = FindVehicleBetween(
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   651
		tile    + delta,
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   652
		endtile - delta,
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   653
		TilePixelHeight(tile) + TILE_HEIGHT + GetCorrectTileHeight(tile)
3227
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   654
	);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   655
	if (v != NULL) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   656
		VehicleInTheWayErrMsg(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   661
	// check if you're allowed to remove the bridge owned by a town.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	// removal allowal depends on difficulty settings
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   663
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
   664
		if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	if (flags & DC_EXEC) {
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   668
		TileIndex c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
1005
f48b2bdd84fc (svn r1504) enummed town ratings (Jango)
celestar
parents: 959
diff changeset
   670
		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
		// you have a "Poor" (0) town rating
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   672
		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
1005
f48b2bdd84fc (svn r1504) enummed town ratings (Jango)
celestar
parents: 959
diff changeset
   673
			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   675
		DoClearSquare(tile);
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   676
		DoClearSquare(endtile);
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   677
		for (c = tile + delta; c != endtile; c += delta) {
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   678
			if (IsTransportUnderBridge(c)) {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   679
				if (GetTransportTypeUnderBridge(c) == TRANSPORT_RAIL) {
3243
87575e904976 (svn r3922) Fix copy&pasto in r3916 (Slowly it's getting a bad habit)
tron
parents: 3242
diff changeset
   680
					MakeRailNormal(c, GetTileOwner(c), GetRailBitsUnderBridge(c), GetRailType(c));
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   681
				} else {
3220
30c21af90cf1 (svn r3893) - Fix: Properly set back the owner of a crossing/road-under bridge after removing it. For crossings we can always use .m2 because it is already 0 when not owned by a town.
Darkvater
parents: 3218
diff changeset
   682
					uint town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0;
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   683
					MakeRoadNormal(c, GetTileOwner(c), GetRoadBitsUnderBridge(c), town);
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   684
				}
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   685
				MarkTileDirtyByTile(c);
3187
6f83f483fed0 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
   686
			} else {
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   687
				if (IsClearUnderBridge(c)) {
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   688
					DoClearSquare(c);
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   689
				} else {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   690
					if (GetTileSlope(c, NULL) == SLOPE_FLAT) {
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   691
						MakeWater(c);
3187
6f83f483fed0 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
   692
					} else {
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   693
						MakeShore(c);
3187
6f83f483fed0 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
   694
					}
6f83f483fed0 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
   695
					MarkTileDirtyByTile(c);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
			}
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   698
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
3227
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   700
		UpdateSignalsOnSegment(tile, ReverseDiagDir(direction));
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   701
		UpdateSignalsOnSegment(endtile, direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
3227
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   704
	return (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   707
static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   708
{
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
   709
	if (IsTunnel(tile)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   710
		if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
		return DoClearTunnel(tile, flags);
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   712
	} else if (IsBridge(tile)) { // XXX Is this necessary?
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   713
		if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
1082
a83d7ac6fecb (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1073
diff changeset
   714
		return DoClearBridge(tile, flags);
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   715
	}
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   716
1082
a83d7ac6fecb (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1073
diff changeset
   717
	return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
3435
dfba5b1c7c2d (svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents: 3422
diff changeset
   720
int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
{
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   722
	TileIndex endtile;
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   723
	uint length;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
   726
	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
		if (!CheckTileOwnership(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   729
		if (GetRailType(tile) == totype) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   730
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
		endtile = CheckTunnelBusy(tile, &length);
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   732
		if (endtile == INVALID_TILE) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
		if (exec) {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   735
			SetRailType(tile, totype);
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   736
			SetRailType(endtile, totype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
			MarkTileDirtyByTile(endtile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
		return (length + 1) * (_price.build_rail >> 1);
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   741
	} else if (IsBridge(tile) &&
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   742
			IsBridgeMiddle(tile) &&
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   743
			IsTransportUnderBridge(tile) &&
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   744
			GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
		// only check for train under bridge
1041
94db182c3614 (svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents: 1035
diff changeset
   746
		if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   749
		if (GetRailType(tile) == totype) return CMD_ERROR;
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   750
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
		if (exec) {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   752
			SetRailType(tile, totype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
		return _price.build_rail >> 1;
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   756
	} else if (IsBridge(tile) && IsBridgeRamp(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
3213
1ada56a3c4e9 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   757
		TileIndexDiff delta;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
		int32 cost;
1073
4e8f5f9d673d (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   759
		uint z = TilePixelHeight(tile);
4e8f5f9d673d (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   760
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   761
		z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
		if (!CheckTileOwnership(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
3215
c5dcb0d4b297 (svn r3888) If you think you've checked everything, check once more. *sigh* Fix r3887
tron
parents: 3214
diff changeset
   765
		endtile = GetOtherBridgeEnd(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
		// Make sure there's no vehicle on the bridge
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   767
		v = FindVehicleBetween(tile, endtile, z);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   768
		if (v != NULL) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   769
			VehicleInTheWayErrMsg(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
3213
1ada56a3c4e9 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   773
		if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) {
1073
4e8f5f9d673d (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   774
			_error_message = STR_8803_TRAIN_IN_THE_WAY;
4e8f5f9d673d (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   775
			return CMD_ERROR;
4e8f5f9d673d (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   776
		}
4e8f5f9d673d (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   777
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   778
		if (GetRailType(tile) == totype) return CMD_ERROR;
3213
1ada56a3c4e9 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   779
3218
1bcbf46819b9 (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   780
		if (exec) {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   781
			SetRailType(tile, totype);
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   782
			SetRailType(endtile, totype);
3218
1bcbf46819b9 (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   783
			MarkTileDirtyByTile(tile);
1bcbf46819b9 (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   784
			MarkTileDirtyByTile(endtile);
1bcbf46819b9 (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   785
		}
3213
1ada56a3c4e9 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   786
		cost = 2 * (_price.build_rail >> 1);
1ada56a3c4e9 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   787
		delta = TileOffsByDir(GetBridgeRampDirection(tile));
1ada56a3c4e9 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   788
		for (tile += delta; tile != endtile; tile += delta) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
			if (exec) {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   790
				SetRailTypeOnBridge(tile, totype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
			}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   793
			cost += _price.build_rail >> 1;
3213
1ada56a3c4e9 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   794
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
		return cost;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   797
	} else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
// fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile.
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3301
diff changeset
   803
uint GetBridgeHeight(TileIndex t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
{
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3301
diff changeset
   805
	TileIndex tile = GetSouthernBridgeEnd(t);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
1192
2649bd4e556a (svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents: 1109
diff changeset
   807
	/* Return the height there (the height of the NORTH CORNER)
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   808
	 * If the end of the bridge is on a tile with all corners except the north corner raised,
1192
2649bd4e556a (svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents: 1109
diff changeset
   809
	 * the z coordinate is 1 height level too low. Compensate for that */
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   810
	return TilePixelHeight(tile) + (GetTileSlope(tile, NULL) == SLOPE_WSE ? TILE_HEIGHT : 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
static const byte _bridge_foundations[2][16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
// 0 1  2  3  4 5 6 7  8 9 10 11 12 13 14 15
3539
bbc5b0e6fc41 (svn r4402) Fix a faulty entry in the table for slopes under bridges, remove a now unnecessary test which hid the faulty entry till now and undo r4398 (don't do this!)
tron
parents: 3537
diff changeset
   815
	{0,16,18,3,20,5,0,7,22,0,10,11,12,13,14},
bbc5b0e6fc41 (svn r4402) Fix a faulty entry in the table for slopes under bridges, remove a now unnecessary test which hid the faulty entry till now and undo r4398 (don't do this!)
tron
parents: 3537
diff changeset
   816
	{0,15,17,0,19,5,6,7,21,9,10,11, 0,13,14},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
extern const byte _road_sloped_sprites[14];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
3556
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
   821
static void DrawBridgePillars(PalSpriteID image, const TileInfo *ti, int x, int y, int z)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	if (image != 0) {
3556
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
   824
		Axis axis = GetBridgeAxis(ti->tile);
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
   825
		bool drawfarpillar = !HASBIT(GetBridgeFlags(GetBridgeType(ti->tile)), 0);
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
   826
		int back_height, front_height;
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
   827
		int i = z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
		const byte *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
		static const byte _tileh_bits[4][8] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
			{2,1,8,4,  16,11,0,9},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
			{1,8,4,2,  11,16,9,0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
			{4,8,1,2,  16,11,0,9},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
			{2,4,8,1,  11,16,9,0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
		};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
2148
542ea702738c (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
   837
		if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
333
be1ecd3b8f7c (svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents: 241
diff changeset
   838
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   839
		p = _tileh_bits[(image & 1) * 2 + (axis == AXIS_X ? 0 : 1)];
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   840
		front_height = ti->z + (ti->tileh & p[0] ? TILE_HEIGHT : 0);
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   841
		back_height  = ti->z + (ti->tileh & p[1] ? TILE_HEIGHT : 0);
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   842
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   843
		if (IsSteepSlope(ti->tileh)) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   844
			if (!(ti->tileh & p[2])) front_height += TILE_HEIGHT;
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   845
			if (!(ti->tileh & p[3])) back_height  += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   848
		for (; z >= front_height || z >= back_height; z -= TILE_HEIGHT) {
3556
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
   849
			if (z >= front_height) { // front facing pillar
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   850
				AddSortableSpriteToDraw(image, x,y, p[4], p[5], 0x28, z);
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   851
			}
3556
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
   852
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   853
			if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   854
				AddSortableSpriteToDraw(image, x - p[6], y - p[7], p[4], p[5], 0x28, z);
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   855
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   860
uint GetBridgeFoundation(Slope tileh, Axis axis)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   861
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	int i;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   863
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) return tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
	// inclined sloped building
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   866
	if ((
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   867
				(i  = 0, tileh == SLOPE_W) ||
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   868
				(i += 2, tileh == SLOPE_S) ||
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   869
				(i += 2, tileh == SLOPE_E) ||
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   870
				(i += 2, tileh == SLOPE_N)
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   871
			) && (
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   872
				      axis == AXIS_X ||
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   873
				(i++, axis == AXIS_Y)
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   874
			)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
		return i + 15;
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   876
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   881
/**
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   882
  * Draws a tunnel of bridge tile.
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   883
  * For tunnels, this is rather simple, as you only needa draw the entrance.
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   884
  * Bridges are a bit more complex. base_offset is where the sprite selection comes into play
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   885
  * and it works a bit like a bitmask.<p> For bridge heads:
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   886
  * <ul><li>Bit 0: direction</li>
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   887
  * <li>Bit 1: northern or southern heads</li>
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   888
  * <li>Bit 2: Set if the bridge head is sloped</li>
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   889
  * <li>Bit 3 and more: Railtype Specific subset</li>
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   890
  * </ul>
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   891
  * For middle parts:
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   892
  * <ul><li>Bits 0-1: need to be 0</li>
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   893
  * <li>Bit 2: direction</li>
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   894
  * <li>Bit 3 and above: Railtype Specific subset</li>
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   895
  * </ul>
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   896
  * Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   897
  */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
static void DrawTile_TunnelBridge(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
	uint32 image;
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   901
	const PalSpriteID *b;
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
   902
	bool ice = _m[ti->tile].m4 & 0x80;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   903
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
   904
	if (IsTunnel(ti->tile)) {
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   905
		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   906
			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
2511
3eb6cb6b750d (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2502
diff changeset
   907
		} else {
3eb6cb6b750d (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2502
diff changeset
   908
			image = SPR_TUNNEL_ENTRY_REAR_ROAD;
3eb6cb6b750d (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2502
diff changeset
   909
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
2511
3eb6cb6b750d (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2502
diff changeset
   911
		if (ice) image += 32;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   913
		image += GetTunnelDirection(ti->tile) * 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
		DrawGroundSprite(image);
3534
73b04ea04c28 (svn r4391) -Fix: faulty ")" in previous commit
celestar
parents: 3533
diff changeset
   915
		if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   917
		AddSortableSpriteToDraw(image+1, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, 1, 1, 8, (byte)ti->z);
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   918
	} else if (IsBridge(ti->tile)) { // XXX is this necessary?
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   919
		int base_offset;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   921
		if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   922
			RailType rt;
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   923
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   924
			if (IsBridgeRamp(ti->tile)) {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   925
				rt = GetRailType(ti->tile);
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   926
			} else {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   927
				rt = GetRailTypeOnBridge(ti->tile);
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   928
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   930
			base_offset = GetRailTypeInfo(rt)->bridge_offset;
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   931
			assert(base_offset != 8); /* This one is used for roads */
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   932
		} else {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   933
			base_offset = 8;
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   934
		}
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   935
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   936
		/* as the lower 3 bits are used for other stuff, make sure they are clear */
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   937
		assert( (base_offset & 0x07) == 0x00);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   939
		if (IsBridgeRamp(ti->tile)) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   940
			if (!HASBIT(BRIDGE_NO_FOUNDATION, ti->tileh)) {
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   941
				int f = GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetBridgeRampDirection(ti->tile)));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
				if (f) DrawFoundation(ti, f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
3196
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3190
diff changeset
   945
			// HACK Wizardry to convert the bridge ramp direction into a sprite offset
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3190
diff changeset
   946
			base_offset += (6 - GetBridgeRampDirection(ti->tile)) % 4;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   947
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   948
			if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   949
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   950
			/* Table number 6 always refers to the bridge heads for any bridge type */
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   951
			image = GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
			if (!ice) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
				DrawClearLandTile(ti, 3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
			} else {
2517
6e3832ddd0f6 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2511
diff changeset
   956
				DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
3362
d30d8f9a37f0 (svn r4157) CodeChange : Keep on cleaning up Celestar's elrail merge
belugas
parents: 3355
diff changeset
   959
			if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3301
diff changeset
   960
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
			// draw ramp
2148
542ea702738c (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
   962
			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
			AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
			// bridge middle part.
3229
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
   966
			Axis axis = GetBridgeAxis(ti->tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
			uint z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
			int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
3216
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
   970
			if (IsTransportUnderBridge(ti->tile)) {
3539
bbc5b0e6fc41 (svn r4402) Fix a faulty entry in the table for slopes under bridges, remove a now unnecessary test which hid the faulty entry till now and undo r4398 (don't do this!)
tron
parents: 3537
diff changeset
   971
				uint f = _bridge_foundations[axis][ti->tileh];
bbc5b0e6fc41 (svn r4402) Fix a faulty entry in the table for slopes under bridges, remove a now unnecessary test which hid the faulty entry till now and undo r4398 (don't do this!)
tron
parents: 3537
diff changeset
   972
bbc5b0e6fc41 (svn r4402) Fix a faulty entry in the table for slopes under bridges, remove a now unnecessary test which hid the faulty entry till now and undo r4398 (don't do this!)
tron
parents: 3537
diff changeset
   973
				if (f != 0) DrawFoundation(ti, f);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
3216
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
   975
				if (GetTransportTypeUnderBridge(ti->tile) == TRANSPORT_RAIL) {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   976
					const RailtypeInfo* rti = GetRailTypeInfo(GetRailType(ti->tile));
3216
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
   977
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   978
					if (ti->tileh == SLOPE_FLAT) {
3229
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
   979
						image = (axis == AXIS_X ? SPR_RAIL_TRACK_Y : SPR_RAIL_TRACK_X);
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
   980
					} else {
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
   981
						image = SPR_RAIL_TRACK_Y + _track_sloped_sprites[ti->tileh - 1];
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
   982
					}
2254
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2187
diff changeset
   983
					image += rti->total_offset;
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2187
diff changeset
   984
					if (ice) image += rti->snow_offset;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
				} else {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   986
					if (ti->tileh == SLOPE_FLAT) {
3230
9ef4ba7f622a (svn r3903) Fix a copy&pasto in last commit and remove a redundant comment (the line above already says what's going on)
tron
parents: 3229
diff changeset
   987
						image = (axis == AXIS_X ? SPR_ROAD_Y : SPR_ROAD_X);
9ef4ba7f622a (svn r3903) Fix a copy&pasto in last commit and remove a redundant comment (the line above already says what's going on)
tron
parents: 3229
diff changeset
   988
					} else {
3229
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
   989
						image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
   990
					}
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   991
					if (ice) image += 19;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
				DrawGroundSprite(image);
3216
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
   994
			} else {
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
   995
				if (IsClearUnderBridge(ti->tile)) {
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
   996
					image = (ice ? SPR_FLAT_SNOWY_TILE : SPR_FLAT_GRASS_TILE);
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
   997
					DrawGroundSprite(image + _tileh_to_sprite[ti->tileh]);
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
   998
				} else {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   999
					if (ti->tileh == SLOPE_FLAT) {
3216
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
  1000
						DrawGroundSprite(SPR_FLAT_WATER_TILE);
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
  1001
						if (ti->z != 0) DrawCanalWater(ti->tile);
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
  1002
					} else {
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
  1003
						DrawGroundSprite(_water_shore_sprites[ti->tileh]);
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
  1004
					}
425b6575d297 (svn r3889) Change a part of the bridge drawing code to make it more comprehensible and add the needed accessors
tron
parents: 3215
diff changeset
  1005
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
			}
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
  1007
3229
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
  1008
			if (axis != AXIS_X) base_offset += 4;
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
  1009
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
  1010
			/*  base_offset needs to be 0 due to the structure of the sprite table see table/bridge_land.h */
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
  1011
			assert( (base_offset & 0x03) == 0x00);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
			// get bridge sprites
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
  1013
			b = GetBridgeSpriteTable(GetBridgeType(ti->tile), GetBridgePiece(ti->tile)) + base_offset;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3301
diff changeset
  1015
			z = GetBridgeHeight(ti->tile) + 5;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1016
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
  1017
			// draw rail or road component
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
			image = b[0];
2148
542ea702738c (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
  1019
			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1020
			if (axis == AXIS_X) {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1021
				AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 11, 1, z);
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1022
			} else {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1023
				AddSortableSpriteToDraw(image, ti->x, ti->y, 11, 16, 1, z);
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1024
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
			x = ti->x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
			y = ti->y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
			image = b[1];
2148
542ea702738c (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
  1029
			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
  1031
			// draw roof, the component of the bridge which is logically between the vehicle and the camera
3229
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
  1032
			if (axis == AXIS_X) {
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
  1033
				y += 12;
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
  1034
				if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 16, 1, 0x28, z);
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
  1035
			} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
				x += 12;
3229
679bdb5b6830 (svn r3902) When drawing a bridge middle part get the bridge axis only once instead of again and again
tron
parents: 3228
diff changeset
  1037
				if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 1, 16, 0x28, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1039
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3301
diff changeset
  1040
			if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC || GetRailTypeOnBridge(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3301
diff changeset
  1041
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1042
			if (ti->z + 5 == z) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
				// draw poles below for small bridges
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
				image = b[2];
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1045
				if (image != 0) {
2148
542ea702738c (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
  1046
					if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
					DrawGroundSpriteAt(image, x, y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
			} else if (_patches.bridge_pillars) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
				// draw pillars below for high bridges
3556
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
  1051
				DrawBridgePillars(b[2], ti, x, y, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
2537
5e4ca74e995a (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2536
diff changeset
  1057
static uint GetSlopeZ_TunnelBridge(const TileInfo* ti)
5e4ca74e995a (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2536
diff changeset
  1058
{
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1059
	TileIndex tile = ti->tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
	uint z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
	uint x = ti->x & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
	uint y = ti->y & 0xF;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
  1063
	Slope tileh = ti->tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1065
	if (IsTunnel(tile)) {
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1066
		uint pos = (DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? y : x);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1068
		// In the tunnel entrance?
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1069
		if (5 <= pos && pos <= 10) return z;
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1070
	} else {
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1071
		if (IsBridgeRamp(tile)) {
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1072
			DiagDirection dir = GetBridgeRampDirection(tile);
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1073
			uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1074
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1075
			// On the bridge ramp?
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1076
			if (5 <= pos && pos <= 10) {
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1077
				uint delta;
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1078
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1079
				if (HASBIT(BRIDGE_HORZ_RAMP, tileh)) return z + TILE_HEIGHT;
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1080
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1081
				if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) z += TILE_HEIGHT;
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1082
				switch (dir) {
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1083
					default:
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1084
					case DIAGDIR_NE: delta = (TILE_SIZE - 1 - x) / 2; break;
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1085
					case DIAGDIR_SE: delta = y / 2; break;
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1086
					case DIAGDIR_SW: delta = x / 2; break;
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1087
					case DIAGDIR_NW: delta = (TILE_SIZE - 1 - y) / 2; break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
				}
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1089
				return z + 1 + delta;
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1090
			} else {
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1091
				uint f = GetBridgeFoundation(tileh, DiagDirToAxis(dir));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1092
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1093
				if (f != 0) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1094
					if (f < 15) return z + TILE_HEIGHT;
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1095
					tileh = _inclined_tileh[f - 15];
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1096
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
			}
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1098
		} else {
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1099
			// HACK on the bridge?
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1100
			if (_get_z_hint >= z + TILE_HEIGHT + (tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT)) return _get_z_hint;
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1101
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1102
			if (IsTransportUnderBridge(tile)) {
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1103
				uint f = _bridge_foundations[GetBridgeAxis(tile)][tileh];
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1104
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1105
				if (f != 0) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1106
					if (f < 15) return z + TILE_HEIGHT;
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1107
					tileh = _inclined_tileh[f - 15];
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1108
				}
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1109
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1113
	return z + GetPartialZ(x, y, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
  1116
static Slope GetSlopeTileh_TunnelBridge(TileIndex tile, Slope tileh)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1117
{
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1118
	// not accurate, but good enough for slope graphics drawing
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
  1119
	return SLOPE_FLAT;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1120
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1121
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1122
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1123
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
	STR_501F_WOODEN_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
	STR_5020_CONCRETE_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
	STR_501C_STEEL_GIRDER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
	STR_501E_REINFORCED_CONCRETE_SUSPENSION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
	STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
	STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
	STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
	STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
	STR_501C_STEEL_GIRDER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
	STR_5027_TUBULAR_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
	STR_5027_TUBULAR_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
	STR_5027_TUBULAR_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	0,0,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	STR_5025_WOODEN_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	STR_5026_CONCRETE_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
	STR_5022_STEEL_GIRDER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	STR_5024_REINFORCED_CONCRETE_SUSPENSION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
	STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	STR_5022_STEEL_GIRDER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	STR_5028_TUBULAR_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	STR_5028_TUBULAR_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
	STR_5028_TUBULAR_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
	0,0,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1160
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
{
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
  1162
	if (IsTunnel(tile)) {
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1163
		td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ?
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1164
			STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
	} else {
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1166
		td->str = _bridge_tile_str[GetBridgeTransportType(tile) << 4 | GetBridgeType(tile)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3220
diff changeset
  1168
		// the owner is stored at the end of the bridge
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3220
diff changeset
  1169
		if (IsBridgeMiddle(tile)) tile = GetSouthernBridgeEnd(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
	}
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1171
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1175
static void AnimateTile_TunnelBridge(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1180
static void TileLoop_TunnelBridge(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
{
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1182
	switch (_opt.landscape) {
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1183
		case LT_HILLY:
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1184
			if (GetTileZ(tile) > _opt.snow_line) {
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1185
				if (!(_m[tile].m4 & 0x80)) {
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1186
					_m[tile].m4 |= 0x80;
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1187
					MarkTileDirtyByTile(tile);
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1188
				}
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1189
			} else {
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1190
				if (_m[tile].m4 & 0x80) {
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1191
					_m[tile].m4 &= ~0x80;
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1192
					MarkTileDirtyByTile(tile);
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1193
				}
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1194
			}
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1195
			break;
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1196
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1197
		case LT_DESERT:
3379
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3367
diff changeset
  1198
			if (GetTropicZone(tile) == TROPICZONE_DESERT && !(_m[tile].m4 & 0x80)) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  1199
				_m[tile].m4 |= 0x80;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
			}
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1202
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1205
	if (IsBridge(tile) && IsBridgeMiddle(tile) && IsWaterUnderBridge(tile)) {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1206
		TileLoop_Water(tile);
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1207
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1210
static void ClickTile_TunnelBridge(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1216
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	uint32 result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
  1220
	if (IsTunnel(tile)) {
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1221
		if (GetTunnelTransportType(tile) == mode) {
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1222
			return DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? 0x101 : 0x202;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
		}
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1224
	} else if (IsBridge(tile)) { // XXX is this necessary?
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3362
diff changeset
  1225
		if (IsBridgeRamp(tile)) {
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3362
diff changeset
  1226
			if (GetBridgeTransportType(tile) != mode) return 0;
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3362
diff changeset
  1227
			return (DiagDirToAxis(GetBridgeRampDirection(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3362
diff changeset
  1228
		} else {
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3362
diff changeset
  1229
			result = 0;
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3362
diff changeset
  1230
			if (GetBridgeTransportType(tile) == mode) {
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3362
diff changeset
  1231
				result = (GetBridgeAxis(tile) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3362
diff changeset
  1232
			}
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1233
			if (IsTransportUnderBridge(tile)) {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1234
				if (GetTransportTypeUnderBridge(tile) != mode) return result;
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1235
			} else {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1236
				if (IsClearUnderBridge(tile)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
					return result;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1238
				} else {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1239
					if (mode != TRANSPORT_WATER) return result;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1240
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
			}
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 98
diff changeset
  1242
			/* If we've not returned yet, there is a compatible
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 98
diff changeset
  1243
			 * transport or water beneath, so we can add it to
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 98
diff changeset
  1244
			 * result */
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 98
diff changeset
  1245
			/* Why is this xor'd ? Can't it just be or'd? */
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1246
			result ^= (GetBridgeAxis(tile) == AXIS_X ? 0x202 : 0x101);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
		return result;
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 98
diff changeset
  1249
	} else {
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 98
diff changeset
  1250
		assert(0); /* This should never occur */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2422
diff changeset
  1255
static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
{
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1257
	if (!IsTileOwner(tile, old_player)) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1258
2502
a77b8b2f173c (svn r3028) s/255/OWNER_SPECTATOR/
tron
parents: 2493
diff changeset
  1259
	if (new_player != OWNER_SPECTATOR) {
1902
86b7fb11f938 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  1260
		SetTileOwner(tile, new_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
	}	else {
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1262
		if (IsBridge(tile) && IsBridgeMiddle(tile) && IsTransportUnderBridge(tile)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
			// the stuff BELOW the middle part is owned by the deleted player.
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1264
			if (GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) {
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
  1265
				SetClearUnderBridge(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
			} else {
1902
86b7fb11f938 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  1267
				SetTileOwner(tile, OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
		} else {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
  1270
			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
static const byte _tunnel_fractcoord_1[4] = {0x8E,0x18,0x81,0xE8};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
static const byte _tunnel_fractcoord_2[4] = {0x81,0x98,0x87,0x38};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
static const byte _tunnel_fractcoord_3[4] = {0x82,0x88,0x86,0x48};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
static const byte _exit_tunnel_track[4] = {1,2,1,2};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
static const byte _road_exit_tunnel_state[4] = {8, 9, 0, 1};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1289
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
{
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
  1291
	if (IsTunnel(tile)) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2958
diff changeset
  1292
		int z = GetSlopeZ(x, y) - v->z_pos;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2958
diff changeset
  1293
		byte fc;
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1294
		DiagDirection dir;
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1295
		DiagDirection vdir;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2958
diff changeset
  1296
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1297
		if (myabs(z) > 2) return 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
		if (v->type == VEH_Train) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1300
			fc = (x & 0xF) + (y << 4);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1301
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1302
			dir = GetTunnelDirection(tile);
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1303
			vdir = DirToDiagDir(v->direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
			if (v->u.rail.track != 0x40 && dir == vdir) {
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2663
diff changeset
  1306
				if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
					if (v->spritenum < 4)
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1308
						SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
					return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
				if (fc == _tunnel_fractcoord_2[dir]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
					v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
					v->u.rail.track = 0x40;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
					v->vehstatus |= VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
					return 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1319
			if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) {
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  1320
				/* We're at the tunnel exit ?? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
				v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
				v->u.rail.track = _exit_tunnel_track[dir];
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1209
diff changeset
  1323
				assert(v->u.rail.track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
				v->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
				return 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
		} else if (v->type == VEH_Road) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1328
			fc = (x & 0xF) + (y << 4);
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1329
			dir = GetTunnelDirection(tile);
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1330
			vdir = DirToDiagDir(v->direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
			// Enter tunnel?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
			if (v->u.road.state != 0xFF && dir == vdir) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
				if (fc == _tunnel_fractcoord_4[dir] ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
						fc == _tunnel_fractcoord_5[dir]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
					v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
					v->u.road.state = 0xFF;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1338
					v->vehstatus |= VS_HIDDEN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
					return 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
					return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1345
			if (dir == ReverseDiagDir(vdir) && (
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1346
						/* We're at the tunnel exit ?? */
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1347
						fc == _tunnel_fractcoord_6[dir] ||
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1348
						fc == _tunnel_fractcoord_7[dir]
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1349
					) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
					z == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
				v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
				v->u.road.state = _road_exit_tunnel_state[dir];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
				v->u.road.frame = _road_exit_tunnel_frame[dir];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
				v->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
				return 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
		}
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1358
	} else if (IsBridge(tile)) { // XXX is this necessary?
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2663
diff changeset
  1359
		if (v->type == VEH_Road || (v->type == VEH_Train && IsFrontEngine(v))) {
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1330
diff changeset
  1360
			uint h;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1330
diff changeset
  1361
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1362
			// Compensate for possible foundation
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1363
			if (GetTileSlope(tile, &h) != SLOPE_FLAT) h += TILE_HEIGHT;
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
  1364
			if (IsBridgeRamp(tile) ||
334
7e87a24e88b5 (svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents: 333
diff changeset
  1365
					myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
				/* modify speed of vehicle */
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
  1367
				uint16 spd = _bridge[GetBridgeType(tile)].speed;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1368
				if (v->type == VEH_Road) spd *= 2;
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1369
				if (v->cur_speed > spd) v->cur_speed = spd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
1587
e054351c7bf0 (svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents: 1585
diff changeset
  1376
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
{
1587
e054351c7bf0 (svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents: 1585
diff changeset
  1378
	TileIndex tile;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1977
diff changeset
  1379
	TileIndexDiff delta = (v->direction & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
1587
e054351c7bf0 (svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents: 1585
diff changeset
  1380
	byte z = v->z_pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
1587
e054351c7bf0 (svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents: 1585
diff changeset
  1382
	for (tile = v->tile;; tile += delta) {
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
  1383
		if (IsTunnelTile(tile) && GetTileZ(tile) == z) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
	return tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
const TileTypeProcs _tile_type_tunnelbridge_procs = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
	DrawTile_TunnelBridge,					/* draw_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
	GetSlopeZ_TunnelBridge,					/* get_slope_z_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
	ClearTile_TunnelBridge,					/* clear_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
	GetAcceptedCargo_TunnelBridge,	/* get_accepted_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
	GetTileDesc_TunnelBridge,				/* get_tile_desc_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
	GetTileTrackStatus_TunnelBridge,/* get_tile_track_status_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
	ClickTile_TunnelBridge,					/* click_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
	AnimateTile_TunnelBridge,				/* animate_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
	TileLoop_TunnelBridge,					/* tile_loop_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
	ChangeTileOwner_TunnelBridge,		/* change_tile_owner_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
	NULL,														/* get_produced_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
	VehicleEnter_TunnelBridge,			/* vehicle_enter_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	NULL,														/* vehicle_leave_tile_proc */
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1402
	GetSlopeTileh_TunnelBridge,			/* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
};