src/tunnelbridge_cmd.cpp
author Tero Marttila <terom@fixme.fi>
Fri, 19 Dec 2008 02:25:44 +0200
branchterom-mini
changeset 10442 7089fa402bfd
parent 10362 20518cacbdb8
permissions -rw-r--r--
mini-branch
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6117
6507b2a7e71d (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 6106
diff changeset
     3
/** @file tunnelbridge_cmd.cpp
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
     4
 * This file deals with tunnels and bridges (non-gui stuff)
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
     5
 * @todo seperate this file into two
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
     6
 */
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
     7
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1884
diff changeset
     9
#include "openttd.h"
3189
bf047128dee7 (svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents: 3188
diff changeset
    10
#include "bridge_map.h"
3187
6f83f483fed0 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
    11
#include "rail_map.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3069
diff changeset
    12
#include "road_map.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
    13
#include "tile_cmd.h"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6259
diff changeset
    14
#include "landscape.h"
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
    15
#include "tunnel_map.h"
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
    16
#include "unmovable_map.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8204
diff changeset
    17
#include "viewport_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    18
#include "command_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "town.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    20
#include "variables.h"
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
    21
#include "bridge.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2663
diff changeset
    22
#include "train.h"
3187
6f83f483fed0 (svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents: 3184
diff changeset
    23
#include "water_map.h"
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3881
diff changeset
    24
#include "yapf/yapf.h"
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4559
diff changeset
    25
#include "newgrf_sound.h"
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
    26
#include "autoslope.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7845
diff changeset
    27
#include "transparency.h"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
    28
#include "tunnelbridge_map.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8108
diff changeset
    29
#include "strings_func.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    30
#include "date_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8119
diff changeset
    31
#include "functions.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8140
diff changeset
    32
#include "vehicle_func.h"
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8144
diff changeset
    33
#include "sound_func.h"
8238
d47a86c79603 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8236
diff changeset
    34
#include "signal_func.h"
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8390
diff changeset
    35
#include "tunnelbridge.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    36
#include "company_base.h"
8786
1823ff88a054 (svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents: 8732
diff changeset
    37
#include "engine_func.h"
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 9034
diff changeset
    38
#include "engine_base.h"
8962
1b263c69799d (svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents: 8865
diff changeset
    39
#include "economy_func.h"
1b263c69799d (svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents: 8865
diff changeset
    40
#include "rail.h"
8965
29a591456a2f (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 8962
diff changeset
    41
#include "cheat_func.h"
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9126
diff changeset
    42
#include "elrail_func.h"
9126
5648d696456b (svn r12986) -Codechange: move the landscape and transport related types from openttd.h to their own headers.
rubidium
parents: 9070
diff changeset
    43
#include "landscape_type.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    45
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    46
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    47
#include "table/bridge_land.h"
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2260
diff changeset
    48
8535
ef36a2eb9345 (svn r12111) -Codechange: Rename Bridge to BridgeSpec, out of consistensy with other Specs in used.
belugas
parents: 8532
diff changeset
    49
BridgeSpec _bridge[MAX_BRIDGES];
8973
749e572f9378 (svn r12765) -Codechange: move some stuff out of variables.h that required including other headers in variables.h.
rubidium
parents: 8965
diff changeset
    50
TileIndex _build_tunnel_endtile;
2763
a4d065e3261b (svn r3308) BAD
tron
parents: 2737
diff changeset
    51
8489
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    52
/** Reset the data been eventually changed by the grf loaded. */
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    53
void ResetBridges()
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    54
{
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    55
	/* First, free sprite table data */
8532
ebe68d6899b6 (svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents: 8531
diff changeset
    56
	for (BridgeType i = 0; i < MAX_BRIDGES; i++) {
8489
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    57
		if (_bridge[i].sprite_table != NULL) {
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
    58
			for (BridgePieces j = BRIDGE_PIECE_NORTH; j < BRIDGE_PIECE_INVALID; j++) free(_bridge[i].sprite_table[j]);
8489
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    59
			free(_bridge[i].sprite_table);
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    60
		}
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    61
	}
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    62
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    63
	/* Then, wipe out current bidges */
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    64
	memset(&_bridge, 0, sizeof(_bridge));
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    65
	/* And finally, reinstall default data */
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    66
	memcpy(&_bridge, &_orig_bridge, sizeof(_orig_bridge));
28bedfca9e27 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8475
diff changeset
    67
}
2763
a4d065e3261b (svn r3308) BAD
tron
parents: 2737
diff changeset
    68
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
    69
/** calculate the price factor for building a long bridge.
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
    70
 * basically the cost delta is 1,1, 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6,  7,7,7,7,7,7,7,  8,8,8,8,8,8,8,8,
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
    71
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
int CalcBridgeLenCostFactor(int x)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    74
	int n;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    75
	int r;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    76
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	if (x < 2) return x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
	x -= 2;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    79
	for (n = 0, r = 2;; n++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
		if (x <= n) return r + x * n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
		r += n * n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
		x -= n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
    86
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
    87
{
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
    88
	if ((tileh == SLOPE_FLAT) ||
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
    89
	    (((tileh == SLOPE_NE) || (tileh == SLOPE_SW)) && (axis == AXIS_X)) ||
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
    90
	    (((tileh == SLOPE_NW) || (tileh == SLOPE_SE)) && (axis == AXIS_Y))) return FOUNDATION_NONE;
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
    91
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
    92
	return (HasSlopeHighestCorner(tileh) ? InclinedFoundation(axis) : FlatteningFoundation(tileh));
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
    93
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
8379
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
    95
/**
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
    96
 * Determines if the track on a bridge ramp is flat or goes up/down.
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
    97
 *
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
    98
 * @param tileh Slope of the tile under the bridge head
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
    99
 * @param axis Orientation of bridge
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
   100
 * @return true iff the track is flat.
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
   101
 */
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
   102
bool HasBridgeFlatRamp(Slope tileh, Axis axis)
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
   103
{
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
   104
	ApplyFoundationToSlope(GetBridgeFoundation(tileh, axis), &tileh);
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
   105
	/* If the foundation slope is flat the bridge has a non-flat ramp and vice versa. */
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
   106
	return (tileh != SLOPE_FLAT);
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
   107
}
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
   108
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
   109
static inline const PalSpriteID *GetBridgeSpriteTable(int index, BridgePieces table)
2478
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   110
{
8535
ef36a2eb9345 (svn r12111) -Codechange: Rename Bridge to BridgeSpec, out of consistensy with other Specs in used.
belugas
parents: 8532
diff changeset
   111
	const BridgeSpec *bridge = GetBridgeSpec(index);
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
   112
	assert(table < BRIDGE_PIECE_INVALID);
2478
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   113
	if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) {
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   114
		return _bridge_sprite_table[index][table];
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   115
	} else {
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   116
		return bridge->sprite_table[table];
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   117
	}
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   118
}
cd6a02ba3853 (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2436
diff changeset
   119
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   121
/**
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   122
 * Determines the foundation for the north bridge head, and tests if the resulting slope is valid.
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   123
 *
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   124
 * @param axis Axis of the bridge
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   125
 * @param tileh Slope of the tile under the north bridge head; returns slope on top of foundation
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   126
 * @param z TileZ corresponding to tileh, gets modified as well
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   127
 * @return Error or cost for bridge foundation
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   128
 */
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   129
static CommandCost CheckBridgeSlopeNorth(Axis axis, Slope *tileh, uint *z)
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   130
{
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   131
	Foundation f = GetBridgeFoundation(*tileh, axis);
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   132
	*z += ApplyFoundationToSlope(f, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   134
	Slope valid_inclined = (axis == AXIS_X ? SLOPE_NE : SLOPE_NW);
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   135
	if ((*tileh != SLOPE_FLAT) && (*tileh != valid_inclined)) return CMD_ERROR;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   136
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   137
	if (f == FOUNDATION_NONE) return CommandCost();
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   138
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   139
	return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   142
/**
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   143
 * Determines the foundation for the south bridge head, and tests if the resulting slope is valid.
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   144
 *
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   145
 * @param axis Axis of the bridge
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   146
 * @param tileh Slope of the tile under the south bridge head; returns slope on top of foundation
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   147
 * @param z TileZ corresponding to tileh, gets modified as well
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   148
 * @return Error or cost for bridge foundation
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   149
 */
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   150
static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope *tileh, uint *z)
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   151
{
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   152
	Foundation f = GetBridgeFoundation(*tileh, axis);
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   153
	*z += ApplyFoundationToSlope(f, tileh);
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   154
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   155
	Slope valid_inclined = (axis == AXIS_X ? SLOPE_SW : SLOPE_SE);
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   156
	if ((*tileh != SLOPE_FLAT) && (*tileh != valid_inclined)) return CMD_ERROR;
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   157
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   158
	if (f == FOUNDATION_NONE) return CommandCost();
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   159
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   160
	return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
4239
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   161
}
4869ca42ffd9 (svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents: 4231
diff changeset
   162
9578
897d5acf2a62 (svn r13611) -Fix [FS#2100]: if the first bridge can't be build for a given length, then none of the other bridges can. Effectively meaning that if someone replaces the first bridge with a bridge that can be only 3 tiles longs then only other bridges that can be 3 tiles long will be buildable, but only if they are 3 tiles long.
rubidium
parents: 9498
diff changeset
   163
bool CheckBridge_Stuff(BridgeType bridge_type, uint bridge_len, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
{
9578
897d5acf2a62 (svn r13611) -Fix [FS#2100]: if the first bridge can't be build for a given length, then none of the other bridges can. Effectively meaning that if someone replaces the first bridge with a bridge that can be only 3 tiles longs then only other bridges that can be 3 tiles long will be buildable, but only if they are 3 tiles long.
rubidium
parents: 9498
diff changeset
   165
	if (flags & DC_QUERY_COST) {
9596
bae8462571bf (svn r13638) -Fix: signed/unsigned warning for MSVC9 and gcc2
smatz
parents: 9578
diff changeset
   166
		return bridge_len <= (_settings_game.construction.longbridges ? 100U : 16U);
9578
897d5acf2a62 (svn r13611) -Fix [FS#2100]: if the first bridge can't be build for a given length, then none of the other bridges can. Effectively meaning that if someone replaces the first bridge with a bridge that can be only 3 tiles longs then only other bridges that can be 3 tiles long will be buildable, but only if they are 3 tiles long.
rubidium
parents: 9498
diff changeset
   167
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
1781
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   169
	if (bridge_type >= MAX_BRIDGES) return false;
9578
897d5acf2a62 (svn r13611) -Fix [FS#2100]: if the first bridge can't be build for a given length, then none of the other bridges can. Effectively meaning that if someone replaces the first bridge with a bridge that can be only 3 tiles longs then only other bridges that can be 3 tiles long will be buildable, but only if they are 3 tiles long.
rubidium
parents: 9498
diff changeset
   170
897d5acf2a62 (svn r13611) -Fix [FS#2100]: if the first bridge can't be build for a given length, then none of the other bridges can. Effectively meaning that if someone replaces the first bridge with a bridge that can be only 3 tiles longs then only other bridges that can be 3 tiles long will be buildable, but only if they are 3 tiles long.
rubidium
parents: 9498
diff changeset
   171
	const BridgeSpec *b = GetBridgeSpec(bridge_type);
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   172
	if (b->avail_year > _cur_year) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
9578
897d5acf2a62 (svn r13611) -Fix [FS#2100]: if the first bridge can't be build for a given length, then none of the other bridges can. Effectively meaning that if someone replaces the first bridge with a bridge that can be only 3 tiles longs then only other bridges that can be 3 tiles long will be buildable, but only if they are 3 tiles long.
rubidium
parents: 9498
diff changeset
   174
	uint max = b->max_length;
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   175
	if (max >= 16 && _settings_game.construction.longbridges) max = 100;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   177
	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
   178
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   180
/** Build a Bridge
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   181
 * @param end_tile end tile
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   182
 * @param flags type of operation
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   183
 * @param p1 packed start tile coords (~ dx)
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   184
 * @param p2 various bitstuffed elements
10140
5c9f3aea73a5 (svn r14326) -Fix: some wrong comments (Yexo)
rubidium
parents: 10109
diff changeset
   185
 * - p2 = (bit  0- 7) - bridge type (hi bh)
5c9f3aea73a5 (svn r14326) -Fix: some wrong comments (Yexo)
rubidium
parents: 10109
diff changeset
   186
 * - p2 = (bit  8-14) - rail type or road types.
5c9f3aea73a5 (svn r14326) -Fix: some wrong comments (Yexo)
rubidium
parents: 10109
diff changeset
   187
 * - p2 = (bit 15-16) - transport type.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   189
CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
{
8532
ebe68d6899b6 (svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents: 8531
diff changeset
   191
	BridgeType bridge_type;
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   192
	RailType railtype = INVALID_RAILTYPE;
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   193
	RoadTypes roadtypes = ROADTYPES_NONE;
3853
1a204a464c7b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   194
	uint x;
1a204a464c7b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   195
	uint y;
1a204a464c7b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   196
	uint sx;
1a204a464c7b (svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents: 3794
diff changeset
   197
	uint sy;
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   198
	TileIndex tile_start;
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   199
	TileIndex tile_end;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   200
	Slope tileh_start;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   201
	Slope tileh_end;
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   202
	uint z_start;
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   203
	uint z_end;
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   204
	TileIndex tile;
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   205
	TileIndexDiff delta;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   206
	uint bridge_len;
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   207
	Axis direction;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   208
	CommandCost cost(EXPENSES_CONSTRUCTION);
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   209
	CommandCost ret;
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   210
	bool replace_bridge = false;
8532
ebe68d6899b6 (svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents: 8531
diff changeset
   211
	BridgeType replaced_bridge_type;
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   212
	TransportType transport_type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	/* unpack parameters */
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   215
	bridge_type = GB(p2, 0, 8);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   216
8531
00730ec6d8c8 (svn r12106) -Fix(r12105): Kill warnings and raise an error when the transport type is not supported
belugas
parents: 8530
diff changeset
   217
	if (p1 >= MapSize()) return CMD_ERROR;
00730ec6d8c8 (svn r12106) -Fix(r12105): Kill warnings and raise an error when the transport type is not supported
belugas
parents: 8530
diff changeset
   218
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   219
	transport_type = (TransportType)GB(p2, 15, 2);
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1587
diff changeset
   220
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   221
	/* type of bridge */
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   222
	switch (transport_type) {
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   223
		case TRANSPORT_ROAD:
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   224
			roadtypes = (RoadTypes)GB(p2, 8, 3);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   225
			if (!AreValidRoadTypes(roadtypes) || !HasRoadTypesAvail(_current_company, roadtypes)) return CMD_ERROR;
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   226
			break;
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   227
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   228
		case TRANSPORT_RAIL:
10140
5c9f3aea73a5 (svn r14326) -Fix: some wrong comments (Yexo)
rubidium
parents: 10109
diff changeset
   229
			railtype = (RailType)GB(p2, 8, 7);
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   230
			if (!ValParamRailtype(railtype)) return CMD_ERROR;
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   231
			break;
8531
00730ec6d8c8 (svn r12106) -Fix(r12105): Kill warnings and raise an error when the transport type is not supported
belugas
parents: 8530
diff changeset
   232
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   233
		case TRANSPORT_WATER:
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   234
			break;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   235
8531
00730ec6d8c8 (svn r12106) -Fix(r12105): Kill warnings and raise an error when the transport type is not supported
belugas
parents: 8530
diff changeset
   236
		default:
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   237
			/* Airports don't have tunnels. */
8531
00730ec6d8c8 (svn r12106) -Fix(r12105): Kill warnings and raise an error when the transport type is not supported
belugas
parents: 8530
diff changeset
   238
			return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   241
	x = TileX(end_tile);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   242
	y = TileY(end_tile);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   243
	sx = TileX(p1);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   244
	sy = TileY(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
	/* 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
   247
	if (x == sx) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   248
		if (y == sy) return_cmd_error(STR_5008_CANNOT_START_AND_END_ON);
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   249
		direction = AXIS_Y;
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 6010
diff changeset
   250
		if (y > sy) Swap(y, sy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	} else if (y == sy) {
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3156
diff changeset
   252
		direction = AXIS_X;
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 6010
diff changeset
   253
		if (x > sx) Swap(x, sx);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   254
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
		return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   256
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   258
	bridge_len = sx + sy - x - y - 1;
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   259
	if (transport_type != TRANSPORT_WATER) {
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   260
		/* set and test bridge length, availability */
9578
897d5acf2a62 (svn r13611) -Fix [FS#2100]: if the first bridge can't be build for a given length, then none of the other bridges can. Effectively meaning that if someone replaces the first bridge with a bridge that can be only 3 tiles longs then only other bridges that can be 3 tiles long will be buildable, but only if they are 3 tiles long.
rubidium
parents: 9498
diff changeset
   261
		if (!CheckBridge_Stuff(bridge_type, bridge_len, flags)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   262
	}
1781
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   263
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	/* retrieve landscape height and ensure it's on land */
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   265
	tile_start = TileXY(x, y);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   266
	tile_end = TileXY(sx, sy);
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8413
diff changeset
   267
	if (IsWaterTile(tile_start) || IsWaterTile(tile_end)) {
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   268
		return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3996
diff changeset
   269
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   271
	tileh_start = GetTileSlope(tile_start, &z_start);
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   272
	tileh_end = GetTileSlope(tile_end, &z_end);
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   273
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   274
	CommandCost terraform_cost_north = CheckBridgeSlopeNorth(direction, &tileh_start, &z_start);
8625
30871547954b (svn r12208) -Codechange: Alignment of params makes the code easier to read.
belugas
parents: 8616
diff changeset
   275
	CommandCost terraform_cost_south = CheckBridgeSlopeSouth(direction, &tileh_end,   &z_end);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
7682
ee53a5efa35b (svn r11213) -Fix [FS#1298]: confusing messages when trying to build a bridge.
rubidium
parents: 7677
diff changeset
   277
	if (z_start != z_end) return_cmd_error(STR_BRIDGEHEADS_NOT_SAME_HEIGHT);
1585
9746fa4b40a7 (svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents: 1562
diff changeset
   278
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   279
	if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   280
			GetOtherBridgeEnd(tile_start) == tile_end &&
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
   281
			GetTunnelBridgeTransportType(tile_start) == transport_type) {
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   282
		/* Replace a current bridge. */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   283
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   284
		/* If this is a railway bridge, make sure the railtypes match. */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   285
		if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   286
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   287
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   289
		/* Do not replace town bridges with lower speed bridges. */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   290
		if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
8491
97fcf662c3c3 (svn r12066) -Codechange: Rename GetBridge for the more common GetBridgeSpec
belugas
parents: 8489
diff changeset
   291
				GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed) {
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   292
			Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   293
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   294
			if (t == NULL) {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   295
				return CMD_ERROR;
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   296
			} else {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   297
				SetDParam(0, t->index);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   298
				return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   299
			}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   300
		}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   301
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   302
		/* Do not replace the bridge with the same bridge type. */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   303
		if (!(flags & DC_QUERY_COST) && bridge_type == GetBridgeType(tile_start)) {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   304
			return_cmd_error(STR_1007_ALREADY_BUILT);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   305
		}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   306
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   307
		/* Do not allow replacing another company's bridges. */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   308
		if (!IsTileOwner(tile_start, _current_company) && !IsTileOwner(tile_start, OWNER_TOWN)) {
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   309
			return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   310
		}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   311
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   312
		cost.AddCost((bridge_len + 1) * _price.clear_bridge); // The cost of clearing the current bridge.
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   313
		replace_bridge = true;
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   314
		replaced_bridge_type = GetBridgeType(tile_start);
6708
257de56ddd2f (svn r9940) -Fix [FS#805]: upgrading a bridge removed roadtypes.
rubidium
parents: 6699
diff changeset
   315
257de56ddd2f (svn r9940) -Fix [FS#805]: upgrading a bridge removed roadtypes.
rubidium
parents: 6699
diff changeset
   316
		/* Do not remove road types when upgrading a bridge */
257de56ddd2f (svn r9940) -Fix [FS#805]: upgrading a bridge removed roadtypes.
rubidium
parents: 6699
diff changeset
   317
		roadtypes |= GetRoadTypes(tile_start);
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   318
	} else {
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   319
		/* Build a new bridge. */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   320
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   321
		bool allow_on_slopes = (!_is_old_ai_company && _settings_game.construction.build_on_slopes && transport_type != TRANSPORT_WATER);
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   322
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   323
		/* Try and clear the start landscape */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   324
		ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   325
		if (CmdFailed(ret)) return ret;
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   326
		cost = ret;
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   327
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   328
		if (CmdFailed(terraform_cost_north) || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes))
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   329
			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   330
		cost.AddCost(terraform_cost_north);
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   331
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   332
		/* Try and clear the end landscape */
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   333
		ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   334
		if (CmdFailed(ret)) return ret;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   335
		cost.AddCost(ret);
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   336
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   337
		/* false - end tile slope check */
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   338
		if (CmdFailed(terraform_cost_south) || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes))
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   339
			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
   340
		cost.AddCost(terraform_cost_south);
9491
12c4ef045d91 (svn r13466) -Fix (r13464): slope checking got lost during development...
rubidium
parents: 9490
diff changeset
   341
12c4ef045d91 (svn r13466) -Fix (r13464): slope checking got lost during development...
rubidium
parents: 9490
diff changeset
   342
		if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   343
	}
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   344
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   345
	if (!replace_bridge) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   346
		TileIndex Heads[] = {tile_start, tile_end};
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   347
		int i;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   348
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   349
		for (i = 0; i < 2; i++) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   350
			if (MayHaveBridgeAbove(Heads[i])) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   351
				if (IsBridgeAbove(Heads[i])) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   352
					TileIndex north_head = GetNorthernBridgeEnd(Heads[i]);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   353
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   354
					if (direction == GetBridgeAxis(Heads[i])) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   355
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   356
					if (z_start + TILE_HEIGHT == GetBridgeHeight(north_head)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   357
						return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   358
					}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   359
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   360
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   361
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   362
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	/* do the drill? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
	if (flags & DC_EXEC) {
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   366
		DiagDirection dir = AxisToDiagDir(direction);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   367
		Owner owner = (replace_bridge && IsTileOwner(tile_start, OWNER_TOWN)) ? OWNER_TOWN : _current_company;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   369
		switch (transport_type) {
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   370
			case TRANSPORT_RAIL:
8625
30871547954b (svn r12208) -Codechange: Alignment of params makes the code easier to read.
belugas
parents: 8616
diff changeset
   371
				MakeRailBridgeRamp(tile_start, owner, bridge_type, dir,                 railtype);
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   372
				MakeRailBridgeRamp(tile_end,   owner, bridge_type, ReverseDiagDir(dir), railtype);
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   373
				break;
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   374
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   375
			case TRANSPORT_ROAD:
8625
30871547954b (svn r12208) -Codechange: Alignment of params makes the code easier to read.
belugas
parents: 8616
diff changeset
   376
				MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir,                 roadtypes);
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   377
				MakeRoadBridgeRamp(tile_end,   owner, bridge_type, ReverseDiagDir(dir), roadtypes);
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   378
				break;
8531
00730ec6d8c8 (svn r12106) -Fix(r12105): Kill warnings and raise an error when the transport type is not supported
belugas
parents: 8530
diff changeset
   379
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   380
			case TRANSPORT_WATER:
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   381
				MakeAqueductBridgeRamp(tile_start, owner, dir);
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   382
				MakeAqueductBridgeRamp(tile_end,   owner, ReverseDiagDir(dir));
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   383
				break;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   384
8531
00730ec6d8c8 (svn r12106) -Fix(r12105): Kill warnings and raise an error when the transport type is not supported
belugas
parents: 8530
diff changeset
   385
			default:
00730ec6d8c8 (svn r12106) -Fix(r12105): Kill warnings and raise an error when the transport type is not supported
belugas
parents: 8530
diff changeset
   386
				NOT_REACHED();
00730ec6d8c8 (svn r12106) -Fix(r12105): Kill warnings and raise an error when the transport type is not supported
belugas
parents: 8530
diff changeset
   387
				break;
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3196
diff changeset
   388
		}
3301
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   389
		MarkTileDirtyByTile(tile_start);
79efd3144eba (svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents: 3267
diff changeset
   390
		MarkTileDirtyByTile(tile_end);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   393
	delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   394
	for (tile = tile_start + delta; tile != tile_end; tile += delta) {
8370
4bbbdd6a7798 (svn r11936) -Fix: 'BRIDGE_TOO_LOW_FOR_TERRAIN'-check was wrong for steep slopes.
frosch
parents: 8360
diff changeset
   395
		if (GetTileMaxZ(tile) > z_start) return_cmd_error(STR_BRIDGE_TOO_LOW_FOR_TERRAIN);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   397
		if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && !replace_bridge) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   398
			/* Disallow crossing bridges for the time being */
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   399
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   400
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   402
		switch (GetTileType(tile)) {
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   403
			case MP_WATER:
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8413
diff changeset
   404
				if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   405
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   407
			case MP_RAILWAY:
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   408
				if (!IsPlainRailTile(tile)) goto not_valid_below;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   409
				break;
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   410
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7335
diff changeset
   411
			case MP_ROAD:
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8549
diff changeset
   412
				if (IsRoadDepot(tile)) goto not_valid_below;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   413
				break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   414
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   415
			case MP_TUNNELBRIDGE:
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   416
				if (IsTunnel(tile)) break;
5930
e55fcb2f892e (svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents: 5852
diff changeset
   417
				if (replace_bridge) break;
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
   418
				if (direction == DiagDirToAxis(GetTunnelBridgeDirection(tile))) goto not_valid_below;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   419
				if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   420
				break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   421
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   422
			case MP_UNMOVABLE:
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   423
				if (!IsOwnedLand(tile)) goto not_valid_below;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   424
				break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   425
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   426
			case MP_CLEAR:
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   427
				break;
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   428
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   429
			default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
not_valid_below:;
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   431
				/* try and clear the middle landscape */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   432
				ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3181
diff changeset
   433
				if (CmdFailed(ret)) return ret;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   434
				cost.AddCost(ret);
3065
c73ad9f6fb33 (svn r3654) Turn another if-cascade into a switch
tron
parents: 3064
diff changeset
   435
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
		if (flags & DC_EXEC) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   439
			SetBridgeMiddle(tile, direction);
3178
f41cd14f6034 (svn r3814) Remove another call to FindLandscapeHeight()
tron
parents: 3172
diff changeset
   440
			MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
8530
0936741af0ac (svn r12105) -Codechange: Use TransportType instead of guessing what kind of bridge we are preparing to build
belugas
parents: 8528
diff changeset
   444
	if (flags & DC_EXEC && transport_type == TRANSPORT_RAIL) {
5561
d276d7fbc819 (svn r7966) -Fix (r7936): Eh AxisToTrack returns Track not Axis, thanks KUDr
Darkvater
parents: 5554
diff changeset
   445
		Track track = AxisToTrack(direction);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   446
		AddSideToSignalBuffer(tile_start, INVALID_DIAGDIR, _current_company);
5561
d276d7fbc819 (svn r7966) -Fix (r7936): Eh AxisToTrack returns Track not Axis, thanks KUDr
Darkvater
parents: 5554
diff changeset
   447
		YapfNotifyTrackLayoutChange(tile_start, track);
5554
49c032cbe21d (svn r7936) -Fix (r4987, old-rev): Only update the signals and YAPF cache on a DC_EXEC action for bridge-building
Darkvater
parents: 5475
diff changeset
   448
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   450
	/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   451
	 * It's unnecessary to execute this command every time for every bridge. So it is done only
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   452
	 * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   453
	 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   454
	if (!(flags & DC_QUERY_COST) || (IsValidCompanyID(_current_company) && GetCompany(_current_company)->is_ai)) {
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
   455
		bridge_len += 2; // begin and end tiles/ramps
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   457
		if (IsValidCompanyID(_current_company) && !_is_old_ai_company)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
			bridge_len = CalcBridgeLenCostFactor(bridge_len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
8491
97fcf662c3c3 (svn r12066) -Codechange: Rename GetBridge for the more common GetBridgeSpec
belugas
parents: 8489
diff changeset
   460
		cost.AddCost((int64)bridge_len * _price.build_bridge * GetBridgeSpec(bridge_type)->price >> 8);
9492
cbd8e40186c3 (svn r13468) -Fix: make aqueducts a little more expensive than normal bridges and disable terraforming of aqueduct bridgeheads; one can't terraform normal canal tiles either.
rubidium
parents: 9491
diff changeset
   461
cbd8e40186c3 (svn r13468) -Fix: make aqueducts a little more expensive than normal bridges and disable terraforming of aqueduct bridgeheads; one can't terraform normal canal tiles either.
rubidium
parents: 9491
diff changeset
   462
		/* Aqueducts are a little more expensive. */
cbd8e40186c3 (svn r13468) -Fix: make aqueducts a little more expensive than normal bridges and disable terraforming of aqueduct bridgeheads; one can't terraform normal canal tiles either.
rubidium
parents: 9491
diff changeset
   463
		if (transport_type == TRANSPORT_WATER) cost.AddCost((int64)bridge_len * _price.clear_water);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   470
/** Build Tunnel.
6484
79156627e1ba (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents: 6427
diff changeset
   471
 * @param start_tile start tile of tunnel
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   472
 * @param flags type of operation
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   473
 * @param p1 railtype or roadtypes. bit 9 set means road tunnel
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   474
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   476
CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
{
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   478
	TileIndexDiff delta;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   479
	TileIndex end_tile;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   480
	DiagDirection direction;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   481
	Slope start_tileh;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   482
	Slope end_tileh;
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
   483
	TransportType transport_type = (TransportType)GB(p1, 9, 1);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   484
	uint start_z;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   485
	uint end_z;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8224
diff changeset
   486
	CommandCost cost(EXPENSES_CONSTRUCTION);
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   487
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   489
	_build_tunnel_endtile = 0;
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
   490
	if (transport_type == TRANSPORT_RAIL) {
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8232
diff changeset
   491
		if (!ValParamRailtype((RailType)p1)) return CMD_ERROR;
7857
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7849
diff changeset
   492
	} else {
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7849
diff changeset
   493
		const RoadTypes rts = (RoadTypes)GB(p1, 0, 3);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   494
		if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6537
diff changeset
   495
	}
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   496
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   497
	start_tileh = GetTileSlope(start_tile, &start_z);
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
   498
	direction = GetInclinedSlopeDirection(start_tileh);
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8398
diff changeset
   499
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8413
diff changeset
   501
	if (IsWaterTile(start_tile)) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
8385
1ed7890b60e5 (svn r11955) -Fix (r11926): Prevent bridge and tunnel ends being placed on rivers.
peter1138
parents: 8379
diff changeset
   502
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   503
	ret = DoCommand(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   504
	if (CmdFailed(ret)) return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
4273
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   506
	/* XXX - do NOT change 'ret' in the loop, as it is used as the price
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   507
	 * for the clearing of the entrance of the tunnel. Assigning it to
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   508
	 * cost before the loop will yield different costs depending on start-
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   509
	 * position, because of increased-cost-by-length: 'cost += cost >> 3' */
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   510
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   511
	delta = TileOffsByDiagDir(direction);
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6992
diff changeset
   512
	DiagDirection tunnel_in_way_dir;
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
   513
	if (DiagDirToAxis(direction) == AXIS_Y) {
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6992
diff changeset
   514
		tunnel_in_way_dir = (TileX(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SW : DIAGDIR_NE;
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6992
diff changeset
   515
	} else {
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6992
diff changeset
   516
		tunnel_in_way_dir = (TileY(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SE : DIAGDIR_NW;
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6992
diff changeset
   517
	}
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6992
diff changeset
   518
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   519
	end_tile = start_tile;
7095
51c5b30176e1 (svn r10362) -Codechange: make tunnel costs less exponential for (very) long tunnels.
rubidium
parents: 7044
diff changeset
   520
51c5b30176e1 (svn r10362) -Codechange: make tunnel costs less exponential for (very) long tunnels.
rubidium
parents: 7044
diff changeset
   521
	/** Tile shift coeficient. Will decrease for very long tunnels to avoid exponential growth of price*/
51c5b30176e1 (svn r10362) -Codechange: make tunnel costs less exponential for (very) long tunnels.
rubidium
parents: 7044
diff changeset
   522
	int tiles_coef = 3;
51c5b30176e1 (svn r10362) -Codechange: make tunnel costs less exponential for (very) long tunnels.
rubidium
parents: 7044
diff changeset
   523
	/** Number of tiles from start of tunnel */
51c5b30176e1 (svn r10362) -Codechange: make tunnel costs less exponential for (very) long tunnels.
rubidium
parents: 7044
diff changeset
   524
	int tiles = 0;
7308
d1be09715915 (svn r10660) -Codechange: simplified tunnel cost algorithm (bilbo)
truelight
parents: 7266
diff changeset
   525
	/** Number of tiles at which the cost increase coefficient per tile is halved */
d1be09715915 (svn r10660) -Codechange: simplified tunnel cost algorithm (bilbo)
truelight
parents: 7266
diff changeset
   526
	int tiles_bump = 25;
7095
51c5b30176e1 (svn r10362) -Codechange: make tunnel costs less exponential for (very) long tunnels.
rubidium
parents: 7044
diff changeset
   527
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   528
	for (;;) {
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   529
		end_tile += delta;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   530
		end_tileh = GetTileSlope(end_tile, &end_z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   532
		if (start_z == end_z) break;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   533
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6992
diff changeset
   534
		if (!_cheats.crossing_tunnels.value && IsTunnelInWayDir(end_tile, start_z, tunnel_in_way_dir)) {
3156
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3154
diff changeset
   535
			return_cmd_error(STR_5003_ANOTHER_TUNNEL_IN_THE_WAY);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   536
		}
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   537
7095
51c5b30176e1 (svn r10362) -Codechange: make tunnel costs less exponential for (very) long tunnels.
rubidium
parents: 7044
diff changeset
   538
		tiles++;
7308
d1be09715915 (svn r10660) -Codechange: simplified tunnel cost algorithm (bilbo)
truelight
parents: 7266
diff changeset
   539
		if (tiles == tiles_bump) {
d1be09715915 (svn r10660) -Codechange: simplified tunnel cost algorithm (bilbo)
truelight
parents: 7266
diff changeset
   540
			tiles_coef++;
d1be09715915 (svn r10660) -Codechange: simplified tunnel cost algorithm (bilbo)
truelight
parents: 7266
diff changeset
   541
			tiles_bump *= 2;
d1be09715915 (svn r10660) -Codechange: simplified tunnel cost algorithm (bilbo)
truelight
parents: 7266
diff changeset
   542
		}
7095
51c5b30176e1 (svn r10362) -Codechange: make tunnel costs less exponential for (very) long tunnels.
rubidium
parents: 7044
diff changeset
   543
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   544
		cost.AddCost(_price.build_tunnel);
7095
51c5b30176e1 (svn r10362) -Codechange: make tunnel costs less exponential for (very) long tunnels.
rubidium
parents: 7044
diff changeset
   545
		cost.AddCost(cost.GetCost() >> tiles_coef); // add a multiplier for longer tunnels
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
4273
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   548
	/* Add the cost of the entrance */
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   549
	cost.AddCost(_price.build_tunnel);
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   550
	cost.AddCost(ret);
4273
131c3aba4c14 (svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents: 4261
diff changeset
   551
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   552
	/* if the command fails from here on we want the end tile to be highlighted */
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   553
	_build_tunnel_endtile = end_tile;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   554
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8413
diff changeset
   555
	if (IsWaterTile(end_tile)) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
8385
1ed7890b60e5 (svn r11955) -Fix (r11926): Prevent bridge and tunnel ends being placed on rivers.
peter1138
parents: 8379
diff changeset
   556
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   557
	/* slope of end tile must be complementary to the slope of the start tile */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3556
diff changeset
   558
	if (end_tileh != ComplementSlope(start_tileh)) {
10362
20518cacbdb8 (svn r14613) -Fix [FS#2420]: When building industries, clear the tiles as OWNER_TOWN instead of the founder to take care of protected buildings and to not get stressed by town ratings.
frosch
parents: 10236
diff changeset
   559
		/* Check if there is a structure on the terraformed tile. Do not add the cost, that will be done by the terraforming
20518cacbdb8 (svn r14613) -Fix [FS#2420]: When building industries, clear the tiles as OWNER_TOWN instead of the founder to take care of protected buildings and to not get stressed by town ratings.
frosch
parents: 10236
diff changeset
   560
		 * Note: Currently the town rating is also affected by this clearing-test. So effectivly the player is punished twice for clearing
20518cacbdb8 (svn r14613) -Fix [FS#2420]: When building industries, clear the tiles as OWNER_TOWN instead of the founder to take care of protected buildings and to not get stressed by town ratings.
frosch
parents: 10236
diff changeset
   561
		 *       the tree on end_tile.
20518cacbdb8 (svn r14613) -Fix [FS#2420]: When building industries, clear the tiles as OWNER_TOWN instead of the founder to take care of protected buildings and to not get stressed by town ratings.
frosch
parents: 10236
diff changeset
   562
		 */
7677
347f780de06a (svn r11208) -Fix [FS#1300]: tunnel excavation could disown somebody elses owned land. Patch by frosch.
rubidium
parents: 7601
diff changeset
   563
		ret = DoCommand(end_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR);
347f780de06a (svn r11208) -Fix [FS#1300]: tunnel excavation could disown somebody elses owned land. Patch by frosch.
rubidium
parents: 7601
diff changeset
   564
		if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
7042
5906c0a786e6 (svn r10306) -Fix [FS#890]: the fix in r10219 was not enough to stop this bug from happening.
rubidium
parents: 7003
diff changeset
   565
7677
347f780de06a (svn r11208) -Fix [FS#1300]: tunnel excavation could disown somebody elses owned land. Patch by frosch.
rubidium
parents: 7601
diff changeset
   566
		ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
347f780de06a (svn r11208) -Fix [FS#1300]: tunnel excavation could disown somebody elses owned land. Patch by frosch.
rubidium
parents: 7601
diff changeset
   567
		if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   568
	} else {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3435
diff changeset
   569
		ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   570
		if (CmdFailed(ret)) return ret;
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   571
	}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   572
	cost.AddCost(_price.build_tunnel);
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   573
	cost.AddCost(ret);
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   574
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   575
	if (flags & DC_EXEC) {
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
   576
		if (transport_type == TRANSPORT_RAIL) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   577
			MakeRailTunnel(start_tile, _current_company, direction,                 (RailType)GB(p1, 0, 4));
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   578
			MakeRailTunnel(end_tile,   _current_company, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4));
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   579
			AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, _current_company);
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
   580
			YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   581
		} else {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   582
			MakeRoadTunnel(start_tile, _current_company, direction,                 (RoadTypes)GB(p1, 0, 3));
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   583
			MakeRoadTunnel(end_tile,   _current_company, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 3));
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   584
		}
3063
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   585
	}
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   586
61a07ec0d09e (svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents: 3056
diff changeset
   587
	return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   591
static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile)
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   592
{
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   593
	/* Floods can remove anything as well as the scenario editor */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
   594
	if (_current_company == OWNER_WATER || _game_mode == GM_EDITOR) return true;
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   595
	/* Obviously if the bridge/tunnel belongs to us, or no-one, we can remove it */
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   596
	if (CheckTileOwnership(tile) || IsTileOwner(tile, OWNER_NONE)) return true;
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   597
	/* Otherwise we can only remove town-owned stuff with extra patch-settings, or cheat */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
   598
	if (IsTileOwner(tile, OWNER_TOWN) && (_settings_game.construction.extra_dynamite || _cheats.magic_bulldozer.value)) return true;
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   599
	return false;
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   600
}
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   601
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   602
static CommandCost DoClearTunnel(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
{
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   604
	Town *t = NULL;
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
   605
	TileIndex endtile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   607
	if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
8072
7b188d7b8199 (svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents: 8043
diff changeset
   609
	endtile = GetOtherTunnelEnd(tile);
7b188d7b8199 (svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents: 8043
diff changeset
   610
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 10017
diff changeset
   611
	if (HasVehicleOnTunnelBridge(tile, endtile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	_build_tunnel_endtile = endtile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   614
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   615
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
10236
50afe9dd466e (svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium
parents: 10208
diff changeset
   616
		t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   617
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   618
		/* Check if you are allowed to remove the tunnel owned by a town
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   619
		 * Removal depends on difficulty settings */
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
   620
		if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 511
diff changeset
   621
			SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
8232
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   626
	/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   627
	 * you have a "Poor" (0) town rating */
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   628
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   629
		ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   630
	}
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   631
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
	if (flags & DC_EXEC) {
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   633
		if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   634
			/* We first need to request values before calling DoClearSquare */
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   635
			DiagDirection dir = GetTunnelBridgeDirection(tile);
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   636
			Track track = DiagDirToDiagTrack(dir);
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   637
			Owner owner = GetTileOwner(tile);
2870
0dc0bcee256a (svn r3418) - Fix: When removing a town-owned tunnel the player's rating was not reduced, as it checked the ownership of the tunnel after clearing it. Now we perform the rating adjustment before clearing the tiles. (spotted by glx)
peter1138
parents: 2843
diff changeset
   638
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   639
			Vehicle *v = NULL;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   640
			if (GetTunnelBridgeReservation(tile)) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   641
				v = GetTrainForReservation(tile, track);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   642
				if (v != NULL) FreeTrainTrackReservation(v);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   643
			}
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   644
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   645
			DoClearSquare(tile);
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   646
			DoClearSquare(endtile);
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   647
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   648
			/* cannot use INVALID_DIAGDIR for signal update because the tunnel doesn't exist anymore */
8625
30871547954b (svn r12208) -Codechange: Alignment of params makes the code easier to read.
belugas
parents: 8616
diff changeset
   649
			AddSideToSignalBuffer(tile,    ReverseDiagDir(dir), owner);
30871547954b (svn r12208) -Codechange: Alignment of params makes the code easier to read.
belugas
parents: 8616
diff changeset
   650
			AddSideToSignalBuffer(endtile, dir,                 owner);
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   651
8625
30871547954b (svn r12208) -Codechange: Alignment of params makes the code easier to read.
belugas
parents: 8616
diff changeset
   652
			YapfNotifyTrackLayoutChange(tile,    track);
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   653
			YapfNotifyTrackLayoutChange(endtile, track);
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   654
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   655
			if (v != NULL) TryPathReserve(v);
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   656
		} else {
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   657
			DoClearSquare(tile);
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   658
			DoClearSquare(endtile);
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   659
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
	}
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8390
diff changeset
   661
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (GetTunnelBridgeLength(tile, endtile) + 2));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   664
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   665
static CommandCost DoClearBridge(TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
{
3227
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   667
	DiagDirection direction;
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   668
	TileIndexDiff delta;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   669
	TileIndex endtile;
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   670
	Town *t = NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   671
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   672
	if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
3228
72f4272b56d8 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   674
	endtile = GetOtherBridgeEnd(tile);
72f4272b56d8 (svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents: 3227
diff changeset
   675
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 10017
diff changeset
   676
	if (HasVehicleOnTunnelBridge(tile, endtile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
   678
	direction = GetTunnelBridgeDirection(tile);
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
   679
	delta = TileOffsByDiagDir(direction);
3227
41435a6d5eb0 (svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents: 3226
diff changeset
   680
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   681
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
10236
50afe9dd466e (svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium
parents: 10208
diff changeset
   682
		t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
5009
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   683
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   684
		/* Check if you are allowed to remove the bridge owned by a town
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   685
		 * Removal depends on difficulty settings */
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   686
		if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) {
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   687
			SetDParam(0, t->index);
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   688
			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
0ae33f104d4f (svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents: 4850
diff changeset
   689
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
8232
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   692
	/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   693
	 * you have a "Poor" (0) town rating */
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   694
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   695
		ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   696
	}
a4883a0598db (svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents: 8230
diff changeset
   697
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	if (flags & DC_EXEC) {
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   699
		/* read this value before actual removal of bridge */
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   700
		bool rail = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL;
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   701
		Owner owner = GetTileOwner(tile);
8589
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8563
diff changeset
   702
		uint height = GetBridgeHeight(tile);
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   703
		Vehicle *v = NULL;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   704
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   705
		if (rail && GetTunnelBridgeReservation(tile)) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   706
			v = GetTrainForReservation(tile, DiagDirToDiagTrack(direction));
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   707
			if (v != NULL) FreeTrainTrackReservation(v);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   708
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   710
		DoClearSquare(tile);
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   711
		DoClearSquare(endtile);
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   712
		for (TileIndex c = tile + delta; c != endtile; c += delta) {
8589
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8563
diff changeset
   713
			/* do not let trees appear from 'nowhere' after removing bridge */
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8563
diff changeset
   714
			if (IsNormalRoadTile(c) && GetRoadside(c) == ROADSIDE_TREES) {
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8563
diff changeset
   715
				uint minz = GetTileMaxZ(c) + 3 * TILE_HEIGHT;
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8563
diff changeset
   716
				if (height < minz) SetRoadside(c, ROADSIDE_PAVED);
e0294479574f (svn r12170) -Fix: do not draw trees along road and street lights under low bridges (spotted by _minime_)
smatz
parents: 8563
diff changeset
   717
			}
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   718
			ClearBridgeMiddle(c);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   719
			MarkTileDirtyByTile(c);
3217
c170368a2c9a (svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents: 3216
diff changeset
   720
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   722
		if (rail) {
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8297
diff changeset
   723
			/* cannot use INVALID_DIAGDIR for signal update because the bridge doesn't exist anymore */
8625
30871547954b (svn r12208) -Codechange: Alignment of params makes the code easier to read.
belugas
parents: 8616
diff changeset
   724
			AddSideToSignalBuffer(tile,    ReverseDiagDir(direction), owner);
30871547954b (svn r12208) -Codechange: Alignment of params makes the code easier to read.
belugas
parents: 8616
diff changeset
   725
			AddSideToSignalBuffer(endtile, direction,                 owner);
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   726
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
   727
			Track track = DiagDirToDiagTrack(direction);
8625
30871547954b (svn r12208) -Codechange: Alignment of params makes the code easier to read.
belugas
parents: 8616
diff changeset
   728
			YapfNotifyTrackLayoutChange(tile,    track);
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   729
			YapfNotifyTrackLayoutChange(endtile, track);
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   730
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
   731
			if (v != NULL) TryPathReserve(v, true);
8297
74bb009bff83 (svn r11861) -Fix: do not call rail specific functions when removing road tunnel/bridge
smatz
parents: 8264
diff changeset
   732
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8390
diff changeset
   735
	return CommandCost(EXPENSES_CONSTRUCTION, (GetTunnelBridgeLength(tile, endtile) + 2) * _price.clear_bridge);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6857
diff changeset
   738
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
   739
{
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
   740
	if (IsTunnel(tile)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   741
		if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
		return DoClearTunnel(tile, flags);
8390
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8385
diff changeset
   743
	} else { // IsBridge(tile)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   744
		if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
1082
a83d7ac6fecb (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1073
diff changeset
   745
		return DoClearBridge(tile, flags);
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   746
	}
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   747
1082
a83d7ac6fecb (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1073
diff changeset
   748
	return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
6368
c58210a58402 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6357
diff changeset
   751
/**
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   752
 * Draws the pillars under high bridges.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   753
 *
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   754
 * @param psid Image and palette of a bridge pillar.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   755
 * @param ti #TileInfo of current bridge-middle-tile.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   756
 * @param axis Orientation of bridge.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   757
 * @param type Bridge type.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   758
 * @param x Sprite X position of front pillar.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   759
 * @param y Sprite Y position of front pillar.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   760
 * @param z_bridge Absolute height of bridge bottom.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   761
 */
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
   762
static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
{
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   764
	/* Do not draw bridge pillars if they are invisible */
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   765
	if (IsInvisibilitySet(TO_BRIDGES)) return;
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   766
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   767
	SpriteID image = psid->sprite;
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   768
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
	if (image != 0) {
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   770
		/* "side" specifies the side the pillars stand on.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   771
		 * The length of the pillars is then set to the height of the bridge over the corners of this edge.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   772
		 *
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   773
		 *                axis==AXIS_X  axis==AXIS_Y
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   774
		 *   side==false      SW            NW
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   775
		 *   side==true       NE            SE
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   776
		 *
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   777
		 * I have no clue, why this was done this way.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   778
		 */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7923
diff changeset
   779
		bool side = HasBit(image, 0);
2262
252cfd94c54d (svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents: 2261
diff changeset
   780
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   781
		/* "dir" means the edge the pillars stand on */
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   782
		DiagDirection dir = AxisToDiagDir(axis);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   783
		if (side != (axis == AXIS_Y)) dir = ReverseDiagDir(dir);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   785
		/* Determine ground height under pillars */
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   786
		int front_height = ti->z;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   787
		int back_height = ti->z;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   788
		GetSlopeZOnEdge(ti->tileh, dir, &front_height, &back_height);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   789
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   790
		/* x and y size of bounding-box of pillars */
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   791
		int w = (axis == AXIS_X ? 16 : 2);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   792
		int h = (axis == AXIS_X ? 2 : 16);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   793
		/* sprite position of back facing pillar */
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   794
		int x_back = x - (axis == AXIS_X ? 0 : 9);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   795
		int y_back = y - (axis == AXIS_X ? 9 : 0);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   796
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   797
		for (int cur_z = z_bridge; cur_z >= front_height || cur_z >= back_height; cur_z -= TILE_HEIGHT) {
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   798
			/* Draw front facing pillar */
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   799
			if (cur_z >= front_height) {
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7845
diff changeset
   800
				AddSortableSpriteToDraw(image, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5);
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   801
			}
3556
9582b648fedd (svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents: 3539
diff changeset
   802
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   803
			/* Draw back facing pillar, but not the highest part directly under the bridge-floor */
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7697
diff changeset
   804
			if (drawfarpillar && cur_z >= back_height && cur_z < z_bridge - TILE_HEIGHT) {
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7845
diff changeset
   805
				AddSortableSpriteToDraw(image, psid->pal, x_back, y_back, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5);
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   806
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   811
/**
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   812
 * Draws the trambits over an already drawn (lower end) of a bridge.
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   813
 * @param x       the x of the bridge
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   814
 * @param y       the y of the bridge
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   815
 * @param z       the z of the bridge
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   816
 * @param offset  number representing whether to level or sloped and the direction
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   817
 * @param overlay do we want to still see the road?
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   818
 * @param head    are we drawing bridge head?
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   819
 */
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   820
static void DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay, bool head)
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   821
{
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   822
	static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } };
7249
6c480d0dda20 (svn r10549) -Fix [FS#1031]: wrong tram catenary poles drawn in some bridge directions.
rubidium
parents: 7095
diff changeset
   823
	static const SpriteID back_offsets[6]    =   {  95,  96,  99, 102, 100, 101 };
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   824
	static const SpriteID front_offsets[6]   =   {  97,  98, 103, 106, 104, 105 };
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   825
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   826
	static const uint size_x[6] = {  1, 16, 16,  1, 16,  1 };
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   827
	static const uint size_y[6] = { 16,  1,  1, 16,  1, 16 };
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   828
	static const uint front_bb_offset_x[6] = { 15,  0,  0, 15,  0, 15 };
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   829
	static const uint front_bb_offset_y[6] = {  0, 15, 15,  0, 15,  0 };
6699
d2f35126c1a6 (svn r9931) -Fix: some glitches with catenary and bridges.
rubidium
parents: 6691
diff changeset
   830
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   831
	/* The sprites under the vehicles are drawn as SpriteCombine. StartSpriteCombine() has already been called
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   832
	 * The bounding boxes here are the same as for bridge front/roof */
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   833
	if (head || !IsInvisibilitySet(TO_BRIDGES)) {
8865
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   834
		AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE,
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   835
			x, y, size_x[offset], size_y[offset], 0x28, z,
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   836
			!head && IsTransparencySet(TO_BRIDGES));
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   837
	}
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   838
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   839
	/* Do not draw catenary if it is set invisible */
8865
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   840
	if (!IsInvisibilitySet(TO_CATENARY)) {
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   841
		AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset], PAL_NONE,
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   842
			x, y, size_x[offset], size_y[offset], 0x28, z,
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   843
			IsTransparencySet(TO_CATENARY));
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   844
	}
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   845
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   846
	/* Start a new SpriteCombine for the front part */
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   847
	EndSpriteCombine();
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   848
	StartSpriteCombine();
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   849
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   850
	/* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */
8865
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   851
	if (!IsInvisibilitySet(TO_CATENARY)) {
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   852
		AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE,
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   853
			x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z,
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   854
			IsTransparencySet(TO_CATENARY), front_bb_offset_x[offset], front_bb_offset_y[offset]);
723529b427d3 (svn r12632) -Fix (r12547): with invisible catenary, trams were be drawn over a bridge
smatz
parents: 8806
diff changeset
   855
	}
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   856
}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   857
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   858
/**
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   859
 * Draws a tunnel of bridge tile.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   860
 * For tunnels, this is rather simple, as you only needa draw the entrance.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   861
 * Bridges are a bit more complex. base_offset is where the sprite selection comes into play
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   862
 * and it works a bit like a bitmask.<p> For bridge heads:
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   863
 * @param ti TileInfo of the structure to draw
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   864
 * <ul><li>Bit 0: direction</li>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   865
 * <li>Bit 1: northern or southern heads</li>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   866
 * <li>Bit 2: Set if the bridge head is sloped</li>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   867
 * <li>Bit 3 and more: Railtype Specific subset</li>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   868
 * </ul>
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   869
 * Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
   870
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
static void DrawTile_TunnelBridge(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   873
	SpriteID image;
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
   874
	TransportType transport_type = GetTunnelBridgeTransportType(ti->tile);
8548
225c051343b7 (svn r12126) -Codechange: Use a variable instead of calling the same function a few times
belugas
parents: 8540
diff changeset
   875
	DiagDirection tunnelbridge_direction = GetTunnelBridgeDirection(ti->tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   876
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
   877
	if (IsTunnel(ti->tile)) {
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   878
		/* Front view of tunnel bounding boxes:
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   879
		 *
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   880
		 *   122223  <- BB_Z_SEPARATOR
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   881
		 *   1    3
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   882
		 *   1    3                1,3 = empty helper BB
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   883
		 *   1    3                  2 = SpriteCombine of tunnel-roof and catenary (tram & elrail)
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   884
		 *
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   885
		 */
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   886
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   887
		static const int _tunnel_BB[4][12] = {
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   888
			/*  tunnnel-roof  |  Z-separator  | tram-catenary
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   889
			 * w  h  bb_x bb_y| x   y   w   h |bb_x bb_y w h */
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   890
			{  1,  0, -15, -14,  0, 15, 16,  1, 0, 1, 16, 15 }, // NE
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   891
			{  0,  1, -14, -15, 15,  0,  1, 16, 1, 0, 15, 16 }, // SE
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   892
			{  1,  0, -15, -14,  0, 15, 16,  1, 0, 1, 16, 15 }, // SW
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   893
			{  0,  1, -14, -15, 15,  0,  1, 16, 1, 0, 15, 16 }, // NW
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   894
		};
8548
225c051343b7 (svn r12126) -Codechange: Use a variable instead of calling the same function a few times
belugas
parents: 8540
diff changeset
   895
		const int *BB_data = _tunnel_BB[tunnelbridge_direction];
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   896
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   897
		bool catenary = false;
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   898
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
   899
		if (transport_type == TRANSPORT_RAIL) {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3234
diff changeset
   900
			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
2511
3eb6cb6b750d (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2502
diff changeset
   901
		} else {
3eb6cb6b750d (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2502
diff changeset
   902
			image = SPR_TUNNEL_ENTRY_REAR_ROAD;
3eb6cb6b750d (svn r3037) Don't deduce the sprites for tunnels and level crossings from magic numbers, but fetch them from the central rail info array. This is a preparation step for electrified rails
tron
parents: 2502
diff changeset
   903
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
   905
		if (HasTunnelBridgeSnowOrDesert(ti->tile)) image += 32;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
8548
225c051343b7 (svn r12126) -Codechange: Use a variable instead of calling the same function a few times
belugas
parents: 8540
diff changeset
   907
		image += tunnelbridge_direction * 2;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   908
		DrawGroundSprite(image, PAL_NONE);
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   909
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   910
		/* PBS debugging, draw reserved tracks darker */
10109
882c4c0a5788 (svn r14293) -Change: do not show PBS track reservation in the intro game
smatz
parents: 10107
diff changeset
   911
		if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && (transport_type == TRANSPORT_RAIL && GetTunnelBridgeReservation(ti->tile))) {
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   912
			const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   913
			DrawGroundSprite(DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? rti->base_sprites.single_y : rti->base_sprites.single_x, PALETTE_CRASH);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   914
		}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   915
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
   916
		if (transport_type == TRANSPORT_ROAD) {
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   917
			RoadTypes rts = GetRoadTypes(ti->tile);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   918
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7923
diff changeset
   919
			if (HasBit(rts, ROADTYPE_TRAM)) {
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   920
				static const SpriteID tunnel_sprites[2][4] = { { 28, 78, 79, 27 }, {  5, 76, 77,  4 } };
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   921
8548
225c051343b7 (svn r12126) -Codechange: Use a variable instead of calling the same function a few times
belugas
parents: 8540
diff changeset
   922
				DrawGroundSprite(SPR_TRAMWAY_BASE + tunnel_sprites[rts - ROADTYPES_TRAM][tunnelbridge_direction], PAL_NONE);
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   923
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   924
				/* Do not draw wires if they are invisible */
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   925
				if (!IsInvisibilitySet(TO_CATENARY)) {
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   926
					catenary = true;
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   927
					StartSpriteCombine();
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   928
					AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_CATENARY), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   929
				}
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
   930
			}
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9126
diff changeset
   931
		} else if (HasCatenaryDrawn(GetRailType(ti->tile))) {
10107
fffbd531e73c (svn r14291) -Fix [FS#2288] (r12853): For tunnels DrawCatenary() draws only pillars; DrawCatenaryOnTunnel() draws only wires.
frosch
parents: 10083
diff changeset
   932
			/* Maybe draw pylons on the entry side */
fffbd531e73c (svn r14291) -Fix [FS#2288] (r12853): For tunnels DrawCatenary() draws only pillars; DrawCatenaryOnTunnel() draws only wires.
frosch
parents: 10083
diff changeset
   933
			DrawCatenary(ti);
fffbd531e73c (svn r14291) -Fix [FS#2288] (r12853): For tunnels DrawCatenary() draws only pillars; DrawCatenaryOnTunnel() draws only wires.
frosch
parents: 10083
diff changeset
   934
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   935
			catenary = true;
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   936
			StartSpriteCombine();
10107
fffbd531e73c (svn r14291) -Fix [FS#2288] (r12853): For tunnels DrawCatenary() draws only pillars; DrawCatenaryOnTunnel() draws only wires.
frosch
parents: 10083
diff changeset
   937
			/* Draw wire above the ramp */
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   938
			DrawCatenaryOnTunnel(ti);
6663
3f0ebbd21f88 (svn r9894) -Fix (r9892): catenary was drawn on road bridges ;)
rubidium
parents: 6661
diff changeset
   939
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   941
		AddSortableSpriteToDraw(image + 1, PAL_NONE, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, BB_data[0], BB_data[1], TILE_HEIGHT, ti->z, false, BB_data[2], BB_data[3], BB_Z_SEPARATOR);
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   942
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   943
		if (catenary) EndSpriteCombine();
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   944
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   945
		/* Add helper BB for sprite sorting, that separate the tunnel from things beside of it */
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   946
		AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x             , ti->y             , BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   947
		AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x + BB_data[4], ti->y + BB_data[5], BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   948
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   949
		DrawBridgeMiddle(ti);
8390
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8385
diff changeset
   950
	} else { // IsBridge(ti->tile)
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   951
		const PalSpriteID *psid;
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   952
		int base_offset;
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
   953
		bool ice = HasTunnelBridgeSnowOrDesert(ti->tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
   955
		if (transport_type == TRANSPORT_RAIL) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   956
			base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   957
			assert(base_offset != 8); // This one is used for roads
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   958
		} else {
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3233
diff changeset
   959
			base_offset = 8;
2536
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   960
		}
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   961
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   962
		/* as the lower 3 bits are used for other stuff, make sure they are clear */
634914d741b4 (svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents: 2535
diff changeset
   963
		assert( (base_offset & 0x07) == 0x00);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
8548
225c051343b7 (svn r12126) -Codechange: Use a variable instead of calling the same function a few times
belugas
parents: 8540
diff changeset
   965
		DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(tunnelbridge_direction)));
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   966
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   967
		/* HACK Wizardry to convert the bridge ramp direction into a sprite offset */
8548
225c051343b7 (svn r12126) -Codechange: Use a variable instead of calling the same function a few times
belugas
parents: 8540
diff changeset
   968
		base_offset += (6 - tunnelbridge_direction) % 4;
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   969
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   970
		if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   971
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
   972
		/* Table number BRIDGE_PIECE_HEAD always refers to the bridge heads for any bridge type */
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   973
		if (transport_type != TRANSPORT_WATER) {
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
   974
			psid = &GetBridgeSpriteTable(GetBridgeType(ti->tile), BRIDGE_PIECE_HEAD)[base_offset];
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   975
		} else {
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   976
			psid = _aqueduct_sprites + base_offset;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
   977
		}
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   978
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   979
		if (!ice) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   980
			DrawClearLandTile(ti, 3);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   981
		} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   982
			DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE);
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
   983
		}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   984
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
   985
		/* draw ramp */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   986
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   987
		/* Draw Trambits as SpriteCombine */
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
   988
		if (transport_type == TRANSPORT_ROAD) StartSpriteCombine();
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
   989
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   990
		/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   991
		 * it doesn't disappear behind it
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   992
		 */
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   993
		/* Bridge heads are drawn solid no matter how invisibility/transparency is set */
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
   994
		AddSortableSpriteToDraw(psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
   995
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   996
		if (_settings_client.gui.show_track_reservation && transport_type == TRANSPORT_RAIL && GetTunnelBridgeReservation(ti->tile)) {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   997
			const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   998
			if (HasBridgeFlatRamp(ti->tileh, DiagDirToAxis(tunnelbridge_direction))) {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
   999
				AddSortableSpriteToDraw(DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? rti->base_sprites.single_y : rti->base_sprites.single_x, PALETTE_CRASH, ti->x, ti->y, 16, 16, 0, ti->z + 8);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
  1000
			} else {
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
  1001
				AddSortableSpriteToDraw(rti->base_sprites.single_sloped + tunnelbridge_direction, PALETTE_CRASH, ti->x, ti->y, 16, 16, 8, ti->z);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
  1002
			}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
  1003
		}
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9689
diff changeset
  1004
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
  1005
		if (transport_type == TRANSPORT_ROAD) {
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1006
			RoadTypes rts = GetRoadTypes(ti->tile);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1007
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7923
diff changeset
  1008
			if (HasBit(rts, ROADTYPE_TRAM)) {
8548
225c051343b7 (svn r12126) -Codechange: Use a variable instead of calling the same function a few times
belugas
parents: 8540
diff changeset
  1009
				uint offset = tunnelbridge_direction;
6712
8f21d5cc9418 (svn r9944) -Fix: tile selection drawn on the wrong height for some road bridges.
rubidium
parents: 6708
diff changeset
  1010
				uint z = ti->z;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1011
				if (ti->tileh != SLOPE_FLAT) {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1012
					offset = (offset + 1) & 1;
6712
8f21d5cc9418 (svn r9944) -Fix: tile selection drawn on the wrong height for some road bridges.
rubidium
parents: 6708
diff changeset
  1013
					z += TILE_HEIGHT;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1014
				} else {
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1015
					offset += 2;
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1016
				}
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1017
				/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1018
				DrawBridgeTramBits(ti->x, ti->y, z, offset, HasBit(rts, ROADTYPE_ROAD), true);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1019
			}
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1020
			EndSpriteCombine();
10014
13c9ede0ae49 (svn r14173) -Fix: Don't check for rail type and catenary on aqueducts.
peter1138
parents: 9815
diff changeset
  1021
		} else if (transport_type == TRANSPORT_RAIL) {
13c9ede0ae49 (svn r14173) -Fix: Don't check for rail type and catenary on aqueducts.
peter1138
parents: 9815
diff changeset
  1022
			if (HasCatenaryDrawn(GetRailType(ti->tile))) {
13c9ede0ae49 (svn r14173) -Fix: Don't check for rail type and catenary on aqueducts.
peter1138
parents: 9815
diff changeset
  1023
				DrawCatenary(ti);
13c9ede0ae49 (svn r14173) -Fix: Don't check for rail type and catenary on aqueducts.
peter1138
parents: 9815
diff changeset
  1024
			}
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1025
		}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1026
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1027
		DrawBridgeMiddle(ti);
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
  1028
	}
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
  1029
}
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3900
diff changeset
  1030
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1031
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1032
/** Compute bridge piece. Computes the bridge piece to display depending on the position inside the bridge.
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1033
 * bridges pieces sequence (middle parts).
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1034
 * Note that it is not covering the bridge heads, which are always referenced by the same sprite table.
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1035
 * bridge len 1: BRIDGE_PIECE_NORTH
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1036
 * bridge len 2: BRIDGE_PIECE_NORTH  BRIDGE_PIECE_SOUTH
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1037
 * bridge len 3: BRIDGE_PIECE_NORTH  BRIDGE_PIECE_MIDDLE_ODD   BRIDGE_PIECE_SOUTH
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1038
 * bridge len 4: BRIDGE_PIECE_NORTH  BRIDGE_PIECE_INNER_NORTH  BRIDGE_PIECE_INNER_SOUTH  BRIDGE_PIECE_SOUTH
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1039
 * bridge len 5: BRIDGE_PIECE_NORTH  BRIDGE_PIECE_INNER_NORTH  BRIDGE_PIECE_MIDDLE_EVEN  BRIDGE_PIECE_INNER_SOUTH  BRIDGE_PIECE_SOUTH
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1040
 * bridge len 6: BRIDGE_PIECE_NORTH  BRIDGE_PIECE_INNER_NORTH  BRIDGE_PIECE_INNER_SOUTH  BRIDGE_PIECE_INNER_NORTH  BRIDGE_PIECE_INNER_SOUTH  BRIDGE_PIECE_SOUTH
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1041
 * bridge len 7: BRIDGE_PIECE_NORTH  BRIDGE_PIECE_INNER_NORTH  BRIDGE_PIECE_INNER_SOUTH  BRIDGE_PIECE_MIDDLE_ODD   BRIDGE_PIECE_INNER_NORTH  BRIDGE_PIECE_INNER_SOUTH  BRIDGE_PIECE_SOUTH
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1042
 * #0 - always as first, #1 - always as last (if len>1)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1043
 * #2,#3 are to pair in order
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1044
 * for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1045
 * @param north Northernmost tile of bridge
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1046
 * @param south Southernmost tile of bridge
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1047
 * @return Index of bridge piece
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1048
 */
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1049
static BridgePieces CalcBridgePiece(uint north, uint south)
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1050
{
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1051
	if (north == 1) {
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1052
		return BRIDGE_PIECE_NORTH;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1053
	} else if (south == 1) {
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1054
		return BRIDGE_PIECE_SOUTH;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1055
	} else if (north < south) {
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1056
		return north & 1 ? BRIDGE_PIECE_INNER_SOUTH : BRIDGE_PIECE_INNER_NORTH;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1057
	} else if (north > south) {
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1058
		return south & 1 ? BRIDGE_PIECE_INNER_NORTH : BRIDGE_PIECE_INNER_SOUTH;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1059
	} else {
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1060
		return north & 1 ? BRIDGE_PIECE_MIDDLE_EVEN : BRIDGE_PIECE_MIDDLE_ODD;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1061
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1062
}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1063
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1064
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1065
void DrawBridgeMiddle(const TileInfo* ti)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1066
{
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1067
	/* Sectional view of bridge bounding boxes:
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1068
	 *
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1069
	 *  1           2                                1,2 = SpriteCombine of Bridge front/(back&floor) and TramCatenary
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1070
	 *  1           2                                  3 = empty helper BB
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1071
	 *  1     7     2                                4,5 = pillars under higher bridges
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1072
	 *  1 6 88888 6 2                                  6 = elrail-pylons
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1073
	 *  1 6 88888 6 2                                  7 = elrail-wire
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1074
	 *  1 6 88888 6 2  <- TILE_HEIGHT                  8 = rail-vehicle on bridge
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1075
	 *  3333333333333  <- BB_Z_SEPARATOR
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1076
	 *                 <- unused
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1077
	 *    4       5    <- BB_HEIGHT_UNDER_BRIDGE
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1078
	 *    4       5
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1079
	 *    4       5
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1080
	 *
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1081
	 */
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1082
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1083
	/* Z position of the bridge sprites relative to bridge height (downwards) */
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1084
	static const int BRIDGE_Z_START = 3;
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1085
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1086
	if (!IsBridgeAbove(ti->tile)) return;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1087
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1088
	TileIndex rampnorth = GetNorthernBridgeEnd(ti->tile);
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1089
	TileIndex rampsouth = GetSouthernBridgeEnd(ti->tile);
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1090
	TransportType transport_type = GetTunnelBridgeTransportType(rampsouth);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1091
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1092
	Axis axis = GetBridgeAxis(ti->tile);
9642
0a700db0611c (svn r13705) -Codechange: Define and use BridgePieces enum, which will remove a few more magic numbers
belugas
parents: 9596
diff changeset
  1093
	BridgePieces piece = CalcBridgePiece(
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8390
diff changeset
  1094
		GetTunnelBridgeLength(ti->tile, rampnorth) + 1,
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8390
diff changeset
  1095
		GetTunnelBridgeLength(ti->tile, rampsouth) + 1
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1096
	);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1097
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1098
	const PalSpriteID *psid;
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1099
	bool drawfarpillar;
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1100
	if (transport_type != TRANSPORT_WATER) {
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1101
		BridgeType type =  GetBridgeType(rampsouth);
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1102
		drawfarpillar = !HasBit(GetBridgeSpec(type)->flags, 0);
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1103
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1104
		uint base_offset;
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1105
		if (transport_type == TRANSPORT_RAIL) {
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1106
			base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1107
		} else {
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1108
			base_offset = 8;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1109
		}
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1110
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1111
		psid = base_offset + GetBridgeSpriteTable(type, piece);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1112
	} else {
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1113
		drawfarpillar = true;
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1114
		psid = _aqueduct_sprites;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1115
	}
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1116
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1117
	if (axis != AXIS_X) psid += 4;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1118
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1119
	int x = ti->x;
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1120
	int y = ti->y;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1121
	uint bridge_z = GetBridgeHeight(rampsouth);
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1122
	uint z = bridge_z - BRIDGE_Z_START;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1123
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1124
	/* Add a bounding box, that separates the bridge from things below it. */
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1125
	AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, x, y, 16, 16, 1, bridge_z - TILE_HEIGHT + BB_Z_SEPARATOR);
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1126
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1127
	/* Draw Trambits as SpriteCombine */
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
  1128
	if (transport_type == TRANSPORT_ROAD) StartSpriteCombine();
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1129
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1130
	/* Draw floor and far part of bridge*/
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1131
	if (!IsInvisibilitySet(TO_BRIDGES)) {
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1132
		if (axis == AXIS_X) {
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1133
			AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1134
		} else {
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1135
			AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START);
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1136
		}
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1137
	}
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1138
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1139
	psid++;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1140
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
  1141
	if (transport_type == TRANSPORT_ROAD) {
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1142
		RoadTypes rts = GetRoadTypes(rampsouth);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1143
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7923
diff changeset
  1144
		if (HasBit(rts, ROADTYPE_TRAM)) {
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1145
			/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1146
			DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HasBit(rts, ROADTYPE_ROAD), false);
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1147
		} else {
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1148
			EndSpriteCombine();
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1149
			StartSpriteCombine();
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6687
diff changeset
  1150
		}
10014
13c9ede0ae49 (svn r14173) -Fix: Don't check for rail type and catenary on aqueducts.
peter1138
parents: 9815
diff changeset
  1151
	} else if (transport_type == TRANSPORT_RAIL) {
13c9ede0ae49 (svn r14173) -Fix: Don't check for rail type and catenary on aqueducts.
peter1138
parents: 9815
diff changeset
  1152
		if (HasCatenaryDrawn(GetRailType(rampsouth))) {
13c9ede0ae49 (svn r14173) -Fix: Don't check for rail type and catenary on aqueducts.
peter1138
parents: 9815
diff changeset
  1153
			DrawCatenaryOnBridge(ti);
13c9ede0ae49 (svn r14173) -Fix: Don't check for rail type and catenary on aqueducts.
peter1138
parents: 9815
diff changeset
  1154
		}
6687
c7b92f03d33f (svn r9919) -Codechange: prepare some more places for more road types.
rubidium
parents: 6683
diff changeset
  1155
	}
c7b92f03d33f (svn r9919) -Codechange: prepare some more places for more road types.
rubidium
parents: 6683
diff changeset
  1156
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1157
	/* draw roof, the component of the bridge which is logically between the vehicle and the camera */
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1158
	if (!IsInvisibilitySet(TO_BRIDGES)) {
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1159
		if (axis == AXIS_X) {
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1160
			y += 12;
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1161
			if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 4, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 3, BRIDGE_Z_START);
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1162
		} else {
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1163
			x += 12;
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1164
			if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 4, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 3, 0, BRIDGE_Z_START);
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1165
		}
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1166
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1167
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1168
	/* Draw TramFront as SpriteCombine */
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
  1169
	if (transport_type == TRANSPORT_ROAD) EndSpriteCombine();
7601
988040ee27f4 (svn r11128) -Fix: a lot of graphical glitches by changing some bounding boxes. It's not perfect yet, but a *very* good step into the right direction. Patch by frosch.
rubidium
parents: 7587
diff changeset
  1170
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1171
	/* Do not draw anything more if bridges are invisible */
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1172
	if (IsInvisibilitySet(TO_BRIDGES)) return;
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8786
diff changeset
  1173
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1174
	psid++;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1175
	if (ti->z + 5 == z) {
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1176
		/* draw poles below for small bridges */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1177
		if (psid->sprite != 0) {
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7308
diff changeset
  1178
			SpriteID image = psid->sprite;
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7308
diff changeset
  1179
			SpriteID pal   = psid->pal;
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7845
diff changeset
  1180
			if (IsTransparencySet(TO_BRIDGES)) {
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  1181
				SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1182
				pal = PALETTE_TO_TRANSPARENT;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1183
			}
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1184
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
  1185
			DrawGroundSpriteAt(image, pal, x, y, z);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1186
		}
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
  1187
	} else if (_settings_client.gui.bridge_pillars) {
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1188
		/* draw pillars below for high bridges */
9498
b9499aab5896 (svn r13478) -Codechange: don't use GetBridgeSpec() for aqueducts
smatz
parents: 9497
diff changeset
  1189
		DrawBridgePillars(psid, ti, axis, drawfarpillar, x, y, z);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1190
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1191
}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1192
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1193
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1194
static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
2537
5e4ca74e995a (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2536
diff changeset
  1195
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1196
	uint z;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1197
	Slope tileh = GetTileSlope(tile, &z);
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1198
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1199
	x &= 0xF;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
  1200
	y &= 0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1202
	if (IsTunnel(tile)) {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
  1203
		uint pos = (DiagDirToAxis(GetTunnelBridgeDirection(tile)) == AXIS_X ? y : x);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1205
		/* In the tunnel entrance? */
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1206
		if (5 <= pos && pos <= 10) return z;
8390
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8385
diff changeset
  1207
	} else { // IsBridge(tile)
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
  1208
		DiagDirection dir = GetTunnelBridgeDirection(tile);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1209
		uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3938
diff changeset
  1210
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
  1211
		z += ApplyFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh);
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
  1212
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1213
		/* On the bridge ramp? */
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1214
		if (5 <= pos && pos <= 10) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1215
			uint delta;
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4239
diff changeset
  1216
8379
94fcc26a241a (svn r11946) -Fix: slope detection of bridge ramps.
frosch
parents: 8371
diff changeset
  1217
			if (tileh != SLOPE_FLAT) return z + TILE_HEIGHT;
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1218
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1219
			switch (dir) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1220
				default: NOT_REACHED();
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1221
				case DIAGDIR_NE: delta = (TILE_SIZE - 1 - x) / 2; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1222
				case DIAGDIR_SE: delta = y / 2; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1223
				case DIAGDIR_SW: delta = x / 2; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1224
				case DIAGDIR_NW: delta = (TILE_SIZE - 1 - y) / 2; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1225
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1226
			return z + 1 + delta;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
3517
f57c12df9a26 (svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents: 3493
diff changeset
  1230
	return z + GetPartialZ(x, y, tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
  1233
static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1234
{
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
  1235
	return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(tile)));
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1236
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1237
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 38
diff changeset
  1238
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1239
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1244
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
{
9497
4af8ca812437 (svn r13477) -Fix (r13464): correct tile type in the Query tile info window
smatz
parents: 9495
diff changeset
  1246
	TransportType tt = GetTunnelBridgeTransportType(tile);
4af8ca812437 (svn r13477) -Fix (r13464): correct tile type in the Query tile info window
smatz
parents: 9495
diff changeset
  1247
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
  1248
	if (IsTunnel(tile)) {
9497
4af8ca812437 (svn r13477) -Fix (r13464): correct tile type in the Query tile info window
smatz
parents: 9495
diff changeset
  1249
		td->str = (tt == TRANSPORT_RAIL) ? STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
4af8ca812437 (svn r13477) -Fix (r13464): correct tile type in the Query tile info window
smatz
parents: 9495
diff changeset
  1250
	} else { // IsBridge(tile)
4af8ca812437 (svn r13477) -Fix (r13464): correct tile type in the Query tile info window
smatz
parents: 9495
diff changeset
  1251
		td->str = (tt == TRANSPORT_WATER) ? STR_AQUEDUCT : GetBridgeSpec(GetBridgeType(tile))->transport_name[tt];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
	}
9322
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9224
diff changeset
  1253
	td->owner[0] = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1257
static void AnimateTile_TunnelBridge(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1262
static void TileLoop_TunnelBridge(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
{
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1264
	bool snow_or_desert = HasTunnelBridgeSnowOrDesert(tile);
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
  1265
	switch (_settings_game.game_creation.landscape) {
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1266
		case LT_ARCTIC:
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6259
diff changeset
  1267
			if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) {
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1268
				SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
4160
81dfe1debead (svn r5592) Merge two complementary cases
tron
parents: 4158
diff changeset
  1269
				MarkTileDirtyByTile(tile);
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1270
			}
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1271
			break;
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1272
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1273
		case LT_TROPIC:
5410
2dae82c6ea63 (svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents: 5385
diff changeset
  1274
			if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) {
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1275
				SetTunnelBridgeSnowOrDesert(tile, true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
			}
3017
a75caf4efa2d (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
  1278
			break;
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1279
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1280
		default:
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8083
diff changeset
  1281
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1930
diff changeset
  1285
static void ClickTile_TunnelBridge(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  1291
static TrackStatus GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
{
8549
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
  1293
	TransportType transport_type = GetTunnelBridgeTransportType(tile);
fe0906311446 (svn r12127) -Codechange: Use a variable instead of calling the same function a few times. Again. Just a different value.
belugas
parents: 8548
diff changeset
  1294
	if (transport_type != mode || (transport_type == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0)) return 0;
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8590
diff changeset
  1295
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8590
diff changeset
  1296
	DiagDirection dir = GetTunnelBridgeDirection(tile);
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8590
diff changeset
  1297
	if (side != INVALID_DIAGDIR && side != ReverseDiagDir(dir)) return 0;
9224
93528d9cb96d (svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents: 9154
diff changeset
  1298
	return CombineTrackStatus(TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir)), TRACKDIR_BIT_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
  1301
static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner new_owner)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
  1303
	if (!IsTileOwner(tile, old_owner)) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1304
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
  1305
	if (new_owner != INVALID_OWNER) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10140
diff changeset
  1306
		SetTileOwner(tile, new_owner);
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4344
diff changeset
  1307
	} else {
8519
fe61d7aa3053 (svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
smatz
parents: 8491
diff changeset
  1308
		if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR))) {
6734
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1309
			/* When clearing the bridge/tunnel failed there are still vehicles on/in
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1310
			 * the bridge/tunnel. As all *our* vehicles are already removed, they
9495
cafcf9e8dbdf (svn r13475) -Fix (r13464): crash on destroying aquaduct with ship on in and on company bankrupt
smatz
parents: 9492
diff changeset
  1311
			 * must be of another owner. Therefore this can't be rail tunnel/bridge.
6734
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1312
			 * In that case we can safely reassign the ownership to OWNER_NONE. */
9495
cafcf9e8dbdf (svn r13475) -Fix (r13464): crash on destroying aquaduct with ship on in and on company bankrupt
smatz
parents: 9492
diff changeset
  1313
			assert(GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL);
6734
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1314
			SetTileOwner(tile, OWNER_NONE);
b87538491b71 (svn r9966) -Fix: bridges and tunnels were not always removed on bankruptcy, thus leaving tunnels/bridges with an invalid owner that would crash the game when clicking with the query tool on them.
rubidium
parents: 6712
diff changeset
  1315
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1320
static const byte _tunnel_fractcoord_1[4]    = {0x8E, 0x18, 0x81, 0xE8};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1321
static const byte _tunnel_fractcoord_2[4]    = {0x81, 0x98, 0x87, 0x38};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1322
static const byte _tunnel_fractcoord_3[4]    = {0x82, 0x88, 0x86, 0x48};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1323
static const byte _exit_tunnel_track[4]      = {1, 2, 1, 2};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1325
/** Get the trackdir of the exit of a tunnel */
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1326
static const Trackdir _road_exit_tunnel_state[DIAGDIR_END] = {
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1327
	TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1328
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1331
static const byte _tunnel_fractcoord_4[4]    = {0x52, 0x85, 0x98, 0x29};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1332
static const byte _tunnel_fractcoord_5[4]    = {0x92, 0x89, 0x58, 0x25};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1333
static const byte _tunnel_fractcoord_6[4]    = {0x92, 0x89, 0x56, 0x45};
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1334
static const byte _tunnel_fractcoord_7[4]    = {0x52, 0x85, 0x96, 0x49};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
  1336
static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
{
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1338
	int z = GetSlopeZ(x, y) - v->z_pos;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1339
7923
91982bd3c549 (svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents: 7857
diff changeset
  1340
	if (abs(z) > 2) return VETSB_CANNOT_ENTER;
8548
225c051343b7 (svn r12126) -Codechange: Use a variable instead of calling the same function a few times
belugas
parents: 8540
diff changeset
  1341
	const DiagDirection dir = GetTunnelBridgeDirection(tile);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1342
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3183
diff changeset
  1343
	if (IsTunnel(tile)) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2958
diff changeset
  1344
		byte fc;
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1345
		DiagDirection vdir;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2958
diff changeset
  1346
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1347
		if (v->type == VEH_TRAIN) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1348
			fc = (x & 0xF) + (y << 4);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1349
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1350
			vdir = DirToDiagDir(v->direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
5993
956d341d930e (svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents: 5991
diff changeset
  1352
			if (v->u.rail.track != TRACK_BIT_WORMHOLE && dir == vdir) {
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2663
diff changeset
  1353
				if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) {
6213
20e4832abe9a (svn r9009) -Fix (r1): Determine whether to play a sound or not when entering a tunnel based on engine type (only steam engines) instead of on spritenum which can be invalid for newgrf trains. DBSet(XL) or any other steam trains without newsounds should sound their horn now.
Darkvater
parents: 6141
diff changeset
  1354
					if (!PlayVehicleSound(v, VSE_TUNNEL) && RailVehInfo(v->engine_type)->engclass == 0) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1355
						SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
4656
9c1d8c4d3e60 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4559
diff changeset
  1356
					}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1357
					return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
				if (fc == _tunnel_fractcoord_2[dir]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
					v->tile = tile;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1361
					v->u.rail.track = TRACK_BIT_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
					v->vehstatus |= VS_HIDDEN;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1363
					return VETSB_ENTERED_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1367
			if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) {
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  1368
				/* We're at the tunnel exit ?? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
				v->tile = tile;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1370
				v->u.rail.track = (TrackBits)_exit_tunnel_track[dir];
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1209
diff changeset
  1371
				assert(v->u.rail.track);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
				v->vehstatus &= ~VS_HIDDEN;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1373
				return VETSB_ENTERED_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
			}
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1375
		} else if (v->type == VEH_ROAD) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1376
			fc = (x & 0xF) + (y << 4);
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1377
			vdir = DirToDiagDir(v->direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
6422
6679df1c05ba (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6406
diff changeset
  1379
			/* Enter tunnel? */
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1380
			if (v->u.road.state != RVSB_WORMHOLE && dir == vdir) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
				if (fc == _tunnel_fractcoord_4[dir] ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
						fc == _tunnel_fractcoord_5[dir]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
					v->tile = tile;
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5993
diff changeset
  1384
					v->u.road.state = RVSB_WORMHOLE;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1385
					v->vehstatus |= VS_HIDDEN;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1386
					return VETSB_ENTERED_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
				} else {
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1388
					return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  1392
			if (dir == ReverseDiagDir(vdir) && (
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1393
						/* We're at the tunnel exit ?? */
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1394
						fc == _tunnel_fractcoord_6[dir] ||
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1395
						fc == _tunnel_fractcoord_7[dir]
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
  1396
					) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
					z == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
				v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
				v->u.road.state = _road_exit_tunnel_state[dir];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
				v->u.road.frame = _road_exit_tunnel_frame[dir];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
				v->vehstatus &= ~VS_HIDDEN;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1402
				return VETSB_ENTERED_WORMHOLE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
		}
8390
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8385
diff changeset
  1405
	} else { // IsBridge(tile)
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1406
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1407
		if (v->IsPrimaryVehicle() && v->type != VEH_SHIP) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1408
			/* modify speed of vehicle */
8491
97fcf662c3c3 (svn r12066) -Codechange: Rename GetBridge for the more common GetBridgeSpec
belugas
parents: 8489
diff changeset
  1409
			uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1410
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  1411
			if (v->type == VEH_ROAD) spd *= 2;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1412
			if (v->cur_speed > spd) v->cur_speed = spd;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1413
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1414
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1415
		if (DirToDiagDir(v->direction) == dir) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1416
			switch (dir) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1417
				default: NOT_REACHED();
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1418
				case DIAGDIR_NE: if ((x & 0xF) != 0)             return VETSB_CONTINUE; break;
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1419
				case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1420
				case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1421
				case DIAGDIR_NW: if ((y & 0xF) != 0)             return VETSB_CONTINUE; break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
			}
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1423
			switch (v->type) {
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1424
				case VEH_TRAIN:
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1425
					v->u.rail.track = TRACK_BIT_WORMHOLE;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1426
					ClrBit(v->u.rail.flags, VRF_GOINGUP);
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1427
					ClrBit(v->u.rail.flags, VRF_GOINGDOWN);
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1428
					break;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1429
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1430
				case VEH_ROAD:
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1431
					v->u.road.state = RVSB_WORMHOLE;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1432
					break;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1433
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1434
				case VEH_SHIP:
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1435
					v->u.ship.state = TRACK_BIT_WORMHOLE;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1436
					break;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1437
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1438
				default: NOT_REACHED();
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1439
			}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1440
			return VETSB_ENTERED_WORMHOLE;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1441
		} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1442
			v->tile = tile;
9490
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1443
			switch (v->type) {
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1444
				case VEH_TRAIN:
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1445
					if (v->u.rail.track == TRACK_BIT_WORMHOLE) {
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1446
						v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1447
						return VETSB_ENTERED_WORMHOLE;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1448
					}
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1449
					break;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1450
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1451
				case VEH_ROAD:
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1452
					if (v->u.road.state == RVSB_WORMHOLE) {
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1453
						v->u.road.state = _road_exit_tunnel_state[dir];
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1454
						v->u.road.frame = 0;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1455
						return VETSB_ENTERED_WORMHOLE;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1456
					}
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1457
					break;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1458
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1459
				case VEH_SHIP:
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1460
					if (v->u.ship.state == TRACK_BIT_WORMHOLE) {
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1461
						v->u.ship.state = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1462
						return VETSB_ENTERED_WORMHOLE;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1463
					}
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1464
					break;
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1465
01c07bde5e84 (svn r13464) -Codechange: support NewGRF Action 0x05, type 12.
rubidium
parents: 9413
diff changeset
  1466
				default: NOT_REACHED();
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5116
diff changeset
  1467
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
	}
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5930
diff changeset
  1470
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7472
diff changeset
  1473
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7472
diff changeset
  1474
{
9492
cbd8e40186c3 (svn r13468) -Fix: make aqueducts a little more expensive than normal bridges and disable terraforming of aqueduct bridgeheads; one can't terraform normal canal tiles either.
rubidium
parents: 9491
diff changeset
  1475
	if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() && IsBridge(tile) && GetTunnelBridgeTransportType(tile) != TRANSPORT_WATER) {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8081
diff changeset
  1476
		DiagDirection direction = GetTunnelBridgeDirection(tile);
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
  1477
		Axis axis = DiagDirToAxis(direction);
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
  1478
		CommandCost res;
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
  1479
		uint z_old;
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
  1480
		Slope tileh_old = GetTileSlope(tile, &z_old);
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
  1481
10017
c0eb11a864d7 (svn r14176) -Fix: better 'safe' than ... 'save'
smatz
parents: 10014
diff changeset
  1482
		/* Check if new slope is valid for bridges in general (so we can safely call GetBridgeFoundation()) */
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
  1483
		if ((direction == DIAGDIR_NW) || (direction == DIAGDIR_NE)) {
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
  1484
			CheckBridgeSlopeSouth(axis, &tileh_old, &z_old);
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
  1485
			res = CheckBridgeSlopeSouth(axis, &tileh_new, &z_new);
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
  1486
		} else {
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
  1487
			CheckBridgeSlopeNorth(axis, &tileh_old, &z_old);
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
  1488
			res = CheckBridgeSlopeNorth(axis, &tileh_new, &z_new);
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
  1489
		}
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
  1490
8371
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
  1491
		/* Surface slope is valid and remains unchanged? */
64082018161f (svn r11937) -Feature: Allow building bridge heads on more slopes.
frosch
parents: 8370
diff changeset
  1492
		if (!CmdFailed(res) && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
  1493
	}
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7548
diff changeset
  1494
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7472
diff changeset
  1495
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7472
diff changeset
  1496
}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7472
diff changeset
  1497
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1498
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1499
	DrawTile_TunnelBridge,           /* draw_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1500
	GetSlopeZ_TunnelBridge,          /* get_slope_z_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1501
	ClearTile_TunnelBridge,          /* clear_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1502
	GetAcceptedCargo_TunnelBridge,   /* get_accepted_cargo_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1503
	GetTileDesc_TunnelBridge,        /* get_tile_desc_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1504
	GetTileTrackStatus_TunnelBridge, /* get_tile_track_status_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1505
	ClickTile_TunnelBridge,          /* click_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1506
	AnimateTile_TunnelBridge,        /* animate_tile_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1507
	TileLoop_TunnelBridge,           /* tile_loop_clear */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1508
	ChangeTileOwner_TunnelBridge,    /* change_tile_owner_clear */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1509
	NULL,                            /* get_produced_cargo_proc */
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4304
diff changeset
  1510
	VehicleEnter_TunnelBridge,       /* vehicle_enter_tile_proc */
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
  1511
	GetFoundation_TunnelBridge,      /* get_foundation_proc */
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7472
diff changeset
  1512
	TerraformTile_TunnelBridge,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
};