src/tunnelbridge_cmd.cpp
author rubidium
Thu, 21 Jun 2007 14:58:30 +0000
changeset 6992 eac917ac2a27
parent 6950 14ecb0acdfb4
child 7002 1bf6a62b0fcb
permissions -rw-r--r--
(svn r10248) -Codechange: don't limit the cost of tunnels.
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
6117
6507b2a7e71d (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 6106
diff changeset
     3
/** @file tunnelbridge_cmd.cpp
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
     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"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6259
diff changeset
    17
#include "landscape.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
    18
#include "tile.h"
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
    19
#include "tunnel_map.h"
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
    20
#include "unmovable_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
#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
    26
#include "sound.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    27
#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
    28
#include "bridge.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2663
diff changeset
    29
#include "train.h"
3187
6f83f483fed0 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
    30
#include "water_map.h"
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3881
diff changeset
    31
#include "yapf/yapf.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4246
diff changeset
    32
#include "date.h"
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4559
diff changeset
    33
#include "newgrf_sound.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
    35
#include "table/bridge_land.h"
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
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
/*
4293
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    39
	     year of availablity
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    40
	     |  minimum length
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    41
	     |  |   maximum length
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    42
	     |  |   |    price
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    43
	     |  |   |    |    maximum speed
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    44
	     |  |   |    |    |  sprite to use in GUI                string with description
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    45
	     |  |   |    |    |  |                                   |                            */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    46
	{    0, 0, 16,  80,  32, 0xA24, PAL_NONE                  , STR_5012_WOODEN             , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    47
	{    0, 0,  2, 112,  48, 0xA26, PALETTE_TO_STRUCT_RED     , STR_5013_CONCRETE           , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    48
	{ 1930, 0,  5, 144,  64, 0xA25, PAL_NONE                  , STR_500F_GIRDER_STEEL       , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    49
	{    0, 2, 10, 168,  80, 0xA22, PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    50
	{ 1930, 3, 16, 185,  96, 0xA22, PAL_NONE                  , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    51
	{ 1930, 3, 16, 192, 112, 0xA22, PALETTE_TO_STRUCT_YELLOW  , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    52
	{ 1930, 3,  7, 224, 160, 0xA23, PAL_NONE                  , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    53
	{ 1930, 3,  8, 232, 208, 0xA23, PALETTE_TO_STRUCT_BROWN   , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    54
	{ 1930, 3,  9, 248, 240, 0xA23, PALETTE_TO_STRUCT_RED     , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    55
	{ 1930, 0,  2, 240, 256, 0xA27, PAL_NONE                  , STR_500F_GIRDER_STEEL       , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    56
	{ 1995, 2, 16, 255, 320, 0xA28, PAL_NONE                  , STR_5014_TUBULAR_STEEL      , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    57
	{ 2005, 2, 32, 380, 512, 0xA28, PALETTE_TO_STRUCT_YELLOW  , STR_5014_TUBULAR_STEEL      , NULL, 0 },
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
    58
	{ 2010, 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
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
    64
/** calculate the price factor for building a long bridge.
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
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,
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
    66
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
int CalcBridgeLenCostFactor(int x)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    69
	int n;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    70
	int r;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    71
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	if (x < 2) return x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	x -= 2;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    74
	for (n = 0, r = 2;; n++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
		if (x <= n) return r + x * n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
		r += n * n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
		x -= n;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    81
#define M(x) (1 << (x))
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6213
diff changeset
    82
enum BridgeFoundation {
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
    83
	/* foundation, whole tile is leveled up --> 3 corners raised */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    84
	BRIDGE_FULL_LEVELED_FOUNDATION = M(SLOPE_WSE) | M(SLOPE_NWS) | M(SLOPE_ENW) | M(SLOPE_SEN),
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
    85
	/* foundation, tile is partly leveled up --> 1 corner raised */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    86
	BRIDGE_PARTLY_LEVELED_FOUNDATION = M(SLOPE_W) | M(SLOPE_S) | M(SLOPE_E) | M(SLOPE_N),
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
    87
	/* no foundations (X,Y direction) */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    88
	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
    89
	BRIDGE_HORZ_RAMP = (BRIDGE_PARTLY_LEVELED_FOUNDATION | BRIDGE_NO_FOUNDATION) & ~M(SLOPE_FLAT)
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6213
diff changeset
    90
};
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
    91
#undef M
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
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
    93
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
    94
{
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
	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
    96
	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
    97
	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
    98
		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
    99
	} 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
   100
		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
   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
}
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
   103
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
   104
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
   105
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   107
/** Check the slope at the bridge ramps in three easy steps:
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   108
 * - valid slopes without foundation
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   109
 * - valid slopes with foundation
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   110
 * - rest is invalid
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   111
 */
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   112
#define M(x) (1 << (x))
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   113
static CommandCost CheckBridgeSlopeNorth(Axis axis, Slope tileh)
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   114
{
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   115
	uint32 valid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   117
	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW));
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   118
	if (HASBIT(valid, tileh)) return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   120
	valid =
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   121
		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) | M(SLOPE_STEEP_N) |
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   122
		(axis == AXIS_X ? M(SLOPE_E) | M(SLOPE_STEEP_E) : M(SLOPE_W) | M(SLOPE_STEEP_W));
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   123
	if (HASBIT(valid, tileh)) return CommandCost(_price.terraform);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   124
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   128
static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope tileh)
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   129
{
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   130
	uint32 valid;
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   131
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   132
	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE));
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   133
	if (HASBIT(valid, tileh)) return CommandCost();
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   134
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   135
	valid =
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   136
		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) | M(SLOPE_STEEP_S) |
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   137
		(axis == AXIS_X ? M(SLOPE_W) | M(SLOPE_STEEP_W) : M(SLOPE_E) | M(SLOPE_STEEP_E));
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   138
	if (HASBIT(valid, tileh)) return CommandCost(_price.terraform);
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   139
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   140
	return CMD_ERROR;
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   141
}
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   142
#undef M
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   143
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   144
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
uint32 GetBridgeLength(TileIndex begin, TileIndex end)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   147
	int x1 = TileX(begin);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   148
	int y1 = TileY(begin);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   149
	int x2 = TileX(end);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   150
	int y2 = TileY(end);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   151
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   152
	return abs(x2 + y2 - x1 - y1) - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   155
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
   156
{
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
   157
	const Bridge *b = &_bridge[bridge_type];
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   158
	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
   159
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
   160
	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
   161
	if (b->avail_year > _cur_year) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
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
   163
	max = b->max_length;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   164
	if (max >= 16 && _patches.longbridges) max = 100;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   166
	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
   167
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
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
   169
/** 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
   170
 * @param end_tile end tile
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   171
 * @param flags type of operation
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
   172
 * @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
   173
 * @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
   174
 * - p2 = (bit 0- 7) - bridge type (hi bh)
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   175
 * - p2 = (bit 8-..) - rail type or road types.
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   176
 * - p2 = (bit 15  ) - set means road bridge.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   178
CommandCost 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
   179
{
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   180
	uint 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
   181
	RailType railtype;
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   182
	RoadTypes roadtypes;
3853
1a204a464c7b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   183
	uint x;
1a204a464c7b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   184
	uint y;
1a204a464c7b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   185
	uint sx;
1a204a464c7b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   186
	uint sy;
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   187
	TileIndex tile_start;
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   188
	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
   189
	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
   190
	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
   191
	uint z_start;
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   192
	uint z_end;
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   193
	TileIndex tile;
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   194
	TileIndexDiff delta;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   195
	uint bridge_len;
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   196
	Axis direction;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   197
	CommandCost cost, terraformcost, ret;
1585
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   198
	bool allow_on_slopes;
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   199
	bool replace_bridge = false;
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   200
	uint replaced_bridge_type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   203
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	/* 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
   205
	bridge_type = GB(p2, 0, 8);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   206
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
   207
	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
   208
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   209
	/* 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
   210
	if (HASBIT(p2, 15)) {
5852
b2cc4fbc448e (svn r8426) -Fix
tron
parents: 5668
diff changeset
   211
		railtype = INVALID_RAILTYPE; // road bridge
6663
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   212
		roadtypes = (RoadTypes)GB(p2, 8, 3);
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   213
		if (!AreValidRoadTypes(roadtypes)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	} 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
   215
		if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   216
		railtype = (RailType)GB(p2, 8, 8);
6663
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   217
		roadtypes = ROADTYPES_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   220
	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
   221
	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
   222
	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
   223
	sy = TileY(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	/* 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
   226
	if (x == sx) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   227
		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
   228
		direction = AXIS_Y;
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 6010
diff changeset
   229
		if (y > sy) Swap(y, sy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	} else if (y == sy) {
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   231
		direction = AXIS_X;
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 6010
diff changeset
   232
		if (x > sx) Swap(x, sx);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   233
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
		return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   235
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
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
   237
	/* set and test bridge length, availability */
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   238
	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
   239
	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
   240
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	/* 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
   242
	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
   243
	tile_end = TileXY(sx, sy);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   244
	if (IsClearWaterTile(tile_start) || IsClearWaterTile(tile_end)) {
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   245
		return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   246
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   248
	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
   249
	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
   250
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   251
	if (IsSteepSlope(tileh_start)) 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
   252
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   253
		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
   254
		tileh_start = SLOPE_FLAT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   257
	if (IsSteepSlope(tileh_end)) 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
   258
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   259
		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
   260
		tileh_end = SLOPE_FLAT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   263
	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
   264
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   265
	/* 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
   266
	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
   267
	                   && _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
   268
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   269
	TransportType transport_type = railtype == INVALID_RAILTYPE ? TRANSPORT_ROAD : TRANSPORT_RAIL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   271
	if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   272
			GetOtherBridgeEnd(tile_start) == tile_end &&
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   273
			GetBridgeTransportType(tile_start) == transport_type) {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   274
		/* Replace a current bridge. */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   275
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   276
		/* If this is a railway bridge, make sure the railtypes match. */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   277
		if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   278
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   279
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   281
		/* Do not replace town bridges with lower speed bridges. */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   282
		if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   283
				_bridge[bridge_type].speed < _bridge[GetBridgeType(tile_start)].speed) {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   284
			Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   285
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   286
			if (t == NULL) {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   287
				return CMD_ERROR;
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   288
			} else {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   289
				SetDParam(0, t->index);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   290
				return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   291
			}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   292
		}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   293
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   294
		/* Do not replace the bridge with the same bridge type. */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   295
		if (!(flags & DC_QUERY_COST) && bridge_type == GetBridgeType(tile_start)) {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   296
			return_cmd_error(STR_1007_ALREADY_BUILT);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   297
		}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   298
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   299
		/* Do not allow replacing another player's bridges. */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   300
		if (!IsTileOwner(tile_start, _current_player) && !IsTileOwner(tile_start, OWNER_TOWN)) {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   301
			return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   302
		}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   303
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   304
		cost.AddCost((bridge_len + 1) * _price.clear_bridge); // The cost of clearing the current bridge.
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   305
		replace_bridge = true;
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   306
		replaced_bridge_type = GetBridgeType(tile_start);
6708
257de56ddd2f (svn r9940) -Fix [FS#805]: upgrading a bridge removed roadtypes.
rubidium
parents: 6699
diff changeset
   307
257de56ddd2f (svn r9940) -Fix [FS#805]: upgrading a bridge removed roadtypes.
rubidium
parents: 6699
diff changeset
   308
		/* Do not remove road types when upgrading a bridge */
257de56ddd2f (svn r9940) -Fix [FS#805]: upgrading a bridge removed roadtypes.
rubidium
parents: 6699
diff changeset
   309
		roadtypes |= GetRoadTypes(tile_start);
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   310
	} else {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   311
		/* Build a new bridge. */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   312
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   313
		/* Try and clear the start landscape */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   314
		ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   315
		if (CmdFailed(ret)) return ret;
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   316
		cost = ret;
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   317
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   318
		terraformcost = CheckBridgeSlopeNorth(direction, tileh_start);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   319
		if (CmdFailed(terraformcost) || (terraformcost.GetCost() != 0 && !allow_on_slopes))
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   320
			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   321
		cost.AddCost(terraformcost);
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   322
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   323
		/* Try and clear the end landscape */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   324
		ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   325
		if (CmdFailed(ret)) return ret;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   326
		cost.AddCost(ret);
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   327
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   328
		/* false - end tile slope check */
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   329
		terraformcost = CheckBridgeSlopeSouth(direction, tileh_end);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   330
		if (CmdFailed(terraformcost) || (terraformcost.GetCost() != 0 && !allow_on_slopes))
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   331
			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   332
		cost.AddCost(terraformcost);
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   333
	}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   334
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   335
	if (!replace_bridge) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   336
		TileIndex Heads[] = {tile_start, tile_end};
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   337
		int i;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   338
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   339
		for (i = 0; i < 2; i++) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   340
			if (MayHaveBridgeAbove(Heads[i])) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   341
				if (IsBridgeAbove(Heads[i])) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   342
					TileIndex north_head = GetNorthernBridgeEnd(Heads[i]);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   343
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   344
					if (direction == GetBridgeAxis(Heads[i])) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   345
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   346
					if (z_start + TILE_HEIGHT == GetBridgeHeight(north_head)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   347
						return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   348
					}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   349
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   350
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   351
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   352
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	/* do the drill? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	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
   356
		DiagDirection dir = AxisToDiagDir(direction);
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   357
		Owner owner = (replace_bridge && IsTileOwner(tile_start, OWNER_TOWN)) ? OWNER_TOWN : _current_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
5852
b2cc4fbc448e (svn r8426) -Fix
tron
parents: 5668
diff changeset
   359
		if (railtype != INVALID_RAILTYPE) {
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   360
			MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   361
			MakeRailBridgeRamp(tile_end,   owner, 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
   362
		} else {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   363
			MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir, roadtypes);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   364
			MakeRoadBridgeRamp(tile_end,   owner, bridge_type, ReverseDiagDir(dir), roadtypes);
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   365
		}
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   366
		MarkTileDirtyByTile(tile_start);
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   367
		MarkTileDirtyByTile(tile_end);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   370
	delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   371
	for (tile = tile_start + delta; tile != tile_end; tile += delta) {
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   372
		uint z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   374
		if (GetTileSlope(tile, &z) != SLOPE_FLAT && z >= z_start) return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   376
		if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && !replace_bridge) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   377
			/* Disallow crossing bridges for the time being */
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   378
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
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
   379
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   381
		switch (GetTileType(tile)) {
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   382
			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
   383
				if (!EnsureNoVehicle(tile)) return_cmd_error(STR_980E_SHIP_IN_THE_WAY);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   384
				if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   385
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   387
			case MP_RAILWAY:
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   388
				if (!IsPlainRailTile(tile)) goto not_valid_below;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   389
				break;
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   390
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   391
			case MP_STREET:
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   392
				if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) goto not_valid_below;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   393
				break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   394
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   395
			case MP_TUNNELBRIDGE:
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   396
				if (IsTunnel(tile)) break;
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   397
				if (replace_bridge) break;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   398
				if (direction == DiagDirToAxis(GetBridgeRampDirection(tile))) goto not_valid_below;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   399
				if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   400
				break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   401
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   402
			case MP_UNMOVABLE:
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   403
				if (!IsOwnedLand(tile)) goto not_valid_below;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   404
				break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   405
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   406
			case MP_CLEAR:
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   407
				if (!replace_bridge && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   408
				break;
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   409
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   410
			default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
not_valid_below:;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   412
				/* 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
   413
				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
   414
				if (CmdFailed(ret)) return ret;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   415
				cost.AddCost(ret);
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   416
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
		if (flags & DC_EXEC) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   420
			SetBridgeMiddle(tile, direction);
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   421
			MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
5554
49c032cbe21d (svn r7936) -Fix (r4987, old-rev): Only update the signals and YAPF cache on a DC_EXEC action for bridge-building
Darkvater
parents: 5475
diff changeset
   425
	if (flags & DC_EXEC) {
5561
d276d7fbc819 (svn r7966) -Fix (r7936): Eh AxisToTrack returns Track not Axis, thanks KUDr
Darkvater
parents: 5554
diff changeset
   426
		Track track = AxisToTrack(direction);
d276d7fbc819 (svn r7966) -Fix (r7936): Eh AxisToTrack returns Track not Axis, thanks KUDr
Darkvater
parents: 5554
diff changeset
   427
		SetSignalsOnBothDir(tile_start, track);
d276d7fbc819 (svn r7966) -Fix (r7936): Eh AxisToTrack returns Track not Axis, thanks KUDr
Darkvater
parents: 5554
diff changeset
   428
		YapfNotifyTrackLayoutChange(tile_start, track);
5554
49c032cbe21d (svn r7936) -Fix (r4987, old-rev): Only update the signals and YAPF cache on a DC_EXEC action for bridge-building
Darkvater
parents: 5475
diff changeset
   429
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   431
	/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   432
	 * It's unnecessary to execute this command every time for every bridge. So it is done only
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   433
	 * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   434
	 */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   435
	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
   436
		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
   437
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   438
		bridge_len += 2; // begin and end tiles/ramps
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   440
		if (IsValidPlayer(_current_player) && !_is_old_ai_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
			bridge_len = CalcBridgeLenCostFactor(bridge_len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   443
		cost.AddCost((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
   444
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   450
/** Build Tunnel.
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6427
diff changeset
   451
 * @param start_tile start tile of tunnel
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   452
 * @param flags type of operation
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   453
 * @param p1 railtype or roadtypes. bit 9 set means road tunnel
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   454
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   456
CommandCost 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
   457
{
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   458
	TileIndexDiff delta;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   459
	TileIndex end_tile;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   460
	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
   461
	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
   462
	Slope end_tileh;
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   463
	uint start_z;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   464
	uint end_z;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   465
	CommandCost cost;
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   466
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   468
	_build_tunnel_endtile = 0;
6663
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   469
	if (!HASBIT(p1, 9)) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   470
		if (!ValParamRailtype(p1)) return CMD_ERROR;
6663
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   471
	} else if (!AreValidRoadTypes((RoadTypes)GB(p1, 0, 3))) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   472
		return CMD_ERROR;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   473
	}
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   474
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   475
	start_tileh = GetTileSlope(start_tile, &start_z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   477
	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
   478
		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
   479
		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
   480
		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
   481
		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
   482
		default: return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   483
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
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
   485
	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
   486
	if (CmdFailed(ret)) return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
4273
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   488
	/* XXX - do NOT change 'ret' in the loop, as it is used as the price
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   489
	 * for the clearing of the entrance of the tunnel. Assigning it to
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   490
	 * cost before the loop will yield different costs depending on start-
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   491
	 * position, because of increased-cost-by-length: 'cost += cost >> 3' */
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   492
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   493
	delta = TileOffsByDiagDir(direction);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   494
	end_tile = start_tile;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   495
	for (;;) {
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   496
		end_tile += delta;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   497
		end_tileh = GetTileSlope(end_tile, &end_z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   499
		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
   500
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
   501
		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
   502
			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
   503
		}
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   504
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   505
		cost.AddCost(_price.build_tunnel);
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   506
		cost.AddCost(cost.GetCost() >> 3); // add a multiplier for longer tunnels
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
4273
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   509
	/* Add the cost of the entrance */
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   510
	cost.AddCost(_price.build_tunnel);
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   511
	cost.AddCost(ret);
4273
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   512
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   513
	/* if the command fails from here on we want the end tile to be highlighted */
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   514
	_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
   515
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   516
	/* 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
   517
	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
   518
		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
   519
		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
   520
	} 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
   521
		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
   522
		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
   523
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   524
	cost.AddCost(_price.build_tunnel);
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   525
	cost.AddCost(ret);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   526
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   527
	if (flags & DC_EXEC) {
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   528
		if (GB(p1, 9, 1) == TRANSPORT_RAIL) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   529
			MakeRailTunnel(start_tile, _current_player, direction,                 (RailType)GB(p1, 0, 4));
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   530
			MakeRailTunnel(end_tile,   _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4));
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3881
diff changeset
   531
			UpdateSignalsOnSegment(start_tile, direction);
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   532
			YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction)));
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   533
		} else {
6663
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   534
			MakeRoadTunnel(start_tile, _current_player, direction,                 (RoadTypes)GB(p1, 0, 3));
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   535
			MakeRoadTunnel(end_tile,   _current_player, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 3));
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   536
		}
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   537
	}
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   538
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   539
	return cost;
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
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   542
TileIndex CheckTunnelBusy(TileIndex tile, uint *length)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
{
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1330
diff changeset
   544
	uint z = GetTileZ(tile);
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   545
	DiagDirection dir = GetTunnelDirection(tile);
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   546
	TileIndexDiff delta = TileOffsByDiagDir(dir);
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   547
	uint len = 0;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   548
	TileIndex starttile = tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	Vehicle *v;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   550
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
   551
	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
   552
		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
   553
		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
   554
	} 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
   555
		!IsTunnelTile(tile) ||
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   556
		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
   557
		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
   558
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   560
	v = FindVehicleBetween(starttile, tile, z);
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   561
	if (v != NULL) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   562
		_error_message = v->type == VEH_TRAIN ?
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   563
			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
   564
		return INVALID_TILE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   566
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   567
	if (length != NULL) *length = len;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
	return tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   571
static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile)
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   572
{
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   573
	/* Floods can remove anything as well as the scenario editor */
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   574
	if (_current_player == OWNER_WATER || _game_mode == GM_EDITOR) return true;
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   575
	/* Obviously if the bridge/tunnel belongs to us, or no-one, we can remove it */
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   576
	if (CheckTileOwnership(tile) || IsTileOwner(tile, OWNER_NONE)) return true;
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   577
	/* Otherwise we can only remove town-owned stuff with extra patch-settings, or cheat */
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   578
	if (IsTileOwner(tile, OWNER_TOWN) && (_patches.extra_dynamite || _cheats.magic_bulldozer.value)) return true;
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   579
	return false;
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   580
}
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   581
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   582
static CommandCost DoClearTunnel(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
{
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   584
	Town *t = NULL;
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   585
	TileIndex endtile;
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   586
	uint length;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   590
	if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
	endtile = CheckTunnelBusy(tile, &length);
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   593
	if (endtile == INVALID_TILE) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
	_build_tunnel_endtile = endtile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   596
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
   597
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   598
		t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   599
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   600
		/* Check if you are allowed to remove the tunnel owned by a town
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   601
		 * Removal depends on difficulty settings */
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
   602
		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
   603
			SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
	if (flags & DC_EXEC) {
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   609
		/* We first need to request the direction before calling DoClearSquare
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   610
		 *  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
   611
		DiagDirection dir = GetTunnelDirection(tile);
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   612
		Track track;
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
   613
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   614
		/* Adjust the town's player rating. Do this before removing the tile owner info. */
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
   615
		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
   616
			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
   617
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
		DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
		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
   620
		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
   621
		UpdateSignalsOnSegment(endtile, dir);
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   622
		track = AxisToTrack(DiagDirToAxis(dir));
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   623
		YapfNotifyTrackLayoutChange(tile, track);
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   624
		YapfNotifyTrackLayoutChange(endtile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   626
	return CommandCost(_price.clear_tunnel * (length + 1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   629
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   630
static bool IsVehicleOnBridge(TileIndex starttile, TileIndex endtile, uint z)
3779
8159f95872dc (svn r4771) -Regression: It was possible to remove a bridge while a vehicle was on it
tron
parents: 3774
diff changeset
   631
{
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   632
	const Vehicle *v;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   633
	FOR_ALL_VEHICLES(v) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   634
		if ((v->tile == starttile || v->tile == endtile) && v->z_pos == z) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   635
			_error_message = VehicleInTheWayErrMsg(v);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   636
			return true;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   637
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   638
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   639
	return false;
3779
8159f95872dc (svn r4771) -Regression: It was possible to remove a bridge while a vehicle was on it
tron
parents: 3774
diff changeset
   640
}
8159f95872dc (svn r4771) -Regression: It was possible to remove a bridge while a vehicle was on it
tron
parents: 3774
diff changeset
   641
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   642
static CommandCost DoClearBridge(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
{
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
   644
	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
   645
	TileIndexDiff delta;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   646
	TileIndex endtile;
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   647
	Town *t = NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   648
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   651
	if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
3228
72f4272b56d8 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   653
	endtile = GetOtherBridgeEnd(tile);
6537
905e947d4b1d (svn r9726) -Fix [FS#738]: crash when destroying bridge with train partially one it.
rubidium
parents: 6484
diff changeset
   654
	byte bridge_height = GetBridgeHeight(tile);
3228
72f4272b56d8 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   655
6537
905e947d4b1d (svn r9726) -Fix [FS#738]: crash when destroying bridge with train partially one it.
rubidium
parents: 6484
diff changeset
   656
	if (FindVehicleOnTileZ(tile, bridge_height) != NULL ||
905e947d4b1d (svn r9726) -Fix [FS#738]: crash when destroying bridge with train partially one it.
rubidium
parents: 6484
diff changeset
   657
			FindVehicleOnTileZ(endtile, bridge_height) != NULL ||
905e947d4b1d (svn r9726) -Fix [FS#738]: crash when destroying bridge with train partially one it.
rubidium
parents: 6484
diff changeset
   658
			IsVehicleOnBridge(tile, endtile, bridge_height)) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   659
		return CMD_ERROR;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   660
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
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
   662
	direction = GetBridgeRampDirection(tile);
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   663
	delta = TileOffsByDiagDir(direction);
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
   664
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
   665
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   666
		t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   667
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   668
		/* Check if you are allowed to remove the bridge owned by a town
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   669
		 * Removal depends on difficulty settings */
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   670
		if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) {
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   671
			SetDParam(0, t->index);
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   672
			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   673
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
	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
   677
		TileIndex c;
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   678
		Track track;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   680
		/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   681
		 * 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
   682
		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
1005
f48b2bdd84fc (svn r1504) enummed town ratings (Jango)
celestar
parents: 959
diff changeset
   683
			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
   684
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   685
		DoClearSquare(tile);
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   686
		DoClearSquare(endtile);
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   687
		for (c = tile + delta; c != endtile; c += delta) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   688
				ClearBridgeMiddle(c);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   689
			MarkTileDirtyByTile(c);
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   690
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
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
   692
		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
   693
		UpdateSignalsOnSegment(endtile, direction);
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   694
		track = AxisToTrack(DiagDirToAxis(direction));
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   695
		YapfNotifyTrackLayoutChange(tile, track);
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   696
		YapfNotifyTrackLayoutChange(endtile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   699
	return CommandCost((DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   702
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   703
{
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
   704
	if (IsTunnel(tile)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   705
		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
   706
		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
   707
	} else if (IsBridge(tile)) { // XXX Is this necessary?
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   708
		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
   709
		return DoClearBridge(tile, flags);
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   710
	}
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   711
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
   712
	return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
6368
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   715
/**
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   716
 * Switches the rail type for a tunnel or a bridgehead. As the railtype
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   717
 * on the bridge are determined by the one of the bridgehead, this
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   718
 * functions converts the railtype on the entire bridge.
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   719
 * @param tile        The tile on which the railtype is to be convert.
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   720
 * @param totype      The railtype we want to convert to
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   721
 * @param exec        Switches between test and execute mode
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   722
 * @return            The cost and state of the operation
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   723
 * @retval CMD_ERROR  An error occured during the operation.
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   724
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   725
CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
{
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   727
	TileIndex endtile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
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
   729
	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   730
		uint length;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   731
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
		if (!CheckTileOwnership(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   734
		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
   735
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   736
		/* 'hidden' elrails can't be downgraded to normal rail when elrails are disabled */
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5057
diff changeset
   737
		if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5057
diff changeset
   738
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
		endtile = CheckTunnelBusy(tile, &length);
1430
967f56d158a5 (svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents: 1419
diff changeset
   740
		if (endtile == INVALID_TILE) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
		if (exec) {
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   743
			Track track;
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   744
			SetRailType(tile, totype);
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   745
			SetRailType(endtile, totype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
			MarkTileDirtyByTile(endtile);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3881
diff changeset
   748
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   749
			track = AxisToTrack(DiagDirToAxis(GetTunnelDirection(tile)));
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3881
diff changeset
   750
			YapfNotifyTrackLayoutChange(tile, track);
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   751
			YapfNotifyTrackLayoutChange(endtile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
		}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   753
		return CommandCost((length + 1) * (_price.build_rail / 2));
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   754
	} else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
		if (!CheckTileOwnership(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
3215
c5dcb0d4b297 (svn r3888) If you think you've checked everything, check once more. *sigh* Fix r3887
tron
parents: 3214
diff changeset
   758
		endtile = GetOtherBridgeEnd(tile);
6537
905e947d4b1d (svn r9726) -Fix [FS#738]: crash when destroying bridge with train partially one it.
rubidium
parents: 6484
diff changeset
   759
		byte bridge_height = GetBridgeHeight(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
6537
905e947d4b1d (svn r9726) -Fix [FS#738]: crash when destroying bridge with train partially one it.
rubidium
parents: 6484
diff changeset
   761
		if (FindVehicleOnTileZ(tile, bridge_height) != NULL ||
905e947d4b1d (svn r9726) -Fix [FS#738]: crash when destroying bridge with train partially one it.
rubidium
parents: 6484
diff changeset
   762
				FindVehicleOnTileZ(endtile, bridge_height) != NULL ||
905e947d4b1d (svn r9726) -Fix [FS#738]: crash when destroying bridge with train partially one it.
rubidium
parents: 6484
diff changeset
   763
				IsVehicleOnBridge(tile, endtile, bridge_height)) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   764
			return CMD_ERROR;
1073
4e8f5f9d673d (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   765
		}
4e8f5f9d673d (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   766
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   767
		if (GetRailType(tile) == totype) return CMD_ERROR;
3213
1ada56a3c4e9 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   768
3218
1bcbf46819b9 (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   769
		if (exec) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   770
			TileIndexDiff delta;
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   771
			Track track;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   772
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   773
			SetRailType(tile, totype);
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   774
			SetRailType(endtile, totype);
3218
1bcbf46819b9 (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   775
			MarkTileDirtyByTile(tile);
1bcbf46819b9 (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   776
			MarkTileDirtyByTile(endtile);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3881
diff changeset
   777
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   778
			track = AxisToTrack(DiagDirToAxis(GetBridgeRampDirection(tile)));
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   779
			YapfNotifyTrackLayoutChange(tile, track);
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   780
			YapfNotifyTrackLayoutChange(endtile, track);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   781
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   782
			delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   783
			for (tile += delta; tile != endtile; tile += delta) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   784
				MarkTileDirtyByTile(tile); // TODO encapsulate this into a function
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
			}
3213
1ada56a3c4e9 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   786
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   788
		return CommandCost((DistanceManhattan(tile, endtile) + 1) * (_price.build_rail / 2));
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   789
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
		return CMD_ERROR;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   791
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   795
static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, uint type, int x, int y, int z)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   797
	SpriteID image = psid->sprite;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
	if (image != 0) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   799
		bool drawfarpillar = !HASBIT(GetBridgeFlags(type), 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
   800
		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
   801
		int i = z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
		const byte *p;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   803
		SpriteID pal;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		static const byte _tileh_bits[4][8] = {
4191
d70efeb2733d (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   806
			{ 2, 1, 8, 4,  16,  2, 0, 9 },
d70efeb2733d (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   807
			{ 1, 8, 4, 2,   2, 16, 9, 0 },
d70efeb2733d (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   808
			{ 4, 8, 1, 2,  16,  2, 0, 9 },
d70efeb2733d (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   809
			{ 2, 4, 8, 1,   2, 16, 9, 0 }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
		};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6422
diff changeset
   812
		if (HASBIT(_transparent_opt, TO_BRIDGES)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   813
			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   814
			pal = PALETTE_TO_TRANSPARENT;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   815
		} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   816
			pal = psid->pal;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   817
		}
333
be1ecd3b8f7c (svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents: 241
diff changeset
   818
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
   819
		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
   820
		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
   821
		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
   822
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   823
		if (IsSteepSlope(ti->tileh)) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   824
			if (!(ti->tileh & p[2])) front_height += TILE_HEIGHT;
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   825
			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
   826
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   828
		for (; z >= front_height || z >= back_height; z -= TILE_HEIGHT) {
4191
d70efeb2733d (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   829
			/* HACK set height of the BB of pillars to 1, because the origin of the
d70efeb2733d (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   830
			 * sprites is at the top
d70efeb2733d (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   831
			 */
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
   832
			if (z >= front_height) { // front facing pillar
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   833
				AddSortableSpriteToDraw(image, pal, x, y, p[4], p[5], 1, z);
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   834
			}
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
   835
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   836
			if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   837
				AddSortableSpriteToDraw(image, pal, x - p[6], y - p[7], p[4], p[5], 1, z);
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   838
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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
uint GetBridgeFoundation(Slope tileh, Axis axis)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   844
{
3878
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   845
	uint i;
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   846
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   847
	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
   848
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   849
	/* inclined sloped building */
3878
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   850
	switch (tileh) {
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   851
		case SLOPE_W:
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   852
		case SLOPE_STEEP_W: i = 0; break;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   853
		case SLOPE_S:
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   854
		case SLOPE_STEEP_S: i = 2; break;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   855
		case SLOPE_E:
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   856
		case SLOPE_STEEP_E: i = 4; break;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   857
		case SLOPE_N:
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   858
		case SLOPE_STEEP_N: i = 6; break;
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   859
		default: return 0;
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
   860
	}
3878
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   861
	if (axis != AXIS_X) ++i;
ef06782573c0 (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   862
	return i + 15;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
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
   865
/**
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   866
 * Draws the trambits over an already drawn (lower end) of a bridge.
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   867
 * @param x       the x of the bridge
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   868
 * @param y       the y of the bridge
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   869
 * @param z       the z of the bridge
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   870
 * @param offset  number representing whether to level or sloped and the direction
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   871
 * @param overlay do we want to still see the road?
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   872
 */
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   873
static void DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay)
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   874
{
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   875
	static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } };
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   876
	static const SpriteID back_offsets[6]    =   {  95,  95,  99, 102, 100, 101 };
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   877
	static const SpriteID front_offsets[6]   =   {  97,  98, 103, 106, 104, 105 };
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   878
6699
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6691
diff changeset
   879
	static const uint size_x[6] = { 11, 16, 16, 16, 16, 16 };
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6691
diff changeset
   880
	static const uint size_y[6] = { 16, 11, 16, 16, 16, 16 };
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6691
diff changeset
   881
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6691
diff changeset
   882
	AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, x, y, size_x[offset], size_y[offset], offset >= 2 ? 1 : 0, z);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   883
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   884
	SpriteID front = SPR_TRAMWAY_BASE + front_offsets[offset];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   885
	SpriteID back  = SPR_TRAMWAY_BASE + back_offsets[offset];
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   886
	SpriteID pal   = PAL_NONE;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   887
	if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   888
		SETBIT(front, PALETTE_MODIFIER_TRANSPARENT);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   889
		SETBIT(back,  PALETTE_MODIFIER_TRANSPARENT);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   890
		pal = PALETTE_TO_TRANSPARENT;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   891
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   892
6699
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6691
diff changeset
   893
	AddSortableSpriteToDraw(back,  pal, x, y, size_x[offset], size_y[offset], 0, z);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   894
	/* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */
6699
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6691
diff changeset
   895
	AddSortableSpriteToDraw(front, pal, x, y, size_x[offset], size_y[offset], offset >= 2 ? 0x30 : 0x10, z);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   896
}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   897
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   898
/**
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   899
 * Draws a tunnel of bridge tile.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   900
 * For tunnels, this is rather simple, as you only needa draw the entrance.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   901
 * Bridges are a bit more complex. base_offset is where the sprite selection comes into play
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   902
 * and it works a bit like a bitmask.<p> For bridge heads:
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   903
 * @param ti TileInfo of the structure to draw
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   904
 * <ul><li>Bit 0: direction</li>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   905
 * <li>Bit 1: northern or southern heads</li>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   906
 * <li>Bit 2: Set if the bridge head is sloped</li>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   907
 * <li>Bit 3 and more: Railtype Specific subset</li>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   908
 * </ul>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   909
 * Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   910
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
static void DrawTile_TunnelBridge(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   913
	SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   914
	SpriteID pal;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   915
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
   916
	if (IsTunnel(ti->tile)) {
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   917
		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
   918
			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
   919
		} 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
   920
			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
   921
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
5410
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
   923
		if (HasTunnelSnowOrDesert(ti->tile)) image += 32;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   925
		image += GetTunnelDirection(ti->tile) * 2;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   926
		DrawGroundSprite(image, PAL_NONE);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   927
		if (GetTunnelTransportType(ti->tile) == TRANSPORT_ROAD) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   928
			DiagDirection dir = GetTunnelDirection(ti->tile);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   929
			RoadTypes rts = GetRoadTypes(ti->tile);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   930
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   931
			if (HASBIT(rts, ROADTYPE_TRAM)) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   932
				static const SpriteID tunnel_sprites[2][4] = { { 28, 78, 79, 27 }, {  5, 76, 77,  4 } };
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   933
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   934
				DrawGroundSprite(SPR_TRAMWAY_BASE + tunnel_sprites[rts - ROADTYPES_TRAM][dir], PAL_NONE);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   935
				AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + dir, PAL_NONE, ti->x, ti->y, 16, 16, 16, (byte)ti->z);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   936
			}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   937
		} else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
6663
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   938
			DrawCatenary(ti);
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   939
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
6663
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   941
		AddSortableSpriteToDraw(image + 1, PAL_NONE, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, 1, 1, 8, (byte)ti->z);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   942
		DrawBridgeMiddle(ti);
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
   943
	} else if (IsBridge(ti->tile)) { // XXX is this necessary?
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   944
		const PalSpriteID *psid;
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
   945
		int base_offset;
5410
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
   946
		bool ice = HasBridgeSnowOrDesert(ti->tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
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
   948
		if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   949
			base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   950
			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
   951
		} 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
   952
			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
   953
		}
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
   954
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
   955
		/* 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
   956
		assert( (base_offset & 0x07) == 0x00);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   958
		if (!HASBIT(BRIDGE_NO_FOUNDATION, ti->tileh)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   959
			int f = GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetBridgeRampDirection(ti->tile)));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   960
			if (f != 0) DrawFoundation(ti, f);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   961
		}
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   962
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   963
		/* HACK Wizardry to convert the bridge ramp direction into a sprite offset */
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   964
		base_offset += (6 - GetBridgeRampDirection(ti->tile)) % 4;
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   965
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   966
		if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   967
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   968
		/* Table number 6 always refers to the bridge heads for any bridge type */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   969
		psid = &GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset];
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   970
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   971
		if (!ice) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   972
			DrawClearLandTile(ti, 3);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   973
		} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   974
			DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE);
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   975
		}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   976
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   977
		image = psid->sprite;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   978
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   979
		/* draw ramp */
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6422
diff changeset
   980
		if (HASBIT(_transparent_opt, TO_BRIDGES)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   981
			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   982
			pal = PALETTE_TO_TRANSPARENT;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   983
		} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   984
			pal = psid->pal;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   985
		}
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   986
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   987
		/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   988
		 * it doesn't disappear behind it
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   989
		 */
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   990
		AddSortableSpriteToDraw(
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   991
			image, pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   992
		);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   993
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   994
		if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   995
			RoadTypes rts = GetRoadTypes(ti->tile);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   996
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   997
			if (HASBIT(rts, ROADTYPE_TRAM)) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   998
				uint offset = GetBridgeRampDirection(ti->tile);
6712
8f21d5cc9418 (svn r9944) -Fix: tile selection drawn on the wrong height for some road bridges.
rubidium
parents: 6708
diff changeset
   999
				uint z = ti->z;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1000
				if (ti->tileh != SLOPE_FLAT) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1001
					offset = (offset + 1) & 1;
6712
8f21d5cc9418 (svn r9944) -Fix: tile selection drawn on the wrong height for some road bridges.
rubidium
parents: 6708
diff changeset
  1002
					z += TILE_HEIGHT;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1003
				} else {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1004
					offset += 2;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1005
				}
6712
8f21d5cc9418 (svn r9944) -Fix: tile selection drawn on the wrong height for some road bridges.
rubidium
parents: 6708
diff changeset
  1006
				DrawBridgeTramBits(ti->x, ti->y, z, offset, HASBIT(rts, ROADTYPE_ROAD));
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1007
			}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1008
		} else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1009
			DrawCatenary(ti);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1010
		}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1011
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1012
		DrawBridgeMiddle(ti);
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
  1013
	}
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
  1014
}
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
  1015
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1016
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1017
/** Compute bridge piece. Computes the bridge piece to display depending on the position inside the bridge.
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1018
 * bridges pieces sequence (middle parts)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1019
 * bridge len 1: 0
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1020
 * bridge len 2: 0 1
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1021
 * bridge len 3: 0 4 1
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1022
 * bridge len 4: 0 2 3 1
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1023
 * bridge len 5: 0 2 5 3 1
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1024
 * bridge len 6: 0 2 3 2 3 1
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1025
 * bridge len 7: 0 2 3 4 2 3 1
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1026
 * #0 - always as first, #1 - always as last (if len>1)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1027
 * #2,#3 are to pair in order
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1028
 * for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1029
 * @param north Northernmost tile of bridge
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1030
 * @param south Southernmost tile of bridge
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1031
 * @return Index of bridge piece
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1032
 */
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1033
static uint CalcBridgePiece(uint north, uint south)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1034
{
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1035
	if (north == 1) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1036
		return 0;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1037
	} else if (south == 1) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1038
		return 1;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1039
	} else if (north < south) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1040
		return north & 1 ? 3 : 2;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1041
	} else if (north > south) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1042
		return south & 1 ? 2 : 3;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1043
	} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1044
		return north & 1 ? 5 : 4;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1045
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1046
}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1047
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1048
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1049
void DrawBridgeMiddle(const TileInfo* ti)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1050
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1051
	const PalSpriteID* psid;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1052
	SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1053
	SpriteID pal;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1054
	uint base_offset;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1055
	TileIndex rampnorth;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1056
	TileIndex rampsouth;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1057
	Axis axis;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1058
	uint piece;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1059
	uint type;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1060
	int x;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1061
	int y;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1062
	uint z;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1063
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1064
	if (!IsBridgeAbove(ti->tile)) return;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1065
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1066
	rampnorth = GetNorthernBridgeEnd(ti->tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1067
	rampsouth = GetSouthernBridgeEnd(ti->tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1068
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1069
	axis = GetBridgeAxis(ti->tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1070
	piece = CalcBridgePiece(
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1071
		DistanceManhattan(ti->tile, rampnorth),
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1072
		DistanceManhattan(ti->tile, rampsouth)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1073
	);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1074
	type = GetBridgeType(rampsouth);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1075
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1076
	if (GetBridgeTransportType(rampsouth) == TRANSPORT_RAIL) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1077
		base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1078
	} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1079
		base_offset = 8;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1080
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1081
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1082
	psid = base_offset + GetBridgeSpriteTable(type, piece);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1083
	if (axis != AXIS_X) psid += 4;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1084
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1085
	x = ti->x;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1086
	y = ti->y;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1087
	uint bridge_z = GetBridgeHeight(rampsouth);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1088
	z = bridge_z - 3;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1089
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1090
	image = psid->sprite;
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6422
diff changeset
  1091
	if (HASBIT(_transparent_opt, TO_BRIDGES)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1092
		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1093
		pal = PALETTE_TO_TRANSPARENT;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1094
	} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1095
		pal = psid->pal;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1096
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1097
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1098
	if (axis == AXIS_X) {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1099
		AddSortableSpriteToDraw(image, pal, x, y, 16, 11, 1, z);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1100
	} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1101
		AddSortableSpriteToDraw(image, pal, x, y, 11, 16, 1, z);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1102
	}
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1103
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1104
	psid++;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1105
	image = psid->sprite;
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6422
diff changeset
  1106
	if (HASBIT(_transparent_opt, TO_BRIDGES)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1107
		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1108
		pal = PALETTE_TO_TRANSPARENT;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1109
	} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1110
		pal = psid->pal;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1111
	}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1112
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1113
	if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1114
		RoadTypes rts = GetRoadTypes(rampsouth);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1115
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1116
		if (HASBIT(rts, ROADTYPE_TRAM)) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1117
			DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HASBIT(rts, ROADTYPE_ROAD));
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1118
		}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1119
	} else if (GetRailType(rampsouth) == RAILTYPE_ELECTRIC) {
6687
c7b92f03d33f (svn r9919) -Codechange: prepare some more places for more road types.
rubidium
parents: 6683
diff changeset
  1120
		DrawCatenary(ti);
c7b92f03d33f (svn r9919) -Codechange: prepare some more places for more road types.
rubidium
parents: 6683
diff changeset
  1121
	}
c7b92f03d33f (svn r9919) -Codechange: prepare some more places for more road types.
rubidium
parents: 6683
diff changeset
  1122
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1123
	/* draw roof, the component of the bridge which is logically between the vehicle and the camera */
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1124
	if (axis == AXIS_X) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1125
		y += 12;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1126
		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, pal, x, y, 16, 1, 0x28, z);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1127
	} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1128
		x += 12;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1129
		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, pal, x, y, 1, 16, 0x28, z);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1130
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1131
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1132
	psid++;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1133
	if (ti->z + 5 == z) {
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1134
		/* draw poles below for small bridges */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1135
		if (psid->sprite != 0) {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1136
			image = psid->sprite;
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6422
diff changeset
  1137
			if (HASBIT(_transparent_opt, TO_BRIDGES)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1138
				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1139
				pal = PALETTE_TO_TRANSPARENT;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1140
			} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1141
				pal = psid->pal;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1142
			}
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1143
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1144
			DrawGroundSpriteAt(image, pal, x, y, z);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1145
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1146
	} else if (_patches.bridge_pillars) {
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1147
		/* draw pillars below for high bridges */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1148
		DrawBridgePillars(psid, ti, axis, type, x, y, z);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1149
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1150
}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1151
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1152
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1153
static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
2537
5e4ca74e995a (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2536
diff changeset
  1154
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1155
	uint z;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1156
	Slope tileh = GetTileSlope(tile, &z);
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1157
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1158
	x &= 0xF;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1159
	y &= 0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1161
	if (IsTunnel(tile)) {
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1162
		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
  1163
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1164
		/* In the tunnel entrance? */
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1165
		if (5 <= pos && pos <= 10) return z;
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1166
	} else {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1167
		DiagDirection dir = GetBridgeRampDirection(tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1168
		uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
  1169
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1170
		/* On the bridge ramp? */
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1171
		if (5 <= pos && pos <= 10) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1172
			uint delta;
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
  1173
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1174
			if (IsSteepSlope(tileh)) return z + TILE_HEIGHT * 2;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1175
			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
  1176
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1177
			if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) z += TILE_HEIGHT;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1178
			switch (dir) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1179
				default: NOT_REACHED();
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1180
				case DIAGDIR_NE: delta = (TILE_SIZE - 1 - x) / 2; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1181
				case DIAGDIR_SE: delta = y / 2; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1182
				case DIAGDIR_SW: delta = x / 2; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1183
				case DIAGDIR_NW: delta = (TILE_SIZE - 1 - y) / 2; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1184
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1185
			return z + 1 + delta;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1186
		} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1187
			uint f = GetBridgeFoundation(tileh, DiagDirToAxis(dir));
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
  1188
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1189
			if (f != 0) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1190
				if (IsSteepSlope(tileh)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1191
					z += TILE_HEIGHT;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1192
				} else if (f < 15) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1193
					return z + TILE_HEIGHT;
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
  1194
				}
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1195
				tileh = (Slope)_inclined_tileh[f - 15];
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1196
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1200
	return z + GetPartialZ(x, y, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
  1203
static Slope GetSlopeTileh_TunnelBridge(TileIndex tile, Slope tileh)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1204
{
4062
e801a8766597 (svn r5352) -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitches
tron
parents: 4046
diff changeset
  1205
	if (IsTunnel(tile)) {
e801a8766597 (svn r5352) -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitches
tron
parents: 4046
diff changeset
  1206
		return tileh;
e801a8766597 (svn r5352) -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitches
tron
parents: 4046
diff changeset
  1207
	} else {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1208
		if (HASBIT(BRIDGE_NO_FOUNDATION, tileh)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1209
			return tileh;
4062
e801a8766597 (svn r5352) -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitches
tron
parents: 4046
diff changeset
  1210
		} else {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1211
			uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1212
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1213
			if (f == 0) return tileh;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1214
			if (f < 15) return SLOPE_FLAT;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1215
			return (Slope)_inclined_tileh[f - 15];
4062
e801a8766597 (svn r5352) -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitches
tron
parents: 4046
diff changeset
  1216
		}
e801a8766597 (svn r5352) -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitches
tron
parents: 4046
diff changeset
  1217
	}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1218
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1219
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1220
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1221
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
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
  1227
	STR_501F_WOODEN_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	STR_5020_CONCRETE_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
	STR_501C_STEEL_GIRDER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
	STR_501E_REINFORCED_CONCRETE_SUSPENSION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
	STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
	STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
	STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
	STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
	STR_501C_STEEL_GIRDER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
	STR_5027_TUBULAR_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
	STR_5027_TUBULAR_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
	STR_5027_TUBULAR_RAIL_BRIDGE,
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1240
	0, 0, 0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
	STR_5025_WOODEN_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
	STR_5026_CONCRETE_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
	STR_5022_STEEL_GIRDER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
	STR_5024_REINFORCED_CONCRETE_SUSPENSION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
	STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
	STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
	STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
	STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
	STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
	STR_5022_STEEL_GIRDER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
	STR_5028_TUBULAR_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
	STR_5028_TUBULAR_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
	STR_5028_TUBULAR_ROAD_BRIDGE,
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1255
	0, 0, 0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1258
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
{
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
  1260
	if (IsTunnel(tile)) {
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1261
		td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ?
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1262
			STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
	} 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
  1264
		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
  1265
	}
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
  1266
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
}
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
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1270
static void AnimateTile_TunnelBridge(TileIndex tile)
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
	/* not used */
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
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1275
static void TileLoop_TunnelBridge(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
{
5410
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1277
	bool snow_or_desert = IsTunnelTile(tile) ? HasTunnelSnowOrDesert(tile) : HasBridgeSnowOrDesert(tile);
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
  1278
	switch (_opt.landscape) {
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1279
		case LT_ARCTIC:
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6259
diff changeset
  1280
			if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) {
5410
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1281
				if (IsTunnelTile(tile)) {
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1282
					SetTunnelSnowOrDesert(tile, !snow_or_desert);
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1283
				} else {
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1284
					SetBridgeSnowOrDesert(tile, !snow_or_desert);
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1285
				}
4160
81dfe1debead (svn r5592) Merge two complementary cases
tron
parents: 4158
diff changeset
  1286
				MarkTileDirtyByTile(tile);
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
  1287
			}
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
  1288
			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
  1289
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1290
		case LT_TROPIC:
5410
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1291
			if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) {
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1292
				if (IsTunnelTile(tile)) {
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1293
					SetTunnelSnowOrDesert(tile, true);
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1294
				} else {
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1295
					SetBridgeSnowOrDesert(tile, true);
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1296
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
			}
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
  1299
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1303
static void ClickTile_TunnelBridge(TileIndex tile)
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
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6663
diff changeset
  1309
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
{
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
  1311
	if (IsTunnel(tile)) {
3996
5d30d315a2ed (svn r5199) Make the control flow of GetTileTrackStatus_TunnelBridge() more comprehensible
tron
parents: 3977
diff changeset
  1312
		if (GetTunnelTransportType(tile) != mode) return 0;
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6663
diff changeset
  1313
		if (GetTunnelTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
  1314
		return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(tile))) * 0x101;
3996
5d30d315a2ed (svn r5199) Make the control flow of GetTileTrackStatus_TunnelBridge() more comprehensible
tron
parents: 3977
diff changeset
  1315
	} else {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1316
		if (GetBridgeTransportType(tile) != mode) return 0;
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6663
diff changeset
  1317
		if (GetBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1318
		return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(tile))) * 0x101;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
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
  1322
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
  1323
{
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
  1324
	if (!IsTileOwner(tile, old_player)) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1325
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4656
diff changeset
  1326
	if (new_player != PLAYER_SPECTATOR) {
1902
86b7fb11f938 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  1327
		SetTileOwner(tile, new_player);
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
  1328
	} else {
6734
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1329
		if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1330
			/* When clearing the bridge/tunnel failed there are still vehicles on/in
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1331
			 * the bridge/tunnel. As all *our* vehicles are already removed, they
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1332
			 * must be of another owner. Therefor this must be a road bridge/tunnel.
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1333
			 * In that case we can safely reassign the ownership to OWNER_NONE. */
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1334
			assert((IsTunnel(tile) ? GetTunnelTransportType(tile) : GetBridgeTransportType(tile)) == TRANSPORT_ROAD);
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1335
			SetTileOwner(tile, OWNER_NONE);
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1336
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1341
static const byte _tunnel_fractcoord_1[4]    = {0x8E, 0x18, 0x81, 0xE8};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1342
static const byte _tunnel_fractcoord_2[4]    = {0x81, 0x98, 0x87, 0x38};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1343
static const byte _tunnel_fractcoord_3[4]    = {0x82, 0x88, 0x86, 0x48};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1344
static const byte _exit_tunnel_track[4]      = {1, 2, 1, 2};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1346
/** Get the trackdir of the exit of a tunnel */
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1347
static const Trackdir _road_exit_tunnel_state[DIAGDIR_END] = {
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1348
	TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1349
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
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
  1351
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1352
static const byte _tunnel_fractcoord_4[4]    = {0x52, 0x85, 0x98, 0x29};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1353
static const byte _tunnel_fractcoord_5[4]    = {0x92, 0x89, 0x58, 0x25};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1354
static const byte _tunnel_fractcoord_6[4]    = {0x92, 0x89, 0x56, 0x45};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1355
static const byte _tunnel_fractcoord_7[4]    = {0x52, 0x85, 0x96, 0x49};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1357
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
  1358
{
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1359
	int z = GetSlopeZ(x, y) - v->z_pos;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1360
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1361
	if (myabs(z) > 2) return VETSB_CANNOT_ENTER;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1362
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
  1363
	if (IsTunnel(tile)) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2958
diff changeset
  1364
		byte fc;
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1365
		DiagDirection dir;
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1366
		DiagDirection vdir;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2958
diff changeset
  1367
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1368
		if (v->type == VEH_TRAIN) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1369
			fc = (x & 0xF) + (y << 4);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1370
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1371
			dir = GetTunnelDirection(tile);
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1372
			vdir = DirToDiagDir(v->direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
5993
956d341d930e (svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents: 5991
diff changeset
  1374
			if (v->u.rail.track != TRACK_BIT_WORMHOLE && dir == vdir) {
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2663
diff changeset
  1375
				if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) {
6213
20e4832abe9a (svn r9009) -Fix (r1): Determine whether to play a sound or not when entering a tunnel based on engine type (only steam engines) instead of on spritenum which can be invalid for newgrf trains. DBSet(XL) or any other steam trains without newsounds should sound their horn now.
Darkvater
parents: 6141
diff changeset
  1376
					if (!PlayVehicleSound(v, VSE_TUNNEL) && RailVehInfo(v->engine_type)->engclass == 0) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1377
						SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4559
diff changeset
  1378
					}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1379
					return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
				if (fc == _tunnel_fractcoord_2[dir]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
					v->tile = tile;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1383
					v->u.rail.track = TRACK_BIT_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
					v->vehstatus |= VS_HIDDEN;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1385
					return VETSB_ENTERED_WORMHOLE;
0
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
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1389
			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
  1390
				/* We're at the tunnel exit ?? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
				v->tile = tile;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1392
				v->u.rail.track = (TrackBits)_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
  1393
				assert(v->u.rail.track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
				v->vehstatus &= ~VS_HIDDEN;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1395
				return VETSB_ENTERED_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
			}
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1397
		} else if (v->type == VEH_ROAD) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1398
			fc = (x & 0xF) + (y << 4);
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
  1399
			dir = GetTunnelDirection(tile);
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1400
			vdir = DirToDiagDir(v->direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1402
			/* Enter tunnel? */
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1403
			if (v->u.road.state != RVSB_WORMHOLE && dir == vdir) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
				if (fc == _tunnel_fractcoord_4[dir] ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
						fc == _tunnel_fractcoord_5[dir]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
					v->tile = tile;
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1407
					v->u.road.state = RVSB_WORMHOLE;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1408
					v->vehstatus |= VS_HIDDEN;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1409
					return VETSB_ENTERED_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
				} else {
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1411
					return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1414
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1415
			if (dir == ReverseDiagDir(vdir) && (
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1416
						/* We're at the tunnel exit ?? */
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1417
						fc == _tunnel_fractcoord_6[dir] ||
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1418
						fc == _tunnel_fractcoord_7[dir]
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1419
					) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
					z == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
				v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
				v->u.road.state = _road_exit_tunnel_state[dir];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
				v->u.road.frame = _road_exit_tunnel_frame[dir];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
				v->vehstatus &= ~VS_HIDDEN;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1425
				return VETSB_ENTERED_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
		}
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
  1428
	} else if (IsBridge(tile)) { // XXX is this necessary?
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1429
		DiagDirection dir;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1430
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6734
diff changeset
  1431
		if (v->HasFront() && v->IsPrimaryVehicle()) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1432
			/* modify speed of vehicle */
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1433
			uint16 spd = _bridge[GetBridgeType(tile)].speed;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1434
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1435
			if (v->type == VEH_ROAD) spd *= 2;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1436
			if (v->cur_speed > spd) v->cur_speed = spd;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1437
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1438
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1439
		dir = GetBridgeRampDirection(tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1440
		if (DirToDiagDir(v->direction) == dir) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1441
			switch (dir) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1442
				default: NOT_REACHED();
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1443
				case DIAGDIR_NE: if ((x & 0xF) != 0)             return VETSB_CONTINUE; break;
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1444
				case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1445
				case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1446
				case DIAGDIR_NW: if ((y & 0xF) != 0)             return VETSB_CONTINUE; break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
			}
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1448
			if (v->type == VEH_TRAIN) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1449
				v->u.rail.track = TRACK_BIT_WORMHOLE;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1450
				CLRBIT(v->u.rail.flags, VRF_GOINGUP);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1451
				CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1452
			} else {
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1453
				v->u.road.state = RVSB_WORMHOLE;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1454
			}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1455
			return VETSB_ENTERED_WORMHOLE;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1456
		} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1457
			v->tile = tile;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1458
			if (v->type == VEH_TRAIN) {
5993
956d341d930e (svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents: 5991
diff changeset
  1459
				if (v->u.rail.track == TRACK_BIT_WORMHOLE) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1460
					v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1461
					return VETSB_ENTERED_WORMHOLE;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1462
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1463
			} else {
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1464
				if (v->u.road.state == RVSB_WORMHOLE) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1465
					v->u.road.state = _road_exit_tunnel_state[dir];
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1466
					v->u.road.frame = 0;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1467
					return VETSB_ENTERED_WORMHOLE;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1468
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1469
			}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1470
			return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
	}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1473
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1476
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1477
	DrawTile_TunnelBridge,           /* draw_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1478
	GetSlopeZ_TunnelBridge,          /* get_slope_z_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1479
	ClearTile_TunnelBridge,          /* clear_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1480
	GetAcceptedCargo_TunnelBridge,   /* get_accepted_cargo_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1481
	GetTileDesc_TunnelBridge,        /* get_tile_desc_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1482
	GetTileTrackStatus_TunnelBridge, /* get_tile_track_status_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1483
	ClickTile_TunnelBridge,          /* click_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1484
	AnimateTile_TunnelBridge,        /* animate_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1485
	TileLoop_TunnelBridge,           /* tile_loop_clear */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1486
	ChangeTileOwner_TunnelBridge,    /* change_tile_owner_clear */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1487
	NULL,                            /* get_produced_cargo_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1488
	VehicleEnter_TunnelBridge,       /* vehicle_enter_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1489
	GetSlopeTileh_TunnelBridge,      /* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
};