OpenTTD Source: src/road_cmd.cpp Source File

OpenTTD Source 13.2.1

road_cmd.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "road.h"
12 #include "road_internal.h"
13 #include "viewport_func.h"
14 #include "command_func.h"
15 #include "pathfinder/yapf/yapf_cache.h"
16 #include "depot_base.h"
17 #include "newgrf.h"
18 #include "autoslope.h"
19 #include "tunnelbridge_map.h"
20 #include "strings_func.h"
21 #include "vehicle_func.h"
22 #include "sound_func.h"
23 #include "tunnelbridge.h"
24 #include "cheat_type.h"
25 #include "effectvehicle_func.h"
26 #include "effectvehicle_base.h"
27 #include "elrail_func.h"
28 #include "roadveh.h"
29 #include "train.h"
30 #include "town.h"
31 #include "company_base.h"
32 #include "core/random_func.hpp"
33 #include "newgrf_debug.h"
34 #include "newgrf_railtype.h"
35 #include "newgrf_roadtype.h"
36 #include "date_func.h"
37 #include "genworld.h"
38 #include "company_gui.h"
39 #include "road_func.h"
40 #include "road_cmd.h"
41 #include "landscape_cmd.h"
42 #include "rail_cmd.h"
43
44 #include "table/strings.h"
45 #include "table/roadtypes.h"
46
47 #include "safeguards.h"
48
50 typedef std::vector<RoadVehicle *> RoadVehicleList;
51
52 RoadTypeInfo _roadtypes[ROADTYPE_END];
53 std::vector<RoadType> _sorted_roadtypes;
54 RoadTypes _roadtypes_hidden_mask;
55
60 RoadTypes _roadtypes_type;
61
65 void ResetRoadTypes()
66 {
67 static_assert(lengthof(_original_roadtypes) <= lengthof(_roadtypes));
68
69 uint i = 0;
70 for (; i < lengthof(_original_roadtypes); i++) _roadtypes[i] = _original_roadtypes[i];
71
72 static const RoadTypeInfo empty_roadtype = {
73 { 0, 0, 0, 0, 0, 0 },
74 { 0, 0, 0, 0, 0, 0 },
75 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {}, {}, 0, {}, {} },
76 ROADTYPES_NONE, ROTFB_NONE, 0, 0, 0, 0,
77 RoadTypeLabelList(), 0, 0, ROADTYPES_NONE, ROADTYPES_NONE, 0,
78 {}, {} };
79 for (; i < lengthof(_roadtypes); i++) _roadtypes[i] = empty_roadtype;
80
81 _roadtypes_hidden_mask = ROADTYPES_NONE;
82 _roadtypes_type = ROADTYPES_TRAM;
83 }
84
85 void ResolveRoadTypeGUISprites(RoadTypeInfo *rti)
86 {
87 SpriteID cursors_base = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_CURSORS);
88 if (cursors_base != 0) {
89 rti->gui_sprites.build_y_road = cursors_base + 0;
90 rti->gui_sprites.build_x_road = cursors_base + 1;
91 rti->gui_sprites.auto_road = cursors_base + 2;
92 rti->gui_sprites.build_depot = cursors_base + 3;
93 rti->gui_sprites.build_tunnel = cursors_base + 4;
94 rti->gui_sprites.convert_road = cursors_base + 5;
95 rti->cursor.road_swne = cursors_base + 6;
96 rti->cursor.road_nwse = cursors_base + 7;
97 rti->cursor.autoroad = cursors_base + 8;
98 rti->cursor.depot = cursors_base + 9;
99 rti->cursor.tunnel = cursors_base + 10;
100 rti->cursor.convert_road = cursors_base + 11;
101 }
102 }
103
110 static bool CompareRoadTypes(const RoadType &first, const RoadType &second)
111 {
112 if (RoadTypeIsRoad(first) == RoadTypeIsRoad(second)) {
113 return GetRoadTypeInfo(first)->sorting_order < GetRoadTypeInfo(second)->sorting_order;
114 }
115 return RoadTypeIsTram(first) < RoadTypeIsTram(second);
116 }
117
121 void InitRoadTypes()
122 {
123 for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
124 RoadTypeInfo *rti = &_roadtypes[rt];
125 ResolveRoadTypeGUISprites(rti);
126 if (HasBit(rti->flags, ROTF_HIDDEN)) SetBit(_roadtypes_hidden_mask, rt);
127 }
128
129 _sorted_roadtypes.clear();
130 for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
131 if (_roadtypes[rt].label != 0 && !HasBit(_roadtypes_hidden_mask, rt)) {
132 _sorted_roadtypes.push_back(rt);
133 }
134 }
135 std::sort(_sorted_roadtypes.begin(), _sorted_roadtypes.end(), CompareRoadTypes);
136 }
137
141 RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
142 {
143 for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
144 RoadTypeInfo *rti = &_roadtypes[rt];
145
146 if (rti->label == 0) {
147 /* Set up new road type */
148 *rti = _original_roadtypes[(rtt == RTT_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD];
149 rti->label = label;
150 rti->alternate_labels.clear();
151 rti->flags = ROTFB_NONE;
152 rti->introduction_date = INVALID_DATE;
153
154 /* Make us compatible with ourself. */
155 rti->powered_roadtypes = (RoadTypes)(1ULL << rt);
156
157 /* We also introduce ourself. */
158 rti->introduces_roadtypes = (RoadTypes)(1ULL << rt);
159
160 /* Default sort order; order of allocation, but with some
161 * offsets so it's easier for NewGRF to pick a spot without
162 * changing the order of other (original) road types.
163 * The << is so you can place other roadtypes in between the
164 * other roadtypes, the 7 is to be able to place something
165 * before the first (default) road type. */
166 rti->sorting_order = rt << 2 | 7;
167
168 /* Set bitmap of road/tram types */
169 if (rtt == RTT_TRAM) {
170 SetBit(_roadtypes_type, rt);
171 } else {
172 ClrBit(_roadtypes_type, rt);
173 }
174
175 return rt;
176 }
177 }
178
179 return INVALID_ROADTYPE;
180 }
181
186 bool RoadVehiclesAreBuilt()
187 {
188 return !RoadVehicle::Iterate().empty();
189 }
190
197 void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
198 {
199 if (rt == INVALID_ROADTYPE) return;
200
201 Company *c = Company::GetIfValid(o);
202 if (c == nullptr) return;
203
204 c->infrastructure.road[rt] += count;
205 DirtyCompanyInfrastructureWindows(c->index);
206 }
207
209 static const RoadBits _invalid_tileh_slopes_road[2][15] = {
210 /* The inverse of the mixable RoadBits on a leveled slope */
211 {
212 ROAD_NONE, // SLOPE_FLAT
213 ROAD_NE | ROAD_SE, // SLOPE_W
214 ROAD_NE | ROAD_NW, // SLOPE_S
215
216 ROAD_NE, // SLOPE_SW
217 ROAD_NW | ROAD_SW, // SLOPE_E
218 ROAD_NONE, // SLOPE_EW
219
220 ROAD_NW, // SLOPE_SE
221 ROAD_NONE, // SLOPE_WSE
222 ROAD_SE | ROAD_SW, // SLOPE_N
223
224 ROAD_SE, // SLOPE_NW
225 ROAD_NONE, // SLOPE_NS
226 ROAD_NONE, // SLOPE_ENW
227
228 ROAD_SW, // SLOPE_NE
229 ROAD_NONE, // SLOPE_SEN
230 ROAD_NONE // SLOPE_NWS
231 },
232 /* The inverse of the allowed straight roads on a slope
233 * (with and without a foundation). */
234 {
235 ROAD_NONE, // SLOPE_FLAT
236 ROAD_NONE, // SLOPE_W Foundation
237 ROAD_NONE, // SLOPE_S Foundation
238
239 ROAD_Y, // SLOPE_SW
240 ROAD_NONE, // SLOPE_E Foundation
241 ROAD_ALL, // SLOPE_EW
242
243 ROAD_X, // SLOPE_SE
244 ROAD_ALL, // SLOPE_WSE
245 ROAD_NONE, // SLOPE_N Foundation
246
247 ROAD_X, // SLOPE_NW
248 ROAD_ALL, // SLOPE_NS
249 ROAD_ALL, // SLOPE_ENW
250
251 ROAD_Y, // SLOPE_NE
252 ROAD_ALL, // SLOPE_SEN
253 ROAD_ALL // SLOPE_NW
254 }
255 };
256
257 static Foundation GetRoadFoundation(Slope tileh, RoadBits bits);
258
269 CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadTramType rtt, DoCommandFlag flags, bool town_check)
270 {
271 if (_game_mode == GM_EDITOR || remove == ROAD_NONE) return CommandCost();
272
273 /* Water can always flood and towns can always remove "normal" road pieces.
274 * Towns are not be allowed to remove non "normal" road pieces, like tram
275 * tracks as that would result in trams that cannot turn. */
276 if (_current_company == OWNER_WATER ||
277 (rtt == RTT_ROAD && !Company::IsValidID(_current_company))) return CommandCost();
278
279 /* Only do the special processing if the road is owned
280 * by a town */
281 if (owner != OWNER_TOWN) {
282 if (owner == OWNER_NONE) return CommandCost();
283 CommandCost ret = CheckOwnership(owner);
284 return ret;
285 }
286
287 if (!town_check) return CommandCost();
288
289 if (_cheats.magic_bulldozer.value) return CommandCost();
290
291 Town *t = ClosestTownFromTile(tile, UINT_MAX);
292 if (t == nullptr) return CommandCost();
293
294 /* check if you're allowed to remove the street owned by a town
295 * removal allowance depends on difficulty setting */
296 CommandCost ret = CheckforTownRating(flags, t, ROAD_REMOVE);
297 if (ret.Failed()) return ret;
298
299 /* Get a bitmask of which neighbouring roads has a tile */
300 RoadBits n = ROAD_NONE;
301 RoadBits present = GetAnyRoadBits(tile, rtt);
302 if ((present & ROAD_NE) && (GetAnyRoadBits(TILE_ADDXY(tile, -1, 0), rtt) & ROAD_SW)) n |= ROAD_NE;
303 if ((present & ROAD_SE) && (GetAnyRoadBits(TILE_ADDXY(tile, 0, 1), rtt) & ROAD_NW)) n |= ROAD_SE;
304 if ((present & ROAD_SW) && (GetAnyRoadBits(TILE_ADDXY(tile, 1, 0), rtt) & ROAD_NE)) n |= ROAD_SW;
305 if ((present & ROAD_NW) && (GetAnyRoadBits(TILE_ADDXY(tile, 0, -1), rtt) & ROAD_SE)) n |= ROAD_NW;
306
307 int rating_decrease = RATING_ROAD_DOWN_STEP_EDGE;
308 /* If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
309 * then allow it */
310 if (KillFirstBit(n) != ROAD_NONE && (n & remove) != ROAD_NONE) {
311 /* you can remove all kind of roads with extra dynamite */
312 if (!_settings_game.construction.extra_dynamite) {
313 SetDParam(0, t->index);
314 return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
315 }
316 rating_decrease = RATING_ROAD_DOWN_STEP_INNER;
317 }
318 ChangeTownRating(t, rating_decrease, RATING_ROAD_MINIMUM, flags);
319
320 return CommandCost();
321 }
322
323
333 static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits pieces, RoadTramType rtt, bool crossing_check, bool town_check = true)
334 {
335 assert(pieces != ROAD_NONE);
336
337 RoadType existing_rt = MayHaveRoad(tile) ? GetRoadType(tile, rtt) : INVALID_ROADTYPE;
338 /* The tile doesn't have the given road type */
339 if (existing_rt == INVALID_ROADTYPE) return_cmd_error((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
340
341 switch (GetTileType(tile)) {
342 case MP_ROAD: {
343 CommandCost ret = EnsureNoVehicleOnGround(tile);
344 if (ret.Failed()) return ret;
345 break;
346 }
347
348 case MP_STATION: {
349 if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
350
351 CommandCost ret = EnsureNoVehicleOnGround(tile);
352 if (ret.Failed()) return ret;
353 break;
354 }
355
356 case MP_TUNNELBRIDGE: {
357 if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
358 CommandCost ret = TunnelBridgeIsFree(tile, GetOtherTunnelBridgeEnd(tile));
359 if (ret.Failed()) return ret;
360 break;
361 }
362
363 default:
364 return CMD_ERROR;
365 }
366
367 CommandCost ret = CheckAllowRemoveRoad(tile, pieces, GetRoadOwner(tile, rtt), rtt, flags, town_check);
368 if (ret.Failed()) return ret;
369
370 if (!IsTileType(tile, MP_ROAD)) {
371 /* If it's the last roadtype, just clear the whole tile */
372 if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
373
374 CommandCost cost(EXPENSES_CONSTRUCTION);
375 if (IsTileType(tile, MP_TUNNELBRIDGE)) {
376 /* Removing any roadbit in the bridge axis removes the roadtype (that's the behaviour remove-long-roads needs) */
377 if ((AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) & pieces) == ROAD_NONE) return_cmd_error((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
378
379 TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
380 /* Pay for *every* tile of the bridge or tunnel */
381 uint len = GetTunnelBridgeLength(other_end, tile) + 2;
382 cost.AddCost(len * 2 * RoadClearCost(existing_rt));
383 if (flags & DC_EXEC) {
384 /* A full diagonal road tile has two road bits. */
385 UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
386
387 SetRoadType(other_end, rtt, INVALID_ROADTYPE);
388 SetRoadType(tile, rtt, INVALID_ROADTYPE);
389
390 /* If the owner of the bridge sells all its road, also move the ownership
391 * to the owner of the other roadtype, unless the bridge owner is a town. */
392 Owner other_owner = GetRoadOwner(tile, OtherRoadTramType(rtt));
393 if (!IsTileOwner(tile, other_owner) && !IsTileOwner(tile, OWNER_TOWN)) {
394 SetTileOwner(tile, other_owner);
395 SetTileOwner(other_end, other_owner);
396 }
397
398 /* Mark tiles dirty that have been repaved */
399 if (IsBridge(tile)) {
400 MarkBridgeDirty(tile);
401 } else {
402 MarkTileDirtyByTile(tile);
403 MarkTileDirtyByTile(other_end);
404 }
405 }
406 } else {
407 assert(IsDriveThroughStopTile(tile));
408 cost.AddCost(RoadClearCost(existing_rt) * 2);
409 if (flags & DC_EXEC) {
410 /* A full diagonal road tile has two road bits. */
411 UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -2);
412 SetRoadType(tile, rtt, INVALID_ROADTYPE);
413 MarkTileDirtyByTile(tile);
414 }
415 }
416 return cost;
417 }
418
419 switch (GetRoadTileType(tile)) {
420 case ROAD_TILE_NORMAL: {
421 Slope tileh = GetTileSlope(tile);
422
423 /* Steep slopes behave the same as slopes with one corner raised. */
424 if (IsSteepSlope(tileh)) {
425 tileh = SlopeWithOneCornerRaised(GetHighestSlopeCorner(tileh));
426 }
427
428 RoadBits present = GetRoadBits(tile, rtt);
429 const RoadBits other = GetRoadBits(tile, OtherRoadTramType(rtt));
430 const Foundation f = GetRoadFoundation(tileh, present);
431
432 if (HasRoadWorks(tile) && _current_company != OWNER_WATER) return_cmd_error(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
433
434 /* Autocomplete to a straight road
435 * @li if the bits of the other roadtypes result in another foundation
436 * @li if build on slopes is disabled */
437 if ((IsStraightRoad(other) && (other & _invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED]) != ROAD_NONE) ||
438 (tileh != SLOPE_FLAT && !_settings_game.construction.build_on_slopes)) {
439 pieces |= MirrorRoadBits(pieces);
440 }
441
442 /* limit the bits to delete to the existing bits. */
443 pieces &= present;
444 if (pieces == ROAD_NONE) return_cmd_error((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
445
446 /* Now set present what it will be after the remove */
447 present ^= pieces;
448
449 /* Check for invalid RoadBit combinations on slopes */
450 if (tileh != SLOPE_FLAT && present != ROAD_NONE &&
451 (present & _invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED]) == present) {
452 return CMD_ERROR;
453 }
454
455 if (flags & DC_EXEC) {
456 if (HasRoadWorks(tile)) {
457 /* flooding tile with road works, don't forget to remove the effect vehicle too */
458 assert(_current_company == OWNER_WATER);
459 for (EffectVehicle *v : EffectVehicle::Iterate()) {
460 if (TileVirtXY(v->x_pos, v->y_pos) == tile) {
461 delete v;
462 }
463 }
464 }
465
466 UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -(int)CountBits(pieces));
467
468 if (present == ROAD_NONE) {
469 /* No other road type, just clear tile. */
470 if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) {
471 /* Includes MarkTileDirtyByTile() */
472 DoClearSquare(tile);
473 } else {
474 if (rtt == RTT_ROAD && IsRoadOwner(tile, rtt, OWNER_TOWN)) {
475 /* Update nearest-town index */
476 const Town *town = CalcClosestTownFromTile(tile);
477 SetTownIndex(tile, town == nullptr ? INVALID_TOWN : town->index);
478 }
479 SetRoadBits(tile, ROAD_NONE, rtt);
480 SetRoadType(tile, rtt, INVALID_ROADTYPE);
481 MarkTileDirtyByTile(tile);
482 }
483 } else {
484 /* When bits are removed, you *always* end up with something that
485 * is not a complete straight road tile. However, trams do not have
486 * onewayness, so they cannot remove it either. */
487 if (rtt == RTT_ROAD) SetDisallowedRoadDirections(tile, DRD_NONE);
488 SetRoadBits(tile, present, rtt);
489 MarkTileDirtyByTile(tile);
490 }
491 }
492
493 CommandCost cost(EXPENSES_CONSTRUCTION, CountBits(pieces) * RoadClearCost(existing_rt));
494 /* If we build a foundation we have to pay for it. */
495 if (f == FOUNDATION_NONE && GetRoadFoundation(tileh, present) != FOUNDATION_NONE) cost.AddCost(_price[PR_BUILD_FOUNDATION]);
496
497 return cost;
498 }
499
500 case ROAD_TILE_CROSSING: {
501 if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
502 return CMD_ERROR;
503 }
504
505 if (flags & DC_EXEC) {
506 UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(tile, GetCrossingRoadAxis(tile));
507
508 /* A full diagonal road tile has two road bits. */
509 UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -2);
510
511 Track railtrack = GetCrossingRailTrack(tile);
512 if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) {
513 TrackBits tracks = GetCrossingRailBits(tile);
514 bool reserved = HasCrossingReservation(tile);
515 MakeRailNormal(tile, GetTileOwner(tile), tracks, GetRailType(tile));
516 if (reserved) SetTrackReservation(tile, tracks);
517
518 /* Update rail count for level crossings. The plain track should still be accounted
519 * for, so only subtract the difference to the level crossing cost. */
520 Company *c = Company::GetIfValid(GetTileOwner(tile));
521 if (c != nullptr) {
522 c->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR - 1;
523 DirtyCompanyInfrastructureWindows(c->index);
524 }
525 } else {
526 SetRoadType(tile, rtt, INVALID_ROADTYPE);
527 }
528 MarkTileDirtyByTile(tile);
529 YapfNotifyTrackLayoutChange(tile, railtrack);
530 }
531 return CommandCost(EXPENSES_CONSTRUCTION, RoadClearCost(existing_rt) * 2);
532 }
533
534 default:
535 case ROAD_TILE_DEPOT:
536 return CMD_ERROR;
537 }
538 }
539
540
552 static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existing, RoadBits other)
553 {
554 /* Remove already build pieces */
555 CLRBITS(*pieces, existing);
556
557 /* If we can't build anything stop here */
558 if (*pieces == ROAD_NONE) return CMD_ERROR;
559
560 /* All RoadBit combos are valid on flat land */
561 if (tileh == SLOPE_FLAT) return CommandCost();
562
563 /* Steep slopes behave the same as slopes with one corner raised. */
564 if (IsSteepSlope(tileh)) {
565 tileh = SlopeWithOneCornerRaised(GetHighestSlopeCorner(tileh));
566 }
567
568 /* Save the merge of all bits of the current type */
569 RoadBits type_bits = existing | *pieces;
570
571 /* Roads on slopes */
572 if (_settings_game.construction.build_on_slopes && (_invalid_tileh_slopes_road[0][tileh] & (other | type_bits)) == ROAD_NONE) {
573
574 /* If we add leveling we've got to pay for it */
575 if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
576
577 return CommandCost();
578 }
579
580 /* Autocomplete uphill roads */
581 *pieces |= MirrorRoadBits(*pieces);
582 type_bits = existing | *pieces;
583
584 /* Uphill roads */
585 if (IsStraightRoad(type_bits) && (other == type_bits || other == ROAD_NONE) &&
586 (_invalid_tileh_slopes_road[1][tileh] & (other | type_bits)) == ROAD_NONE) {
587
588 /* Slopes with foundation ? */
589 if (IsSlopeWithOneCornerRaised(tileh)) {
590
591 /* Prevent build on slopes if it isn't allowed */
592 if (_settings_game.construction.build_on_slopes) {
593
594 /* If we add foundation we've got to pay for it */
595 if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
596
597 return CommandCost();
598 }
599 } else {
600 if (HasExactlyOneBit(existing) && GetRoadFoundation(tileh, existing) == FOUNDATION_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
601 return CommandCost();
602 }
603 }
604 return CMD_ERROR;
605 }
606
617 CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, RoadType rt, DisallowedRoadDirections toggle_drd, TownID town_id)
618 {
619 CompanyID company = _current_company;
620 CommandCost cost(EXPENSES_CONSTRUCTION);
621
622 RoadBits existing = ROAD_NONE;
623 RoadBits other_bits = ROAD_NONE;
624
625 /* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
626 * if a non-company is building the road */
627 if ((Company::IsValidID(company) && town_id != 0) || (company == OWNER_TOWN && !Town::IsValidID(town_id)) || (company == OWNER_DEITY && town_id != 0)) return CMD_ERROR;
628 if (company != OWNER_TOWN) {
629 const Town *town = CalcClosestTownFromTile(tile);
630 town_id = (town != nullptr) ? town->index : INVALID_TOWN;
631
632 if (company == OWNER_DEITY) {
633 company = OWNER_TOWN;
634
635 /* If we are not within a town, we are not owned by the town */
636 if (town == nullptr || DistanceSquare(tile, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
637 company = OWNER_NONE;
638 }
639 }
640 }
641
642 /* do not allow building 'zero' road bits, code wouldn't handle it */
643 if (pieces == ROAD_NONE || !IsValidRoadBits(pieces) || !IsValidDisallowedRoadDirections(toggle_drd)) return CMD_ERROR;
644 if (!ValParamRoadType(rt)) return CMD_ERROR;
645
646 Slope tileh = GetTileSlope(tile);
647 RoadTramType rtt = GetRoadTramType(rt);
648
649 bool need_to_clear = false;
650 switch (GetTileType(tile)) {
651 case MP_ROAD:
652 switch (GetRoadTileType(tile)) {
653 case ROAD_TILE_NORMAL: {
654 if (HasRoadWorks(tile)) return_cmd_error(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
655
656 other_bits = GetRoadBits(tile, OtherRoadTramType(rtt));
657 if (!HasTileRoadType(tile, rtt)) break;
658
659 existing = GetRoadBits(tile, rtt);
660 bool crossing = !IsStraightRoad(existing | pieces);
661 if (rtt == RTT_ROAD && (GetDisallowedRoadDirections(tile) != DRD_NONE || toggle_drd != DRD_NONE) && crossing) {
662 /* Junctions cannot be one-way */
663 return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
664 }
665 if ((existing & pieces) == pieces) {
666 /* We only want to set the (dis)allowed road directions */
667 if (toggle_drd != DRD_NONE && rtt == RTT_ROAD) {
668 if (crossing) return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
669
670 Owner owner = GetRoadOwner(tile, rtt);
671 if (owner != OWNER_NONE) {
672 CommandCost ret = CheckOwnership(owner, tile);
673 if (ret.Failed()) return ret;
674 }
675
676 DisallowedRoadDirections dis_existing = GetDisallowedRoadDirections(tile);
677 DisallowedRoadDirections dis_new = dis_existing ^ toggle_drd;
678
679 /* We allow removing disallowed directions to break up
680 * deadlocks, but adding them can break articulated
681 * vehicles. As such, only when less is disallowed,
682 * i.e. bits are removed, we skip the vehicle check. */
683 if (CountBits(dis_existing) <= CountBits(dis_new)) {
684 CommandCost ret = EnsureNoVehicleOnGround(tile);
685 if (ret.Failed()) return ret;
686 }
687
688 /* Ignore half built tiles */
689 if ((flags & DC_EXEC) && IsStraightRoad(existing)) {
690 SetDisallowedRoadDirections(tile, dis_new);
691 MarkTileDirtyByTile(tile);
692 }
693 return CommandCost();
694 }
695 return_cmd_error(STR_ERROR_ALREADY_BUILT);
696 }
697 /* Disallow breaking end-of-line of someone else
698 * so trams can still reverse on this tile. */
699 if (rtt == RTT_TRAM && HasExactlyOneBit(existing)) {
700 Owner owner = GetRoadOwner(tile, rtt);
701 if (Company::IsValidID(owner)) {
702 CommandCost ret = CheckOwnership(owner);
703 if (ret.Failed()) return ret;
704 }
705 }
706 break;
707 }
708
709 case ROAD_TILE_CROSSING:
710 if (RoadNoLevelCrossing(rt)) {
711 return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
712 }
713
714 other_bits = GetCrossingRoadBits(tile);
715 if (pieces & ComplementRoadBits(other_bits)) goto do_clear;
716 pieces = other_bits; // we need to pay for both roadbits
717
718 if (HasTileRoadType(tile, rtt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
719 break;
720
721 case ROAD_TILE_DEPOT:
722 if ((GetAnyRoadBits(tile, rtt) & pieces) == pieces) return_cmd_error(STR_ERROR_ALREADY_BUILT);
723 goto do_clear;
724
725 default: NOT_REACHED();
726 }
727 break;
728
729 case MP_RAILWAY: {
730 if (IsSteepSlope(tileh)) {
731 return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
732 }
733
734 /* Level crossings may only be built on these slopes */
735 if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) {
736 return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
737 }
738
739 if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
740
741 if (RoadNoLevelCrossing(rt)) {
742 return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
743 }
744
745 if (RailNoLevelCrossings(GetRailType(tile))) {
746 return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_RAIL);
747 }
748
749 Axis roaddir;
750 switch (GetTrackBits(tile)) {
751 case TRACK_BIT_X:
752 if (pieces & ROAD_X) goto do_clear;
753 roaddir = AXIS_Y;
754 break;
755
756 case TRACK_BIT_Y:
757 if (pieces & ROAD_Y) goto do_clear;
758 roaddir = AXIS_X;
759 break;
760
761 default: goto do_clear;
762 }
763
764 CommandCost ret = EnsureNoVehicleOnGround(tile);
765 if (ret.Failed()) return ret;
766
767 if (flags & DC_EXEC) {
768 Track railtrack = AxisToTrack(OtherAxis(roaddir));
769 YapfNotifyTrackLayoutChange(tile, railtrack);
770 /* Update company infrastructure counts. A level crossing has two road bits. */
771 UpdateCompanyRoadInfrastructure(rt, company, 2);
772
773 /* Update rail count for level crossings. The plain track is already
774 * counted, so only add the difference to the level crossing cost. */
775 Company *c = Company::GetIfValid(GetTileOwner(tile));
776 if (c != nullptr) {
777 c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR - 1;
778 DirtyCompanyInfrastructureWindows(c->index);
779 }
780
781 /* Always add road to the roadtypes (can't draw without it) */
782 bool reserved = HasBit(GetRailReservationTrackBits(tile), railtrack);
783 MakeRoadCrossing(tile, company, company, GetTileOwner(tile), roaddir, GetRailType(tile), rtt == RTT_ROAD ? rt : INVALID_ROADTYPE, (rtt == RTT_TRAM) ? rt : INVALID_ROADTYPE, town_id);
784 SetCrossingReservation(tile, reserved);
785 UpdateLevelCrossing(tile, false);
786 MarkDirtyAdjacentLevelCrossingTiles(tile, GetCrossingRoadAxis(tile));
787 MarkTileDirtyByTile(tile);
788 }
789 return CommandCost(EXPENSES_CONSTRUCTION, 2 * RoadBuildCost(rt));
790 }
791
792 case MP_STATION: {
793 if ((GetAnyRoadBits(tile, rtt) & pieces) == pieces) return_cmd_error(STR_ERROR_ALREADY_BUILT);
794 if (!IsDriveThroughStopTile(tile)) goto do_clear;
795
796 RoadBits curbits = AxisToRoadBits(DiagDirToAxis(GetRoadStopDir(tile)));
797 if (pieces & ~curbits) goto do_clear;
798 pieces = curbits; // we need to pay for both roadbits
799
800 if (HasTileRoadType(tile, rtt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
801 break;
802 }
803
804 case MP_TUNNELBRIDGE: {
805 if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) goto do_clear;
806 /* Only allow building the outern roadbit, so building long roads stops at existing bridges */
807 if (MirrorRoadBits(DiagDirToRoadBits(GetTunnelBridgeDirection(tile))) != pieces) goto do_clear;
808 if (HasTileRoadType(tile, rtt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
809 /* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
810 CommandCost ret = TunnelBridgeIsFree(tile, GetOtherTunnelBridgeEnd(tile));
811 if (ret.Failed()) return ret;
812 break;
813 }
814
815 default: {
816 do_clear:;
817 need_to_clear = true;
818 break;
819 }
820 }
821
822 if (need_to_clear) {
823 CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
824 if (ret.Failed()) return ret;
825 cost.AddCost(ret);
826 }
827
828 if (other_bits != pieces) {
829 /* Check the foundation/slopes when adding road/tram bits */
830 CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
831 /* Return an error if we need to build a foundation (ret != 0) but the
832 * current setting is turned off */
833 if (ret.Failed() || (ret.GetCost() != 0 && !_settings_game.construction.build_on_slopes)) {
834 return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
835 }
836 cost.AddCost(ret);
837 }
838
839 if (!need_to_clear) {
840 if (IsTileType(tile, MP_ROAD)) {
841 /* Don't put the pieces that already exist */
842 pieces &= ComplementRoadBits(existing);
843
844 /* Check if new road bits will have the same foundation as other existing road types */
845 if (IsNormalRoad(tile)) {
846 Slope slope = GetTileSlope(tile);
847 Foundation found_new = GetRoadFoundation(slope, pieces | existing);
848
849 RoadBits bits = GetRoadBits(tile, OtherRoadTramType(rtt));
850 /* do not check if there are not road bits of given type */
851 if (bits != ROAD_NONE && GetRoadFoundation(slope, bits) != found_new) {
852 return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
853 }
854 }
855 }
856
857 CommandCost ret = EnsureNoVehicleOnGround(tile);
858 if (ret.Failed()) return ret;
859
860 if (IsNormalRoadTile(tile)) {
861 /* If the road types don't match, try to convert only if vehicles of
862 * the new road type are not powered on the present road type and vehicles of
863 * the present road type are powered on the new road type. */
864 RoadType existing_rt = GetRoadType(tile, rtt);
865 if (existing_rt != INVALID_ROADTYPE && existing_rt != rt) {
866 if (HasPowerOnRoad(rt, existing_rt)) {
867 rt = existing_rt;
868 } else if (HasPowerOnRoad(existing_rt, rt)) {
869 CommandCost ret = Command<CMD_CONVERT_ROAD>::Do(flags, tile, tile, rt);
870 if (ret.Failed()) return ret;
871 cost.AddCost(ret);
872 } else {
873 return CMD_ERROR;
874 }
875 }
876 }
877 }
878
879 uint num_pieces = (!need_to_clear && IsTileType(tile, MP_TUNNELBRIDGE)) ?
880 /* There are 2 pieces on *every* tile of the bridge or tunnel */
881 2 * (GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2) :
882 /* Count pieces */
883 CountBits(pieces);
884
885 cost.AddCost(num_pieces * RoadBuildCost(rt));
886
887 if (flags & DC_EXEC) {
888 switch (GetTileType(tile)) {
889 case MP_ROAD: {
890 RoadTileType rttype = GetRoadTileType(tile);
891 if (existing == ROAD_NONE || rttype == ROAD_TILE_CROSSING) {
892 SetRoadType(tile, rtt, rt);
893 SetRoadOwner(tile, rtt, company);
894 if (rtt == RTT_ROAD) SetTownIndex(tile, town_id);
895 }
896 if (rttype != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rtt);
897 break;
898 }
899
900 case MP_TUNNELBRIDGE: {
901 TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
902
903 SetRoadType(other_end, rtt, rt);
904 SetRoadType(tile, rtt, rt);
905 SetRoadOwner(other_end, rtt, company);
906 SetRoadOwner(tile, rtt, company);
907
908 /* Mark tiles dirty that have been repaved */
909 if (IsBridge(tile)) {
910 MarkBridgeDirty(tile);
911 } else {
912 MarkTileDirtyByTile(other_end);
913 MarkTileDirtyByTile(tile);
914 }
915 break;
916 }
917
918 case MP_STATION: {
919 assert(IsDriveThroughStopTile(tile));
920 SetRoadType(tile, rtt, rt);
921 SetRoadOwner(tile, rtt, company);
922 break;
923 }
924
925 default:
926 MakeRoadNormal(tile, pieces, (rtt == RTT_ROAD) ? rt : INVALID_ROADTYPE, (rtt == RTT_TRAM) ? rt : INVALID_ROADTYPE, town_id, company, company);
927 break;
928 }
929
930 /* Update company infrastructure count. */
931 if (IsTileType(tile, MP_TUNNELBRIDGE)) num_pieces *= TUNNELBRIDGE_TRACKBIT_FACTOR;
932 UpdateCompanyRoadInfrastructure(rt, GetRoadOwner(tile, rtt), num_pieces);
933
934 if (rtt == RTT_ROAD && IsNormalRoadTile(tile)) {
935 existing |= pieces;
936 SetDisallowedRoadDirections(tile, IsStraightRoad(existing) ?
937 GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE);
938 }
939
940 MarkTileDirtyByTile(tile);
941 }
942 return cost;
943 }
944
952 static bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir)
953 {
954 tile += TileOffsByDiagDir(dir);
955 if (!IsValidTile(tile) || !MayHaveRoad(tile)) return false;
956
957 RoadTramType rtt = GetRoadTramType(rt);
958 RoadType existing = GetRoadType(tile, rtt);
959 if (existing == INVALID_ROADTYPE) return false;
960 if (!HasPowerOnRoad(existing, rt) && !HasPowerOnRoad(rt, existing)) return false;
961
962 RoadBits bits = GetAnyRoadBits(tile, rtt, false);
963 return (bits & DiagDirToRoadBits(ReverseDiagDir(dir))) != 0;
964 }
965
981 CommandCost CmdBuildLongRoad(DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, DisallowedRoadDirections drd, bool start_half, bool end_half, bool is_ai)
982 {
983 if (start_tile >= MapSize()) return CMD_ERROR;
984
985 if (!ValParamRoadType(rt) || !IsValidAxis(axis) || !IsValidDisallowedRoadDirections(drd)) return CMD_ERROR;
986
987 /* Only drag in X or Y direction dictated by the direction variable */
988 if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
989 if (axis == AXIS_Y && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
990
991 DiagDirection dir = AxisToDiagDir(axis);
992
993 /* Swap direction, also the half-tile drag vars. */
994 if (start_tile > end_tile || (start_tile == end_tile && start_half)) {
995 dir = ReverseDiagDir(dir);
996 start_half = !start_half;
997 end_half = !end_half;
998 if (drd == DRD_NORTHBOUND || drd == DRD_SOUTHBOUND) drd ^= DRD_BOTH;
999 }
1000
1001 /* On the X-axis, we have to swap the initial bits, so they
1002 * will be interpreted correctly in the GTTS. Furthermore
1003 * when you just 'click' on one tile to build them. */
1004 if ((drd == DRD_NORTHBOUND || drd == DRD_SOUTHBOUND) && (axis == AXIS_Y) == (start_tile == end_tile && start_half == end_half)) drd ^= DRD_BOTH;
1005
1006 CommandCost cost(EXPENSES_CONSTRUCTION);
1007 CommandCost last_error = CMD_ERROR;
1008 TileIndex tile = start_tile;
1009 bool had_bridge = false;
1010 bool had_tunnel = false;
1011 bool had_success = false;
1012
1013 /* Start tile is the first tile clicked by the user. */
1014 for (;;) {
1015 RoadBits bits = AxisToRoadBits(axis);
1016
1017 /* Determine which road parts should be built. */
1018 if (!is_ai && start_tile != end_tile) {
1019 /* Only build the first and last roadbit if they can connect to something. */
1020 if (tile == end_tile && !CanConnectToRoad(tile, rt, dir)) {
1021 bits = DiagDirToRoadBits(ReverseDiagDir(dir));
1022 } else if (tile == start_tile && !CanConnectToRoad(tile, rt, ReverseDiagDir(dir))) {
1023 bits = DiagDirToRoadBits(dir);
1024 }
1025 } else {
1026 /* Road parts only have to be built at the start tile or at the end tile. */
1027 if (tile == end_tile && !end_half) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
1028 if (tile == start_tile && start_half) bits &= DiagDirToRoadBits(dir);
1029 }
1030
1031 CommandCost ret = Command<CMD_BUILD_ROAD>::Do(flags, tile, bits, rt, drd, 0);
1032 if (ret.Failed()) {
1033 last_error = ret;
1034 if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {
1035 if (is_ai) return last_error;
1036 break;
1037 }
1038 } else {
1039 had_success = true;
1040 /* Only pay for the upgrade on one side of the bridges and tunnels */
1041 if (IsTileType(tile, MP_TUNNELBRIDGE)) {
1042 if (IsBridge(tile)) {
1043 if (!had_bridge || GetTunnelBridgeDirection(tile) == dir) {
1044 cost.AddCost(ret);
1045 }
1046 had_bridge = true;
1047 } else { // IsTunnel(tile)
1048 if (!had_tunnel || GetTunnelBridgeDirection(tile) == dir) {
1049 cost.AddCost(ret);
1050 }
1051 had_tunnel = true;
1052 }
1053 } else {
1054 cost.AddCost(ret);
1055 }
1056 }
1057
1058 if (tile == end_tile) break;
1059
1060 tile += TileOffsByDiagDir(dir);
1061 }
1062
1063 return had_success ? cost : last_error;
1064 }
1065
1077 std::tuple<CommandCost, Money> CmdRemoveLongRoad(DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, bool start_half, bool end_half)
1078 {
1079 CommandCost cost(EXPENSES_CONSTRUCTION);
1080
1081 if (start_tile >= MapSize()) return { CMD_ERROR, 0 };
1082 if (!ValParamRoadType(rt) || !IsValidAxis(axis)) return { CMD_ERROR, 0 };
1083
1084 /* Only drag in X or Y direction dictated by the direction variable */
1085 if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return { CMD_ERROR, 0 }; // x-axis
1086 if (axis == AXIS_Y && TileX(start_tile) != TileX(end_tile)) return { CMD_ERROR, 0 }; // y-axis
1087
1088 /* Swap start and ending tile, also the half-tile drag vars. */
1089 if (start_tile > end_tile || (start_tile == end_tile && start_half)) {
1090 std::swap(start_tile, end_tile);
1091 std::swap(start_half, end_half);
1092 }
1093
1094 Money money_available = GetAvailableMoneyForCommand();
1095 Money money_spent = 0;
1096 TileIndex tile = start_tile;
1097 CommandCost last_error = CMD_ERROR;
1098 bool had_success = false;
1099 /* Start tile is the small number. */
1100 for (;;) {
1101 RoadBits bits = AxisToRoadBits(axis);
1102
1103 if (tile == end_tile && !end_half) bits &= ROAD_NW | ROAD_NE;
1104 if (tile == start_tile && start_half) bits &= ROAD_SE | ROAD_SW;
1105
1106 /* try to remove the halves. */
1107 if (bits != 0) {
1108 RoadTramType rtt = GetRoadTramType(rt);
1109 CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rtt, true);
1110 if (ret.Succeeded()) {
1111 if (flags & DC_EXEC) {
1112 money_spent += ret.GetCost();
1113 if (money_spent > 0 && money_spent > money_available) {
1114 return { cost, std::get<0>(Command<CMD_REMOVE_LONG_ROAD>::Do(flags & ~DC_EXEC, end_tile, start_tile, rt, axis, start_half, end_half)).GetCost() };
1115 }
1116 RemoveRoad(tile, flags, bits, rtt, true, false);
1117 }
1118 cost.AddCost(ret);
1119 had_success = true;
1120 } else {
1121 /* Some errors are more equal than others. */
1122 switch (last_error.GetErrorMessage()) {
1123 case STR_ERROR_OWNED_BY:
1124 case STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS:
1125 break;
1126 default:
1127 last_error = ret;
1128 }
1129 }
1130 }
1131
1132 if (tile == end_tile) break;
1133
1134 tile += (axis == AXIS_Y) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
1135 }
1136
1137 return { had_success ? cost : last_error, 0 };
1138 }
1139
1151 CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt, DiagDirection dir)
1152 {
1153 if (!ValParamRoadType(rt) || !IsValidDiagDirection(dir)) return CMD_ERROR;
1154
1155 CommandCost cost(EXPENSES_CONSTRUCTION);
1156
1157 Slope tileh = GetTileSlope(tile);
1158 if (tileh != SLOPE_FLAT) {
1159 if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) {
1160 return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
1161 }
1162 cost.AddCost(_price[PR_BUILD_FOUNDATION]);
1163 }
1164
1165 cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile));
1166 if (cost.Failed()) return cost;
1167
1168 if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
1169
1170 if (!Depot::CanAllocateItem()) return CMD_ERROR;
1171
1172 if (flags & DC_EXEC) {
1173 Depot *dep = new Depot(tile);
1174 dep->build_date = _date;
1175
1176 /* A road depot has two road bits. */
1177 UpdateCompanyRoadInfrastructure(rt, _current_company, ROAD_DEPOT_TRACKBIT_FACTOR);
1178
1179 MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
1180 MarkTileDirtyByTile(tile);
1181 MakeDefaultName(dep);
1182 }
1183 cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]);
1184 return cost;
1185 }
1186
1187 static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
1188 {
1189 if (_current_company != OWNER_WATER) {
1190 CommandCost ret = CheckTileOwnership(tile);
1191 if (ret.Failed()) return ret;
1192 }
1193
1194 CommandCost ret = EnsureNoVehicleOnGround(tile);
1195 if (ret.Failed()) return ret;
1196
1197 if (flags & DC_EXEC) {
1198 Company *c = Company::GetIfValid(GetTileOwner(tile));
1199 if (c != nullptr) {
1200 /* A road depot has two road bits. */
1201 RoadType rt = GetRoadTypeRoad(tile);
1202 if (rt == INVALID_ROADTYPE) rt = GetRoadTypeTram(tile);
1203 c->infrastructure.road[rt] -= ROAD_DEPOT_TRACKBIT_FACTOR;
1204 DirtyCompanyInfrastructureWindows(c->index);
1205 }
1206
1207 delete Depot::GetByTile(tile);
1208 DoClearSquare(tile);
1209 }
1210
1211 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_ROAD]);
1212 }
1213
1214 static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
1215 {
1216 switch (GetRoadTileType(tile)) {
1217 case ROAD_TILE_NORMAL: {
1218 RoadBits b = GetAllRoadBits(tile);
1219
1220 /* Clear the road if only one piece is on the tile OR we are not using the DC_AUTO flag */
1221 if ((HasExactlyOneBit(b) && GetRoadBits(tile, RTT_TRAM) == ROAD_NONE) || !(flags & DC_AUTO)) {
1222 CommandCost ret(EXPENSES_CONSTRUCTION);
1223 for (RoadTramType rtt : _roadtramtypes) {
1224 if (!MayHaveRoad(tile) || GetRoadType(tile, rtt) == INVALID_ROADTYPE) continue;
1225
1226 CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rtt), rtt, true);
1227 if (tmp_ret.Failed()) return tmp_ret;
1228 ret.AddCost(tmp_ret);
1229 }
1230 return ret;
1231 }
1232 return_cmd_error(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
1233 }
1234
1235 case ROAD_TILE_CROSSING: {
1236 CommandCost ret(EXPENSES_CONSTRUCTION);
1237
1238 if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
1239
1240 /* Must iterate over the roadtypes in a reverse manner because
1241 * tram tracks must be removed before the road bits. */
1242 for (RoadTramType rtt : { RTT_TRAM, RTT_ROAD }) {
1243 if (!MayHaveRoad(tile) || GetRoadType(tile, rtt) == INVALID_ROADTYPE) continue;
1244
1245 CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rtt, false);
1246 if (tmp_ret.Failed()) return tmp_ret;
1247 ret.AddCost(tmp_ret);
1248 }
1249
1250 if (flags & DC_EXEC) {
1251 Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
1252 }
1253 return ret;
1254 }
1255
1256 default:
1257 case ROAD_TILE_DEPOT:
1258 if (flags & DC_AUTO) {
1259 return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
1260 }
1261 return RemoveRoadDepot(tile, flags);
1262 }
1263 }
1264
1265
1266 struct DrawRoadTileStruct {
1267 uint16 image;
1268 byte subcoord_x;
1269 byte subcoord_y;
1270 };
1271
1272 #include "table/road_land.h"
1273
1281 static Foundation GetRoadFoundation(Slope tileh, RoadBits bits)
1282 {
1283 /* Flat land and land without a road doesn't require a foundation */
1284 if (tileh == SLOPE_FLAT || bits == ROAD_NONE) return FOUNDATION_NONE;
1285
1286 /* Steep slopes behave the same as slopes with one corner raised. */
1287 if (IsSteepSlope(tileh)) {
1288 tileh = SlopeWithOneCornerRaised(GetHighestSlopeCorner(tileh));
1289 }
1290
1291 /* Leveled RoadBits on a slope */
1292 if ((_invalid_tileh_slopes_road[0][tileh] & bits) == ROAD_NONE) return FOUNDATION_LEVELED;
1293
1294 /* Straight roads without foundation on a slope */
1295 if (!IsSlopeWithOneCornerRaised(tileh) &&
1296 (_invalid_tileh_slopes_road[1][tileh] & bits) == ROAD_NONE)
1297 return FOUNDATION_NONE;
1298
1299 /* Roads on steep Slopes or on Slopes with one corner raised */
1300 return (bits == ROAD_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y);
1301 }
1302
1303 const byte _road_sloped_sprites[14] = {
1304 0, 0, 2, 0,
1305 0, 1, 0, 0,
1306 3, 0, 0, 0,
1307 0, 0
1308 };
1309
1316 static uint GetRoadSpriteOffset(Slope slope, RoadBits bits)
1317 {
1318 if (slope != SLOPE_FLAT) {
1319 switch (slope) {
1320 case SLOPE_NE: return 11;
1321 case SLOPE_SE: return 12;
1322 case SLOPE_SW: return 13;
1323 case SLOPE_NW: return 14;
1324 default: NOT_REACHED();
1325 }
1326 } else {
1327 static const uint offsets[] = {
1328 0, 18, 17, 7,
1329 16, 0, 10, 5,
1330 15, 8, 1, 4,
1331 9, 3, 6, 2
1332 };
1333 return offsets[bits];
1334 }
1335 }
1336
1346 static bool DrawRoadAsSnowDesert(TileIndex tile, Roadside roadside)
1347 {
1348 return (IsOnSnow(tile) &&
1349 !(_settings_game.game_creation.landscape == LT_TROPIC && HasGrfMiscBit(GMB_DESERT_PAVED_ROADS) &&
1350 roadside != ROADSIDE_BARREN && roadside != ROADSIDE_GRASS && roadside != ROADSIDE_GRASS_ROAD_WORKS));
1351 }
1352
1359 void DrawRoadTypeCatenary(const TileInfo *ti, RoadType rt, RoadBits rb)
1360 {
1361 /* Don't draw the catenary under a low bridge */
1362 if (IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_CATENARY)) {
1363 int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
1364
1365 if (height <= GetTileMaxZ(ti->tile) + 1) return;
1366 }
1367
1368 if (CountBits(rb) > 2) {
1369 /* On junctions we check whether neighbouring tiles also have catenary, and possibly
1370 * do not draw catenary towards those neighbours, which do not have catenary. */
1371 RoadBits rb_new = ROAD_NONE;
1372 for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
1373 if (rb & DiagDirToRoadBits(dir)) {
1374 TileIndex neighbour = TileAddByDiagDir(ti->tile, dir);
1375 if (MayHaveRoad(neighbour)) {
1376 RoadType rt_road = GetRoadTypeRoad(neighbour);
1377 RoadType rt_tram = GetRoadTypeTram(neighbour);
1378
1379 if ((rt_road != INVALID_ROADTYPE && HasRoadCatenary(rt_road)) ||
1380 (rt_tram != INVALID_ROADTYPE && HasRoadCatenary(rt_tram))) {
1381 rb_new |= DiagDirToRoadBits(dir);
1382 }
1383 }
1384 }
1385 }
1386 if (CountBits(rb_new) >= 2) rb = rb_new;
1387 }
1388
1389 const RoadTypeInfo* rti = GetRoadTypeInfo(rt);
1390 SpriteID front = GetCustomRoadSprite(rti, ti->tile, ROTSG_CATENARY_FRONT);
1391 SpriteID back = GetCustomRoadSprite(rti, ti->tile, ROTSG_CATENARY_BACK);
1392
1393 if (front != 0 || back != 0) {
1394 if (front != 0) front += GetRoadSpriteOffset(ti->tileh, rb);
1395 if (back != 0) back += GetRoadSpriteOffset(ti->tileh, rb);
1396 } else if (ti->tileh != SLOPE_FLAT) {
1397 back = SPR_TRAMWAY_BACK_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1];
1398 front = SPR_TRAMWAY_FRONT_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1];
1399 } else {
1400 back = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[rb];
1401 front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[rb];
1402 }
1403
1404 /* Catenary uses 1st company colour to help identify owner.
1405 * For tiles with OWNER_TOWN or OWNER_NONE, recolour CC to grey as a neutral colour. */
1406 Owner owner = GetRoadOwner(ti->tile, GetRoadTramType(rt));
1407 PaletteID pal = (owner == OWNER_NONE || owner == OWNER_TOWN ? GENERAL_SPRITE_COLOUR(COLOUR_GREY) : COMPANY_SPRITE_COLOUR(owner));
1408 int z_wires = (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT) + BB_HEIGHT_UNDER_BRIDGE;
1409 if (back != 0) {
1410 /* The "back" sprite contains the west, north and east pillars.
1411 * We cut the sprite at 3/8 of the west/east edges to create 3 sprites.
1412 * 3/8 is chosen so that sprites can somewhat graphically extend into the tile. */
1413 static const int INF = 1000;
1414 static const SubSprite west = { -INF, -INF, -12, INF };
1415 static const SubSprite north = { -12, -INF, 12, INF };
1416 static const SubSprite east = { 12, -INF, INF, INF };
1417 AddSortableSpriteToDraw(back, pal, ti->x, ti->y, 16, 1, z_wires, ti->z, IsTransparencySet(TO_CATENARY), 15, 0, GetSlopePixelZInCorner(ti->tileh, CORNER_W), &west);
1418 AddSortableSpriteToDraw(back, pal, ti->x, ti->y, 1, 1, z_wires, ti->z, IsTransparencySet(TO_CATENARY), 0, 0, GetSlopePixelZInCorner(ti->tileh, CORNER_N), &north);
1419 AddSortableSpriteToDraw(back, pal, ti->x, ti->y, 1, 16, z_wires, ti->z, IsTransparencySet(TO_CATENARY), 0, 15, GetSlopePixelZInCorner(ti->tileh, CORNER_E), &east);
1420 }
1421 if (front != 0) {
1422 /* Draw the "front" sprite (containing south pillar and wires) at a Z height that is both above the vehicles and above the "back" pillars. */
1423 AddSortableSpriteToDraw(front, pal, ti->x, ti->y, 16, 16, z_wires + 1, ti->z, IsTransparencySet(TO_CATENARY), 0, 0, z_wires);
1424 }
1425 }
1426
1431 void DrawRoadCatenary(const TileInfo *ti)
1432 {
1433 RoadBits road = ROAD_NONE;
1434 RoadBits tram = ROAD_NONE;
1435
1436 if (IsTileType(ti->tile, MP_ROAD)) {
1437 if (IsNormalRoad(ti->tile)) {
1438 road = GetRoadBits(ti->tile, RTT_ROAD);
1439 tram = GetRoadBits(ti->tile, RTT_TRAM);
1440 } else if (IsLevelCrossing(ti->tile)) {
1441 tram = road = (GetCrossingRailAxis(ti->tile) == AXIS_Y ? ROAD_X : ROAD_Y);
1442 }
1443 } else if (IsTileType(ti->tile, MP_STATION)) {
1444 if (IsRoadStop(ti->tile)) {
1445 if (IsDriveThroughStopTile(ti->tile)) {
1446 Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y;
1447 tram = road = (axis == AXIS_X ? ROAD_X : ROAD_Y);
1448 } else {
1449 tram = road = DiagDirToRoadBits(GetRoadStopDir(ti->tile));
1450 }
1451 }
1452 } else {
1453 // No road here, no catenary to draw
1454 return;
1455 }
1456
1457 RoadType rt = GetRoadTypeRoad(ti->tile);
1458 if (rt != INVALID_ROADTYPE && HasRoadCatenaryDrawn(rt)) {
1459 DrawRoadTypeCatenary(ti, rt, road);
1460 }
1461
1462 rt = GetRoadTypeTram(ti->tile);
1463 if (rt != INVALID_ROADTYPE && HasRoadCatenaryDrawn(rt)) {
1464 DrawRoadTypeCatenary(ti, rt, tram);
1465 }
1466 }
1467
1477 static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int h, bool transparent)
1478 {
1479 int x = ti->x | dx;
1480 int y = ti->y | dy;
1481 int z = ti->z;
1482 if (ti->tileh != SLOPE_FLAT) z = GetSlopePixelZ(x, y);
1483 AddSortableSpriteToDraw(img, PAL_NONE, x, y, 2, 2, h, z, transparent);
1484 }
1485
1495 void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset, bool draw_underlay)
1496 {
1497 if (draw_underlay) {
1498 /* Road underlay takes precedence over tram */
1499 if (road_rti != nullptr) {
1500 if (road_rti->UsesOverlay()) {
1501 SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_GROUND);
1502 DrawGroundSprite(ground + road_offset, pal);
1503 }
1504 } else {
1505 if (tram_rti->UsesOverlay()) {
1506 SpriteID ground = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_GROUND);
1507 DrawGroundSprite(ground + tram_offset, pal);
1508 } else {
1509 DrawGroundSprite(SPR_TRAMWAY_TRAM + tram_offset, pal);
1510 }
1511 }
1512 }
1513
1514 /* Draw road overlay */
1515 if (road_rti != nullptr) {
1516 if (road_rti->UsesOverlay()) {
1517 SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_OVERLAY);
1518 if (ground != 0) DrawGroundSprite(ground + road_offset, pal);
1519 }
1520 }
1521
1522 /* Draw tram overlay */
1523 if (tram_rti != nullptr) {
1524 if (tram_rti->UsesOverlay()) {
1525 SpriteID ground = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_OVERLAY);
1526 if (ground != 0) DrawGroundSprite(ground + tram_offset, pal);
1527 } else if (road_rti != nullptr) {
1528 DrawGroundSprite(SPR_TRAMWAY_OVERLAY + tram_offset, pal);
1529 }
1530 }
1531 }
1532
1541 static SpriteID GetRoadGroundSprite(const TileInfo *ti, Roadside roadside, const RoadTypeInfo *rti, uint offset, PaletteID *pal)
1542 {
1543 /* Draw bare ground sprite if no road or road uses overlay system. */
1544 if (rti == nullptr || rti->UsesOverlay()) {
1545 if (DrawRoadAsSnowDesert(ti->tile, roadside)) {
1546 return SPR_FLAT_SNOW_DESERT_TILE + SlopeToSpriteOffset(ti->tileh);
1547 }
1548
1549 switch (roadside) {
1550 case ROADSIDE_BARREN: *pal = PALETTE_TO_BARE_LAND;
1551 return SPR_FLAT_GRASS_TILE + SlopeToSpriteOffset(ti->tileh);
1552 case ROADSIDE_GRASS:
1553 case ROADSIDE_GRASS_ROAD_WORKS: return SPR_FLAT_GRASS_TILE + SlopeToSpriteOffset(ti->tileh);
1554 default: break; // Paved
1555 }
1556 }
1557
1558 /* Draw original road base sprite */
1559 SpriteID image = SPR_ROAD_Y + offset;
1560 if (DrawRoadAsSnowDesert(ti->tile, roadside)) {
1561 image += 19;
1562 } else {
1563 switch (roadside) {
1564 case ROADSIDE_BARREN: *pal = PALETTE_TO_BARE_LAND; break;
1565 case ROADSIDE_GRASS: break;
1566 case ROADSIDE_GRASS_ROAD_WORKS: break;
1567 default: image -= 19; break; // Paved
1568 }
1569 }
1570
1571 return image;
1572 }
1573
1578 static void DrawRoadBits(TileInfo *ti)
1579 {
1580 RoadBits road = GetRoadBits(ti->tile, RTT_ROAD);
1581 RoadBits tram = GetRoadBits(ti->tile, RTT_TRAM);
1582
1583 RoadType road_rt = GetRoadTypeRoad(ti->tile);
1584 RoadType tram_rt = GetRoadTypeTram(ti->tile);
1585 const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
1586 const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
1587
1588 if (ti->tileh != SLOPE_FLAT) {
1589 DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
1590 /* DrawFoundation() modifies ti. */
1591 }
1592
1593 /* Determine sprite offsets */
1594 uint road_offset = GetRoadSpriteOffset(ti->tileh, road);
1595 uint tram_offset = GetRoadSpriteOffset(ti->tileh, tram);
1596
1597 /* Draw baseset underlay */
1598 Roadside roadside = GetRoadside(ti->tile);
1599
1600 PaletteID pal = PAL_NONE;
1601 SpriteID image = GetRoadGroundSprite(ti, roadside, road_rti, road == ROAD_NONE ? tram_offset : road_offset, &pal);
1602 DrawGroundSprite(image, pal);
1603
1604 DrawRoadOverlays(ti, pal, road_rti, tram_rti, road_offset, tram_offset);
1605
1606 /* Draw one way */
1607 if (road_rti != nullptr) {
1608 DisallowedRoadDirections drd = GetDisallowedRoadDirections(ti->tile);
1609 if (drd != DRD_NONE) {
1610 SpriteID oneway = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_ONEWAY);
1611
1612 if (oneway == 0) oneway = SPR_ONEWAY_BASE;
1613
1614 if ((ti->tileh == SLOPE_NE) || (ti->tileh == SLOPE_NW)) {
1615 oneway += SPR_ONEWAY_SLOPE_N_OFFSET;
1616 } else if ((ti->tileh == SLOPE_SE) || (ti->tileh == SLOPE_SW)) {
1617 oneway += SPR_ONEWAY_SLOPE_S_OFFSET;
1618 }
1619
1620 DrawGroundSpriteAt(oneway + drd - 1 + ((road == ROAD_X) ? 0 : 3), PAL_NONE, 8, 8, GetPartialPixelZ(8, 8, ti->tileh));
1621 }
1622 }
1623
1624 if (HasRoadWorks(ti->tile)) {
1625 /* Road works */
1626 DrawGroundSprite((road | tram) & ROAD_X ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE);
1627 return;
1628 }
1629
1630 /* Draw road, tram catenary */
1631 DrawRoadCatenary(ti);
1632
1633 /* Return if full detail is disabled, or we are zoomed fully out. */
1634 if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
1635
1636 /* Do not draw details (street lights, trees) under low bridge */
1637 if (IsBridgeAbove(ti->tile) && (roadside == ROADSIDE_TREES || roadside == ROADSIDE_STREET_LIGHTS)) {
1638 int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
1639 int minz = GetTileMaxZ(ti->tile) + 2;
1640
1641 if (roadside == ROADSIDE_TREES) minz++;
1642
1643 if (height < minz) return;
1644 }
1645
1646 /* If there are no road bits, return, as there is nothing left to do */
1647 if (HasAtMostOneBit(road)) return;
1648
1649 if (roadside == ROADSIDE_TREES && IsInvisibilitySet(TO_TREES)) return;
1650 bool is_transparent = roadside == ROADSIDE_TREES && IsTransparencySet(TO_TREES);
1651
1652 /* Draw extra details. */
1653 for (const DrawRoadTileStruct *drts = _road_display_table[roadside][road | tram]; drts->image != 0; drts++) {
1654 DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10, is_transparent);
1655 }
1656 }
1657
1659 static void DrawTile_Road(TileInfo *ti)
1660 {
1661 switch (GetRoadTileType(ti->tile)) {
1662 case ROAD_TILE_NORMAL:
1663 DrawRoadBits(ti);
1664 break;
1665
1666 case ROAD_TILE_CROSSING: {
1667 if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
1668
1669 Axis axis = GetCrossingRailAxis(ti->tile);
1670
1671 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
1672
1673 RoadType road_rt = GetRoadTypeRoad(ti->tile);
1674 RoadType tram_rt = GetRoadTypeTram(ti->tile);
1675 const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
1676 const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
1677
1678 PaletteID pal = PAL_NONE;
1679
1680 /* Draw base ground */
1681 if (rti->UsesOverlay()) {
1682 SpriteID image = SPR_ROAD_Y + axis;
1683
1684 Roadside roadside = GetRoadside(ti->tile);
1685 if (DrawRoadAsSnowDesert(ti->tile, roadside)) {
1686 image += 19;
1687 } else {
1688 switch (roadside) {
1689 case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break;
1690 case ROADSIDE_GRASS: break;
1691 default: image -= 19; break; // Paved
1692 }
1693 }
1694
1695 DrawGroundSprite(image, pal);
1696 } else {
1697 SpriteID image = rti->base_sprites.crossing + axis;
1698 if (IsCrossingBarred(ti->tile)) image += 2;
1699
1700 Roadside roadside = GetRoadside(ti->tile);
1701 if (DrawRoadAsSnowDesert(ti->tile, roadside)) {
1702 image += 8;
1703 } else {
1704 switch (roadside) {
1705 case ROADSIDE_BARREN: pal = PALETTE_TO_BARE_LAND; break;
1706 case ROADSIDE_GRASS: break;
1707 default: image += 4; break; // Paved
1708 }
1709 }
1710
1711 DrawGroundSprite(image, pal);
1712 }
1713
1714 DrawRoadOverlays(ti, pal, road_rti, tram_rti, axis, axis);
1715
1716 /* Draw rail/PBS overlay */
1717 bool draw_pbs = _game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasCrossingReservation(ti->tile);
1718 if (rti->UsesOverlay()) {
1719 PaletteID pal = draw_pbs ? PALETTE_CRASH : PAL_NONE;
1720 SpriteID rail = GetCustomRailSprite(rti, ti->tile, RTSG_CROSSING) + axis;
1721 DrawGroundSprite(rail, pal);
1722
1723 const Axis road_axis = GetCrossingRoadAxis(ti->tile);
1724 const DiagDirection dir1 = AxisToDiagDir(road_axis);
1725 const DiagDirection dir2 = ReverseDiagDir(dir1);
1726 uint adjacent_diagdirs = 0;
1727 for (DiagDirection dir : { dir1, dir2 }) {
1728 const TileIndex t = TileAddByDiagDir(ti->tile, dir);
1729 if (t < MapSize() && IsLevelCrossingTile(t) && GetCrossingRoadAxis(t) == road_axis) {
1730 SetBit(adjacent_diagdirs, dir);
1731 }
1732 }
1733
1734 switch (adjacent_diagdirs) {
1735 case 0:
1736 DrawRailTileSeq(ti, &_crossing_layout, TO_CATENARY, rail, 0, PAL_NONE);
1737 break;
1738
1739 case (1 << DIAGDIR_NE):
1740 DrawRailTileSeq(ti, &_crossing_layout_SW, TO_CATENARY, rail, 0, PAL_NONE);
1741 break;
1742
1743 case (1 << DIAGDIR_SE):
1744 DrawRailTileSeq(ti, &_crossing_layout_NW, TO_CATENARY, rail, 0, PAL_NONE);
1745 break;
1746
1747 case (1 << DIAGDIR_SW):
1748 DrawRailTileSeq(ti, &_crossing_layout_NE, TO_CATENARY, rail, 0, PAL_NONE);
1749 break;
1750
1751 case (1 << DIAGDIR_NW):
1752 DrawRailTileSeq(ti, &_crossing_layout_SE, TO_CATENARY, rail, 0, PAL_NONE);
1753 break;
1754
1755 default:
1756 /* Show no sprites */
1757 break;
1758 }
1759 } else if (draw_pbs || tram_rti != nullptr || road_rti->UsesOverlay()) {
1760 /* Add another rail overlay, unless there is only the base road sprite. */
1761 PaletteID pal = draw_pbs ? PALETTE_CRASH : PAL_NONE;
1762 SpriteID rail = GetCrossingRoadAxis(ti->tile) == AXIS_Y ? GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_x : GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_y;
1763 DrawGroundSprite(rail, pal);
1764 }
1765
1766 /* Draw road, tram catenary */
1767 DrawRoadCatenary(ti);
1768
1769 /* Draw rail catenary */
1770 if (HasRailCatenaryDrawn(GetRailType(ti->tile))) DrawRailCatenary(ti);
1771
1772 break;
1773 }
1774
1775 default:
1776 case ROAD_TILE_DEPOT: {
1777 if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
1778
1779 PaletteID palette = COMPANY_SPRITE_COLOUR(GetTileOwner(ti->tile));
1780
1781 RoadType road_rt = GetRoadTypeRoad(ti->tile);
1782 RoadType tram_rt = GetRoadTypeTram(ti->tile);
1783 const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt == INVALID_ROADTYPE ? tram_rt : road_rt);
1784
1785 int relocation = GetCustomRoadSprite(rti, ti->tile, ROTSG_DEPOT);
1786 bool default_gfx = relocation == 0;
1787 if (default_gfx) {
1788 if (HasBit(rti->flags, ROTF_CATENARY)) {
1789 if (_loaded_newgrf_features.tram == TRAMWAY_REPLACE_DEPOT_WITH_TRACK && road_rt == INVALID_ROADTYPE && !rti->UsesOverlay()) {
1790 /* Sprites with track only work for default tram */
1791 relocation = SPR_TRAMWAY_DEPOT_WITH_TRACK - SPR_ROAD_DEPOT;
1792 default_gfx = false;
1793 } else {
1794 /* Sprites without track are always better, if provided */
1795 relocation = SPR_TRAMWAY_DEPOT_NO_TRACK - SPR_ROAD_DEPOT;
1796 }
1797 }
1798 } else {
1799 relocation -= SPR_ROAD_DEPOT;
1800 }
1801
1802 DiagDirection dir = GetRoadDepotDirection(ti->tile);
1803 const DrawTileSprites *dts = &_road_depot[dir];
1804 DrawGroundSprite(dts->ground.sprite, PAL_NONE);
1805
1806 if (default_gfx) {
1807 uint offset = GetRoadSpriteOffset(SLOPE_FLAT, DiagDirToRoadBits(dir));
1808 if (rti->UsesOverlay()) {
1809 SpriteID ground = GetCustomRoadSprite(rti, ti->tile, ROTSG_OVERLAY);
1810 if (ground != 0) DrawGroundSprite(ground + offset, PAL_NONE);
1811 } else if (road_rt == INVALID_ROADTYPE) {
1812 DrawGroundSprite(SPR_TRAMWAY_OVERLAY + offset, PAL_NONE);
1813 }
1814 }
1815
1816 DrawRailTileSeq(ti, dts, TO_BUILDINGS, relocation, 0, palette);
1817 break;
1818 }
1819 }
1820 DrawBridgeMiddle(ti);
1821 }
1822
1830 void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
1831 {
1832 PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company);
1833
1834 const RoadTypeInfo* rti = GetRoadTypeInfo(rt);
1835 int relocation = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_DEPOT);
1836 bool default_gfx = relocation == 0;
1837 if (default_gfx) {
1838 if (HasBit(rti->flags, ROTF_CATENARY)) {
1839 if (_loaded_newgrf_features.tram == TRAMWAY_REPLACE_DEPOT_WITH_TRACK && RoadTypeIsTram(rt) && !rti->UsesOverlay()) {
1840 /* Sprites with track only work for default tram */
1841 relocation = SPR_TRAMWAY_DEPOT_WITH_TRACK - SPR_ROAD_DEPOT;
1842 default_gfx = false;
1843 } else {
1844 /* Sprites without track are always better, if provided */
1845 relocation = SPR_TRAMWAY_DEPOT_NO_TRACK - SPR_ROAD_DEPOT;
1846 }
1847 }
1848 } else {
1849 relocation -= SPR_ROAD_DEPOT;
1850 }
1851
1852 const DrawTileSprites *dts = &_road_depot[dir];
1853 DrawSprite(dts->ground.sprite, PAL_NONE, x, y);
1854
1855 if (default_gfx) {
1856 uint offset = GetRoadSpriteOffset(SLOPE_FLAT, DiagDirToRoadBits(dir));
1857 if (rti->UsesOverlay()) {
1858 SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_OVERLAY);
1859 if (ground != 0) DrawSprite(ground + offset, PAL_NONE, x, y);
1860 } else if (RoadTypeIsTram(rt)) {
1861 DrawSprite(SPR_TRAMWAY_OVERLAY + offset, PAL_NONE, x, y);
1862 }
1863 }
1864
1865 DrawRailTileSeqInGUI(x, y, dts, relocation, 0, palette);
1866 }
1867
1873 void UpdateNearestTownForRoadTiles(bool invalidate)
1874 {
1875 assert(!invalidate || _generating_world);
1876
1877 for (TileIndex t = 0; t < MapSize(); t++) {
1878 if (IsTileType(t, MP_ROAD) && !IsRoadDepot(t) && !HasTownOwnedRoad(t)) {
1879 TownID tid = INVALID_TOWN;
1880 if (!invalidate) {
1881 const Town *town = CalcClosestTownFromTile(t);
1882 if (town != nullptr) tid = town->index;
1883 }
1884 SetTownIndex(t, tid);
1885 }
1886 }
1887 }
1888
1889 static int GetSlopePixelZ_Road(TileIndex tile, uint x, uint y)
1890 {
1891
1892 if (IsNormalRoad(tile)) {
1893 int z;
1894 Slope tileh = GetTilePixelSlope(tile, &z);
1895 if (tileh == SLOPE_FLAT) return z;
1896
1897 Foundation f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
1898 z += ApplyPixelFoundationToSlope(f, &tileh);
1899 return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
1900 } else {
1901 return GetTileMaxPixelZ(tile);
1902 }
1903 }
1904
1905 static Foundation GetFoundation_Road(TileIndex tile, Slope tileh)
1906 {
1907 if (IsNormalRoad(tile)) {
1908 return GetRoadFoundation(tileh, GetAllRoadBits(tile));
1909 } else {
1910 return FlatteningFoundation(tileh);
1911 }
1912 }
1913
1914 static const Roadside _town_road_types[][2] = {
1915 { ROADSIDE_GRASS, ROADSIDE_GRASS },
1916 { ROADSIDE_PAVED, ROADSIDE_PAVED },
1917 { ROADSIDE_PAVED, ROADSIDE_PAVED },
1918 { ROADSIDE_TREES, ROADSIDE_TREES },
1919 { ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
1920 };
1921
1922 static const Roadside _town_road_types_2[][2] = {
1923 { ROADSIDE_GRASS, ROADSIDE_GRASS },
1924 { ROADSIDE_PAVED, ROADSIDE_PAVED },
1925 { ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
1926 { ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
1927 { ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
1928 };
1929
1930
1931 static void TileLoop_Road(TileIndex tile)
1932 {
1933 switch (_settings_game.game_creation.landscape) {
1934 case LT_ARCTIC:
1935 if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) {
1936 ToggleSnow(tile);
1937 MarkTileDirtyByTile(tile);
1938 }
1939 break;
1940
1941 case LT_TROPIC:
1942 if (GetTropicZone(tile) == TROPICZONE_DESERT && !IsOnDesert(tile)) {
1943 ToggleDesert(tile);
1944 MarkTileDirtyByTile(tile);
1945 }
1946 break;
1947 }
1948
1949 if (IsRoadDepot(tile)) return;
1950
1951 const Town *t = ClosestTownFromTile(tile, UINT_MAX);
1952 if (!HasRoadWorks(tile)) {
1953 HouseZonesBits grp = HZB_TOWN_EDGE;
1954
1955 if (t != nullptr) {
1956 grp = GetTownRadiusGroup(t, tile);
1957
1958 /* Show an animation to indicate road work */
1959 if (t->road_build_months != 0 &&
1960 (DistanceManhattan(t->xy, tile) < 8 || grp != HZB_TOWN_EDGE) &&
1961 IsNormalRoad(tile) && !HasAtMostOneBit(GetAllRoadBits(tile))) {
1962 if (GetFoundationSlope(tile) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile).Succeeded() && Chance16(1, 40)) {
1963 StartRoadWorks(tile);
1964
1965 if (_settings_client.sound.ambient) SndPlayTileFx(SND_21_ROAD_WORKS, tile);
1966 CreateEffectVehicleAbove(
1967 TileX(tile) * TILE_SIZE + 7,
1968 TileY(tile) * TILE_SIZE + 7,
1969 0,
1970 EV_BULLDOZER);
1971 MarkTileDirtyByTile(tile);
1972 return;
1973 }
1974 }
1975 }
1976
1977 {
1978 /* Adjust road ground type depending on 'grp' (grp is the distance to the center) */
1979 const Roadside *new_rs = (_settings_game.game_creation.landscape == LT_TOYLAND) ? _town_road_types_2[grp] : _town_road_types[grp];
1980 Roadside cur_rs = GetRoadside(tile);
1981
1982 /* We have our desired type, do nothing */
1983 if (cur_rs == new_rs[0]) return;
1984
1985 /* We have the pre-type of the desired type, switch to the desired type */
1986 if (cur_rs == new_rs[1]) {
1987 cur_rs = new_rs[0];
1988 /* We have barren land, install the pre-type */
1989 } else if (cur_rs == ROADSIDE_BARREN) {
1990 cur_rs = new_rs[1];
1991 /* We're totally off limits, remove any installation and make barren land */
1992 } else {
1993 cur_rs = ROADSIDE_BARREN;
1994 }
1995 SetRoadside(tile, cur_rs);
1996 MarkTileDirtyByTile(tile);
1997 }
1998 } else if (IncreaseRoadWorksCounter(tile)) {
1999 TerminateRoadWorks(tile);
2000
2001 if (_settings_game.economy.mod_road_rebuild) {
2002 /* Generate a nicer town surface */
2003 const RoadBits old_rb = GetAnyRoadBits(tile, RTT_ROAD);
2004 const RoadBits new_rb = CleanUpRoadBits(tile, old_rb);
2005
2006 if (old_rb != new_rb) {
2007 RemoveRoad(tile, DC_EXEC | DC_AUTO | DC_NO_WATER, (old_rb ^ new_rb), RTT_ROAD, true);
2008
2009 /* If new_rb is 0, there are now no road pieces left and the tile is no longer a road tile */
2010 if (new_rb == 0) {
2011 MarkTileDirtyByTile(tile);
2012 return;
2013 }
2014 }
2015 }
2016
2017 /* Possibly change road type */
2018 if (GetRoadOwner(tile, RTT_ROAD) == OWNER_TOWN) {
2019 RoadType rt = GetTownRoadType(t);
2020 if (rt != GetRoadTypeRoad(tile)) {
2021 SetRoadType(tile, RTT_ROAD, rt);
2022 }
2023 }
2024
2025 MarkTileDirtyByTile(tile);
2026 }
2027 }
2028
2029 static bool ClickTile_Road(TileIndex tile)
2030 {
2031 if (!IsRoadDepot(tile)) return false;
2032
2033 ShowDepotWindow(tile, VEH_ROAD);
2034 return true;
2035 }
2036
2037 /* Converts RoadBits to TrackBits */
2038 static const TrackBits _road_trackbits[16] = {
2039 TRACK_BIT_NONE, // ROAD_NONE
2040 TRACK_BIT_NONE, // ROAD_NW
2041 TRACK_BIT_NONE, // ROAD_SW
2042 TRACK_BIT_LEFT, // ROAD_W
2043 TRACK_BIT_NONE, // ROAD_SE
2044 TRACK_BIT_Y, // ROAD_Y
2045 TRACK_BIT_LOWER, // ROAD_S
2046 TRACK_BIT_LEFT | TRACK_BIT_LOWER | TRACK_BIT_Y, // ROAD_Y | ROAD_SW
2047 TRACK_BIT_NONE, // ROAD_NE
2048 TRACK_BIT_UPPER, // ROAD_N
2049 TRACK_BIT_X, // ROAD_X
2050 TRACK_BIT_LEFT | TRACK_BIT_UPPER | TRACK_BIT_X, // ROAD_X | ROAD_NW
2051 TRACK_BIT_RIGHT, // ROAD_E
2052 TRACK_BIT_RIGHT | TRACK_BIT_UPPER | TRACK_BIT_Y, // ROAD_Y | ROAD_NE
2053 TRACK_BIT_RIGHT | TRACK_BIT_LOWER | TRACK_BIT_X, // ROAD_X | ROAD_SE
2054 TRACK_BIT_ALL, // ROAD_ALL
2055 };
2056
2057 static TrackStatus GetTileTrackStatus_Road(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
2058 {
2059 TrackdirBits trackdirbits = TRACKDIR_BIT_NONE;
2060 TrackdirBits red_signals = TRACKDIR_BIT_NONE; // crossing barred
2061 switch (mode) {
2062 case TRANSPORT_RAIL:
2063 if (IsLevelCrossing(tile)) trackdirbits = TrackBitsToTrackdirBits(GetCrossingRailBits(tile));
2064 break;
2065
2066 case TRANSPORT_ROAD: {
2067 RoadTramType rtt = (RoadTramType)sub_mode;
2068 if (!HasTileRoadType(tile, rtt)) break;
2069 switch (GetRoadTileType(tile)) {
2070 case ROAD_TILE_NORMAL: {
2071 const uint drd_to_multiplier[DRD_END] = { 0x101, 0x100, 0x1, 0x0 };
2072 RoadBits bits = GetRoadBits(tile, rtt);
2073
2074 /* no roadbit at this side of tile, return 0 */
2075 if (side != INVALID_DIAGDIR && (DiagDirToRoadBits(side) & bits) == 0) break;
2076
2077 uint multiplier = drd_to_multiplier[(rtt == RTT_TRAM) ? DRD_NONE : GetDisallowedRoadDirections(tile)];
2078 if (!HasRoadWorks(tile)) trackdirbits = (TrackdirBits)(_road_trackbits[bits] * multiplier);
2079 break;
2080 }
2081
2082 case ROAD_TILE_CROSSING: {
2083 Axis axis = GetCrossingRoadAxis(tile);
2084
2085 if (side != INVALID_DIAGDIR && axis != DiagDirToAxis(side)) break;
2086
2087 trackdirbits = TrackBitsToTrackdirBits(AxisToTrackBits(axis));
2088 if (IsCrossingBarred(tile)) {
2089 red_signals = trackdirbits;
2090 if (TrainOnCrossing(tile)) break;
2091
2092 auto mask_red_signal_bits_if_crossing_barred = [&](TileIndex t, TrackdirBits mask) {
2093 if (IsLevelCrossingTile(t) && IsCrossingBarred(t)) red_signals &= mask;
2094 };
2095 /* Check for blocked adjacent crossing to south, keep only southbound red signal trackdirs, allow northbound traffic */
2096 mask_red_signal_bits_if_crossing_barred(TileAddByDiagDir(tile, AxisToDiagDir(axis)), TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_SE);
2097 /* Check for blocked adjacent crossing to north, keep only northbound red signal trackdirs, allow southbound traffic */
2098 mask_red_signal_bits_if_crossing_barred(TileAddByDiagDir(tile, ReverseDiagDir(AxisToDiagDir(axis))), TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_NW);
2099 }
2100 break;
2101 }
2102
2103 default:
2104 case ROAD_TILE_DEPOT: {
2105 DiagDirection dir = GetRoadDepotDirection(tile);
2106
2107 if (side != INVALID_DIAGDIR && side != dir) break;
2108
2109 trackdirbits = TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir));
2110 break;
2111 }
2112 }
2113 break;
2114 }
2115
2116 default: break;
2117 }
2118 return CombineTrackStatus(trackdirbits, red_signals);
2119 }
2120
2121 static const StringID _road_tile_strings[] = {
2122 STR_LAI_ROAD_DESCRIPTION_ROAD,
2123 STR_LAI_ROAD_DESCRIPTION_ROAD,
2124 STR_LAI_ROAD_DESCRIPTION_ROAD,
2125 STR_LAI_ROAD_DESCRIPTION_ROAD_WITH_STREETLIGHTS,
2126 STR_LAI_ROAD_DESCRIPTION_ROAD,
2127 STR_LAI_ROAD_DESCRIPTION_TREE_LINED_ROAD,
2128 STR_LAI_ROAD_DESCRIPTION_ROAD,
2129 STR_LAI_ROAD_DESCRIPTION_ROAD,
2130 };
2131
2132 static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
2133 {
2134 Owner rail_owner = INVALID_OWNER;
2135 Owner road_owner = INVALID_OWNER;
2136 Owner tram_owner = INVALID_OWNER;
2137
2138 RoadType road_rt = GetRoadTypeRoad(tile);
2139 RoadType tram_rt = GetRoadTypeTram(tile);
2140 if (road_rt != INVALID_ROADTYPE) {
2141 const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
2142 td->roadtype = rti->strings.name;
2143 td->road_speed = rti->max_speed / 2;
2144 road_owner = GetRoadOwner(tile, RTT_ROAD);
2145 }
2146 if (tram_rt != INVALID_ROADTYPE) {
2147 const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
2148 td->tramtype = rti->strings.name;
2149 td->tram_speed = rti->max_speed / 2;
2150 tram_owner = GetRoadOwner(tile, RTT_TRAM);
2151 }
2152
2153 switch (GetRoadTileType(tile)) {
2154 case ROAD_TILE_CROSSING: {
2155 td->str = STR_LAI_ROAD_DESCRIPTION_ROAD_RAIL_LEVEL_CROSSING;
2156 rail_owner = GetTileOwner(tile);
2157
2158 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
2159 td->railtype = rti->strings.name;
2160 td->rail_speed = rti->max_speed;
2161
2162 break;
2163 }
2164
2165 case ROAD_TILE_DEPOT:
2166 td->str = STR_LAI_ROAD_DESCRIPTION_ROAD_VEHICLE_DEPOT;
2167 td->build_date = Depot::GetByTile(tile)->build_date;
2168 break;
2169
2170 default: {
2171 td->str = (road_rt != INVALID_ROADTYPE ? _road_tile_strings[GetRoadside(tile)] : STR_LAI_ROAD_DESCRIPTION_TRAMWAY);
2172 break;
2173 }
2174 }
2175
2176 /* Now we have to discover, if the tile has only one owner or many:
2177 * - Find a first_owner of the tile. (Currently road or tram must be present, but this will break when the third type becomes available)
2178 * - Compare the found owner with the other owners, and test if they differ.
2179 * Note: If road exists it will be the first_owner.
2180 */
2181 Owner first_owner = (road_owner == INVALID_OWNER ? tram_owner : road_owner);
2182 bool mixed_owners = (tram_owner != INVALID_OWNER && tram_owner != first_owner) || (rail_owner != INVALID_OWNER && rail_owner != first_owner);
2183
2184 if (mixed_owners) {
2185 /* Multiple owners */
2186 td->owner_type[0] = (rail_owner == INVALID_OWNER ? STR_NULL : STR_LAND_AREA_INFORMATION_RAIL_OWNER);
2187 td->owner[0] = rail_owner;
2188 td->owner_type[1] = (road_owner == INVALID_OWNER ? STR_NULL : STR_LAND_AREA_INFORMATION_ROAD_OWNER);
2189 td->owner[1] = road_owner;
2190 td->owner_type[2] = (tram_owner == INVALID_OWNER ? STR_NULL : STR_LAND_AREA_INFORMATION_TRAM_OWNER);
2191 td->owner[2] = tram_owner;
2192 } else {
2193 /* One to rule them all */
2194 td->owner[0] = first_owner;
2195 }
2196 }
2197
2202 static const byte _roadveh_enter_depot_dir[4] = {
2203 TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE
2204 };
2205
2206 static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
2207 {
2208 switch (GetRoadTileType(tile)) {
2209 case ROAD_TILE_DEPOT: {
2210 if (v->type != VEH_ROAD) break;
2211
2212 RoadVehicle *rv = RoadVehicle::From(v);
2213 if (rv->frame == RVC_DEPOT_STOP_FRAME &&
2214 _roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == rv->state) {
2215 rv->state = RVSB_IN_DEPOT;
2216 rv->vehstatus |= VS_HIDDEN;
2217 rv->direction = ReverseDir(rv->direction);
2218 if (rv->Next() == nullptr) VehicleEnterDepot(rv->First());
2219 rv->tile = tile;
2220
2221 InvalidateWindowData(WC_VEHICLE_DEPOT, rv->tile);
2222 return VETSB_ENTERED_WORMHOLE;
2223 }
2224 break;
2225 }
2226
2227 default: break;
2228 }
2229 return VETSB_CONTINUE;
2230 }
2231
2232
2233 static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owner)
2234 {
2235 if (IsRoadDepot(tile)) {
2236 if (GetTileOwner(tile) == old_owner) {
2237 if (new_owner == INVALID_OWNER) {
2238 Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile);
2239 } else {
2240 /* A road depot has two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
2241 RoadType rt = GetRoadTypeRoad(tile);
2242 if (rt == INVALID_ROADTYPE) rt = GetRoadTypeTram(tile);
2243 Company::Get(old_owner)->infrastructure.road[rt] -= 2;
2244 Company::Get(new_owner)->infrastructure.road[rt] += 2;
2245
2246 SetTileOwner(tile, new_owner);
2247 for (RoadTramType rtt : _roadtramtypes) {
2248 if (GetRoadOwner(tile, rtt) == old_owner) {
2249 SetRoadOwner(tile, rtt, new_owner);
2250 }
2251 }
2252 }
2253 }
2254 return;
2255 }
2256
2257 for (RoadTramType rtt : _roadtramtypes) {
2258 /* Update all roadtypes, no matter if they are present */
2259 if (GetRoadOwner(tile, rtt) == old_owner) {
2260 RoadType rt = GetRoadType(tile, rtt);
2261 if (rt != INVALID_ROADTYPE) {
2262 /* A level crossing has two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
2263 uint num_bits = IsLevelCrossing(tile) ? 2 : CountBits(GetRoadBits(tile, rtt));
2264 Company::Get(old_owner)->infrastructure.road[rt] -= num_bits;
2265 if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += num_bits;
2266 }
2267
2268 SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
2269 }
2270 }
2271
2272 if (IsLevelCrossing(tile)) {
2273 if (GetTileOwner(tile) == old_owner) {
2274 if (new_owner == INVALID_OWNER) {
2275 Command<CMD_REMOVE_SINGLE_RAIL>::Do(DC_EXEC | DC_BANKRUPT, tile, GetCrossingRailTrack(tile));
2276 } else {
2277 /* Update infrastructure counts. No need to dirty windows here, we'll redraw the whole screen anyway. */
2278 Company::Get(old_owner)->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR;
2279 Company::Get(new_owner)->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
2280
2281 SetTileOwner(tile, new_owner);
2282 }
2283 }
2284 }
2285 }
2286
2287 static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
2288 {
2289 if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
2290 switch (GetRoadTileType(tile)) {
2291 case ROAD_TILE_CROSSING:
2292 if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
2293 break;
2294
2295 case ROAD_TILE_DEPOT:
2296 if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
2297 break;
2298
2299 case ROAD_TILE_NORMAL: {
2300 RoadBits bits = GetAllRoadBits(tile);
2301 RoadBits bits_copy = bits;
2302 /* Check if the slope-road_bits combination is valid at all, i.e. it is safe to call GetRoadFoundation(). */
2303 if (CheckRoadSlope(tileh_new, &bits_copy, ROAD_NONE, ROAD_NONE).Succeeded()) {
2304 /* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */
2305 if (bits == bits_copy) {
2306 int z_old;
2307 Slope tileh_old = GetTileSlope(tile, &z_old);
2308
2309 /* Get the slope on top of the foundation */
2310 z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), &tileh_old);
2311 z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new);
2312
2313 /* The surface slope must not be changed */
2314 if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
2315 }
2316 }
2317 break;
2318 }
2319
2320 default: NOT_REACHED();
2321 }
2322 }
2323
2324 return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
2325 }
2326
2328 static Vehicle *UpdateRoadVehPowerProc(Vehicle *v, void *data)
2329 {
2330 if (v->type != VEH_ROAD) return nullptr;
2331
2332 RoadVehicleList *affected_rvs = static_cast<RoadVehicleList*>(data);
2333 include(*affected_rvs, RoadVehicle::From(v)->First());
2334
2335 return nullptr;
2336 }
2337
2344 static bool CanConvertUnownedRoadType(Owner owner, RoadTramType rtt)
2345 {
2346 return (owner == OWNER_NONE || (owner == OWNER_TOWN && rtt == RTT_ROAD));
2347 }
2348
2357 static void ConvertRoadTypeOwner(TileIndex tile, uint num_pieces, Owner owner, RoadType from_type, RoadType to_type)
2358 {
2359 // Scenario editor, maybe? Don't touch the owners when converting roadtypes...
2360 if (_current_company >= MAX_COMPANIES) return;
2361
2362 // We can't get a company from invalid owners but we can get ownership of roads without an owner
2363 if (owner >= MAX_COMPANIES && owner != OWNER_NONE) return;
2364
2365 Company *c;
2366
2367 switch (owner) {
2368 case OWNER_NONE:
2369 SetRoadOwner(tile, GetRoadTramType(to_type), (Owner)_current_company);
2370 UpdateCompanyRoadInfrastructure(to_type, _current_company, num_pieces);
2371 break;
2372
2373 default:
2374 c = Company::Get(owner);
2375 c->infrastructure.road[from_type] -= num_pieces;
2376 c->infrastructure.road[to_type] += num_pieces;
2377 DirtyCompanyInfrastructureWindows(c->index);
2378 break;
2379 }
2380 }
2381
2392 CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_start, RoadType to_type)
2393 {
2394 TileIndex area_end = tile;
2395
2396 if (!ValParamRoadType(to_type)) return CMD_ERROR;
2397 if (area_start >= MapSize()) return CMD_ERROR;
2398
2399 RoadVehicleList affected_rvs;
2400 RoadTramType rtt = GetRoadTramType(to_type);
2401
2402 CommandCost cost(EXPENSES_CONSTRUCTION);
2403 CommandCost error = CommandCost((rtt == RTT_TRAM) ? STR_ERROR_NO_SUITABLE_TRAMWAY : STR_ERROR_NO_SUITABLE_ROAD); // by default, there is no road to convert.
2404 bool found_convertible_road = false; // whether we actually did convert any road/tram (see bug #7633)
2405
2406 TileIterator *iter = new OrthogonalTileIterator(area_start, area_end);
2407 for (; (tile = *iter) != INVALID_TILE; ++(*iter)) {
2408 /* Is road present on tile? */
2409 if (!MayHaveRoad(tile)) continue;
2410
2411 /* Converting to the same subtype? */
2412 RoadType from_type = GetRoadType(tile, rtt);
2413 if (from_type == INVALID_ROADTYPE || from_type == to_type) continue;
2414
2415 /* Check if there is any infrastructure on tile */
2416 TileType tt = GetTileType(tile);
2417 switch (tt) {
2418 case MP_STATION:
2419 if (!IsRoadStop(tile)) continue;
2420 break;
2421 case MP_ROAD:
2422 if (IsLevelCrossing(tile) && RoadNoLevelCrossing(to_type)) {
2423 error.MakeError(STR_ERROR_CROSSING_DISALLOWED_ROAD);
2424 continue;
2425 }
2426 break;
2427 case MP_TUNNELBRIDGE:
2428 if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) continue;
2429 break;
2430 default: continue;
2431 }
2432
2433 /* Trying to convert other's road */
2434 Owner owner = GetRoadOwner(tile, rtt);
2435 if (!CanConvertUnownedRoadType(owner, rtt)) {
2436 CommandCost ret = CheckOwnership(owner, tile);
2437 if (ret.Failed()) {
2438 error = ret;
2439 continue;
2440 }
2441 }
2442
2443 /* Base the ability to replace town roads and bridges on the town's
2444 * acceptance of destructive actions. */
2445 if (owner == OWNER_TOWN) {
2446 Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
2447 CommandCost ret = CheckforTownRating(DC_NONE, t, tt == MP_TUNNELBRIDGE ? TUNNELBRIDGE_REMOVE : ROAD_REMOVE);
2448 if (ret.Failed()) {
2449 error = ret;
2450 continue;
2451 }
2452 }
2453
2454 /* Vehicle on the tile when not converting normal <-> powered
2455 * Tunnels and bridges have special check later */
2456 if (tt != MP_TUNNELBRIDGE) {
2457 if (!HasPowerOnRoad(from_type, to_type)) {
2458 CommandCost ret = EnsureNoVehicleOnGround(tile);
2459 if (ret.Failed()) {
2460 error = ret;
2461 continue;
2462 }
2463
2464 if (rtt == RTT_ROAD && owner == OWNER_TOWN) {
2465 error.MakeError(STR_ERROR_OWNED_BY);
2466 GetNameOfOwner(OWNER_TOWN, tile);
2467 continue;
2468 }
2469 }
2470
2471 uint num_pieces = CountBits(GetAnyRoadBits(tile, rtt));
2472 if (tt == MP_STATION && IsStandardRoadStopTile(tile)) {
2473 num_pieces *= ROAD_STOP_TRACKBIT_FACTOR;
2474 } else if (tt == MP_ROAD && IsRoadDepot(tile)) {
2475 num_pieces *= ROAD_DEPOT_TRACKBIT_FACTOR;
2476 }
2477
2478 found_convertible_road = true;
2479 cost.AddCost(num_pieces * RoadConvertCost(from_type, to_type));
2480
2481 if (flags & DC_EXEC) { // we can safely convert, too
2482 /* Call ConvertRoadTypeOwner() to update the company infrastructure counters. */
2483 if (owner == _current_company) {
2484 ConvertRoadTypeOwner(tile, num_pieces, owner, from_type, to_type);
2485 }
2486
2487 /* Perform the conversion */
2488 SetRoadType(tile, rtt, to_type);
2489 MarkTileDirtyByTile(tile);
2490
2491 /* update power of train on this tile */
2492 FindVehicleOnPos(tile, &affected_rvs, &UpdateRoadVehPowerProc);
2493
2494 if (IsRoadDepotTile(tile)) {
2495 /* Update build vehicle window related to this depot */
2496 InvalidateWindowData(WC_VEHICLE_DEPOT, tile);
2497 InvalidateWindowData(WC_BUILD_VEHICLE, tile);
2498 }
2499 }
2500 } else {
2501 TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
2502
2503 /* If both ends of tunnel/bridge are in the range, do not try to convert twice -
2504 * it would cause assert because of different test and exec runs */
2505 if (endtile < tile) {
2506 if (OrthogonalTileArea(area_start, area_end).Contains(endtile)) continue;
2507 }
2508
2509 /* When not converting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
2510 if (!HasPowerOnRoad(from_type, to_type)) {
2511 CommandCost ret = TunnelBridgeIsFree(tile, endtile);
2512 if (ret.Failed()) {
2513 error = ret;
2514 continue;
2515 }
2516
2517 if (rtt == RTT_ROAD && owner == OWNER_TOWN) {
2518 error.MakeError(STR_ERROR_OWNED_BY);
2519 GetNameOfOwner(OWNER_TOWN, tile);
2520 continue;
2521 }
2522 }
2523
2524 /* There are 2 pieces on *every* tile of the bridge or tunnel */
2525 uint num_pieces = (GetTunnelBridgeLength(tile, endtile) + 2) * 2;
2526 found_convertible_road = true;
2527 cost.AddCost(num_pieces * RoadConvertCost(from_type, to_type));
2528
2529 if (flags & DC_EXEC) {
2530 /* Update the company infrastructure counters. */
2531 if (owner == _current_company) {
2532 /* Each piece should be counted TUNNELBRIDGE_TRACKBIT_FACTOR times
2533 * for the infrastructure counters (cause of #8297). */
2534 ConvertRoadTypeOwner(tile, num_pieces * TUNNELBRIDGE_TRACKBIT_FACTOR, owner, from_type, to_type);
2535 SetTunnelBridgeOwner(tile, endtile, _current_company);
2536 }
2537
2538 /* Perform the conversion */
2539 SetRoadType(tile, rtt, to_type);
2540 SetRoadType(endtile, rtt, to_type);
2541
2542 FindVehicleOnPos(tile, &affected_rvs, &UpdateRoadVehPowerProc);
2543 FindVehicleOnPos(endtile, &affected_rvs, &UpdateRoadVehPowerProc);
2544
2545 if (IsBridge(tile)) {
2546 MarkBridgeDirty(tile);
2547 } else {
2548 MarkTileDirtyByTile(tile);
2549 MarkTileDirtyByTile(endtile);
2550 }
2551 }
2552 }
2553 }
2554
2555 if (flags & DC_EXEC) {
2556 /* Roadtype changed, update roadvehicles as when entering different track */
2557 for (RoadVehicle *v : affected_rvs) {
2558 v->CargoChanged();
2559 }
2560 }
2561
2562 delete iter;
2563 return found_convertible_road ? cost : error;
2564 }
2565
2566
2568 extern const TileTypeProcs _tile_type_road_procs = {
2569 DrawTile_Road, // draw_tile_proc
2570 GetSlopePixelZ_Road, // get_slope_z_proc
2571 ClearTile_Road, // clear_tile_proc
2572 nullptr, // add_accepted_cargo_proc
2573 GetTileDesc_Road, // get_tile_desc_proc
2574 GetTileTrackStatus_Road, // get_tile_track_status_proc
2575 ClickTile_Road, // click_tile_proc
2576 nullptr, // animate_tile_proc
2577 TileLoop_Road, // tile_loop_proc
2578 ChangeTileOwner_Road, // change_tile_owner_proc
2579 nullptr, // add_produced_cargo_proc
2580 VehicleEnter_Road, // vehicle_enter_tile_proc
2581 GetFoundation_Road, // get_foundation_proc
2582 TerraformTile_Road, // terraform_tile_proc
2583 };
DrawRailTileSeqInGUI
static void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence in GUI with railroad specifics.
Definition: sprite.h:99
RoadTypeInfo::flags
RoadTypeFlags flags
Bit mask of road type flags.
Definition: road.h:125
EV_BULLDOZER
@ EV_BULLDOZER
Bulldozer at roadworks.
Definition: effectvehicle_func.h:25
DrawRoadBits
static void DrawRoadBits(TileInfo *ti)
Draw ground sprite and road pieces.
Definition: road_cmd.cpp:1578
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
TileInfo::z
int z
Height.
Definition: tile_cmd.h:47
RailNoLevelCrossings
static bool RailNoLevelCrossings(RailType rt)
Test if a RailType disallows build of level crossings.
Definition: rail.h:342
ROTSG_ONEWAY
@ ROTSG_ONEWAY
Optional: One-way indicator images.
Definition: road.h:69
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:80
HasTownOwnedRoad
static bool HasTownOwnedRoad(TileIndex t)
Checks if given tile has town owned road.
Definition: road_map.h:280
SLOPE_SE
@ SLOPE_SE
south and east corner are raised
Definition: slope_type.h:57
tunnelbridge.h
GetRoadDepotDirection
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
Definition: road_map.h:565
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:78
RoadTypeInfo
Definition: road.h:76
RoadVehicle::state
byte state
Definition: roadveh.h:109
ROTSG_GROUND
@ ROTSG_GROUND
Required: Main group of ground images.
Definition: road.h:60
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3254
TO_CATENARY
@ TO_CATENARY
catenary
Definition: transparency.h:30
sound_func.h
RailtypeInfo::single_x
SpriteID single_x
single piece of rail in X direction, without ground
Definition: rail.h:134
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:127
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:39
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:26
Cheats::magic_bulldozer
Cheat magic_bulldozer
dynamite industries, objects
Definition: cheat_type.h:27
RailtypeInfo::max_speed
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
Definition: rail.h:228
Chance16
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
Definition: random_func.hpp:131
IsValidAxis
static bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Definition: direction_func.h:43
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
_original_roadtypes
static const RoadTypeInfo _original_roadtypes[]
Global Roadtype definition.
Definition: roadtypes.h:19
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
IsRoadStop
static bool IsRoadStop(TileIndex t)
Is the station at t a road station?
Definition: station_map.h:202
HasAtMostOneBit
static bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
Definition: bitmath_func.hpp:286
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
ROTF_CATENARY
@ ROTF_CATENARY
Bit number for adding catenary.
Definition: road.h:39
RoadTypeInfo::build_y_road
SpriteID build_y_road
button for building single rail in Y direction
Definition: road.h:84
train.h
command_func.h
TrackdirBits
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:101
YapfNotifyTrackLayoutChange
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
Definition: yapf_rail.cpp:644
Town::road_build_months
byte road_build_months
fund road reconstruction in action?
Definition: town.h:91
TileInfo::x
uint x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:43
UpdateRoadVehPowerProc
static Vehicle * UpdateRoadVehPowerProc(Vehicle *v, void *data)
Update power of road vehicle under which is the roadtype being converted.
Definition: road_cmd.cpp:2328
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
road_land.h
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
AutoslopeCheckForEntranceEdge
static bool AutoslopeCheckForEntranceEdge(TileIndex tile, int z_new, Slope tileh_new, DiagDirection entrance)
Autoslope check for tiles with an entrance on an edge.
Definition: autoslope.h:31
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Definition: town_cmd.cpp:3594
TO_BUILDINGS
@ TO_BUILDINGS
company buildings - depots, stations, HQ, ...
Definition: transparency.h:27
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
ROAD_TILE_CROSSING
@ ROAD_TILE_CROSSING
Level crossing.
Definition: road_map.h:24
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:328
TileDesc::railtype
StringID railtype
Type of rail on the tile.
Definition: tile_cmd.h:63
RoadTypeInfo::introduces_roadtypes
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition: road.h:175
company_base.h
IsTransparencySet
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:48
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1098
tunnelbridge_map.h
IsValidDisallowedRoadDirections
static bool IsValidDisallowedRoadDirections(DisallowedRoadDirections drt)
Checks if a DisallowedRoadDirections is valid.
Definition: road_map.h:291
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:53
RoadTypeInfo::sorting_order
byte sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Definition: road.h:180
SND_21_ROAD_WORKS
@ SND_21_ROAD_WORKS
31 == 0x1F Road reconstruction animation
Definition: sound_type.h:70
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:125
SLOPE_NW
@ SLOPE_NW
north and west corner are raised
Definition: slope_type.h:55
company_gui.h
OtherAxis
static Axis OtherAxis(Axis a)
Select the other axis as provided.
Definition: direction_func.h:197
SetTrackReservation
static void SetTrackReservation(TileIndex t, TrackBits b)
Sets the reserved track bits of the tile.
Definition: rail_map.h:209
LEVELCROSSING_TRACKBIT_FACTOR
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
Definition: economy_type.h:224
elrail_func.h
GetRoadGroundSprite
static SpriteID GetRoadGroundSprite(const TileInfo *ti, Roadside roadside, const RoadTypeInfo *rti, uint offset, PaletteID *pal)
Get ground sprite to draw for a road tile.
Definition: road_cmd.cpp:1541
RTSG_CROSSING
@ RTSG_CROSSING
Level crossing overlay images.
Definition: rail.h:54
DiagDirToAxis
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
IsRoadDepotTile
static bool IsRoadDepotTile(TileIndex t)
Return whether a tile is a road depot tile.
Definition: road_map.h:116
MarkDirtyAdjacentLevelCrossingTiles
void MarkDirtyAdjacentLevelCrossingTiles(TileIndex tile, Axis road_axis)
Find adjacent level crossing tiles in this multi-track crossing and mark them dirty.
Definition: train_cmd.cpp:1785
road_func.h
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:332
RoadConvertCost
static Money RoadConvertCost(RoadType from, RoadType to)
Calculates the cost of road conversion.
Definition: road.h:279
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:83
TownCache::squared_town_zone_radius
uint32 squared_town_zone_radius[HZB_END]
UpdateTownRadius updates this given the house count.
Definition: town.h:45
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
DrawRoadCatenary
void DrawRoadCatenary(const TileInfo *ti)
Draws the catenary for the given tile.
Definition: road_cmd.cpp:1431
TrainOnCrossing
bool TrainOnCrossing(TileIndex tile)
Check if a level crossing tile has a train on it.
Definition: train_cmd.cpp:1663
AxisToTrackBits
static TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Definition: track_func.h:87
RoadTypeInfo::build_depot
SpriteID build_depot
button for building depots
Definition: road.h:86
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
GetBridgeHeight
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
Definition: bridge_map.cpp:70
RailtypeInfo::single_y
SpriteID single_y
single piece of rail in Y direction, without ground
Definition: rail.h:135
SLOPE_ELEVATED
@ SLOPE_ELEVATED
bit mask containing all 'simple' slopes
Definition: slope_type.h:61
KillFirstBit
static T KillFirstBit(T value)
Clear the first bit in an integer.
Definition: bitmath_func.hpp:239
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
TileDesc::tram_speed
uint16 tram_speed
Speed limit of tram (bridges and track)
Definition: tile_cmd.h:68
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
RoadTileType
RoadTileType
The different types of road tiles.
Definition: road_map.h:22
RailtypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:124
include
bool include(std::vector< T > &vec, const T &item)
Helper function to append an item to a vector if it is not already contained Consider using std::set,...
Definition: smallvec_type.hpp:27
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
VETSB_CONTINUE
@ VETSB_CONTINUE
Bit sets of the above specified bits.
Definition: tile_cmd.h:34
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
ROADSIDE_BARREN
@ ROADSIDE_BARREN
Road on barren land.
Definition: road_map.h:478
IsStandardRoadStopTile
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Definition: station_map.h:223
BB_HEIGHT_UNDER_BRIDGE
static const uint BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).
Definition: viewport_type.h:84
IsValidDiagDirection
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Definition: direction_func.h:21
SetCrossingReservation
static void SetCrossingReservation(TileIndex t, bool b)
Set the reservation state of the rail crossing.
Definition: road_map.h:393
SetRoadOwner
static void SetRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:251
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:219
IsDriveThroughStopTile
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
Definition: station_map.h:233
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
DrawBridgeMiddle
void DrawBridgeMiddle(const TileInfo *ti)
Draw the middle bits of a bridge.
Definition: tunnelbridge_cmd.cpp:1543
GetTrackBits
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
DrawRoadDepotSprite
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
Draw the road depot sprite.
Definition: road_cmd.cpp:1830
TileInfo::y
uint y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:44
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
VehicleEnterDepot
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it,...
Definition: vehicle.cpp:1487
Town::xy
TileIndex xy
town center tile
Definition: town.h:51
DC_NO_WATER
@ DC_NO_WATER
don't allow building on water
Definition: command_type.h:360
newgrf_debug.h
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
effectvehicle_base.h
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:82
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:130
VALID_LEVEL_CROSSING_SLOPES
static const uint32 VALID_LEVEL_CROSSING_SLOPES
Constant bitset with safe slopes for building a level crossing.
Definition: slope_type.h:86
GetSlopePixelZInCorner
static int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition: landscape.h:53
GetCrossingRoadBits
static RoadBits GetCrossingRoadBits(TileIndex tile)
Get the road bits of a level crossing.
Definition: road_map.h:348
_display_opt
byte _display_opt
What do we want to draw/do?
Definition: transparency_gui.cpp:26
SetRoadBits
static void SetRoadBits(TileIndex t, RoadBits r, RoadTramType rtt)
Set the present road bits for a specific road type.
Definition: road_map.h:153
StartRoadWorks
static void StartRoadWorks(TileIndex t)
Start road works on a tile.
Definition: road_map.h:535
RoadTypeInfo::tunnel
CursorID tunnel
Cursor for building a tunnel.
Definition: road.h:96
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
RoadTypeInfo::introduction_date
Date introduction_date
Introduction date.
Definition: road.h:164
TerminateRoadWorks
static void TerminateRoadWorks(TileIndex t)
Terminate road works on a tile.
Definition: road_map.h:551
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:357
SubSprite
Used to only draw a part of the sprite.
Definition: gfx_type.h:225
CheckforTownRating
CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type)
Does the town authority allow the (destructive) action of the current company?
Definition: town_cmd.cpp:3710
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:50
CommandCost::GetErrorMessage
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:141
RoadTypeInfo::depot
CursorID depot
Cursor for building a depot.
Definition: road.h:95
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:51
CanBuildDepotByTileh
static bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
Find out if the slope of the tile is suitable to build a depot of given direction.
Definition: depot_func.h:26
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
GetHighestSlopeCorner
static Corner GetHighestSlopeCorner(Slope s)
Returns the highest corner of a slope (one corner raised or a steep slope).
Definition: slope_func.h:126
ROTSG_CURSORS
@ ROTSG_CURSORS
Optional: Cursor and toolbar icon images.
Definition: road.h:58
GetCrossingRailTrack
static Track GetCrossingRailTrack(TileIndex tile)
Get the rail track of a level crossing.
Definition: road_map.h:358
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:355
TRACKDIR_Y_SE
@ TRACKDIR_Y_SE
Y-axis and direction to south-east.
Definition: track_type.h:73
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
genworld.h
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
IsLevelCrossing
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
Definition: road_map.h:85
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:539
RoadTypeInfo::road_nwse
CursorID road_nwse
Cursor for building rail in Y direction.
Definition: road.h:93
RoadTypeInfo::road_swne
CursorID road_swne
Cursor for building rail in X direction.
Definition: road.h:92
IsValidRoadBits
static bool IsValidRoadBits(RoadBits r)
Whether the given roadtype is valid.
Definition: road_func.h:23
FlatteningFoundation
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
Definition: slope_func.h:369
IsStraightRoad
static bool IsStraightRoad(RoadBits r)
Check if we've got a straight road.
Definition: road_func.h:81
TRACK_BIT_UPPER
@ TRACK_BIT_UPPER
Upper track.
Definition: track_type.h:42
CmdRemoveLongRoad
std::tuple< CommandCost, Money > CmdRemoveLongRoad(DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, bool start_half, bool end_half)
Remove a long piece of road.
Definition: road_cmd.cpp:1077
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
SlopeToSpriteOffset
static uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
Definition: slope_func.h:415
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
GetRailReservationTrackBits
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
Definition: rail_map.h:194
DiagDirToRoadBits
static RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition: road_func.h:96
RoadTypeLabelList
std::vector< RoadTypeLabel > RoadTypeLabelList
List of road type labels.
Definition: road.h:74
CountBits
static uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:251
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
effectvehicle_func.h
TRACK_BIT_RIGHT
@ TRACK_BIT_RIGHT
Right track.
Definition: track_type.h:45
IncreaseRoadWorksCounter
static bool IncreaseRoadWorksCounter(TileIndex t)
Increase the progress counter of road works.
Definition: road_map.h:523
CompareRoadTypes
static bool CompareRoadTypes(const RoadType &first, const RoadType &second)
Compare roadtypes based on their sorting order.
Definition: road_cmd.cpp:110
GetTownRadiusGroup
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Definition: town_cmd.cpp:2282
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:45
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
AxisToRoadBits
static RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition: road_func.h:111
ROAD_X
@ ROAD_X
Full road along the x-axis (south-west + north-east)
Definition: road_type.h:56
TO_TREES
@ TO_TREES
trees
Definition: transparency.h:24
SoundSettings::ambient
bool ambient
Play ambient, industry and town sounds.
Definition: settings_type.h:220
RailtypeInfo::name
StringID name
Name of this rail type.
Definition: rail.h:173
TileDesc::build_date
Date build_date
Date of construction of tile contents.
Definition: tile_cmd.h:55
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
SetTunnelBridgeOwner
static void SetTunnelBridgeOwner(TileIndex begin, TileIndex end, Owner owner)
Sets the ownership of the bridge/tunnel ramps.
Definition: tunnelbridge.h:41
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
Roadside
Roadside
The possible road side decorations.
Definition: road_map.h:477
DrawRoadAsSnowDesert
static bool DrawRoadAsSnowDesert(TileIndex tile, Roadside roadside)
Should the road be drawn as a unpaved snow/desert road? By default, roads are always drawn as unpaved...
Definition: road_cmd.cpp:1346
GetAllRoadBits
static RoadBits GetAllRoadBits(TileIndex tile)
Get all set RoadBits on the given tile.
Definition: road_map.h:141
GetCustomRoadSprite
SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
Definition: newgrf_roadtype.cpp:100
RoadVehiclesAreBuilt
bool RoadVehiclesAreBuilt()
Verify whether a road vehicle is available.
Definition: road_cmd.cpp:186
ROAD_TILE_NORMAL
@ ROAD_TILE_NORMAL
Normal road.
Definition: road_map.h:23
ROAD_Y
@ ROAD_Y
Full road along the y-axis (north-west + south-east)
Definition: road_type.h:57
GetRoadBits
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition: road_map.h:128
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
ROADSIDE_STREET_LIGHTS
@ ROADSIDE_STREET_LIGHTS
Road with street lights on paved sidewalks.
Definition: road_map.h:481
OrthogonalTileIterator
Iterator to iterate over a tile area (rectangle) of the map.
Definition: tilearea_type.h:183
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:157
GetSlopeMaxZ
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
Definition: slope_func.h:160
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:81
DrawRailTileSeq
static void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence on tile with railroad specifics.
Definition: sprite.h:89
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:34
depot_base.h
landscape_cmd.h
RoadTypeInfo::powered_roadtypes
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition: road.h:120
ROAD_ALL
@ ROAD_ALL
Full 4-way crossing.
Definition: road_type.h:64
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:316
FOUNDATION_INCLINED_Y
@ FOUNDATION_INCLINED_Y
The tile has an along Y-axis inclined foundation.
Definition: slope_type.h:97
RoadVehicleList
std::vector< RoadVehicle * > RoadVehicleList
Helper type for lists/vectors of road vehicles.
Definition: road_cmd.cpp:50
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
ROAD_NE
@ ROAD_NE
North-east part.
Definition: road_type.h:55
TRACKDIR_BIT_X_NE
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
Definition: track_type.h:103
ROADSIDE_GRASS
@ ROADSIDE_GRASS
Road on grass.
Definition: road_map.h:479
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:158
ComplementRoadBits
static RoadBits ComplementRoadBits(RoadBits r)
Calculate the complement of a RoadBits value.
Definition: road_func.h:37
IsSteepSlope
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:36
CommandCost
Common return value for all commands.
Definition: command_type.h:24
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:656
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
HasGrfMiscBit
static bool HasGrfMiscBit(GrfMiscBit bit)
Check for grf miscellaneous bits.
Definition: newgrf.h:187
InitRoadTypes
void InitRoadTypes()
Resolve sprites of custom road types.
Definition: road_cmd.cpp:121
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:607
ROTF_HIDDEN
@ ROTF_HIDDEN
Bit number for hidden from construction.
Definition: road.h:42
AxisToTrack
static Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
Definition: track_func.h:65
GetAnyRoadBits
RoadBits GetAnyRoadBits(TileIndex tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
Definition: road_map.cpp:33
SLOPE_NE
@ SLOPE_NE
north and east corner are raised
Definition: slope_type.h:58
HasExactlyOneBit
static bool HasExactlyOneBit(T value)
Test whether value has exactly 1 bit set.
Definition: bitmath_func.hpp:274
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition: company_gui.cpp:2774
CalcClosestTownFromTile
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
Definition: town_cmd.cpp:3576
TrackBitsToTrackdirBits
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:318
GetRailTileType
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition: rail_map.h:36
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:245
IsNormalRoad
static bool IsNormalRoad(TileIndex t)
Return whether a tile is a normal road.
Definition: road_map.h:64
ToggleSnow
static void ToggleSnow(TileIndex t)
Toggle the snow/desert state of a road tile.
Definition: road_map.h:470
autoslope.h
TileIterator
Base class for tile iterators.
Definition: tilearea_type.h:105
RemoveRoad
static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits pieces, RoadTramType rtt, bool crossing_check, bool town_check=true)
Delete a piece of road.
Definition: road_cmd.cpp:333
TileDesc::roadtype
StringID roadtype
Type of road on the tile.
Definition: tile_cmd.h:65
ResetRoadTypes
void ResetRoadTypes()
Reset all road type information to its default values.
Definition: road_cmd.cpp:65
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
rail_cmd.h
RailtypeInfo::base_sprites
struct RailtypeInfo::@36 base_sprites
Struct containing the main sprites.
_cheats
Cheats _cheats
All the cheats.
Definition: cheat.cpp:16
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
MakeRoadCrossing
static void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner rail, Axis roaddir, RailType rat, RoadType road_rt, RoadType tram_rt, uint town)
Make a level crossing.
Definition: road_map.h:660
RoadTypeInfo::auto_road
SpriteID auto_road
button for the autoroad construction
Definition: road.h:85
FOUNDATION_INCLINED_X
@ FOUNDATION_INCLINED_X
The tile has an along X-axis inclined foundation.
Definition: slope_type.h:96
IsRoadOwner
static bool IsRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Check if a specific road type is owned by an owner.
Definition: road_map.h:268
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
EconomySettings::mod_road_rebuild
bool mod_road_rebuild
roadworks remove unnecessary RoadBits
Definition: settings_type.h:521
GetRoadside
static Roadside GetRoadside(TileIndex tile)
Get the decorations of a road.
Definition: road_map.h:493
IsInvisibilitySet
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:59
ROADSIDE_PAVED
@ ROADSIDE_PAVED
Road with paved sidewalks.
Definition: road_map.h:480
HasRoadCatenaryDrawn
static bool HasRoadCatenaryDrawn(RoadType roadtype)
Test if we should draw road catenary.
Definition: road_func.h:145
GetNorthernBridgeEnd
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:39
ROADTYPES_TRAM
@ ROADTYPES_TRAM
Trams.
Definition: road_type.h:39
GetNameOfOwner
void GetNameOfOwner(Owner owner, TileIndex tile)
Set the right DParams to get the name of an owner.
Definition: company_cmd.cpp:287
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
RoadTypes
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
TUNNELBRIDGE_TRACKBIT_FACTOR
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
Definition: economy_type.h:222
HasTileRoadType
static bool HasTileRoadType(TileIndex t, RoadTramType rtt)
Check if a tile has a road or a tram road type.
Definition: road_map.h:211
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
GetTropicZone
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
Definition: tile_map.h:238
RoadTypeInfo::alternate_labels
RoadTypeLabelList alternate_labels
Road type labels this type provides in addition to the main label.
Definition: road.h:150
ToggleDesert
#define ToggleDesert
Toggle the snow/desert state of a road tile.
Definition: road_map.h:465
DisallowedRoadDirections
DisallowedRoadDirections
Which directions are disallowed ?
Definition: road_type.h:72
_roadveh_enter_depot_dir
static const byte _roadveh_enter_depot_dir[4]
Given the direction the road depot is pointing, this is the direction the vehicle should be travellin...
Definition: road_cmd.cpp:2202
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:596
IsCrossingBarred
static bool IsCrossingBarred(TileIndex t)
Check if the level crossing is barred.
Definition: road_map.h:416
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition: track_type.h:40
_tile_type_road_procs
const TileTypeProcs _tile_type_road_procs
Tile callback functions for road tiles.
Definition: landscape.cpp:49
GetRoadTileType
static RoadTileType GetRoadTileType(TileIndex t)
Get the type of the road tile.
Definition: road_map.h:52
CmdBuildLongRoad
CommandCost CmdBuildLongRoad(DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, DisallowedRoadDirections drd, bool start_half, bool end_half, bool is_ai)
Build a long piece of road.
Definition: road_cmd.cpp:981
safeguards.h
CombineTrackStatus
static TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
Definition: track_func.h:387
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
TileAddByDiagDir
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:382
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
IsBridge
static bool IsBridge(TileIndex t)
Checks if this is a bridge, instead of a tunnel.
Definition: bridge_map.h:24
TRACKDIR_BIT_Y_SE
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
Definition: track_type.h:104
IsTileOwner
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
IsOnSnow
static bool IsOnSnow(TileIndex t)
Check if a road tile has snow/desert.
Definition: road_map.h:459
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
CleanUpRoadBits
RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
Clean up unnecessary RoadBits of a planned tile.
Definition: road.cpp:47
ROADTYPE_ROAD
@ ROADTYPE_ROAD
Basic road type.
Definition: road_type.h:24
UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval
void UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(TileIndex tile, Axis road_axis)
Update adjacent level crossing tiles in this multi-track crossing, due to removal of a level crossing...
Definition: train_cmd.cpp:1802
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition: direction_type.h:84
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1058
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
DrawRoadTileStruct
Definition: road_cmd.cpp:1266
AutoslopeEnabled
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Definition: autoslope.h:44
road_internal.h
road.h
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
Definition: command.cpp:173
TRACKDIR_X_NE
@ TRACKDIR_X_NE
X-axis and direction to north-east.
Definition: track_type.h:72
CompanyInfrastructure::road
uint32 road[ROADTYPE_END]
Count of company owned track bits for each road type.
Definition: company_base.h:32
HasCrossingReservation
static bool HasCrossingReservation(TileIndex t)
Get the reservation state of the rail crossing.
Definition: road_map.h:380
FOUNDATION_NONE
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition: slope_type.h:94
IsRoadDepot
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
Definition: road_map.h:106
RoadTypeInfo::name
StringID name
Name of this rail type.
Definition: road.h:101
ValParamRoadType
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition: road.cpp:142
GetRoadStopDir
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
Definition: station_map.h:257
MarkBridgeDirty
void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
Mark bridge tiles dirty.
Definition: tunnelbridge_cmd.cpp:66
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
GetFoundationSlope
Slope GetFoundationSlope(TileIndex tile, int *z)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
Definition: landscape.cpp:426
_loaded_newgrf_features
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Definition: newgrf.cpp:81
TRACK_BIT_ALL
@ TRACK_BIT_ALL
All possible tracks.
Definition: track_type.h:53
roadtypes.h
RoadTypeInfo::build_tunnel
SpriteID build_tunnel
button for building a tunnel
Definition: road.h:87
ZOOM_LVL_DETAIL
@ ZOOM_LVL_DETAIL
All zoomlevels below or equal to this, will result in details on the screen, like road-work,...
Definition: zoom_type.h:43
ROADSIDE_TREES
@ ROADSIDE_TREES
Road with trees on paved sidewalks.
Definition: road_map.h:483
date_func.h
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:63
TRACK_BIT_LOWER
@ TRACK_BIT_LOWER
Lower track.
Definition: track_type.h:43
GUISettings::show_track_reservation
bool show_track_reservation
highlight reserved tracks.
Definition: settings_type.h:162
stdafx.h
CheckAllowRemoveRoad
CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadTramType rtt, DoCommandFlag flags, bool town_check)
Is it allowed to remove the given road bits from the given tile?
Definition: road_cmd.cpp:269
DO_FULL_DETAIL
@ DO_FULL_DETAIL
Also draw details of track and roads.
Definition: openttd.h:49
DrawRoadOverlays
void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset, bool draw_underlay)
Draw road underlay and overlay sprites.
Definition: road_cmd.cpp:1495
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:145
ConstructionSettings::extra_dynamite
bool extra_dynamite
extra dynamite
Definition: settings_type.h:349
RATING_ROAD_MINIMUM
@ RATING_ROAD_MINIMUM
minimum rating after removing town owned road
Definition: town_type.h:66
DRD_NONE
@ DRD_NONE
None of the directions are disallowed.
Definition: road_type.h:73
Cheat::value
bool value
tells if the bool cheat is active or not
Definition: cheat_type.h:18
UpdateNearestTownForRoadTiles
void UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
Definition: road_cmd.cpp:1873
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:363
CanConvertUnownedRoadType
static bool CanConvertUnownedRoadType(Owner owner, RoadTramType rtt)
Checks the tile and returns whether the current player is allowed to convert the roadtype to another ...
Definition: road_cmd.cpp:2344
viewport_func.h
AxisToDiagDir
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition: direction_func.h:232
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
DRD_SOUTHBOUND
@ DRD_SOUTHBOUND
All southbound traffic is disallowed.
Definition: road_type.h:74
GetTunnelBridgeDirection
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26
ChangeTownRating
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
Definition: town_cmd.cpp:3673
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:667
ConvertRoadTypeOwner
static void ConvertRoadTypeOwner(TileIndex tile, uint num_pieces, Owner owner, RoadType from_type, RoadType to_type)
Convert the ownership of the RoadType of the tile if applicable.
Definition: road_cmd.cpp:2357
yapf_cache.h
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:286
ApplyPixelFoundationToSlope
static uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.h:129
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:474
DrawTile_Road
static void DrawTile_Road(TileInfo *ti)
Tile callback function for rendering a road tile to the screen.
Definition: road_cmd.cpp:1659
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:61
EconomySettings::dist_local_authority
byte dist_local_authority
distance for town local authority, default 20
Definition: settings_type.h:516
CmdBuildRoad
CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, RoadType rt, DisallowedRoadDirections toggle_drd, TownID town_id)
Build a piece of road.
Definition: road_cmd.cpp:617
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition: map.cpp:174
RoadTypeInfo::build_x_road
SpriteID build_x_road
button for building single rail in X direction
Definition: road.h:83
RoadTypeInfo::convert_road
SpriteID convert_road
button for converting road types
Definition: road.h:88
SetRoadType
static void SetRoadType(TileIndex t, RoadTramType rtt, RoadType rt)
Set the road type of a tile.
Definition: road_map.h:604
ReverseDir
static Direction ReverseDir(Direction d)
Return the reverse of a direction.
Definition: direction_func.h:54
MakeDefaultName
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition: town.h:245
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:102
GetDisallowedRoadDirections
static DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
Gets the disallowed directions.
Definition: road_map.h:301
ROAD_DEPOT_TRACKBIT_FACTOR
static const uint ROAD_DEPOT_TRACKBIT_FACTOR
Multiplier for how many regular track bits a road depot counts.
Definition: economy_type.h:226
GetCustomRailSprite
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
Definition: newgrf_railtype.cpp:95
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
HasRoadCatenary
static bool HasRoadCatenary(RoadType roadtype)
Test if a road type has catenary.
Definition: road_func.h:135
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1598
strings_func.h
PALETTE_TO_BARE_LAND
static const PaletteID PALETTE_TO_BARE_LAND
sets colour to bare land stuff for rail, road and crossings
Definition: sprites.h:1586
DRD_BOTH
@ DRD_BOTH
All directions are disallowed.
Definition: road_type.h:76
SlopeWithOneCornerRaised
static Slope SlopeWithOneCornerRaised(Corner corner)
Returns the slope with a specific corner raised.
Definition: slope_func.h:99
newgrf_roadtype.h
RoadTypeInfo::gui_sprites
struct RoadTypeInfo::@40 gui_sprites
struct containing the sprites for the road GUI.
TRACK_BIT_LEFT
@ TRACK_BIT_LEFT
Left track.
Definition: track_type.h:44
GRFLoadedFeatures::tram
TramReplacement tram
In which way tram depots were replaced.
Definition: newgrf.h:179
CmdConvertRoad
CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_start, RoadType to_type)
Convert one road subtype to another.
Definition: road_cmd.cpp:2392
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition: window_type.h:376
INVALID_DATE
static const Date INVALID_DATE
Representation of an invalid date.
Definition: date_type.h:111
RoadTypeInfo::label
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition: road.h:145
SpecializedVehicle< RoadVehicle, Type >::From
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1183
SetDisallowedRoadDirections
static void SetDisallowedRoadDirections(TileIndex t, DisallowedRoadDirections drd)
Sets the disallowed directions.
Definition: road_map.h:312
IsSlopeWithOneCornerRaised
static bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Definition: slope_func.h:88
TRAMWAY_REPLACE_DEPOT_WITH_TRACK
@ TRAMWAY_REPLACE_DEPOT_WITH_TRACK
Electrified depot graphics with tram track were loaded.
Definition: newgrf.h:171
RoadTypeInfo::cursor
struct RoadTypeInfo::@41 cursor
Cursors associated with the road type.
TileType
TileType
The different types of tiles.
Definition: tile_type.h:47
ROAD_TILE_DEPOT
@ ROAD_TILE_DEPOT
Depot (one entrance)
Definition: road_map.h:25
TRACKDIR_BIT_Y_NW
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
Definition: track_type.h:111
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
HasRailCatenaryDrawn
static bool HasRailCatenaryDrawn(RailType rt)
Test if we should draw rail catenary.
Definition: elrail_func.h:30
ConstructionSettings::build_on_slopes
bool build_on_slopes
allow building on slopes
Definition: settings_type.h:343
ROTSG_OVERLAY
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
Definition: road.h:59
RoadTypeInfo::autoroad
CursorID autoroad
Cursor for autorail tool.
Definition: road.h:94
DrawRoadDetail
static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int h, bool transparent)
Draws details on/around the road.
Definition: road_cmd.cpp:1477
RoadClearCost
static Money RoadClearCost(RoadType roadtype)
Returns the cost of clearing the specified roadtype.
Definition: road.h:261
TRACKDIR_Y_NW
@ TRACKDIR_Y_NW
Y-axis and direction to north-west.
Definition: track_type.h:81
SLOPE_SW
@ SLOPE_SW
south and west corner are raised
Definition: slope_type.h:56
cheat_type.h
SetTownIndex
static void SetTownIndex(TileIndex t, TownID index)
Set the town index for a road or house tile.
Definition: town_map.h:34
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1998
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
FOUNDATION_LEVELED
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
Definition: slope_type.h:95
CompanyInfrastructure::rail
uint32 rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
Definition: company_base.h:34
MakeRoadNormal
static void MakeRoadNormal(TileIndex t, RoadBits bits, RoadType road_rt, RoadType tram_rt, TownID town, Owner road, Owner tram)
Make a normal road tile.
Definition: road_map.h:635
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
WC_VEHICLE_DEPOT
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
Definition: window_type.h:344
newgrf.h
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
ROTSG_CATENARY_FRONT
@ ROTSG_CATENARY_FRONT
Optional: Catenary front.
Definition: road.h:62
Town::cache
TownCache cache
Container for all cacheable data.
Definition: town.h:53
GetCrossingRailAxis
static Axis GetCrossingRailAxis(TileIndex t)
Get the rail axis of a level crossing.
Definition: road_map.h:337
FindVehicleOnPos
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
Definition: vehicle.cpp:498
UpdateCompanyRoadInfrastructure
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
Definition: road_cmd.cpp:197
RAIL_TILE_NORMAL
@ RAIL_TILE_NORMAL
Normal rail tile without signals.
Definition: rail_map.h:24
Pool::PoolItem<&_depot_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:307
RATING_ROAD_DOWN_STEP_EDGE
@ RATING_ROAD_DOWN_STEP_EDGE
removing a roadpiece at the edge
Definition: town_type.h:65
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:78
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:225
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:52
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:358
GetTileMaxPixelZ
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
Definition: tile_map.h:304
EffectVehicle
A special vehicle is one of the following:
Definition: effectvehicle_base.h:24
CreateEffectVehicleAbove
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
Definition: effectvehicle.cpp:622
RoadBits
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:50
SpecializedVehicle< RoadVehicle, Type >::Iterate
static Pool::IterateWrapper< RoadVehicle > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition: vehicle_base.h:1252
IsLevelCrossingTile
static bool IsLevelCrossingTile(TileIndex t)
Return whether a tile is a level crossing tile.
Definition: road_map.h:95
DrawGroundSpriteAt
void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite at a specific world-coordinate relative to the current tile.
Definition: viewport.cpp:560
IsOnDesert
#define IsOnDesert
Check if a road tile has snow/desert.
Definition: road_map.h:453
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:126
UpdateLevelCrossing
void UpdateLevelCrossing(TileIndex tile, bool sound=true, bool force_bar=false)
Update a level crossing to barred or open (crossing may include multiple adjacent tiles).
Definition: train_cmd.cpp:1753
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:258
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:134
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
CheckTileOwnership
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
Definition: company_cmd.cpp:334
CommandHelper
Definition: command_func.h:94
GetRoadFoundation
static Foundation GetRoadFoundation(Slope tileh, RoadBits bits)
Get the foundationtype of a RoadBits Slope combination.
Definition: road_cmd.cpp:1281
GetTunnelBridgeLength
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition: tunnelbridge.h:25
Depot::build_date
Date build_date
Date of construction.
Definition: depot_base.h:25
ROAD_NW
@ ROAD_NW
North-west part.
Definition: road_type.h:52
Depot
Definition: depot_base.h:19
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Town
Town data structure.
Definition: town.h:50
ROAD_SW
@ ROAD_SW
South-west part.
Definition: road_type.h:53
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
ROTSG_DEPOT
@ ROTSG_DEPOT
Optional: Depot images.
Definition: road.h:66
TileDesc::rail_speed
uint16 rail_speed
Speed limit of rail (bridges and track)
Definition: tile_cmd.h:64
ROAD_NONE
@ ROAD_NONE
No road-part is build.
Definition: road_type.h:51
DiagDirToDiagTrackBits
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Definition: track_func.h:523
RoadTypeInfo::max_speed
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
Definition: road.h:140
ROAD_SE
@ ROAD_SE
South-east part.
Definition: road_type.h:54
random_func.hpp
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:18
DrawRoadTypeCatenary
void DrawRoadTypeCatenary(const TileInfo *ti, RoadType rt, RoadBits rb)
Draws the catenary for the RoadType of the given tile.
Definition: road_cmd.cpp:1359
OverflowSafeInt< int64 >
ROADTYPE_TRAM
@ ROADTYPE_TRAM
Trams.
Definition: road_type.h:25
DrawRailCatenary
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
Definition: elrail.cpp:566
RoadBuildCost
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition: road.h:250
HasPowerOnRoad
static bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
Definition: road.h:240
IsNormalRoadTile
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
Definition: road_map.h:74
SetRoadside
static void SetRoadside(TileIndex tile, Roadside s)
Set the decorations of a road.
Definition: road_map.h:503
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
MakeRoadDepot
static void MakeRoadDepot(TileIndex t, Owner owner, DepotID did, DiagDirection dir, RoadType rt)
Make a road depot.
Definition: road_map.h:683
GetRoadOwner
static Owner GetRoadOwner(TileIndex t, RoadTramType rtt)
Get the owner of a specific road type.
Definition: road_map.h:234
RATING_ROAD_DOWN_STEP_INNER
@ RATING_ROAD_DOWN_STEP_INNER
removing a roadpiece in the middle
Definition: town_type.h:64
TileDesc::owner_type
StringID owner_type[4]
Type of each owner.
Definition: tile_cmd.h:54
GetCrossingRoadAxis
static Axis GetCrossingRoadAxis(TileIndex t)
Get the road axis of a level crossing.
Definition: road_map.h:325
TRACKDIR_BIT_X_SW
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
Definition: track_type.h:110
GetOtherTunnelBridgeEnd
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Definition: tunnelbridge_map.h:78
ROAD_STOP_TRACKBIT_FACTOR
static const uint ROAD_STOP_TRACKBIT_FACTOR
Multiplier for how many regular track bits a bay stop counts.
Definition: economy_type.h:228
AllocateRoadType
RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
Allocate a new road type label.
Definition: road_cmd.cpp:141
SetTileOwner
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
GetRoadSpriteOffset
static uint GetRoadSpriteOffset(Slope slope, RoadBits bits)
Get the sprite offset within a spritegroup.
Definition: road_cmd.cpp:1316
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition: track_type.h:41
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
_invalid_tileh_slopes_road
static const RoadBits _invalid_tileh_slopes_road[2][15]
Invalid RoadBits on slopes.
Definition: road_cmd.cpp:209
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
MirrorRoadBits
static RoadBits MirrorRoadBits(RoadBits r)
Calculate the mirrored RoadBits.
Definition: road_func.h:51
DC_NONE
@ DC_NONE
no flag is set
Definition: command_type.h:356
ROTFB_NONE
@ ROTFB_NONE
All flags cleared.
Definition: road.h:45
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
RailtypeInfo::crossing
SpriteID crossing
level crossing, rail in X direction
Definition: rail.h:141
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
RailtypeInfo::strings
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
TRACKDIR_X_SW
@ TRACKDIR_X_SW
X-axis and direction to south-west.
Definition: track_type.h:80
TileDesc::tramtype
StringID tramtype
Type of tram on the tile.
Definition: tile_cmd.h:67
SpecializedVehicle::First
T * First() const
Get the first vehicle in the chain.
Definition: vehicle_base.h:1080
_roadtypes_type
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition: road_cmd.cpp:60
RoadNoLevelCrossing
static bool RoadNoLevelCrossing(RoadType roadtype)
Test if road disallows level crossings.
Definition: road.h:293
TUNNELBRIDGE_REMOVE
@ TUNNELBRIDGE_REMOVE
Removal of a tunnel or bridge owned by the towb.
Definition: town.h:169
GetTilePixelSlope
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
Definition: tile_map.h:280
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
ApplyFoundationToSlope
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.cpp:166
CheckRoadSlope
static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existing, RoadBits other)
Calculate the costs for roads on slopes Aside modify the RoadBits to fit on the slopes.
Definition: road_cmd.cpp:552
ROAD_REMOVE
@ ROAD_REMOVE
Removal of a road owned by the town.
Definition: town.h:168
ShowDepotWindow
void ShowDepotWindow(TileIndex tile, VehicleType type)
Opens a depot window.
Definition: depot_gui.cpp:1149
GetTunnelBridgeTransportType
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition: tunnelbridge_map.h:39
GetCrossingRailBits
static TrackBits GetCrossingRailBits(TileIndex tile)
Get the rail track bits of a level crossing.
Definition: road_map.h:368
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:79
ROADTYPES_NONE
@ ROADTYPES_NONE
No roadtypes.
Definition: road_type.h:37
Company
Definition: company_base.h:117
RVSB_IN_DEPOT
@ RVSB_IN_DEPOT
The vehicle is in a depot.
Definition: roadveh.h:39
HasRoadWorks
static bool HasRoadWorks(TileIndex t)
Check if a tile has road works.
Definition: road_map.h:513
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:166
ROTSG_CATENARY_BACK
@ ROTSG_CATENARY_BACK
Optional: Catenary back.
Definition: road.h:63
ROADTYPE_BEGIN
@ ROADTYPE_BEGIN
Used for iterations.
Definition: road_type.h:23
CanConnectToRoad
static bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir)
Checks whether a road or tram connection can be found when building a new road or tram.
Definition: road_cmd.cpp:952
CmdBuildRoadDepot
CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt, DiagDirection dir)
Build a road depot.
Definition: road_cmd.cpp:1151
SPR_ONEWAY_BASE
static const SpriteID SPR_ONEWAY_BASE
One way road sprites.
Definition: sprites.h:293
VehicleEnterTileStatus
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition: tile_cmd.h:20
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
DRD_END
@ DRD_END
Sentinel.
Definition: road_type.h:77
DRD_NORTHBOUND
@ DRD_NORTHBOUND
All northbound traffic is disallowed.
Definition: road_type.h:75
newgrf_railtype.h
TunnelBridgeIsFree
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore)
Finds vehicle in tunnel / bridge.
Definition: vehicle.cpp:568
road_cmd.h
DrawGroundSprite
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Definition: viewport.cpp:583
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
ROADSIDE_GRASS_ROAD_WORKS
@ ROADSIDE_GRASS_ROAD_WORKS
Road on grass with road works.
Definition: road_map.h:484
MayHaveRoad
static bool MayHaveRoad(TileIndex t)
Test whether a tile can have road/tram types.
Definition: road_map.h:33
SPR_TRAMWAY_BASE
static const SpriteID SPR_TRAMWAY_BASE
Tramway sprites.
Definition: sprites.h:272
TileVirtXY
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
RoadTypeInfo::strings
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
VETSB_ENTERED_WORMHOLE
@ VETSB_ENTERED_WORMHOLE
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition: tile_cmd.h:36
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
roadveh.h
TileDesc::road_speed
uint16 road_speed
Speed limit of road (bridges and track)
Definition: tile_cmd.h:66