src/bridge_cmd.cpp
author celestar
Sun, 11 Mar 2007 09:28:58 +0000
branchcustombridgeheads
changeset 5651 335d9bd345b0
parent 5650 aefc131bf5ce
permissions -rw-r--r--
(svn r9109) [cbh] -Fix: Stabilize the reversing of trains on bridges/bridgeheads a little (it still crashes at times however). Also re-allow the construction of signals on bridgeheads
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
5595
049ed4486972 (svn r7613) [cbh] - Codechange: Removed tunnel-specific functions from bridge_cmd.c and bridge-specific functions from tunnel_cmd.c
celestar
parents: 5594
diff changeset
     3
/** @file bridge_cmd.c
2262
bd59b2d8d75f (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)
bd59b2d8d75f (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
bd59b2d8d75f (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
 */
bd59b2d8d75f (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
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1884
diff changeset
     9
#include "openttd.h"
3189
1af302c5abd0 (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
0813719b05a9 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
    11
#include "rail_map.h"
3144
426b825578f9 (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
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1335
diff changeset
    13
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
    14
#include "table/strings.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
    15
#include "functions.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 541
diff changeset
    16
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1192
diff changeset
    17
#include "tile.h"
3154
a8fffb204d0e (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
    18
#include "tunnel_map.h"
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
    19
#include "unmovable_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "town.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 334
diff changeset
    25
#include "sound.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    26
#include "variables.h"
2262
bd59b2d8d75f (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
    27
#include "bridge.h"
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2663
diff changeset
    28
#include "train.h"
3187
0813719b05a9 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
    29
#include "water_map.h"
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3881
diff changeset
    30
#include "yapf/yapf.h"
4261
2ec8f5a9747b (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4246
diff changeset
    31
#include "date.h"
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4559
diff changeset
    32
#include "newgrf_sound.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
    34
#include "table/bridge_land.h"
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
    35
2478
16b05f1de6bb (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
    36
const Bridge orig_bridge[] = {
2262
bd59b2d8d75f (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
    37
/*
4293
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    38
	     year of availablity
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    39
	     |  minimum length
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    40
	     |  |   maximum length
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    41
	     |  |   |    price
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    42
	     |  |   |    |    maximum speed
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    43
	     |  |   |    |    |  sprite to use in GUI                string with description
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    44
	     |  |   |    |    |  |                                   |                            */
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    45
	{    0, 0, 16,  80,  32, 0xA24                             , STR_5012_WOODEN             , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    46
	{    0, 0,  2, 112,  48, 0xA26 | PALETTE_TO_STRUCT_RED     , STR_5013_CONCRETE           , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    47
	{ 1930, 0,  5, 144,  64, 0xA25                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    48
	{    0, 2, 10, 168,  80, 0xA22 | PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    49
	{ 1930, 3, 16, 185,  96, 0xA22                             , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    50
	{ 1930, 3, 16, 192, 112, 0xA22 | PALETTE_TO_STRUCT_YELLOW  , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    51
	{ 1930, 3,  7, 224, 160, 0xA23                             , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    52
	{ 1930, 3,  8, 232, 208, 0xA23 | PALETTE_TO_STRUCT_BROWN   , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    53
	{ 1930, 3,  9, 248, 240, 0xA23 | PALETTE_TO_STRUCT_RED     , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    54
	{ 1930, 0,  2, 240, 256, 0xA27                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    55
	{ 1995, 2, 16, 255, 320, 0xA28                             , STR_5014_TUBULAR_STEEL      , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    56
	{ 2005, 2, 32, 380, 512, 0xA28 | PALETTE_TO_STRUCT_YELLOW  , STR_5014_TUBULAR_STEEL      , NULL, 0 },
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4291
diff changeset
    57
	{ 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
    58
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
2763
d579caf58b59 (svn r3308) BAD
tron
parents: 2737
diff changeset
    60
Bridge _bridge[MAX_BRIDGES];
d579caf58b59 (svn r3308) BAD
tron
parents: 2737
diff changeset
    61
d579caf58b59 (svn r3308) BAD
tron
parents: 2737
diff changeset
    62
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
// calculate the price factor for building a long bridge.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
// basically the cost delta is 1,1, 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6,  7,7,7,7,7,7,7,  8,8,8,8,8,8,8,8,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
int CalcBridgeLenCostFactor(int x)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    67
	int n;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    68
	int r;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    69
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	if (x < 2) return x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	x -= 2;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    72
	for (n = 0, r = 2;; n++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
		if (x <= n) return r + x * n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
		r += n * n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
		x -= n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
2478
16b05f1de6bb (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
    79
static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table)
16b05f1de6bb (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
    80
{
16b05f1de6bb (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
    81
	const Bridge *bridge = &_bridge[index];
16b05f1de6bb (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
    82
	assert(table < 7);
16b05f1de6bb (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
    83
	if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) {
16b05f1de6bb (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
    84
		return _bridge_sprite_table[index][table];
16b05f1de6bb (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
    85
	} else {
16b05f1de6bb (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
    86
		return bridge->sprite_table[table];
16b05f1de6bb (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
    87
	}
16b05f1de6bb (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
    88
}
16b05f1de6bb (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
    89
3556
d25b35568c48 (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
    90
static inline byte GetBridgeFlags(int index) { return _bridge[index].flags;}
2262
bd59b2d8d75f (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
    91
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
4239
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
    93
/** Check the slope at the bridge ramps in three easy steps:
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
    94
 * - valid slopes without foundation
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
    95
 * - valid slopes with foundation
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
    96
 * - rest is invalid
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
    97
 */
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
    98
#define M(x) (1 << (x))
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
    99
static int32 CheckBridgeSlopeNorth(Axis axis, Slope tileh)
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   100
{
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   101
	uint32 valid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
4239
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   103
	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_NE) : M(SLOPE_NW));
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   104
	if (HASBIT(valid, tileh)) return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
4239
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   106
	valid =
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   107
		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) | M(SLOPE_STEEP_N) |
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   108
		(axis == AXIS_X ? M(SLOPE_E) | M(SLOPE_STEEP_E) : M(SLOPE_W) | M(SLOPE_STEEP_W));
4239
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   109
	if (HASBIT(valid, tileh)) return _price.terraform;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   110
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
4239
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   114
static int32 CheckBridgeSlopeSouth(Axis axis, Slope tileh)
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   115
{
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   116
	uint32 valid;
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   117
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   118
	valid = M(SLOPE_FLAT) | (axis == AXIS_X ? M(SLOPE_SW) : M(SLOPE_SE));
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   119
	if (HASBIT(valid, tileh)) return 0;
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   120
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   121
	valid =
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   122
		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) | M(SLOPE_STEEP_S) |
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   123
		(axis == AXIS_X ? M(SLOPE_W) | M(SLOPE_STEEP_W) : M(SLOPE_E) | M(SLOPE_STEEP_E));
4239
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   124
	if (HASBIT(valid, tileh)) return _price.terraform;
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   125
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   126
	return CMD_ERROR;
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   127
}
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   128
#undef M
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   129
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   130
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
uint32 GetBridgeLength(TileIndex begin, TileIndex end)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   133
	int x1 = TileX(begin);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   134
	int y1 = TileY(begin);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   135
	int x2 = TileX(end);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   136
	int y2 = TileY(end);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   137
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   138
	return abs(x2 + y2 - x1 - y1) - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   141
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
   142
{
2262
bd59b2d8d75f (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
   143
	const Bridge *b = &_bridge[bridge_type];
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   144
	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
   145
1781
92e08797c84b (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
   146
	if (bridge_type >= MAX_BRIDGES) return false;
2262
bd59b2d8d75f (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
   147
	if (b->avail_year > _cur_year) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
2262
bd59b2d8d75f (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
   149
	max = b->max_length;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   150
	if (max >= 16 && _patches.longbridges) max = 100;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   152
	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
   153
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
1775
08ff0f12ccdc (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
   155
/** Build a Bridge
3491
4c8427796c64 (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
   156
 * @param end_tile end tile
1775
08ff0f12ccdc (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
   157
 * @param p1 packed start tile coords (~ dx)
08ff0f12ccdc (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
   158
 * @param p2 various bitstuffed elements
08ff0f12ccdc (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
   159
 * - p2 = (bit 0- 7) - bridge type (hi bh)
08ff0f12ccdc (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
   160
 * - p2 = (bit 8-..) - rail type. bit15 ((x>>8)&0x80) means road bridge.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
 */
3491
4c8427796c64 (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
   162
int32 CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	int bridge_type;
3180
2123f8062a2d (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
   165
	TransportType transport;
2123f8062a2d (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
   166
	RailType railtype;
3853
c49992ab497b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   167
	uint x;
c49992ab497b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   168
	uint y;
c49992ab497b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   169
	uint sx;
c49992ab497b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   170
	uint sy;
3301
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   171
	TileIndex tile_start;
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   172
	TileIndex tile_end;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   173
	Slope tileh_start;
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   174
	Slope tileh_end;
3301
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   175
	uint z_start;
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   176
	uint z_end;
3178
c275826135da (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   177
	TileIndex tile;
c275826135da (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   178
	TileIndexDiff delta;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   179
	uint bridge_len;
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   180
	Axis direction;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	int32 cost, terraformcost, ret;
1585
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   182
	bool allow_on_slopes;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   185
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	/* unpack parameters */
2140
d708eb80ab8b (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
   187
	bridge_type = GB(p2, 0, 8);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   188
2934
3b7eef9871f8 (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
   189
	if (p1 >= MapSize()) return CMD_ERROR;
1775
08ff0f12ccdc (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
   190
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	// type of bridge
3180
2123f8062a2d (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
   192
	if (HASBIT(p2, 15)) {
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
   193
		railtype = RAILTYPE_BEGIN;
3180
2123f8062a2d (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
   194
		transport = TRANSPORT_ROAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
	} else {
3180
2123f8062a2d (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
   196
		if (!ValParamRailtype(GB(p2, 8, 8))) return CMD_ERROR;
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
   197
		railtype = (RailType)GB(p2, 8, 8);
3180
2123f8062a2d (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
   198
		transport = TRANSPORT_RAIL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   201
	x = TileX(end_tile);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   202
	y = TileY(end_tile);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   203
	sx = TileX(p1);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   204
	sy = TileY(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	/* 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
   207
	if (x == sx) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   208
		if (y == sy) return_cmd_error(STR_5008_CANNOT_START_AND_END_ON);
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   209
		direction = AXIS_Y;
3854
4821667ad368 (svn r4882) -Fix: Forgot a change in previous commit
celestar
parents: 3853
diff changeset
   210
		if (y > sy) uintswap(y,sy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	} else if (y == sy) {
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   212
		direction = AXIS_X;
3854
4821667ad368 (svn r4882) -Fix: Forgot a change in previous commit
celestar
parents: 3853
diff changeset
   213
		if (x > sx) uintswap(x,sx);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   214
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   216
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
1781
92e08797c84b (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
   218
	/* set and test bridge length, availability */
4000
bab1ebc37da0 (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
   219
	bridge_len = sx + sy - x - y - 1;
1781
92e08797c84b (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
   220
	if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
92e08797c84b (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
   221
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	/* retrieve landscape height and ensure it's on land */
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   223
	tile_start = TileXY(x, y);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   224
	tile_end = TileXY(sx, sy);
4000
bab1ebc37da0 (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
   225
	if (IsClearWaterTile(tile_start) || IsClearWaterTile(tile_end)) {
bab1ebc37da0 (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
   226
		return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
bab1ebc37da0 (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
   227
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
3301
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   229
	tileh_start = GetTileSlope(tile_start, &z_start);
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   230
	tileh_end = GetTileSlope(tile_end, &z_end);
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   231
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   232
	if (IsSteepSlope(tileh_start)) z_start += TILE_HEIGHT;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   233
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) {
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   234
		z_start += TILE_HEIGHT;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   235
		tileh_start = SLOPE_FLAT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   238
	if (IsSteepSlope(tileh_end)) z_end += TILE_HEIGHT;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   239
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) {
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   240
		z_end += TILE_HEIGHT;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   241
		tileh_end = SLOPE_FLAT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
3301
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   244
	if (z_start != z_end) return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED);
1585
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   245
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   246
	// Towns are not allowed to use bridges on slopes.
2422
914a12dee832 (svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents: 2314
diff changeset
   247
	allow_on_slopes = (!_is_old_ai_player
1781
92e08797c84b (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
   248
	                   && _current_player != OWNER_TOWN && _patches.build_on_slopes);
1585
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   249
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   250
	/* Try and clear the start landscape */
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   251
3491
4c8427796c64 (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
   252
	ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   253
	if (CmdFailed(ret)) return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	cost = ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
4239
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   256
	terraformcost = CheckBridgeSlopeNorth(direction, tileh_start);
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   257
	if (CmdFailed(terraformcost) || (terraformcost != 0 && !allow_on_slopes))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	cost += terraformcost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
1585
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   261
	/* Try and clear the end landscape */
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   262
3491
4c8427796c64 (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
   263
	ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   264
	if (CmdFailed(ret)) return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	cost += ret;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   266
1585
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   267
	// false - end tile slope check
4239
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   268
	terraformcost = CheckBridgeSlopeSouth(direction, tileh_end);
9ec74a9b8b58 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   269
	if (CmdFailed(terraformcost) || (terraformcost != 0 && !allow_on_slopes))
1585
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   270
		return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
3dc279e97623 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   271
	cost += terraformcost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   273
	{
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   274
		TileIndex Heads[] = {tile_start, tile_end};
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   275
		int i;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   276
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   277
		for (i = 0; i < 2; i++) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   278
			if (MayHaveBridgeAbove(Heads[i])) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   279
				if (IsBridgeAbove(Heads[i])) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   280
					TileIndex north_head = GetNorthernBridgeEnd(Heads[i]);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   281
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   282
					if (direction == GetBridgeAxis(Heads[i])) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   283
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   284
					if (z_start + TILE_HEIGHT == GetBridgeHeight(north_head)) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   285
						return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   286
					}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   287
				}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   288
			}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   289
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   290
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
	/* do the drill? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
	if (flags & DC_EXEC) {
3209
e0b7d48351a3 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   294
		DiagDirection dir = AxisToDiagDir(direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
3209
e0b7d48351a3 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   296
		if (transport == TRANSPORT_RAIL) {
3301
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   297
			MakeRailBridgeRamp(tile_start, _current_player, bridge_type, dir, railtype);
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   298
			MakeRailBridgeRamp(tile_end,   _current_player, bridge_type, ReverseDiagDir(dir), railtype);
3209
e0b7d48351a3 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   299
		} else {
3301
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   300
			MakeRoadBridgeRamp(tile_start, _current_player, bridge_type, dir);
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   301
			MakeRoadBridgeRamp(tile_end,   _current_player, bridge_type, ReverseDiagDir(dir));
3209
e0b7d48351a3 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   302
		}
3301
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   303
		MarkTileDirtyByTile(tile_start);
4ac662c79ad3 (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   304
		MarkTileDirtyByTile(tile_end);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
3178
c275826135da (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   307
	delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   308
	for (tile = tile_start + delta; tile != tile_end; tile += delta) {
3178
c275826135da (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   309
		uint z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   311
		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
   312
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   313
		if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   314
			/* Disallow crossing bridges for the time being */
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   315
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   316
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
3178
c275826135da (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   318
		switch (GetTileType(tile)) {
3065
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   319
			case MP_WATER:
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   320
				if (!EnsureNoVehicle(tile)) return_cmd_error(STR_980E_SHIP_IN_THE_WAY);
4000
bab1ebc37da0 (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
   321
				if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below;
3065
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   322
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
3065
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   324
			case MP_RAILWAY:
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   325
				if (!IsPlainRailTile(tile)) goto not_valid_below;
3065
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   326
				break;
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   327
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   328
			case MP_STREET:
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   329
				if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) goto not_valid_below;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   330
				break;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   331
5590
dc34c43fc3eb (svn r7597) [cbh] - Codechange: Remove MP_TUNNELBRIDGE and introduce three new TileTypes: MP_TUNNEL, MP_STREET_BRIDGE, MP_RAILWAY_BRIDGE
celestar
parents: 5573
diff changeset
   332
			case MP_TUNNEL:
dc34c43fc3eb (svn r7597) [cbh] - Codechange: Remove MP_TUNNELBRIDGE and introduce three new TileTypes: MP_TUNNEL, MP_STREET_BRIDGE, MP_RAILWAY_BRIDGE
celestar
parents: 5573
diff changeset
   333
				break;
dc34c43fc3eb (svn r7597) [cbh] - Codechange: Remove MP_TUNNELBRIDGE and introduce three new TileTypes: MP_TUNNEL, MP_STREET_BRIDGE, MP_RAILWAY_BRIDGE
celestar
parents: 5573
diff changeset
   334
dc34c43fc3eb (svn r7597) [cbh] - Codechange: Remove MP_TUNNELBRIDGE and introduce three new TileTypes: MP_TUNNEL, MP_STREET_BRIDGE, MP_RAILWAY_BRIDGE
celestar
parents: 5573
diff changeset
   335
			case MP_STREET_BRIDGE:
dc34c43fc3eb (svn r7597) [cbh] - Codechange: Remove MP_TUNNELBRIDGE and introduce three new TileTypes: MP_TUNNEL, MP_STREET_BRIDGE, MP_RAILWAY_BRIDGE
celestar
parents: 5573
diff changeset
   336
			case MP_RAILWAY_BRIDGE:
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   337
				if (direction == DiagDirToAxis(GetBridgeRampDirection(tile))) goto not_valid_below;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   338
				if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   339
				break;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   340
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   341
			case MP_UNMOVABLE:
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   342
				if (!IsOwnedLand(tile)) goto not_valid_below;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   343
				break;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   344
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   345
			case MP_CLEAR:
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   346
				if (IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3065
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   347
				break;
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   348
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   349
			default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
not_valid_below:;
3065
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   351
				/* try and clear the middle landscape */
3491
4c8427796c64 (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
   352
				ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   353
				if (CmdFailed(ret)) return ret;
3065
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   354
				cost += ret;
2bce72c02f63 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   355
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
		if (flags & DC_EXEC) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   359
			SetBridgeMiddle(tile, direction);
3178
c275826135da (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   360
			MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
5648
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   364
	if (flags & DC_EXEC) {
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   365
		Track track = AxisToTrack(direction);
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   366
		SetSignalsOnBothDir(tile_start, track);
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   367
		YapfNotifyTrackLayoutChange(tile_start, track);
1608018c5ff2 (svn r8059) [cbh] - Sync with r7788:8032 from trunk
celestar
parents: 5643
diff changeset
   368
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   370
	/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   371
	 * It's unnecessary to execute this command every time for every bridge. So it is done only
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   372
	 * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   373
	 */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   374
	if (!(flags & DC_QUERY_COST)) {
2262
bd59b2d8d75f (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
   375
		const Bridge *b = &_bridge[bridge_type];
bd59b2d8d75f (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
   376
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   377
		bridge_len += 2; // begin and end tiles/ramps
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
4850
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   379
		if (IsValidPlayer(_current_player) && !_is_old_ai_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
			bridge_len = CalcBridgeLenCostFactor(bridge_len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3017
diff changeset
   382
		cost += (int64)bridge_len * _price.build_bridge * b->price >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
5595
049ed4486972 (svn r7613) [cbh] - Codechange: Removed tunnel-specific functions from bridge_cmd.c and bridge-specific functions from tunnel_cmd.c
celestar
parents: 5594
diff changeset
   389
static inline bool CheckAllowRemoveBridge(TileIndex tile)
5009
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   390
{
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   391
	/* Floods can remove anything as well as the scenario editor */
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   392
	if (_current_player == OWNER_WATER || _game_mode == GM_EDITOR) return true;
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   393
	/* Obviously if the bridge/tunnel belongs to us, or no-one, we can remove it */
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   394
	if (CheckTileOwnership(tile) || IsTileOwner(tile, OWNER_NONE)) return true;
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   395
	/* Otherwise we can only remove town-owned stuff with extra patch-settings, or cheat */
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   396
	if (IsTileOwner(tile, OWNER_TOWN) && (_patches.extra_dynamite || _cheats.magic_bulldozer.value)) return true;
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   397
	return false;
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   398
}
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   399
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   400
static bool IsVehicleOnBridge(TileIndex starttile, TileIndex endtile, uint z)
3779
86bbf020ec2c (svn r4771) -Regression: It was possible to remove a bridge while a vehicle was on it
tron
parents: 3774
diff changeset
   401
{
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   402
	const Vehicle *v;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   403
	FOR_ALL_VEHICLES(v) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   404
		if ((v->tile == starttile || v->tile == endtile) && v->z_pos == z) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   405
			_error_message = VehicleInTheWayErrMsg(v);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   406
			return true;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   407
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   408
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   409
	return false;
3779
86bbf020ec2c (svn r4771) -Regression: It was possible to remove a bridge while a vehicle was on it
tron
parents: 3774
diff changeset
   410
}
86bbf020ec2c (svn r4771) -Regression: It was possible to remove a bridge while a vehicle was on it
tron
parents: 3774
diff changeset
   411
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   412
static int32 DoClearBridge(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
{
3227
8bb33a2299a5 (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
   414
	DiagDirection direction;
8bb33a2299a5 (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
   415
	TileIndexDiff delta;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   416
	TileIndex endtile;
5009
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   417
	Town *t = NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   418
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
5595
049ed4486972 (svn r7613) [cbh] - Codechange: Removed tunnel-specific functions from bridge_cmd.c and bridge-specific functions from tunnel_cmd.c
celestar
parents: 5594
diff changeset
   421
	if (!CheckAllowRemoveBridge(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
3228
270ab760cc16 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   423
	endtile = GetOtherBridgeEnd(tile);
270ab760cc16 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   424
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   425
	if (!EnsureNoVehicle(tile) ||
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   426
			!EnsureNoVehicle(endtile) ||
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   427
			IsVehicleOnBridge(tile, endtile, GetBridgeHeight(tile))) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   428
		return CMD_ERROR;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   429
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
3227
8bb33a2299a5 (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
   431
	direction = GetBridgeRampDirection(tile);
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   432
	delta = TileOffsByDiagDir(direction);
3227
8bb33a2299a5 (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
   433
1901
fb05044cf5c3 (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
   434
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
5009
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   435
		t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   436
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   437
		/* Check if you are allowed to remove the bridge owned by a town
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   438
		 * Removal depends on difficulty settings */
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   439
		if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) {
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   440
			SetDParam(0, t->index);
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   441
			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
437645a303b4 (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   442
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	}
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
	if (flags & DC_EXEC) {
3217
60f832048cd4 (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   446
		TileIndex c;
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   447
		Track track;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 959
diff changeset
   449
		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
		// you have a "Poor" (0) town rating
1901
fb05044cf5c3 (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
   451
		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
1005
8c6a9bf44bf1 (svn r1504) enummed town ratings (Jango)
celestar
parents: 959
diff changeset
   452
			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
   453
3217
60f832048cd4 (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   454
		DoClearSquare(tile);
60f832048cd4 (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   455
		DoClearSquare(endtile);
60f832048cd4 (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   456
		for (c = tile + delta; c != endtile; c += delta) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   457
				ClearBridgeMiddle(c);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   458
			MarkTileDirtyByTile(c);
3217
60f832048cd4 (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   459
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
3227
8bb33a2299a5 (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
   461
		UpdateSignalsOnSegment(tile, ReverseDiagDir(direction));
8bb33a2299a5 (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
   462
		UpdateSignalsOnSegment(endtile, direction);
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   463
		track = AxisToTrack(DiagDirToAxis(direction));
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   464
		YapfNotifyTrackLayoutChange(tile, track);
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   465
		YapfNotifyTrackLayoutChange(endtile, track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
3227
8bb33a2299a5 (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
   468
	return (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   471
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   472
static int32 ClearTile_Bridge(TileIndex tile, byte flags)
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   473
{
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   474
	assert(IsBridgeTile(tile));
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   475
	if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   476
	return DoClearBridge(tile, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
5595
049ed4486972 (svn r7613) [cbh] - Codechange: Removed tunnel-specific functions from bridge_cmd.c and bridge-specific functions from tunnel_cmd.c
celestar
parents: 5594
diff changeset
   479
int32 DoConvertBridgeRail(TileIndex tile, RailType totype, bool exec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
{
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   481
	TileIndex endtile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
5595
049ed4486972 (svn r7613) [cbh] - Codechange: Removed tunnel-specific functions from bridge_cmd.c and bridge-specific functions from tunnel_cmd.c
celestar
parents: 5594
diff changeset
   483
	if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
		if (!CheckTileOwnership(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
3215
56c250955b3b (svn r3888) If you think you've checked everything, check once more. *sigh* Fix r3887
tron
parents: 3214
diff changeset
   486
		endtile = GetOtherBridgeEnd(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
4172
5ca428e46357 (svn r5610) Remove a pointless call to VehicleInTheWayErrMsg() - only trains can be on rail bridges
tron
parents: 4160
diff changeset
   488
		if (!EnsureNoVehicle(tile) ||
5ca428e46357 (svn r5610) Remove a pointless call to VehicleInTheWayErrMsg() - only trains can be on rail bridges
tron
parents: 4160
diff changeset
   489
				!EnsureNoVehicle(endtile) ||
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   490
				IsVehicleOnBridge(tile, endtile, GetBridgeHeight(tile))) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   491
			return CMD_ERROR;
1073
0e844583b549 (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   492
		}
0e844583b549 (svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents: 1067
diff changeset
   493
3242
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   494
		if (GetRailType(tile) == totype) return CMD_ERROR;
3213
8e56434d36d5 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   495
3218
68decfba698f (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   496
		if (exec) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   497
			TileIndexDiff delta;
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   498
			Track track;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   499
3242
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   500
			SetRailType(tile, totype);
1cefa03f0d5e (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   501
			SetRailType(endtile, totype);
3218
68decfba698f (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   502
			MarkTileDirtyByTile(tile);
68decfba698f (svn r3891) Fix r3885
tron
parents: 3217
diff changeset
   503
			MarkTileDirtyByTile(endtile);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3881
diff changeset
   504
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   505
			track = AxisToTrack(DiagDirToAxis(GetBridgeRampDirection(tile)));
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   506
			YapfNotifyTrackLayoutChange(tile, track);
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4156
diff changeset
   507
			YapfNotifyTrackLayoutChange(endtile, track);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   508
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   509
			delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   510
			for (tile += delta; tile != endtile; tile += delta) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   511
				MarkTileDirtyByTile(tile); // TODO encapsulate this into a function
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
			}
3213
8e56434d36d5 (svn r3885) Simplify DoConvertTunnelBridgeRail() a bit
tron
parents: 3209
diff changeset
   513
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   515
		return (DistanceManhattan(tile, endtile) + 1) * (_price.build_rail >> 1);
4000
bab1ebc37da0 (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
   516
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
		return CMD_ERROR;
4000
bab1ebc37da0 (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
   518
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   522
static void DrawBridgePillars(PalSpriteID image, 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
   523
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
	if (image != 0) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   525
		bool drawfarpillar = !HASBIT(GetBridgeFlags(type), 0);
3556
d25b35568c48 (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
   526
		int back_height, front_height;
d25b35568c48 (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
   527
		int i = z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
		const byte *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
		static const byte _tileh_bits[4][8] = {
4191
25538ade07c2 (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   531
			{ 2, 1, 8, 4,  16,  2, 0, 9 },
25538ade07c2 (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   532
			{ 1, 8, 4, 2,   2, 16, 9, 0 },
25538ade07c2 (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   533
			{ 4, 8, 1, 2,  16,  2, 0, 9 },
25538ade07c2 (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   534
			{ 2, 4, 8, 1,   2, 16, 9, 0 }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
		};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
2148
47ba4a1b1c3b (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
   537
		if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
333
6dee54ed9701 (svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents: 241
diff changeset
   538
3234
986c30171e92 (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
   539
		p = _tileh_bits[(image & 1) * 2 + (axis == AXIS_X ? 0 : 1)];
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   540
		front_height = ti->z + (ti->tileh & p[0] ? TILE_HEIGHT : 0);
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   541
		back_height  = ti->z + (ti->tileh & p[1] ? TILE_HEIGHT : 0);
2262
bd59b2d8d75f (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
   542
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   543
		if (IsSteepSlope(ti->tileh)) {
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   544
			if (!(ti->tileh & p[2])) front_height += TILE_HEIGHT;
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   545
			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
   546
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   548
		for (; z >= front_height || z >= back_height; z -= TILE_HEIGHT) {
4191
25538ade07c2 (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   549
			/* HACK set height of the BB of pillars to 1, because the origin of the
25538ade07c2 (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   550
			 * sprites is at the top
25538ade07c2 (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   551
			 */
3556
d25b35568c48 (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
   552
			if (z >= front_height) { // front facing pillar
4191
25538ade07c2 (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   553
				AddSortableSpriteToDraw(image, x, y, p[4], p[5], 1, z);
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   554
			}
3556
d25b35568c48 (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
   555
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   556
			if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar
4191
25538ade07c2 (svn r5641) -Fix: Adjust/correct some bounding boxes. This fixes some graphical glitches near bridges
tron
parents: 4173
diff changeset
   557
				AddSortableSpriteToDraw(image, x - p[6], y - p[7], p[4], p[5], 1, z);
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   558
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   563
uint GetBridgeFoundation(Slope tileh, Axis axis)
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   564
{
3878
91a8b87f641e (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   565
	uint i;
91a8b87f641e (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   566
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   567
	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
   568
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
	// inclined sloped building
3878
91a8b87f641e (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   570
	switch (tileh) {
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   571
		case SLOPE_W:
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   572
		case SLOPE_STEEP_W: i = 0; break;
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   573
		case SLOPE_S:
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   574
		case SLOPE_STEEP_S: i = 2; break;
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   575
		case SLOPE_E:
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   576
		case SLOPE_STEEP_E: i = 4; break;
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   577
		case SLOPE_N:
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   578
		case SLOPE_STEEP_N: i = 6; break;
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
   579
		default: return 0;
3017
915fae59d5e0 (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
   580
	}
3878
91a8b87f641e (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   581
	if (axis != AXIS_X) ++i;
91a8b87f641e (svn r4927) Replace 3 big ifs (which regard foundations) by a bit less confusing code
tron
parents: 3854
diff changeset
   582
	return i + 15;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   585
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   586
/**
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   587
 * Draws a bridge tile.
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   588
 * base_offset is where the sprite selection comes into play
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   589
 * and it works a bit like a bitmask.<p> For bridge heads:
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   590
 * <ul><li>Bit 0: direction</li>
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   591
 * <li>Bit 1: northern or southern heads</li>
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   592
 * <li>Bit 2: Set if the bridge head is sloped</li>
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   593
 * <li>Bit 3 and more: Railtype Specific subset</li>
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   594
 * </ul>
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   595
 * Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   596
 */
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   597
static void DrawTile_Bridge(TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
	uint32 image;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   600
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   601
	int base_offset;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   602
	bool ice = HasBridgeSnowOrDesert(ti->tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   604
	if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
5599
a18b0c2587f7 (svn r7644) [cbh] - Codechange: For custombridgeheads (those that have more than just one straight piece of track) use a foundation and the normal track drawing code
celestar
parents: 5598
diff changeset
   605
		if (GetTrackBits(ti->tile) != TRACK_BIT_X && GetTrackBits(ti->tile) != TRACK_BIT_Y) {
a18b0c2587f7 (svn r7644) [cbh] - Codechange: For custombridgeheads (those that have more than just one straight piece of track) use a foundation and the normal track drawing code
celestar
parents: 5598
diff changeset
   606
			DrawTile_Track(ti);
a18b0c2587f7 (svn r7644) [cbh] - Codechange: For custombridgeheads (those that have more than just one straight piece of track) use a foundation and the normal track drawing code
celestar
parents: 5598
diff changeset
   607
			return;
a18b0c2587f7 (svn r7644) [cbh] - Codechange: For custombridgeheads (those that have more than just one straight piece of track) use a foundation and the normal track drawing code
celestar
parents: 5598
diff changeset
   608
		}
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   609
		base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   610
		assert(base_offset != 8); /* This one is used for roads */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   611
	} else {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   612
		base_offset = 8;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   613
	}
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   614
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   615
	/* as the lower 3 bits are used for other stuff, make sure they are clear */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   616
	assert( (base_offset & 0x07) == 0x00);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   617
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   618
	if (!HASBIT(BRIDGE_NO_FOUNDATION, ti->tileh)) {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   619
		int f = GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetBridgeRampDirection(ti->tile)));
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   620
		if (f != 0) DrawFoundation(ti, f);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   621
	}
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   622
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   623
	// HACK Wizardry to convert the bridge ramp direction into a sprite offset
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   624
	base_offset += (6 - GetBridgeRampDirection(ti->tile)) % 4;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   625
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   626
	if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   627
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   628
	/* Table number 6 always refers to the bridge heads for any bridge type */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   629
	image = GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset];
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   630
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   631
	if (!ice) {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   632
		DrawClearLandTile(ti, 3);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   633
	} else {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   634
		DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh]);
3933
a5f08e17f4a0 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
   635
	}
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   636
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   637
	if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   638
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   639
	// draw ramp
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   640
	if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   641
	/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   642
	 * it doesn't disappear behind it
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   643
	 */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   644
	AddSortableSpriteToDraw(
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   645
		image, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 1 : 8, ti->z
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   646
	);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   647
5633
c61d481dbd0b (svn r7740) [cbh] - Fix: Do not try to draw signals on road bridge heads because .. it won't work
celestar
parents: 5632
diff changeset
   648
	if (IsTileType(ti->tile, MP_RAILWAY_BRIDGE) && HasSignals(ti->tile)) DrawSignals(ti->tile, GetTrackBits(ti->tile));
5632
025c3b25f1fd (svn r7739) [cbh] - Feature: Allow the construction and removal of signals on bridge heads. Warning: the signals are only displayed, they do not work yet
celestar
parents: 5628
diff changeset
   649
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   650
	DrawBridgeMiddle(ti);
3933
a5f08e17f4a0 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
   651
}
a5f08e17f4a0 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
   652
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   653
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   654
/** Compute bridge piece. Computes the bridge piece to display depending on the position inside the bridge.
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   655
 * bridges pieces sequence (middle parts)
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   656
 * bridge len 1: 0
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   657
 * bridge len 2: 0 1
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   658
 * bridge len 3: 0 4 1
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   659
 * bridge len 4: 0 2 3 1
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   660
 * bridge len 5: 0 2 5 3 1
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   661
 * bridge len 6: 0 2 3 2 3 1
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   662
 * bridge len 7: 0 2 3 4 2 3 1
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   663
 * #0 - always as first, #1 - always as last (if len>1)
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   664
 * #2,#3 are to pair in order
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   665
 * for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0)
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   666
 * @param north Northernmost tile of bridge
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   667
 * @param south Southernmost tile of bridge
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   668
 * @return Index of bridge piece
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   669
 */
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   670
static uint CalcBridgePiece(uint north, uint south)
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   671
{
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   672
	if (north == 1) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   673
		return 0;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   674
	} else if (south == 1) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   675
		return 1;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   676
	} else if (north < south) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   677
		return north & 1 ? 3 : 2;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   678
	} else if (north > south) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   679
		return south & 1 ? 2 : 3;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   680
	} else {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   681
		return north & 1 ? 5 : 4;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   682
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   683
}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   684
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   685
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   686
void DrawBridgeMiddle(const TileInfo* ti)
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   687
{
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   688
	const PalSpriteID* b;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   689
	PalSpriteID image;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   690
	uint base_offset;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   691
	TileIndex rampnorth;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   692
	TileIndex rampsouth;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   693
	Axis axis;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   694
	uint piece;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   695
	uint type;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   696
	int x;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   697
	int y;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   698
	uint z;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   699
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   700
	if (!IsBridgeAbove(ti->tile)) return;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   701
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   702
	rampnorth = GetNorthernBridgeEnd(ti->tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   703
	rampsouth = GetSouthernBridgeEnd(ti->tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   704
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   705
	axis = GetBridgeAxis(ti->tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   706
	piece = CalcBridgePiece(
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   707
		DistanceManhattan(ti->tile, rampnorth),
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   708
		DistanceManhattan(ti->tile, rampsouth)
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   709
	);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   710
	type = GetBridgeType(rampsouth);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   711
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   712
	if (GetBridgeTransportType(rampsouth) == TRANSPORT_RAIL) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   713
		base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   714
	} else {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   715
		base_offset = 8;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   716
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   717
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   718
	b = base_offset + GetBridgeSpriteTable(type, piece);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   719
	if (axis != AXIS_X) b += 4;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   720
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   721
	x = ti->x;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   722
	y = ti->y;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   723
	z = GetBridgeHeight(rampsouth) - 3;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   724
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   725
	image = b[0];
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   726
	if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   727
	if (axis == AXIS_X) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   728
		AddSortableSpriteToDraw(image, x, y, 16, 11, 1, z);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   729
	} else {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   730
		AddSortableSpriteToDraw(image, x, y, 11, 16, 1, z);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   731
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   732
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   733
	image = b[1];
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   734
	if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   735
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   736
	// draw roof, the component of the bridge which is logically between the vehicle and the camera
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   737
	if (axis == AXIS_X) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   738
		y += 12;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   739
		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 16, 1, 0x28, z);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   740
	} else {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   741
		x += 12;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   742
		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 1, 16, 0x28, z);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   743
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   744
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   745
	if (GetRailType(rampsouth) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   746
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   747
	if (ti->z + 5 == z) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   748
		// draw poles below for small bridges
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   749
		image = b[2];
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   750
		if (image != 0) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   751
			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   752
			DrawGroundSpriteAt(image, x, y, z);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   753
		}
afa6f92a71fd (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 (_patches.bridge_pillars) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   755
		// draw pillars below for high bridges
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   756
		DrawBridgePillars(b[2], ti, axis, type, x, y, z);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   757
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   758
}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   759
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   760
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   761
uint SetSpeedLimitOnBridge(Vehicle *v)
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   762
{
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   763
	uint bridge_speed;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   764
	if (v->vehstatus & VS_HIDDEN) return v->max_speed; /* in tunnel */
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   765
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   766
	bridge_speed = _bridge[GetBridgeType(v->tile)].speed;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   767
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   768
	if (v->type == VEH_Road) bridge_speed *= 2; /* XXX give vehicles proper speeds */
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   769
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   770
	if (v->cur_speed > bridge_speed) v->cur_speed = bridge_speed;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   771
	return bridge_speed;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   772
}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   773
5606
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   774
static bool IsCustomBridgeHead(TileIndex tile)
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   775
{
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   776
	assert(IsBridgeTile(tile));
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   777
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   778
	if (IsTileType(tile, MP_RAILWAY_BRIDGE)) {
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   779
		return !(GetTrackBits(tile) == TRACK_BIT_X || GetTrackBits(tile) == TRACK_BIT_Y);
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   780
	}
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   781
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   782
	return false; /* TODO - street bridges */
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   783
}
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   784
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   785
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   786
/** Gets the absolute z coordinate of a point inside a bridge tile
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   787
 *  When we're on the track (that means between position 5 and 10)
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   788
 *  on the coordinate perpendicular to the track it returns the base
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   789
 *  height of the ramp
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   790
 *  Outside this range (from 0 to 4 and from 11 to 15) it returns the
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   791
 *  "true" Z coordinate of the tile by taking the slope into account
5606
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   792
 *  For custom bridge heads the entire bridge head is flat and has the
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   793
 *  same z coordinate
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   794
 *  @param tile The index of the tile we are talking about
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   795
 *  @param x Absolute or relative x coordinate
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   796
 *  @param y Absolute or relative y coordinate
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   797
 *  @return Absolute z coordinate
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   798
 */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   799
static uint GetSlopeZ_Bridge(TileIndex tile, uint x, uint y)
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   800
{
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   801
	uint z, pos;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   802
	Slope tileh = GetTileSlope(tile, &z);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   803
	DiagDirection dir = GetBridgeRampDirection(tile);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   804
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   805
	x &= 0xF;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   806
	y &= 0xF;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   807
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   808
	pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   809
5606
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
   810
	// On the bridge ramp or flat bridge head?
5632
025c3b25f1fd (svn r7739) [cbh] - Feature: Allow the construction and removal of signals on bridge heads. Warning: the signals are only displayed, they do not work yet
celestar
parents: 5628
diff changeset
   811
	if ( (2 <= pos && pos <= 13) || IsCustomBridgeHead(tile)) {
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   812
		uint delta;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   813
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   814
		if (IsSteepSlope(tileh)) return z + TILE_HEIGHT * 2;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   815
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   816
		if (HASBIT(BRIDGE_HORZ_RAMP, tileh)) return z + TILE_HEIGHT;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   817
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   818
		if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) z += TILE_HEIGHT;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   819
		switch (dir) {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   820
			default: NOT_REACHED();
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   821
			case DIAGDIR_NE: delta = (TILE_SIZE - 1 - x) / 2; break;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   822
			case DIAGDIR_SE: delta = y / 2; break;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   823
			case DIAGDIR_SW: delta = x / 2; break;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   824
			case DIAGDIR_NW: delta = (TILE_SIZE - 1 - y) / 2; break;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   825
		}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   826
		return z + 1 + delta;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   827
	} else {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   828
		uint f = GetBridgeFoundation(tileh, DiagDirToAxis(dir));
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   829
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   830
		if (f != 0) {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   831
			if (IsSteepSlope(tileh)) {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   832
				z += TILE_HEIGHT;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   833
			} else if (f < 15) {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   834
				return z + TILE_HEIGHT;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   835
			}
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
   836
			tileh = (Slope)_inclined_tileh[f - 15];
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   837
		}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   838
	}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   839
	return z + GetPartialZ(x, y, tileh);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   840
}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   841
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   842
static Slope GetSlopeTileh_Bridge(TileIndex tile, Slope tileh)
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   843
{
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   844
	if (HASBIT(BRIDGE_NO_FOUNDATION, tileh)) {
4062
e4a3faed6fe4 (svn r5352) -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitches
tron
parents: 4046
diff changeset
   845
		return tileh;
e4a3faed6fe4 (svn r5352) -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitches
tron
parents: 4046
diff changeset
   846
	} else {
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   847
		uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   848
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   849
		if (f == 0) return tileh;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   850
		if (f < 15) return SLOPE_FLAT;
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
   851
		return (Slope)_inclined_tileh[f - 15];
4062
e4a3faed6fe4 (svn r5352) -Fix: Return accurate slope information for tunnels and bridges to fix several foundation graphics glitches
tron
parents: 4046
diff changeset
   852
	}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
   853
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
   854
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   855
static void GetAcceptedCargo_Bridge(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
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
   861
	STR_501F_WOODEN_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	STR_5020_CONCRETE_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	STR_501C_STEEL_GIRDER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
	STR_501E_REINFORCED_CONCRETE_SUSPENSION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
	STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
	STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
	STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
	STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
	STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	STR_501C_STEEL_GIRDER_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
	STR_5027_TUBULAR_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
	STR_5027_TUBULAR_RAIL_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
	STR_5027_TUBULAR_RAIL_BRIDGE,
4344
5d0e40cd67b9 (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
   874
	0, 0, 0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	STR_5025_WOODEN_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	STR_5026_CONCRETE_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
	STR_5022_STEEL_GIRDER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	STR_5024_REINFORCED_CONCRETE_SUSPENSION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
	STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
	STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
	STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
	STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
	STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
	STR_5022_STEEL_GIRDER_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
	STR_5028_TUBULAR_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	STR_5028_TUBULAR_ROAD_BRIDGE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
	STR_5028_TUBULAR_ROAD_BRIDGE,
4344
5d0e40cd67b9 (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
   889
	0, 0, 0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   892
static void GetTileDesc_Bridge(TileIndex tile, TileDesc *td)
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   893
{
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   894
	td->str = _bridge_tile_str[GetBridgeTransportType(tile) << 4 | GetBridgeType(tile)];
1901
fb05044cf5c3 (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
   895
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   899
static void AnimateTile_Bridge(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
{
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   901
	/* not used */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   902
}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   903
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   905
static void TileLoop_Bridge(TileIndex tile)
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   906
{
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   907
	bool snow_or_desert = HasBridgeSnowOrDesert(tile);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   908
	switch (_opt.landscape) {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   909
		case LT_HILLY:
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   910
			if (snow_or_desert != (GetTileZ(tile) > _opt.snow_line)) {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   911
				SetBridgeSnowOrDesert(tile, !snow_or_desert);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   912
				MarkTileDirtyByTile(tile);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   913
			}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   914
			break;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   915
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   916
		case LT_DESERT:
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   917
			if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) {
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   918
				SetBridgeSnowOrDesert(tile, true);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   919
				MarkTileDirtyByTile(tile);
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   920
			}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   921
			break;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   922
	}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   923
}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   924
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   925
static void ClickTile_Bridge(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   931
static uint32 GetTileTrackStatus_Bridge(TileIndex tile, TransportType mode)
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   932
{
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   933
	if (GetBridgeTransportType(tile) != mode) return 0;
5598
166345600ba9 (svn r7643) [cbh] - Codechange: Railway bridges now store track bits just like normal rail tiles. For railway bridges, GetTileTrackStatus_Bridge just calls GetTileTrackStatus_Track
celestar
parents: 5595
diff changeset
   934
166345600ba9 (svn r7643) [cbh] - Codechange: Railway bridges now store track bits just like normal rail tiles. For railway bridges, GetTileTrackStatus_Bridge just calls GetTileTrackStatus_Track
celestar
parents: 5595
diff changeset
   935
	if (IsTileType(tile, MP_RAILWAY_BRIDGE)) return GetTileTrackStatus_Track(tile, mode);
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   936
	return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(tile))) * 0x101;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   937
}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   938
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   940
static void ChangeTileOwner_Bridge(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
{
1901
fb05044cf5c3 (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
   942
	if (!IsTileOwner(tile, old_player)) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   943
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4656
diff changeset
   944
	if (new_player != PLAYER_SPECTATOR) {
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
   945
		SetTileOwner(tile, new_player);
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   946
	} else {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   947
		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
5608
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   952
static uint32 VehicleEnter_Street_Bridge(Vehicle *v, TileIndex tile, int x, int y)
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   953
{
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   954
	int z = GetSlopeZ(x, y) - v->z_pos;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   955
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   956
	DiagDirection dir;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   957
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   958
	if (myabs(z) > 2) return 8;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   959
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   960
	if (v->type == VEH_Road) {
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   961
		/* modify speed of vehicle */
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   962
		uint16 spd = _bridge[GetBridgeType(tile)].speed * 2;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   963
		if (v->cur_speed > spd) v->cur_speed = spd;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   964
	}
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   965
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   966
	dir = GetBridgeRampDirection(tile);
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   967
	if (DirToDiagDir(v->direction) == dir) {
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   968
		switch (dir) {
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   969
			default: NOT_REACHED();
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   970
			case DIAGDIR_NE: if ((x & 0xF) != 0)             return 0; break;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   971
			case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   972
			case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   973
			case DIAGDIR_NW: if ((y & 0xF) != 0)             return 0; break;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   974
		}
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   975
		v->u.road.state = 0xFF;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   976
		return 4;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   977
	} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   978
		v->tile = tile;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   979
		if (v->u.road.state == 0xFF) {
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   980
			static const byte road_exit_bridge_state[4] = {8, 9, 0, 1};
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   981
			v->u.road.state = road_exit_bridge_state[dir];
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   982
			v->u.road.frame = 0;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   983
			return 4;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   984
		}
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   985
		return 0;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   986
	}
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   987
	return 0;
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   988
}
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
   989
5622
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
   990
/**
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
   991
  * @retval 0 The vehicle can proceed
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
   992
  * @retval 4 The vehicle changed onto of off the bridge (depending on the
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
   993
  *           status before, check with v->u.rail.track == 0x40)
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
   994
  * @retval 8 The vehicle cannot enter the tile
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
   995
  */
5613
8b68de175f44 (svn r7702) [cbh] - Moved around some functions and changes from r7687 abd 7697
celestar
parents: 5612
diff changeset
   996
static uint32 VehicleEnter_Railway_Bridge(Vehicle *v, TileIndex tile, int x, int y)
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   997
{
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   998
	int z = GetSlopeZ(x, y) - v->z_pos;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
   999
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1000
	DiagDirection dir;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1001
5606
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
  1002
	if (IsCustomBridgeHead(tile)) {
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
  1003
		uint h;
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
  1004
		GetTileSlope(tile, &h);
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
  1005
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
  1006
		z = h + TILE_HEIGHT - v->z_pos;
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
  1007
	}
a8e391b7b10a (svn r7651) [cbh] - Fix: Allow trains to enter bridge head tiles from "the side"
celestar
parents: 5601
diff changeset
  1008
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1009
	if (myabs(z) > 2) return 8;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1010
5608
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
  1011
	if (IsFrontEngine(v)) {
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1012
		/* modify speed of vehicle */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1013
		uint16 spd = _bridge[GetBridgeType(tile)].speed;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1014
		if (v->cur_speed > spd) v->cur_speed = spd;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1015
	}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1016
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1017
	dir = GetBridgeRampDirection(tile);
5622
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1018
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1019
	if (v->direction == DiagDirToDir(ReverseDiagDir(dir))) {
5624
7901de192beb (svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
KUDr
parents: 5622
diff changeset
  1020
		/* We are entering the bridge head from the bridge itself */
5651
335d9bd345b0 (svn r9109) [cbh] -Fix: Stabilize the reversing of trains on bridges/bridgeheads a little (it still crashes at times however). Also re-allow the construction of signals on bridgeheads
celestar
parents: 5650
diff changeset
  1021
		if (v->u.rail.track == TRACK_BIT_WORMHOLE && (tile == TileVirtXY(v->x_pos, v->y_pos))) {
5622
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1022
			/* Get the vehicle out of the wormhole, the track will be chosen later
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1023
			   by the pathfinder */
5624
7901de192beb (svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
KUDr
parents: 5622
diff changeset
  1024
			v->tile = tile;
5628
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1025
			v->u.rail.track = TrackToTrackBits(TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
5622
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1026
			return 4;
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1027
		}
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1028
		return 0;
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1029
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1030
	} else {
5628
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1031
		TileIndex other_bridge_end_tile;
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1032
		uint32 bridge_length;
5624
7901de192beb (svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
KUDr
parents: 5622
diff changeset
  1033
		/* We are on the bridge head itself, possibly entering the bridge */
7901de192beb (svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
KUDr
parents: 5622
diff changeset
  1034
		/* Vehicle will enter the bridge wormhole when it reaches the tile edge in the
7901de192beb (svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
KUDr
parents: 5622
diff changeset
  1035
		 * direction of the bridge. */
7901de192beb (svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
KUDr
parents: 5622
diff changeset
  1036
		TileIndexDiffC diff = TileIndexDiffCByDiagDir(dir);
7901de192beb (svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
KUDr
parents: 5622
diff changeset
  1037
		/* If vehicle didn't reach the edge we can return and try it next time */
7901de192beb (svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
KUDr
parents: 5622
diff changeset
  1038
		if (((diff.x != 0 ? x : y) & 0x0F) != (diff.x + diff.y > 0 ? TILE_SIZE - 1 : 0)) return 0;
5628
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1039
		/* We will enter the bridge wormhole. */
5622
2f0cb276d32a (svn r7720) [cbh] - Fix: Trains can now access bridges from, and depart bridge onto, non X- and Y-direction Tracks.
celestar
parents: 5621
diff changeset
  1040
5628
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1041
		other_bridge_end_tile = GetOtherBridgeEnd(tile);
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1042
		bridge_length = GetBridgeLength(tile, other_bridge_end_tile);
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1043
		if (bridge_length > 0) {
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1044
			/* Non-zero bridge length. Adjust the other coordinate to the middle of tile
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1045
			* to allow train controller to select proper vehicle image */
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1046
			if (diff.x != 0) v->y_pos = y; else v->x_pos = x;
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1047
			v->direction = DiagDirToDir(dir);
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1048
			/* We're about to enter the bridge body, clear all up/down flags just in case */
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
  1049
			v->u.rail.track = TRACK_BIT_WORMHOLE;
5628
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1050
			v->direction = DiagDirToDir(dir);
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1051
			CLRBIT(v->u.rail.flags, VRF_GOINGUP);
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1052
			CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1053
			return 4;
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1054
		} else {
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1055
			/* Zero bridge length. Pretend that nothing extra happened. Custom bridge heads should act as normal tracks. */
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1056
			;
6975ccb4a7bd (svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
KUDr
parents: 5625
diff changeset
  1057
		}
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1058
	}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1059
	return 0;
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1060
}
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1061
5608
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
  1062
static uint32 VehicleEnter_Bridge(Vehicle *v, TileIndex tile, int x, int y)
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
  1063
{
5613
8b68de175f44 (svn r7702) [cbh] - Moved around some functions and changes from r7687 abd 7697
celestar
parents: 5612
diff changeset
  1064
	if (v->type == VEH_Train) return VehicleEnter_Railway_Bridge(v, tile, x, y);
5608
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
  1065
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
  1066
	if (v->type == VEH_Road) return VehicleEnter_Street_Bridge(v, tile, x, y);
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
  1067
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
  1068
	NOT_REACHED();
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
  1069
}
a0768f524071 (svn r7653) [cbh] - Codechange: Split VehicleEnter_Bridge into separate files for road and rail to simplify further work on this
celestar
parents: 5607
diff changeset
  1070
5650
aefc131bf5ce (svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents: 5649
diff changeset
  1071
extern const TileTypeProcs _tile_type_bridge_procs = {
5593
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1072
	DrawTile_Bridge,           /* draw_tile_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1073
	GetSlopeZ_Bridge,          /* get_slope_z_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1074
	ClearTile_Bridge,          /* clear_tile_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1075
	GetAcceptedCargo_Bridge,   /* get_accepted_cargo_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1076
	GetTileDesc_Bridge,        /* get_tile_desc_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1077
	GetTileTrackStatus_Bridge, /* get_tile_track_status_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1078
	ClickTile_Bridge,          /* click_tile_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1079
	AnimateTile_Bridge,        /* animate_tile_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1080
	TileLoop_Bridge,           /* tile_loop_clear */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1081
	ChangeTileOwner_Bridge,    /* change_tile_owner_clear */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1082
	NULL,                      /* get_produced_cargo_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1083
	VehicleEnter_Bridge,       /* vehicle_enter_tile_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1084
	GetSlopeTileh_Bridge,      /* get_slope_tileh_proc */
3e0dd1f014ca (svn r7610) [cbh] - Codechange: Created seperate Tile Type Procs for tunnel and bridge tiles
celestar
parents: 5592
diff changeset
  1085
};