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