author | tron |
Thu, 02 Dec 2004 22:53:07 +0000 | |
changeset 534 | 17ab2f22ff74 |
parent 507 | 8aa8100b0b22 |
child 541 | e1cd34389f79 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
3 |
#include "table/strings.h" |
0 | 4 |
#include "vehicle.h" |
5 |
#include "viewport.h" |
|
6 |
#include "command.h" |
|
7 |
#include "player.h" |
|
8 |
#include "town.h" |
|
9 |
#include "gfx.h" |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
10 |
#include "table/directions.h" |
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
241
diff
changeset
|
11 |
#include "sound.h" |
0 | 12 |
|
22 | 13 |
/* When true, GetTrackStatus for roads will treat roads under reconstruction |
14 |
* as normal roads instead of impassable. This is used when detecting whether |
|
15 |
* a road can be removed. This is of course ugly, but I don't know a better |
|
16 |
* solution just like that... */ |
|
0 | 17 |
static bool _road_special_gettrackstatus; |
18 |
||
19 |
void RoadVehEnterDepot(Vehicle *v); |
|
20 |
||
21 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
22 |
bool HasTileRoadAt(uint tile, int i) |
0 | 23 |
{ |
24 |
int mask; |
|
25 |
byte b; |
|
26 |
||
27 |
switch(GET_TILETYPE(tile)) { |
|
28 |
case MP_STREET: |
|
29 |
b = _map5[tile]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
30 |
|
0 | 31 |
if ((b & 0xF0) == 0) { |
32 |
} else if ((b & 0xF0) == 0x10) { |
|
33 |
b = (b&8)?5:10; |
|
34 |
} else if ((b & 0xF0) == 0x20) { |
|
35 |
return (~b & 3) == i; |
|
36 |
} else |
|
37 |
return false; |
|
38 |
break; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
39 |
|
0 | 40 |
case MP_STATION: |
41 |
b = _map5[tile]; |
|
42 |
if (!IS_BYTE_INSIDE(b, 0x43, 0x43+8)) |
|
43 |
return false; |
|
44 |
return ((~(b - 0x43) & 3) == i); |
|
45 |
||
46 |
case MP_TUNNELBRIDGE: |
|
47 |
mask = GetRoadBitsByTile(tile); |
|
48 |
b = 10; if (mask & 1) break; |
|
49 |
b = 5; if (mask & 2) break; |
|
50 |
return false; |
|
51 |
||
52 |
default: |
|
53 |
return false; |
|
54 |
} |
|
55 |
||
56 |
return HASBIT(b, i); |
|
57 |
} |
|
58 |
||
59 |
static bool CheckAllowRemoveRoad(uint tile, uint br, bool *edge_road) |
|
60 |
{ |
|
61 |
int blocks; |
|
62 |
byte owner; |
|
63 |
uint n; |
|
64 |
*edge_road = true; |
|
65 |
||
66 |
if (_game_mode == GM_EDITOR) |
|
67 |
return true; |
|
68 |
||
69 |
blocks = GetRoadBitsByTile(tile); |
|
70 |
if (blocks == 0) |
|
71 |
return true; |
|
72 |
||
73 |
// Only do the special processing for actual players. |
|
74 |
if (_current_player >= MAX_PLAYERS) |
|
75 |
return true; |
|
76 |
||
77 |
// A railway crossing has the road owner in the map3_lo byte. |
|
78 |
if (IS_TILETYPE(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) { |
|
79 |
owner = _map3_lo[tile]; |
|
80 |
} else { |
|
81 |
owner = _map_owner[tile]; |
|
82 |
} |
|
83 |
// Only do the special processing if the road is owned |
|
84 |
// by a town |
|
85 |
if (owner != OWNER_TOWN) { |
|
86 |
return owner == OWNER_NONE || CheckOwnership(owner); |
|
87 |
} |
|
88 |
||
89 |
if (_cheats.magic_bulldozer.value) |
|
90 |
return true; |
|
91 |
||
92 |
// Get a bitmask of which neighbouring roads has a tile |
|
93 |
n = 0; |
|
94 |
if (blocks&0x25 && HasTileRoadAt(TILE_ADDXY(tile,-1, 0), 1)) n |= 8; |
|
95 |
if (blocks&0x2A && HasTileRoadAt(TILE_ADDXY(tile, 0, 1), 0)) n |= 4; |
|
96 |
if (blocks&0x19 && HasTileRoadAt(TILE_ADDXY(tile, 1, 0), 3)) n |= 2; |
|
97 |
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
|
98 |
|
0 | 99 |
// If 0 or 1 bits are set in n, or if no bits that match the bits to remove, |
100 |
// then allow it |
|
101 |
if ((n & (n-1)) != 0 && (n & br) != 0) { |
|
102 |
Town *t; |
|
103 |
*edge_road = false; |
|
104 |
// you can remove all kind of roads with extra dynamite |
|
105 |
if (_patches.extra_dynamite) |
|
106 |
return true; |
|
107 |
||
108 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
109 |
SetDParam(0, t->index); |
0 | 110 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
111 |
return false; |
|
112 |
} |
|
113 |
||
114 |
return true; |
|
115 |
} |
|
116 |
||
117 |
bool IsRoadDepotTile(TileIndex tile) |
|
118 |
{ |
|
119 |
return IS_TILETYPE(tile, MP_STREET) && |
|
120 |
(_map5[tile] & 0xF0) == 0x20; |
|
121 |
} |
|
122 |
||
123 |
uint GetRoadBitsByTile(TileIndex tile) |
|
124 |
{ |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
125 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
0 | 126 |
return (byte)(r | (r >> 8)); |
127 |
} |
|
128 |
||
129 |
// cost for removing inner/edge -roads |
|
130 |
static const uint16 _road_remove_cost[2] = {50, 18}; |
|
131 |
||
132 |
/* Delete a piece of road |
|
133 |
* p1 = piece type |
|
134 |
*/ |
|
135 |
int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
136 |
{ |
|
137 |
TileInfo ti; |
|
138 |
int32 cost; |
|
139 |
uint tile; |
|
140 |
Town *t; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
141 |
/* true if the roadpiece was always removeable, |
0 | 142 |
false if it was a center piece. Affects town ratings drop |
143 |
*/ |
|
144 |
bool edge_road; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
145 |
|
0 | 146 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
147 |
||
148 |
FindLandscapeHeight(&ti, x, y); |
|
149 |
tile = ti.tile; |
|
150 |
t = ClosestTownFromTile(tile, (uint)-1); // needed for town rating penalty |
|
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) { |
|
166 |
if (!EnsureNoVehicleZ(tile, GET_TILEHEIGHT(tile))) |
|
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 |
0 | 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 |
213 |
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
|
214 |
ChangeTownRating(t, -_road_remove_cost[(byte)edge_road], -100); |
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 |
|
334 |
*/ |
|
335 |
||
336 |
int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
337 |
{ |
|
338 |
TileInfo ti; |
|
339 |
int32 cost; |
|
340 |
byte pieces = (byte)p1, existing = 0; |
|
341 |
uint tile; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
342 |
|
0 | 343 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
344 |
||
345 |
FindLandscapeHeight(&ti, x, y); |
|
346 |
tile = ti.tile; |
|
347 |
||
348 |
// allow building road under bridge |
|
349 |
if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) |
|
350 |
return CMD_ERROR; |
|
351 |
||
352 |
if (ti.type == MP_STREET) { |
|
353 |
if (!(ti.map5 & 0xF0)) { |
|
354 |
if ( ((pieces) & (byte)(ti.map5)) == (pieces)) |
|
355 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
356 |
existing = ti.map5; |
|
357 |
} else { |
|
358 |
if (!(ti.map5 & 0xE0) && pieces != ((ti.map5 & 8) ? 5 : 10)) |
|
359 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
360 |
goto do_clear; |
|
361 |
} |
|
362 |
} else if (ti.type == MP_RAILWAY) { |
|
363 |
byte m5; |
|
364 |
||
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
365 |
if (ti.tileh & 0x10) // very steep tile |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
366 |
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
|
367 |
|
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
368 |
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
|
369 |
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
|
370 |
|
0 | 371 |
if (ti.map5 == 2) { |
372 |
if (pieces & 5) goto do_clear; |
|
373 |
m5 = 0x10; |
|
374 |
} else if (ti.map5 == 1) { |
|
375 |
if (pieces & 10) goto do_clear; |
|
376 |
m5 = 0x18; |
|
377 |
} else |
|
378 |
goto do_clear; |
|
379 |
||
380 |
if (flags & DC_EXEC) { |
|
381 |
ModifyTile(tile, |
|
382 |
MP_SETTYPE(MP_STREET) | |
|
383 |
MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI | MP_MAP5, |
|
384 |
_current_player, /* map3_lo */ |
|
385 |
_map3_lo[tile] & 0xF, /* map3_hi */ |
|
386 |
m5 /* map5 */ |
|
387 |
); |
|
388 |
} |
|
389 |
return _price.build_road * 2; |
|
390 |
} else if (ti.type == MP_TUNNELBRIDGE) { |
|
391 |
||
392 |
/* check for flat land */ |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
393 |
if (ti.tileh & 0x10) // very steep tile |
0 | 394 |
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
395 |
||
396 |
/* is this middle part of a bridge? */ |
|
397 |
if ((ti.map5 & 0xC0) != 0xC0) |
|
398 |
goto do_clear; |
|
399 |
||
400 |
/* only allow roads pertendicular to bridge */ |
|
401 |
if ((pieces & 5) == (ti.map5 & 0x01)) |
|
402 |
goto do_clear; |
|
403 |
||
404 |
/* check if clear land under bridge */ |
|
405 |
if ((ti.map5 & 0xF8) == 0xE8) /* road under bridge */ |
|
406 |
return_cmd_error(STR_1007_ALREADY_BUILT); |
|
407 |
else if ((ti.map5 & 0xE0) == 0xE0) /* other transport route under bridge */ |
|
408 |
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
|
409 |
else if ((ti.map5 & 0xF8) == 0xC8) /* water under bridge */ |
|
410 |
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
|
411 |
||
412 |
/* all checked, can build road now! */ |
|
413 |
cost = _price.build_road * 2; |
|
414 |
if (flags & DC_EXEC) { |
|
415 |
ModifyTile(tile, |
|
416 |
MP_MAPOWNER_CURRENT | MP_MAP5, |
|
417 |
(ti.map5 & 0xC7) | 0x28 // map5 |
|
418 |
); |
|
419 |
} |
|
420 |
return cost; |
|
421 |
} else { |
|
422 |
do_clear:; |
|
423 |
if (DoCommandByTile(tile, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR) == CMD_ERROR) |
|
424 |
return CMD_ERROR; |
|
425 |
} |
|
426 |
||
427 |
cost = CheckRoadSlope(ti.tileh, &pieces, existing); |
|
428 |
if (cost == CMD_ERROR) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
429 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
430 |
if (cost && (!_patches.build_on_slopes || (!_patches.ainew_active && _is_ai_player))) |
0 | 431 |
return CMD_ERROR; |
432 |
||
433 |
if (!(ti.type == MP_STREET && (ti.map5 & 0xF0) == 0)) { |
|
434 |
cost += DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
435 |
} else { |
|
436 |
// Don't put the pieces that already exist |
|
437 |
pieces &= ~ti.map5; |
|
438 |
} |
|
439 |
||
440 |
{ |
|
441 |
byte t = pieces; |
|
442 |
while (t) { |
|
443 |
if (t & 1) cost += _price.build_road; |
|
444 |
t >>= 1; |
|
445 |
} |
|
446 |
} |
|
447 |
||
448 |
if (flags & DC_EXEC) { |
|
449 |
if (ti.type != MP_STREET) { |
|
450 |
_map_type_and_height[tile] &= 0xF; |
|
451 |
_map_type_and_height[tile] |= MP_STREET << 4; |
|
452 |
_map5[tile] = 0; |
|
453 |
_map_owner[tile] = _current_player; |
|
454 |
} |
|
455 |
||
456 |
_map5[tile] |= (byte)pieces; |
|
457 |
||
458 |
MarkTileDirtyByTile(tile); |
|
459 |
} |
|
460 |
return cost; |
|
461 |
} |
|
462 |
||
463 |
int32 DoConvertStreetRail(uint tile, uint totype, bool exec) |
|
464 |
{ |
|
465 |
// not a railroad crossing? |
|
466 |
if ((_map5[tile] & 0xF0) != 0x10) return CMD_ERROR; |
|
467 |
||
468 |
// not owned by me? |
|
469 |
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; |
|
470 |
||
471 |
// tile is already of requested type? |
|
472 |
if ( (uint)(_map3_hi[tile] & 0xF) == totype) return CMD_ERROR; |
|
473 |
||
474 |
if (exec) { |
|
475 |
// change type. |
|
476 |
_map3_hi[tile] = (_map3_hi[tile] & 0xF0) + totype; |
|
477 |
MarkTileDirtyByTile(tile); |
|
478 |
} |
|
479 |
||
480 |
return _price.build_rail >> 1; |
|
481 |
} |
|
482 |
||
483 |
||
484 |
// Build a long piece of road. |
|
485 |
// x,y = end tile |
|
486 |
// p1 = start tile |
|
487 |
// p2&1 = start tile starts in the 2nd half |
|
488 |
// p2&2 = end tile starts in the 2nd half |
|
489 |
// p2&4 = direction (0 = along x, 1=along y) |
|
490 |
int32 CmdBuildLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
491 |
{ |
|
492 |
uint start_tile, end_tile, tile; |
|
493 |
int mode; |
|
494 |
int32 cost,ret; |
|
495 |
||
496 |
start_tile = p1; |
|
497 |
end_tile = TILE_FROM_XY(x, y); |
|
498 |
||
499 |
if (start_tile > end_tile || (start_tile == end_tile && (p2&1))) { |
|
500 |
uint t = start_tile; start_tile = end_tile; end_tile = t; |
|
501 |
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0; |
|
502 |
} |
|
503 |
||
504 |
cost = 0; |
|
505 |
tile = start_tile; |
|
506 |
// Start tile is the small number. |
|
507 |
for(;;) { |
|
508 |
mode = (p2&4) ? 5 : 10; |
|
509 |
||
510 |
if (tile == start_tile && (p2&1)) |
|
511 |
mode &= (4+2); |
|
512 |
else if (tile == end_tile && !(p2&2)) |
|
513 |
mode &= (1+8); |
|
514 |
||
515 |
ret = DoCommandByTile(tile, mode, 0, flags, CMD_BUILD_ROAD); |
|
516 |
if (ret == CMD_ERROR) { |
|
517 |
if (_error_message != STR_1007_ALREADY_BUILT) |
|
518 |
return CMD_ERROR; |
|
519 |
} else { |
|
520 |
cost += ret; |
|
521 |
} |
|
522 |
||
523 |
if (tile == end_tile) |
|
524 |
break; |
|
525 |
||
526 |
tile += (p2&4)?TILE_XY(0,1):TILE_XY(1,0); |
|
527 |
} |
|
528 |
||
529 |
// already built? |
|
530 |
if (cost == 0) |
|
531 |
return CMD_ERROR; |
|
532 |
||
533 |
return cost; |
|
534 |
} |
|
535 |
||
536 |
// Remove a long piece of road. |
|
537 |
// x,y = end tile |
|
538 |
// p1 = start tile |
|
539 |
// p2&1 = start tile starts in the 2nd half |
|
540 |
// p2&2 = end tile starts in the 2nd half |
|
541 |
// p2&4 = direction (0 = along x, 1=along y) |
|
542 |
int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
543 |
{ |
|
544 |
uint start_tile, end_tile, tile; |
|
545 |
int32 cost,ret; |
|
546 |
||
547 |
start_tile = p1; |
|
548 |
end_tile = TILE_FROM_XY(x, y); |
|
549 |
||
550 |
if (start_tile > end_tile || (start_tile == end_tile && (p2&1))) { |
|
551 |
uint t = start_tile; start_tile = end_tile; end_tile = t; |
|
552 |
p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0; |
|
553 |
} |
|
554 |
||
555 |
cost = 0; |
|
556 |
tile = start_tile; |
|
557 |
// Start tile is the small number. |
|
558 |
for(;;) { |
|
559 |
uint bits = (p2 & 4) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE; |
|
560 |
if (tile == end_tile && !(p2&2)) bits &= ROAD_NW | ROAD_NE; |
|
561 |
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
|
562 |
|
0 | 563 |
// try to remove the halves. |
564 |
if (bits) { |
|
565 |
ret = DoCommandByTile(tile, bits, 0, flags, CMD_REMOVE_ROAD); |
|
566 |
if (ret != CMD_ERROR) |
|
567 |
cost += ret; |
|
568 |
} |
|
569 |
||
570 |
if (tile == end_tile) |
|
571 |
break; |
|
572 |
||
573 |
tile += (p2&4)?TILE_XY(0,1):TILE_XY(1,0); |
|
574 |
} |
|
575 |
||
576 |
// already built? |
|
577 |
if (cost == 0) |
|
578 |
return CMD_ERROR; |
|
579 |
||
580 |
return cost; |
|
581 |
} |
|
582 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
583 |
/* Build a road depot |
0 | 584 |
* p1 - direction (0-3) |
585 |
* p2 - unused |
|
586 |
*/ |
|
587 |
||
588 |
int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
589 |
{ |
|
590 |
TileInfo ti; |
|
591 |
int32 cost; |
|
592 |
Depot *dep; |
|
593 |
uint tile; |
|
594 |
||
595 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
596 |
||
597 |
FindLandscapeHeight(&ti, x, y); |
|
598 |
||
599 |
tile = ti.tile; |
|
600 |
||
601 |
if (!EnsureNoVehicle(tile)) |
|
602 |
return CMD_ERROR; |
|
603 |
||
604 |
if (ti.tileh != 0) { |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
605 |
if (!_patches.build_on_slopes || (ti.tileh & 0x10 || !((0x4C >> p1) & ti.tileh) )) |
0 | 606 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
607 |
} |
|
608 |
||
609 |
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
|
610 |
if (cost == CMD_ERROR) |
|
611 |
return CMD_ERROR; |
|
612 |
||
613 |
dep = AllocateDepot(); |
|
614 |
if (dep == NULL) |
|
615 |
return CMD_ERROR; |
|
616 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
617 |
if (flags & DC_EXEC) { |
0 | 618 |
if (_current_player == _local_player) |
619 |
_last_built_road_depot_tile = (TileIndex)tile; |
|
620 |
||
621 |
dep->xy = tile; |
|
622 |
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; |
|
623 |
||
624 |
ModifyTile(tile, |
|
625 |
MP_SETTYPE(MP_STREET) | |
|
626 |
MP_MAPOWNER_CURRENT | MP_MAP5, |
|
627 |
(p1 | 0x20) /* map5 */ |
|
628 |
); |
|
629 |
||
630 |
} |
|
631 |
return cost + _price.build_road_depot; |
|
632 |
} |
|
633 |
||
634 |
static int32 RemoveRoadDepot(uint tile, uint32 flags) |
|
635 |
{ |
|
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
84
diff
changeset
|
636 |
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) |
0 | 637 |
return CMD_ERROR; |
638 |
||
639 |
if (!EnsureNoVehicle(tile)) |
|
640 |
return CMD_ERROR; |
|
641 |
||
642 |
if (flags & DC_EXEC) { |
|
643 |
DoDeleteDepot(tile); |
|
644 |
} |
|
645 |
||
646 |
return _price.remove_road_depot; |
|
647 |
} |
|
648 |
||
649 |
#define M(x) (1<<(x)) |
|
650 |
||
651 |
static int32 ClearTile_Road(uint tile, byte flags) { |
|
652 |
int32 ret; |
|
653 |
byte m5 = _map5[tile]; |
|
654 |
||
655 |
if ( (m5 & 0xF0) == 0) { |
|
656 |
byte b = m5 & 0xF; |
|
657 |
||
658 |
if (! ((1 << b) & (M(1)|M(2)|M(4)|M(8))) ) { |
|
659 |
if ( (!(flags & DC_AI_BUILDING) || _map_owner[tile]!=OWNER_TOWN) && flags&DC_AUTO) |
|
660 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
|
661 |
} |
|
662 |
return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD); |
|
663 |
} else if ( (m5 & 0xE0) == 0) { |
|
664 |
if (flags & DC_AUTO) |
|
665 |
return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
|
666 |
||
667 |
ret = DoCommandByTile(tile, (m5&8)?5:10, 0, flags, CMD_REMOVE_ROAD); |
|
668 |
if (ret == CMD_ERROR) |
|
669 |
return CMD_ERROR; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
670 |
|
0 | 671 |
if (flags & DC_EXEC) { |
672 |
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
|
673 |
} |
0 | 674 |
|
675 |
return ret; |
|
676 |
} else { |
|
677 |
if (flags & DC_AUTO) |
|
678 |
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
679 |
return RemoveRoadDepot(tile,flags); |
|
680 |
} |
|
681 |
} |
|
682 |
||
683 |
||
684 |
typedef struct DrawRoadTileStruct { |
|
685 |
uint16 image; |
|
686 |
byte subcoord_x; |
|
687 |
byte subcoord_y; |
|
688 |
} DrawRoadTileStruct; |
|
689 |
||
690 |
typedef struct DrawRoadSeqStruct { |
|
691 |
uint32 image; |
|
692 |
byte subcoord_x; |
|
693 |
byte subcoord_y; |
|
694 |
byte width; |
|
695 |
byte height; |
|
696 |
} DrawRoadSeqStruct; |
|
697 |
||
698 |
#include "table/road_land.h" |
|
699 |
||
700 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
72
diff
changeset
|
701 |
uint GetRoadFoundation(uint tileh, uint bits) { |
0 | 702 |
int i; |
703 |
// normal level sloped building |
|
704 |
if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) |
|
705 |
return tileh; |
|
706 |
||
707 |
// inclined sloped building |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
708 |
if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && |
0 | 709 |
((bits == (ROAD_SW | ROAD_NE)) || (i++, bits == (ROAD_NW | ROAD_SE)))) |
710 |
return i + 15; |
|
711 |
||
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
712 |
// rail crossing |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
713 |
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
|
714 |
return tileh; |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
715 |
|
0 | 716 |
return 0; |
717 |
} |
|
718 |
||
719 |
const byte _road_sloped_sprites[14] = { |
|
720 |
0, 0, 2, 0, |
|
721 |
0, 1, 0, 0, |
|
722 |
3, 0, 0, 0, |
|
723 |
0, 0 |
|
724 |
}; |
|
725 |
||
726 |
static void DrawTile_Road(TileInfo *ti) |
|
727 |
{ |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
728 |
uint32 image; |
0 | 729 |
byte m2; |
730 |
const byte *s; |
|
731 |
||
732 |
if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0 |
|
733 |
const DrawRoadTileStruct *drts; |
|
734 |
||
735 |
if (ti->tileh != 0) { |
|
736 |
int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF); |
|
737 |
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
|
738 |
|
0 | 739 |
// default sloped sprites.. |
740 |
if (ti->tileh != 0) { |
|
741 |
image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; |
|
742 |
} else { |
|
743 |
image = _road_tile_sprites_1[ti->map5 & 0xF]; |
|
744 |
} |
|
745 |
} else { |
|
746 |
image = _road_tile_sprites_1[ti->map5 & 0xF]; |
|
747 |
} |
|
748 |
||
749 |
m2 = _map2[ti->tile] & 7; |
|
750 |
||
751 |
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
|
752 |
|
0 | 753 |
if (_map3_hi[ti->tile] & 0x80) { |
754 |
image += 19; |
|
755 |
} else if (m2 > 1 && m2 != 6) { |
|
756 |
image -= 19; /* pavement along the road? */ |
|
757 |
} |
|
758 |
||
759 |
DrawGroundSprite(image); |
|
760 |
||
761 |
if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2) |
|
762 |
return; |
|
763 |
||
764 |
if (m2 >= 6) { |
|
765 |
// roadwork |
|
766 |
DrawGroundSprite(0x586 + ((ti->map5&8)!=0 ? 0 : 1)); |
|
767 |
return; |
|
768 |
} |
|
769 |
||
770 |
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
|
771 |
|
0 | 772 |
while ((image = drts->image) != 0) { |
773 |
int x = ti->x | drts->subcoord_x; |
|
774 |
int y = ti->y | drts->subcoord_y; |
|
775 |
byte z = ti->z; |
|
776 |
if (ti->tileh != 0) z = GetSlopeZ(x, y); |
|
777 |
AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z); |
|
778 |
drts++; |
|
779 |
} |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
780 |
} else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
781 |
int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
782 |
if (f) DrawFoundation(ti, f); |
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
783 |
|
0 | 784 |
image = 0x55B; |
785 |
||
786 |
if ( (ti->map5 & 8) != 0) |
|
787 |
image--; |
|
788 |
||
789 |
if ( (ti->map5 & 4) != 0) |
|
790 |
image += 2; |
|
791 |
||
792 |
if ( _map3_hi[ti->tile] & 0x80) { |
|
793 |
image += 8; |
|
794 |
} else { |
|
795 |
m2 = _map2[ti->tile] & 7; |
|
796 |
if (m2 == 0) image |= 0x3178000; |
|
797 |
if (m2 > 1) image += 4; |
|
798 |
} |
|
799 |
||
800 |
DrawGroundSprite(image + (_map3_hi[ti->tile] & 0xF) * 12); |
|
801 |
} else { |
|
802 |
uint32 ormod; |
|
803 |
int player; |
|
804 |
const DrawRoadSeqStruct *drss; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
805 |
|
0 | 806 |
if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); } |
807 |
||
808 |
ormod = 0x315; |
|
809 |
player = _map_owner[ti->tile]; |
|
810 |
if (player < MAX_PLAYERS) |
|
811 |
ormod = PLAYER_SPRITE_COLOR(player); |
|
812 |
||
813 |
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
|
814 |
|
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
|
815 |
DrawGroundSprite(*(const uint32*)s); |
0 | 816 |
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
|
817 |
drss = (const DrawRoadSeqStruct*)s; |
0 | 818 |
|
819 |
while ((image=drss->image) != 0) { |
|
820 |
if (image & 0x8000) |
|
821 |
image |= ormod; |
|
497
2d6d31173813
(svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents:
473
diff
changeset
|
822 |
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
|
823 |
image = (image & 0x3FFF) | 0x3224000; |
0 | 824 |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
825 |
AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x, |
0 | 826 |
ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z); |
827 |
drss++; |
|
828 |
} |
|
829 |
} |
|
830 |
} |
|
831 |
||
832 |
void DrawRoadDepotSprite(int x, int y, int image) |
|
833 |
{ |
|
834 |
uint32 ormod; |
|
835 |
const DrawRoadSeqStruct *dtss; |
|
836 |
const byte *t; |
|
837 |
||
838 |
ormod = PLAYER_SPRITE_COLOR(_local_player); |
|
839 |
||
840 |
t = _road_display_datas[image]; |
|
841 |
||
842 |
x+=33; |
|
843 |
y+=17; |
|
844 |
||
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
|
845 |
DrawSprite(*(const uint32*)t, x, y); |
0 | 846 |
t += sizeof(uint32); |
847 |
||
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
|
848 |
for(dtss = (const DrawRoadSeqStruct *)t; dtss->image != 0; dtss++) { |
0 | 849 |
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
|
850 |
|
0 | 851 |
image = dtss->image; |
852 |
if (image & 0x8000) |
|
853 |
image |= ormod; |
|
854 |
||
855 |
DrawSprite(image, x + pt.x, y + pt.y); |
|
856 |
} |
|
857 |
} |
|
858 |
||
410 | 859 |
static uint GetSlopeZ_Road(TileInfo *ti) |
0 | 860 |
{ |
861 |
uint z = ti->z; |
|
862 |
int th = ti->tileh; |
|
863 |
||
864 |
// check if it's a foundation |
|
865 |
if (ti->tileh != 0) { |
|
13
3e7c1f74a996
(svn r14) Fix: railroad crossings on slopes are now possible
dominik
parents:
0
diff
changeset
|
866 |
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
0 | 867 |
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
868 |
if (f != 0) { |
|
869 |
if (f < 15) { |
|
870 |
// leveled foundation |
|
871 |
return z + 8; |
|
872 |
} |
|
873 |
// inclined foundation |
|
874 |
th = _inclined_tileh[f - 15]; |
|
875 |
} |
|
876 |
} else if ((ti->map5 & 0xF0) == 0x20) { |
|
877 |
// depot |
|
878 |
return z + 8; |
|
879 |
} |
|
880 |
return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z; |
|
881 |
} |
|
39 | 882 |
return z; // normal Z if no slope |
883 |
} |
|
884 |
||
885 |
uint GetSlopeTileh_Road(TileInfo *ti) |
|
886 |
{ |
|
887 |
// check if it's a foundation |
|
888 |
if (ti->tileh != 0) { |
|
889 |
if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
|
890 |
uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
|
891 |
if (f != 0) { |
|
892 |
if (f < 15) { |
|
893 |
// leveled foundation |
|
894 |
return 0; |
|
895 |
} |
|
896 |
// inclined foundation |
|
897 |
return _inclined_tileh[f - 15]; |
|
898 |
} |
|
899 |
} else if ((ti->map5 & 0xF0) == 0x20) { |
|
900 |
// depot |
|
901 |
return 0; |
|
902 |
} |
|
903 |
} |
|
904 |
return ti->tileh; |
|
0 | 905 |
} |
906 |
||
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
410
diff
changeset
|
907 |
static void GetAcceptedCargo_Road(uint tile, AcceptedCargo ac) |
0 | 908 |
{ |
909 |
/* not used */ |
|
910 |
} |
|
911 |
||
912 |
static void AnimateTile_Road(uint tile) |
|
913 |
{ |
|
914 |
if ((_map5[tile] & 0xF0) == 0x10) { |
|
915 |
MarkTileDirtyByTile(tile); |
|
916 |
} |
|
917 |
} |
|
918 |
||
919 |
static const byte _town_road_types[5][2] = { |
|
920 |
{1,1}, |
|
921 |
{2,2}, |
|
922 |
{2,2}, |
|
923 |
{5,5}, |
|
924 |
{3,2}, |
|
925 |
}; |
|
926 |
||
927 |
static const byte _town_road_types_2[5][2] = { |
|
928 |
{1,1}, |
|
929 |
{2,2}, |
|
930 |
{3,2}, |
|
931 |
{3,2}, |
|
932 |
{3,2}, |
|
933 |
}; |
|
934 |
||
935 |
||
936 |
static void TileLoop_Road(uint tile) |
|
937 |
{ |
|
938 |
Town *t; |
|
939 |
int grp; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
940 |
|
0 | 941 |
if (_opt.landscape == LT_HILLY) { |
942 |
// Fix snow style if the road is above the snowline |
|
943 |
if ((_map3_hi[tile] & 0x80) != ((GetTileZ(tile) > _opt.snow_line) ? 0x80 : 0x00)) { |
|
944 |
_map3_hi[tile] ^= 0x80; |
|
945 |
MarkTileDirtyByTile(tile); |
|
946 |
} |
|
947 |
} else if (_opt.landscape == LT_DESERT) { |
|
948 |
// Fix desert style |
|
949 |
if (GetMapExtraBits(tile) == 1 && !(_map3_hi[tile] & 0x80)) { |
|
950 |
_map3_hi[tile] |= 0x80; |
|
951 |
MarkTileDirtyByTile(tile); |
|
952 |
} |
|
953 |
} |
|
954 |
||
955 |
if (_map5[tile] & 0xE0) |
|
956 |
return; |
|
957 |
||
958 |
if ((_map2[tile] & 7) < 6) { |
|
959 |
t = ClosestTownFromTile(tile, (uint)-1); |
|
960 |
grp = 0; |
|
961 |
if (t != NULL) { |
|
962 |
// If in the scenario editor, set the owner to a town. |
|
963 |
if (_game_mode == GM_EDITOR) { |
|
964 |
_map_owner[tile] = OWNER_TOWN; |
|
965 |
} |
|
966 |
||
967 |
grp = GetTownRadiusGroup(t, tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
968 |
|
0 | 969 |
// 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
|
970 |
if (t->road_build_months != 0 && |
0 | 971 |
!(GetTileDist(t->xy, tile) >= 8 && grp==0) && |
972 |
(_map5[tile]==5 || _map5[tile]==10)) { |
|
973 |
if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1,20)) { |
|
974 |
_map2[tile] = ((_map2[tile]&7) <= 1) ? 6 : 7; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
975 |
|
0 | 976 |
SndPlayTileFx(0x1F,tile); |
977 |
CreateEffectVehicleAbove( |
|
978 |
GET_TILE_X(tile) * 16 + 7, |
|
979 |
GET_TILE_Y(tile) * 16 + 7, |
|
980 |
0, |
|
981 |
EV_ROADWORK); |
|
982 |
MarkTileDirtyByTile(tile); |
|
983 |
return; |
|
984 |
} |
|
985 |
} |
|
986 |
} |
|
987 |
||
988 |
{ |
|
989 |
const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp]; |
|
990 |
byte b = _map2[tile] & 7; |
|
991 |
||
992 |
if (b == p[0]) |
|
993 |
return; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
994 |
|
0 | 995 |
if (b == p[1]) { |
996 |
b = p[0]; |
|
997 |
} else if (b == 0) { |
|
998 |
b = p[1]; |
|
999 |
} else { |
|
1000 |
b = 0; |
|
1001 |
} |
|
1002 |
_map2[tile] = (_map2[tile] & ~7) | b; |
|
1003 |
MarkTileDirtyByTile(tile); |
|
1004 |
} |
|
1005 |
} else { |
|
1006 |
// Handle road work |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1007 |
|
0 | 1008 |
byte b = _map2[tile]; |
1009 |
if (b < 0x80) { |
|
1010 |
_map2[tile] = b + 8; |
|
1011 |
return; |
|
1012 |
} |
|
1013 |
_map2[tile] = ((b&7) == 6) ? 1 : 2; |
|
1014 |
MarkTileDirtyByTile(tile); |
|
1015 |
} |
|
1016 |
} |
|
1017 |
||
1018 |
void ShowRoadDepotWindow(uint tile); |
|
1019 |
||
1020 |
static void ClickTile_Road(uint tile) |
|
1021 |
{ |
|
1022 |
if ((_map5[tile] & 0xF0) == 0x20) { |
|
1023 |
ShowRoadDepotWindow(tile); |
|
1024 |
} |
|
1025 |
} |
|
1026 |
||
1027 |
static const byte _road_trackbits[16] = { |
|
1028 |
0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F, |
|
1029 |
}; |
|
1030 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1031 |
static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1032 |
if (mode == TRANSPORT_RAIL) { |
0 | 1033 |
if ((_map5[tile] & 0xF0) != 0x10) |
1034 |
return 0; |
|
1035 |
return _map5[tile] & 8 ? 0x101 : 0x202; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1036 |
} else if (mode == TRANSPORT_ROAD) { |
0 | 1037 |
byte b = _map5[tile]; |
1038 |
if ((b & 0xF0) == 0) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1039 |
/* Ordinary road */ |
0 | 1040 |
if (!_road_special_gettrackstatus && (_map2[tile]&7) >= 6) |
1041 |
return 0; |
|
1042 |
return _road_trackbits[b&0xF] * 0x101; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1043 |
} else if ((b&0xF0) == 0x10) { |
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
149
diff
changeset
|
1044 |
/* Crossing */ |
0 | 1045 |
uint32 r = 0x101; |
1046 |
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
|
1047 |
|
0 | 1048 |
if (b&4) { |
1049 |
r *= 0x10001; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1050 |
} |
0 | 1051 |
return r; |
1052 |
} |
|
1053 |
} |
|
1054 |
return 0; |
|
1055 |
} |
|
1056 |
||
1057 |
static const StringID _road_tile_strings[] = { |
|
1058 |
STR_1818_ROAD_RAIL_LEVEL_CROSSING, |
|
1059 |
STR_1817_ROAD_VEHICLE_DEPOT, |
|
1060 |
||
1061 |
STR_1814_ROAD, |
|
1062 |
STR_1814_ROAD, |
|
1063 |
STR_1814_ROAD, |
|
1064 |
STR_1815_ROAD_WITH_STREETLIGHTS, |
|
1065 |
STR_1814_ROAD, |
|
1066 |
STR_1816_TREE_LINED_ROAD, |
|
1067 |
STR_1814_ROAD, |
|
1068 |
STR_1814_ROAD, |
|
1069 |
}; |
|
1070 |
||
1071 |
static void GetTileDesc_Road(uint tile, TileDesc *td) |
|
1072 |
{ |
|
1073 |
int i = (_map5[tile] >> 4); |
|
1074 |
if (i == 0) |
|
1075 |
i = (_map2[tile] & 7) + 3; |
|
1076 |
td->str = _road_tile_strings[i - 1]; |
|
1077 |
td->owner = _map_owner[tile]; |
|
1078 |
} |
|
1079 |
||
1080 |
static const byte _roadveh_enter_depot_unk0[4] = { |
|
1081 |
8, 9, 0, 1 |
|
1082 |
}; |
|
1083 |
||
1084 |
static uint32 VehicleEnter_Road(Vehicle *v, uint tile, int x, int y) |
|
1085 |
{ |
|
1086 |
if ((_map5[tile] & 0xF0) == 0x10) { |
|
1087 |
if (v->type == VEH_Train && (_map5[tile] & 4) == 0) { |
|
1088 |
/* train crossing a road */ |
|
1089 |
SndPlayVehicleFx(12, v); |
|
1090 |
_map5[tile] |= 4; |
|
1091 |
MarkTileDirtyByTile(tile); |
|
1092 |
} |
|
1093 |
} else if ((_map5[tile]&0xF0) == 0x20){ |
|
1094 |
if (v->type == VEH_Road && v->u.road.frame == 11) { |
|
1095 |
if (_roadveh_enter_depot_unk0[_map5[tile]&3] == v->u.road.state) { |
|
1096 |
RoadVehEnterDepot(v); |
|
1097 |
return 4; |
|
1098 |
} |
|
1099 |
} |
|
1100 |
} |
|
1101 |
return 0; |
|
1102 |
} |
|
1103 |
||
1104 |
static void VehicleLeave_Road(Vehicle *v, uint tile, int x, int y) |
|
1105 |
{ |
|
1106 |
if ((_map5[tile] & 0xF0) == 0x10 && v->type == VEH_Train && v->next == NULL) { |
|
1107 |
_map5[tile] &= ~4; |
|
1108 |
MarkTileDirtyByTile(tile); |
|
1109 |
} |
|
1110 |
} |
|
1111 |
||
1112 |
static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player) |
|
1113 |
{ |
|
1114 |
byte b; |
|
1115 |
||
1116 |
// road/rail crossing where the road is owned by the current player? |
|
1117 |
if (old_player == _map3_lo[tile] && (_map5[tile]&0xF0) == 0x10) { |
|
1118 |
_map3_lo[tile] = (new_player == 0xFF) ? OWNER_NONE : new_player; |
|
1119 |
} |
|
1120 |
||
1121 |
if (_map_owner[tile] != old_player) |
|
1122 |
return; |
|
1123 |
||
1124 |
if (new_player != 255) { |
|
1125 |
_map_owner[tile] = new_player; |
|
1126 |
} else { |
|
1127 |
b = _map5[tile]&0xF0; |
|
1128 |
if (b == 0) { |
|
1129 |
_map_owner[tile] = OWNER_NONE; |
|
1130 |
} else if (b == 0x10) { |
|
1131 |
_map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA; |
|
1132 |
_map_owner[tile] = _map3_lo[tile]; |
|
1133 |
_map3_lo[tile] = 0; |
|
1134 |
_map3_hi[tile] &= 0x80; |
|
1135 |
} else { |
|
1136 |
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1137 |
} |
|
1138 |
} |
|
1139 |
} |
|
1140 |
||
1141 |
void InitializeRoad() |
|
1142 |
{ |
|
1143 |
_last_built_road_depot_tile = 0; |
|
1144 |
} |
|
1145 |
||
1146 |
const TileTypeProcs _tile_type_road_procs = { |
|
1147 |
DrawTile_Road, /* draw_tile_proc */ |
|
1148 |
GetSlopeZ_Road, /* get_slope_z_proc */ |
|
1149 |
ClearTile_Road, /* clear_tile_proc */ |
|
1150 |
GetAcceptedCargo_Road, /* get_accepted_cargo_proc */ |
|
1151 |
GetTileDesc_Road, /* get_tile_desc_proc */ |
|
1152 |
GetTileTrackStatus_Road, /* get_tile_track_status_proc */ |
|
1153 |
ClickTile_Road, /* click_tile_proc */ |
|
1154 |
AnimateTile_Road, /* animate_tile_proc */ |
|
1155 |
TileLoop_Road, /* tile_loop_clear */ |
|
1156 |
ChangeTileOwner_Road, /* change_tile_owner_clear */ |
|
1157 |
NULL, /* get_produced_cargo_proc */ |
|
1158 |
VehicleEnter_Road, /* vehicle_enter_tile_proc */ |
|
1159 |
VehicleLeave_Road, /* vehicle_leave_tile_proc */ |
|
39 | 1160 |
GetSlopeTileh_Road, /* get_slope_tileh_proc */ |
0 | 1161 |
}; |