author | Darkvater |
Thu, 02 Jun 2005 19:30:21 +0000 | |
changeset 1891 | 92a3b0aa0946 |
parent 1884 | ae1d6213c6dd |
child 1901 | fb05044cf5c3 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1884
diff
changeset
|
2 |
#include "openttd.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
3 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
4 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
541
diff
changeset
|
5 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1192
diff
changeset
|
6 |
#include "tile.h" |
0 | 7 |
#include "vehicle.h" |
8 |
#include "viewport.h" |
|
9 |
#include "command.h" |
|
10 |
#include "player.h" |
|
11 |
#include "town.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
334
diff
changeset
|
12 |
#include "sound.h" |
0 | 13 |
|
14 |
extern void DrawCanalWater(uint tile); |
|
15 |
||
16 |
static const byte _bridge_available_year[MAX_BRIDGES] = { |
|
17 |
0, 0, 10, 0, 10, 10, 10, 10, 10, 10, 75, 85, 90 |
|
18 |
}; |
|
19 |
||
20 |
static const byte _bridge_minlen[MAX_BRIDGES] = { |
|
21 |
0, 0, 0, 2, 3, 3, 3, 3, 3, 0, 2, 2, 2 |
|
22 |
}; |
|
23 |
||
24 |
static const byte _bridge_maxlen[MAX_BRIDGES] = { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
25 |
16, 2, 5, 10, 16, 16, 7, 8, 9, 2, 16, 32, 32, |
0 | 26 |
}; |
27 |
||
28 |
const uint16 _bridge_type_price_mod[MAX_BRIDGES] = { |
|
29 |
80, 112, 144, 168, 185, 192, 224, 232, 248, 240, 255, 380, 510, |
|
30 |
}; |
|
31 |
||
32 |
const uint16 _bridge_speeds[MAX_BRIDGES] = { |
|
33 |
0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x0A0, 0x0D0, 0x0F0, 0x100, 0x140, 0x200, 0x260 |
|
34 |
}; |
|
35 |
||
36 |
const PalSpriteID _bridge_sprites[MAX_BRIDGES] = { |
|
37 |
0x0A24, 0x31E8A26, 0x0A25, 0x3208A22, |
|
38 |
0x0A22, 0x3218A22, 0x0A23, 0x31C8A23, |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
39 |
0x31E8A23, 0x0A27, 0x0A28, 0x3218A28, |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
40 |
0x3238A28, |
0 | 41 |
}; |
42 |
||
43 |
const StringID _bridge_material[MAX_BRIDGES] = { |
|
44 |
STR_5012_WOODEN, |
|
45 |
STR_5013_CONCRETE, |
|
46 |
STR_500F_GIRDER_STEEL, |
|
47 |
STR_5011_SUSPENSION_CONCRETE, |
|
48 |
STR_500E_SUSPENSION_STEEL, |
|
49 |
STR_500E_SUSPENSION_STEEL, |
|
50 |
STR_5010_CANTILEVER_STEEL, |
|
51 |
STR_5010_CANTILEVER_STEEL, |
|
52 |
STR_5010_CANTILEVER_STEEL, |
|
53 |
STR_500F_GIRDER_STEEL, |
|
54 |
STR_5014_TUBULAR_STEEL, |
|
55 |
STR_5014_TUBULAR_STEEL, |
|
56 |
STR_BRIDGE_TUBULAR_SILICON, |
|
57 |
}; |
|
58 |
||
59 |
// calculate the price factor for building a long bridge. |
|
60 |
// 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, |
|
61 |
int CalcBridgeLenCostFactor(int x) |
|
62 |
{ |
|
63 |
int n,r; |
|
64 |
if (x < 2) return x; |
|
65 |
x -= 2; |
|
66 |
for(n=0,r=2;;n++) { |
|
67 |
if (x <= n) return r + x * n; |
|
68 |
r += n * n; |
|
69 |
x -= n; |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
enum { |
|
74 |
// foundation, whole tile is leveled up (tileh's 7, 11, 13, 14) --> 3 corners raised |
|
75 |
BRIDGE_FULL_LEVELED_FOUNDATION = 1 << 7 | 1 << 11 | 1 << 13 | 1 << 14, |
|
76 |
// foundation, tile is partly leveled up (tileh's 1, 2, 4, 8) --> 1 corner raised |
|
77 |
BRIDGE_PARTLY_LEVELED_FOUNDATION = 1 << 1 | 1 << 2 | 1 << 4 | 1 << 8, |
|
78 |
// no foundations (X,Y direction) (tileh's 0, 3, 6, 9, 12) |
|
79 |
BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12, |
|
80 |
}; |
|
81 |
||
82 |
/* check if bridge can be built on slope |
|
83 |
* direction 0 = X-axis, direction 1 = Y-axis |
|
84 |
* is_start_tile = false <-- end tile |
|
85 |
* is_start_tile = true <-- start tile |
|
86 |
*/ |
|
87 |
static uint32 CheckBridgeSlope(uint direction, uint tileh, bool is_start_tile) |
|
88 |
{ |
|
89 |
if (!(tileh & 0x10)) { // disable building on very steep slopes |
|
90 |
||
91 |
if (is_start_tile) { |
|
92 |
/* check slope at start tile |
|
93 |
- no extra cost |
|
94 |
- direction X: tiles 0,12 |
|
95 |
- direction Y: tiles 0, 9 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
96 |
*/ |
0 | 97 |
if ((direction?0x201:0x1001) & (1 << tileh)) |
98 |
return 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
99 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
100 |
// disallow certain start tiles to avoid certain crooked bridges |
0 | 101 |
if (tileh == 2) |
102 |
return CMD_ERROR; |
|
103 |
||
104 |
} |
|
105 |
else { |
|
106 |
/* check slope at end tile |
|
107 |
- no extra cost |
|
108 |
- direction X: tiles 0, 3 |
|
109 |
- direction Y: tiles 0, 6 |
|
110 |
*/ |
|
111 |
if ((direction?0x41:0x9) & (1 << tileh)) |
|
112 |
return 0; |
|
113 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
114 |
// disallow certain end tiles to avoid certain crooked bridges |
0 | 115 |
if (tileh == 8) |
116 |
return CMD_ERROR; |
|
117 |
||
118 |
} |
|
119 |
||
120 |
/* disallow common start/end tiles to avoid certain crooked bridges e.g. |
|
121 |
* start-tile: X 2,1 Y 2,4 (2 was disabled before) |
|
122 |
* end-tile: X 8,4 Y 8,1 (8 was disabled before) |
|
123 |
*/ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
124 |
if ( (tileh == 1 && (is_start_tile != (bool)direction)) || |
0 | 125 |
(tileh == 4 && (is_start_tile == (bool)direction)) ) |
126 |
return CMD_ERROR; |
|
127 |
||
128 |
// slope foundations |
|
129 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh) || BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << tileh)) |
|
130 |
return _price.terraform; |
|
131 |
} |
|
132 |
||
133 |
return CMD_ERROR; |
|
134 |
} |
|
135 |
||
136 |
uint32 GetBridgeLength(TileIndex begin, TileIndex end) |
|
137 |
{ |
|
138 |
int x1, y1, x2, y2; // coordinates of starting and end tiles |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
139 |
x1 = TileX(begin); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
140 |
y1 = TileY(begin); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
141 |
x2 = TileX(end); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
142 |
y2 = TileY(end); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
143 |
|
0 | 144 |
return abs((x2 + y2 - x1 - y1)) - 1; |
145 |
} |
|
146 |
||
147 |
bool CheckBridge_Stuff(byte bridge_type, int bridge_len) |
|
148 |
{ |
|
149 |
int max; // max possible length of a bridge (with patch 100) |
|
150 |
||
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
|
151 |
if (bridge_type >= MAX_BRIDGES) return false; |
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
|
152 |
if (_bridge_available_year[bridge_type] > _cur_year) return false; |
0 | 153 |
|
154 |
max = _bridge_maxlen[bridge_type]; |
|
155 |
if (max >= 16 && _patches.longbridges) |
|
156 |
max = 100; |
|
157 |
||
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
|
158 |
if (bridge_len < _bridge_minlen[bridge_type] || bridge_len > max) return false; |
0 | 159 |
|
160 |
return true; |
|
161 |
} |
|
162 |
||
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
|
163 |
/** Build a Bridge |
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
|
164 |
* @param x,y end tile coord |
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
|
165 |
* @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
|
166 |
* @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
|
167 |
* - p2 = (bit 0- 7) - bridge type (hi bh) |
08ff0f12ccdc
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
168 |
* - p2 = (bit 8-..) - rail type. bit15 ((x>>8)&0x80) means road bridge. |
0 | 169 |
*/ |
170 |
int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
171 |
{ |
|
172 |
int bridge_type; |
|
173 |
byte rail_or_road, railtype, m5; |
|
174 |
int sx,sy; |
|
175 |
TileInfo ti_start, ti_end, ti; /* OPT: only 2 of those are ever used */ |
|
176 |
int bridge_len, odd_middle_part; |
|
177 |
uint direction; |
|
178 |
int i; |
|
179 |
int32 cost, terraformcost, ret; |
|
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
180 |
bool allow_on_slopes; |
0 | 181 |
|
182 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
183 |
|
0 | 184 |
/* unpack parameters */ |
185 |
bridge_type = p2 & 0xFF; |
|
186 |
railtype = (byte)(p2 >> 8); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
187 |
|
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
|
188 |
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
|
189 |
|
0 | 190 |
// type of bridge |
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
|
191 |
if (HASBIT(railtype, 7)) { // bit 15 of original p2 param |
0 | 192 |
railtype = 0; |
193 |
rail_or_road = 2; |
|
194 |
} else { |
|
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
|
195 |
if (!ValParamRailtype(railtype)) return CMD_ERROR; |
0 | 196 |
rail_or_road = 0; |
197 |
} |
|
198 |
||
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
199 |
sx = TileX(p1) * 16; |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
900
diff
changeset
|
200 |
sy = TileY(p1) * 16; |
0 | 201 |
|
202 |
direction = 0; |
|
203 |
||
204 |
/* check if valid, and make sure that (x,y) are smaller than (sx,sy) */ |
|
205 |
if (x == sx) { |
|
206 |
if (y == sy) |
|
207 |
return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); |
|
208 |
direction = 1; |
|
209 |
if (y > sy) { |
|
210 |
intswap(y,sy); |
|
211 |
intswap(x,sx); |
|
212 |
} |
|
213 |
} else if (y == sy) { |
|
214 |
if (x > sx) { |
|
215 |
intswap(y,sy); |
|
216 |
intswap(x,sx); |
|
217 |
} |
|
218 |
} else |
|
219 |
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); |
|
220 |
||
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
|
221 |
/* set and test bridge length, availability */ |
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
|
222 |
bridge_len = ((sx + sy - x - y) >> 4) - 1; |
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
|
223 |
if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE); |
92e08797c84b
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
224 |
|
0 | 225 |
/* retrieve landscape height and ensure it's on land */ |
226 |
if ( |
|
227 |
((FindLandscapeHeight(&ti_end, sx, sy), |
|
228 |
ti_end.type == MP_WATER) && ti_end.map5 == 0) || |
|
229 |
((FindLandscapeHeight(&ti_start, x, y), |
|
230 |
ti_start.type == MP_WATER) && ti_start.map5 == 0)) |
|
231 |
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH); |
|
232 |
||
233 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_start.tileh)) { |
|
234 |
ti_start.z += 8; |
|
235 |
ti_start.tileh = 0; |
|
236 |
} |
|
237 |
||
238 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_end.tileh)) { |
|
239 |
ti_end.z += 8; |
|
240 |
ti_end.tileh = 0; |
|
241 |
} |
|
242 |
||
243 |
if (ti_start.z != ti_end.z) |
|
244 |
return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); |
|
245 |
||
246 |
_error_message = STR_500C; |
|
247 |
||
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
248 |
|
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
249 |
// Towns are not allowed to use bridges on slopes. |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
250 |
allow_on_slopes = ((!_is_ai_player || _patches.ainew_active) |
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
|
251 |
&& _current_player != OWNER_TOWN && _patches.build_on_slopes); |
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
252 |
|
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
253 |
/* Try and clear the start landscape */ |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
254 |
|
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
|
255 |
if (CmdFailed(ret = DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) |
0 | 256 |
return CMD_ERROR; |
257 |
cost = ret; |
|
258 |
||
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
259 |
// true - bridge-start-tile, false - bridge-end-tile |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
260 |
terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true); |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
261 |
if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes)) |
0 | 262 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
263 |
cost += terraformcost; |
|
264 |
||
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
265 |
/* Try and clear the end landscape */ |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
266 |
|
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
|
267 |
if (CmdFailed(ret = DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) |
0 | 268 |
return CMD_ERROR; |
269 |
cost += ret; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
270 |
|
1585
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
271 |
// false - end tile slope check |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
272 |
terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false); |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
273 |
if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes)) |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
274 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3dc279e97623
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
275 |
cost += terraformcost; |
0 | 276 |
|
277 |
||
278 |
/* do the drill? */ |
|
279 |
if (flags & DC_EXEC) { |
|
280 |
/* build the start tile */ |
|
281 |
ModifyTile(ti_start.tile, |
|
282 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
283 |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
284 |
(bridge_type << 4), /* map2 */ |
|
285 |
railtype, /* map3_lo */ |
|
286 |
0x80 | direction | rail_or_road /* map5 */ |
|
287 |
); |
|
288 |
||
289 |
/* build the end tile */ |
|
290 |
ModifyTile(ti_end.tile, |
|
291 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
292 |
MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
293 |
(bridge_type << 4), /* map2 */ |
|
294 |
railtype, /* map3_lo */ |
|
295 |
0x80 | 0x20 | direction | rail_or_road /* map5 */ |
|
296 |
); |
|
297 |
} |
|
298 |
||
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
|
299 |
// position of middle part of the odd bridge (larger than MAX(i) otherwise) |
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
|
300 |
odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len; |
0 | 301 |
|
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
|
302 |
for (i = 0; i != bridge_len; i++) { |
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
|
303 |
if (direction != 0) { |
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
|
304 |
y += 16; |
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
|
305 |
} else |
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
|
306 |
x += 16; |
0 | 307 |
|
308 |
FindLandscapeHeight(&ti, x, y); |
|
309 |
||
310 |
_error_message = STR_5009_LEVEL_LAND_OR_WATER_REQUIRED; |
|
311 |
if (ti.tileh != 0 && ti.z >= ti_start.z) |
|
312 |
return CMD_ERROR; |
|
313 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
314 |
// Find ship below |
0 | 315 |
if ( ti.type == MP_WATER && !EnsureNoVehicle(ti.tile) ) |
316 |
{ |
|
317 |
_error_message = STR_980E_SHIP_IN_THE_WAY; |
|
318 |
return CMD_ERROR; |
|
319 |
} |
|
320 |
||
321 |
if (ti.type == MP_WATER) { |
|
1091
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
322 |
if (ti.map5 > 1) goto not_valid_below; |
0 | 323 |
m5 = 0xC8; |
324 |
} else if (ti.type == MP_RAILWAY) { |
|
325 |
if (direction == 0) { |
|
326 |
if (ti.map5 != 2) goto not_valid_below; |
|
327 |
} else { |
|
328 |
if (ti.map5 != 1) goto not_valid_below; |
|
329 |
} |
|
330 |
m5 = 0xE0; |
|
331 |
} else if (ti.type == MP_STREET) { |
|
332 |
if (direction == 0) { |
|
333 |
if (ti.map5 != 5) goto not_valid_below; |
|
334 |
} else { |
|
335 |
if (ti.map5 != 10) goto not_valid_below; |
|
336 |
} |
|
337 |
m5 = 0xE8; |
|
338 |
} else { |
|
339 |
not_valid_below:; |
|
340 |
/* try and clear the middle landscape */ |
|
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
|
341 |
if (CmdFailed(ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) |
0 | 342 |
return CMD_ERROR; |
343 |
cost += ret; |
|
344 |
m5 = 0xC0; |
|
345 |
} |
|
346 |
||
347 |
/* do middle part of bridge */ |
|
348 |
if (flags & DC_EXEC) { |
|
349 |
_map5[ti.tile] = (byte)(m5 | direction | rail_or_road); |
|
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
350 |
SetTileType(ti.tile, MP_TUNNELBRIDGE); |
0 | 351 |
|
352 |
//bridges pieces sequence (middle parts) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
353 |
// bridge len 1: 0 |
0 | 354 |
// bridge len 2: 0 1 |
355 |
// bridge len 3: 0 4 1 |
|
356 |
// bridge len 4: 0 2 3 1 |
|
357 |
// bridge len 5: 0 2 5 3 1 |
|
358 |
// bridge len 6: 0 2 3 2 3 1 |
|
359 |
// bridge len 7: 0 2 3 4 2 3 1 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
360 |
// #0 - alwats as first, #1 - always as last (if len>1) |
0 | 361 |
// #2,#3 are to pair in order |
362 |
// for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0) |
|
363 |
||
364 |
if(i==0) //first tile |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
365 |
m5 = 0; |
0 | 366 |
else if (i==bridge_len-1) //last tile |
367 |
m5 = 1; |
|
368 |
else if(i==odd_middle_part) //we are on the middle of odd bridge: #5 on even pos, #4 on odd |
|
369 |
m5 = 5 - (i%2); |
|
370 |
else { |
|
371 |
// generate #2 and #3 in turns [i%2==0], after the middle of odd bridge |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
372 |
// this sequence swaps [... XOR (i>odd_middle_part)], |
0 | 373 |
// for even bridges XOR does not apply as odd_middle_part==bridge_len |
374 |
m5 = 2 + ((i%2==0)^(i>odd_middle_part)); |
|
375 |
} |
|
376 |
||
377 |
_map2[ti.tile] = (bridge_type << 4) | m5; |
|
378 |
_map3_lo[ti.tile] &= 0xF; |
|
379 |
_map3_lo[ti.tile] |= (byte)(railtype << 4); |
|
380 |
||
381 |
MarkTileDirtyByTile(ti.tile); |
|
382 |
} |
|
383 |
} |
|
384 |
||
385 |
SetSignalsOnBothDir(ti_start.tile, (direction&1) ? 1 : 0); |
|
386 |
||
387 |
/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST) |
|
388 |
It's unnecessary to execute this command every time for every bridge. So it is done only |
|
389 |
and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated |
|
390 |
*/ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
391 |
if (!(flags & DC_QUERY_COST)) { |
0 | 392 |
bridge_len += 2; // begin and end tiles/ramps |
393 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
39
diff
changeset
|
394 |
if (_current_player < MAX_PLAYERS && !(_is_ai_player && !_patches.ainew_active)) |
0 | 395 |
bridge_len = CalcBridgeLenCostFactor(bridge_len); |
396 |
||
203
d16d6e91bff8
(svn r204) -Fix: deleted unneeded casts (tnx Tron)
truelight
parents:
200
diff
changeset
|
397 |
cost += ((int64)bridge_len * _price.build_bridge * _bridge_type_price_mod[bridge_type]) >> 8; |
0 | 398 |
} |
399 |
||
400 |
return cost; |
|
401 |
} |
|
402 |
||
403 |
static bool DoCheckTunnelInWay(uint tile, uint z, uint dir) |
|
404 |
{ |
|
405 |
TileInfo ti; |
|
406 |
int delta; |
|
407 |
||
900 | 408 |
delta = TileOffsByDir(dir); |
0 | 409 |
|
410 |
do { |
|
411 |
tile -= delta; |
|
412 |
FindLandscapeHeightByTile(&ti, tile); |
|
413 |
} while (z < ti.z); |
|
414 |
||
415 |
if (z == ti.z && ti.type == MP_TUNNELBRIDGE && (ti.map5&0xF0) == 0 && (ti.map5&3) == dir) { |
|
416 |
_error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY; |
|
417 |
return false; |
|
418 |
} |
|
419 |
||
420 |
return true; |
|
421 |
} |
|
422 |
||
423 |
bool CheckTunnelInWay(uint tile, int z) |
|
424 |
{ |
|
425 |
return DoCheckTunnelInWay(tile,z,0) && |
|
426 |
DoCheckTunnelInWay(tile,z,1) && |
|
427 |
DoCheckTunnelInWay(tile,z,2) && |
|
428 |
DoCheckTunnelInWay(tile,z,3); |
|
429 |
} |
|
430 |
||
431 |
static byte _build_tunnel_bh; |
|
432 |
static byte _build_tunnel_railtype; |
|
433 |
||
434 |
static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_tile) |
|
435 |
{ |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
436 |
TileIndex end_tile; |
0 | 437 |
int direction; |
438 |
int32 cost, ret; |
|
439 |
TileInfo ti; |
|
440 |
uint z; |
|
441 |
||
856
07dc27d0503e
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
679
diff
changeset
|
442 |
if ((uint)x > MapMaxX() * 16 - 1 || (uint)y > MapMaxY() * 16 - 1) |
0 | 443 |
return CMD_ERROR; |
444 |
||
445 |
/* check if valid, and make sure that (x,y) is smaller than (x2,y2) */ |
|
446 |
direction = 0; |
|
447 |
if (x == x2) { |
|
448 |
if (y == y2) |
|
449 |
return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); |
|
450 |
direction++; |
|
451 |
if (y > y2) { |
|
452 |
intswap(y,y2); |
|
453 |
intswap(x,x2); |
|
454 |
exc_tile|=2; |
|
455 |
} |
|
456 |
} else if (y == y2) { |
|
457 |
if (x > x2) { |
|
458 |
intswap(y,y2); |
|
459 |
intswap(x,x2); |
|
460 |
exc_tile|=2; |
|
461 |
} |
|
462 |
} else |
|
463 |
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); |
|
464 |
||
465 |
cost = 0; |
|
466 |
||
467 |
FindLandscapeHeight(&ti, x2, y2); |
|
468 |
end_tile = ti.tile; |
|
469 |
z = ti.z; |
|
470 |
||
471 |
if (exc_tile != 3) { |
|
472 |
if ( (direction ? 9U : 12U) != ti.tileh) |
|
473 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
474 |
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
475 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 476 |
cost += ret; |
477 |
} |
|
478 |
cost += _price.build_tunnel; |
|
479 |
||
480 |
for(;;) { |
|
481 |
if (direction) y2-=16; else x2-=16; |
|
482 |
||
483 |
if (x2 == x && y2 == y) |
|
484 |
break; |
|
485 |
||
486 |
FindLandscapeHeight(&ti, x2, y2); |
|
487 |
if (ti.z <= z) |
|
488 |
return_cmd_error(STR_5002); |
|
489 |
||
490 |
if (!_cheats.crossing_tunnels.value && !CheckTunnelInWay(ti.tile, z)) |
|
491 |
return CMD_ERROR; |
|
492 |
||
493 |
cost += _price.build_tunnel; |
|
494 |
cost += (cost >> 3); |
|
495 |
||
496 |
if (cost >= 400000000) |
|
497 |
cost = 400000000; |
|
498 |
} |
|
499 |
||
500 |
FindLandscapeHeight(&ti, x2, y2); |
|
501 |
if (ti.z != z) |
|
502 |
return_cmd_error(STR_5004); |
|
503 |
||
504 |
if (exc_tile != 1) { |
|
505 |
if ( (direction ? 6U : 3U) != ti.tileh) |
|
506 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
507 |
||
508 |
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
509 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 510 |
cost += ret; |
511 |
} |
|
512 |
||
513 |
if (flags & DC_EXEC) { |
|
514 |
ModifyTile(ti.tile, |
|
515 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
516 |
MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
517 |
_build_tunnel_railtype, /* map3lo */ |
|
518 |
((_build_tunnel_bh << 1) | 2) - direction /* map5 */ |
|
519 |
); |
|
520 |
||
521 |
ModifyTile(end_tile, |
|
522 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
523 |
MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
524 |
_build_tunnel_railtype, /* map3lo */ |
|
525 |
(_build_tunnel_bh << 1) | (direction ? 3:0)/* map5 */ |
|
526 |
); |
|
527 |
||
528 |
UpdateSignalsOnSegment(end_tile, direction?7:1); |
|
529 |
} |
|
530 |
||
531 |
return cost + _price.build_tunnel; |
|
532 |
} |
|
533 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
534 |
/** Build Tunnel. |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
535 |
* @param x,y start tile coord of tunnel |
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
536 |
* @param p1 railtype, 0x200 for road tunnel |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
537 |
* @param p2 unused (XXX - ptr to uint that recieves end tile; wtf?????) |
0 | 538 |
*/ |
539 |
int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
540 |
{ |
|
541 |
TileInfo ti, tiorg; |
|
542 |
int direction; |
|
543 |
uint z; |
|
544 |
static const int8 _build_tunnel_coord_mod[4+1] = { -16, 0, 16, 0, -16 }; |
|
545 |
static const byte _build_tunnel_tileh[4] = {3, 9, 12, 6}; |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
546 |
TileIndex excavated_tile; |
0 | 547 |
|
548 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
549 |
||
1784
6eb3ab1bc33c
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
550 |
if (p1 != 0x200 && !ValParamRailtype(p1)) return CMD_ERROR; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
551 |
|
0 | 552 |
_build_tunnel_railtype = (byte)(p1 & 0xFF); |
553 |
_build_tunnel_bh = (byte)(p1 >> 8); |
|
554 |
||
555 |
_build_tunnel_endtile = 0; |
|
556 |
excavated_tile = 0; |
|
557 |
||
558 |
FindLandscapeHeight(&tiorg, x, y); |
|
559 |
||
560 |
if (!EnsureNoVehicle(tiorg.tile)) |
|
561 |
return CMD_ERROR; |
|
562 |
||
563 |
if (!(direction=0, tiorg.tileh==12) && |
|
564 |
!(direction++, tiorg.tileh==6) && |
|
565 |
!(direction++, tiorg.tileh==3) && |
|
566 |
!(direction++, tiorg.tileh==9) ) |
|
567 |
return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL); |
|
568 |
||
569 |
z = tiorg.z; |
|
570 |
do { |
|
571 |
x += _build_tunnel_coord_mod[direction]; |
|
572 |
y += _build_tunnel_coord_mod[direction+1]; |
|
573 |
FindLandscapeHeight(&ti, x, y); |
|
574 |
} while (z != ti.z); |
|
575 |
_build_tunnel_endtile = ti.tile; |
|
576 |
||
577 |
||
578 |
if (!EnsureNoVehicle(ti.tile)) |
|
579 |
return CMD_ERROR; |
|
580 |
||
581 |
if (ti.tileh != _build_tunnel_tileh[direction]) { |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
582 |
if (CmdFailed(DoCommandByTile(ti.tile, ti.tileh & ~_build_tunnel_tileh[direction], 0, flags, CMD_TERRAFORM_LAND))) |
0 | 583 |
return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND); |
584 |
excavated_tile = 1; |
|
585 |
} |
|
586 |
||
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
587 |
return DoBuildTunnel(x, y, tiorg.x, tiorg.y, flags, excavated_tile); |
0 | 588 |
} |
589 |
||
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
590 |
TileIndex CheckTunnelBusy(TileIndex tile, uint *length) |
0 | 591 |
{ |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
592 |
uint z = GetTileZ(tile); |
0 | 593 |
byte m5 = _map5[tile]; |
900 | 594 |
int delta = TileOffsByDir(m5 & 3); |
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
595 |
uint len = 0; |
0 | 596 |
uint starttile = tile; |
597 |
Vehicle *v; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
598 |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
599 |
do { |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
600 |
tile += delta; |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
601 |
len++; |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
602 |
} while ( |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
603 |
!IsTileType(tile, MP_TUNNELBRIDGE) || |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
604 |
(_map5[tile] & 0xF0) != 0 || |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
605 |
(byte)(_map5[tile] ^ 2) != m5 || |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
606 |
GetTileZ(tile) != z |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
607 |
); |
0 | 608 |
|
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
609 |
v = FindVehicleBetween(starttile, tile, z); |
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
610 |
if (v != NULL) { |
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
611 |
_error_message = v->type == VEH_Train ? |
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
612 |
STR_5000_TRAIN_IN_TUNNEL : STR_5001_ROAD_VEHICLE_IN_TUNNEL; |
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
613 |
return INVALID_TILE; |
0 | 614 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
615 |
|
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
616 |
if (length != NULL) *length = len; |
0 | 617 |
return tile; |
618 |
} |
|
619 |
||
620 |
static int32 DoClearTunnel(uint tile, uint32 flags) |
|
621 |
{ |
|
622 |
Town *t; |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
623 |
TileIndex endtile; |
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
624 |
uint length; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
625 |
static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3}; |
0 | 626 |
|
627 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
628 |
||
629 |
// in scenario editor you can always destroy tunnels |
|
630 |
if (_game_mode != GM_EDITOR && !CheckTileOwnership(tile)) { |
|
631 |
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || _map_owner[tile] != OWNER_TOWN) |
|
632 |
return CMD_ERROR; |
|
633 |
} |
|
634 |
||
635 |
endtile = CheckTunnelBusy(tile, &length); |
|
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
636 |
if (endtile == INVALID_TILE) return CMD_ERROR; |
0 | 637 |
|
638 |
_build_tunnel_endtile = endtile; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
639 |
|
0 | 640 |
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty |
641 |
// check if you're allowed to remove the tunnel owned by a town |
|
642 |
// removal allowal depends on difficulty settings |
|
643 |
if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR ) { |
|
644 |
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
511
diff
changeset
|
645 |
SetDParam(0, t->index); |
0 | 646 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
647 |
} |
|
648 |
} |
|
649 |
||
650 |
if (flags & DC_EXEC) { |
|
38
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
651 |
// We first need to request the direction before calling DoClearSquare |
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
652 |
// else the direction is always 0.. dah!! ;) |
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
653 |
byte tile_dir = _map5[tile]&3; |
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
654 |
byte endtile_dir = _map5[endtile]&3; |
0 | 655 |
DoClearSquare(tile); |
656 |
DoClearSquare(endtile); |
|
38
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
657 |
UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]); |
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
658 |
UpdateSignalsOnSegment(endtile, _updsignals_tunnel_dir[endtile_dir]); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
659 |
if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) |
1005 | 660 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
0 | 661 |
} |
662 |
return _price.clear_tunnel * (length + 1); |
|
663 |
} |
|
664 |
||
665 |
static uint FindEdgesOfBridge(uint tile, uint *endtile) |
|
666 |
{ |
|
667 |
int direction = _map5[tile] & 1; |
|
668 |
uint start; |
|
669 |
||
670 |
// find start of bridge |
|
671 |
for(;;) { |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
672 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0x80) |
0 | 673 |
break; |
674 |
tile += direction ? TILE_XY(0,-1) : TILE_XY(-1,0); |
|
675 |
} |
|
676 |
||
677 |
start = tile; |
|
678 |
||
679 |
// find end of bridge |
|
680 |
for(;;) { |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
681 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0xA0) |
0 | 682 |
break; |
683 |
tile += direction ? TILE_XY(0,1) : TILE_XY(1,0); |
|
684 |
} |
|
685 |
||
686 |
*endtile = tile; |
|
687 |
||
688 |
return start; |
|
689 |
} |
|
690 |
||
691 |
static int32 DoClearBridge(uint tile, uint32 flags) |
|
692 |
{ |
|
693 |
uint endtile; |
|
694 |
Vehicle *v; |
|
695 |
Town *t; |
|
696 |
int direction; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
697 |
|
0 | 698 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
699 |
||
700 |
direction = _map5[tile]&1; |
|
701 |
||
702 |
/* delete stuff under the middle part if there's a transport route there..? */ |
|
703 |
if ((_map5[tile] & 0xE0) == 0xE0) { |
|
704 |
int32 cost; |
|
705 |
||
706 |
// check if we own the tile below the bridge.. |
|
1041
be151b7bc909
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
707 |
if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))) |
0 | 708 |
return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
709 |
|
0 | 710 |
cost = (_map5[tile] & 8) ? _price.remove_road * 2 : _price.remove_rail; |
711 |
||
712 |
if (flags & DC_EXEC) { |
|
713 |
_map5[tile] = _map5[tile] & ~0x38; |
|
714 |
_map_owner[tile] = OWNER_NONE; |
|
715 |
MarkTileDirtyByTile(tile); |
|
716 |
} |
|
717 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
718 |
|
0 | 719 |
/* delete canal under bridge */ |
1041
be151b7bc909
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
720 |
} else if(_map5[tile] == 0xC8 && TilePixelHeight(tile) != 0) { |
0 | 721 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
722 |
|
0 | 723 |
// check for vehicles under bridge |
1041
be151b7bc909
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
724 |
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 725 |
return CMD_ERROR; |
726 |
cost = _price.clear_water; |
|
727 |
if (flags & DC_EXEC) { |
|
728 |
_map5[tile] = _map5[tile] & ~0x38; |
|
729 |
_map_owner[tile] = OWNER_NONE; |
|
730 |
MarkTileDirtyByTile(tile); |
|
731 |
} |
|
732 |
return cost; |
|
733 |
} |
|
734 |
||
735 |
tile = FindEdgesOfBridge(tile, &endtile); |
|
736 |
||
737 |
// floods, scenario editor can always destroy bridges |
|
738 |
if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) { |
|
739 |
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || _map_owner[tile] != OWNER_TOWN) |
|
740 |
return CMD_ERROR; |
|
741 |
} |
|
742 |
||
743 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) |
|
744 |
return CMD_ERROR; |
|
745 |
||
746 |
/* Make sure there's no vehicle on the bridge |
|
747 |
Omit tile and endtile, since these are already checked, thus solving the problem |
|
748 |
of bridges over water, or higher bridges, where z is not increased, eg level bridge |
|
749 |
*/ |
|
750 |
tile += direction ? TILE_XY(0, 1) : TILE_XY( 1,0); |
|
751 |
endtile -= direction ? TILE_XY(0, 1) : TILE_XY( 1,0); |
|
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
|
752 |
/* Bridges on slopes might have their Z-value offset..correct this */ |
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
|
753 |
if ((v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile))) != NULL) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
754 |
VehicleInTheWayErrMsg(v); |
0 | 755 |
return CMD_ERROR; |
756 |
} |
|
757 |
||
758 |
/* Put the tiles back to start/end position */ |
|
759 |
tile -= direction ? TILE_XY(0, 1) : TILE_XY( 1,0); |
|
760 |
endtile += direction ? TILE_XY(0, 1) : TILE_XY( 1,0); |
|
761 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
762 |
|
0 | 763 |
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
764 |
// check if you're allowed to remove the bridge owned by a town. |
0 | 765 |
// removal allowal depends on difficulty settings |
766 |
if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
767 |
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) |
0 | 768 |
return CMD_ERROR; |
769 |
} |
|
770 |
||
771 |
if (flags & DC_EXEC) { |
|
772 |
byte m5; |
|
773 |
uint c = tile; |
|
774 |
uint16 new_data; |
|
775 |
||
1005 | 776 |
//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until |
0 | 777 |
// you have a "Poor" (0) town rating |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
778 |
if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) |
1005 | 779 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
0 | 780 |
|
781 |
do { |
|
782 |
m5 = _map5[c]; |
|
783 |
||
784 |
if (m5 & 0x40) { |
|
785 |
if (m5 & 0x20) { |
|
786 |
static const uint16 _new_data_table[] = {0x1002, 0x1001, 0x2005, 0x200A, 0, 0, 0, 0}; |
|
787 |
new_data = _new_data_table[((m5 & 0x18) >> 2) | (m5&1)]; |
|
788 |
} else { |
|
789 |
if (!(m5 & 0x18)) goto clear_it; |
|
1091
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
790 |
new_data = (GetTileSlope(c, NULL) == 0) ? 0x6000 : 0x6001; |
0 | 791 |
} |
792 |
||
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
793 |
SetTileType(c, new_data >> 12); |
0 | 794 |
_map5[c] = (byte)new_data; |
795 |
_map2[c] = 0; |
|
796 |
||
797 |
MarkTileDirtyByTile(c); |
|
798 |
||
799 |
} else { |
|
800 |
clear_it:; |
|
801 |
DoClearSquare(c); |
|
802 |
} |
|
803 |
c += direction ? TILE_XY(0,1) : TILE_XY(1,0); |
|
804 |
} while (c <= endtile); |
|
805 |
||
806 |
SetSignalsOnBothDir(tile, direction); |
|
807 |
SetSignalsOnBothDir(endtile, direction); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
808 |
|
0 | 809 |
} |
810 |
||
811 |
return ((((endtile - tile) >> (direction?8:0))&0xFF)+1) * _price.clear_bridge; |
|
812 |
} |
|
813 |
||
814 |
static int32 ClearTile_TunnelBridge(uint tile, byte flags) { |
|
815 |
byte m5 = _map5[tile]; |
|
816 |
||
817 |
if ((m5 & 0xF0) == 0) { |
|
818 |
if (flags & DC_AUTO) |
|
819 |
return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_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
|
820 |
|
0 | 821 |
return DoClearTunnel(tile, flags); |
822 |
} else if (m5 & 0x80) { |
|
823 |
if (flags & DC_AUTO) |
|
824 |
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
|
825 |
||
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
|
826 |
return DoClearBridge(tile, flags); |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
827 |
} |
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
828 |
|
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
|
829 |
return CMD_ERROR; |
0 | 830 |
} |
831 |
||
832 |
int32 DoConvertTunnelBridgeRail(uint tile, uint totype, bool exec) |
|
833 |
{ |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
834 |
TileIndex endtile; |
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
835 |
uint length; |
0 | 836 |
Vehicle *v; |
837 |
||
838 |
if ((_map5[tile] & 0xFC) == 0x00) { |
|
839 |
// railway tunnel |
|
840 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
841 |
||
842 |
if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
843 |
|
0 | 844 |
endtile = CheckTunnelBusy(tile, &length); |
1430
68847f67a412
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
845 |
if (endtile == INVALID_TILE) return CMD_ERROR; |
0 | 846 |
|
847 |
if (exec) { |
|
848 |
_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype; |
|
849 |
_map3_lo[endtile] = (_map3_lo[endtile] & 0xF0) + totype; |
|
850 |
MarkTileDirtyByTile(tile); |
|
851 |
MarkTileDirtyByTile(endtile); |
|
852 |
} |
|
853 |
return (length + 1) * (_price.build_rail >> 1); |
|
854 |
} else if ((_map5[tile] & 0xF8) == 0xE0) { |
|
855 |
// bridge middle part with rail below |
|
856 |
// only check for train under bridge |
|
1041
be151b7bc909
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
857 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 858 |
return CMD_ERROR; |
859 |
||
860 |
// tile is already of requested type? |
|
861 |
if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR; |
|
862 |
// change type. |
|
863 |
if (exec) { |
|
864 |
_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype; |
|
865 |
MarkTileDirtyByTile(tile); |
|
866 |
} |
|
867 |
return _price.build_rail >> 1; |
|
868 |
} else if ((_map5[tile]&0xC6) == 0x80) { |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
869 |
TileIndex starttile; |
0 | 870 |
int32 cost; |
1073
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
871 |
uint z = TilePixelHeight(tile); |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
872 |
|
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
873 |
z += 8; |
0 | 874 |
|
875 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
876 |
||
877 |
// railway bridge |
|
878 |
starttile = tile = FindEdgesOfBridge(tile, &endtile); |
|
879 |
// Make sure there's no vehicle on the bridge |
|
1073
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
880 |
if ((v=FindVehicleBetween(tile, endtile, z)) != NULL) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
881 |
VehicleInTheWayErrMsg(v); |
0 | 882 |
return CMD_ERROR; |
883 |
} |
|
884 |
||
1073
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
885 |
if (!EnsureNoVehicle(starttile) || !EnsureNoVehicle(endtile)) { |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
886 |
_error_message = STR_8803_TRAIN_IN_THE_WAY; |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
887 |
return CMD_ERROR; |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
888 |
} |
0e844583b549
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
889 |
|
0 | 890 |
if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR; |
891 |
cost = 0; |
|
892 |
do { |
|
893 |
if (exec) { |
|
894 |
if (tile == starttile || tile == endtile) { |
|
895 |
_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype; |
|
896 |
} else { |
|
897 |
_map3_lo[tile] = (_map3_lo[tile] & 0x0F) + (totype << 4); |
|
898 |
} |
|
899 |
MarkTileDirtyByTile(tile); |
|
900 |
} |
|
901 |
cost += (_price.build_rail>>1); |
|
902 |
tile += _map5[tile]&1 ? TILE_XY(0,1) : TILE_XY(1,0); |
|
903 |
} while (tile <= endtile); |
|
904 |
||
905 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
906 |
} else |
0 | 907 |
return CMD_ERROR; |
908 |
} |
|
909 |
||
910 |
||
911 |
// fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile. |
|
1095 | 912 |
static uint GetBridgeHeight(const TileInfo *ti) |
0 | 913 |
{ |
914 |
uint delta; |
|
1192
cd9b8a18a183
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
915 |
TileIndex tile = ti->tile; |
0 | 916 |
|
917 |
// find the end tile of the bridge. |
|
918 |
delta = (_map5[tile] & 1) ? TILE_XY(0,1) : TILE_XY(1,0); |
|
919 |
do { |
|
920 |
assert((_map5[tile] & 0xC0) == 0xC0); // bridge and middle part |
|
921 |
tile += delta; |
|
922 |
} while (_map5[tile] & 0x40); // while bridge middle parts |
|
923 |
||
1192
cd9b8a18a183
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
924 |
/* Return the height there (the height of the NORTH CORNER) |
cd9b8a18a183
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
925 |
* If the end of the bridge is on a tileh 7 (all raised, except north corner), |
cd9b8a18a183
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
926 |
* the z coordinate is 1 height level too low. Compensate for that */ |
cd9b8a18a183
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents:
1109
diff
changeset
|
927 |
return TilePixelHeight(tile) + (GetTileSlope(tile, NULL) == 7 ? 8 : 0); |
0 | 928 |
} |
929 |
||
930 |
static const byte _bridge_foundations[2][16] = { |
|
931 |
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
932 |
{1,16,18,3,20,5,0,7,22,0,10,11,12,13,14}, |
|
933 |
{1,15,17,0,19,5,6,7,21,9,10,11, 0,13,14}, |
|
934 |
}; |
|
935 |
||
936 |
extern const byte _road_sloped_sprites[14]; |
|
937 |
||
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1430
diff
changeset
|
938 |
#include "table/track_land.h" |
511
b86b13d2288b
(svn r826) Seperate all bridge related tables from tunnel_land.h into their own file
tron
parents:
507
diff
changeset
|
939 |
#include "table/bridge_land.h" |
0 | 940 |
#include "table/tunnel_land.h" |
1091
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
941 |
#include "table/water_land.h" |
0 | 942 |
|
943 |
static void DrawBridgePillars(TileInfo *ti, int x, int y, int z) |
|
944 |
{ |
|
945 |
const uint32 *b; |
|
946 |
uint32 image; |
|
947 |
int piece; |
|
948 |
||
949 |
b = _bridge_poles_table[_map2[ti->tile]>>4]; |
|
950 |
||
951 |
// Draw first piece |
|
952 |
// (necessary for cantilever bridges) |
|
953 |
image = b[12 + (ti->map5&0x01)]; |
|
954 |
piece = _map2[ti->tile]&0xF; |
|
333
6dee54ed9701
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
955 |
if (image != 0 && piece != 0) { |
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
956 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
333
6dee54ed9701
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
957 |
DrawGroundSpriteAt(image, x, y, z); |
6dee54ed9701
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
958 |
} |
0 | 959 |
|
960 |
image = b[(ti->map5&0x01)*6 + piece]; |
|
961 |
||
962 |
if (image != 0) { |
|
963 |
int back_height, front_height, i=z; |
|
964 |
const byte *p; |
|
965 |
||
966 |
static const byte _tileh_bits[4][8] = { |
|
967 |
{2,1,8,4, 16,11,0,9}, |
|
968 |
{1,8,4,2, 11,16,9,0}, |
|
969 |
{4,8,1,2, 16,11,0,9}, |
|
970 |
{2,4,8,1, 11,16,9,0}, |
|
971 |
}; |
|
972 |
||
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
973 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
333
6dee54ed9701
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
974 |
|
0 | 975 |
p = _tileh_bits[(image & 1) * 2 + (ti->map5&0x01)]; |
976 |
front_height = ti->z + ((ti->tileh & p[0])?8:0); |
|
977 |
back_height = ti->z + ((ti->tileh & p[1])?8:0); |
|
978 |
if (ti->tileh & 0x10) { |
|
979 |
if (!(ti->tileh & p[2])) front_height += 8; |
|
980 |
if (!(ti->tileh & p[3])) back_height += 8; |
|
981 |
} |
|
982 |
||
983 |
for(; z>=front_height || z>=back_height; z=z-8) { |
|
984 |
if (z>=front_height) AddSortableSpriteToDraw(image, x,y, p[4], p[5], 0x28, z); // front facing pillar |
|
985 |
if (z>=back_height && z<i-8) AddSortableSpriteToDraw(image, x - p[6], y - p[7], p[4], p[5], 0x28, z); // back facing pillar |
|
986 |
} |
|
987 |
} |
|
988 |
} |
|
989 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
39
diff
changeset
|
990 |
uint GetBridgeFoundation(uint tileh, byte direction) { |
0 | 991 |
int i; |
992 |
// normal level sloped building (7, 11, 13, 14) |
|
993 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) |
|
994 |
return tileh; |
|
995 |
||
996 |
// inclined sloped building |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
997 |
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && |
0 | 998 |
( direction == 0 || (i++, direction == 1)) ) |
999 |
return i + 15; |
|
1000 |
||
1001 |
return 0; |
|
1002 |
} |
|
1003 |
||
1004 |
static void DrawTile_TunnelBridge(TileInfo *ti) |
|
1005 |
{ |
|
1006 |
uint32 image; |
|
1007 |
uint tmp; |
|
1008 |
const uint32 *b; |
|
1009 |
bool ice = _map3_hi[ti->tile] & 0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1010 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1011 |
// draw tunnel? |
0 | 1012 |
if ( (byte)(ti->map5&0xF0) == 0) { |
1013 |
/* railway type */ |
|
1014 |
image = (_map3_lo[ti->tile] & 0xF) * 8; |
|
1015 |
||
1016 |
/* ice? */ |
|
1017 |
if (ice) |
|
1018 |
image += 32; |
|
1019 |
||
1020 |
image += _draw_tunnel_table_1[(ti->map5 >> 2) & 0x3]; |
|
1021 |
image += (ti->map5 & 3) << 1; |
|
1022 |
DrawGroundSprite(image); |
|
1023 |
||
1024 |
AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z); |
|
1025 |
// draw bridge? |
|
1026 |
} else if ((byte)ti->map5 & 0x80) { |
|
1027 |
// get type of track on the bridge. |
|
1028 |
tmp = _map3_lo[ti->tile]; |
|
1029 |
if (ti->map5 & 0x40) tmp >>= 4; |
|
1030 |
tmp &= 0xF; |
|
1031 |
||
1032 |
// 0 = rail bridge |
|
1033 |
// 1 = road bridge |
|
1034 |
// 2 = monorail bridge |
|
1035 |
// 3 = maglev bridge |
|
1036 |
||
1037 |
// add direction and fix stuff. |
|
1038 |
if (tmp != 0) tmp++; |
|
1039 |
tmp = (ti->map5&3) + (tmp*2); |
|
1040 |
||
1041 |
if (!(ti->map5 & 0x40)) { // bridge ramps |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1042 |
|
0 | 1043 |
if (!(BRIDGE_NO_FOUNDATION & (1 << ti->tileh))) { // no foundations for 0, 3, 6, 9, 12 |
1044 |
int f = GetBridgeFoundation(ti->tileh, ti->map5 & 0x1); // pass direction |
|
1045 |
if (f) DrawFoundation(ti, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1046 |
|
0 | 1047 |
// default sloped sprites.. |
1048 |
if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3; |
|
1049 |
} |
|
1050 |
||
1051 |
// bridge ending. |
|
1562
a5507e041d97
(svn r2066) - Fix: [ 1164248 ] game crash while AI builds bridge. Also protect bridge building against invalid bridges and some safeguards when drawing.
Darkvater
parents:
1542
diff
changeset
|
1052 |
b = _bridge_sprite_table[(_map2[ti->tile] >> 4) & 0xF][6]; |
0 | 1053 |
b += (tmp&(3<<1))*4; /* actually ((tmp>>2)&3)*8 */ |
1054 |
b += (tmp&1); // direction |
|
1055 |
if (ti->tileh == 0) b += 4; // sloped "entrance" ? |
|
1056 |
if (ti->map5 & 0x20) b += 2; // which side |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1057 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1058 |
image = *b; |
0 | 1059 |
|
1060 |
if (!ice) { |
|
1061 |
DrawClearLandTile(ti, 3); |
|
1062 |
} else { |
|
1063 |
DrawGroundSprite(0x11C6 + _tileh_to_sprite[ti->tileh]); |
|
1064 |
} |
|
1065 |
||
1066 |
// draw ramp |
|
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
1067 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
0 | 1068 |
AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z); |
1069 |
} else { |
|
1070 |
// bridge middle part. |
|
1071 |
uint z; |
|
1072 |
int x,y; |
|
1073 |
||
1074 |
image = (ti->map5 >> 3) & 3; // type of stuff under bridge (only defined for 0,1) |
|
1075 |
assert(image <= 1); |
|
1076 |
||
1077 |
if (!(ti->map5 & 0x20)) { |
|
1078 |
// draw land under bridge |
|
1079 |
if (ice) image += 2; // ice too? |
|
1091
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1080 |
|
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1081 |
if (image != 1 || ti->tileh == 0) |
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1082 |
DrawGroundSprite(_bridge_land_below[image] + _tileh_to_sprite[ti->tileh]); |
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1083 |
else |
be3ba61df059
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1084 |
DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
0 | 1085 |
|
1086 |
// draw canal water? |
|
1087 |
if (ti->map5 & 8 && ti->z != 0) DrawCanalWater(ti->tile); |
|
1088 |
} else { |
|
1089 |
// draw transport route under bridge |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1090 |
|
0 | 1091 |
// draw foundation? |
1092 |
if (ti->tileh) { |
|
1093 |
int f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1094 |
if (f) DrawFoundation(ti, f); |
|
1095 |
} |
|
1096 |
||
1097 |
if (!(image&1)) { |
|
1098 |
// railway |
|
1099 |
image = 0x3F3 + (ti->map5 & 1); |
|
1100 |
if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3; |
|
1101 |
image += (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH; |
|
1102 |
if (ice) image += 26; // ice? |
|
1103 |
} else { |
|
1104 |
// road |
|
1105 |
image = 1332 + (ti->map5 & 1); |
|
1106 |
if (ti->tileh != 0) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
|
1107 |
if (ice) image += 19; // ice? |
|
1108 |
} |
|
1109 |
DrawGroundSprite(image); |
|
1110 |
} |
|
1111 |
// get bridge sprites |
|
1562
a5507e041d97
(svn r2066) - Fix: [ 1164248 ] game crash while AI builds bridge. Also protect bridge building against invalid bridges and some safeguards when drawing.
Darkvater
parents:
1542
diff
changeset
|
1112 |
b = _bridge_sprite_table[(_map2[ti->tile] >> 4) & 0xF][_map2[ti->tile]&0xF] + tmp * 4; |
0 | 1113 |
|
1114 |
z = GetBridgeHeight(ti) + 5; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1115 |
|
0 | 1116 |
// draw rail |
1117 |
image = b[0]; |
|
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
1118 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
0 | 1119 |
AddSortableSpriteToDraw(image, ti->x, ti->y, (ti->map5&1)?11:16, (ti->map5&1)?16:11, 1, z); |
1120 |
||
1121 |
x = ti->x; |
|
1122 |
y = ti->y; |
|
1123 |
image = b[1]; |
|
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
1124 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
0 | 1125 |
|
1126 |
// draw roof |
|
1127 |
if (ti->map5&1) { |
|
1128 |
x += 12; |
|
1129 |
if (image&0x3FFF) AddSortableSpriteToDraw(image, x,y, 1, 16, 0x28, z); |
|
1130 |
} else { |
|
1131 |
y += 12; |
|
1132 |
if (image&0x3FFF) AddSortableSpriteToDraw(image, x,y, 16, 1, 0x28, z); |
|
1133 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1134 |
|
0 | 1135 |
if (ti->z + 5 == z ) { |
1136 |
// draw poles below for small bridges |
|
1137 |
image = b[2]; |
|
1138 |
if (image) { |
|
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
1139 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
0 | 1140 |
DrawGroundSpriteAt(image, x, y, z); |
1141 |
} |
|
1142 |
} else if (_patches.bridge_pillars) { |
|
1143 |
// draw pillars below for high bridges |
|
1144 |
DrawBridgePillars(ti, x, y, z); |
|
1145 |
} |
|
1146 |
} |
|
1147 |
} |
|
1148 |
} |
|
1149 |
||
1150 |
static uint GetSlopeZ_TunnelBridge(TileInfo *ti) { |
|
1151 |
uint z = ti->z; |
|
1152 |
uint x = ti->x & 0xF; |
|
1153 |
uint y = ti->y & 0xF; |
|
1154 |
||
1155 |
// swap directions if Y tunnel/bridge to let the code handle the X case only. |
|
1884
ae1d6213c6dd
(svn r2390) - Codechange: Fix some warnings on GCC 4.0.0
hackykid
parents:
1784
diff
changeset
|
1156 |
if (ti->map5 & 1) uintswap(x,y); |
0 | 1157 |
|
1158 |
// to the side of the tunnel/bridge? |
|
1159 |
if (IS_INT_INSIDE(y, 5, 10+1)) { |
|
1160 |
// tunnel? |
|
1161 |
if ( (ti->map5 & 0xF0) == 0) |
|
1162 |
return z; |
|
1163 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1164 |
// bridge? |
0 | 1165 |
if ( ti->map5 & 0x80 ) { |
1166 |
// bridge ending? |
|
1167 |
if (!(ti->map5 & 0x40)) { |
|
1168 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti->tileh)) // 7, 11, 13, 14 |
|
1169 |
z += 8; |
|
1170 |
||
1171 |
// no ramp for bridge ending |
|
1172 |
if ((BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << ti->tileh) || BRIDGE_NO_FOUNDATION & (1 << ti->tileh)) && ti->tileh != 0) { |
|
1173 |
return z + 8; |
|
1174 |
||
1175 |
} else if (!(ti->map5 & 0x20)) { // northern / southern ending |
|
1176 |
// ramp |
|
1177 |
return (z + (x>>1) + 1); |
|
1178 |
} else { |
|
1179 |
// ramp in opposite dir |
|
1180 |
return (z + ((x^0xF)>>1)); |
|
1181 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1182 |
|
0 | 1183 |
// bridge middle part |
1184 |
} else { |
|
1185 |
// build on slopes? |
|
1186 |
if (ti->tileh) z+=8; |
|
1187 |
||
1188 |
// keep the same elevation because we're on the bridge? |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1189 |
if (_get_z_hint >= z + 8) |
0 | 1190 |
return _get_z_hint; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1191 |
|
0 | 1192 |
// actually on the bridge, but not yet in the shared area. |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1193 |
if (!IS_INT_INSIDE(x, 5, 10+1)) |
0 | 1194 |
return GetBridgeHeight(ti) + 8; |
1195 |
||
1196 |
// in the shared area, assume that we're below the bridge, cause otherwise the hint would've caught it. |
|
1197 |
// if rail or road below then it means it's possibly build on slope below the bridge. |
|
1198 |
if (ti->map5 & 0x20) { |
|
1199 |
uint f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1200 |
// make sure that the slope is not inclined foundation |
|
1201 |
if (IS_BYTE_INSIDE(f, 1, 15)) return z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1202 |
|
0 | 1203 |
// change foundation type? |
1204 |
if (f) ti->tileh = _inclined_tileh[f - 15]; |
|
1205 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1206 |
|
0 | 1207 |
// no transport route, fallback to default |
1208 |
} |
|
1209 |
} |
|
1210 |
} else { |
|
1211 |
// if it's a bridge middle with transport route below, then we need to compensate for build on slopes |
|
1212 |
if ( (ti->map5 & (0x80 + 0x40 + 0x20)) == (0x80 + 0x40 + 0x20)) { |
|
1213 |
uint f; |
|
1214 |
if (ti->tileh) z += 8; |
|
1215 |
f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1216 |
if (IS_BYTE_INSIDE(f, 1, 15)) return z; |
|
1217 |
if (f) ti->tileh = _inclined_tileh[f - 15]; |
|
1218 |
} |
|
1219 |
} |
|
1220 |
||
1221 |
// default case |
|
1222 |
z = ti->z; |
|
1223 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + z; |
|
1224 |
} |
|
1225 |
||
39 | 1226 |
static uint GetSlopeTileh_TunnelBridge(TileInfo *ti) { |
1227 |
// not accurate, but good enough for slope graphics drawing |
|
1228 |
return 0; |
|
1229 |
} |
|
1230 |
||
1231 |
||
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
337
diff
changeset
|
1232 |
static void GetAcceptedCargo_TunnelBridge(uint tile, AcceptedCargo ac) |
0 | 1233 |
{ |
1234 |
/* not used */ |
|
1235 |
} |
|
1236 |
||
1237 |
static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = { |
|
1238 |
STR_501F_WOODEN_RAIL_BRIDGE, |
|
1239 |
STR_5020_CONCRETE_RAIL_BRIDGE, |
|
1240 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1241 |
STR_501E_REINFORCED_CONCRETE_SUSPENSION, |
|
1242 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1243 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1244 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1245 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1246 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1247 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1248 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1249 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1250 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1251 |
0,0,0, |
|
1252 |
||
1253 |
STR_5025_WOODEN_ROAD_BRIDGE, |
|
1254 |
STR_5026_CONCRETE_ROAD_BRIDGE, |
|
1255 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1256 |
STR_5024_REINFORCED_CONCRETE_SUSPENSION, |
|
1257 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1258 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1259 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1260 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1261 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1262 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1263 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1264 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1265 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1266 |
0,0,0, |
|
1267 |
}; |
|
1268 |
||
1269 |
static void GetTileDesc_TunnelBridge(uint tile, TileDesc *td) |
|
1270 |
{ |
|
1271 |
int delta; |
|
1272 |
||
1273 |
if ((_map5[tile] & 0x80) == 0) { |
|
1274 |
td->str = STR_5017_RAILROAD_TUNNEL + ((_map5[tile] >> 2) & 3); |
|
1275 |
} else { |
|
1276 |
td->str = _bridge_tile_str[ (_map2[tile] >> 4) + (((_map5[tile]>>1)&3)<<4) ]; |
|
1277 |
||
1278 |
/* scan to the end of the bridge, that's where the owner is stored */ |
|
1279 |
if (_map5[tile] & 0x40) { |
|
1280 |
delta = _map5[tile] & 1 ? TILE_XY(0,-1) : TILE_XY(-1,0); |
|
1281 |
do tile += delta; while (_map5[tile] & 0x40); |
|
1282 |
} |
|
1283 |
} |
|
1284 |
td->owner = _map_owner[tile]; |
|
1285 |
} |
|
1286 |
||
1287 |
||
1288 |
static void AnimateTile_TunnelBridge(uint tile) |
|
1289 |
{ |
|
1290 |
/* not used */ |
|
1291 |
} |
|
1292 |
||
1293 |
static void TileLoop_TunnelBridge(uint tile) |
|
1294 |
{ |
|
1295 |
if (_opt.landscape == LT_HILLY) { |
|
1296 |
if ( GetTileZ(tile) > _opt.snow_line) { |
|
1297 |
if (!(_map3_hi[tile] & 0x80)) { |
|
1298 |
_map3_hi[tile] |= 0x80; |
|
1299 |
MarkTileDirtyByTile(tile); |
|
1300 |
} |
|
1301 |
} else { |
|
1302 |
if (_map3_hi[tile] & 0x80) { |
|
1303 |
_map3_hi[tile] &= ~0x80; |
|
1304 |
MarkTileDirtyByTile(tile); |
|
1305 |
} |
|
1306 |
} |
|
1307 |
} else if (_opt.landscape == LT_DESERT) { |
|
1308 |
if (GetMapExtraBits(tile) == 1 && !(_map3_hi[tile]&0x80)) { |
|
1309 |
_map3_hi[tile] |= 0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1310 |
MarkTileDirtyByTile(tile); |
0 | 1311 |
} |
1312 |
} |
|
1313 |
||
1314 |
// if it's a bridge with water below, call tileloop_water on it. |
|
1315 |
if ((_map5[tile] & 0xF8) == 0xC8) TileLoop_Water(tile); |
|
1316 |
} |
|
1317 |
||
1318 |
static void ClickTile_TunnelBridge(uint tile) |
|
1319 |
{ |
|
1320 |
/* not used */ |
|
1321 |
} |
|
1322 |
||
1323 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1324 |
static uint32 GetTileTrackStatus_TunnelBridge(uint tile, TransportType mode) |
0 | 1325 |
{ |
1326 |
uint32 result; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1327 |
byte m5 = _map5[tile]; |
0 | 1328 |
|
1329 |
if ((m5 & 0xF0) == 0) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1330 |
/* This is a tunnel */ |
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1331 |
if (((m5 & 0xCU) >> 2) == mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1332 |
/* Tranport in the tunnel is compatible */ |
0 | 1333 |
return m5&1 ? 0x202 : 0x101; |
1334 |
} |
|
1335 |
} else if (m5 & 0x80) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1336 |
/* This is a bridge */ |
0 | 1337 |
result = 0; |
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1338 |
if (((m5 & 0x6U) >> 1) == mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1339 |
/* Transport over the bridge is compatible */ |
0 | 1340 |
result = m5&1 ? 0x202 : 0x101; |
1341 |
} |
|
1342 |
if (m5 & 0x40) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1343 |
/* Bridge middle part */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1344 |
if (!(m5 & 0x20)) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1345 |
/* Clear ground or water underneath */ |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
203
diff
changeset
|
1346 |
if ((m5 & 0x18) != 8) |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1347 |
/* Clear ground */ |
0 | 1348 |
return result; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1349 |
else |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1350 |
if (mode != TRANSPORT_WATER) |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1351 |
return result; |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1352 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1353 |
/* Transport underneath */ |
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1354 |
if ((m5 & 0x18U) >> 3 != mode) |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1355 |
/* Incompatible transport underneath */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1356 |
return result; |
0 | 1357 |
} |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1358 |
/* If we've not returned yet, there is a compatible |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1359 |
* transport or water beneath, so we can add it to |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1360 |
* result */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1361 |
/* Why is this xor'd ? Can't it just be or'd? */ |
0 | 1362 |
result ^= m5&1 ? 0x101 : 0x202; |
1363 |
} |
|
1364 |
return result; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1365 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1366 |
assert(0); /* This should never occur */ |
0 | 1367 |
} |
1368 |
return 0; |
|
1369 |
} |
|
1370 |
||
1371 |
static void ChangeTileOwner_TunnelBridge(uint tile, byte old_player, byte new_player) |
|
1372 |
{ |
|
1373 |
if (_map_owner[tile] != old_player) |
|
1374 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1375 |
|
0 | 1376 |
if (new_player != 255) { |
1377 |
_map_owner[tile] = new_player; |
|
1378 |
} else { |
|
1379 |
if((_map5[tile] & 0xC0)==0xC0) { |
|
1380 |
// the stuff BELOW the middle part is owned by the deleted player. |
|
1381 |
if (!(_map5[tile] & (1 << 4 | 1 << 3))) { |
|
1382 |
// convert railway into grass. |
|
1383 |
_map5[tile] &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore.. |
|
1384 |
} else { |
|
1385 |
// for road, change the owner of the road to local authority |
|
1386 |
_map_owner[tile] = OWNER_NONE; |
|
1387 |
} |
|
1388 |
} else { |
|
1389 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1390 |
} |
|
1391 |
} |
|
1392 |
} |
|
1393 |
||
1394 |
||
1395 |
static const byte _tunnel_fractcoord_1[4] = {0x8E,0x18,0x81,0xE8}; |
|
1396 |
static const byte _tunnel_fractcoord_2[4] = {0x81,0x98,0x87,0x38}; |
|
1397 |
static const byte _tunnel_fractcoord_3[4] = {0x82,0x88,0x86,0x48}; |
|
1398 |
static const byte _exit_tunnel_track[4] = {1,2,1,2}; |
|
1399 |
||
1400 |
static const byte _road_exit_tunnel_state[4] = {8, 9, 0, 1}; |
|
1401 |
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4}; |
|
1402 |
||
1403 |
static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29}; |
|
1404 |
static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25}; |
|
1405 |
static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45}; |
|
1406 |
static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49}; |
|
1407 |
||
1408 |
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, uint tile, int x, int y) |
|
1409 |
{ |
|
1410 |
int z; |
|
1411 |
int dir, vdir; |
|
1412 |
byte fc; |
|
1413 |
||
1414 |
if ((_map5[tile] & 0xF0) == 0) { |
|
1415 |
z = GetSlopeZ(x, y) - v->z_pos; |
|
1416 |
if (myabs(z) > 2) |
|
1417 |
return 8; |
|
1418 |
||
1419 |
if (v->type == VEH_Train) { |
|
1420 |
fc = (x&0xF)+(y<<4); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1421 |
|
0 | 1422 |
dir = _map5[tile] & 3; |
1423 |
vdir = v->direction >> 1; |
|
1424 |
||
1425 |
if (v->u.rail.track != 0x40 && dir == vdir) { |
|
1067
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1059
diff
changeset
|
1426 |
if (v->subtype == TS_Front_Engine && fc == _tunnel_fractcoord_1[dir]) { |
0 | 1427 |
if (v->spritenum < 4) |
541 | 1428 |
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); |
0 | 1429 |
return 0; |
1430 |
} |
|
1431 |
if (fc == _tunnel_fractcoord_2[dir]) { |
|
1432 |
v->tile = tile; |
|
1433 |
v->u.rail.track = 0x40; |
|
1434 |
v->vehstatus |= VS_HIDDEN; |
|
1435 |
return 4; |
|
1436 |
} |
|
1437 |
} |
|
1438 |
||
1439 |
if (dir == (vdir^2) && fc == _tunnel_fractcoord_3[dir] && z == 0) { |
|
22 | 1440 |
/* We're at the tunnel exit ?? */ |
0 | 1441 |
v->tile = tile; |
1442 |
v->u.rail.track = _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
|
1443 |
assert(v->u.rail.track); |
0 | 1444 |
v->vehstatus &= ~VS_HIDDEN; |
1445 |
return 4; |
|
1446 |
} |
|
1447 |
} else if (v->type == VEH_Road) { |
|
1448 |
fc = (x&0xF)+(y<<4); |
|
1449 |
dir = _map5[tile] & 3; |
|
1450 |
vdir = v->direction >> 1; |
|
1451 |
||
1452 |
// Enter tunnel? |
|
1453 |
if (v->u.road.state != 0xFF && dir == vdir) { |
|
1454 |
if (fc == _tunnel_fractcoord_4[dir] || |
|
1455 |
fc == _tunnel_fractcoord_5[dir]) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1456 |
|
0 | 1457 |
v->tile = tile; |
1458 |
v->u.road.state = 0xFF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1459 |
v->vehstatus |= VS_HIDDEN; |
0 | 1460 |
return 4; |
1461 |
} else { |
|
1462 |
return 0; |
|
1463 |
} |
|
1464 |
} |
|
1465 |
||
1466 |
if (dir == (vdir^2) && ( |
|
22 | 1467 |
/* We're at the tunnel exit ?? */ |
0 | 1468 |
fc == _tunnel_fractcoord_6[dir] || |
1469 |
fc == _tunnel_fractcoord_7[dir]) && |
|
1470 |
z == 0) { |
|
1471 |
v->tile = tile; |
|
1472 |
v->u.road.state = _road_exit_tunnel_state[dir]; |
|
1473 |
v->u.road.frame = _road_exit_tunnel_frame[dir]; |
|
1474 |
v->vehstatus &= ~VS_HIDDEN; |
|
1475 |
return 4; |
|
1476 |
} |
|
1477 |
} |
|
1478 |
} else if (_map5[tile] & 0x80) { |
|
1067
a083a6dd1419
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1059
diff
changeset
|
1479 |
if (v->type == VEH_Road || (v->type == VEH_Train && v->subtype == TS_Front_Engine)) { |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1480 |
uint h; |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1481 |
|
334
8fb78c8c10e5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1482 |
if (GetTileSlope(tile, &h) != 0) |
8fb78c8c10e5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1483 |
h += 8; // Compensate for possible foundation |
8fb78c8c10e5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1484 |
if (!(_map5[tile] & 0x40) || // start/end tile of bridge |
8fb78c8c10e5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1485 |
myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge |
0 | 1486 |
/* modify speed of vehicle */ |
1487 |
uint16 spd = _bridge_speeds[_map2[tile] >> 4]; |
|
1488 |
if (v->type == VEH_Road) spd<<=1; |
|
1489 |
if (spd < v->cur_speed) |
|
1490 |
v->cur_speed = spd; |
|
1491 |
} |
|
1492 |
} |
|
1493 |
} |
|
1494 |
return 0; |
|
1495 |
} |
|
1496 |
||
1587
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1497 |
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v) |
0 | 1498 |
{ |
1587
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1499 |
TileIndex tile; |
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1500 |
TileIndexDiff delta = (v->direction & 2) ? TILE_XY(0, 1) : TILE_XY(1, 0); |
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1501 |
byte z = v->z_pos; |
0 | 1502 |
|
1587
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1503 |
for (tile = v->tile;; tile += delta) { |
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1504 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0) == 0 && |
e6bcc5a3cb86
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1505 |
GetTileZ(tile) == z) |
0 | 1506 |
break; |
1507 |
} |
|
1508 |
return tile; |
|
1509 |
} |
|
1510 |
||
1511 |
const TileTypeProcs _tile_type_tunnelbridge_procs = { |
|
1512 |
DrawTile_TunnelBridge, /* draw_tile_proc */ |
|
1513 |
GetSlopeZ_TunnelBridge, /* get_slope_z_proc */ |
|
1514 |
ClearTile_TunnelBridge, /* clear_tile_proc */ |
|
1515 |
GetAcceptedCargo_TunnelBridge, /* get_accepted_cargo_proc */ |
|
1516 |
GetTileDesc_TunnelBridge, /* get_tile_desc_proc */ |
|
1517 |
GetTileTrackStatus_TunnelBridge,/* get_tile_track_status_proc */ |
|
1518 |
ClickTile_TunnelBridge, /* click_tile_proc */ |
|
1519 |
AnimateTile_TunnelBridge, /* animate_tile_proc */ |
|
1520 |
TileLoop_TunnelBridge, /* tile_loop_clear */ |
|
1521 |
ChangeTileOwner_TunnelBridge, /* change_tile_owner_clear */ |
|
1522 |
NULL, /* get_produced_cargo_proc */ |
|
1523 |
VehicleEnter_TunnelBridge, /* vehicle_enter_tile_proc */ |
|
1524 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1525 |
GetSlopeTileh_TunnelBridge, /* get_slope_tileh_proc */ |
0 | 1526 |
}; |