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