author | tron |
Sun, 06 Feb 2005 20:53:31 +0000 | |
changeset 1328 | eacd8225ed42 |
parent 1327 | 6e507eb10edd |
child 1359 | 52782e5cf7c9 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
3 |
#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
|
4 |
#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:
1095
diff
changeset
|
5 |
#include "tile.h" |
0 | 6 |
#include "vehicle.h" |
7 |
#include "viewport.h" |
|
8 |
#include "command.h" |
|
9 |
#include "player.h" |
|
10 |
#include "town.h" |
|
11 |
#include "gfx.h" |
|
1247 | 12 |
#include "npf.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
241
diff
changeset
|
13 |
#include "sound.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1281
diff
changeset
|
14 |
#include "depot.h" |
0 | 15 |
|
22 | 16 |
/* When true, GetTrackStatus for roads will treat roads under reconstruction |
17 |
* as normal roads instead of impassable. This is used when detecting whether |
|
18 |
* a road can be removed. This is of course ugly, but I don't know a better |
|
19 |
* solution just like that... */ |
|
0 | 20 |
static bool _road_special_gettrackstatus; |
21 |
||
22 |
void RoadVehEnterDepot(Vehicle *v); |
|
23 |
||
24 |
||
1095 | 25 |
static bool HasTileRoadAt(uint tile, int i) |
0 | 26 |
{ |
27 |
int mask; |
|
28 |
byte b; |
|
29 |
||
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
30 |
switch (GetTileType(tile)) { |
0 | 31 |
case MP_STREET: |
32 |
b = _map5[tile]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
33 |
|
0 | 34 |
if ((b & 0xF0) == 0) { |
35 |
} else if ((b & 0xF0) == 0x10) { |
|
36 |
b = (b&8)?5:10; |
|
37 |
} else if ((b & 0xF0) == 0x20) { |
|
38 |
return (~b & 3) == i; |
|
39 |
} else |
|
40 |
return false; |
|
41 |
break; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
42 |
|
0 | 43 |
case MP_STATION: |
44 |
b = _map5[tile]; |
|
45 |
if (!IS_BYTE_INSIDE(b, 0x43, 0x43+8)) |
|
46 |
return false; |
|
47 |
return ((~(b - 0x43) & 3) == i); |
|
48 |
||
49 |
case MP_TUNNELBRIDGE: |
|
50 |
mask = GetRoadBitsByTile(tile); |
|
51 |
b = 10; if (mask & 1) break; |
|
52 |
b = 5; if (mask & 2) break; |
|
53 |
return false; |
|
54 |
||
55 |
default: |
|
56 |
return false; |
|
57 |
} |
|
58 |
||
59 |
return HASBIT(b, i); |
|
60 |
} |
|
61 |
||
62 |
static bool CheckAllowRemoveRoad(uint tile, uint br, bool *edge_road) |
|
63 |
{ |
|
64 |
int blocks; |
|
65 |
byte owner; |
|
66 |
uint n; |
|
67 |
*edge_road = true; |
|
68 |
||
69 |
if (_game_mode == GM_EDITOR) |
|
70 |
return true; |
|
71 |
||
72 |
blocks = GetRoadBitsByTile(tile); |
|
73 |
if (blocks == 0) |
|
74 |
return true; |
|
75 |
||
76 |
// Only do the special processing for actual players. |
|
77 |
if (_current_player >= MAX_PLAYERS) |
|
78 |
return true; |
|
79 |
||
80 |
// A railway crossing has the road owner in the map3_lo byte. |
|
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
|
81 |
if (IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) { |
0 | 82 |
owner = _map3_lo[tile]; |
83 |
} else { |
|
84 |
owner = _map_owner[tile]; |
|
85 |
} |
|
86 |
// Only do the special processing if the road is owned |
|
87 |
// by a town |
|
88 |
if (owner != OWNER_TOWN) { |
|
89 |
return owner == OWNER_NONE || CheckOwnership(owner); |
|
90 |
} |
|
91 |
||
92 |
if (_cheats.magic_bulldozer.value) |
|
93 |
return true; |
|
94 |
||
95 |
// Get a bitmask of which neighbouring roads has a tile |
|
96 |
n = 0; |
|
97 |
if (blocks&0x25 && HasTileRoadAt(TILE_ADDXY(tile,-1, 0), 1)) n |= 8; |
|
98 |
if (blocks&0x2A && HasTileRoadAt(TILE_ADDXY(tile, 0, 1), 0)) n |= 4; |
|
99 |
if (blocks&0x19 && HasTileRoadAt(TILE_ADDXY(tile, 1, 0), 3)) n |= 2; |
|
100 |
if (blocks&0x16 && HasTileRoadAt(TILE_ADDXY(tile, 0,-1), 2)) n |= 1; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
101 |
|
0 | 102 |
// If 0 or 1 bits are set in n, or if no bits that match the bits to remove, |
103 |
// then allow it |
|
104 |
if ((n & (n-1)) != 0 && (n & br) != 0) { |
|
105 |
Town *t; |
|
106 |
*edge_road = false; |
|
107 |
// you can remove all kind of roads with extra dynamite |
|
108 |
if (_patches.extra_dynamite) |
|
109 |
return true; |
|
110 |
||
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
111 |
t = GetTown(_map2[tile]); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
112 |
SetDParam(0, t->index); |
0 | 113 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
114 |
return false; |
|
115 |
} |
|
116 |
||
117 |
return true; |
|
118 |
} |
|
119 |
||
120 |
uint GetRoadBitsByTile(TileIndex tile) |
|
121 |
{ |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
122 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
0 | 123 |
return (byte)(r | (r >> 8)); |
124 |
} |
|
125 |
||
126 |
// cost for removing inner/edge -roads |
|
127 |
static const uint16 _road_remove_cost[2] = {50, 18}; |
|
128 |
||
129 |
/* Delete a piece of road |
|
130 |
* p1 = piece type |
|
131 |
*/ |
|
132 |
int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
133 |
{ |
|
134 |
TileInfo ti; |
|
135 |
int32 cost; |
|
136 |
uint tile; |
|
137 |
Town *t; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
138 |
/* true if the roadpiece was always removeable, |
0 | 139 |
false if it was a center piece. Affects town ratings drop |
140 |
*/ |
|
141 |
bool edge_road; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
142 |
|
0 | 143 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
144 |
||
145 |
FindLandscapeHeight(&ti, x, y); |
|
146 |
tile = ti.tile; |
|
1281
dd226de69402
(svn r1785) -Fix: space-correctness in road_cmd.c, and one wrong line from last
truelight
parents:
1280
diff
changeset
|
147 |
if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) |
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
148 |
t = GetTown(_map2[tile]); // needed for town rating penalty |
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
149 |
else |
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
150 |
t = NULL; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
151 |
|
0 | 152 |
// allow deleting road under bridge |
153 |
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) |
|
154 |
return CMD_ERROR; |
|
155 |
||
156 |
{ |
|
157 |
bool b; |
|
158 |
_road_special_gettrackstatus = true; |
|
159 |
b = CheckAllowRemoveRoad(tile, p1, &edge_road); |
|
160 |
_road_special_gettrackstatus = false; |
|
161 |
if (!b) |
|
162 |
return CMD_ERROR; |
|
163 |
} |
|
164 |
||
165 |
if (ti.type == MP_TUNNELBRIDGE) { |
|
1041
94db182c3614
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
166 |
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
0 | 167 |
return CMD_ERROR; |
168 |
||
169 |
if ((ti.map5 & 0xE9) == 0xE8) { |
|
170 |
if (p1 & 10) goto return_error; |
|
171 |
} else if ((ti.map5 & 0xE9) == 0xE9) { |
|
172 |
if (p1 & 5) goto return_error; |
|
173 |
} else |
|
174 |
goto return_error; |
|
175 |
||
176 |
cost = _price.remove_road * 2; |
|
177 |
||
178 |
if (flags & DC_EXEC) { |
|
179 |
_map5[tile] = ti.map5 & 0xC7; |
|
180 |
_map_owner[tile] = OWNER_NONE; |
|
181 |
MarkTileDirtyByTile(tile); |
|
182 |
} |
|
183 |
return cost; |
|
184 |
} else if (ti.type == MP_STREET) { |
|
185 |
if (!(ti.map5 & 0xF0)) { |
|
186 |
uint c = p1, t2; |
|
187 |
||
188 |
if (ti.tileh != 0 && (ti.map5 == 5 || ti.map5 == 10)) { |
|
189 |
c |= (c & 0xC) >> 2; |
|
190 |
c |= (c & 0x3) << 2; |
|
191 |
} |
|
192 |
||
193 |
// limit the bits to delete to the existing bits. |
|
194 |
if ((c &= ti.map5) == 0) goto return_error; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
195 |
|
0 | 196 |
// calculate the cost |
197 |
t2 = c; |
|
198 |
cost = 0; |
|
199 |
do { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
200 |
if (t2&1) cost += _price.remove_road; |
0 | 201 |
} while(t2>>=1); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
202 |
|
0 | 203 |
// check if you're allowed to remove the street owned by a town |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
204 |
// removal allowance depends on difficulty setting |
1281
dd226de69402
(svn r1785) -Fix: space-correctness in road_cmd.c, and one wrong line from last
truelight
parents:
1280
diff
changeset
|
205 |
if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) { |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
206 |
if (!CheckforTownRating(tile, flags, t, ROAD_REMOVE)) |
0 | 207 |
return CMD_ERROR; |
208 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
209 |
|
0 | 210 |
if (flags & DC_EXEC) { |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
211 |
// checks if the owner is town than decrease town rating by 50 until you have |
0 | 212 |
// a "Poor" town rating |
1281
dd226de69402
(svn r1785) -Fix: space-correctness in road_cmd.c, and one wrong line from last
truelight
parents:
1280
diff
changeset
|
213 |
if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) |
1005 | 214 |
ChangeTownRating(t, -_road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
0 | 215 |
|
216 |
_map5[tile] ^= c; |
|
217 |
if ((_map5[tile]&0xF) == 0) |
|
218 |
DoClearSquare(tile); |
|
219 |
else |
|
220 |
MarkTileDirtyByTile(tile); |
|
221 |
||
222 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
223 |
return cost; |
0 | 224 |
} else if (!(ti.map5 & 0xE0)) { |
225 |
byte c; |
|
226 |
||
227 |
if (!(ti.map5 & 8)) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
228 |
c = 2; |
0 | 229 |
if (p1 & 5) goto return_error; |
230 |
} else { |
|
231 |
c = 1; |
|
232 |
if (p1 & 10) goto return_error; |
|
233 |
} |
|
234 |
||
235 |
cost = _price.remove_road * 2; |
|
236 |
if (flags & DC_EXEC) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
237 |
ModifyTile(tile, |
0 | 238 |
MP_SETTYPE(MP_RAILWAY) | |
239 |
MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5, |
|
240 |
_map3_hi[tile] & 0xF, /* map3_lo */ |
|
241 |
c /* map5 */ |
|
242 |
); |
|
243 |
} |
|
244 |
return cost; |
|
245 |
} else |
|
246 |
goto return_error; |
|
247 |
||
248 |
} else { |
|
249 |
return_error:; |
|
250 |
return_cmd_error(INVALID_STRING_ID); |
|
251 |
} |
|
252 |
} |
|
253 |
||
254 |
||
255 |
enum { |
|
256 |
ROAD_NW = 1, // NW road track |
|
257 |
ROAD_SW = 2, // SW road track |
|
258 |
ROAD_SE = 4, // SE road track |
|
259 |
ROAD_NE = 8, // NE road track |
|
260 |
ROAD_ALL = (ROAD_NW | ROAD_SW | ROAD_SE | ROAD_NE) |
|
261 |
}; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
262 |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
263 |
static const byte _valid_tileh_slopes_road[3][15] = { |
0 | 264 |
// set of normal ones |
265 |
{ |
|
266 |
ROAD_ALL, 0, 0, |
|
267 |
ROAD_SW | ROAD_NE, 0, 0, // 3, 4, 5 |
|
268 |
ROAD_NW | ROAD_SE, 0, 0, |
|
269 |
ROAD_NW | ROAD_SE, 0, 0, // 9, 10, 11 |
|
270 |
ROAD_SW | ROAD_NE, 0, 0 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
271 |
}, |
0 | 272 |
// allowed road for an evenly raised platform |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
273 |
{ |
0 | 274 |
0, |
275 |
ROAD_SW | ROAD_NW, |
|
276 |
ROAD_SW | ROAD_SE, |
|
277 |
ROAD_NW | ROAD_SE | ROAD_SW, |
|
278 |
||
279 |
ROAD_SE | ROAD_NE, // 4 |
|
280 |
ROAD_ALL, |
|
281 |
ROAD_SW | ROAD_NE | ROAD_SE, |
|
282 |
ROAD_ALL, |
|
283 |
||
284 |
ROAD_NW | ROAD_NE, // 8 |
|
285 |
ROAD_SW | ROAD_NE | ROAD_NW, |
|
286 |
ROAD_ALL, |
|
287 |
ROAD_ALL, |
|
288 |
||
289 |
ROAD_NW | ROAD_SE | ROAD_NE, // 12 |
|
290 |
ROAD_ALL, |
|
291 |
ROAD_ALL |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
292 |
}, |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
293 |
// valid railway crossings on slopes |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
294 |
{ |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
295 |
1, 0, 0, // 0, 1, 2 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
296 |
0, 0, 1, // 3, 4, 5 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
297 |
0, 1, 0, // 6, 7, 8 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
298 |
0, 1, 1, // 9, 10, 11 |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
299 |
0, 1, 1, // 12, 13, 14 |
0 | 300 |
} |
301 |
}; |
|
302 |
||
303 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
304 |
static uint32 CheckRoadSlope(int tileh, byte *pieces, byte existing) |
0 | 305 |
{ |
306 |
if (!(tileh & 0x10)) { |
|
307 |
byte road_bits = *pieces | existing; |
|
308 |
||
309 |
// no special foundation |
|
310 |
if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) { |
|
311 |
// force that all bits are set when we have slopes |
|
312 |
if (tileh != 0) *pieces |= _valid_tileh_slopes_road[0][tileh]; |
|
313 |
return 0; // no extra cost |
|
314 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
315 |
|
0 | 316 |
// foundation is used. Whole tile is leveled up |
317 |
if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
318 |
return existing ? 0 : _price.terraform; |
0 | 319 |
} |
320 |
||
321 |
// partly leveled up tile, only if there's no road on that tile |
|
322 |
if ( !existing && (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8) ) { |
|
323 |
// force full pieces. |
|
324 |
*pieces |= (*pieces & 0xC) >> 2; |
|
325 |
*pieces |= (*pieces & 0x3) << 2; |
|
72
24bdf837198c
(svn r73) -Fix: Wrong building of road-slopes for a future AI/Town
darkvater
parents:
39
diff
changeset
|
326 |
return (*pieces == (ROAD_NE|ROAD_SW) || *pieces == (ROAD_SE|ROAD_NW)) ? _price.terraform : CMD_ERROR; |
0 | 327 |
} |
328 |
} |
|
329 |
return CMD_ERROR; |
|
330 |
} |
|
331 |
||
332 |
/* Build a piece of road |
|
333 |
* p1 = piece flags |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
334 |
* p2 = town which is building the road |
0 | 335 |
*/ |
336 |
||
337 |
int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
338 |
{ |
|
339 |
TileInfo ti; |
|
340 |
int32 cost; |
|
341 |
byte pieces = (byte)p1, existing = 0; |
|
342 |
uint tile; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
343 |
|
0 | 344 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
345 |
||
346 |
FindLandscapeHeight(&ti, x, y); |
|
347 |
tile = ti.tile; |
|
348 |
||
349 |
// allow building road under bridge |
|
350 |
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) |
|
351 |
return CMD_ERROR; |
|
352 |
||
353 |
if (ti.type == MP_STREET) { |
|
354 |
if (!(ti.map5 & 0xF0)) { |
|
355 |
if ( ((pieces) & (byte)(ti.map5)) == (pieces)) |
|
356 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
357 |
existing = ti.map5; |
|
358 |
} else { |
|
359 |
if (!(ti.map5 & 0xE0) && pieces != ((ti.map5 & 8) ? 5 : 10)) |
|
360 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
361 |
goto do_clear; |
|
362 |
} |
|
363 |
} else if (ti.type == MP_RAILWAY) { |
|
364 |
byte m5; |
|
365 |
||
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
366 |
if (ti.tileh & 0x10) // very steep tile |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
367 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
368 |
|
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
369 |
if(!_valid_tileh_slopes_road[2][ti.tileh]) // prevent certain slopes |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
370 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
371 |
|
0 | 372 |
if (ti.map5 == 2) { |
373 |
if (pieces & 5) goto do_clear; |
|
374 |
m5 = 0x10; |
|
375 |
} else if (ti.map5 == 1) { |
|
376 |
if (pieces & 10) goto do_clear; |
|
377 |
m5 = 0x18; |
|
378 |
} else |
|
379 |
goto do_clear; |
|
380 |
||
381 |
if (flags & DC_EXEC) { |
|
382 |
ModifyTile(tile, |
|
383 |
MP_SETTYPE(MP_STREET) | |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
384 |
MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5, |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
385 |
p2, |
0 | 386 |
_current_player, /* map3_lo */ |
387 |
_map3_lo[tile] & 0xF, /* map3_hi */ |
|
388 |
m5 /* map5 */ |
|
389 |
); |
|
390 |
} |
|
391 |
return _price.build_road * 2; |
|
392 |
} else if (ti.type == MP_TUNNELBRIDGE) { |
|
393 |
||
394 |
/* check for flat land */ |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
395 |
if (ti.tileh & 0x10) // very steep tile |
0 | 396 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
397 |
||
398 |
/* is this middle part of a bridge? */ |
|
399 |
if ((ti.map5 & 0xC0) != 0xC0) |
|
400 |
goto do_clear; |
|
401 |
||
402 |
/* only allow roads pertendicular to bridge */ |
|
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
403 |
if ((pieces & 5U) == (ti.map5 & 0x01U)) |
0 | 404 |
goto do_clear; |
405 |
||
406 |
/* check if clear land under bridge */ |
|
407 |
if ((ti.map5 & 0xF8) == 0xE8) /* road under bridge */ |
|
408 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
409 |
else if ((ti.map5 & 0xE0) == 0xE0) /* other transport route under bridge */ |
|
410 |
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
|
411 |
else if ((ti.map5 & 0xF8) == 0xC8) /* water under bridge */ |
|
412 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
|
413 |
||
414 |
/* all checked, can build road now! */ |
|
415 |
cost = _price.build_road * 2; |
|
416 |
if (flags & DC_EXEC) { |
|
417 |
ModifyTile(tile, |
|
418 |
MP_MAPOWNER_CURRENT | MP_MAP5, |
|
419 |
(ti.map5 & 0xC7) | 0x28 // map5 |
|
420 |
); |
|
421 |
} |
|
422 |
return cost; |
|
423 |
} else { |
|
424 |
do_clear:; |
|
425 |
if (DoCommandByTile(tile, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR) == CMD_ERROR) |
|
426 |
return CMD_ERROR; |
|
427 |
} |
|
428 |
||
429 |
cost = CheckRoadSlope(ti.tileh, &pieces, existing); |
|
430 |
if (cost == CMD_ERROR) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
431 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
432 |
if (cost && (!_patches.build_on_slopes || (!_patches.ainew_active && _is_ai_player))) |
0 | 433 |
return CMD_ERROR; |
434 |
||
435 |
if (!(ti.type == MP_STREET && (ti.map5 & 0xF0) == 0)) { |
|
436 |
cost += DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
437 |
} else { |
|
438 |
// Don't put the pieces that already exist |
|
439 |
pieces &= ~ti.map5; |
|
440 |
} |
|
441 |
||
442 |
{ |
|
443 |
byte t = pieces; |
|
444 |
while (t) { |
|
445 |
if (t & 1) cost += _price.build_road; |
|
446 |
t >>= 1; |
|
447 |
} |
|
448 |
} |
|
449 |
||
450 |
if (flags & DC_EXEC) { |
|
451 |
if (ti.type != MP_STREET) { |
|
1059
fe97d81a1b4f
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1041
diff
changeset
|
452 |
SetTileType(tile, MP_STREET); |
0 | 453 |
_map5[tile] = 0; |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
454 |
_map2[tile] = p2; |
0 | 455 |
_map_owner[tile] = _current_player; |
456 |
} |
|
457 |
||
458 |
_map5[tile] |= (byte)pieces; |
|
459 |
||
460 |
MarkTileDirtyByTile(tile); |
|
461 |
} |
|
462 |
return cost; |
|
463 |
} |
|
464 |
||
465 |
int32 DoConvertStreetRail(uint tile, uint totype, bool exec) |
|
466 |
{ |
|
467 |
// not a railroad crossing? |
|
468 |
if ((_map5[tile] & 0xF0) != 0x10) return CMD_ERROR; |
|
469 |
||
470 |
// not owned by me? |
|
471 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
|
472 |
||
473 |
// tile is already of requested type? |
|
474 |
if ( (uint)(_map3_hi[tile] & 0xF) == totype) return CMD_ERROR; |
|
475 |
||
476 |
if (exec) { |
|
477 |
// change type. |
|
478 |
_map3_hi[tile] = (_map3_hi[tile] & 0xF0) + totype; |
|
479 |
MarkTileDirtyByTile(tile); |
|
480 |
} |
|
481 |
||
482 |
return _price.build_rail >> 1; |
|
483 |
} |
|
484 |
||
485 |
||
486 |
// Build a long piece of road. |
|
487 |
// x,y = end tile |
|
488 |
// p1 = start tile |
|
489 |
// p2&1 = start tile starts in the 2nd half |
|
490 |
// p2&2 = end tile starts in the 2nd half |
|
491 |
// p2&4 = direction (0 = along x, 1=along y) |
|
492 |
int32 CmdBuildLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
493 |
{ |
|
494 |
uint start_tile, end_tile, tile; |
|
495 |
int mode; |
|
496 |
int32 cost,ret; |
|
497 |
||
889
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
498 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
499 |
|
0 | 500 |
start_tile = p1; |
501 |
end_tile = TILE_FROM_XY(x, y); |
|
502 |
||
503 |
if (start_tile > end_tile || (start_tile == end_tile && (p2&1))) { |
|
504 |
uint t = start_tile; start_tile = end_tile; end_tile = t; |
|
505 |
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0; |
|
506 |
} |
|
507 |
||
508 |
cost = 0; |
|
509 |
tile = start_tile; |
|
510 |
// Start tile is the small number. |
|
511 |
for(;;) { |
|
512 |
mode = (p2&4) ? 5 : 10; |
|
513 |
||
514 |
if (tile == start_tile && (p2&1)) |
|
515 |
mode &= (4+2); |
|
516 |
else if (tile == end_tile && !(p2&2)) |
|
517 |
mode &= (1+8); |
|
518 |
||
519 |
ret = DoCommandByTile(tile, mode, 0, flags, CMD_BUILD_ROAD); |
|
520 |
if (ret == CMD_ERROR) { |
|
521 |
if (_error_message != STR_1007_ALREADY_BUILT) |
|
522 |
return CMD_ERROR; |
|
523 |
} else { |
|
524 |
cost += ret; |
|
525 |
} |
|
526 |
||
527 |
if (tile == end_tile) |
|
528 |
break; |
|
529 |
||
530 |
tile += (p2&4)?TILE_XY(0,1):TILE_XY(1,0); |
|
531 |
} |
|
532 |
||
533 |
// already built? |
|
534 |
if (cost == 0) |
|
535 |
return CMD_ERROR; |
|
536 |
||
537 |
return cost; |
|
538 |
} |
|
539 |
||
540 |
// Remove a long piece of road. |
|
541 |
// x,y = end tile |
|
542 |
// p1 = start tile |
|
543 |
// p2&1 = start tile starts in the 2nd half |
|
544 |
// p2&2 = end tile starts in the 2nd half |
|
545 |
// p2&4 = direction (0 = along x, 1=along y) |
|
546 |
int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
547 |
{ |
|
548 |
uint start_tile, end_tile, tile; |
|
549 |
int32 cost,ret; |
|
550 |
||
889
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
551 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
64d2f7d5f02b
(svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents:
817
diff
changeset
|
552 |
|
0 | 553 |
start_tile = p1; |
554 |
end_tile = TILE_FROM_XY(x, y); |
|
555 |
||
556 |
if (start_tile > end_tile || (start_tile == end_tile && (p2&1))) { |
|
557 |
uint t = start_tile; start_tile = end_tile; end_tile = t; |
|
558 |
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0; |
|
559 |
} |
|
560 |
||
561 |
cost = 0; |
|
562 |
tile = start_tile; |
|
563 |
// Start tile is the small number. |
|
564 |
for(;;) { |
|
565 |
uint bits = (p2 & 4) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE; |
|
566 |
if (tile == end_tile && !(p2&2)) bits &= ROAD_NW | ROAD_NE; |
|
567 |
if (tile == start_tile && (p2&1)) bits &= ROAD_SE | ROAD_SW; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
568 |
|
0 | 569 |
// try to remove the halves. |
570 |
if (bits) { |
|
571 |
ret = DoCommandByTile(tile, bits, 0, flags, CMD_REMOVE_ROAD); |
|
572 |
if (ret != CMD_ERROR) |
|
573 |
cost += ret; |
|
574 |
} |
|
575 |
||
576 |
if (tile == end_tile) |
|
577 |
break; |
|
578 |
||
579 |
tile += (p2&4)?TILE_XY(0,1):TILE_XY(1,0); |
|
580 |
} |
|
581 |
||
582 |
// already built? |
|
583 |
if (cost == 0) |
|
584 |
return CMD_ERROR; |
|
585 |
||
586 |
return cost; |
|
587 |
} |
|
588 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
589 |
/* Build a road depot |
0 | 590 |
* p1 - direction (0-3) |
591 |
* p2 - unused |
|
592 |
*/ |
|
593 |
||
594 |
int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
595 |
{ |
|
596 |
TileInfo ti; |
|
597 |
int32 cost; |
|
598 |
Depot *dep; |
|
599 |
uint tile; |
|
600 |
||
601 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
602 |
||
603 |
FindLandscapeHeight(&ti, x, y); |
|
604 |
||
605 |
tile = ti.tile; |
|
606 |
||
607 |
if (!EnsureNoVehicle(tile)) |
|
608 |
return CMD_ERROR; |
|
609 |
||
610 |
if (ti.tileh != 0) { |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
611 |
if (!_patches.build_on_slopes || (ti.tileh & 0x10 || !((0x4C >> p1) & ti.tileh) )) |
0 | 612 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
613 |
} |
|
614 |
||
615 |
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
616 |
if (cost == CMD_ERROR) |
|
617 |
return CMD_ERROR; |
|
618 |
||
619 |
dep = AllocateDepot(); |
|
620 |
if (dep == NULL) |
|
621 |
return CMD_ERROR; |
|
622 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
623 |
if (flags & DC_EXEC) { |
0 | 624 |
if (_current_player == _local_player) |
625 |
_last_built_road_depot_tile = (TileIndex)tile; |
|
626 |
||
627 |
dep->xy = tile; |
|
628 |
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
|
629 |
||
630 |
ModifyTile(tile, |
|
631 |
MP_SETTYPE(MP_STREET) | |
|
632 |
MP_MAPOWNER_CURRENT | MP_MAP5, |
|
633 |
(p1 | 0x20) /* map5 */ |
|
634 |
); |
|
635 |
||
636 |
} |
|
637 |
return cost + _price.build_road_depot; |
|
638 |
} |
|
639 |
||
640 |
static int32 RemoveRoadDepot(uint tile, uint32 flags) |
|
641 |
{ |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
84
diff
changeset
|
642 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) |
0 | 643 |
return CMD_ERROR; |
644 |
||
645 |
if (!EnsureNoVehicle(tile)) |
|
646 |
return CMD_ERROR; |
|
647 |
||
648 |
if (flags & DC_EXEC) { |
|
649 |
DoDeleteDepot(tile); |
|
650 |
} |
|
651 |
||
652 |
return _price.remove_road_depot; |
|
653 |
} |
|
654 |
||
655 |
#define M(x) (1<<(x)) |
|
656 |
||
657 |
static int32 ClearTile_Road(uint tile, byte flags) { |
|
658 |
int32 ret; |
|
659 |
byte m5 = _map5[tile]; |
|
660 |
||
661 |
if ( (m5 & 0xF0) == 0) { |
|
662 |
byte b = m5 & 0xF; |
|
663 |
||
664 |
if (! ((1 << b) & (M(1)|M(2)|M(4)|M(8))) ) { |
|
665 |
if ( (!(flags & DC_AI_BUILDING) || _map_owner[tile]!=OWNER_TOWN) && flags&DC_AUTO) |
|
666 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
|
667 |
} |
|
668 |
return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD); |
|
669 |
} else if ( (m5 & 0xE0) == 0) { |
|
670 |
if (flags & DC_AUTO) |
|
671 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
|
672 |
||
673 |
ret = DoCommandByTile(tile, (m5&8)?5:10, 0, flags, CMD_REMOVE_ROAD); |
|
674 |
if (ret == CMD_ERROR) |
|
675 |
return CMD_ERROR; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
676 |
|
0 | 677 |
if (flags & DC_EXEC) { |
678 |
DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
679 |
} |
0 | 680 |
|
681 |
return ret; |
|
682 |
} else { |
|
683 |
if (flags & DC_AUTO) |
|
684 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
685 |
return RemoveRoadDepot(tile,flags); |
|
686 |
} |
|
687 |
} |
|
688 |
||
689 |
||
690 |
typedef struct DrawRoadTileStruct { |
|
691 |
uint16 image; |
|
692 |
byte subcoord_x; |
|
693 |
byte subcoord_y; |
|
694 |
} DrawRoadTileStruct; |
|
695 |
||
696 |
typedef struct DrawRoadSeqStruct { |
|
697 |
uint32 image; |
|
698 |
byte subcoord_x; |
|
699 |
byte subcoord_y; |
|
700 |
byte width; |
|
701 |
byte height; |
|
702 |
} DrawRoadSeqStruct; |
|
703 |
||
704 |
#include "table/road_land.h" |
|
705 |
||
706 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
707 |
uint GetRoadFoundation(uint tileh, uint bits) { |
0 | 708 |
int i; |
709 |
// normal level sloped building |
|
710 |
if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) |
|
711 |
return tileh; |
|
712 |
||
713 |
// inclined sloped building |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
714 |
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && |
0 | 715 |
((bits == (ROAD_SW | ROAD_NE)) || (i++, bits == (ROAD_NW | ROAD_SE)))) |
716 |
return i + 15; |
|
717 |
||
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
718 |
// rail crossing |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
719 |
if ((bits & 0x10) && _valid_tileh_slopes_road[2][tileh]) |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
720 |
return tileh; |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
721 |
|
0 | 722 |
return 0; |
723 |
} |
|
724 |
||
725 |
const byte _road_sloped_sprites[14] = { |
|
726 |
0, 0, 2, 0, |
|
727 |
0, 1, 0, 0, |
|
728 |
3, 0, 0, 0, |
|
729 |
0, 0 |
|
730 |
}; |
|
731 |
||
732 |
static void DrawTile_Road(TileInfo *ti) |
|
733 |
{ |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
734 |
uint32 image; |
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
679
diff
changeset
|
735 |
uint16 m2; |
0 | 736 |
const byte *s; |
737 |
||
738 |
if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0 |
|
739 |
const DrawRoadTileStruct *drts; |
|
740 |
||
741 |
if (ti->tileh != 0) { |
|
742 |
int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF); |
|
743 |
if (f) DrawFoundation(ti, f); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
744 |
|
0 | 745 |
// default sloped sprites.. |
746 |
if (ti->tileh != 0) { |
|
747 |
image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
|
748 |
} else { |
|
749 |
image = _road_tile_sprites_1[ti->map5 & 0xF]; |
|
750 |
} |
|
751 |
} else { |
|
752 |
image = _road_tile_sprites_1[ti->map5 & 0xF]; |
|
753 |
} |
|
754 |
||
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
755 |
m2 = (_map3_hi[ti->tile] & 0x70) >> 4; |
0 | 756 |
|
757 |
if (m2 == 0) image |= 0x3178000; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
758 |
|
0 | 759 |
if (_map3_hi[ti->tile] & 0x80) { |
760 |
image += 19; |
|
761 |
} else if (m2 > 1 && m2 != 6) { |
|
762 |
image -= 19; /* pavement along the road? */ |
|
763 |
} |
|
764 |
||
765 |
DrawGroundSprite(image); |
|
766 |
||
767 |
if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2) |
|
768 |
return; |
|
769 |
||
770 |
if (m2 >= 6) { |
|
771 |
// roadwork |
|
772 |
DrawGroundSprite(0x586 + ((ti->map5&8)!=0 ? 0 : 1)); |
|
773 |
return; |
|
774 |
} |
|
775 |
||
776 |
drts = (const DrawRoadTileStruct*)_road_display_table[m2][ti->map5 & 0xF]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
777 |
|
0 | 778 |
while ((image = drts->image) != 0) { |
779 |
int x = ti->x | drts->subcoord_x; |
|
780 |
int y = ti->y | drts->subcoord_y; |
|
781 |
byte z = ti->z; |
|
782 |
if (ti->tileh != 0) z = GetSlopeZ(x, y); |
|
783 |
AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z); |
|
784 |
drts++; |
|
785 |
} |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
786 |
} else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
787 |
int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
788 |
if (f) DrawFoundation(ti, f); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
789 |
|
0 | 790 |
image = 0x55B; |
791 |
||
792 |
if ( (ti->map5 & 8) != 0) |
|
793 |
image--; |
|
794 |
||
795 |
if ( (ti->map5 & 4) != 0) |
|
796 |
image += 2; |
|
797 |
||
798 |
if ( _map3_hi[ti->tile] & 0x80) { |
|
799 |
image += 8; |
|
800 |
} else { |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
801 |
m2 = (_map3_hi[ti->tile] & 0x70) >> 4; |
0 | 802 |
if (m2 == 0) image |= 0x3178000; |
803 |
if (m2 > 1) image += 4; |
|
804 |
} |
|
805 |
||
806 |
DrawGroundSprite(image + (_map3_hi[ti->tile] & 0xF) * 12); |
|
807 |
} else { |
|
808 |
uint32 ormod; |
|
809 |
int player; |
|
810 |
const DrawRoadSeqStruct *drss; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
811 |
|
0 | 812 |
if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); } |
813 |
||
814 |
ormod = 0x315; |
|
815 |
player = _map_owner[ti->tile]; |
|
816 |
if (player < MAX_PLAYERS) |
|
817 |
ormod = PLAYER_SPRITE_COLOR(player); |
|
818 |
||
819 |
s = _road_display_datas[ti->map5 & 0xF]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
820 |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
204
diff
changeset
|
821 |
DrawGroundSprite(*(const uint32*)s); |
0 | 822 |
s += sizeof(uint32); |
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
204
diff
changeset
|
823 |
drss = (const DrawRoadSeqStruct*)s; |
0 | 824 |
|
825 |
while ((image=drss->image) != 0) { |
|
826 |
if (image & 0x8000) |
|
827 |
image |= ormod; |
|
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
|
828 |
if (_display_opt & DO_TRANS_BUILDINGS) // show transparent depots |
204
1646d7049950
(svn r205) -Fix: [1026271] Vehicle depots not transparent with transparent buildings.
darkvater
parents:
201
diff
changeset
|
829 |
image = (image & 0x3FFF) | 0x3224000; |
0 | 830 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
831 |
AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x, |
0 | 832 |
ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z); |
833 |
drss++; |
|
834 |
} |
|
835 |
} |
|
836 |
} |
|
837 |
||
838 |
void DrawRoadDepotSprite(int x, int y, int image) |
|
839 |
{ |
|
840 |
uint32 ormod; |
|
841 |
const DrawRoadSeqStruct *dtss; |
|
842 |
const byte *t; |
|
843 |
||
844 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
845 |
||
846 |
t = _road_display_datas[image]; |
|
847 |
||
848 |
x+=33; |
|
849 |
y+=17; |
|
850 |
||
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
204
diff
changeset
|
851 |
DrawSprite(*(const uint32*)t, x, y); |
0 | 852 |
t += sizeof(uint32); |
853 |
||
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
204
diff
changeset
|
854 |
for(dtss = (const DrawRoadSeqStruct *)t; dtss->image != 0; dtss++) { |
0 | 855 |
Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
856 |
|
0 | 857 |
image = dtss->image; |
858 |
if (image & 0x8000) |
|
859 |
image |= ormod; |
|
860 |
||
861 |
DrawSprite(image, x + pt.x, y + pt.y); |
|
862 |
} |
|
863 |
} |
|
864 |
||
410 | 865 |
static uint GetSlopeZ_Road(TileInfo *ti) |
0 | 866 |
{ |
867 |
uint z = ti->z; |
|
868 |
int th = ti->tileh; |
|
869 |
||
870 |
// check if it's a foundation |
|
871 |
if (ti->tileh != 0) { |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
872 |
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
0 | 873 |
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
874 |
if (f != 0) { |
|
875 |
if (f < 15) { |
|
876 |
// leveled foundation |
|
877 |
return z + 8; |
|
878 |
} |
|
879 |
// inclined foundation |
|
880 |
th = _inclined_tileh[f - 15]; |
|
881 |
} |
|
882 |
} else if ((ti->map5 & 0xF0) == 0x20) { |
|
883 |
// depot |
|
884 |
return z + 8; |
|
885 |
} |
|
886 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z; |
|
887 |
} |
|
39 | 888 |
return z; // normal Z if no slope |
889 |
} |
|
890 |
||
1095 | 891 |
static uint GetSlopeTileh_Road(TileInfo *ti) |
39 | 892 |
{ |
893 |
// check if it's a foundation |
|
894 |
if (ti->tileh != 0) { |
|
895 |
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
|
896 |
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
|
897 |
if (f != 0) { |
|
898 |
if (f < 15) { |
|
899 |
// leveled foundation |
|
900 |
return 0; |
|
901 |
} |
|
902 |
// inclined foundation |
|
903 |
return _inclined_tileh[f - 15]; |
|
904 |
} |
|
905 |
} else if ((ti->map5 & 0xF0) == 0x20) { |
|
906 |
// depot |
|
907 |
return 0; |
|
908 |
} |
|
909 |
} |
|
910 |
return ti->tileh; |
|
0 | 911 |
} |
912 |
||
473
77f0ef57e7cf
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
913 |
static void GetAcceptedCargo_Road(uint tile, AcceptedCargo ac) |
0 | 914 |
{ |
915 |
/* not used */ |
|
916 |
} |
|
917 |
||
918 |
static void AnimateTile_Road(uint tile) |
|
919 |
{ |
|
920 |
if ((_map5[tile] & 0xF0) == 0x10) { |
|
921 |
MarkTileDirtyByTile(tile); |
|
922 |
} |
|
923 |
} |
|
924 |
||
925 |
static const byte _town_road_types[5][2] = { |
|
926 |
{1,1}, |
|
927 |
{2,2}, |
|
928 |
{2,2}, |
|
929 |
{5,5}, |
|
930 |
{3,2}, |
|
931 |
}; |
|
932 |
||
933 |
static const byte _town_road_types_2[5][2] = { |
|
934 |
{1,1}, |
|
935 |
{2,2}, |
|
936 |
{3,2}, |
|
937 |
{3,2}, |
|
938 |
{3,2}, |
|
939 |
}; |
|
940 |
||
941 |
||
942 |
static void TileLoop_Road(uint tile) |
|
943 |
{ |
|
944 |
Town *t; |
|
945 |
int grp; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
946 |
|
0 | 947 |
if (_opt.landscape == LT_HILLY) { |
948 |
// Fix snow style if the road is above the snowline |
|
949 |
if ((_map3_hi[tile] & 0x80) != ((GetTileZ(tile) > _opt.snow_line) ? 0x80 : 0x00)) { |
|
950 |
_map3_hi[tile] ^= 0x80; |
|
951 |
MarkTileDirtyByTile(tile); |
|
952 |
} |
|
953 |
} else if (_opt.landscape == LT_DESERT) { |
|
954 |
// Fix desert style |
|
955 |
if (GetMapExtraBits(tile) == 1 && !(_map3_hi[tile] & 0x80)) { |
|
956 |
_map3_hi[tile] |= 0x80; |
|
957 |
MarkTileDirtyByTile(tile); |
|
958 |
} |
|
959 |
} |
|
960 |
||
961 |
if (_map5[tile] & 0xE0) |
|
962 |
return; |
|
963 |
||
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
964 |
if (((_map3_hi[tile] & 0x70) >> 4) < 6) { |
1281
dd226de69402
(svn r1785) -Fix: space-correctness in road_cmd.c, and one wrong line from last
truelight
parents:
1280
diff
changeset
|
965 |
t = ClosestTownFromTile(tile, (uint)-1); |
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
966 |
|
0 | 967 |
grp = 0; |
968 |
if (t != NULL) { |
|
969 |
grp = GetTownRadiusGroup(t, tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
970 |
|
0 | 971 |
// Show an animation to indicate road work |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
972 |
if (t->road_build_months != 0 && |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1214
diff
changeset
|
973 |
!(DistanceManhattan(t->xy, tile) >= 8 && grp == 0) && |
0 | 974 |
(_map5[tile]==5 || _map5[tile]==10)) { |
975 |
if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1,20)) { |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
976 |
_map3_hi[tile] |= ((((_map3_hi[tile] & 0x70) >> 4 ) <= 2) ? 7 : 6) << 4; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
977 |
|
541 | 978 |
SndPlayTileFx(SND_21_JACKHAMMER, tile); |
0 | 979 |
CreateEffectVehicleAbove( |
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:
889
diff
changeset
|
980 |
TileX(tile) * 16 + 7, |
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:
889
diff
changeset
|
981 |
TileY(tile) * 16 + 7, |
0 | 982 |
0, |
983 |
EV_ROADWORK); |
|
984 |
MarkTileDirtyByTile(tile); |
|
985 |
return; |
|
986 |
} |
|
987 |
} |
|
988 |
} |
|
989 |
||
990 |
{ |
|
991 |
const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp]; |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
992 |
byte b = (_map3_hi[tile] & 0x70) >> 4; |
0 | 993 |
|
994 |
if (b == p[0]) |
|
995 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
996 |
|
0 | 997 |
if (b == p[1]) { |
998 |
b = p[0]; |
|
999 |
} else if (b == 0) { |
|
1000 |
b = p[1]; |
|
1001 |
} else { |
|
1002 |
b = 0; |
|
1003 |
} |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1004 |
_map3_hi[tile] = (_map3_hi[tile] & ~0x70) | (b << 4); |
0 | 1005 |
MarkTileDirtyByTile(tile); |
1006 |
} |
|
1007 |
} else { |
|
1008 |
// Handle road work |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1009 |
//XXX undocumented |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1010 |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1011 |
byte b = _map3_hi[tile]; |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1012 |
//roadworks take place only |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1013 |
//keep roadworks running for 16 loops |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1014 |
//lower 4 bits of map3_hi store the counter now |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1015 |
if ((b & 0xF) != 0xF) { |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1016 |
_map3_hi[tile] = b + 1; |
0 | 1017 |
return; |
1018 |
} |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1019 |
//roadworks finished |
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1020 |
_map3_hi[tile] = ((((b& 0x70) >> 4)== 6) ? 1 : 2) << 4; |
0 | 1021 |
MarkTileDirtyByTile(tile); |
1022 |
} |
|
1023 |
} |
|
1024 |
||
1025 |
void ShowRoadDepotWindow(uint tile); |
|
1026 |
||
1027 |
static void ClickTile_Road(uint tile) |
|
1028 |
{ |
|
1029 |
if ((_map5[tile] & 0xF0) == 0x20) { |
|
1030 |
ShowRoadDepotWindow(tile); |
|
1031 |
} |
|
1032 |
} |
|
1033 |
||
1034 |
static const byte _road_trackbits[16] = { |
|
1035 |
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F, |
|
1036 |
}; |
|
1037 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1038 |
static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1039 |
if (mode == TRANSPORT_RAIL) { |
0 | 1040 |
if ((_map5[tile] & 0xF0) != 0x10) |
1041 |
return 0; |
|
1042 |
return _map5[tile] & 8 ? 0x101 : 0x202; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1043 |
} else if (mode == TRANSPORT_ROAD) { |
0 | 1044 |
byte b = _map5[tile]; |
1045 |
if ((b & 0xF0) == 0) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1046 |
/* Ordinary road */ |
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1047 |
if (!_road_special_gettrackstatus && ((_map3_hi[tile]&0x70) >> 4) >= 6) |
0 | 1048 |
return 0; |
1049 |
return _road_trackbits[b&0xF] * 0x101; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1050 |
} else if ((b&0xF0) == 0x10) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1051 |
/* Crossing */ |
0 | 1052 |
uint32 r = 0x101; |
1053 |
if (b&8) r <<= 1; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1054 |
|
0 | 1055 |
if (b&4) { |
1056 |
r *= 0x10001; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1057 |
} |
0 | 1058 |
return r; |
1059 |
} |
|
1060 |
} |
|
1061 |
return 0; |
|
1062 |
} |
|
1063 |
||
1064 |
static const StringID _road_tile_strings[] = { |
|
1065 |
STR_1818_ROAD_RAIL_LEVEL_CROSSING, |
|
1066 |
STR_1817_ROAD_VEHICLE_DEPOT, |
|
1067 |
||
1068 |
STR_1814_ROAD, |
|
1069 |
STR_1814_ROAD, |
|
1070 |
STR_1814_ROAD, |
|
1071 |
STR_1815_ROAD_WITH_STREETLIGHTS, |
|
1072 |
STR_1814_ROAD, |
|
1073 |
STR_1816_TREE_LINED_ROAD, |
|
1074 |
STR_1814_ROAD, |
|
1075 |
STR_1814_ROAD, |
|
1076 |
}; |
|
1077 |
||
1078 |
static void GetTileDesc_Road(uint tile, TileDesc *td) |
|
1079 |
{ |
|
1080 |
int i = (_map5[tile] >> 4); |
|
1081 |
if (i == 0) |
|
1264
acebb2b01e32
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1247
diff
changeset
|
1082 |
i = ((_map3_hi[tile] & 0x70) >> 4) + 3; |
0 | 1083 |
td->str = _road_tile_strings[i - 1]; |
1084 |
td->owner = _map_owner[tile]; |
|
1085 |
} |
|
1086 |
||
1087 |
static const byte _roadveh_enter_depot_unk0[4] = { |
|
1088 |
8, 9, 0, 1 |
|
1089 |
}; |
|
1090 |
||
1091 |
static uint32 VehicleEnter_Road(Vehicle *v, uint tile, int x, int y) |
|
1092 |
{ |
|
1093 |
if ((_map5[tile] & 0xF0) == 0x10) { |
|
1094 |
if (v->type == VEH_Train && (_map5[tile] & 4) == 0) { |
|
1095 |
/* train crossing a road */ |
|
541 | 1096 |
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |
0 | 1097 |
_map5[tile] |= 4; |
1098 |
MarkTileDirtyByTile(tile); |
|
1099 |
} |
|
1100 |
} else if ((_map5[tile]&0xF0) == 0x20){ |
|
1101 |
if (v->type == VEH_Road && v->u.road.frame == 11) { |
|
1102 |
if (_roadveh_enter_depot_unk0[_map5[tile]&3] == v->u.road.state) { |
|
1103 |
RoadVehEnterDepot(v); |
|
1104 |
return 4; |
|
1105 |
} |
|
1106 |
} |
|
1107 |
} |
|
1108 |
return 0; |
|
1109 |
} |
|
1110 |
||
1111 |
static void VehicleLeave_Road(Vehicle *v, uint tile, int x, int y) |
|
1112 |
{ |
|
1113 |
if ((_map5[tile] & 0xF0) == 0x10 && v->type == VEH_Train && v->next == NULL) { |
|
1114 |
_map5[tile] &= ~4; |
|
1115 |
MarkTileDirtyByTile(tile); |
|
1116 |
} |
|
1117 |
} |
|
1118 |
||
1119 |
static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player) |
|
1120 |
{ |
|
1121 |
byte b; |
|
1122 |
||
1123 |
// road/rail crossing where the road is owned by the current player? |
|
1124 |
if (old_player == _map3_lo[tile] && (_map5[tile]&0xF0) == 0x10) { |
|
1125 |
_map3_lo[tile] = (new_player == 0xFF) ? OWNER_NONE : new_player; |
|
1126 |
} |
|
1127 |
||
1128 |
if (_map_owner[tile] != old_player) |
|
1129 |
return; |
|
1130 |
||
1131 |
if (new_player != 255) { |
|
1132 |
_map_owner[tile] = new_player; |
|
1133 |
} else { |
|
1134 |
b = _map5[tile]&0xF0; |
|
1135 |
if (b == 0) { |
|
1136 |
_map_owner[tile] = OWNER_NONE; |
|
1137 |
} else if (b == 0x10) { |
|
1138 |
_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA; |
|
1139 |
_map_owner[tile] = _map3_lo[tile]; |
|
1140 |
_map3_lo[tile] = 0; |
|
1141 |
_map3_hi[tile] &= 0x80; |
|
1142 |
} else { |
|
1143 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1144 |
} |
|
1145 |
} |
|
1146 |
} |
|
1147 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1148 |
void InitializeRoad(void) |
0 | 1149 |
{ |
1150 |
_last_built_road_depot_tile = 0; |
|
1151 |
} |
|
1152 |
||
1153 |
const TileTypeProcs _tile_type_road_procs = { |
|
1154 |
DrawTile_Road, /* draw_tile_proc */ |
|
1155 |
GetSlopeZ_Road, /* get_slope_z_proc */ |
|
1156 |
ClearTile_Road, /* clear_tile_proc */ |
|
1157 |
GetAcceptedCargo_Road, /* get_accepted_cargo_proc */ |
|
1158 |
GetTileDesc_Road, /* get_tile_desc_proc */ |
|
1159 |
GetTileTrackStatus_Road, /* get_tile_track_status_proc */ |
|
1160 |
ClickTile_Road, /* click_tile_proc */ |
|
1161 |
AnimateTile_Road, /* animate_tile_proc */ |
|
1162 |
TileLoop_Road, /* tile_loop_clear */ |
|
1163 |
ChangeTileOwner_Road, /* change_tile_owner_clear */ |
|
1164 |
NULL, /* get_produced_cargo_proc */ |
|
1165 |
VehicleEnter_Road, /* vehicle_enter_tile_proc */ |
|
1166 |
VehicleLeave_Road, /* vehicle_leave_tile_proc */ |
|
39 | 1167 |
GetSlopeTileh_Road, /* get_slope_tileh_proc */ |
0 | 1168 |
}; |