author | tron |
Sat, 25 Jun 2005 16:44:57 +0000 | |
changeset 1981 | 3c9c682f1212 |
parent 1977 | 37bbebf94434 |
child 2008 | cdb444f6d43c |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1884
diff
changeset
|
2 |
#include "openttd.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1335
diff
changeset
|
3 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
4 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
541
diff
changeset
|
5 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1192
diff
changeset
|
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
cbe0c766c947
(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 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
14 |
extern void DrawCanalWater(TileIndex tile); |
0 | 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
a6d140a6a4de
(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); |
a6d140a6a4de
(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); |
a6d140a6a4de
(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); |
a6d140a6a4de
(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
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
151 |
if (bridge_type >= MAX_BRIDGES) return false; |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
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
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
158 |
if (bridge_len < _bridge_minlen[bridge_type] || bridge_len > max) return false; |
0 | 159 |
|
160 |
return true; |
|
161 |
} |
|
162 |
||
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
163 |
/** Build a Bridge |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
164 |
* @param x,y end tile coord |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
165 |
* @param p1 packed start tile coords (~ dx) |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
166 |
* @param p2 various bitstuffed elements |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
167 |
* - p2 = (bit 0- 7) - bridge type (hi bh) |
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
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
9746fa4b40a7
(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
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
188 |
if (p1 > MapSize()) return CMD_ERROR; |
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
189 |
|
0 | 190 |
// type of bridge |
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
191 |
if (HASBIT(railtype, 7)) { // bit 15 of original p2 param |
0 | 192 |
railtype = 0; |
193 |
rail_or_road = 2; |
|
194 |
} else { |
|
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
195 |
if (!ValParamRailtype(railtype)) return CMD_ERROR; |
0 | 196 |
rail_or_road = 0; |
197 |
} |
|
198 |
||
926
a6d140a6a4de
(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; |
a6d140a6a4de
(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
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
221 |
/* set and test bridge length, availability */ |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
222 |
bridge_len = ((sx + sy - x - y) >> 4) - 1; |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
223 |
if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE); |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
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
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
248 |
|
9746fa4b40a7
(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. |
9746fa4b40a7
(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
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
251 |
&& _current_player != OWNER_TOWN && _patches.build_on_slopes); |
1585
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
252 |
|
9746fa4b40a7
(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 */ |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
254 |
|
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
255 |
if (CmdFailed(ret = DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) |
0 | 256 |
return CMD_ERROR; |
257 |
cost = ret; |
|
258 |
||
1585
9746fa4b40a7
(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 |
9746fa4b40a7
(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); |
9746fa4b40a7
(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
9746fa4b40a7
(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 */ |
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
266 |
|
1775
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
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
9746fa4b40a7
(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.
pasky
parents:
1562
diff
changeset
|
271 |
// false - end tile slope check |
9746fa4b40a7
(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); |
9746fa4b40a7
(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)) |
9746fa4b40a7
(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); |
9746fa4b40a7
(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
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
299 |
// position of middle part of the odd bridge (larger than MAX(i) otherwise) |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
300 |
odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len; |
0 | 301 |
|
1781
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
302 |
for (i = 0; i != bridge_len; i++) { |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
303 |
if (direction != 0) { |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
304 |
y += 16; |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
305 |
} else |
5e2fef482637
(svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents:
1775
diff
changeset
|
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
0f113f2ed794
(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
548dc04d50e2
(svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents:
1587
diff
changeset
|
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
fe97d81a1b4f
(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 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
403 |
static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir) |
0 | 404 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
405 |
TileIndexDiff delta = TileOffsByDir(dir); |
0 | 406 |
TileInfo ti; |
407 |
||
408 |
do { |
|
409 |
tile -= delta; |
|
410 |
FindLandscapeHeightByTile(&ti, tile); |
|
411 |
} while (z < ti.z); |
|
412 |
||
413 |
if (z == ti.z && ti.type == MP_TUNNELBRIDGE && (ti.map5&0xF0) == 0 && (ti.map5&3) == dir) { |
|
414 |
_error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY; |
|
415 |
return false; |
|
416 |
} |
|
417 |
||
418 |
return true; |
|
419 |
} |
|
420 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
421 |
bool CheckTunnelInWay(TileIndex tile, int z) |
0 | 422 |
{ |
423 |
return DoCheckTunnelInWay(tile,z,0) && |
|
424 |
DoCheckTunnelInWay(tile,z,1) && |
|
425 |
DoCheckTunnelInWay(tile,z,2) && |
|
426 |
DoCheckTunnelInWay(tile,z,3); |
|
427 |
} |
|
428 |
||
429 |
static byte _build_tunnel_bh; |
|
430 |
static byte _build_tunnel_railtype; |
|
431 |
||
432 |
static int32 DoBuildTunnel(int x, int y, int x2, int y2, uint32 flags, uint exc_tile) |
|
433 |
{ |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
434 |
TileIndex end_tile; |
0 | 435 |
int direction; |
436 |
int32 cost, ret; |
|
437 |
TileInfo ti; |
|
438 |
uint z; |
|
439 |
||
856
918759cedca8
(svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents:
679
diff
changeset
|
440 |
if ((uint)x > MapMaxX() * 16 - 1 || (uint)y > MapMaxY() * 16 - 1) |
0 | 441 |
return CMD_ERROR; |
442 |
||
443 |
/* check if valid, and make sure that (x,y) is smaller than (x2,y2) */ |
|
444 |
direction = 0; |
|
445 |
if (x == x2) { |
|
446 |
if (y == y2) |
|
447 |
return_cmd_error(STR_5008_CANNOT_START_AND_END_ON); |
|
448 |
direction++; |
|
449 |
if (y > y2) { |
|
450 |
intswap(y,y2); |
|
451 |
intswap(x,x2); |
|
452 |
exc_tile|=2; |
|
453 |
} |
|
454 |
} else if (y == y2) { |
|
455 |
if (x > x2) { |
|
456 |
intswap(y,y2); |
|
457 |
intswap(x,x2); |
|
458 |
exc_tile|=2; |
|
459 |
} |
|
460 |
} else |
|
461 |
return_cmd_error(STR_500A_START_AND_END_MUST_BE_IN); |
|
462 |
||
463 |
cost = 0; |
|
464 |
||
465 |
FindLandscapeHeight(&ti, x2, y2); |
|
466 |
end_tile = ti.tile; |
|
467 |
z = ti.z; |
|
468 |
||
469 |
if (exc_tile != 3) { |
|
470 |
if ( (direction ? 9U : 12U) != ti.tileh) |
|
471 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
472 |
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
473 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 474 |
cost += ret; |
475 |
} |
|
476 |
cost += _price.build_tunnel; |
|
477 |
||
478 |
for(;;) { |
|
479 |
if (direction) y2-=16; else x2-=16; |
|
480 |
||
481 |
if (x2 == x && y2 == y) |
|
482 |
break; |
|
483 |
||
484 |
FindLandscapeHeight(&ti, x2, y2); |
|
485 |
if (ti.z <= z) |
|
486 |
return_cmd_error(STR_5002); |
|
487 |
||
488 |
if (!_cheats.crossing_tunnels.value && !CheckTunnelInWay(ti.tile, z)) |
|
489 |
return CMD_ERROR; |
|
490 |
||
491 |
cost += _price.build_tunnel; |
|
492 |
cost += (cost >> 3); |
|
493 |
||
494 |
if (cost >= 400000000) |
|
495 |
cost = 400000000; |
|
496 |
} |
|
497 |
||
498 |
FindLandscapeHeight(&ti, x2, y2); |
|
499 |
if (ti.z != z) |
|
500 |
return_cmd_error(STR_5004); |
|
501 |
||
502 |
if (exc_tile != 1) { |
|
503 |
if ( (direction ? 6U : 3U) != ti.tileh) |
|
504 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
505 |
||
506 |
ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
507 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 508 |
cost += ret; |
509 |
} |
|
510 |
||
511 |
if (flags & DC_EXEC) { |
|
512 |
ModifyTile(ti.tile, |
|
513 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
514 |
MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
515 |
_build_tunnel_railtype, /* map3lo */ |
|
516 |
((_build_tunnel_bh << 1) | 2) - direction /* map5 */ |
|
517 |
); |
|
518 |
||
519 |
ModifyTile(end_tile, |
|
520 |
MP_SETTYPE(MP_TUNNELBRIDGE) | |
|
521 |
MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5, |
|
522 |
_build_tunnel_railtype, /* map3lo */ |
|
523 |
(_build_tunnel_bh << 1) | (direction ? 3:0)/* map5 */ |
|
524 |
); |
|
525 |
||
526 |
UpdateSignalsOnSegment(end_tile, direction?7:1); |
|
527 |
} |
|
528 |
||
529 |
return cost + _price.build_tunnel; |
|
530 |
} |
|
531 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
532 |
/** Build Tunnel. |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
533 |
* @param x,y start tile coord of tunnel |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
534 |
* @param p1 railtype, 0x200 for road tunnel |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
535 |
* @param p2 unused (XXX - ptr to uint that recieves end tile; wtf?????) |
0 | 536 |
*/ |
537 |
int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
538 |
{ |
|
539 |
TileInfo ti, tiorg; |
|
540 |
int direction; |
|
541 |
uint z; |
|
542 |
static const int8 _build_tunnel_coord_mod[4+1] = { -16, 0, 16, 0, -16 }; |
|
543 |
static const byte _build_tunnel_tileh[4] = {3, 9, 12, 6}; |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
544 |
TileIndex excavated_tile; |
0 | 545 |
|
546 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
547 |
||
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1782
diff
changeset
|
548 |
if (p1 != 0x200 && !ValParamRailtype(p1)) return CMD_ERROR; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
549 |
|
0 | 550 |
_build_tunnel_railtype = (byte)(p1 & 0xFF); |
551 |
_build_tunnel_bh = (byte)(p1 >> 8); |
|
552 |
||
553 |
_build_tunnel_endtile = 0; |
|
554 |
excavated_tile = 0; |
|
555 |
||
556 |
FindLandscapeHeight(&tiorg, x, y); |
|
557 |
||
558 |
if (!EnsureNoVehicle(tiorg.tile)) |
|
559 |
return CMD_ERROR; |
|
560 |
||
561 |
if (!(direction=0, tiorg.tileh==12) && |
|
562 |
!(direction++, tiorg.tileh==6) && |
|
563 |
!(direction++, tiorg.tileh==3) && |
|
564 |
!(direction++, tiorg.tileh==9) ) |
|
565 |
return_cmd_error(STR_500B_SITE_UNSUITABLE_FOR_TUNNEL); |
|
566 |
||
567 |
z = tiorg.z; |
|
568 |
do { |
|
569 |
x += _build_tunnel_coord_mod[direction]; |
|
570 |
y += _build_tunnel_coord_mod[direction+1]; |
|
571 |
FindLandscapeHeight(&ti, x, y); |
|
572 |
} while (z != ti.z); |
|
573 |
_build_tunnel_endtile = ti.tile; |
|
574 |
||
575 |
||
576 |
if (!EnsureNoVehicle(ti.tile)) |
|
577 |
return CMD_ERROR; |
|
578 |
||
579 |
if (ti.tileh != _build_tunnel_tileh[direction]) { |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
580 |
if (CmdFailed(DoCommandByTile(ti.tile, ti.tileh & ~_build_tunnel_tileh[direction], 0, flags, CMD_TERRAFORM_LAND))) |
0 | 581 |
return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND); |
582 |
excavated_tile = 1; |
|
583 |
} |
|
584 |
||
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
585 |
return DoBuildTunnel(x, y, tiorg.x, tiorg.y, flags, excavated_tile); |
0 | 586 |
} |
587 |
||
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
588 |
TileIndex CheckTunnelBusy(TileIndex tile, uint *length) |
0 | 589 |
{ |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
590 |
uint z = GetTileZ(tile); |
0 | 591 |
byte m5 = _map5[tile]; |
900 | 592 |
int delta = TileOffsByDir(m5 & 3); |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
593 |
uint len = 0; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
594 |
TileIndex starttile = tile; |
0 | 595 |
Vehicle *v; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
596 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
597 |
do { |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
598 |
tile += delta; |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
599 |
len++; |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
600 |
} while ( |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
601 |
!IsTileType(tile, MP_TUNNELBRIDGE) || |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
602 |
(_map5[tile] & 0xF0) != 0 || |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
603 |
(byte)(_map5[tile] ^ 2) != m5 || |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
604 |
GetTileZ(tile) != z |
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
605 |
); |
0 | 606 |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
607 |
v = FindVehicleBetween(starttile, tile, z); |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
608 |
if (v != NULL) { |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
609 |
_error_message = v->type == VEH_Train ? |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
610 |
STR_5000_TRAIN_IN_TUNNEL : STR_5001_ROAD_VEHICLE_IN_TUNNEL; |
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
611 |
return INVALID_TILE; |
0 | 612 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
613 |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
614 |
if (length != NULL) *length = len; |
0 | 615 |
return tile; |
616 |
} |
|
617 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
618 |
static int32 DoClearTunnel(TileIndex tile, uint32 flags) |
0 | 619 |
{ |
620 |
Town *t; |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
621 |
TileIndex endtile; |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
622 |
uint length; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
623 |
static const byte _updsignals_tunnel_dir[4] = { 5, 7, 1, 3}; |
0 | 624 |
|
625 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
626 |
||
627 |
// in scenario editor you can always destroy tunnels |
|
628 |
if (_game_mode != GM_EDITOR && !CheckTileOwnership(tile)) { |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
629 |
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN)) |
0 | 630 |
return CMD_ERROR; |
631 |
} |
|
632 |
||
633 |
endtile = CheckTunnelBusy(tile, &length); |
|
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
634 |
if (endtile == INVALID_TILE) return CMD_ERROR; |
0 | 635 |
|
636 |
_build_tunnel_endtile = endtile; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
637 |
|
0 | 638 |
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty |
639 |
// check if you're allowed to remove the tunnel owned by a town |
|
640 |
// removal allowal depends on difficulty settings |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
641 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) { |
0 | 642 |
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
511
diff
changeset
|
643 |
SetDParam(0, t->index); |
0 | 644 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
645 |
} |
|
646 |
} |
|
647 |
||
648 |
if (flags & DC_EXEC) { |
|
38
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
649 |
// 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
|
650 |
// 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
|
651 |
byte tile_dir = _map5[tile]&3; |
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
652 |
byte endtile_dir = _map5[endtile]&3; |
0 | 653 |
DoClearSquare(tile); |
654 |
DoClearSquare(endtile); |
|
38
d20549a6ea13
(svn r39) -Fix [1008605] Signals not updated after ClearTunnel Bug [985920] (TrueLight)
darkvater
parents:
22
diff
changeset
|
655 |
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
|
656 |
UpdateSignalsOnSegment(endtile, _updsignals_tunnel_dir[endtile_dir]); |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
657 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) |
1005 | 658 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
0 | 659 |
} |
660 |
return _price.clear_tunnel * (length + 1); |
|
661 |
} |
|
662 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
663 |
static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile) |
0 | 664 |
{ |
665 |
int direction = _map5[tile] & 1; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
666 |
TileIndex start; |
0 | 667 |
|
668 |
// find start of bridge |
|
669 |
for(;;) { |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
670 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0x80) |
0 | 671 |
break; |
1981 | 672 |
tile += direction ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); |
0 | 673 |
} |
674 |
||
675 |
start = tile; |
|
676 |
||
677 |
// find end of bridge |
|
678 |
for(;;) { |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
679 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xE0) == 0xA0) |
0 | 680 |
break; |
1981 | 681 |
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 682 |
} |
683 |
||
684 |
*endtile = tile; |
|
685 |
||
686 |
return start; |
|
687 |
} |
|
688 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
689 |
static int32 DoClearBridge(TileIndex tile, uint32 flags) |
0 | 690 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
691 |
TileIndex endtile; |
0 | 692 |
Vehicle *v; |
693 |
Town *t; |
|
694 |
int direction; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
695 |
|
0 | 696 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
697 |
||
698 |
direction = _map5[tile]&1; |
|
699 |
||
700 |
/* delete stuff under the middle part if there's a transport route there..? */ |
|
701 |
if ((_map5[tile] & 0xE0) == 0xE0) { |
|
702 |
int32 cost; |
|
703 |
||
704 |
// check if we own the tile below the bridge.. |
|
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
705 |
if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))) |
0 | 706 |
return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
707 |
|
0 | 708 |
cost = (_map5[tile] & 8) ? _price.remove_road * 2 : _price.remove_rail; |
709 |
||
710 |
if (flags & DC_EXEC) { |
|
711 |
_map5[tile] = _map5[tile] & ~0x38; |
|
1902 | 712 |
SetTileOwner(tile, OWNER_NONE); |
0 | 713 |
MarkTileDirtyByTile(tile); |
714 |
} |
|
715 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
716 |
|
0 | 717 |
/* delete canal under bridge */ |
1930
29c3aae05716
(svn r2436) - Fix: Deleting canals under bridges removes bridges first in certain configurations (peter1138)
Darkvater
parents:
1902
diff
changeset
|
718 |
} else if ((_map5[tile] & 0xC8) == 0xC8 && TilePixelHeight(tile) != 0) { |
0 | 719 |
int32 cost; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
720 |
|
0 | 721 |
// check for vehicles under bridge |
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
722 |
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 723 |
return CMD_ERROR; |
724 |
cost = _price.clear_water; |
|
725 |
if (flags & DC_EXEC) { |
|
726 |
_map5[tile] = _map5[tile] & ~0x38; |
|
1902 | 727 |
SetTileOwner(tile, OWNER_NONE); |
0 | 728 |
MarkTileDirtyByTile(tile); |
729 |
} |
|
730 |
return cost; |
|
731 |
} |
|
732 |
||
733 |
tile = FindEdgesOfBridge(tile, &endtile); |
|
734 |
||
735 |
// floods, scenario editor can always destroy bridges |
|
736 |
if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) { |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
737 |
if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN)) |
0 | 738 |
return CMD_ERROR; |
739 |
} |
|
740 |
||
741 |
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) |
|
742 |
return CMD_ERROR; |
|
743 |
||
744 |
/* Make sure there's no vehicle on the bridge |
|
745 |
Omit tile and endtile, since these are already checked, thus solving the problem |
|
746 |
of bridges over water, or higher bridges, where z is not increased, eg level bridge |
|
747 |
*/ |
|
1981 | 748 |
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
749 |
endtile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
|
1082
a83d7ac6fecb
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1073
diff
changeset
|
750 |
/* Bridges on slopes might have their Z-value offset..correct this */ |
a83d7ac6fecb
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1073
diff
changeset
|
751 |
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
|
752 |
VehicleInTheWayErrMsg(v); |
0 | 753 |
return CMD_ERROR; |
754 |
} |
|
755 |
||
756 |
/* Put the tiles back to start/end position */ |
|
1981 | 757 |
tile -= direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
758 |
endtile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
|
0 | 759 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
760 |
|
0 | 761 |
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
|
762 |
// check if you're allowed to remove the bridge owned by a town. |
0 | 763 |
// removal allowal depends on difficulty settings |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
764 |
if (IsTileOwner(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
|
765 |
if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) |
0 | 766 |
return CMD_ERROR; |
767 |
} |
|
768 |
||
769 |
if (flags & DC_EXEC) { |
|
770 |
byte m5; |
|
771 |
uint c = tile; |
|
772 |
uint16 new_data; |
|
773 |
||
1005 | 774 |
//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until |
0 | 775 |
// you have a "Poor" (0) town rating |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
776 |
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) |
1005 | 777 |
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM); |
0 | 778 |
|
779 |
do { |
|
780 |
m5 = _map5[c]; |
|
781 |
||
782 |
if (m5 & 0x40) { |
|
783 |
if (m5 & 0x20) { |
|
784 |
static const uint16 _new_data_table[] = {0x1002, 0x1001, 0x2005, 0x200A, 0, 0, 0, 0}; |
|
785 |
new_data = _new_data_table[((m5 & 0x18) >> 2) | (m5&1)]; |
|
786 |
} else { |
|
787 |
if (!(m5 & 0x18)) goto clear_it; |
|
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
788 |
new_data = (GetTileSlope(c, NULL) == 0) ? 0x6000 : 0x6001; |
0 | 789 |
} |
790 |
||
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
791 |
SetTileType(c, new_data >> 12); |
0 | 792 |
_map5[c] = (byte)new_data; |
793 |
_map2[c] = 0; |
|
794 |
||
795 |
MarkTileDirtyByTile(c); |
|
796 |
||
797 |
} else { |
|
798 |
clear_it:; |
|
799 |
DoClearSquare(c); |
|
800 |
} |
|
1981 | 801 |
c += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 802 |
} while (c <= endtile); |
803 |
||
804 |
SetSignalsOnBothDir(tile, direction); |
|
805 |
SetSignalsOnBothDir(endtile, direction); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
806 |
|
0 | 807 |
} |
808 |
||
809 |
return ((((endtile - tile) >> (direction?8:0))&0xFF)+1) * _price.clear_bridge; |
|
810 |
} |
|
811 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
812 |
static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags) |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
813 |
{ |
0 | 814 |
byte m5 = _map5[tile]; |
815 |
||
816 |
if ((m5 & 0xF0) == 0) { |
|
817 |
if (flags & DC_AUTO) |
|
818 |
return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST); |
|
1082
a83d7ac6fecb
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1073
diff
changeset
|
819 |
|
0 | 820 |
return DoClearTunnel(tile, flags); |
821 |
} else if (m5 & 0x80) { |
|
822 |
if (flags & DC_AUTO) |
|
823 |
return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
|
824 |
||
1082
a83d7ac6fecb
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1073
diff
changeset
|
825 |
return DoClearBridge(tile, flags); |
1109
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
826 |
} |
ecb98f43ba2c
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1095
diff
changeset
|
827 |
|
1082
a83d7ac6fecb
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1073
diff
changeset
|
828 |
return CMD_ERROR; |
0 | 829 |
} |
830 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
831 |
int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec) |
0 | 832 |
{ |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
833 |
TileIndex endtile; |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
834 |
uint length; |
0 | 835 |
Vehicle *v; |
836 |
||
837 |
if ((_map5[tile] & 0xFC) == 0x00) { |
|
838 |
// railway tunnel |
|
839 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
840 |
||
841 |
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
|
842 |
|
0 | 843 |
endtile = CheckTunnelBusy(tile, &length); |
1430
967f56d158a5
(svn r1934) Small cleanup (uint -> TileIndex, (uint)-1 -> INVALID_TILE and similar stuff)
tron
parents:
1419
diff
changeset
|
844 |
if (endtile == INVALID_TILE) return CMD_ERROR; |
0 | 845 |
|
846 |
if (exec) { |
|
847 |
_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype; |
|
848 |
_map3_lo[endtile] = (_map3_lo[endtile] & 0xF0) + totype; |
|
849 |
MarkTileDirtyByTile(tile); |
|
850 |
MarkTileDirtyByTile(endtile); |
|
851 |
} |
|
852 |
return (length + 1) * (_price.build_rail >> 1); |
|
853 |
} else if ((_map5[tile] & 0xF8) == 0xE0) { |
|
854 |
// bridge middle part with rail below |
|
855 |
// only check for train under bridge |
|
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
856 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 857 |
return CMD_ERROR; |
858 |
||
859 |
// tile is already of requested type? |
|
860 |
if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR; |
|
861 |
// change type. |
|
862 |
if (exec) { |
|
863 |
_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype; |
|
864 |
MarkTileDirtyByTile(tile); |
|
865 |
} |
|
866 |
return _price.build_rail >> 1; |
|
867 |
} else if ((_map5[tile]&0xC6) == 0x80) { |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1781
diff
changeset
|
868 |
TileIndex starttile; |
0 | 869 |
int32 cost; |
1073
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
870 |
uint z = TilePixelHeight(tile); |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
871 |
|
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
872 |
z += 8; |
0 | 873 |
|
874 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
|
875 |
||
876 |
// railway bridge |
|
877 |
starttile = tile = FindEdgesOfBridge(tile, &endtile); |
|
878 |
// Make sure there's no vehicle on the bridge |
|
1073
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
879 |
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
|
880 |
VehicleInTheWayErrMsg(v); |
0 | 881 |
return CMD_ERROR; |
882 |
} |
|
883 |
||
1073
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
884 |
if (!EnsureNoVehicle(starttile) || !EnsureNoVehicle(endtile)) { |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
885 |
_error_message = STR_8803_TRAIN_IN_THE_WAY; |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
886 |
return CMD_ERROR; |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
887 |
} |
4e8f5f9d673d
(svn r1574) -Fix [ 1105281 ] upgrade rail fails when train under bridge
celestar
parents:
1067
diff
changeset
|
888 |
|
0 | 889 |
if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR; |
890 |
cost = 0; |
|
891 |
do { |
|
892 |
if (exec) { |
|
893 |
if (tile == starttile || tile == endtile) { |
|
894 |
_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype; |
|
895 |
} else { |
|
896 |
_map3_lo[tile] = (_map3_lo[tile] & 0x0F) + (totype << 4); |
|
897 |
} |
|
898 |
MarkTileDirtyByTile(tile); |
|
899 |
} |
|
900 |
cost += (_price.build_rail>>1); |
|
1981 | 901 |
tile += _map5[tile] & 1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 902 |
} while (tile <= endtile); |
903 |
||
904 |
return cost; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
905 |
} else |
0 | 906 |
return CMD_ERROR; |
907 |
} |
|
908 |
||
909 |
||
910 |
// fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile. |
|
1095 | 911 |
static uint GetBridgeHeight(const TileInfo *ti) |
0 | 912 |
{ |
1981 | 913 |
TileIndexDiff delta; |
1192
2649bd4e556a
(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
|
914 |
TileIndex tile = ti->tile; |
0 | 915 |
|
916 |
// find the end tile of the bridge. |
|
1981 | 917 |
delta = (_map5[tile] & 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
0 | 918 |
do { |
919 |
assert((_map5[tile] & 0xC0) == 0xC0); // bridge and middle part |
|
920 |
tile += delta; |
|
921 |
} while (_map5[tile] & 0x40); // while bridge middle parts |
|
922 |
||
1192
2649bd4e556a
(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
|
923 |
/* Return the height there (the height of the NORTH CORNER) |
2649bd4e556a
(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 |
* If the end of the bridge is on a tileh 7 (all raised, except north corner), |
2649bd4e556a
(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 |
* the z coordinate is 1 height level too low. Compensate for that */ |
2649bd4e556a
(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 |
return TilePixelHeight(tile) + (GetTileSlope(tile, NULL) == 7 ? 8 : 0); |
0 | 927 |
} |
928 |
||
929 |
static const byte _bridge_foundations[2][16] = { |
|
930 |
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
931 |
{1,16,18,3,20,5,0,7,22,0,10,11,12,13,14}, |
|
932 |
{1,15,17,0,19,5,6,7,21,9,10,11, 0,13,14}, |
|
933 |
}; |
|
934 |
||
935 |
extern const byte _road_sloped_sprites[14]; |
|
936 |
||
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1430
diff
changeset
|
937 |
#include "table/track_land.h" |
511
7c89b8581876
(svn r826) Seperate all bridge related tables from tunnel_land.h into their own file
tron
parents:
507
diff
changeset
|
938 |
#include "table/bridge_land.h" |
0 | 939 |
#include "table/tunnel_land.h" |
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
940 |
#include "table/water_land.h" |
0 | 941 |
|
942 |
static void DrawBridgePillars(TileInfo *ti, int x, int y, int z) |
|
943 |
{ |
|
944 |
const uint32 *b; |
|
945 |
uint32 image; |
|
946 |
int piece; |
|
947 |
||
948 |
b = _bridge_poles_table[_map2[ti->tile]>>4]; |
|
949 |
||
950 |
// Draw first piece |
|
951 |
// (necessary for cantilever bridges) |
|
952 |
image = b[12 + (ti->map5&0x01)]; |
|
953 |
piece = _map2[ti->tile]&0xF; |
|
333
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
954 |
if (image != 0 && piece != 0) { |
497
4d1c889526ee
(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
|
955 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
333
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
956 |
DrawGroundSpriteAt(image, x, y, z); |
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
957 |
} |
0 | 958 |
|
959 |
image = b[(ti->map5&0x01)*6 + piece]; |
|
960 |
||
961 |
if (image != 0) { |
|
962 |
int back_height, front_height, i=z; |
|
963 |
const byte *p; |
|
964 |
||
965 |
static const byte _tileh_bits[4][8] = { |
|
966 |
{2,1,8,4, 16,11,0,9}, |
|
967 |
{1,8,4,2, 11,16,9,0}, |
|
968 |
{4,8,1,2, 16,11,0,9}, |
|
969 |
{2,4,8,1, 11,16,9,0}, |
|
970 |
}; |
|
971 |
||
497
4d1c889526ee
(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
|
972 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
333
be1ecd3b8f7c
(svn r500) -Fix: Some bridge part isn't displayed transparent in transparent mode
tron
parents:
241
diff
changeset
|
973 |
|
0 | 974 |
p = _tileh_bits[(image & 1) * 2 + (ti->map5&0x01)]; |
975 |
front_height = ti->z + ((ti->tileh & p[0])?8:0); |
|
976 |
back_height = ti->z + ((ti->tileh & p[1])?8:0); |
|
977 |
if (ti->tileh & 0x10) { |
|
978 |
if (!(ti->tileh & p[2])) front_height += 8; |
|
979 |
if (!(ti->tileh & p[3])) back_height += 8; |
|
980 |
} |
|
981 |
||
982 |
for(; z>=front_height || z>=back_height; z=z-8) { |
|
983 |
if (z>=front_height) AddSortableSpriteToDraw(image, x,y, p[4], p[5], 0x28, z); // front facing pillar |
|
984 |
if (z>=back_height && z<i-8) AddSortableSpriteToDraw(image, x - p[6], y - p[7], p[4], p[5], 0x28, z); // back facing pillar |
|
985 |
} |
|
986 |
} |
|
987 |
} |
|
988 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
39
diff
changeset
|
989 |
uint GetBridgeFoundation(uint tileh, byte direction) { |
0 | 990 |
int i; |
991 |
// normal level sloped building (7, 11, 13, 14) |
|
992 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh)) |
|
993 |
return tileh; |
|
994 |
||
995 |
// inclined sloped building |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
996 |
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && |
0 | 997 |
( direction == 0 || (i++, direction == 1)) ) |
998 |
return i + 15; |
|
999 |
||
1000 |
return 0; |
|
1001 |
} |
|
1002 |
||
1003 |
static void DrawTile_TunnelBridge(TileInfo *ti) |
|
1004 |
{ |
|
1005 |
uint32 image; |
|
1006 |
uint tmp; |
|
1007 |
const uint32 *b; |
|
1008 |
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
|
1009 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1010 |
// draw tunnel? |
0 | 1011 |
if ( (byte)(ti->map5&0xF0) == 0) { |
1012 |
/* railway type */ |
|
1013 |
image = (_map3_lo[ti->tile] & 0xF) * 8; |
|
1014 |
||
1015 |
/* ice? */ |
|
1016 |
if (ice) |
|
1017 |
image += 32; |
|
1018 |
||
1019 |
image += _draw_tunnel_table_1[(ti->map5 >> 2) & 0x3]; |
|
1020 |
image += (ti->map5 & 3) << 1; |
|
1021 |
DrawGroundSprite(image); |
|
1022 |
||
1023 |
AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z); |
|
1024 |
// draw bridge? |
|
1025 |
} else if ((byte)ti->map5 & 0x80) { |
|
1026 |
// get type of track on the bridge. |
|
1027 |
tmp = _map3_lo[ti->tile]; |
|
1028 |
if (ti->map5 & 0x40) tmp >>= 4; |
|
1029 |
tmp &= 0xF; |
|
1030 |
||
1031 |
// 0 = rail bridge |
|
1032 |
// 1 = road bridge |
|
1033 |
// 2 = monorail bridge |
|
1034 |
// 3 = maglev bridge |
|
1035 |
||
1036 |
// add direction and fix stuff. |
|
1037 |
if (tmp != 0) tmp++; |
|
1038 |
tmp = (ti->map5&3) + (tmp*2); |
|
1039 |
||
1040 |
if (!(ti->map5 & 0x40)) { // bridge ramps |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1041 |
|
0 | 1042 |
if (!(BRIDGE_NO_FOUNDATION & (1 << ti->tileh))) { // no foundations for 0, 3, 6, 9, 12 |
1043 |
int f = GetBridgeFoundation(ti->tileh, ti->map5 & 0x1); // pass direction |
|
1044 |
if (f) DrawFoundation(ti, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1045 |
|
0 | 1046 |
// default sloped sprites.. |
1047 |
if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3; |
|
1048 |
} |
|
1049 |
||
1050 |
// bridge ending. |
|
1562
20af59a8bc3b
(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
|
1051 |
b = _bridge_sprite_table[(_map2[ti->tile] >> 4) & 0xF][6]; |
0 | 1052 |
b += (tmp&(3<<1))*4; /* actually ((tmp>>2)&3)*8 */ |
1053 |
b += (tmp&1); // direction |
|
1054 |
if (ti->tileh == 0) b += 4; // sloped "entrance" ? |
|
1055 |
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
|
1056 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1057 |
image = *b; |
0 | 1058 |
|
1059 |
if (!ice) { |
|
1060 |
DrawClearLandTile(ti, 3); |
|
1061 |
} else { |
|
1062 |
DrawGroundSprite(0x11C6 + _tileh_to_sprite[ti->tileh]); |
|
1063 |
} |
|
1064 |
||
1065 |
// draw ramp |
|
497
4d1c889526ee
(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
|
1066 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
0 | 1067 |
AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z); |
1068 |
} else { |
|
1069 |
// bridge middle part. |
|
1070 |
uint z; |
|
1071 |
int x,y; |
|
1072 |
||
1073 |
image = (ti->map5 >> 3) & 3; // type of stuff under bridge (only defined for 0,1) |
|
1074 |
assert(image <= 1); |
|
1075 |
||
1076 |
if (!(ti->map5 & 0x20)) { |
|
1077 |
// draw land under bridge |
|
1078 |
if (ice) image += 2; // ice too? |
|
1091
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1079 |
|
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1080 |
if (image != 1 || ti->tileh == 0) |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1081 |
DrawGroundSprite(_bridge_land_below[image] + _tileh_to_sprite[ti->tileh]); |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1082 |
else |
0f113f2ed794
(svn r1592) -Fix: [1090495] Slopes under high bridges weren't flooded
tron
parents:
1082
diff
changeset
|
1083 |
DrawGroundSprite(_water_shore_sprites[ti->tileh]); |
0 | 1084 |
|
1085 |
// draw canal water? |
|
1086 |
if (ti->map5 & 8 && ti->z != 0) DrawCanalWater(ti->tile); |
|
1087 |
} else { |
|
1088 |
// draw transport route under bridge |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1089 |
|
0 | 1090 |
// draw foundation? |
1091 |
if (ti->tileh) { |
|
1092 |
int f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1093 |
if (f) DrawFoundation(ti, f); |
|
1094 |
} |
|
1095 |
||
1096 |
if (!(image&1)) { |
|
1097 |
// railway |
|
1098 |
image = 0x3F3 + (ti->map5 & 1); |
|
1099 |
if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3; |
|
1100 |
image += (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH; |
|
1101 |
if (ice) image += 26; // ice? |
|
1102 |
} else { |
|
1103 |
// road |
|
1104 |
image = 1332 + (ti->map5 & 1); |
|
1105 |
if (ti->tileh != 0) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
|
1106 |
if (ice) image += 19; // ice? |
|
1107 |
} |
|
1108 |
DrawGroundSprite(image); |
|
1109 |
} |
|
1110 |
// get bridge sprites |
|
1562
20af59a8bc3b
(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
|
1111 |
b = _bridge_sprite_table[(_map2[ti->tile] >> 4) & 0xF][_map2[ti->tile]&0xF] + tmp * 4; |
0 | 1112 |
|
1113 |
z = GetBridgeHeight(ti) + 5; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1114 |
|
0 | 1115 |
// draw rail |
1116 |
image = b[0]; |
|
497
4d1c889526ee
(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
|
1117 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
0 | 1118 |
AddSortableSpriteToDraw(image, ti->x, ti->y, (ti->map5&1)?11:16, (ti->map5&1)?16:11, 1, z); |
1119 |
||
1120 |
x = ti->x; |
|
1121 |
y = ti->y; |
|
1122 |
image = b[1]; |
|
497
4d1c889526ee
(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
|
1123 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
0 | 1124 |
|
1125 |
// draw roof |
|
1126 |
if (ti->map5&1) { |
|
1127 |
x += 12; |
|
1128 |
if (image&0x3FFF) AddSortableSpriteToDraw(image, x,y, 1, 16, 0x28, z); |
|
1129 |
} else { |
|
1130 |
y += 12; |
|
1131 |
if (image&0x3FFF) AddSortableSpriteToDraw(image, x,y, 16, 1, 0x28, z); |
|
1132 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1133 |
|
0 | 1134 |
if (ti->z + 5 == z ) { |
1135 |
// draw poles below for small bridges |
|
1136 |
image = b[2]; |
|
1137 |
if (image) { |
|
497
4d1c889526ee
(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
|
1138 |
if (_display_opt & DO_TRANS_BUILDINGS) image = (image & 0x3FFF) | 0x03224000; |
0 | 1139 |
DrawGroundSpriteAt(image, x, y, z); |
1140 |
} |
|
1141 |
} else if (_patches.bridge_pillars) { |
|
1142 |
// draw pillars below for high bridges |
|
1143 |
DrawBridgePillars(ti, x, y, z); |
|
1144 |
} |
|
1145 |
} |
|
1146 |
} |
|
1147 |
} |
|
1148 |
||
1149 |
static uint GetSlopeZ_TunnelBridge(TileInfo *ti) { |
|
1150 |
uint z = ti->z; |
|
1151 |
uint x = ti->x & 0xF; |
|
1152 |
uint y = ti->y & 0xF; |
|
1153 |
||
1154 |
// swap directions if Y tunnel/bridge to let the code handle the X case only. |
|
1884
804ff5f94ed0
(svn r2390) - Codechange: Fix some warnings on GCC 4.0.0
hackykid
parents:
1784
diff
changeset
|
1155 |
if (ti->map5 & 1) uintswap(x,y); |
0 | 1156 |
|
1157 |
// to the side of the tunnel/bridge? |
|
1158 |
if (IS_INT_INSIDE(y, 5, 10+1)) { |
|
1159 |
// tunnel? |
|
1160 |
if ( (ti->map5 & 0xF0) == 0) |
|
1161 |
return z; |
|
1162 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1163 |
// bridge? |
0 | 1164 |
if ( ti->map5 & 0x80 ) { |
1165 |
// bridge ending? |
|
1166 |
if (!(ti->map5 & 0x40)) { |
|
1167 |
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti->tileh)) // 7, 11, 13, 14 |
|
1168 |
z += 8; |
|
1169 |
||
1170 |
// no ramp for bridge ending |
|
1171 |
if ((BRIDGE_PARTLY_LEVELED_FOUNDATION & (1 << ti->tileh) || BRIDGE_NO_FOUNDATION & (1 << ti->tileh)) && ti->tileh != 0) { |
|
1172 |
return z + 8; |
|
1173 |
||
1174 |
} else if (!(ti->map5 & 0x20)) { // northern / southern ending |
|
1175 |
// ramp |
|
1176 |
return (z + (x>>1) + 1); |
|
1177 |
} else { |
|
1178 |
// ramp in opposite dir |
|
1179 |
return (z + ((x^0xF)>>1)); |
|
1180 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1181 |
|
0 | 1182 |
// bridge middle part |
1183 |
} else { |
|
1184 |
// build on slopes? |
|
1185 |
if (ti->tileh) z+=8; |
|
1186 |
||
1187 |
// 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
|
1188 |
if (_get_z_hint >= z + 8) |
0 | 1189 |
return _get_z_hint; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1190 |
|
0 | 1191 |
// 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
|
1192 |
if (!IS_INT_INSIDE(x, 5, 10+1)) |
0 | 1193 |
return GetBridgeHeight(ti) + 8; |
1194 |
||
1195 |
// in the shared area, assume that we're below the bridge, cause otherwise the hint would've caught it. |
|
1196 |
// if rail or road below then it means it's possibly build on slope below the bridge. |
|
1197 |
if (ti->map5 & 0x20) { |
|
1198 |
uint f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1199 |
// make sure that the slope is not inclined foundation |
|
1200 |
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
|
1201 |
|
0 | 1202 |
// change foundation type? |
1203 |
if (f) ti->tileh = _inclined_tileh[f - 15]; |
|
1204 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1205 |
|
0 | 1206 |
// no transport route, fallback to default |
1207 |
} |
|
1208 |
} |
|
1209 |
} else { |
|
1210 |
// if it's a bridge middle with transport route below, then we need to compensate for build on slopes |
|
1211 |
if ( (ti->map5 & (0x80 + 0x40 + 0x20)) == (0x80 + 0x40 + 0x20)) { |
|
1212 |
uint f; |
|
1213 |
if (ti->tileh) z += 8; |
|
1214 |
f = _bridge_foundations[ti->map5&1][ti->tileh]; |
|
1215 |
if (IS_BYTE_INSIDE(f, 1, 15)) return z; |
|
1216 |
if (f) ti->tileh = _inclined_tileh[f - 15]; |
|
1217 |
} |
|
1218 |
} |
|
1219 |
||
1220 |
// default case |
|
1221 |
z = ti->z; |
|
1222 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + z; |
|
1223 |
} |
|
1224 |
||
39 | 1225 |
static uint GetSlopeTileh_TunnelBridge(TileInfo *ti) { |
1226 |
// not accurate, but good enough for slope graphics drawing |
|
1227 |
return 0; |
|
1228 |
} |
|
1229 |
||
1230 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1231 |
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac) |
0 | 1232 |
{ |
1233 |
/* not used */ |
|
1234 |
} |
|
1235 |
||
1236 |
static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] = { |
|
1237 |
STR_501F_WOODEN_RAIL_BRIDGE, |
|
1238 |
STR_5020_CONCRETE_RAIL_BRIDGE, |
|
1239 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1240 |
STR_501E_REINFORCED_CONCRETE_SUSPENSION, |
|
1241 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1242 |
STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, |
|
1243 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1244 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1245 |
STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, |
|
1246 |
STR_501C_STEEL_GIRDER_RAIL_BRIDGE, |
|
1247 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1248 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1249 |
STR_5027_TUBULAR_RAIL_BRIDGE, |
|
1250 |
0,0,0, |
|
1251 |
||
1252 |
STR_5025_WOODEN_ROAD_BRIDGE, |
|
1253 |
STR_5026_CONCRETE_ROAD_BRIDGE, |
|
1254 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1255 |
STR_5024_REINFORCED_CONCRETE_SUSPENSION, |
|
1256 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1257 |
STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE, |
|
1258 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1259 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1260 |
STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE, |
|
1261 |
STR_5022_STEEL_GIRDER_ROAD_BRIDGE, |
|
1262 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1263 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1264 |
STR_5028_TUBULAR_ROAD_BRIDGE, |
|
1265 |
0,0,0, |
|
1266 |
}; |
|
1267 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1268 |
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td) |
0 | 1269 |
{ |
1270 |
if ((_map5[tile] & 0x80) == 0) { |
|
1271 |
td->str = STR_5017_RAILROAD_TUNNEL + ((_map5[tile] >> 2) & 3); |
|
1272 |
} else { |
|
1273 |
td->str = _bridge_tile_str[ (_map2[tile] >> 4) + (((_map5[tile]>>1)&3)<<4) ]; |
|
1274 |
||
1275 |
/* scan to the end of the bridge, that's where the owner is stored */ |
|
1276 |
if (_map5[tile] & 0x40) { |
|
1981 | 1277 |
TileIndexDiff delta = _map5[tile] & 1 ? TileDiffXY(0, -1) : TileDiffXY(-1, 0); |
1278 |
||
0 | 1279 |
do tile += delta; while (_map5[tile] & 0x40); |
1280 |
} |
|
1281 |
} |
|
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1282 |
td->owner = GetTileOwner(tile); |
0 | 1283 |
} |
1284 |
||
1285 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1286 |
static void AnimateTile_TunnelBridge(TileIndex tile) |
0 | 1287 |
{ |
1288 |
/* not used */ |
|
1289 |
} |
|
1290 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1291 |
static void TileLoop_TunnelBridge(TileIndex tile) |
0 | 1292 |
{ |
1293 |
if (_opt.landscape == LT_HILLY) { |
|
1294 |
if ( GetTileZ(tile) > _opt.snow_line) { |
|
1295 |
if (!(_map3_hi[tile] & 0x80)) { |
|
1296 |
_map3_hi[tile] |= 0x80; |
|
1297 |
MarkTileDirtyByTile(tile); |
|
1298 |
} |
|
1299 |
} else { |
|
1300 |
if (_map3_hi[tile] & 0x80) { |
|
1301 |
_map3_hi[tile] &= ~0x80; |
|
1302 |
MarkTileDirtyByTile(tile); |
|
1303 |
} |
|
1304 |
} |
|
1305 |
} else if (_opt.landscape == LT_DESERT) { |
|
1306 |
if (GetMapExtraBits(tile) == 1 && !(_map3_hi[tile]&0x80)) { |
|
1307 |
_map3_hi[tile] |= 0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1308 |
MarkTileDirtyByTile(tile); |
0 | 1309 |
} |
1310 |
} |
|
1311 |
||
1312 |
// if it's a bridge with water below, call tileloop_water on it. |
|
1313 |
if ((_map5[tile] & 0xF8) == 0xC8) TileLoop_Water(tile); |
|
1314 |
} |
|
1315 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1316 |
static void ClickTile_TunnelBridge(TileIndex tile) |
0 | 1317 |
{ |
1318 |
/* not used */ |
|
1319 |
} |
|
1320 |
||
1321 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1322 |
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode) |
0 | 1323 |
{ |
1324 |
uint32 result; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1325 |
byte m5 = _map5[tile]; |
0 | 1326 |
|
1327 |
if ((m5 & 0xF0) == 0) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1328 |
/* This is a tunnel */ |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1329 |
if (((m5 & 0xCU) >> 2) == mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1330 |
/* Tranport in the tunnel is compatible */ |
0 | 1331 |
return m5&1 ? 0x202 : 0x101; |
1332 |
} |
|
1333 |
} else if (m5 & 0x80) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1334 |
/* This is a bridge */ |
0 | 1335 |
result = 0; |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1336 |
if (((m5 & 0x6U) >> 1) == mode) { |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1337 |
/* Transport over the bridge is compatible */ |
0 | 1338 |
result = m5&1 ? 0x202 : 0x101; |
1339 |
} |
|
1340 |
if (m5 & 0x40) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1341 |
/* Bridge middle part */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1342 |
if (!(m5 & 0x20)) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1343 |
/* 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
|
1344 |
if ((m5 & 0x18) != 8) |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1345 |
/* Clear ground */ |
0 | 1346 |
return result; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1347 |
else |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1348 |
if (mode != TRANSPORT_WATER) |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1349 |
return result; |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1350 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1351 |
/* Transport underneath */ |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
1352 |
if ((m5 & 0x18U) >> 3 != mode) |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1353 |
/* Incompatible transport underneath */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1354 |
return result; |
0 | 1355 |
} |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1356 |
/* If we've not returned yet, there is a compatible |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1357 |
* transport or water beneath, so we can add it to |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1358 |
* result */ |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1359 |
/* Why is this xor'd ? Can't it just be or'd? */ |
0 | 1360 |
result ^= m5&1 ? 0x101 : 0x202; |
1361 |
} |
|
1362 |
return result; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1363 |
} else { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
98
diff
changeset
|
1364 |
assert(0); /* This should never occur */ |
0 | 1365 |
} |
1366 |
return 0; |
|
1367 |
} |
|
1368 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1369 |
static void ChangeTileOwner_TunnelBridge(TileIndex tile, byte old_player, byte new_player) |
0 | 1370 |
{ |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1371 |
if (!IsTileOwner(tile, old_player)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1372 |
|
0 | 1373 |
if (new_player != 255) { |
1902 | 1374 |
SetTileOwner(tile, new_player); |
0 | 1375 |
} else { |
1376 |
if((_map5[tile] & 0xC0)==0xC0) { |
|
1377 |
// the stuff BELOW the middle part is owned by the deleted player. |
|
1378 |
if (!(_map5[tile] & (1 << 4 | 1 << 3))) { |
|
1379 |
// convert railway into grass. |
|
1380 |
_map5[tile] &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore.. |
|
1381 |
} else { |
|
1382 |
// for road, change the owner of the road to local authority |
|
1902 | 1383 |
SetTileOwner(tile, OWNER_NONE); |
0 | 1384 |
} |
1385 |
} else { |
|
1386 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1387 |
} |
|
1388 |
} |
|
1389 |
} |
|
1390 |
||
1391 |
||
1392 |
static const byte _tunnel_fractcoord_1[4] = {0x8E,0x18,0x81,0xE8}; |
|
1393 |
static const byte _tunnel_fractcoord_2[4] = {0x81,0x98,0x87,0x38}; |
|
1394 |
static const byte _tunnel_fractcoord_3[4] = {0x82,0x88,0x86,0x48}; |
|
1395 |
static const byte _exit_tunnel_track[4] = {1,2,1,2}; |
|
1396 |
||
1397 |
static const byte _road_exit_tunnel_state[4] = {8, 9, 0, 1}; |
|
1398 |
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4}; |
|
1399 |
||
1400 |
static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29}; |
|
1401 |
static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25}; |
|
1402 |
static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45}; |
|
1403 |
static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49}; |
|
1404 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1930
diff
changeset
|
1405 |
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) |
0 | 1406 |
{ |
1407 |
int z; |
|
1408 |
int dir, vdir; |
|
1409 |
byte fc; |
|
1410 |
||
1411 |
if ((_map5[tile] & 0xF0) == 0) { |
|
1412 |
z = GetSlopeZ(x, y) - v->z_pos; |
|
1413 |
if (myabs(z) > 2) |
|
1414 |
return 8; |
|
1415 |
||
1416 |
if (v->type == VEH_Train) { |
|
1417 |
fc = (x&0xF)+(y<<4); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1418 |
|
0 | 1419 |
dir = _map5[tile] & 3; |
1420 |
vdir = v->direction >> 1; |
|
1421 |
||
1422 |
if (v->u.rail.track != 0x40 && dir == vdir) { |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1059
diff
changeset
|
1423 |
if (v->subtype == TS_Front_Engine && fc == _tunnel_fractcoord_1[dir]) { |
0 | 1424 |
if (v->spritenum < 4) |
541 | 1425 |
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); |
0 | 1426 |
return 0; |
1427 |
} |
|
1428 |
if (fc == _tunnel_fractcoord_2[dir]) { |
|
1429 |
v->tile = tile; |
|
1430 |
v->u.rail.track = 0x40; |
|
1431 |
v->vehstatus |= VS_HIDDEN; |
|
1432 |
return 4; |
|
1433 |
} |
|
1434 |
} |
|
1435 |
||
1436 |
if (dir == (vdir^2) && fc == _tunnel_fractcoord_3[dir] && z == 0) { |
|
22 | 1437 |
/* We're at the tunnel exit ?? */ |
0 | 1438 |
v->tile = tile; |
1439 |
v->u.rail.track = _exit_tunnel_track[dir]; |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1209
diff
changeset
|
1440 |
assert(v->u.rail.track); |
0 | 1441 |
v->vehstatus &= ~VS_HIDDEN; |
1442 |
return 4; |
|
1443 |
} |
|
1444 |
} else if (v->type == VEH_Road) { |
|
1445 |
fc = (x&0xF)+(y<<4); |
|
1446 |
dir = _map5[tile] & 3; |
|
1447 |
vdir = v->direction >> 1; |
|
1448 |
||
1449 |
// Enter tunnel? |
|
1450 |
if (v->u.road.state != 0xFF && dir == vdir) { |
|
1451 |
if (fc == _tunnel_fractcoord_4[dir] || |
|
1452 |
fc == _tunnel_fractcoord_5[dir]) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1453 |
|
0 | 1454 |
v->tile = tile; |
1455 |
v->u.road.state = 0xFF; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1456 |
v->vehstatus |= VS_HIDDEN; |
0 | 1457 |
return 4; |
1458 |
} else { |
|
1459 |
return 0; |
|
1460 |
} |
|
1461 |
} |
|
1462 |
||
1463 |
if (dir == (vdir^2) && ( |
|
22 | 1464 |
/* We're at the tunnel exit ?? */ |
0 | 1465 |
fc == _tunnel_fractcoord_6[dir] || |
1466 |
fc == _tunnel_fractcoord_7[dir]) && |
|
1467 |
z == 0) { |
|
1468 |
v->tile = tile; |
|
1469 |
v->u.road.state = _road_exit_tunnel_state[dir]; |
|
1470 |
v->u.road.frame = _road_exit_tunnel_frame[dir]; |
|
1471 |
v->vehstatus &= ~VS_HIDDEN; |
|
1472 |
return 4; |
|
1473 |
} |
|
1474 |
} |
|
1475 |
} else if (_map5[tile] & 0x80) { |
|
1067
3ba7987a004e
(svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents:
1059
diff
changeset
|
1476 |
if (v->type == VEH_Road || (v->type == VEH_Train && v->subtype == TS_Front_Engine)) { |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1477 |
uint h; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1478 |
|
334
7e87a24e88b5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1479 |
if (GetTileSlope(tile, &h) != 0) |
7e87a24e88b5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1480 |
h += 8; // Compensate for possible foundation |
7e87a24e88b5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1481 |
if (!(_map5[tile] & 0x40) || // start/end tile of bridge |
7e87a24e88b5
(svn r501) -Fix: Vehicles slow down under bridge if the track is on a foundation
tron
parents:
333
diff
changeset
|
1482 |
myabs(h - v->z_pos) > 2) { // high above the ground -> on the bridge |
0 | 1483 |
/* modify speed of vehicle */ |
1484 |
uint16 spd = _bridge_speeds[_map2[tile] >> 4]; |
|
1485 |
if (v->type == VEH_Road) spd<<=1; |
|
1486 |
if (spd < v->cur_speed) |
|
1487 |
v->cur_speed = spd; |
|
1488 |
} |
|
1489 |
} |
|
1490 |
} |
|
1491 |
return 0; |
|
1492 |
} |
|
1493 |
||
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1494 |
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v) |
0 | 1495 |
{ |
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1496 |
TileIndex tile; |
1981 | 1497 |
TileIndexDiff delta = (v->direction & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0); |
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1498 |
byte z = v->z_pos; |
0 | 1499 |
|
1587
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1500 |
for (tile = v->tile;; tile += delta) { |
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1501 |
if (IsTileType(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0) == 0 && |
e054351c7bf0
(svn r2091) Small cleanup: uint -> TileIndex, const, don't call FindLandscapeHeightByTile()
tron
parents:
1585
diff
changeset
|
1502 |
GetTileZ(tile) == z) |
0 | 1503 |
break; |
1504 |
} |
|
1505 |
return tile; |
|
1506 |
} |
|
1507 |
||
1508 |
const TileTypeProcs _tile_type_tunnelbridge_procs = { |
|
1509 |
DrawTile_TunnelBridge, /* draw_tile_proc */ |
|
1510 |
GetSlopeZ_TunnelBridge, /* get_slope_z_proc */ |
|
1511 |
ClearTile_TunnelBridge, /* clear_tile_proc */ |
|
1512 |
GetAcceptedCargo_TunnelBridge, /* get_accepted_cargo_proc */ |
|
1513 |
GetTileDesc_TunnelBridge, /* get_tile_desc_proc */ |
|
1514 |
GetTileTrackStatus_TunnelBridge,/* get_tile_track_status_proc */ |
|
1515 |
ClickTile_TunnelBridge, /* click_tile_proc */ |
|
1516 |
AnimateTile_TunnelBridge, /* animate_tile_proc */ |
|
1517 |
TileLoop_TunnelBridge, /* tile_loop_clear */ |
|
1518 |
ChangeTileOwner_TunnelBridge, /* change_tile_owner_clear */ |
|
1519 |
NULL, /* get_produced_cargo_proc */ |
|
1520 |
VehicleEnter_TunnelBridge, /* vehicle_enter_tile_proc */ |
|
1521 |
NULL, /* vehicle_leave_tile_proc */ |
|
39 | 1522 |
GetSlopeTileh_TunnelBridge, /* get_slope_tileh_proc */ |
0 | 1523 |
}; |