author | glx |
Fri, 13 Jun 2008 15:43:39 +0000 | |
branch | noai |
changeset 10955 | 56b381e5253f |
parent 10920 | e33442a2b239 |
child 11126 | 72d4c9314c72 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6443
b8f06d8eb7be
(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:
6432
diff
changeset
|
3 |
/** @file tunnelbridge_cmd.cpp |
2262
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
4 |
* This file deals with tunnels and bridges (non-gui stuff) |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
5 |
* @todo seperate this file into two |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
6 |
*/ |
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
7 |
|
0 | 8 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1884
diff
changeset
|
9 |
#include "openttd.h" |
3189
1af302c5abd0
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
tron
parents:
3188
diff
changeset
|
10 |
#include "bridge_map.h" |
3187
0813719b05a9
(svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents:
3184
diff
changeset
|
11 |
#include "rail_map.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3069
diff
changeset
|
12 |
#include "road_map.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
13 |
#include "tile_cmd.h" |
9505 | 14 |
#include "landscape.h" |
3154 | 15 |
#include "tunnel_map.h" |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
16 |
#include "unmovable_map.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
17 |
#include "viewport_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
18 |
#include "command_func.h" |
0 | 19 |
#include "town.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
20 |
#include "variables.h" |
2262
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
21 |
#include "bridge.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2663
diff
changeset
|
22 |
#include "train.h" |
3187
0813719b05a9
(svn r3837) Partially unmagicfy restoring the tiles when deleting a bridge
tron
parents:
3184
diff
changeset
|
23 |
#include "water_map.h" |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3881
diff
changeset
|
24 |
#include "yapf/yapf.h" |
4656
acffecd6f484
(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" |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
26 |
#include "autoslope.h" |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
27 |
#include "transparency.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
28 |
#include "tunnelbridge_map.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
29 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
30 |
#include "date_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
31 |
#include "functions.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
32 |
#include "vehicle_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
33 |
#include "sound_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
34 |
#include "signal_func.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
35 |
#include "tunnelbridge.h" |
9732 | 36 |
#include "player_base.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
37 |
#include "engine_func.h" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
38 |
#include "engine_base.h" |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10142
diff
changeset
|
39 |
#include "economy_func.h" |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10142
diff
changeset
|
40 |
#include "rail.h" |
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10142
diff
changeset
|
41 |
#include "cheat_func.h" |
10513
33cb70ff2f5d
(svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents:
10455
diff
changeset
|
42 |
#include "elrail_func.h" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10355
diff
changeset
|
43 |
#include "landscape_type.h" |
0 | 44 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
45 |
#include "table/sprites.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
46 |
#include "table/strings.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
47 |
#include "table/bridge_land.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
48 |
|
9732 | 49 |
BridgeSpec _bridge[MAX_BRIDGES]; |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10142
diff
changeset
|
50 |
TileIndex _build_tunnel_endtile; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
51 |
|
9732 | 52 |
/** Reset the data been eventually changed by the grf loaded. */ |
53 |
void ResetBridges() |
|
54 |
{ |
|
55 |
/* First, free sprite table data */ |
|
56 |
for (BridgeType i = 0; i < MAX_BRIDGES; i++) { |
|
57 |
if (_bridge[i].sprite_table != NULL) { |
|
58 |
for (uint j = 0; j < 7; j++) free(_bridge[i].sprite_table[j]); |
|
59 |
free(_bridge[i].sprite_table); |
|
60 |
} |
|
61 |
} |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
62 |
|
9732 | 63 |
/* Then, wipe out current bidges */ |
64 |
memset(&_bridge, 0, sizeof(_bridge)); |
|
65 |
/* And finally, reinstall default data */ |
|
66 |
memcpy(&_bridge, &_orig_bridge, sizeof(_orig_bridge)); |
|
67 |
} |
|
2763 | 68 |
|
9574 | 69 |
/** calculate the price factor for building a long bridge. |
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, |
|
71 |
*/ |
|
0 | 72 |
int CalcBridgeLenCostFactor(int x) |
73 |
{ |
|
2639 | 74 |
int n; |
75 |
int r; |
|
76 |
||
0 | 77 |
if (x < 2) return x; |
78 |
x -= 2; |
|
2639 | 79 |
for (n = 0, r = 2;; n++) { |
0 | 80 |
if (x <= n) return r + x * n; |
81 |
r += n * n; |
|
82 |
x -= n; |
|
83 |
} |
|
84 |
} |
|
85 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
86 |
Foundation GetBridgeFoundation(Slope tileh, Axis axis) |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
87 |
{ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
88 |
if ((tileh == SLOPE_FLAT) || |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
89 |
(((tileh == SLOPE_NE) || (tileh == SLOPE_SW)) && (axis == AXIS_X)) || |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
90 |
(((tileh == SLOPE_NW) || (tileh == SLOPE_SE)) && (axis == AXIS_Y))) return FOUNDATION_NONE; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
91 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
92 |
return (HasSlopeHighestCorner(tileh) ? InclinedFoundation(axis) : FlatteningFoundation(tileh)); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
93 |
} |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
94 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
95 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
96 |
* Determines if the track on a bridge ramp is flat or goes up/down. |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
97 |
* |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
98 |
* @param tileh Slope of the tile under the bridge head |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
99 |
* @param axis Orientation of bridge |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
100 |
* @return true iff the track is flat. |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
101 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
102 |
bool HasBridgeFlatRamp(Slope tileh, Axis axis) |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
103 |
{ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
104 |
ApplyFoundationToSlope(GetBridgeFoundation(tileh, axis), &tileh); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
105 |
/* If the foundation slope is flat the bridge has a non-flat ramp and vice versa. */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
106 |
return (tileh != SLOPE_FLAT); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
107 |
} |
0 | 108 |
|
2478
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
109 |
static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table) |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
110 |
{ |
9732 | 111 |
const BridgeSpec *bridge = GetBridgeSpec(index); |
2478
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
112 |
assert(table < 7); |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
113 |
if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) { |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
114 |
return _bridge_sprite_table[index][table]; |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
115 |
} else { |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
116 |
return bridge->sprite_table[table]; |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
117 |
} |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
118 |
} |
16b05f1de6bb
(svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents:
2436
diff
changeset
|
119 |
|
0 | 120 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
121 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
122 |
* Determines the foundation for the north bridge head, and tests if the resulting slope is valid. |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
123 |
* |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
124 |
* @param axis Axis of the bridge |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
125 |
* @param tileh Slope of the tile under the north bridge head; returns slope on top of foundation |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
126 |
* @param z TileZ corresponding to tileh, gets modified as well |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
127 |
* @return Error or cost for bridge foundation |
4239
9ec74a9b8b58
(svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents:
4231
diff
changeset
|
128 |
*/ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
129 |
static CommandCost CheckBridgeSlopeNorth(Axis axis, Slope *tileh, uint *z) |
4239
9ec74a9b8b58
(svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents:
4231
diff
changeset
|
130 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
131 |
Foundation f = GetBridgeFoundation(*tileh, axis); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
132 |
*z += ApplyFoundationToSlope(f, tileh); |
0 | 133 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
134 |
Slope valid_inclined = (axis == AXIS_X ? SLOPE_NE : SLOPE_NW); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
135 |
if ((*tileh != SLOPE_FLAT) && (*tileh != valid_inclined)) return CMD_ERROR; |
2639 | 136 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
137 |
if (f == FOUNDATION_NONE) return CommandCost(); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
138 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
139 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
0 | 140 |
} |
141 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
142 |
/** |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
143 |
* Determines the foundation for the south bridge head, and tests if the resulting slope is valid. |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
144 |
* |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
145 |
* @param axis Axis of the bridge |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
146 |
* @param tileh Slope of the tile under the south bridge head; returns slope on top of foundation |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
147 |
* @param z TileZ corresponding to tileh, gets modified as well |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
148 |
* @return Error or cost for bridge foundation |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
149 |
*/ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
150 |
static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope *tileh, uint *z) |
4239
9ec74a9b8b58
(svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents:
4231
diff
changeset
|
151 |
{ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
152 |
Foundation f = GetBridgeFoundation(*tileh, axis); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
153 |
*z += ApplyFoundationToSlope(f, tileh); |
4239
9ec74a9b8b58
(svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents:
4231
diff
changeset
|
154 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
155 |
Slope valid_inclined = (axis == AXIS_X ? SLOPE_SW : SLOPE_SE); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
156 |
if ((*tileh != SLOPE_FLAT) && (*tileh != valid_inclined)) return CMD_ERROR; |
4239
9ec74a9b8b58
(svn r5809) Turn the tests for valid bridge ramp slopes into something comprehensible
tron
parents:
4231
diff
changeset
|
157 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
158 |
if (f == FOUNDATION_NONE) return CommandCost(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
159 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
160 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
0 | 161 |
} |
162 |
||
9732 | 163 |
bool CheckBridge_Stuff(BridgeType bridge_type, uint bridge_len) |
0 | 164 |
{ |
9732 | 165 |
const BridgeSpec *b = GetBridgeSpec(bridge_type); |
2639 | 166 |
uint max; // max possible length of a bridge (with patch 100) |
0 | 167 |
|
1781
92e08797c84b
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
168 |
if (bridge_type >= MAX_BRIDGES) return false; |
2262
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
169 |
if (b->avail_year > _cur_year) return false; |
0 | 170 |
|
2262
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
171 |
max = b->max_length; |
10776 | 172 |
if (max >= 16 && _settings_game.construction.longbridges) max = 100; |
0 | 173 |
|
2639 | 174 |
return b->min_length <= bridge_len && bridge_len <= max; |
0 | 175 |
} |
176 |
||
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
177 |
/** Build a Bridge |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
178 |
* @param end_tile end tile |
9574 | 179 |
* @param flags type of operation |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
180 |
* @param p1 packed start tile coords (~ dx) |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
181 |
* @param p2 various bitstuffed elements |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
182 |
* - p2 = (bit 0- 7) - bridge type (hi bh) |
9624 | 183 |
* - p2 = (bit 8-..) - rail type or road types. |
184 |
* - p2 = (bit 15 ) - set means road bridge. |
|
0 | 185 |
*/ |
9629 | 186 |
CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 187 |
{ |
9732 | 188 |
BridgeType bridge_type; |
189 |
RailType railtype = INVALID_RAILTYPE; |
|
190 |
RoadTypes roadtypes = ROADTYPES_NONE; |
|
3853
c49992ab497b
(svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents:
3794
diff
changeset
|
191 |
uint x; |
c49992ab497b
(svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents:
3794
diff
changeset
|
192 |
uint y; |
c49992ab497b
(svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents:
3794
diff
changeset
|
193 |
uint sx; |
c49992ab497b
(svn r4881) -Codechange: Be a little more strict about types and remove some null-operations
celestar
parents:
3794
diff
changeset
|
194 |
uint sy; |
3301
4ac662c79ad3
(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents:
3267
diff
changeset
|
195 |
TileIndex tile_start; |
4ac662c79ad3
(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents:
3267
diff
changeset
|
196 |
TileIndex tile_end; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3556
diff
changeset
|
197 |
Slope tileh_start; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3556
diff
changeset
|
198 |
Slope tileh_end; |
3301
4ac662c79ad3
(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents:
3267
diff
changeset
|
199 |
uint z_start; |
4ac662c79ad3
(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents:
3267
diff
changeset
|
200 |
uint z_end; |
3178
c275826135da
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
201 |
TileIndex tile; |
c275826135da
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
202 |
TileIndexDiff delta; |
2639 | 203 |
uint bridge_len; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
204 |
Axis direction; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
205 |
CommandCost cost(EXPENSES_CONSTRUCTION); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
206 |
CommandCost ret; |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
207 |
bool replace_bridge = false; |
9732 | 208 |
BridgeType replaced_bridge_type; |
209 |
TransportType transport_type; |
|
0 | 210 |
|
211 |
/* unpack parameters */ |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
212 |
bridge_type = GB(p2, 0, 8); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
213 |
|
2934
3b7eef9871f8
(svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents:
2931
diff
changeset
|
214 |
if (p1 >= MapSize()) return CMD_ERROR; |
1775
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
215 |
|
9732 | 216 |
transport_type = (TransportType)GB(p2, 15, 2); |
217 |
||
9574 | 218 |
/* type of bridge */ |
9732 | 219 |
switch (transport_type) { |
220 |
case TRANSPORT_ROAD: |
|
221 |
roadtypes = (RoadTypes)GB(p2, 8, 3); |
|
222 |
if (!AreValidRoadTypes(roadtypes) || !HasRoadTypesAvail(_current_player, roadtypes)) return CMD_ERROR; |
|
223 |
break; |
|
224 |
||
225 |
case TRANSPORT_RAIL: |
|
226 |
railtype = (RailType)GB(p2, 8, 8); |
|
227 |
if (!ValParamRailtype(railtype)) return CMD_ERROR; |
|
228 |
break; |
|
229 |
||
10920 | 230 |
case TRANSPORT_WATER: |
231 |
break; |
|
232 |
||
9732 | 233 |
default: |
10920 | 234 |
/* Airports don't have tunnels. */ |
9732 | 235 |
return CMD_ERROR; |
0 | 236 |
} |
237 |
||
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
238 |
x = TileX(end_tile); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
239 |
y = TileY(end_tile); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
240 |
sx = TileX(p1); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
241 |
sy = TileY(p1); |
0 | 242 |
|
243 |
/* check if valid, and make sure that (x,y) are smaller than (sx,sy) */ |
|
244 |
if (x == sx) { |
|
2639 | 245 |
if (y == sy) return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
246 |
direction = AXIS_Y; |
6432 | 247 |
if (y > sy) Swap(y, sy); |
0 | 248 |
} else if (y == sy) { |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3156
diff
changeset
|
249 |
direction = AXIS_X; |
6432 | 250 |
if (x > sx) Swap(x, sx); |
2639 | 251 |
} else { |
0 | 252 |
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); |
2639 | 253 |
} |
0 | 254 |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3996
diff
changeset
|
255 |
bridge_len = sx + sy - x - y - 1; |
10920 | 256 |
if (transport_type != TRANSPORT_WATER) { |
257 |
/* set and test bridge length, availability */ |
|
258 |
if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE); |
|
259 |
} |
|
1781
92e08797c84b
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
260 |
|
0 | 261 |
/* retrieve landscape height and ensure it's on land */ |
3493
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
262 |
tile_start = TileXY(x, y); |
4d5830846ec2
(svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents:
3491
diff
changeset
|
263 |
tile_end = TileXY(sx, sy); |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
264 |
if (IsWaterTile(tile_start) || IsWaterTile(tile_end)) { |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3996
diff
changeset
|
265 |
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH); |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3996
diff
changeset
|
266 |
} |
0 | 267 |
|
3301
4ac662c79ad3
(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents:
3267
diff
changeset
|
268 |
tileh_start = GetTileSlope(tile_start, &z_start); |
4ac662c79ad3
(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents:
3267
diff
changeset
|
269 |
tileh_end = GetTileSlope(tile_end, &z_end); |
4ac662c79ad3
(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents:
3267
diff
changeset
|
270 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
271 |
CommandCost terraform_cost_north = CheckBridgeSlopeNorth(direction, &tileh_start, &z_start); |
9732 | 272 |
CommandCost terraform_cost_south = CheckBridgeSlopeSouth(direction, &tileh_end, &z_end); |
0 | 273 |
|
9704 | 274 |
if (z_start != z_end) return_cmd_error(STR_BRIDGEHEADS_NOT_SAME_HEIGHT); |
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
275 |
|
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
276 |
if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) && |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
277 |
GetOtherBridgeEnd(tile_start) == tile_end && |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
278 |
GetTunnelBridgeTransportType(tile_start) == transport_type) { |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
279 |
/* Replace a current bridge. */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
280 |
|
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
281 |
/* If this is a railway bridge, make sure the railtypes match. */ |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
282 |
if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) { |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
283 |
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
284 |
} |
0 | 285 |
|
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
286 |
/* Do not replace town bridges with lower speed bridges. */ |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
287 |
if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) && |
9732 | 288 |
GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed) { |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
289 |
Town *t = ClosestTownFromTile(tile_start, UINT_MAX); |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
290 |
|
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
291 |
if (t == NULL) { |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
292 |
return CMD_ERROR; |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
293 |
} else { |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
294 |
SetDParam(0, t->index); |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
295 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
296 |
} |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
297 |
} |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
298 |
|
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
299 |
/* Do not replace the bridge with the same bridge type. */ |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
300 |
if (!(flags & DC_QUERY_COST) && bridge_type == GetBridgeType(tile_start)) { |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
301 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
302 |
} |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
303 |
|
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
304 |
/* Do not allow replacing another player's bridges. */ |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
305 |
if (!IsTileOwner(tile_start, _current_player) && !IsTileOwner(tile_start, OWNER_TOWN)) { |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
306 |
return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER); |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
307 |
} |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
308 |
|
9629 | 309 |
cost.AddCost((bridge_len + 1) * _price.clear_bridge); // The cost of clearing the current bridge. |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
310 |
replace_bridge = true; |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
311 |
replaced_bridge_type = GetBridgeType(tile_start); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
312 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
313 |
/* Do not remove road types when upgrading a bridge */ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
314 |
roadtypes |= GetRoadTypes(tile_start); |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
315 |
} else { |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
316 |
/* Build a new bridge. */ |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
317 |
|
10920 | 318 |
bool allow_on_slopes = (_settings_game.construction.build_on_slopes && transport_type != TRANSPORT_WATER); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
319 |
|
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
320 |
/* Try and clear the start landscape */ |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
321 |
ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
322 |
if (CmdFailed(ret)) return ret; |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
323 |
cost = ret; |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
324 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
325 |
if (CmdFailed(terraform_cost_north) || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes)) |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
326 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
327 |
cost.AddCost(terraform_cost_north); |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
328 |
|
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
329 |
/* Try and clear the end landscape */ |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
330 |
ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
331 |
if (CmdFailed(ret)) return ret; |
9629 | 332 |
cost.AddCost(ret); |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
333 |
|
9574 | 334 |
/* false - end tile slope check */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
335 |
if (CmdFailed(terraform_cost_south) || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
336 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
337 |
cost.AddCost(terraform_cost_south); |
10920 | 338 |
|
339 |
if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
340 |
} |
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
341 |
|
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
342 |
if (!replace_bridge) { |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
343 |
TileIndex Heads[] = {tile_start, tile_end}; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
344 |
int i; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
345 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
346 |
for (i = 0; i < 2; i++) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
347 |
if (MayHaveBridgeAbove(Heads[i])) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
348 |
if (IsBridgeAbove(Heads[i])) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
349 |
TileIndex north_head = GetNorthernBridgeEnd(Heads[i]); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
350 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
351 |
if (direction == GetBridgeAxis(Heads[i])) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
352 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
353 |
if (z_start + TILE_HEIGHT == GetBridgeHeight(north_head)) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
354 |
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
355 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
356 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
357 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
358 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
359 |
} |
0 | 360 |
|
361 |
/* do the drill? */ |
|
362 |
if (flags & DC_EXEC) { |
|
3209
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3196
diff
changeset
|
363 |
DiagDirection dir = AxisToDiagDir(direction); |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
364 |
Owner owner = (replace_bridge && IsTileOwner(tile_start, OWNER_TOWN)) ? OWNER_TOWN : _current_player; |
0 | 365 |
|
9732 | 366 |
switch (transport_type) { |
367 |
case TRANSPORT_RAIL: |
|
368 |
MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype); |
|
369 |
MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype); |
|
370 |
break; |
|
371 |
||
372 |
case TRANSPORT_ROAD: |
|
373 |
MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir, roadtypes); |
|
374 |
MakeRoadBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), roadtypes); |
|
375 |
break; |
|
376 |
||
10920 | 377 |
case TRANSPORT_WATER: |
378 |
MakeAqueductBridgeRamp(tile_start, owner, dir); |
|
379 |
MakeAqueductBridgeRamp(tile_end, owner, ReverseDiagDir(dir)); |
|
380 |
break; |
|
381 |
||
9732 | 382 |
default: |
383 |
NOT_REACHED(); |
|
384 |
break; |
|
3209
e0b7d48351a3
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents:
3196
diff
changeset
|
385 |
} |
3301
4ac662c79ad3
(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents:
3267
diff
changeset
|
386 |
MarkTileDirtyByTile(tile_start); |
4ac662c79ad3
(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator
tron
parents:
3267
diff
changeset
|
387 |
MarkTileDirtyByTile(tile_end); |
0 | 388 |
} |
389 |
||
3178
c275826135da
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
390 |
delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
391 |
for (tile = tile_start + delta; tile != tile_end; tile += delta) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
392 |
if (GetTileMaxZ(tile) > z_start) return_cmd_error(STR_BRIDGE_TOO_LOW_FOR_TERRAIN); |
0 | 393 |
|
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
394 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && !replace_bridge) { |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
395 |
/* Disallow crossing bridges for the time being */ |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
396 |
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
397 |
} |
0 | 398 |
|
3178
c275826135da
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
399 |
switch (GetTileType(tile)) { |
3065 | 400 |
case MP_WATER: |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
401 |
if (!EnsureNoVehicleOnGround(tile)) return_cmd_error(STR_980E_SHIP_IN_THE_WAY); |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3996
diff
changeset
|
402 |
if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below; |
3065 | 403 |
break; |
0 | 404 |
|
3065 | 405 |
case MP_RAILWAY: |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
406 |
if (!IsPlainRailTile(tile)) goto not_valid_below; |
3065 | 407 |
break; |
408 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
409 |
case MP_ROAD: |
9732 | 410 |
if (IsRoadDepot(tile)) goto not_valid_below; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
411 |
break; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
412 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
413 |
case MP_TUNNELBRIDGE: |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
414 |
if (IsTunnel(tile)) break; |
6181
b43f7753f4c3
(svn r8567) -Feature: Allow upgrading bridges by building a new bridge over the top. (Based on a patch by gigajum)
maedhros
parents:
6103
diff
changeset
|
415 |
if (replace_bridge) break; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
416 |
if (direction == DiagDirToAxis(GetTunnelBridgeDirection(tile))) goto not_valid_below; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
417 |
if (z_start < GetBridgeHeight(tile)) goto not_valid_below; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
418 |
break; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
419 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
420 |
case MP_UNMOVABLE: |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
421 |
if (!IsOwnedLand(tile)) goto not_valid_below; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
422 |
break; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
423 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
424 |
case MP_CLEAR: |
3065 | 425 |
break; |
426 |
||
427 |
default: |
|
0 | 428 |
not_valid_below:; |
3065 | 429 |
/* try and clear the middle landscape */ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
430 |
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3183
cf71bd234ebd
(svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents:
3181
diff
changeset
|
431 |
if (CmdFailed(ret)) return ret; |
9629 | 432 |
cost.AddCost(ret); |
3065 | 433 |
break; |
0 | 434 |
} |
435 |
||
436 |
if (flags & DC_EXEC) { |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
437 |
SetBridgeMiddle(tile, direction); |
3178
c275826135da
(svn r3814) Remove another call to FindLandscapeHeight()
tron
parents:
3172
diff
changeset
|
438 |
MarkTileDirtyByTile(tile); |
0 | 439 |
} |
440 |
} |
|
441 |
||
9732 | 442 |
if (flags & DC_EXEC && transport_type == TRANSPORT_RAIL) { |
5812
cfb97d0d3ffd
(svn r7966) -Fix (r7936): Eh AxisToTrack returns Track not Axis, thanks KUDr
Darkvater
parents:
5805
diff
changeset
|
443 |
Track track = AxisToTrack(direction); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
444 |
AddSideToSignalBuffer(tile_start, INVALID_DIAGDIR, _current_player); |
5812
cfb97d0d3ffd
(svn r7966) -Fix (r7936): Eh AxisToTrack returns Track not Axis, thanks KUDr
Darkvater
parents:
5805
diff
changeset
|
445 |
YapfNotifyTrackLayoutChange(tile_start, track); |
5805
94cb5895c923
(svn r7936) -Fix (r4987, old-rev): Only update the signals and YAPF cache on a DC_EXEC action for bridge-building
Darkvater
parents:
5726
diff
changeset
|
446 |
} |
0 | 447 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4344
diff
changeset
|
448 |
/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST) |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4344
diff
changeset
|
449 |
* It's unnecessary to execute this command every time for every bridge. So it is done only |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4344
diff
changeset
|
450 |
* and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4344
diff
changeset
|
451 |
*/ |
9732 | 452 |
if (!(flags & DC_QUERY_COST) || (IsValidPlayer(_current_player) && GetPlayer(_current_player)->is_ai)) { |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4344
diff
changeset
|
453 |
bridge_len += 2; // begin and end tiles/ramps |
0 | 454 |
|
9359
e915dd81a279
(svn r9140) [NoAI] -Remove: both 'default' and 'trolly' AI
truelight
parents:
6585
diff
changeset
|
455 |
if (IsValidPlayer(_current_player)) |
0 | 456 |
bridge_len = CalcBridgeLenCostFactor(bridge_len); |
457 |
||
9732 | 458 |
cost.AddCost((int64)bridge_len * _price.build_bridge * GetBridgeSpec(bridge_type)->price >> 8); |
10920 | 459 |
|
460 |
/* Aqueducts are a little more expensive. */ |
|
461 |
if (transport_type == TRANSPORT_WATER) cost.AddCost((int64)bridge_len * _price.clear_water); |
|
0 | 462 |
} |
463 |
||
464 |
return cost; |
|
465 |
} |
|
466 |
||
467 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
468 |
/** Build Tunnel. |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
469 |
* @param start_tile start tile of tunnel |
9574 | 470 |
* @param flags type of operation |
9624 | 471 |
* @param p1 railtype or roadtypes. bit 9 set means road tunnel |
2639 | 472 |
* @param p2 unused |
0 | 473 |
*/ |
9629 | 474 |
CommandCost CmdBuildTunnel(TileIndex start_tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 475 |
{ |
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
476 |
TileIndexDiff delta; |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
477 |
TileIndex end_tile; |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
478 |
DiagDirection direction; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3556
diff
changeset
|
479 |
Slope start_tileh; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3556
diff
changeset
|
480 |
Slope end_tileh; |
9732 | 481 |
TransportType transport_type = (TransportType)GB(p1, 9, 1); |
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
482 |
uint start_z; |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
483 |
uint end_z; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
484 |
CommandCost cost(EXPENSES_CONSTRUCTION); |
9629 | 485 |
CommandCost ret; |
0 | 486 |
|
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
487 |
_build_tunnel_endtile = 0; |
9732 | 488 |
if (transport_type == TRANSPORT_RAIL) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
489 |
if (!ValParamRailtype((RailType)p1)) return CMD_ERROR; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
490 |
} else { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
491 |
const RoadTypes rts = (RoadTypes)GB(p1, 0, 3); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
492 |
if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_player, rts)) return CMD_ERROR; |
9624 | 493 |
} |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
494 |
|
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
495 |
start_tileh = GetTileSlope(start_tile, &start_z); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
496 |
direction = GetInclinedSlopeDirection(start_tileh); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
497 |
if (direction == INVALID_DIAGDIR) return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL); |
0 | 498 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
499 |
if (IsWaterTile(start_tile)) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
0 | 500 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
501 |
ret = DoCommand(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
502 |
if (CmdFailed(ret)) return ret; |
0 | 503 |
|
4273
6467c2c54d58
(svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents:
4261
diff
changeset
|
504 |
/* XXX - do NOT change 'ret' in the loop, as it is used as the price |
6467c2c54d58
(svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents:
4261
diff
changeset
|
505 |
* for the clearing of the entrance of the tunnel. Assigning it to |
6467c2c54d58
(svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents:
4261
diff
changeset
|
506 |
* cost before the loop will yield different costs depending on start- |
6467c2c54d58
(svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents:
4261
diff
changeset
|
507 |
* position, because of increased-cost-by-length: 'cost += cost >> 3' */ |
9629 | 508 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
509 |
delta = TileOffsByDiagDir(direction); |
9629 | 510 |
DiagDirection tunnel_in_way_dir; |
10645 | 511 |
if (DiagDirToAxis(direction) == AXIS_Y) { |
9629 | 512 |
tunnel_in_way_dir = (TileX(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SW : DIAGDIR_NE; |
513 |
} else { |
|
514 |
tunnel_in_way_dir = (TileY(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SE : DIAGDIR_NW; |
|
515 |
} |
|
516 |
||
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
517 |
end_tile = start_tile; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
518 |
|
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
519 |
/** Tile shift coeficient. Will decrease for very long tunnels to avoid exponential growth of price*/ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
520 |
int tiles_coef = 3; |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
521 |
/** Number of tiles from start of tunnel */ |
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
522 |
int tiles = 0; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
523 |
/** Number of tiles at which the cost increase coefficient per tile is halved */ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
524 |
int tiles_bump = 25; |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
525 |
|
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
526 |
for (;;) { |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
527 |
end_tile += delta; |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
528 |
end_tileh = GetTileSlope(end_tile, &end_z); |
0 | 529 |
|
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
530 |
if (start_z == end_z) break; |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
531 |
|
9629 | 532 |
if (!_cheats.crossing_tunnels.value && IsTunnelInWayDir(end_tile, start_z, tunnel_in_way_dir)) { |
3156
028b6756b279
(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
|
533 |
return_cmd_error(STR_5003_ANOTHER_TUNNEL_IN_THE_WAY); |
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
534 |
} |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
535 |
|
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
536 |
tiles++; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
537 |
if (tiles == tiles_bump) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
538 |
tiles_coef++; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
539 |
tiles_bump *= 2; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
540 |
} |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
541 |
|
9629 | 542 |
cost.AddCost(_price.build_tunnel); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
543 |
cost.AddCost(cost.GetCost() >> tiles_coef); // add a multiplier for longer tunnels |
0 | 544 |
} |
545 |
||
4273
6467c2c54d58
(svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents:
4261
diff
changeset
|
546 |
/* Add the cost of the entrance */ |
9629 | 547 |
cost.AddCost(_price.build_tunnel); |
548 |
cost.AddCost(ret); |
|
4273
6467c2c54d58
(svn r5901) -Fix [FS#253]: Differing price calculation for tunnels depending on starting point
Darkvater
parents:
4261
diff
changeset
|
549 |
|
9574 | 550 |
/* if the command fails from here on we want the end tile to be highlighted */ |
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
551 |
_build_tunnel_endtile = end_tile; |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
552 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
553 |
if (IsWaterTile(end_tile)) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
554 |
|
9574 | 555 |
/* slope of end tile must be complementary to the slope of the start tile */ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3556
diff
changeset
|
556 |
if (end_tileh != ComplementSlope(start_tileh)) { |
9704 | 557 |
/* Check if there is a structure on the terraformed tile. Do not add the cost, that will be done by the terraforming */ |
558 |
ret = DoCommand(end_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR); |
|
559 |
if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND); |
|
9629 | 560 |
|
9704 | 561 |
ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND); |
562 |
if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND); |
|
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
563 |
} else { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3435
diff
changeset
|
564 |
ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
565 |
if (CmdFailed(ret)) return ret; |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
566 |
} |
9629 | 567 |
cost.AddCost(_price.build_tunnel); |
568 |
cost.AddCost(ret); |
|
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
569 |
|
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
570 |
if (flags & DC_EXEC) { |
9732 | 571 |
if (transport_type == TRANSPORT_RAIL) { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
572 |
MakeRailTunnel(start_tile, _current_player, direction, (RailType)GB(p1, 0, 4)); |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
573 |
MakeRailTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4)); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
574 |
AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, _current_player); |
10645 | 575 |
YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction)); |
3154 | 576 |
} else { |
9624 | 577 |
MakeRoadTunnel(start_tile, _current_player, direction, (RoadTypes)GB(p1, 0, 3)); |
578 |
MakeRoadTunnel(end_tile, _current_player, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 3)); |
|
3154 | 579 |
} |
3063
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
580 |
} |
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
581 |
|
794656a0856e
(svn r3652) Rewrite CmdBuildTunnel in the hope to make it a bit more comprehensible
tron
parents:
3056
diff
changeset
|
582 |
return cost; |
0 | 583 |
} |
584 |
||
585 |
||
5009
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
586 |
static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile) |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
587 |
{ |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
588 |
/* Floods can remove anything as well as the scenario editor */ |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
589 |
if (_current_player == OWNER_WATER || _game_mode == GM_EDITOR) return true; |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
590 |
/* Obviously if the bridge/tunnel belongs to us, or no-one, we can remove it */ |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
591 |
if (CheckTileOwnership(tile) || IsTileOwner(tile, OWNER_NONE)) return true; |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
592 |
/* Otherwise we can only remove town-owned stuff with extra patch-settings, or cheat */ |
10776 | 593 |
if (IsTileOwner(tile, OWNER_TOWN) && (_settings_game.construction.extra_dynamite || _cheats.magic_bulldozer.value)) return true; |
5009
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
594 |
return false; |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
595 |
} |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
596 |
|
9629 | 597 |
static CommandCost DoClearTunnel(TileIndex tile, uint32 flags) |
0 | 598 |
{ |
5009
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
599 |
Town *t = NULL; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
600 |
TileIndex endtile; |
0 | 601 |
|
5009
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
602 |
if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; |
0 | 603 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
604 |
endtile = GetOtherTunnelEnd(tile); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
605 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
606 |
if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR; |
0 | 607 |
|
608 |
_build_tunnel_endtile = endtile; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
609 |
|
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
610 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
5009
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
611 |
t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
612 |
|
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
613 |
/* Check if you are allowed to remove the tunnel owned by a town |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
614 |
* Removal depends on difficulty settings */ |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
615 |
if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
511
diff
changeset
|
616 |
SetDParam(0, t->index); |
0 | 617 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
618 |
} |
|
619 |
} |
|
620 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
621 |
/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
622 |
* you have a "Poor" (0) town rating */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
623 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
624 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
625 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
626 |
|
0 | 627 |
if (flags & DC_EXEC) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
628 |
if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
629 |
/* We first need to request values before calling DoClearSquare */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
630 |
DiagDirection dir = GetTunnelBridgeDirection(tile); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
631 |
Owner owner = GetTileOwner(tile); |
2870
32c980d2b8e9
(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
|
632 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
633 |
DoClearSquare(tile); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
634 |
DoClearSquare(endtile); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
635 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
636 |
/* cannot use INVALID_DIAGDIR for signal update because the tunnel doesn't exist anymore */ |
9732 | 637 |
AddSideToSignalBuffer(tile, ReverseDiagDir(dir), owner); |
638 |
AddSideToSignalBuffer(endtile, dir, owner); |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
639 |
|
10645 | 640 |
Track track = DiagDirToDiagTrack(dir); |
9732 | 641 |
YapfNotifyTrackLayoutChange(tile, track); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
642 |
YapfNotifyTrackLayoutChange(endtile, track); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
643 |
} else { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
644 |
DoClearSquare(tile); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
645 |
DoClearSquare(endtile); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
646 |
} |
0 | 647 |
} |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
648 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (GetTunnelBridgeLength(tile, endtile) + 2)); |
0 | 649 |
} |
650 |
||
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3938
diff
changeset
|
651 |
|
9629 | 652 |
static CommandCost DoClearBridge(TileIndex tile, uint32 flags) |
0 | 653 |
{ |
3227
8bb33a2299a5
(svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents:
3226
diff
changeset
|
654 |
DiagDirection direction; |
8bb33a2299a5
(svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents:
3226
diff
changeset
|
655 |
TileIndexDiff delta; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
656 |
TileIndex endtile; |
5009
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
657 |
Town *t = NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
658 |
|
5009
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
659 |
if (!CheckAllowRemoveTunnelBridge(tile)) return CMD_ERROR; |
0 | 660 |
|
3228
270ab760cc16
(svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents:
3227
diff
changeset
|
661 |
endtile = GetOtherBridgeEnd(tile); |
270ab760cc16
(svn r3901) Remove the last user of FindEdgesOfBridge() by using functions with similar functionality
tron
parents:
3227
diff
changeset
|
662 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
663 |
if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR; |
0 | 664 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
665 |
direction = GetTunnelBridgeDirection(tile); |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
666 |
delta = TileOffsByDiagDir(direction); |
3227
8bb33a2299a5
(svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tron
parents:
3226
diff
changeset
|
667 |
|
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
668 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
5009
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
669 |
t = ClosestTownFromTile(tile, (uint)-1); // town penalty rating |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
670 |
|
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
671 |
/* Check if you are allowed to remove the bridge owned by a town |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
672 |
* Removal depends on difficulty settings */ |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
673 |
if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) { |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
674 |
SetDParam(0, t->index); |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
675 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
437645a303b4
(svn r7028) -Fix [FS#200]: Scenario bridges/tunnels cannot be demolished; now it's possible to
Darkvater
parents:
4850
diff
changeset
|
676 |
} |
0 | 677 |
} |
678 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
679 |
/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
680 |
* you have a "Poor" (0) town rating */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
681 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
682 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
683 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
684 |
|
0 | 685 |
if (flags & DC_EXEC) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
686 |
/* read this value before actual removal of bridge */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
687 |
bool rail = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
688 |
Owner owner = GetTileOwner(tile); |
9732 | 689 |
uint height = GetBridgeHeight(tile); |
0 | 690 |
|
3217
60f832048cd4
(svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents:
3216
diff
changeset
|
691 |
DoClearSquare(tile); |
60f832048cd4
(svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents:
3216
diff
changeset
|
692 |
DoClearSquare(endtile); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
693 |
for (TileIndex c = tile + delta; c != endtile; c += delta) { |
9732 | 694 |
/* do not let trees appear from 'nowhere' after removing bridge */ |
695 |
if (IsNormalRoadTile(c) && GetRoadside(c) == ROADSIDE_TREES) { |
|
696 |
uint minz = GetTileMaxZ(c) + 3 * TILE_HEIGHT; |
|
697 |
if (height < minz) SetRoadside(c, ROADSIDE_PAVED); |
|
698 |
} |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
699 |
ClearBridgeMiddle(c); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
700 |
MarkTileDirtyByTile(c); |
3217
60f832048cd4
(svn r3890) Simplify deleting a bridge by handling the ramps outside of the removal loop
tron
parents:
3216
diff
changeset
|
701 |
} |
0 | 702 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
703 |
if (rail) { |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
704 |
/* cannot use INVALID_DIAGDIR for signal update because the bridge doesn't exist anymore */ |
9732 | 705 |
AddSideToSignalBuffer(tile, ReverseDiagDir(direction), owner); |
706 |
AddSideToSignalBuffer(endtile, direction, owner); |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
707 |
|
10645 | 708 |
Track track = DiagDirToDiagTrack(direction); |
9732 | 709 |
YapfNotifyTrackLayoutChange(tile, track); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
710 |
YapfNotifyTrackLayoutChange(endtile, track); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
711 |
} |
0 | 712 |
} |
713 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
714 |
return CommandCost(EXPENSES_CONSTRUCTION, (GetTunnelBridgeLength(tile, endtile) + 2) * _price.clear_bridge); |
0 | 715 |
} |
716 |
||
9629 | 717 |
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
718 |
{ |
3184
7405329343ce
(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
|
719 |
if (IsTunnel(tile)) { |
2639 | 720 |
if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST); |
0 | 721 |
return DoClearTunnel(tile, flags); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
722 |
} else { // IsBridge(tile) |
2639 | 723 |
if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
1082
56a4c048c5c3
(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
|
724 |
return DoClearBridge(tile, flags); |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
725 |
} |
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
726 |
|
1082
56a4c048c5c3
(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
|
727 |
return CMD_ERROR; |
0 | 728 |
} |
729 |
||
9517 | 730 |
/** |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
731 |
* Draws the pillars under high bridges. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
732 |
* |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
733 |
* @param psid Image and palette of a bridge pillar. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
734 |
* @param ti #TileInfo of current bridge-middle-tile. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
735 |
* @param axis Orientation of bridge. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
736 |
* @param type Bridge type. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
737 |
* @param x Sprite X position of front pillar. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
738 |
* @param y Sprite Y position of front pillar. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
739 |
* @param z_bridge Absolute height of bridge bottom. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
740 |
*/ |
10955 | 741 |
static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge) |
0 | 742 |
{ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
743 |
/* Do not draw bridge pillars if they are invisible */ |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
744 |
if (IsInvisibilitySet(TO_BRIDGES)) return; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
745 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
746 |
SpriteID image = psid->sprite; |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
747 |
|
0 | 748 |
if (image != 0) { |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
749 |
/* "side" specifies the side the pillars stand on. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
750 |
* The length of the pillars is then set to the height of the bridge over the corners of this edge. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
751 |
* |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
752 |
* axis==AXIS_X axis==AXIS_Y |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
753 |
* side==false SW NW |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
754 |
* side==true NE SE |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
755 |
* |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
756 |
* I have no clue, why this was done this way. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
757 |
*/ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
758 |
bool side = HasBit(image, 0); |
2262
bd59b2d8d75f
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2261
diff
changeset
|
759 |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
760 |
/* "dir" means the edge the pillars stand on */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
761 |
DiagDirection dir = AxisToDiagDir(axis); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
762 |
if (side != (axis == AXIS_Y)) dir = ReverseDiagDir(dir); |
0 | 763 |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
764 |
/* Determine ground height under pillars */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
765 |
int front_height = ti->z; |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
766 |
int back_height = ti->z; |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
767 |
GetSlopeZOnEdge(ti->tileh, dir, &front_height, &back_height); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
768 |
|
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
769 |
/* x and y size of bounding-box of pillars */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
770 |
int w = (axis == AXIS_X ? 16 : 2); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
771 |
int h = (axis == AXIS_X ? 2 : 16); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
772 |
/* sprite position of back facing pillar */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
773 |
int x_back = x - (axis == AXIS_X ? 0 : 9); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
774 |
int y_back = y - (axis == AXIS_X ? 9 : 0); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
775 |
|
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
776 |
for (int cur_z = z_bridge; cur_z >= front_height || cur_z >= back_height; cur_z -= TILE_HEIGHT) { |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
777 |
/* Draw front facing pillar */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
778 |
if (cur_z >= front_height) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
779 |
AddSortableSpriteToDraw(image, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5); |
2952 | 780 |
} |
3556
d25b35568c48
(svn r4430) - NewGRF: Use the bridge's sprite layout for drawing high pillars. This fixes newgrf's high-bridge pillars drawing. Also remove the now obsolete _bridge_poles_table which was already integrated into the bridge sprite tables
Darkvater
parents:
3539
diff
changeset
|
781 |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
782 |
/* Draw back facing pillar, but not the highest part directly under the bridge-floor */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9704
diff
changeset
|
783 |
if (drawfarpillar && cur_z >= back_height && cur_z < z_bridge - TILE_HEIGHT) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
784 |
AddSortableSpriteToDraw(image, psid->pal, x_back, y_back, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5); |
2952 | 785 |
} |
0 | 786 |
} |
787 |
} |
|
788 |
} |
|
789 |
||
2536
8c4e298f4886
(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
|
790 |
/** |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
791 |
* Draws the trambits over an already drawn (lower end) of a bridge. |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
792 |
* @param x the x of the bridge |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
793 |
* @param y the y of the bridge |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
794 |
* @param z the z of the bridge |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
795 |
* @param offset number representing whether to level or sloped and the direction |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
796 |
* @param overlay do we want to still see the road? |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
797 |
* @param head are we drawing bridge head? |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
798 |
*/ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
799 |
static void DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay, bool head) |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
800 |
{ |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
801 |
static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } }; |
9686
d3c195c226f9
(svn r10636) [NoAI] -Sync with trunk r10532:10635.
rubidium
parents:
9631
diff
changeset
|
802 |
static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 }; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
803 |
static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 }; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
804 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
805 |
static const uint size_x[6] = { 1, 16, 16, 1, 16, 1 }; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
806 |
static const uint size_y[6] = { 16, 1, 1, 16, 1, 16 }; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
807 |
static const uint front_bb_offset_x[6] = { 15, 0, 0, 15, 0, 15 }; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
808 |
static const uint front_bb_offset_y[6] = { 0, 15, 15, 0, 15, 0 }; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
809 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
810 |
/* The sprites under the vehicles are drawn as SpriteCombine. StartSpriteCombine() has already been called |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
811 |
* The bounding boxes here are the same as for bridge front/roof */ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
812 |
if (head || !IsInvisibilitySet(TO_BRIDGES)) { |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
813 |
AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
814 |
x, y, size_x[offset], size_y[offset], 0x28, z, |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
815 |
!head && IsTransparencySet(TO_BRIDGES)); |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
816 |
} |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
817 |
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
818 |
/* Do not draw catenary if it is set invisible */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
819 |
if (!IsInvisibilitySet(TO_CATENARY)) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
820 |
AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset], PAL_NONE, |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
821 |
x, y, size_x[offset], size_y[offset], 0x28, z, |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
822 |
IsTransparencySet(TO_CATENARY)); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
823 |
} |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
824 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
825 |
/* Start a new SpriteCombine for the front part */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
826 |
EndSpriteCombine(); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
827 |
StartSpriteCombine(); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
828 |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
829 |
/* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
830 |
if (!IsInvisibilitySet(TO_CATENARY)) { |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
831 |
AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE, |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
832 |
x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z, |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
833 |
IsTransparencySet(TO_CATENARY), front_bb_offset_x[offset], front_bb_offset_y[offset]); |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
834 |
} |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
835 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
836 |
|
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
837 |
/** |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
838 |
* Draws a tunnel of bridge tile. |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
839 |
* For tunnels, this is rather simple, as you only needa draw the entrance. |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
840 |
* Bridges are a bit more complex. base_offset is where the sprite selection comes into play |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
841 |
* and it works a bit like a bitmask.<p> For bridge heads: |
9574 | 842 |
* @param ti TileInfo of the structure to draw |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
843 |
* <ul><li>Bit 0: direction</li> |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
844 |
* <li>Bit 1: northern or southern heads</li> |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
845 |
* <li>Bit 2: Set if the bridge head is sloped</li> |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
846 |
* <li>Bit 3 and more: Railtype Specific subset</li> |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
847 |
* </ul> |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
848 |
* Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3 |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
849 |
*/ |
0 | 850 |
static void DrawTile_TunnelBridge(TileInfo *ti) |
851 |
{ |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
852 |
SpriteID image; |
9732 | 853 |
TransportType transport_type = GetTunnelBridgeTransportType(ti->tile); |
854 |
DiagDirection tunnelbridge_direction = GetTunnelBridgeDirection(ti->tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
855 |
|
3184
7405329343ce
(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
|
856 |
if (IsTunnel(ti->tile)) { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
857 |
/* Front view of tunnel bounding boxes: |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
858 |
* |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
859 |
* 122223 <- BB_Z_SEPARATOR |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
860 |
* 1 3 |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
861 |
* 1 3 1,3 = empty helper BB |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
862 |
* 1 3 2 = SpriteCombine of tunnel-roof and catenary (tram & elrail) |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
863 |
* |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
864 |
*/ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
865 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
866 |
static const int _tunnel_BB[4][12] = { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
867 |
/* tunnnel-roof | Z-separator | tram-catenary |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
868 |
* w h bb_x bb_y| x y w h |bb_x bb_y w h */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
869 |
{ 1, 0, -15, -14, 0, 15, 16, 1, 0, 1, 16, 15 }, // NE |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
870 |
{ 0, 1, -14, -15, 15, 0, 1, 16, 1, 0, 15, 16 }, // SE |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
871 |
{ 1, 0, -15, -14, 0, 15, 16, 1, 0, 1, 16, 15 }, // SW |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
872 |
{ 0, 1, -14, -15, 15, 0, 1, 16, 1, 0, 15, 16 }, // NW |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
873 |
}; |
9732 | 874 |
const int *BB_data = _tunnel_BB[tunnelbridge_direction]; |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
875 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
876 |
bool catenary = false; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
877 |
|
9732 | 878 |
if (transport_type == TRANSPORT_RAIL) { |
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3234
diff
changeset
|
879 |
image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel; |
2511
0a81d9ca79bc
(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
|
880 |
} else { |
0a81d9ca79bc
(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
|
881 |
image = SPR_TUNNEL_ENTRY_REAR_ROAD; |
0a81d9ca79bc
(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
|
882 |
} |
0 | 883 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
884 |
if (HasTunnelBridgeSnowOrDesert(ti->tile)) image += 32; |
0 | 885 |
|
9732 | 886 |
image += tunnelbridge_direction * 2; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
887 |
DrawGroundSprite(image, PAL_NONE); |
9732 | 888 |
if (transport_type == TRANSPORT_ROAD) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
889 |
RoadTypes rts = GetRoadTypes(ti->tile); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
890 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
891 |
if (HasBit(rts, ROADTYPE_TRAM)) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
892 |
static const SpriteID tunnel_sprites[2][4] = { { 28, 78, 79, 27 }, { 5, 76, 77, 4 } }; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
893 |
|
9732 | 894 |
DrawGroundSprite(SPR_TRAMWAY_BASE + tunnel_sprites[rts - ROADTYPES_TRAM][tunnelbridge_direction], PAL_NONE); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
895 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
896 |
/* Do not draw wires if they are invisible */ |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
897 |
if (!IsInvisibilitySet(TO_CATENARY)) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
898 |
catenary = true; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
899 |
StartSpriteCombine(); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
900 |
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); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
901 |
} |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
902 |
} |
10513
33cb70ff2f5d
(svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents:
10455
diff
changeset
|
903 |
} else if (HasCatenaryDrawn(GetRailType(ti->tile))) { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
904 |
catenary = true; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
905 |
StartSpriteCombine(); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
906 |
DrawCatenaryOnTunnel(ti); |
9624 | 907 |
} |
0 | 908 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
909 |
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); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
910 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
911 |
if (catenary) EndSpriteCombine(); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
912 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
913 |
/* Add helper BB for sprite sorting, that separate the tunnel from things beside of it */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
914 |
AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x , ti->y , BB_data[6], BB_data[7], TILE_HEIGHT, ti->z); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
915 |
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); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
916 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
917 |
DrawBridgeMiddle(ti); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
918 |
} else { // IsBridge(ti->tile) |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
919 |
const PalSpriteID *psid; |
2536
8c4e298f4886
(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
|
920 |
int base_offset; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
921 |
bool ice = HasTunnelBridgeSnowOrDesert(ti->tile); |
0 | 922 |
|
9732 | 923 |
if (transport_type == TRANSPORT_RAIL) { |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
924 |
base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset; |
9574 | 925 |
assert(base_offset != 8); // This one is used for roads |
3234
986c30171e92
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3233
diff
changeset
|
926 |
} else { |
986c30171e92
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3233
diff
changeset
|
927 |
base_offset = 8; |
2536
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
928 |
} |
8c4e298f4886
(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
|
929 |
|
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
930 |
/* as the lower 3 bits are used for other stuff, make sure they are clear */ |
8c4e298f4886
(svn r3065) -Codechange/Add: Modified the bridge drawing code so that the basic offset is read from the RailTypeInfo struct. This is (hopefully) the last DrawTile change on the way to electrified railways. While being at it, de-mystified the function a bit and added some asserts.
celestar
parents:
2535
diff
changeset
|
931 |
assert( (base_offset & 0x07) == 0x00); |
0 | 932 |
|
9732 | 933 |
DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(tunnelbridge_direction))); |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3938
diff
changeset
|
934 |
|
9574 | 935 |
/* HACK Wizardry to convert the bridge ramp direction into a sprite offset */ |
9732 | 936 |
base_offset += (6 - tunnelbridge_direction) % 4; |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3938
diff
changeset
|
937 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
938 |
if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3938
diff
changeset
|
939 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
940 |
/* Table number 6 always refers to the bridge heads for any bridge type */ |
10920 | 941 |
if (transport_type != TRANSPORT_WATER) { |
942 |
psid = &GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset]; |
|
943 |
} else { |
|
944 |
psid = _aqueduct_sprites + base_offset; |
|
945 |
} |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3938
diff
changeset
|
946 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
947 |
if (!ice) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
948 |
DrawClearLandTile(ti, 3); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
949 |
} else { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
950 |
DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE); |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3938
diff
changeset
|
951 |
} |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
952 |
|
9574 | 953 |
/* draw ramp */ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
954 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
955 |
/* Draw Trambits as SpriteCombine */ |
9732 | 956 |
if (transport_type == TRANSPORT_ROAD) StartSpriteCombine(); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
957 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
958 |
/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
959 |
* it doesn't disappear behind it |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
960 |
*/ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
961 |
/* Bridge heads are drawn solid no matter how invisibility/transparency is set */ |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
962 |
AddSortableSpriteToDraw(psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
963 |
|
9732 | 964 |
if (transport_type == TRANSPORT_ROAD) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
965 |
RoadTypes rts = GetRoadTypes(ti->tile); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
966 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
967 |
if (HasBit(rts, ROADTYPE_TRAM)) { |
9732 | 968 |
uint offset = tunnelbridge_direction; |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
969 |
uint z = ti->z; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
970 |
if (ti->tileh != SLOPE_FLAT) { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
971 |
offset = (offset + 1) & 1; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
972 |
z += TILE_HEIGHT; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
973 |
} else { |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
974 |
offset += 2; |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
975 |
} |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
976 |
/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
977 |
DrawBridgeTramBits(ti->x, ti->y, z, offset, HasBit(rts, ROADTYPE_ROAD), true); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
978 |
} |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
979 |
EndSpriteCombine(); |
10513
33cb70ff2f5d
(svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents:
10455
diff
changeset
|
980 |
} else if (HasCatenaryDrawn(GetRailType(ti->tile))) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
981 |
DrawCatenary(ti); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
982 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
983 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
984 |
DrawBridgeMiddle(ti); |
3933 | 985 |
} |
986 |
} |
|
987 |
||
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
988 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
989 |
/** Compute bridge piece. Computes the bridge piece to display depending on the position inside the bridge. |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
990 |
* bridges pieces sequence (middle parts) |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
991 |
* bridge len 1: 0 |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
992 |
* bridge len 2: 0 1 |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
993 |
* bridge len 3: 0 4 1 |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
994 |
* bridge len 4: 0 2 3 1 |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
995 |
* bridge len 5: 0 2 5 3 1 |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
996 |
* bridge len 6: 0 2 3 2 3 1 |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
997 |
* bridge len 7: 0 2 3 4 2 3 1 |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
998 |
* #0 - always as first, #1 - always as last (if len>1) |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
999 |
* #2,#3 are to pair in order |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1000 |
* for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0) |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1001 |
* @param north Northernmost tile of bridge |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1002 |
* @param south Southernmost tile of bridge |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1003 |
* @return Index of bridge piece |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1004 |
*/ |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1005 |
static uint CalcBridgePiece(uint north, uint south) |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1006 |
{ |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1007 |
if (north == 1) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1008 |
return 0; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1009 |
} else if (south == 1) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1010 |
return 1; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1011 |
} else if (north < south) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1012 |
return north & 1 ? 3 : 2; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1013 |
} else if (north > south) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1014 |
return south & 1 ? 2 : 3; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1015 |
} else { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1016 |
return north & 1 ? 5 : 4; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1017 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1018 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1019 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1020 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1021 |
void DrawBridgeMiddle(const TileInfo* ti) |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1022 |
{ |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1023 |
/* Sectional view of bridge bounding boxes: |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1024 |
* |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1025 |
* 1 2 1,2 = SpriteCombine of Bridge front/(back&floor) and TramCatenary |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1026 |
* 1 2 3 = empty helper BB |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1027 |
* 1 7 2 4,5 = pillars under higher bridges |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1028 |
* 1 6 88888 6 2 6 = elrail-pylons |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1029 |
* 1 6 88888 6 2 7 = elrail-wire |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1030 |
* 1 6 88888 6 2 <- TILE_HEIGHT 8 = rail-vehicle on bridge |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1031 |
* 3333333333333 <- BB_Z_SEPARATOR |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1032 |
* <- unused |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1033 |
* 4 5 <- BB_HEIGHT_UNDER_BRIDGE |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1034 |
* 4 5 |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1035 |
* 4 5 |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1036 |
* |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1037 |
*/ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1038 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1039 |
/* Z position of the bridge sprites relative to bridge height (downwards) */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1040 |
static const int BRIDGE_Z_START = 3; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1041 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1042 |
if (!IsBridgeAbove(ti->tile)) return; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1043 |
|
10955 | 1044 |
TileIndex rampnorth = GetNorthernBridgeEnd(ti->tile); |
1045 |
TileIndex rampsouth = GetSouthernBridgeEnd(ti->tile); |
|
1046 |
TransportType transport_type = GetTunnelBridgeTransportType(rampsouth); |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1047 |
|
10955 | 1048 |
Axis axis = GetBridgeAxis(ti->tile); |
1049 |
uint piece = CalcBridgePiece( |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1050 |
GetTunnelBridgeLength(ti->tile, rampnorth) + 1, |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1051 |
GetTunnelBridgeLength(ti->tile, rampsouth) + 1 |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1052 |
); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1053 |
|
10955 | 1054 |
const PalSpriteID *psid; |
1055 |
bool drawfarpillar; |
|
10920 | 1056 |
if (transport_type != TRANSPORT_WATER) { |
10955 | 1057 |
BridgeType type = GetBridgeType(rampsouth); |
1058 |
drawfarpillar = !HasBit(GetBridgeSpec(type)->flags, 0); |
|
1059 |
||
1060 |
uint base_offset; |
|
10920 | 1061 |
if (transport_type == TRANSPORT_RAIL) { |
1062 |
base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset; |
|
1063 |
} else { |
|
1064 |
base_offset = 8; |
|
1065 |
} |
|
1066 |
||
1067 |
psid = base_offset + GetBridgeSpriteTable(type, piece); |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1068 |
} else { |
10955 | 1069 |
drawfarpillar = true; |
10920 | 1070 |
psid = _aqueduct_sprites; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1071 |
} |
10955 | 1072 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1073 |
if (axis != AXIS_X) psid += 4; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1074 |
|
10955 | 1075 |
int x = ti->x; |
1076 |
int y = ti->y; |
|
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1077 |
uint bridge_z = GetBridgeHeight(rampsouth); |
10955 | 1078 |
uint z = bridge_z - BRIDGE_Z_START; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1079 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1080 |
/* Add a bounding box, that separates the bridge from things below it. */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1081 |
AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, x, y, 16, 16, 1, bridge_z - TILE_HEIGHT + BB_Z_SEPARATOR); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1082 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1083 |
/* Draw Trambits as SpriteCombine */ |
9732 | 1084 |
if (transport_type == TRANSPORT_ROAD) StartSpriteCombine(); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1085 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1086 |
/* Draw floor and far part of bridge*/ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1087 |
if (!IsInvisibilitySet(TO_BRIDGES)) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1088 |
if (axis == AXIS_X) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1089 |
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1090 |
} else { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1091 |
AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 0, BRIDGE_Z_START); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1092 |
} |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1093 |
} |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1094 |
|
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1095 |
psid++; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1096 |
|
9732 | 1097 |
if (transport_type == TRANSPORT_ROAD) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1098 |
RoadTypes rts = GetRoadTypes(rampsouth); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1099 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1100 |
if (HasBit(rts, ROADTYPE_TRAM)) { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1101 |
/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1102 |
DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HasBit(rts, ROADTYPE_ROAD), false); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1103 |
} else { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1104 |
EndSpriteCombine(); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1105 |
StartSpriteCombine(); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1106 |
} |
10513
33cb70ff2f5d
(svn r13056) [NoAI] -Sync: with trunk r12996:13055.
rubidium
parents:
10455
diff
changeset
|
1107 |
} else if (HasCatenaryDrawn(GetRailType(rampsouth))) { |
10355
ee4b5f7a5bf2
(svn r12896) [NoAI] -Sync: with trunk r12824:r12895.
rubidium
parents:
10249
diff
changeset
|
1108 |
DrawCatenaryOnBridge(ti); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1109 |
} |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1110 |
|
9574 | 1111 |
/* draw roof, the component of the bridge which is logically between the vehicle and the camera */ |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1112 |
if (!IsInvisibilitySet(TO_BRIDGES)) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1113 |
if (axis == AXIS_X) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1114 |
y += 12; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1115 |
if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 4, 0x28, z, IsTransparencySet(TO_BRIDGES), 0, 3, BRIDGE_Z_START); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1116 |
} else { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1117 |
x += 12; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1118 |
if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 4, 16, 0x28, z, IsTransparencySet(TO_BRIDGES), 3, 0, BRIDGE_Z_START); |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1119 |
} |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1120 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1121 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1122 |
/* Draw TramFront as SpriteCombine */ |
9732 | 1123 |
if (transport_type == TRANSPORT_ROAD) EndSpriteCombine(); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1124 |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1125 |
/* Do not draw anything more if bridges are invisible */ |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1126 |
if (IsInvisibilitySet(TO_BRIDGES)) return; |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
1127 |
|
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1128 |
psid++; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1129 |
if (ti->z + 5 == z) { |
9574 | 1130 |
/* draw poles below for small bridges */ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1131 |
if (psid->sprite != 0) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1132 |
SpriteID image = psid->sprite; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1133 |
SpriteID pal = psid->pal; |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1134 |
if (IsTransparencySet(TO_BRIDGES)) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1135 |
SetBit(image, PALETTE_MODIFIER_TRANSPARENT); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1136 |
pal = PALETTE_TO_TRANSPARENT; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1137 |
} |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1138 |
|
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
1139 |
DrawGroundSpriteAt(image, pal, x, y, z); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1140 |
} |
10776 | 1141 |
} else if (_settings_client.gui.bridge_pillars) { |
9574 | 1142 |
/* draw pillars below for high bridges */ |
10955 | 1143 |
DrawBridgePillars(psid, ti, axis, drawfarpillar, x, y, z); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1144 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1145 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1146 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1147 |
|
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4191
diff
changeset
|
1148 |
static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y) |
2537 | 1149 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4191
diff
changeset
|
1150 |
uint z; |
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4191
diff
changeset
|
1151 |
Slope tileh = GetTileSlope(tile, &z); |
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4191
diff
changeset
|
1152 |
|
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4191
diff
changeset
|
1153 |
x &= 0xF; |
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4191
diff
changeset
|
1154 |
y &= 0xF; |
0 | 1155 |
|
3517
76814013e912
(svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents:
3493
diff
changeset
|
1156 |
if (IsTunnel(tile)) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1157 |
uint pos = (DiagDirToAxis(GetTunnelBridgeDirection(tile)) == AXIS_X ? y : x); |
0 | 1158 |
|
9574 | 1159 |
/* In the tunnel entrance? */ |
3517
76814013e912
(svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents:
3493
diff
changeset
|
1160 |
if (5 <= pos && pos <= 10) return z; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1161 |
} else { // IsBridge(tile) |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1162 |
DiagDirection dir = GetTunnelBridgeDirection(tile); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1163 |
uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x); |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3938
diff
changeset
|
1164 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1165 |
z += ApplyFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1166 |
|
9574 | 1167 |
/* On the bridge ramp? */ |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1168 |
if (5 <= pos && pos <= 10) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1169 |
uint delta; |
4246
14a8849c32df
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents:
4239
diff
changeset
|
1170 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1171 |
if (tileh != SLOPE_FLAT) return z + TILE_HEIGHT; |
3517
76814013e912
(svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents:
3493
diff
changeset
|
1172 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1173 |
switch (dir) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1174 |
default: NOT_REACHED(); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1175 |
case DIAGDIR_NE: delta = (TILE_SIZE - 1 - x) / 2; break; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1176 |
case DIAGDIR_SE: delta = y / 2; break; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1177 |
case DIAGDIR_SW: delta = x / 2; break; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1178 |
case DIAGDIR_NW: delta = (TILE_SIZE - 1 - y) / 2; break; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1179 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1180 |
return z + 1 + delta; |
0 | 1181 |
} |
1182 |
} |
|
1183 |
||
3517
76814013e912
(svn r4373) Rewrite GetSlopeZ_TunnelBridge() and slightly change its behavior:
tron
parents:
3493
diff
changeset
|
1184 |
return z + GetPartialZ(x, y, tileh); |
0 | 1185 |
} |
1186 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1187 |
static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh) |
2639 | 1188 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1189 |
return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(tile))); |
39 | 1190 |
} |
1191 |
||
1192 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1193 |
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac) |
0 | 1194 |
{ |
1195 |
/* not used */ |
|
1196 |
} |
|
1197 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1198 |
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td) |
0 | 1199 |
{ |
10955 | 1200 |
TransportType tt = GetTunnelBridgeTransportType(tile); |
1201 |
||
3184
7405329343ce
(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
|
1202 |
if (IsTunnel(tile)) { |
10955 | 1203 |
td->str = (tt == TRANSPORT_RAIL) ? STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL; |
1204 |
} else { // IsBridge(tile) |
|
1205 |
td->str = (tt == TRANSPORT_WATER) ? STR_AQUEDUCT : GetBridgeSpec(GetBridgeType(tile))->transport_name[tt]; |
|
0 | 1206 |
} |
10715
6bdf79ffb022
(svn r13265) [NoAI] -Sync with trunk r13185:13264.
rubidium
parents:
10645
diff
changeset
|
1207 |
td->owner[0] = GetTileOwner(tile); |
0 | 1208 |
} |
1209 |
||
1210 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1211 |
static void AnimateTile_TunnelBridge(TileIndex tile) |
0 | 1212 |
{ |
1213 |
/* not used */ |
|
1214 |
} |
|
1215 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1216 |
static void TileLoop_TunnelBridge(TileIndex tile) |
0 | 1217 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1218 |
bool snow_or_desert = HasTunnelBridgeSnowOrDesert(tile); |
10776 | 1219 |
switch (_settings_game.game_creation.landscape) { |
9517 | 1220 |
case LT_ARCTIC: |
9505 | 1221 |
if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1222 |
SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert); |
4160 | 1223 |
MarkTileDirtyByTile(tile); |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1224 |
} |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1225 |
break; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1226 |
|
9517 | 1227 |
case LT_TROPIC: |
5661
6c6145677e7c
(svn r7607) -Codechange: remove direct map accesses for snow/desert on tunnels and bridges.
rubidium
parents:
5573
diff
changeset
|
1228 |
if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1229 |
SetTunnelBridgeSnowOrDesert(tile, true); |
0 | 1230 |
MarkTileDirtyByTile(tile); |
1231 |
} |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
2989
diff
changeset
|
1232 |
break; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1233 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1234 |
default: |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1235 |
break; |
0 | 1236 |
} |
1237 |
} |
|
1238 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1239 |
static void ClickTile_TunnelBridge(TileIndex tile) |
0 | 1240 |
{ |
1241 |
/* not used */ |
|
1242 |
} |
|
1243 |
||
1244 |
||
9732 | 1245 |
static TrackStatus GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) |
0 | 1246 |
{ |
9732 | 1247 |
TransportType transport_type = GetTunnelBridgeTransportType(tile); |
1248 |
if (transport_type != mode || (transport_type == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0)) return 0; |
|
1249 |
||
1250 |
DiagDirection dir = GetTunnelBridgeDirection(tile); |
|
1251 |
if (side != INVALID_DIAGDIR && side != ReverseDiagDir(dir)) return 0; |
|
10645 | 1252 |
return CombineTrackStatus(TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir)), TRACKDIR_BIT_NONE); |
0 | 1253 |
} |
1254 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2422
diff
changeset
|
1255 |
static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 1256 |
{ |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1257 |
if (!IsTileOwner(tile, old_player)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1258 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4656
diff
changeset
|
1259 |
if (new_player != PLAYER_SPECTATOR) { |
1902 | 1260 |
SetTileOwner(tile, new_player); |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4344
diff
changeset
|
1261 |
} else { |
9732 | 1262 |
if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR))) { |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1263 |
/* When clearing the bridge/tunnel failed there are still vehicles on/in |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1264 |
* the bridge/tunnel. As all *our* vehicles are already removed, they |
10955 | 1265 |
* must be of another owner. Therefore this can't be rail tunnel/bridge. |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1266 |
* In that case we can safely reassign the ownership to OWNER_NONE. */ |
10955 | 1267 |
assert(GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL); |
9625
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1268 |
SetTileOwner(tile, OWNER_NONE); |
3301b1b3889c
(svn r10016) [NoAI] -Sync with trunk r9914:r10015.
rubidium
parents:
9624
diff
changeset
|
1269 |
} |
0 | 1270 |
} |
1271 |
} |
|
1272 |
||
1273 |
||
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1274 |
static const byte _tunnel_fractcoord_1[4] = {0x8E, 0x18, 0x81, 0xE8}; |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1275 |
static const byte _tunnel_fractcoord_2[4] = {0x81, 0x98, 0x87, 0x38}; |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1276 |
static const byte _tunnel_fractcoord_3[4] = {0x82, 0x88, 0x86, 0x48}; |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1277 |
static const byte _exit_tunnel_track[4] = {1, 2, 1, 2}; |
0 | 1278 |
|
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6319
diff
changeset
|
1279 |
/** Get the trackdir of the exit of a tunnel */ |
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6319
diff
changeset
|
1280 |
static const Trackdir _road_exit_tunnel_state[DIAGDIR_END] = { |
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6319
diff
changeset
|
1281 |
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE |
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6319
diff
changeset
|
1282 |
}; |
0 | 1283 |
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4}; |
1284 |
||
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1285 |
static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29}; |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1286 |
static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25}; |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1287 |
static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45}; |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1288 |
static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49}; |
0 | 1289 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1290 |
static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1291 |
{ |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1292 |
int z = GetSlopeZ(x, y) - v->z_pos; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1293 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1294 |
if (abs(z) > 2) return VETSB_CANNOT_ENTER; |
9732 | 1295 |
const DiagDirection dir = GetTunnelBridgeDirection(tile); |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1296 |
|
3184
7405329343ce
(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
|
1297 |
if (IsTunnel(tile)) { |
2989 | 1298 |
byte fc; |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1299 |
DiagDirection vdir; |
2989 | 1300 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1301 |
if (v->type == VEH_TRAIN) { |
2951 | 1302 |
fc = (x & 0xF) + (y << 4); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1303 |
|
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1304 |
vdir = DirToDiagDir(v->direction); |
0 | 1305 |
|
6319
27e68b914d3d
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents:
6317
diff
changeset
|
1306 |
if (v->u.rail.track != TRACK_BIT_WORMHOLE && dir == vdir) { |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2663
diff
changeset
|
1307 |
if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) { |
6539
6824b94ed21c
(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:
6467
diff
changeset
|
1308 |
if (!PlayVehicleSound(v, VSE_TUNNEL) && RailVehInfo(v->engine_type)->engclass == 0) { |
541 | 1309 |
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4559
diff
changeset
|
1310 |
} |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1311 |
return VETSB_CONTINUE; |
0 | 1312 |
} |
1313 |
if (fc == _tunnel_fractcoord_2[dir]) { |
|
1314 |
v->tile = tile; |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1315 |
v->u.rail.track = TRACK_BIT_WORMHOLE; |
0 | 1316 |
v->vehstatus |= VS_HIDDEN; |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1317 |
return VETSB_ENTERED_WORMHOLE; |
0 | 1318 |
} |
1319 |
} |
|
1320 |
||
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1321 |
if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) { |
22 | 1322 |
/* We're at the tunnel exit ?? */ |
0 | 1323 |
v->tile = tile; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1324 |
v->u.rail.track = (TrackBits)_exit_tunnel_track[dir]; |
1330
8a67d04016ce
(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
|
1325 |
assert(v->u.rail.track); |
0 | 1326 |
v->vehstatus &= ~VS_HIDDEN; |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1327 |
return VETSB_ENTERED_WORMHOLE; |
0 | 1328 |
} |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1329 |
} else if (v->type == VEH_ROAD) { |
2951 | 1330 |
fc = (x & 0xF) + (y << 4); |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1331 |
vdir = DirToDiagDir(v->direction); |
0 | 1332 |
|
9574 | 1333 |
/* Enter tunnel? */ |
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6319
diff
changeset
|
1334 |
if (v->u.road.state != RVSB_WORMHOLE && dir == vdir) { |
0 | 1335 |
if (fc == _tunnel_fractcoord_4[dir] || |
1336 |
fc == _tunnel_fractcoord_5[dir]) { |
|
1337 |
v->tile = tile; |
|
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6319
diff
changeset
|
1338 |
v->u.road.state = RVSB_WORMHOLE; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1339 |
v->vehstatus |= VS_HIDDEN; |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1340 |
return VETSB_ENTERED_WORMHOLE; |
0 | 1341 |
} else { |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1342 |
return VETSB_CONTINUE; |
0 | 1343 |
} |
1344 |
} |
|
1345 |
||
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1346 |
if (dir == ReverseDiagDir(vdir) && ( |
2951 | 1347 |
/* We're at the tunnel exit ?? */ |
1348 |
fc == _tunnel_fractcoord_6[dir] || |
|
1349 |
fc == _tunnel_fractcoord_7[dir] |
|
1350 |
) && |
|
0 | 1351 |
z == 0) { |
1352 |
v->tile = tile; |
|
1353 |
v->u.road.state = _road_exit_tunnel_state[dir]; |
|
1354 |
v->u.road.frame = _road_exit_tunnel_frame[dir]; |
|
1355 |
v->vehstatus &= ~VS_HIDDEN; |
|
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1356 |
return VETSB_ENTERED_WORMHOLE; |
0 | 1357 |
} |
1358 |
} |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1359 |
} else { // IsBridge(tile) |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1360 |
|
10920 | 1361 |
if (v->IsPrimaryVehicle() && v->type != VEH_SHIP) { |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1362 |
/* modify speed of vehicle */ |
9732 | 1363 |
uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1364 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1365 |
if (v->type == VEH_ROAD) spd *= 2; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1366 |
if (v->cur_speed > spd) v->cur_speed = spd; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1367 |
} |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1368 |
|
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1369 |
if (DirToDiagDir(v->direction) == dir) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1370 |
switch (dir) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1371 |
default: NOT_REACHED(); |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1372 |
case DIAGDIR_NE: if ((x & 0xF) != 0) return VETSB_CONTINUE; break; |
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1373 |
case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break; |
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1374 |
case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break; |
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1375 |
case DIAGDIR_NW: if ((y & 0xF) != 0) return VETSB_CONTINUE; break; |
0 | 1376 |
} |
10920 | 1377 |
switch (v->type) { |
1378 |
case VEH_TRAIN: |
|
1379 |
v->u.rail.track = TRACK_BIT_WORMHOLE; |
|
1380 |
ClrBit(v->u.rail.flags, VRF_GOINGUP); |
|
1381 |
ClrBit(v->u.rail.flags, VRF_GOINGDOWN); |
|
1382 |
break; |
|
1383 |
||
1384 |
case VEH_ROAD: |
|
1385 |
v->u.road.state = RVSB_WORMHOLE; |
|
1386 |
break; |
|
1387 |
||
1388 |
case VEH_SHIP: |
|
1389 |
v->u.ship.state = TRACK_BIT_WORMHOLE; |
|
1390 |
break; |
|
1391 |
||
1392 |
default: NOT_REACHED(); |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1393 |
} |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1394 |
return VETSB_ENTERED_WORMHOLE; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1395 |
} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) { |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1396 |
v->tile = tile; |
10920 | 1397 |
switch (v->type) { |
1398 |
case VEH_TRAIN: |
|
1399 |
if (v->u.rail.track == TRACK_BIT_WORMHOLE) { |
|
1400 |
v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y); |
|
1401 |
return VETSB_ENTERED_WORMHOLE; |
|
1402 |
} |
|
1403 |
break; |
|
1404 |
||
1405 |
case VEH_ROAD: |
|
1406 |
if (v->u.road.state == RVSB_WORMHOLE) { |
|
1407 |
v->u.road.state = _road_exit_tunnel_state[dir]; |
|
1408 |
v->u.road.frame = 0; |
|
1409 |
return VETSB_ENTERED_WORMHOLE; |
|
1410 |
} |
|
1411 |
break; |
|
1412 |
||
1413 |
case VEH_SHIP: |
|
1414 |
if (v->u.ship.state == TRACK_BIT_WORMHOLE) { |
|
1415 |
v->u.ship.state = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y); |
|
1416 |
return VETSB_ENTERED_WORMHOLE; |
|
1417 |
} |
|
1418 |
break; |
|
1419 |
||
1420 |
default: NOT_REACHED(); |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5116
diff
changeset
|
1421 |
} |
0 | 1422 |
} |
1423 |
} |
|
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6181
diff
changeset
|
1424 |
return VETSB_CONTINUE; |
0 | 1425 |
} |
1426 |
||
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1427 |
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1428 |
{ |
10920 | 1429 |
if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() && IsBridge(tile) && GetTunnelBridgeTransportType(tile) != TRANSPORT_WATER) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1430 |
DiagDirection direction = GetTunnelBridgeDirection(tile); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1431 |
Axis axis = DiagDirToAxis(direction); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1432 |
CommandCost res; |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1433 |
uint z_old; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1434 |
Slope tileh_old = GetTileSlope(tile, &z_old); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1435 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1436 |
/* Check if new slope is valid for bridges in general (so we can savely call GetBridgeFoundation()) */ |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1437 |
if ((direction == DIAGDIR_NW) || (direction == DIAGDIR_NE)) { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1438 |
CheckBridgeSlopeSouth(axis, &tileh_old, &z_old); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1439 |
res = CheckBridgeSlopeSouth(axis, &tileh_new, &z_new); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1440 |
} else { |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1441 |
CheckBridgeSlopeNorth(axis, &tileh_old, &z_old); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1442 |
res = CheckBridgeSlopeNorth(axis, &tileh_new, &z_new); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1443 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1444 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1445 |
/* Surface slope is valid and remains unchanged? */ |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
1446 |
if (!CmdFailed(res) && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1447 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
1448 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1449 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1450 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1451 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1452 |
extern const TileTypeProcs _tile_type_tunnelbridge_procs = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1453 |
DrawTile_TunnelBridge, /* draw_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1454 |
GetSlopeZ_TunnelBridge, /* get_slope_z_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1455 |
ClearTile_TunnelBridge, /* clear_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1456 |
GetAcceptedCargo_TunnelBridge, /* get_accepted_cargo_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1457 |
GetTileDesc_TunnelBridge, /* get_tile_desc_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1458 |
GetTileTrackStatus_TunnelBridge, /* get_tile_track_status_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1459 |
ClickTile_TunnelBridge, /* click_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1460 |
AnimateTile_TunnelBridge, /* animate_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1461 |
TileLoop_TunnelBridge, /* tile_loop_clear */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1462 |
ChangeTileOwner_TunnelBridge, /* change_tile_owner_clear */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1463 |
NULL, /* get_produced_cargo_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4304
diff
changeset
|
1464 |
VehicleEnter_TunnelBridge, /* vehicle_enter_tile_proc */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
1465 |
GetFoundation_TunnelBridge, /* get_foundation_proc */ |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
1466 |
TerraformTile_TunnelBridge, /* terraform_tile_proc */ |
0 | 1467 |
}; |