OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "bridge.h"
12#include "road.h"
13#include "road_internal.h"
14#include "tilearea_type.h"
15#include "viewport_func.h"
16#include "command_func.h"
17#include "company_func.h"
19#include "depot_base.h"
20#include "newgrf.h"
21#include "autoslope.h"
22#include "tunnelbridge_map.h"
23#include "strings_func.h"
24#include "vehicle_func.h"
25#include "sound_func.h"
26#include "tunnelbridge.h"
27#include "cheat_type.h"
28#include "effectvehicle_func.h"
29#include "effectvehicle_base.h"
30#include "elrail_func.h"
31#include "roadveh.h"
32#include "train.h"
33#include "town.h"
34#include "company_base.h"
35#include "core/random_func.hpp"
37#include "newgrf_railtype.h"
38#include "newgrf_roadtype.h"
40#include "genworld.h"
41#include "company_gui.h"
42#include "road_func.h"
43#include "road_cmd.h"
44#include "landscape_cmd.h"
45#include "rail_cmd.h"
46
47#include "table/strings.h"
48#include "table/roadtypes.h"
49
50#include "safeguards.h"
51
53typedef std::vector<RoadVehicle *> RoadVehicleList;
54
55RoadTypeInfo _roadtypes[ROADTYPE_END];
56std::vector<RoadType> _sorted_roadtypes;
60
65{
66 static_assert(std::size(_original_roadtypes) <= std::size(_roadtypes));
67
68 auto insert = std::copy(std::begin(_original_roadtypes), std::end(_original_roadtypes), std::begin(_roadtypes));
69 std::fill(insert, std::end(_roadtypes), RoadTypeInfo{});
70
74}
75
76void ResolveRoadTypeGUISprites(RoadTypeInfo *rti)
77{
79 if (cursors_base != 0) {
80 rti->gui_sprites.build_y_road = cursors_base + 0;
81 rti->gui_sprites.build_x_road = cursors_base + 1;
82 rti->gui_sprites.auto_road = cursors_base + 2;
83 rti->gui_sprites.build_depot = cursors_base + 3;
84 rti->gui_sprites.build_tunnel = cursors_base + 4;
85 rti->gui_sprites.convert_road = cursors_base + 5;
86 rti->cursor.road_swne = cursors_base + 6;
87 rti->cursor.road_nwse = cursors_base + 7;
88 rti->cursor.autoroad = cursors_base + 8;
89 rti->cursor.depot = cursors_base + 9;
90 rti->cursor.tunnel = cursors_base + 10;
91 rti->cursor.convert_road = cursors_base + 11;
92 }
93}
94
101static bool CompareRoadTypes(const RoadType &first, const RoadType &second)
102{
103 if (RoadTypeIsRoad(first) == RoadTypeIsRoad(second)) {
105 }
106 return RoadTypeIsTram(first) < RoadTypeIsTram(second);
107}
108
113{
114 _sorted_roadtypes.clear();
115 for (RoadTypeInfo &rti : _roadtypes) {
116 RoadType rt = rti.Index();
117
118 ResolveRoadTypeGUISprites(&rti);
120
121 if (rti.label.Empty()) continue;
122 _sorted_roadtypes.push_back(rt);
123 }
124 std::sort(_sorted_roadtypes.begin(), _sorted_roadtypes.end(), CompareRoadTypes);
125}
126
133RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
134{
135 auto it = std::ranges::find(_roadtypes, RoadTypeLabel{}, &RoadTypeInfo::label);
136 if (it == std::end(_roadtypes)) return INVALID_ROADTYPE;
137
138 RoadTypeInfo &rti = *it;
139 RoadType rt = rti.Index();
140
141 /* Set up new road type based on default tram or road. */
143 rti.label = label;
144 rti.alternate_labels.clear();
145 rti.flags = {};
147
148 /* Make us compatible with ourself. */
149 rti.powered_roadtypes = rt;
150
151 /* We also introduce ourself. */
152 rti.introduces_roadtypes = rt;
153
154 /* Default sort order; order of allocation, but with some
155 * offsets so it's easier for NewGRF to pick a spot without
156 * changing the order of other (original) road types.
157 * The << is so you can place other roadtypes in between the
158 * other roadtypes, the 7 is to be able to place something
159 * before the first (default) road type. */
160 rti.sorting_order = rt << 2 | 7;
161
162 /* Set bitmap of road/tram types */
163 _roadtypes_road.Set(rt, rtt == RoadTramType::Road);
164 _roadtypes_tram.Set(rt, rtt == RoadTramType::Tram);
165
166 return rt;
167}
168
174{
175 return !RoadVehicle::Iterate().empty();
176}
177
184void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
185{
186 if (rt == INVALID_ROADTYPE) return;
187
189 if (c == nullptr) return;
190
191 c->infrastructure.road[rt] += count;
193}
194
196static const std::array<NonSteepSlopeIndexArray<RoadBits>, 2> _invalid_tileh_slopes_road = {{
197 /* The inverse of the mixable RoadBits on a leveled slope */
198 {{{
199 {}, // SLOPE_FLAT
200 {RoadBit::NE, RoadBit::SE}, // SLOPE_W
201 {RoadBit::NE, RoadBit::NW}, // SLOPE_S
202
203 RoadBit::NE, // SLOPE_SW
204 {RoadBit::NW, RoadBit::SW}, // SLOPE_E
205 {}, // SLOPE_EW
206
207 RoadBit::NW, // SLOPE_SE
208 {}, // SLOPE_WSE
209 {RoadBit::SE, RoadBit::SW}, // SLOPE_N
210
211 RoadBit::SE, // SLOPE_NW
212 {}, // SLOPE_NS
213 {}, // SLOPE_ENW
214
215 RoadBit::SW, // SLOPE_NE
216 {}, // SLOPE_SEN
217 {}, // SLOPE_NWS
218 }}},
219 /* The inverse of the allowed straight roads on a slope
220 * (with and without a foundation). */
221 {{{
222 {}, // SLOPE_FLAT
223 {}, // SLOPE_W (Foundation)
224 {}, // SLOPE_S (Foundation)
225
226 ROAD_Y, // SLOPE_SW
227 {}, // SLOPE_E (Foundation)
228 ROAD_ALL, // SLOPE_EW
229
230 ROAD_X, // SLOPE_SE
231 ROAD_ALL, // SLOPE_WSE
232 {}, // SLOPE_N (Foundation)
233
234 ROAD_X, // SLOPE_NW
235 ROAD_ALL, // SLOPE_NS
236 ROAD_ALL, // SLOPE_ENW
237
238 ROAD_Y, // SLOPE_NE
239 ROAD_ALL, // SLOPE_SEN
240 ROAD_ALL, // SLOPE_NW
241 }}}
242}};
243
244static Foundation GetRoadFoundation(Slope tileh, RoadBits bits);
245
256CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadTramType rtt, DoCommandFlags flags, bool town_check)
257{
258 if (_game_mode == GameMode::Editor || remove.None()) return CommandCost();
259
260 /* Water can always flood and towns can always remove "normal" road pieces.
261 * Towns are not be allowed to remove non "normal" road pieces, like tram
262 * tracks as that would result in trams that cannot turn. */
265
266 /* Only do the special processing if the road is owned
267 * by a town */
268 if (owner != OWNER_TOWN) {
269 if (owner == OWNER_NONE) return CommandCost();
270 CommandCost ret = CheckOwnership(owner);
271 return ret;
272 }
273
274 if (!town_check) return CommandCost();
275
276 if (_cheats.magic_bulldozer.value) return CommandCost();
277
278 Town *t = ClosestTownFromTile(tile, UINT_MAX);
279 if (t == nullptr) return CommandCost();
280
281 /* check if you're allowed to remove the street owned by a town
282 * removal allowance depends on difficulty setting */
284 if (ret.Failed()) return ret;
285
286 /* Get a bitmask of which neighbouring roads has a tile */
287 RoadBits n{};
288 RoadBits present = GetAnyRoadBits(tile, rtt);
289 if (present.Test(RoadBit::NE) && GetAnyRoadBits(TileAddXY(tile, -1, 0), rtt).Test(RoadBit::SW)) n.Set(RoadBit::NE);
290 if (present.Test(RoadBit::SE) && GetAnyRoadBits(TileAddXY(tile, 0, 1), rtt).Test(RoadBit::NW)) n.Set(RoadBit::SE);
291 if (present.Test(RoadBit::SW) && GetAnyRoadBits(TileAddXY(tile, 1, 0), rtt).Test(RoadBit::NE)) n.Set(RoadBit::SW);
292 if (present.Test(RoadBit::NW) && GetAnyRoadBits(TileAddXY(tile, 0, -1), rtt).Test(RoadBit::SE)) n.Set(RoadBit::NW);
293
294 int rating_decrease = RATING_ROAD_DOWN_STEP_EDGE;
295 /* If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
296 * then allow it */
297 if (n.Count() > 1 && n.Any(remove)) {
298 /* you can remove all kind of roads with extra dynamite */
299 if (!_settings_game.construction.extra_dynamite) {
300 return CommandCostWithParam(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS, t->index);
301 }
302 rating_decrease = RATING_ROAD_DOWN_STEP_INNER;
303 }
304 ChangeTownRating(t, rating_decrease, RATING_ROAD_MINIMUM, flags);
305
306 return CommandCost();
307}
308
309
319static CommandCost RemoveRoad(TileIndex tile, DoCommandFlags flags, RoadBits pieces, RoadTramType rtt, bool town_check)
320{
321 assert(pieces.Any());
322
323 RoadType existing_rt = MayHaveRoad(tile) ? GetRoadType(tile, rtt) : INVALID_ROADTYPE;
324 /* The tile doesn't have the given road type */
325 if (existing_rt == INVALID_ROADTYPE) return CommandCost((rtt == RoadTramType::Tram) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
326
327 switch (GetTileType(tile)) {
328 case TileType::Road: {
330 if (ret.Failed()) return ret;
331 break;
332 }
333
334 case TileType::Station: {
335 if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
336
338 if (ret.Failed()) return ret;
339 break;
340 }
341
345 if (ret.Failed()) return ret;
346 break;
347 }
348
349 default:
350 return CMD_ERROR;
351 }
352
353 CommandCost ret = CheckAllowRemoveRoad(tile, pieces, GetRoadOwner(tile, rtt), rtt, flags, town_check);
354 if (ret.Failed()) return ret;
355
356 if (!IsTileType(tile, TileType::Road)) {
357 /* If it's the last roadtype, just clear the whole tile */
358 if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) return Command<Commands::LandscapeClear>::Do(flags, tile);
359
362 /* Removing any roadbit in the bridge axis removes the roadtype (that's the behaviour remove-long-roads needs) */
363 if (!AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))).Any(pieces)) return CommandCost((rtt == RoadTramType::Tram) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
364
365 TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
366 /* Pay for *every* tile of the bridge or tunnel */
367 uint len = GetTunnelBridgeLength(other_end, tile) + 2;
368 cost.AddCost(len * 2 * RoadClearCost(existing_rt));
369 if (flags.Test(DoCommandFlag::Execute)) {
370 /* A full diagonal road tile has two road bits. */
371 UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
372
373 SetRoadType(other_end, rtt, INVALID_ROADTYPE);
374 SetRoadType(tile, rtt, INVALID_ROADTYPE);
375
376 /* If the owner of the bridge sells all its road, also move the ownership
377 * to the owner of the other roadtype, unless the bridge owner is a town. */
378 Owner other_owner = GetRoadOwner(tile, OtherRoadTramType(rtt));
379 if (!IsTileOwner(tile, other_owner) && !IsTileOwner(tile, OWNER_TOWN)) {
380 SetTileOwner(tile, other_owner);
381 SetTileOwner(other_end, other_owner);
382 }
383
384 /* Mark tiles dirty that have been repaved */
385 if (IsBridge(tile)) {
386 MarkBridgeDirty(tile);
387 } else {
389 MarkTileDirtyByTile(other_end);
390 }
391 }
392 } else {
393 assert(IsDriveThroughStopTile(tile));
394 cost.AddCost(RoadClearCost(existing_rt) * 2);
395 if (flags.Test(DoCommandFlag::Execute)) {
396 /* A full diagonal road tile has two road bits. */
397 UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -2);
398 SetRoadType(tile, rtt, INVALID_ROADTYPE);
400 }
401 }
402 return cost;
403 }
404
405 switch (GetRoadTileType(tile)) {
407 Slope tileh = GetTileSlope(tile);
408
409 /* Steep slopes behave the same as slopes with one corner raised. */
410 if (IsSteepSlope(tileh)) {
412 }
413
414 RoadBits present = GetRoadBits(tile, rtt);
415 const RoadBits other = GetRoadBits(tile, OtherRoadTramType(rtt));
416 const Foundation f = GetRoadFoundation(tileh, present);
417
418 if (HasRoadWorks(tile) && _current_company != OWNER_WATER) return CommandCost(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
419
420 /* Autocomplete to a straight road
421 * @li if the bits of the other roadtypes result in another foundation
422 * @li if build on slopes is disabled */
423 if ((IsStraightRoad(other) && other.Any(_invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED])) ||
424 (tileh != SLOPE_FLAT && !_settings_game.construction.build_on_slopes)) {
425 pieces.Set(MirrorRoadBits(pieces));
426 }
427
428 /* limit the bits to delete to the existing bits. */
429 pieces &= present;
430 if (pieces.None()) return CommandCost((rtt == RoadTramType::Tram) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
431
432 /* Now set present what it will be after the remove */
433 present.Flip(pieces);
434
435 /* Check for invalid RoadBit combinations on slopes */
436 if (tileh != SLOPE_FLAT && present.Any() &&
437 _invalid_tileh_slopes_road[0][tileh & SLOPE_ELEVATED].All(present)) {
438 return CMD_ERROR;
439 }
440
441 if (flags.Test(DoCommandFlag::Execute)) {
442 if (HasRoadWorks(tile)) {
443 /* flooding tile with road works, don't forget to remove the effect vehicle too */
444 assert(_current_company == OWNER_WATER);
446 if (TileVirtXY(v->x_pos, v->y_pos) == tile) {
447 delete v;
448 }
449 }
450 }
451
452 UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -static_cast<int>(pieces.Count()));
453
454 if (present.None()) {
455 /* No other road type, just clear tile. */
456 if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) {
457 /* Includes MarkTileDirtyByTile() */
458 DoClearSquare(tile);
459 } else {
460 if (rtt == RoadTramType::Road && IsRoadOwner(tile, rtt, OWNER_TOWN)) {
461 /* Update nearest-town index */
462 const Town *town = CalcClosestTownFromTile(tile);
463 SetTownIndex(tile, town == nullptr ? TownID::Invalid() : town->index);
464 }
466 SetRoadBits(tile, {}, rtt);
467 SetRoadType(tile, rtt, INVALID_ROADTYPE);
469 }
470 } else {
471 /* When bits are removed, you *always* end up with something that
472 * is not a complete straight road tile. However, trams do not have
473 * onewayness, so they cannot remove it either. */
475 SetRoadBits(tile, present, rtt);
477 }
478 }
479
480 CommandCost cost(ExpensesType::Construction, pieces.Count() * RoadClearCost(existing_rt));
481 /* If we build a foundation we have to pay for it. */
483
484 return cost;
485 }
486
488 if (pieces.Any(ComplementRoadBits(GetCrossingRoadBits(tile)))) {
489 return CMD_ERROR;
490 }
491
492 if (flags.Test(DoCommandFlag::Execute)) {
494
495 /* A full diagonal road tile has two road bits. */
496 UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -2);
497
498 Track track = GetCrossingRailTrack(tile);
499 if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) {
500 bool reserved = HasCrossingReservation(tile);
501 MakeRailNormal(tile, GetTileOwner(tile), track, GetRailType(tile));
502 if (reserved) SetTrackReservation(tile, track);
503
504 /* Update rail count for level crossings. The plain track should still be accounted
505 * for, so only subtract the difference to the level crossing cost. */
507 if (c != nullptr) {
510 }
511 } else {
512 SetRoadType(tile, rtt, INVALID_ROADTYPE);
513 }
515 YapfNotifyTrackLayoutChange(tile, track);
516 }
517 return CommandCost(ExpensesType::Construction, RoadClearCost(existing_rt) * 2);
518 }
519
520 default:
522 return CMD_ERROR;
523 }
524}
525
526
538static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existing, RoadBits other)
539{
540 /* Remove already build pieces */
541 pieces->Reset(existing);
542
543 /* If we can't build anything stop here */
544 if (pieces->None()) return CMD_ERROR;
545
546 /* All RoadBit combos are valid on flat land */
547 if (tileh == SLOPE_FLAT) return CommandCost();
548
549 /* Steep slopes behave the same as slopes with one corner raised. */
550 if (IsSteepSlope(tileh)) {
552 }
553
554 /* Save the merge of all bits of the current type */
555 RoadBits type_bits = existing | *pieces;
556
557 /* Roads on slopes */
558 if (_settings_game.construction.build_on_slopes && !_invalid_tileh_slopes_road[0][tileh].Any(other | type_bits)) {
559
560 /* If we add leveling we've got to pay for it */
561 if ((other | existing).None()) return CommandCost(ExpensesType::Construction, _price[Price::BuildFoundation]);
562
563 return CommandCost();
564 }
565
566 /* Autocomplete uphill roads */
567 pieces->Set(MirrorRoadBits(*pieces));
568 type_bits = existing | *pieces;
569
570 /* Uphill roads */
571 if (IsStraightRoad(type_bits) && (other == type_bits || other.None()) &&
572 !_invalid_tileh_slopes_road[1][tileh].Any(other | type_bits)) {
573
574 /* Slopes with foundation ? */
575 if (IsSlopeWithOneCornerRaised(tileh)) {
576
577 /* Prevent build on slopes if it isn't allowed */
578 if (_settings_game.construction.build_on_slopes) {
579
580 /* If we add foundation we've got to pay for it */
581 if ((other | existing).None()) return CommandCost(ExpensesType::Construction, _price[Price::BuildFoundation]);
582
583 return CommandCost();
584 }
585 } else {
587 return CommandCost();
588 }
589 }
590 return CMD_ERROR;
591}
592
604{
605 CompanyID company = _current_company;
607
608 RoadBits existing{};
609 RoadBits other_bits{};
610
611 /* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
612 * if a non-company is building the road */
613 if ((Company::IsValidID(company) && town_id != TownID::Invalid()) || (company == OWNER_TOWN && !Town::IsValidID(town_id)) || (company == OWNER_DEITY && town_id != TownID::Invalid())) return CMD_ERROR;
614 if (company != OWNER_TOWN) {
615 const Town *town = CalcClosestTownFromTile(tile);
616 town_id = (town != nullptr) ? town->index : TownID::Invalid();
617
618 if (company == OWNER_DEITY) {
619 company = OWNER_TOWN;
620
621 /* If we are not within a town, we are not owned by the town */
622 if (town == nullptr || DistanceSquare(tile, town->xy) > town->cache.squared_town_zone_radius[to_underlying(HouseZone::TownEdge)]) {
623 company = OWNER_NONE;
624 }
625 }
626 }
627
628 /* do not allow building 'zero' road bits, code wouldn't handle it */
629 if (pieces.None() || !IsValidRoadBits(pieces) || !IsValidDisallowedRoadDirections(toggle_drd)) return CMD_ERROR;
630 if (!ValParamRoadType(rt)) return CMD_ERROR;
631
632 Slope tileh = GetTileSlope(tile);
633 RoadTramType rtt = GetRoadTramType(rt);
634
635 bool need_to_clear = false;
636 switch (GetTileType(tile)) {
637 case TileType::Road:
638 switch (GetRoadTileType(tile)) {
640 if (HasRoadWorks(tile)) return CommandCost(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
641
642 other_bits = GetRoadBits(tile, OtherRoadTramType(rtt));
643 if (!HasTileRoadType(tile, rtt)) break;
644
645 existing = GetRoadBits(tile, rtt);
646 bool crossing = !IsStraightRoad(existing | pieces);
647 if (rtt == RoadTramType::Road && (GetDisallowedRoadDirections(tile).Any() || toggle_drd.Any()) && crossing) {
648 /* Junctions cannot be one-way */
649 return CommandCost(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
650 }
651 if (existing.All(pieces)) {
652 /* We only want to set the (dis)allowed road directions */
653 if (toggle_drd.Any() && rtt == RoadTramType::Road) {
654 Owner owner = GetRoadOwner(tile, rtt);
655 if (owner != OWNER_NONE) {
656 CommandCost ret = CheckOwnership(owner, tile);
657 if (ret.Failed()) return ret;
658 }
659
662
663 /* We allow removing disallowed directions to break up
664 * deadlocks, but adding them can break articulated
665 * vehicles. As such, only when less is disallowed,
666 * i.e. bits are removed, we skip the vehicle check. */
667 if (dis_existing.Count() <= dis_new.Count()) {
669 if (ret.Failed()) return ret;
670 }
671
672 /* Ignore half built tiles */
673 if (flags.Test(DoCommandFlag::Execute) && IsStraightRoad(existing)) {
674 SetDisallowedRoadDirections(tile, dis_new);
676 }
677 return CommandCost();
678 }
679 return CommandCost(STR_ERROR_ALREADY_BUILT);
680 }
681 /* Disallow breaking end-of-line of someone else
682 * so trams can still reverse on this tile. */
683 if (rtt == RoadTramType::Tram && existing.Count() == 1) {
684 Owner owner = GetRoadOwner(tile, rtt);
685 if (Company::IsValidID(owner)) {
686 CommandCost ret = CheckOwnership(owner);
687 if (ret.Failed()) return ret;
688 }
689 }
690 break;
691 }
692
694 if (RoadNoLevelCrossing(rt)) {
695 return CommandCost(STR_ERROR_CROSSING_DISALLOWED_ROAD);
696 }
697
698 other_bits = GetCrossingRoadBits(tile);
699 if (pieces.Any(ComplementRoadBits(other_bits))) goto do_clear;
700 pieces = other_bits; // we need to pay for both roadbits
701
702 if (HasTileRoadType(tile, rtt)) return CommandCost(STR_ERROR_ALREADY_BUILT);
703 break;
704
706 if (GetAnyRoadBits(tile, rtt).All(pieces)) return CommandCost(STR_ERROR_ALREADY_BUILT);
707 goto do_clear;
708
709 default: NOT_REACHED();
710 }
711 break;
712
713 case TileType::Railway: {
714 if (IsSteepSlope(tileh)) {
715 return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
716 }
717
718 /* Level crossings may only be built on these slopes */
719 if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) {
720 return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
721 }
722
723 if (!_settings_game.construction.crossing_with_competitor && company != OWNER_TOWN && company != OWNER_DEITY) {
725 if (ret.Failed()) return ret;
726 }
727
728 if (GetRailTileType(tile) != RailTileType::Normal) goto do_clear;
729
730 if (RoadNoLevelCrossing(rt)) {
731 return CommandCost(STR_ERROR_CROSSING_DISALLOWED_ROAD);
732 }
733
735 return CommandCost(STR_ERROR_CROSSING_DISALLOWED_RAIL);
736 }
737
738 Axis roaddir;
739 switch (GetTrackBits(tile).base()) {
740 case TrackBits{Track::X}.base():
741 if (pieces.Any(ROAD_X)) goto do_clear;
742 roaddir = Axis::Y;
743 break;
744
745 case TrackBits{Track::Y}.base():
746 if (pieces.Any(ROAD_Y)) goto do_clear;
747 roaddir = Axis::X;
748 break;
749
750 default: goto do_clear;
751 }
752
754 if (ret.Failed()) return ret;
755
756 if (flags.Test(DoCommandFlag::Execute)) {
757 Track railtrack = AxisToTrack(OtherAxis(roaddir));
758 YapfNotifyTrackLayoutChange(tile, railtrack);
759 /* Update company infrastructure counts. A level crossing has two road bits. */
760 UpdateCompanyRoadInfrastructure(rt, company, 2);
761
762 /* Update rail count for level crossings. The plain track is already
763 * counted, so only add the difference to the level crossing cost. */
765 if (c != nullptr) {
768 }
769
770 /* Always add road to the roadtypes (can't draw without it) */
771 bool reserved = GetRailReservationTrackBits(tile).Test(railtrack);
772 MakeRoadCrossing(tile, company, company, GetTileOwner(tile), roaddir, GetRailType(tile), rtt == RoadTramType::Road ? rt : INVALID_ROADTYPE, (rtt == RoadTramType::Tram) ? rt : INVALID_ROADTYPE, town_id);
773 SetCrossingReservation(tile, reserved);
774 UpdateLevelCrossing(tile, false);
777 }
779 }
780
781 case TileType::Station: {
782 if (GetAnyRoadBits(tile, rtt).All(pieces)) return CommandCost(STR_ERROR_ALREADY_BUILT);
783 if (!IsDriveThroughStopTile(tile)) goto do_clear;
784
786 if (pieces.Any(ComplementRoadBits(curbits))) goto do_clear;
787 pieces = curbits; // we need to pay for both roadbits
788
789 if (HasTileRoadType(tile, rtt)) return CommandCost(STR_ERROR_ALREADY_BUILT);
790 break;
791 }
792
794 if (GetTunnelBridgeTransportType(tile) != TransportType::Road) goto do_clear;
795 /* Only allow building the outer roadbit, so building long roads stops at existing bridges */
796 if (MirrorRoadBits(DiagDirToRoadBits(GetTunnelBridgeDirection(tile))) != pieces) goto do_clear;
797 if (HasTileRoadType(tile, rtt)) return CommandCost(STR_ERROR_ALREADY_BUILT);
798 /* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
800 if (ret.Failed()) return ret;
801 break;
802 }
803
804 default: {
805do_clear:;
806 need_to_clear = true;
807 break;
808 }
809 }
810
811 if (need_to_clear) {
812 CommandCost ret = Command<Commands::LandscapeClear>::Do(flags, tile);
813 if (ret.Failed()) return ret;
814 cost.AddCost(ret.GetCost());
815 }
816
817 if (other_bits != pieces) {
818 /* Check the foundation/slopes when adding road/tram bits */
819 CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
820 /* Return an error if we need to build a foundation (ret != 0) but the
821 * current setting is turned off */
822 if (ret.Failed() || (ret.GetCost() != 0 && !_settings_game.construction.build_on_slopes)) {
823 return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
824 }
825 cost.AddCost(ret.GetCost());
826 }
827
828 if (!need_to_clear) {
829 if (IsTileType(tile, TileType::Road)) {
830 /* Don't put the pieces that already exist */
831 pieces.Reset(existing);
832
833 /* Check if new road bits will have the same foundation as other existing road types */
834 if (IsNormalRoad(tile)) {
835 Slope slope = GetTileSlope(tile);
836 Foundation found_new = GetRoadFoundation(slope, pieces | existing);
837
838 RoadBits bits = GetRoadBits(tile, OtherRoadTramType(rtt));
839 /* do not check if there are not road bits of given type */
840 if (bits.Any() && GetRoadFoundation(slope, bits) != found_new) {
841 return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
842 }
843 }
844 }
845
847 if (ret.Failed()) return ret;
848
849 if (IsNormalRoadTile(tile)) {
850 /* If the road types don't match, try to convert only if vehicles of
851 * the new road type are not powered on the present road type and vehicles of
852 * the present road type are powered on the new road type. */
853 RoadType existing_rt = GetRoadType(tile, rtt);
854 if (existing_rt != INVALID_ROADTYPE && existing_rt != rt) {
855 if (HasPowerOnRoad(rt, existing_rt)) {
856 rt = existing_rt;
857 } else if (HasPowerOnRoad(existing_rt, rt)) {
858 ret = Command<Commands::ConvertRoad>::Do(flags, tile, tile, rt, false);
859 if (ret.Failed()) return ret;
860 cost.AddCost(ret.GetCost());
861 } else {
862 return CMD_ERROR;
863 }
864 }
865 }
866 }
867
868 uint num_pieces = (!need_to_clear && IsTileType(tile, TileType::TunnelBridge)) ?
869 /* There are 2 pieces on *every* tile of the bridge or tunnel */
870 2 * (GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2) :
871 /* Count pieces */
872 pieces.Count();
873
874 cost.AddCost(num_pieces * RoadBuildCost(rt));
875
876 if (flags.Test(DoCommandFlag::Execute)) {
877 switch (GetTileType(tile)) {
878 case TileType::Road: {
879 RoadTileType rttype = GetRoadTileType(tile);
880 if (existing.None() || rttype == RoadTileType::Crossing) {
881 SetRoadType(tile, rtt, rt);
882 SetRoadOwner(tile, rtt, company);
883 if (rtt == RoadTramType::Road) SetTownIndex(tile, town_id);
884 }
885 if (rttype != RoadTileType::Crossing) SetRoadBits(tile, existing | pieces, rtt);
886 break;
887 }
888
890 TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
891
892 SetRoadType(other_end, rtt, rt);
893 SetRoadType(tile, rtt, rt);
894 SetRoadOwner(other_end, rtt, company);
895 SetRoadOwner(tile, rtt, company);
896
897 /* Mark tiles dirty that have been repaved */
898 if (IsBridge(tile)) {
899 MarkBridgeDirty(tile);
900 } else {
901 MarkTileDirtyByTile(other_end);
903 }
904 break;
905 }
906
907 case TileType::Station: {
908 assert(IsDriveThroughStopTile(tile));
909 SetRoadType(tile, rtt, rt);
910 SetRoadOwner(tile, rtt, company);
911 break;
912 }
913
914 default:
915 MakeRoadNormal(tile, pieces, (rtt == RoadTramType::Road) ? rt : INVALID_ROADTYPE, (rtt == RoadTramType::Tram) ? rt : INVALID_ROADTYPE, town_id, company, company);
916 break;
917 }
918
919 /* Update company infrastructure count. */
921 UpdateCompanyRoadInfrastructure(rt, GetRoadOwner(tile, rtt), num_pieces);
922
923 if (rtt == RoadTramType::Road && IsNormalRoadTile(tile)) {
924 existing.Set(pieces);
926 GetDisallowedRoadDirections(tile).Flip(toggle_drd) : DisallowedRoadDirections{});
927 }
928
930 }
931 return cost;
932}
933
942{
943 tile += TileOffsByDiagDir(dir);
944 if (!IsValidTile(tile) || !MayHaveRoad(tile)) return false;
945
946 RoadTramType rtt = GetRoadTramType(rt);
947 RoadType existing = GetRoadType(tile, rtt);
948 if (existing == INVALID_ROADTYPE) return false;
949 if (!HasPowerOnRoad(existing, rt) && !HasPowerOnRoad(rt, existing)) return false;
950
951 RoadBits bits = GetAnyRoadBits(tile, rtt, false);
952 return bits.Any(DiagDirToRoadBits(ReverseDiagDir(dir)));
953}
954
970CommandCost CmdBuildLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, DisallowedRoadDirections drd, bool start_half, bool end_half, bool is_ai)
971{
972 if (start_tile >= Map::Size()) return CMD_ERROR;
973
974 if (!ValParamRoadType(rt) || !IsValidAxis(axis) || !IsValidDisallowedRoadDirections(drd)) return CMD_ERROR;
975
976 /* Only drag in X or Y direction dictated by the direction variable */
977 if (axis == Axis::X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
978 if (axis == Axis::Y && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
979
980 DiagDirection dir = AxisToDiagDir(axis);
981
982 /* Swap direction, also the half-tile drag vars. */
983 if (start_tile > end_tile || (start_tile == end_tile && start_half)) {
984 dir = ReverseDiagDir(dir);
985 start_half = !start_half;
986 end_half = !end_half;
988 }
989
990 /* On the X-axis, we have to swap the initial bits, so they
991 * will be interpreted correctly in the GTTS. Furthermore
992 * when you just 'click' on one tile to build them. */
993 if ((drd == DisallowedRoadDirection::Northbound || drd == DisallowedRoadDirection::Southbound) && (axis == Axis::Y) == (start_tile == end_tile && start_half == end_half)) drd.Flip({DisallowedRoadDirection::Northbound, DisallowedRoadDirection::Southbound});
994
996 CommandCost last_error = CMD_ERROR;
997 TileIndex tile = start_tile;
998 bool had_bridge = false;
999 bool had_tunnel = false;
1000 bool had_success = false;
1001
1002 /* Start tile is the first tile clicked by the user. */
1003 for (;;) {
1004 RoadBits bits = AxisToRoadBits(axis);
1005
1006 /* Determine which road parts should be built. */
1007 if (!is_ai && start_tile != end_tile) {
1008 /* Only build the first and last roadbit if they can connect to something. */
1009 if (tile == end_tile && !CanConnectToRoad(tile, rt, dir)) {
1010 bits = DiagDirToRoadBits(ReverseDiagDir(dir));
1011 } else if (tile == start_tile && !CanConnectToRoad(tile, rt, ReverseDiagDir(dir))) {
1012 bits = DiagDirToRoadBits(dir);
1013 }
1014 } else {
1015 /* Road parts only have to be built at the start tile or at the end tile. */
1016 if (tile == end_tile && !end_half) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
1017 if (tile == start_tile && start_half) bits &= DiagDirToRoadBits(dir);
1018 }
1019
1020 CommandCost ret = Command<Commands::BuildRoad>::Do(flags, tile, bits, rt, drd, TownID::Invalid());
1021 if (!is_ai && ret.GetErrorMessage() == STR_ERROR_ALREADY_BUILT) had_success = true;
1022 if (ret.Failed()) {
1023 last_error = std::move(ret);
1024 if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) {
1025 if (is_ai) return last_error;
1026 if (had_success) break; // Keep going if we haven't constructed any road yet, skipping the start of the drag
1027 }
1028 } else {
1029 had_success = true;
1030 /* Only pay for the upgrade on one side of the bridges and tunnels */
1032 if (IsBridge(tile)) {
1033 if (!had_bridge || GetTunnelBridgeDirection(tile) == dir) {
1034 cost.AddCost(ret.GetCost());
1035 }
1036 had_bridge = true;
1037 } else { // IsTunnel(tile)
1038 if (!had_tunnel || GetTunnelBridgeDirection(tile) == dir) {
1039 cost.AddCost(ret.GetCost());
1040 }
1041 had_tunnel = true;
1042 }
1043 } else {
1044 cost.AddCost(ret.GetCost());
1045 }
1046 }
1047
1048 if (tile == end_tile) break;
1049
1050 tile += TileOffsByDiagDir(dir);
1051 }
1052
1053 return had_success ? cost : last_error;
1054}
1055
1067std::tuple<CommandCost, Money> CmdRemoveLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, bool start_half, bool end_half)
1068{
1070
1071 if (start_tile >= Map::Size()) return { CMD_ERROR, 0 };
1072 if (!ValParamRoadType(rt) || !IsValidAxis(axis)) return { CMD_ERROR, 0 };
1073
1074 /* Only drag in X or Y direction dictated by the direction variable */
1075 if (axis == Axis::X && TileY(start_tile) != TileY(end_tile)) return { CMD_ERROR, 0 }; // x-axis
1076 if (axis == Axis::Y && TileX(start_tile) != TileX(end_tile)) return { CMD_ERROR, 0 }; // y-axis
1077
1078 /* Swap start and ending tile, also the half-tile drag vars. */
1079 if (start_tile > end_tile || (start_tile == end_tile && start_half)) {
1080 std::swap(start_tile, end_tile);
1081 std::swap(start_half, end_half);
1082 }
1083
1084 Money money_available = GetAvailableMoneyForCommand();
1085 Money money_spent = 0;
1086 TileIndex tile = start_tile;
1087 CommandCost last_error = CMD_ERROR;
1088 bool had_success = false;
1089 /* Start tile is the small number. */
1090 for (;;) {
1091 RoadBits bits = AxisToRoadBits(axis);
1092
1093 if (tile == end_tile && !end_half) bits &= RoadBits{RoadBit::NW, RoadBit::NE};
1094 if (tile == start_tile && start_half) bits &= RoadBits{RoadBit::SE, RoadBit::SW};
1095
1096 /* try to remove the halves. */
1097 if (bits.Any()) {
1098 RoadTramType rtt = GetRoadTramType(rt);
1099 CommandCost ret = RemoveRoad(tile, DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), bits, rtt, true);
1100 if (ret.Succeeded()) {
1101 if (flags.Test(DoCommandFlag::Execute)) {
1102 money_spent += ret.GetCost();
1103 if (money_spent > 0 && money_spent > money_available) {
1104 return { cost, ExtractCommandCost(Command<Commands::RemoveRoadLong>::Do(DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), end_tile, start_tile, rt, axis, start_half, end_half)).GetCost() };
1105 }
1106 RemoveRoad(tile, flags, bits, rtt, false);
1107 }
1108 cost.AddCost(ret.GetCost());
1109 had_success = true;
1110 } else {
1111 /* Some errors are more equal than others. */
1112 switch (last_error.GetErrorMessage().base()) {
1113 case STR_ERROR_OWNED_BY.base():
1114 case STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS.base():
1115 break;
1116 default:
1117 last_error = std::move(ret);
1118 }
1119 }
1120 }
1121
1122 if (tile == end_tile) break;
1123
1124 tile += TileOffsByAxis(axis);
1125 }
1126
1127 return { had_success ? cost : last_error, 0 };
1128}
1129
1139{
1140 if (!ValParamRoadType(rt) || !IsValidDiagDirection(dir)) return CMD_ERROR;
1141
1143
1144 Slope tileh = GetTileSlope(tile);
1145 if (tileh != SLOPE_FLAT) {
1146 if (!_settings_game.construction.build_on_slopes) return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
1147 if (!CanBuildDepotByTileh(dir, tileh)) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
1149 }
1150
1151 /* Allow the user to rotate the depot instead of having to destroy it and build it again */
1152 bool rotate_existing_depot = false;
1153 if (IsRoadDepotTile(tile) && (HasRoadTypeTram(tile) ? rt == GetRoadTypeTram(tile) : rt == GetRoadTypeRoad(tile)))
1154 {
1155 CommandCost ret = CheckTileOwnership(tile);
1156 if (ret.Failed()) return ret;
1157
1158 if (dir == GetRoadDepotDirection(tile)) return CommandCost();
1159
1160 ret = EnsureNoVehicleOnGround(tile);
1161 if (ret.Failed()) return ret;
1162
1163 rotate_existing_depot = true;
1164 }
1165
1166 if (!rotate_existing_depot) {
1167 cost.AddCost(Command<Commands::LandscapeClear>::Do(flags, tile));
1168 if (cost.Failed()) return cost;
1169
1170 if (IsBridgeAbove(tile)) {
1172 if (height_diff > 0) return CommandCostWithParam(STR_ERROR_BRIDGE_TOO_LOW_FOR_ROADVEH_DEPOT, height_diff * TILE_HEIGHT_STEP);
1173 }
1174
1175 if (!Depot::CanAllocateItem()) return CMD_ERROR;
1176 }
1177
1178 if (flags.Test(DoCommandFlag::Execute)) {
1179 if (rotate_existing_depot) {
1180 SetRoadDepotExitDirection(tile, dir);
1181 } else {
1182 Depot *dep = Depot::Create(tile);
1183 MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
1184 MakeDefaultName(dep);
1185
1186 /* A road depot has two road bits. */
1188 }
1189
1190 MarkTileDirtyByTile(tile);
1191 }
1192
1194 return cost;
1195}
1196
1197static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlags flags)
1198{
1200 CommandCost ret = CheckTileOwnership(tile);
1201 if (ret.Failed()) return ret;
1202 }
1203
1205 if (ret.Failed()) return ret;
1206
1207 if (flags.Test(DoCommandFlag::Execute)) {
1209 if (c != nullptr) {
1210 /* A road depot has two road bits. */
1211 RoadType rt = GetRoadTypeRoad(tile);
1212 if (rt == INVALID_ROADTYPE) rt = GetRoadTypeTram(tile);
1215 }
1216
1217 delete Depot::GetByTile(tile);
1218 DoClearSquare(tile);
1219 }
1220
1222}
1223
1226{
1227 switch (GetRoadTileType(tile)) {
1228 case RoadTileType::Normal: {
1229 RoadBits b = GetAllRoadBits(tile);
1230
1231 /* Clear the road if only one piece is on the tile OR we are not using the DoCommandFlag::Auto flag */
1232 if ((b.Count() == 1 && GetRoadBits(tile, RoadTramType::Tram).None()) || !flags.Test(DoCommandFlag::Auto)) {
1234 for (RoadTramType rtt : ROADTRAMTYPES_ALL) {
1235 if (!MayHaveRoad(tile) || GetRoadType(tile, rtt) == INVALID_ROADTYPE) continue;
1236
1237 CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rtt), rtt, true);
1238 if (tmp_ret.Failed()) return tmp_ret;
1239 ret.AddCost(tmp_ret.GetCost());
1240 }
1241 return ret;
1242 }
1243 return CommandCost(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
1244 }
1245
1248
1249 if (flags.Test(DoCommandFlag::Auto)) return CommandCost(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
1250
1251 /* Must iterate over the roadtypes in a reverse manner because
1252 * tram tracks must be removed before the road bits. */
1254 if (!MayHaveRoad(tile) || GetRoadType(tile, rtt) == INVALID_ROADTYPE) continue;
1255
1256 CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rtt, true);
1257 if (tmp_ret.Failed()) return tmp_ret;
1258 ret.AddCost(tmp_ret.GetCost());
1259 }
1260
1261 if (flags.Test(DoCommandFlag::Execute)) {
1262 Command<Commands::LandscapeClear>::Do(flags, tile);
1263 }
1264 return ret;
1265 }
1266
1267 default:
1269 if (flags.Test(DoCommandFlag::Auto)) {
1270 return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
1271 }
1272 return RemoveRoadDepot(tile, flags);
1273 }
1274}
1275
1276
1278 uint16_t image;
1279 uint8_t subcoord_x;
1280 uint8_t subcoord_y;
1281};
1282
1283#include "table/road_land.h"
1284
1293{
1294 /* Flat land and land without a road doesn't require a foundation */
1295 if (tileh == SLOPE_FLAT || bits.None()) return Foundation::None;
1296
1297 /* Steep slopes behave the same as slopes with one corner raised. */
1298 if (IsSteepSlope(tileh)) {
1300 }
1301
1302 /* Leveled RoadBits on a slope */
1303 if (!_invalid_tileh_slopes_road[0][tileh].Any(bits)) return Foundation::Leveled;
1304
1305 /* Straight roads without foundation on a slope */
1306 if (!IsSlopeWithOneCornerRaised(tileh) &&
1307 !_invalid_tileh_slopes_road[1][tileh].Any(bits))
1308 return Foundation::None;
1309
1310 /* Roads on steep Slopes or on Slopes with one corner raised */
1312}
1313
1316 0xFF, // Dummy value to prevent `index - 1` while accesing.
1317 0, 0, 2, 0,
1318 0, 1, 0, 0,
1319 3, 0, 0, 0,
1320 0, 0
1321};
1322
1329static uint GetRoadSpriteOffset(Slope slope, RoadBits bits)
1330{
1331 if (slope != SLOPE_FLAT) {
1332 switch (slope) {
1333 case SLOPE_NE: return 11;
1334 case SLOPE_SE: return 12;
1335 case SLOPE_SW: return 13;
1336 case SLOPE_NW: return 14;
1337 default: NOT_REACHED();
1338 }
1339 } else {
1340 static const uint offsets[] = {
1341 0, 18, 17, 7,
1342 16, 0, 10, 5,
1343 15, 8, 1, 4,
1344 9, 3, 6, 2
1345 };
1346 return offsets[bits.base()];
1347 }
1348}
1349
1359static bool DrawRoadAsSnowOrDesert(bool snow_or_desert, Roadside roadside)
1360{
1361 return (snow_or_desert &&
1363 roadside != Roadside::Barren && roadside != Roadside::Grass && roadside != Roadside::GrassRoadWorks));
1364}
1365
1373{
1374 /* Don't draw the catenary under a low bridge */
1376 int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
1377
1378 if (height <= GetTileMaxZ(ti->tile) + 1) return;
1379 }
1380
1381 if (rb.Count() > 2) {
1382 /* On junctions we check whether neighbouring tiles also have catenary, and possibly
1383 * do not draw catenary towards those neighbours, which do not have catenary. */
1384 RoadBits rb_new{};
1386 if (rb.Any(DiagDirToRoadBits(dir))) {
1387 TileIndex neighbour = TileAddByDiagDir(ti->tile, dir);
1388 if (MayHaveRoad(neighbour)) {
1389 RoadType rt_road = GetRoadTypeRoad(neighbour);
1390 RoadType rt_tram = GetRoadTypeTram(neighbour);
1391
1392 if ((rt_road != INVALID_ROADTYPE && HasRoadCatenary(rt_road)) ||
1393 (rt_tram != INVALID_ROADTYPE && HasRoadCatenary(rt_tram))) {
1394 rb_new.Set(DiagDirToRoadBits(dir));
1395 }
1396 }
1397 }
1398 }
1399 if (rb_new.Count() >= 2) rb = rb_new;
1400 }
1401
1402 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1405
1406 if (front != 0 || back != 0) {
1407 if (front != 0) front += GetRoadSpriteOffset(ti->tileh, rb);
1408 if (back != 0) back += GetRoadSpriteOffset(ti->tileh, rb);
1409 } else if (ti->tileh != SLOPE_FLAT) {
1412 } else {
1413 back = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[rb.base()];
1414 front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[rb.base()];
1415 }
1416
1417 /* Catenary uses 1st company colour to help identify owner.
1418 * For tiles with OWNER_TOWN or OWNER_NONE, recolour CC to grey as a neutral colour. */
1419 Owner owner = GetRoadOwner(ti->tile, GetRoadTramType(rt));
1420 PaletteID pal = (owner == OWNER_NONE || owner == OWNER_TOWN ? GetColourPalette(Colours::Grey) : GetCompanyPalette(owner));
1421 uint8_t z_wires = (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT) + BB_HEIGHT_UNDER_BRIDGE;
1422 if (back != 0) {
1423 /* The "back" sprite contains the west, north and east pillars.
1424 * We cut the sprite at 3/8 of the west/east edges to create 3 sprites.
1425 * 3/8 is chosen so that sprites can somewhat graphically extend into the tile. */
1426 static const int INF = 1000;
1427 static const SubSprite west = { -INF, -INF, -12, INF };
1428 static const SubSprite north = { -12, -INF, 12, INF };
1429 static const SubSprite east = { 12, -INF, INF, INF };
1430 int8_t west_z = GetSlopePixelZInCorner(ti->tileh, Corner::W);
1431 int8_t north_z = GetSlopePixelZInCorner(ti->tileh, Corner::N);
1432 int8_t east_z = GetSlopePixelZInCorner(ti->tileh, Corner::E);
1433 AddSortableSpriteToDraw(back, pal, *ti, {{15, 0, west_z}, {1, 1, z_wires}, {-15, 0, static_cast<int8_t>(-west_z)}}, IsTransparencySet(TransparencyOption::Catenary), &west);
1434 AddSortableSpriteToDraw(back, pal, *ti, {{0, 0, north_z}, {1, 1, z_wires}, {0, 0, static_cast<int8_t>(-north_z)}}, IsTransparencySet(TransparencyOption::Catenary), &north);
1435 AddSortableSpriteToDraw(back, pal, *ti, {{0, 15, east_z}, {1, 1, z_wires}, {0, -15, static_cast<int8_t>(-east_z)}}, IsTransparencySet(TransparencyOption::Catenary), &east);
1436 }
1437 if (front != 0) {
1438 /* Draw the "front" sprite (containing south pillar and wires) at a Z height that is both above the vehicles and above the "back" pillars. */
1439 AddSortableSpriteToDraw(front, pal, *ti, {{0, 0, static_cast<int8_t>(z_wires)}, {TILE_SIZE, TILE_SIZE, 1}, {0, 0, static_cast<int8_t>(-z_wires)}}, IsTransparencySet(TransparencyOption::Catenary));
1440 }
1441}
1442
1448{
1449 RoadBits road{};
1450 RoadBits tram{};
1451
1452 if (IsTileType(ti->tile, TileType::Road)) {
1453 if (IsNormalRoad(ti->tile)) {
1454 road = GetRoadBits(ti->tile, RoadTramType::Road);
1455 tram = GetRoadBits(ti->tile, RoadTramType::Tram);
1456 } else if (IsLevelCrossing(ti->tile)) {
1457 tram = road = GetCrossingRoadBits(ti->tile);
1458 }
1459 } else if (IsTileType(ti->tile, TileType::Station)) {
1460 if (IsAnyRoadStop(ti->tile)) {
1461 if (IsDriveThroughStopTile(ti->tile)) {
1462 Axis axis = GetDriveThroughStopAxis(ti->tile);
1463 tram = road = AxisToRoadBits(axis);
1464 } else {
1465 tram = road = DiagDirToRoadBits(GetBayRoadStopDir(ti->tile));
1466 }
1467 }
1468 } else {
1469 /* No road here, no catenary to draw */
1470 return;
1471 }
1472
1473 RoadType rt = GetRoadTypeRoad(ti->tile);
1474 if (rt != INVALID_ROADTYPE && HasRoadCatenaryDrawn(rt)) {
1475 DrawRoadTypeCatenary(ti, rt, road);
1476 }
1477
1478 rt = GetRoadTypeTram(ti->tile);
1479 if (rt != INVALID_ROADTYPE && HasRoadCatenaryDrawn(rt)) {
1480 DrawRoadTypeCatenary(ti, rt, tram);
1481 }
1482}
1483
1493static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int8_t dx, int8_t dy, uint8_t h, bool transparent)
1494{
1495 int x = ti->x | dx;
1496 int y = ti->y | dy;
1497 int z = ti->z;
1498 if (ti->tileh != SLOPE_FLAT) z = GetSlopePixelZ(x, y);
1499 AddSortableSpriteToDraw(img, PAL_NONE, ti->x, ti->y, z, {{dx, dy, 0}, {2, 2, h}, {}}, transparent);
1500}
1501
1512void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset, bool draw_underlay)
1513{
1514 if (draw_underlay) {
1515 /* Road underlay takes precedence over tram */
1516 if (road_rti != nullptr) {
1517 if (road_rti->UsesOverlay()) {
1519 DrawGroundSprite(ground + road_offset, pal);
1520 }
1521 } else {
1522 if (tram_rti->UsesOverlay()) {
1524 DrawGroundSprite(ground + tram_offset, pal);
1525 } else {
1526 DrawGroundSprite(SPR_TRAMWAY_TRAM + tram_offset, pal);
1527 }
1528 }
1529 }
1530
1531 /* Draw road overlay */
1532 if (road_rti != nullptr) {
1533 if (road_rti->UsesOverlay()) {
1535 if (ground != 0) DrawGroundSprite(ground + road_offset, pal);
1536 }
1537 }
1538
1539 /* Draw tram overlay */
1540 if (tram_rti != nullptr) {
1541 if (tram_rti->UsesOverlay()) {
1543 if (ground != 0) DrawGroundSprite(ground + tram_offset, pal);
1544 } else if (road_rti != nullptr) {
1545 DrawGroundSprite(SPR_TRAMWAY_OVERLAY + tram_offset, pal);
1546 }
1547 }
1548}
1549
1560static SpriteID GetRoadGroundSprite(const TileInfo *ti, Roadside roadside, const RoadTypeInfo *rti, uint offset, bool snow_or_desert, PaletteID *pal)
1561{
1562 /* Draw bare ground sprite if no road or road uses overlay system. */
1563 if (rti == nullptr || rti->UsesOverlay()) {
1564 if (DrawRoadAsSnowOrDesert(snow_or_desert, roadside)) {
1566 }
1567
1568 switch (roadside) {
1569 case Roadside::Barren:
1570 *pal = PALETTE_TO_BARE_LAND;
1572
1573 case Roadside::Grass:
1576
1577 default:
1578 break; // Paved
1579 }
1580 }
1581
1582 /* Draw original road base sprite */
1583 SpriteID image = SPR_ROAD_Y + offset;
1584 if (DrawRoadAsSnowOrDesert(snow_or_desert, roadside)) {
1585 image += NUM_SLOPES;
1586 } else {
1587 switch (roadside) {
1588 case Roadside::Barren:
1589 *pal = PALETTE_TO_BARE_LAND;
1590 break;
1591
1592 case Roadside::Grass:
1594 break;
1595
1596 default:
1597 image -= NUM_SLOPES;
1598 break; // Paved
1599 }
1600 }
1601
1602 return image;
1603}
1604
1615void DrawRoadGroundSprites(const TileInfo *ti, RoadBits road, RoadBits tram, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, Roadside roadside, bool snow_or_desert)
1616{
1617 /* Determine sprite offsets */
1618 uint road_offset = GetRoadSpriteOffset(ti->tileh, road);
1619 uint tram_offset = GetRoadSpriteOffset(ti->tileh, tram);
1620
1621 /* Draw baseset underlay */
1622 PaletteID pal = PAL_NONE;
1623 SpriteID image = GetRoadGroundSprite(ti, roadside, road_rti, road.None() ? tram_offset : road_offset, snow_or_desert, &pal);
1624 DrawGroundSprite(image, pal);
1625
1626 DrawRoadOverlays(ti, pal, road_rti, tram_rti, road_offset, tram_offset);
1627}
1628
1633static void DrawRoadBits(TileInfo *ti)
1634{
1637
1638 RoadType road_rt = GetRoadTypeRoad(ti->tile);
1639 RoadType tram_rt = GetRoadTypeTram(ti->tile);
1640 const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
1641 const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
1642
1643 if (ti->tileh != SLOPE_FLAT) {
1644 DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
1645 /* DrawFoundation() modifies ti. */
1646 }
1647
1648 DrawRoadGroundSprites(ti, road, tram, road_rti, tram_rti, GetRoadside(ti->tile), IsOnSnowOrDesert(ti->tile));
1649
1650 /* Draw one way */
1651 if (road_rti != nullptr) {
1653 if (drd.Any()) {
1655
1656 if (oneway == 0) oneway = SPR_ONEWAY_BASE;
1657
1658 if ((ti->tileh == SLOPE_NE) || (ti->tileh == SLOPE_NW)) {
1659 oneway += ONEWAY_SLOPE_N_OFFSET;
1660 } else if ((ti->tileh == SLOPE_SE) || (ti->tileh == SLOPE_SW)) {
1661 oneway += ONEWAY_SLOPE_S_OFFSET;
1662 }
1663
1664 DrawGroundSpriteAt(oneway + drd.base() - 1 + ((road == ROAD_X) ? 0 : 3), PAL_NONE, 8, 8, GetPartialPixelZ(8, 8, ti->tileh));
1665 }
1666 }
1667
1668 if (HasRoadWorks(ti->tile)) {
1669 /* Road works */
1670 DrawGroundSprite((road | tram).Any(ROAD_X) ? SPR_EXCAVATION_X : SPR_EXCAVATION_Y, PAL_NONE);
1671 return;
1672 }
1673
1674 /* Draw road, tram catenary */
1675 DrawRoadCatenary(ti);
1676
1677 /* Return if full detail is disabled, or we are zoomed fully out. */
1678 if (!_display_opt.Test(DisplayOption::FullDetail) || _cur_dpi->zoom > ZoomLevel::Detail) return;
1679
1680 /* Do not draw details (street lights, trees) under low bridge */
1681 Roadside roadside = GetRoadside(ti->tile);
1682 if (IsBridgeAbove(ti->tile) && (roadside == Roadside::Trees || roadside == Roadside::StreetLights)) {
1683 int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
1684 int minz = GetTileMaxZ(ti->tile) + 2;
1685
1686 if (roadside == Roadside::Trees) minz++;
1687
1688 if (height < minz) return;
1689 }
1690
1691 /* If there are no road bits, return, as there is nothing left to do */
1692 if (road.Count() <= 1) return;
1693
1694 /* Do not draw details when invisible. */
1697
1698 /* Check whether details should be transparent. */
1699 bool is_transparent = false;
1701 is_transparent = true;
1702 }
1704 is_transparent = true;
1705 }
1706
1707 /* Draw extra details. */
1708 for (const DrawRoadTileStruct *drts = _road_display_table[to_underlying(roadside)][(road | tram).base()]; drts->image != 0; drts++) {
1709 DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10, is_transparent);
1710 }
1711}
1712
1714static void DrawTile_Road(TileInfo *ti)
1715{
1716 BridgePillarFlags blocked_pillars{};
1717 switch (GetRoadTileType(ti->tile)) {
1719 DrawRoadBits(ti);
1720
1721 if (IsBridgeAbove(ti->tile)) {
1722 RoadBits bits = GetAllRoadBits(ti->tile);
1723 if (bits.Test(RoadBit::NE)) blocked_pillars.Set(BridgePillarFlag::EdgeNE);
1724 if (bits.Test(RoadBit::SE)) blocked_pillars.Set(BridgePillarFlag::EdgeSE);
1725 if (bits.Test(RoadBit::SW)) blocked_pillars.Set(BridgePillarFlag::EdgeSW);
1726 if (bits.Test(RoadBit::NW)) blocked_pillars.Set(BridgePillarFlag::EdgeNW);
1727 }
1728 break;
1729
1732
1733 Axis axis = GetCrossingRailAxis(ti->tile);
1734
1735 const RailTypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
1736
1737 RoadType road_rt = GetRoadTypeRoad(ti->tile);
1738 RoadType tram_rt = GetRoadTypeTram(ti->tile);
1739 const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
1740 const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
1741
1742 PaletteID pal = PAL_NONE;
1743
1744 /* Draw base ground */
1745 if (rti->UsesOverlay()) {
1746 SpriteID image = SPR_ROAD_Y + to_underlying(axis);
1747
1748 Roadside roadside = GetRoadside(ti->tile);
1749 if (DrawRoadAsSnowOrDesert(IsOnSnowOrDesert(ti->tile), roadside)) {
1750 image += NUM_SLOPES;
1751 } else {
1752 switch (roadside) {
1753 case Roadside::Barren:
1755 break;
1756
1757 case Roadside::Grass:
1758 break;
1759
1760 default:
1761 image -= NUM_SLOPES;
1762 break; // Paved
1763 }
1764 }
1765
1766 DrawGroundSprite(image, pal);
1767 } else {
1768 SpriteID image = rti->base_sprites.crossing + to_underlying(axis);
1769 if (IsCrossingBarred(ti->tile)) image += 2;
1770
1771 Roadside roadside = GetRoadside(ti->tile);
1772 if (DrawRoadAsSnowOrDesert(IsOnSnowOrDesert(ti->tile), roadside)) {
1773 image += 8;
1774 } else {
1775 switch (roadside) {
1776 case Roadside::Barren:
1778 break;
1779
1780 case Roadside::Grass:
1781 break;
1782
1783 default:
1784 image += 4;
1785 break; // Paved
1786 }
1787 }
1788
1789 DrawGroundSprite(image, pal);
1790 }
1791
1792 DrawRoadOverlays(ti, pal, road_rti, tram_rti, to_underlying(axis), to_underlying(axis));
1793
1794 /* Draw rail/PBS overlay */
1795 bool draw_pbs = _game_mode != GameMode::Menu && _settings_client.gui.show_track_reservation && HasCrossingReservation(ti->tile);
1796 if (rti->UsesOverlay()) {
1797 pal = draw_pbs ? PALETTE_CRASH : PAL_NONE;
1799 DrawGroundSprite(rail, pal);
1800
1801 Axis road_axis = GetCrossingRoadAxis(ti->tile);
1802 DiagDirections adjacent_diagdirs{};
1803 for (DiagDirection dir : AxisToDiagDirs(road_axis)) {
1804 const TileIndex t = TileAddByDiagDir(ti->tile, dir);
1805 if (t < Map::Size() && IsLevelCrossingTile(t) && GetCrossingRoadAxis(t) == road_axis) {
1806 adjacent_diagdirs.Set(dir);
1807 }
1808 }
1809
1810 switch (adjacent_diagdirs.base()) {
1811 case DiagDirections{}.base():
1812 DrawRailTileSeq(ti, &_crossing_layout, TransparencyOption::Catenary, rail, 0, PAL_NONE);
1813 break;
1814
1815 case DiagDirections{DiagDirection::NE}.base():
1816 DrawRailTileSeq(ti, &_crossing_layout_SW, TransparencyOption::Catenary, rail, 0, PAL_NONE);
1817 break;
1818
1819 case DiagDirections{DiagDirection::SE}.base():
1820 DrawRailTileSeq(ti, &_crossing_layout_NW, TransparencyOption::Catenary, rail, 0, PAL_NONE);
1821 break;
1822
1823 case DiagDirections{DiagDirection::SW}.base():
1824 DrawRailTileSeq(ti, &_crossing_layout_NE, TransparencyOption::Catenary, rail, 0, PAL_NONE);
1825 break;
1826
1827 case DiagDirections{DiagDirection::NW}.base():
1828 DrawRailTileSeq(ti, &_crossing_layout_SE, TransparencyOption::Catenary, rail, 0, PAL_NONE);
1829 break;
1830
1831 default:
1832 /* Show no sprites */
1833 break;
1834 }
1835 } else if (draw_pbs || tram_rti != nullptr || road_rti->UsesOverlay()) {
1836 /* Add another rail overlay, unless there is only the base road sprite. */
1837 pal = draw_pbs ? PALETTE_CRASH : PAL_NONE;
1839 DrawGroundSprite(rail, pal);
1840 }
1841
1842 /* Draw road, tram catenary */
1843 DrawRoadCatenary(ti);
1844
1845 /* Draw rail catenary */
1848 break;
1849 }
1850
1851 default:
1852 case RoadTileType::Depot: {
1854
1856
1857 RoadType road_rt = GetRoadTypeRoad(ti->tile);
1858 RoadType tram_rt = GetRoadTypeTram(ti->tile);
1859 const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt == INVALID_ROADTYPE ? tram_rt : road_rt);
1860
1861 int relocation = GetCustomRoadSprite(rti, ti->tile, RoadSpriteType::Depot);
1862 bool default_gfx = relocation == 0;
1863 if (default_gfx) {
1864 if (rti->flags.Test(RoadTypeFlag::Catenary)) {
1865 if (_loaded_newgrf_features.tram == TramDepotReplacement::WithTrack && road_rt == INVALID_ROADTYPE && !rti->UsesOverlay()) {
1866 /* Sprites with track only work for default tram */
1868 default_gfx = false;
1869 } else {
1870 /* Sprites without track are always better, if provided */
1872 }
1873 }
1874 } else {
1875 relocation -= SPR_ROAD_DEPOT;
1876 }
1877
1879 const DrawTileSprites *dts = &_road_depot[dir];
1880 DrawGroundSprite(dts->ground.sprite, PAL_NONE);
1881
1882 if (default_gfx) {
1884 if (rti->UsesOverlay()) {
1886 if (ground != 0) DrawGroundSprite(ground + offset, PAL_NONE);
1887 } else if (road_rt == INVALID_ROADTYPE) {
1888 DrawGroundSprite(SPR_TRAMWAY_OVERLAY + offset, PAL_NONE);
1889 }
1890 }
1891
1892 DrawRailTileSeq(ti, dts, TransparencyOption::Buildings, relocation, 0, palette);
1893 blocked_pillars = BRIDGEPILLARFLAGS_ALL;
1894 break;
1895 }
1896 }
1897 DrawBridgeMiddle(ti, blocked_pillars);
1898}
1899
1907void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
1908{
1910
1911 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1913 bool default_gfx = relocation == 0;
1914 if (default_gfx) {
1915 if (rti->flags.Test(RoadTypeFlag::Catenary)) {
1916 if (_loaded_newgrf_features.tram == TramDepotReplacement::WithTrack && RoadTypeIsTram(rt) && !rti->UsesOverlay()) {
1917 /* Sprites with track only work for default tram */
1919 default_gfx = false;
1920 } else {
1921 /* Sprites without track are always better, if provided */
1923 }
1924 }
1925 } else {
1926 relocation -= SPR_ROAD_DEPOT;
1927 }
1928
1929 const DrawTileSprites *dts = &_road_depot[dir];
1930 DrawSprite(dts->ground.sprite, PAL_NONE, x, y);
1931
1932 if (default_gfx) {
1934 if (rti->UsesOverlay()) {
1936 if (ground != 0) DrawSprite(ground + offset, PAL_NONE, x, y);
1937 } else if (RoadTypeIsTram(rt)) {
1938 DrawSprite(SPR_TRAMWAY_OVERLAY + offset, PAL_NONE, x, y);
1939 }
1940 }
1941
1942 DrawRailTileSeqInGUI(x, y, dts, relocation, 0, palette);
1943}
1944
1952{
1953 assert(!invalidate || _generating_world);
1954
1955 bool found = false;
1956
1957 for (const auto t : Map::Iterate()) {
1958 if (IsTileType(t, TileType::Road) && !IsRoadDepot(t) && !HasTownOwnedRoad(t)) {
1959 TownID tid = TownID::Invalid();
1960 if (!invalidate) {
1961 const Town *town = CalcClosestTownFromTile(t);
1962 if (town != nullptr) tid = town->index;
1963 }
1964 SetTownIndex(t, tid);
1965 found = true;
1966 }
1967 }
1968
1969 return found;
1970}
1971
1973static int GetSlopePixelZ_Road(TileIndex tile, uint x, uint y, [[maybe_unused]] bool ground_vehicle)
1974{
1975
1976 if (IsNormalRoad(tile)) {
1977 auto [tileh, z] = GetTilePixelSlope(tile);
1978 if (tileh == SLOPE_FLAT) return z;
1979
1981 z += ApplyPixelFoundationToSlope(f, tileh);
1982 return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
1983 } else {
1984 return GetTileMaxPixelZ(tile);
1985 }
1986}
1987
1990{
1991 if (IsNormalRoad(tile)) {
1992 return GetRoadFoundation(tileh, GetAllRoadBits(tile));
1993 } else {
1994 return FlatteningFoundation(tileh);
1995 }
1996}
1997
1998static const Roadside _town_road_types[][2] = {
2004};
2005
2006static_assert(lengthof(_town_road_types) == NUM_HOUSE_ZONES);
2007
2008static const Roadside _town_road_types_2[][2] = {
2014};
2015
2016static_assert(lengthof(_town_road_types_2) == NUM_HOUSE_ZONES);
2017
2018
2020static void TileLoop_Road(TileIndex tile)
2021{
2022 switch (_settings_game.game_creation.landscape) {
2023 case LandscapeType::Arctic: {
2024 /* Roads use the snow level of their maximum height minus one, unless flat. */
2025 int tile_z = (std::get<Slope>(GetFoundationSlope(tile)) == SLOPE_FLAT) ? GetTileMaxZ(tile) : GetTileMaxZ(tile) - 1;
2026 if (IsOnSnowOrDesert(tile) != (tile_z > GetSnowLine())) {
2027 ToggleSnowOrDesert(tile);
2028 MarkTileDirtyByTile(tile);
2029 }
2030 break;
2031 }
2032
2034 if (GetTropicZone(tile) == TropicZone::Desert && !IsOnSnowOrDesert(tile)) {
2035 ToggleSnowOrDesert(tile);
2036 MarkTileDirtyByTile(tile);
2037 }
2038 break;
2039
2040 default:
2041 break;
2042 }
2043
2044 if (IsRoadDepot(tile)) return;
2045
2046 const Town *t = ClosestTownFromTile(tile, UINT_MAX);
2047 if (!HasRoadWorks(tile)) {
2049
2050 if (t != nullptr) {
2051 grp = GetTownRadiusGroup(t, tile);
2052
2053 /* Show an animation to indicate road work */
2054 if (t->road_build_months != 0 &&
2055 (DistanceManhattan(t->xy, tile) < 8 || grp != HouseZone::TownEdge) &&
2056 IsNormalRoad(tile) && GetAllRoadBits(tile).Count() > 1) {
2057 if (std::get<Slope>(GetFoundationSlope(tile)) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile).Succeeded() && Chance16(1, 40)) {
2058 StartRoadWorks(tile);
2059
2060 if (_settings_client.sound.ambient) SndPlayTileFx(SND_21_ROAD_WORKS, tile);
2062 TileX(tile) * TILE_SIZE + 7,
2063 TileY(tile) * TILE_SIZE + 7,
2064 0,
2065 EV_BULLDOZER);
2066 MarkTileDirtyByTile(tile);
2067 return;
2068 }
2069 }
2070 }
2071
2072 {
2073 /* Adjust road ground type depending on 'grp' (grp is the distance to the center) */
2074 const Roadside *new_rs = (_settings_game.game_creation.landscape == LandscapeType::Toyland) ? _town_road_types_2[to_underlying(grp)] : _town_road_types[to_underlying(grp)];
2075 Roadside cur_rs = GetRoadside(tile);
2076
2077 /* We have our desired type, do nothing */
2078 if (cur_rs == new_rs[0]) return;
2079
2080 /* We have the pre-type of the desired type, switch to the desired type */
2081 if (cur_rs == new_rs[1]) {
2082 cur_rs = new_rs[0];
2083 /* We have barren land, install the pre-type */
2084 } else if (cur_rs == Roadside::Barren) {
2085 cur_rs = new_rs[1];
2086 /* We're totally off limits, remove any installation and make barren land */
2087 } else {
2088 cur_rs = Roadside::Barren;
2089 }
2090 SetRoadside(tile, cur_rs);
2091 MarkTileDirtyByTile(tile);
2092 }
2093 } else if (IncreaseRoadWorksCounter(tile)) {
2094 TerminateRoadWorks(tile);
2095
2096 if (_settings_game.economy.mod_road_rebuild) {
2097 /* Generate a nicer town surface */
2099 RoadBits new_rb = CleanUpRoadBits(tile, old_rb);
2100
2101 if (old_rb != new_rb) {
2103
2104 /* If new_rb is 0, there are now no road pieces left and the tile is no longer a road tile */
2105 if (new_rb.None()) {
2106 MarkTileDirtyByTile(tile);
2107 return;
2108 }
2109 }
2110 }
2111
2112 /* Possibly change road type */
2115 if (rt != GetRoadTypeRoad(tile)) {
2117 }
2118 }
2119
2120 MarkTileDirtyByTile(tile);
2121 }
2122}
2123
2125static bool ClickTile_Road(TileIndex tile)
2126{
2127 if (!IsRoadDepot(tile)) return false;
2128
2130 return true;
2131}
2132
2134static const TrackBits _road_trackbits[16] = {
2135 {}, // ROAD_NONE
2136 {}, // RoadBit::NW
2137 {}, // RoadBit::SW
2138 Track::Left, // ROAD_W
2139 {}, // RoadBit::SE
2140 Track::Y, // ROAD_Y
2141 Track::Lower, // ROAD_S
2142 {Track::Left, Track::Lower, Track::Y}, // ROAD_Y | RoadBit::SW
2143 {}, // RoadBit::NE
2144 Track::Upper, // ROAD_N
2145 Track::X, // ROAD_X
2146 {Track::Left, Track::Upper, Track::X}, // ROAD_X | RoadBit::NW
2147 Track::Right, // ROAD_E
2148 {Track::Right, Track::Upper, Track::Y}, // ROAD_Y | RoadBit::NE
2149 {Track::Right, Track::Lower, Track::X}, // ROAD_X | RoadBit::SE
2150 TRACK_BIT_ALL, // ROAD_ALL
2151};
2152
2155{
2156 TrackdirBits trackdirbits{};
2157 TrackdirBits red_signals{}; // crossing barred
2158 switch (mode) {
2160 if (IsLevelCrossing(tile)) trackdirbits = TrackBitsToTrackdirBits(GetCrossingRailTrack(tile));
2161 break;
2162
2163 case TransportType::Road: {
2164 RoadTramType rtt = (RoadTramType)sub_mode;
2165 if (!HasTileRoadType(tile, rtt)) break;
2166 switch (GetRoadTileType(tile)) {
2167 case RoadTileType::Normal: {
2168 const uint drd_to_multiplier[] = { 0x101, 0x100, 0x1, 0x0 };
2169 RoadBits bits = GetRoadBits(tile, rtt);
2170
2171 /* no roadbit at this side of tile, return 0 */
2172 if (side != DiagDirection::Invalid && !DiagDirToRoadBits(side).Any(bits)) break;
2173
2174 uint multiplier = drd_to_multiplier[(rtt == RoadTramType::Tram) ? 0 : GetDisallowedRoadDirections(tile).base()];
2175 if (!HasRoadWorks(tile)) trackdirbits = static_cast<TrackdirBits>(_road_trackbits[bits.base()].base() * multiplier);
2176 break;
2177 }
2178
2180 Axis axis = GetCrossingRoadAxis(tile);
2181
2182 if (side != DiagDirection::Invalid && axis != DiagDirToAxis(side)) break;
2183
2184 trackdirbits = TrackBitsToTrackdirBits(AxisToTrack(axis));
2185 if (IsCrossingBarred(tile)) {
2186 red_signals = trackdirbits;
2187 if (TrainOnCrossing(tile)) break;
2188
2189 auto mask_red_signal_bits_if_crossing_barred = [&](TileIndex t, TrackdirBits mask) {
2190 if (IsLevelCrossingTile(t) && IsCrossingBarred(t)) red_signals &= mask;
2191 };
2192 /* Check for blocked adjacent crossing to south, keep only southbound red signal trackdirs, allow northbound traffic */
2193 mask_red_signal_bits_if_crossing_barred(TileAddByDiagDir(tile, AxisToDiagDir(axis)), {Trackdir::X_SW, Trackdir::Y_SE});
2194 /* Check for blocked adjacent crossing to north, keep only northbound red signal trackdirs, allow southbound traffic */
2195 mask_red_signal_bits_if_crossing_barred(TileAddByDiagDir(tile, ReverseDiagDir(AxisToDiagDir(axis))), {Trackdir::X_NE, Trackdir::Y_NW});
2196 }
2197 break;
2198 }
2199
2200 default:
2201 case RoadTileType::Depot: {
2203
2204 if (side != DiagDirection::Invalid && side != dir) break;
2205
2206 trackdirbits = TrackBitsToTrackdirBits(DiagDirToDiagTrack(dir));
2207 break;
2208 }
2209 }
2210 break;
2211 }
2212
2213 default: break;
2214 }
2215 return {trackdirbits, red_signals};
2216}
2217
2218static const StringID _road_tile_strings[] = {
2219 STR_LAI_ROAD_DESCRIPTION_ROAD,
2220 STR_LAI_ROAD_DESCRIPTION_ROAD,
2221 STR_LAI_ROAD_DESCRIPTION_ROAD,
2222 STR_LAI_ROAD_DESCRIPTION_ROAD_WITH_STREETLIGHTS,
2223 STR_LAI_ROAD_DESCRIPTION_ROAD,
2224 STR_LAI_ROAD_DESCRIPTION_TREE_LINED_ROAD,
2225 STR_LAI_ROAD_DESCRIPTION_ROAD,
2226 STR_LAI_ROAD_DESCRIPTION_ROAD,
2227};
2228
2231{
2232 Owner rail_owner = INVALID_OWNER;
2233 Owner road_owner = INVALID_OWNER;
2234 Owner tram_owner = INVALID_OWNER;
2235
2236 RoadType road_rt = GetRoadTypeRoad(tile);
2237 RoadType tram_rt = GetRoadTypeTram(tile);
2238 if (road_rt != INVALID_ROADTYPE) {
2239 const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
2240 td.roadtype = rti->strings.name;
2241 td.road_speed = rti->max_speed / 2;
2242 road_owner = GetRoadOwner(tile, RoadTramType::Road);
2243 }
2244 if (tram_rt != INVALID_ROADTYPE) {
2245 const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
2246 td.tramtype = rti->strings.name;
2247 td.tram_speed = rti->max_speed / 2;
2248 tram_owner = GetRoadOwner(tile, RoadTramType::Tram);
2249 }
2250
2251 switch (GetRoadTileType(tile)) {
2253 td.str = STR_LAI_ROAD_DESCRIPTION_ROAD_RAIL_LEVEL_CROSSING;
2254 rail_owner = GetTileOwner(tile);
2255
2256 const RailTypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
2257 td.railtype = rti->strings.name;
2258 td.rail_speed = rti->max_speed;
2259
2260 break;
2261 }
2262
2264 td.str = STR_LAI_ROAD_DESCRIPTION_ROAD_VEHICLE_DEPOT;
2265 td.build_date = Depot::GetByTile(tile)->build_date;
2266 break;
2267
2268 default: {
2269 td.str = (road_rt != INVALID_ROADTYPE ? _road_tile_strings[to_underlying(GetRoadside(tile))] : STR_LAI_ROAD_DESCRIPTION_TRAMWAY);
2270 break;
2271 }
2272 }
2273
2274 /* Now we have to discover, if the tile has only one owner or many:
2275 * - Find a first_owner of the tile. (Currently road or tram must be present, but this will break when the third type becomes available)
2276 * - Compare the found owner with the other owners, and test if they differ.
2277 * Note: If road exists it will be the first_owner.
2278 */
2279 Owner first_owner = (road_owner == INVALID_OWNER ? tram_owner : road_owner);
2280 bool mixed_owners = (tram_owner != INVALID_OWNER && tram_owner != first_owner) || (rail_owner != INVALID_OWNER && rail_owner != first_owner);
2281
2282 if (mixed_owners) {
2283 /* Multiple owners */
2284 td.owner_type[0] = (rail_owner == INVALID_OWNER ? STR_NULL : STR_LAND_AREA_INFORMATION_RAIL_OWNER);
2285 td.owner[0] = rail_owner;
2286 td.owner_type[1] = (road_owner == INVALID_OWNER ? STR_NULL : STR_LAND_AREA_INFORMATION_ROAD_OWNER);
2287 td.owner[1] = road_owner;
2288 td.owner_type[2] = (tram_owner == INVALID_OWNER ? STR_NULL : STR_LAND_AREA_INFORMATION_TRAM_OWNER);
2289 td.owner[2] = tram_owner;
2290 } else {
2291 /* One to rule them all */
2292 td.owner[0] = first_owner;
2293 }
2294}
2295
2303
2305static VehicleEnterTileStates VehicleEnterTile_Road(Vehicle *v, TileIndex tile, [[maybe_unused]] int x, [[maybe_unused]] int y)
2306{
2307 switch (GetRoadTileType(tile)) {
2308 case RoadTileType::Depot: {
2309 if (v->type != VehicleType::Road) break;
2310
2312 if (rv->frame == RVC_DEPOT_STOP_FRAME &&
2313 _roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == static_cast<Trackdir>(rv->state)) {
2314 rv->state = RVSB_IN_DEPOT;
2316 rv->direction = ReverseDir(rv->direction);
2317 if (rv->Next() == nullptr) VehicleEnterDepot(rv->First());
2318 rv->tile = tile;
2319
2320 InvalidateWindowData(WindowClass::VehicleDepot, rv->tile);
2322 }
2323 break;
2324 }
2325
2326 default: break;
2327 }
2328 return {};
2329}
2330
2331
2333static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owner)
2334{
2335 if (IsRoadDepot(tile)) {
2336 if (GetTileOwner(tile) == old_owner) {
2337 if (new_owner == INVALID_OWNER) {
2338 Command<Commands::LandscapeClear>::Do({DoCommandFlag::Execute, DoCommandFlag::Bankrupt}, tile);
2339 } else {
2340 /* A road depot has two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
2341 RoadType rt = GetRoadTypeRoad(tile);
2342 if (rt == INVALID_ROADTYPE) rt = GetRoadTypeTram(tile);
2343 Company::Get(old_owner)->infrastructure.road[rt] -= 2;
2344 Company::Get(new_owner)->infrastructure.road[rt] += 2;
2345
2346 SetTileOwner(tile, new_owner);
2347 for (RoadTramType rtt : ROADTRAMTYPES_ALL) {
2348 if (GetRoadOwner(tile, rtt) == old_owner) {
2349 SetRoadOwner(tile, rtt, new_owner);
2350 }
2351 }
2352 }
2353 }
2354 return;
2355 }
2356
2357 for (RoadTramType rtt : ROADTRAMTYPES_ALL) {
2358 /* Update all roadtypes, no matter if they are present */
2359 if (GetRoadOwner(tile, rtt) == old_owner) {
2360 RoadType rt = GetRoadType(tile, rtt);
2361 if (rt != INVALID_ROADTYPE) {
2362 /* A level crossing has two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
2363 uint num_bits = IsLevelCrossing(tile) ? 2 : GetRoadBits(tile, rtt).Count();
2364 Company::Get(old_owner)->infrastructure.road[rt] -= num_bits;
2365 if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += num_bits;
2366 }
2367
2368 SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
2369 }
2370 }
2371
2372 if (IsLevelCrossing(tile)) {
2373 if (GetTileOwner(tile) == old_owner) {
2374 if (new_owner == INVALID_OWNER) {
2375 Command<Commands::RemoveRail>::Do({DoCommandFlag::Execute, DoCommandFlag::Bankrupt}, tile, GetCrossingRailTrack(tile));
2376 } else {
2377 /* Update infrastructure counts. No need to dirty windows here, we'll redraw the whole screen anyway. */
2378 Company::Get(old_owner)->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR;
2379 Company::Get(new_owner)->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
2380
2381 SetTileOwner(tile, new_owner);
2382 }
2383 }
2384 }
2385}
2386
2388static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
2389{
2390 if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
2391 switch (GetRoadTileType(tile)) {
2393 if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(ExpensesType::Construction, _price[Price::BuildFoundation]);
2394 break;
2395
2398 break;
2399
2400 case RoadTileType::Normal: {
2401 RoadBits bits = GetAllRoadBits(tile);
2402 RoadBits bits_copy = bits;
2403 /* Check if the slope-road_bits combination is valid at all, i.e. it is safe to call GetRoadFoundation(). */
2404 if (CheckRoadSlope(tileh_new, &bits_copy, {}, {}).Succeeded()) {
2405 /* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */
2406 if (bits == bits_copy) {
2407 auto [tileh_old, z_old] = GetTileSlopeZ(tile);
2408
2409 /* Get the slope on top of the foundation */
2410 z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), tileh_old);
2411 z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), tileh_new);
2412
2413 /* The surface slope must not be changed */
2414 if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(ExpensesType::Construction, _price[Price::BuildFoundation]);
2415 }
2416 }
2417 break;
2418 }
2419
2420 default: NOT_REACHED();
2421 }
2422 }
2423
2424 return Command<Commands::LandscapeClear>::Do(flags, tile);
2425}
2426
2433static bool CanConvertUnownedRoadType(Owner owner, RoadTramType rtt)
2434{
2435 return (owner == OWNER_NONE || (owner == OWNER_TOWN && rtt == RoadTramType::Road));
2436}
2437
2446static void ConvertRoadTypeOwner(TileIndex tile, uint num_pieces, Owner owner, RoadType from_type, RoadType to_type)
2447{
2448 /* Scenario editor, maybe? Don't touch the owners when converting roadtypes... */
2449 if (_current_company >= MAX_COMPANIES) return;
2450
2451 /* We can't get a company from invalid owners but we can get ownership of roads without an owner */
2452 if (owner >= MAX_COMPANIES && owner != OWNER_NONE) return;
2453
2454 Company *c;
2455
2456 switch (owner.base()) {
2457 case OWNER_NONE.base():
2458 SetRoadOwner(tile, GetRoadTramType(to_type), (Owner)_current_company);
2460 break;
2461
2462 default:
2463 c = Company::Get(owner);
2464 c->infrastructure.road[from_type] -= num_pieces;
2465 c->infrastructure.road[to_type] += num_pieces;
2467 break;
2468 }
2469}
2470
2482CommandCost CmdConvertRoad(DoCommandFlags flags, TileIndex tile, TileIndex area_start, RoadType to_type, bool diagonal)
2483{
2484 TileIndex area_end = tile;
2485
2486 if (!ValParamRoadType(to_type)) return CMD_ERROR;
2487 if (area_start >= Map::Size()) return CMD_ERROR;
2488
2489 RoadVehicleList affected_rvs;
2490 RoadTramType rtt = GetRoadTramType(to_type);
2491
2493 CommandCost error = CommandCost((rtt == RoadTramType::Tram) ? STR_ERROR_NO_SUITABLE_TRAMWAY : STR_ERROR_NO_SUITABLE_ROAD); // by default, there is no road to convert.
2494 bool found_convertible_road = false; // whether we actually did convert any road/tram (see bug #7633)
2495
2496 auto tilearea = CreateOrthoDiagonalArea(area_end, area_start, diagonal);
2497 for (TileIndex cur_tile : tilearea) {
2498 /* Is road present on tile? */
2499 if (!MayHaveRoad(cur_tile)) continue;
2500
2501 /* Converting to the same subtype? */
2502 RoadType from_type = GetRoadType(cur_tile, rtt);
2503 if (from_type == INVALID_ROADTYPE || from_type == to_type) continue;
2504
2505 /* Check if there is any infrastructure on tile */
2506 TileType tt = GetTileType(cur_tile);
2507 switch (tt) {
2508 case TileType::Station:
2509 if (!IsAnyRoadStop(cur_tile)) continue;
2510 break;
2511 case TileType::Road:
2512 if (IsLevelCrossing(cur_tile) && RoadNoLevelCrossing(to_type)) {
2513 error.MakeError(STR_ERROR_CROSSING_DISALLOWED_ROAD);
2514 continue;
2515 }
2516 break;
2518 if (GetTunnelBridgeTransportType(cur_tile) != TransportType::Road) continue;
2519 break;
2520 default: continue;
2521 }
2522
2523 /* Trying to convert other's road */
2524 Owner owner = GetRoadOwner(cur_tile, rtt);
2525 if (!CanConvertUnownedRoadType(owner, rtt)) {
2526 CommandCost ret = CheckOwnership(owner, cur_tile);
2527 if (ret.Failed()) {
2528 error = std::move(ret);
2529 continue;
2530 }
2531 }
2532
2533 /* Base the ability to replace town roads and bridges on the town's
2534 * acceptance of destructive actions. */
2535 if (owner == OWNER_TOWN) {
2536 Town *t = ClosestTownFromTile(cur_tile, _settings_game.economy.dist_local_authority);
2538 if (ret.Failed()) {
2539 error = std::move(ret);
2540 continue;
2541 }
2542 }
2543
2544 /* Vehicle on the tile when not converting normal <-> powered
2545 * Tunnels and bridges have special check later */
2546 if (tt != TileType::TunnelBridge) {
2547 if (!HasPowerOnRoad(from_type, to_type)) {
2548 CommandCost ret = EnsureNoVehicleOnGround(cur_tile);
2549 if (ret.Failed()) {
2550 error = std::move(ret);
2551 continue;
2552 }
2553
2554 if (rtt == RoadTramType::Road && owner == OWNER_TOWN) {
2555 error.MakeError(STR_ERROR_OWNED_BY);
2556 if (IsLocalCompany()) {
2557 auto params = GetParamsForOwnedBy(OWNER_TOWN, cur_tile);
2558 error.SetEncodedMessage(GetEncodedStringWithArgs(STR_ERROR_OWNED_BY, params));
2559 }
2560 continue;
2561 }
2562 }
2563
2564 uint num_pieces = GetAnyRoadBits(cur_tile, rtt).Count();
2565 if (tt == TileType::Station && IsBayRoadStopTile(cur_tile)) {
2566 num_pieces *= ROAD_STOP_TRACKBIT_FACTOR;
2567 } else if (tt == TileType::Road && IsRoadDepot(cur_tile)) {
2568 num_pieces *= ROAD_DEPOT_TRACKBIT_FACTOR;
2569 }
2570
2571 found_convertible_road = true;
2572 cost.AddCost(num_pieces * RoadConvertCost(from_type, to_type));
2573
2574 if (flags.Test(DoCommandFlag::Execute)) { // we can safely convert, too
2575 /* Call ConvertRoadTypeOwner() to update the company infrastructure counters. */
2576 if (owner == _current_company) {
2577 ConvertRoadTypeOwner(cur_tile, num_pieces, owner, from_type, to_type);
2578 }
2579
2580 /* Perform the conversion */
2581 SetRoadType(cur_tile, rtt, to_type);
2582 MarkTileDirtyByTile(cur_tile);
2583
2584 /* update power of train on this tile */
2585 for (Vehicle *v : VehiclesOnTile(cur_tile)) {
2586 if (v->type == VehicleType::Road) include(affected_rvs, RoadVehicle::From(v)->First());
2587 }
2588
2589 if (IsRoadDepotTile(cur_tile)) {
2590 /* Update build vehicle window related to this depot */
2591 InvalidateWindowData(WindowClass::VehicleDepot, cur_tile);
2592 InvalidateWindowData(WindowClass::BuildVehicle, cur_tile);
2593 }
2594 }
2595 } else {
2596 TileIndex endtile = GetOtherTunnelBridgeEnd(cur_tile);
2597
2598 /* If both ends of tunnel/bridge are in the range, do not try to convert twice -
2599 * it would cause assert because of different test and exec runs */
2600 if (endtile < cur_tile) {
2601 if (tilearea.Contains(endtile)) continue;
2602 }
2603
2604 /* When not converting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
2605 if (!HasPowerOnRoad(from_type, to_type)) {
2606 CommandCost ret = TunnelBridgeIsFree(cur_tile, endtile);
2607 if (ret.Failed()) {
2608 error = std::move(ret);
2609 continue;
2610 }
2611
2612 if (rtt == RoadTramType::Road && owner == OWNER_TOWN) {
2613 error.MakeError(STR_ERROR_OWNED_BY);
2614 if (IsLocalCompany()) {
2615 auto params = GetParamsForOwnedBy(OWNER_TOWN, cur_tile);
2616 error.SetEncodedMessage(GetEncodedStringWithArgs(STR_ERROR_OWNED_BY, params));
2617 }
2618 continue;
2619 }
2620 }
2621
2622 /* There are 2 pieces on *every* tile of the bridge or tunnel */
2623 uint num_pieces = (GetTunnelBridgeLength(cur_tile, endtile) + 2) * 2;
2624 found_convertible_road = true;
2625 cost.AddCost(num_pieces * RoadConvertCost(from_type, to_type));
2626
2627 if (flags.Test(DoCommandFlag::Execute)) {
2628 /* Update the company infrastructure counters. */
2629 if (owner == _current_company) {
2630 /* Each piece should be counted TUNNELBRIDGE_TRACKBIT_FACTOR times
2631 * for the infrastructure counters (cause of #8297). */
2632 ConvertRoadTypeOwner(cur_tile, num_pieces * TUNNELBRIDGE_TRACKBIT_FACTOR, owner, from_type, to_type);
2633 SetTunnelBridgeOwner(cur_tile, endtile, _current_company);
2634 }
2635
2636 /* Perform the conversion */
2637 SetRoadType(cur_tile, rtt, to_type);
2638 SetRoadType(endtile, rtt, to_type);
2639
2640 for (Vehicle *v : VehiclesOnTile(cur_tile)) {
2641 if (v->type == VehicleType::Road) include(affected_rvs, RoadVehicle::From(v)->First());
2642 }
2643 for (Vehicle *v : VehiclesOnTile(endtile)) {
2644 if (v->type == VehicleType::Road) include(affected_rvs, RoadVehicle::From(v)->First());
2645 }
2646
2647 if (IsBridge(cur_tile)) {
2648 MarkBridgeDirty(cur_tile);
2649 } else {
2650 MarkTileDirtyByTile(cur_tile);
2651 MarkTileDirtyByTile(endtile);
2652 }
2653 }
2654 }
2655 }
2656
2657 if (flags.Test(DoCommandFlag::Execute)) {
2658 /* Roadtype changed, update roadvehicles as when entering different track */
2659 for (RoadVehicle *v : affected_rvs) {
2660 v->CargoChanged();
2661 }
2662 }
2663
2664 return found_convertible_road ? cost : error;
2665}
2666
2668static CommandCost CheckBuildAbove_Road(TileIndex tile, [[maybe_unused]] DoCommandFlags flags, [[maybe_unused]] Axis axis, int height)
2669{
2670 if (!IsRoadDepot(tile)) return CommandCost();
2671
2672 int height_diff = GetTileMaxZ(tile) + MINIMAL_DEPOT_BRIDGE_HEIGHT - height;
2673 if (height_diff <= 0) return CommandCost();
2674 return CommandCostWithParam(STR_ERROR_BRIDGE_TOO_LOW_FOR_ROADVEH_DEPOT, height_diff * TILE_HEIGHT_STEP);
2675}
2676
2678extern const TileTypeProcs _tile_type_road_procs = {
2679 .draw_tile_proc = DrawTile_Road,
2680 .get_slope_pixel_z_proc = GetSlopePixelZ_Road,
2681 .clear_tile_proc = ClearTile_Road,
2682 .get_tile_desc_proc = GetTileDesc_Road,
2683 .get_tile_track_status_proc = GetTileTrackStatus_Road,
2684 .click_tile_proc = ClickTile_Road,
2685 .tile_loop_proc = TileLoop_Road,
2686 .change_tile_owner_proc = ChangeTileOwner_Road,
2687 .vehicle_enter_tile_proc = VehicleEnterTile_Road,
2688 .get_foundation_proc = GetFoundation_Road,
2689 .terraform_tile_proc = TerraformTile_Road,
2690 .check_build_above_proc = CheckBuildAbove_Road,
2691};
@ None
Tile is not animated.
Functions related to autoslope.
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
bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Definition autoslope.h:65
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Header file for bridges.
void DrawBridgeMiddle(const TileInfo *ti, BridgePillarFlags blocked_pillars)
Draw the middle bits of a bridge.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition bridge_map.h:45
bool IsBridge(Tile t)
Checks if this is a bridge, instead of a tunnel.
Definition bridge_map.h:24
EnumBitSet< BridgePillarFlag, uint8_t > BridgePillarFlags
Bitset of BridgePillarFlag elements.
Definition bridge_type.h:53
@ EdgeNE
Northeast edge is obstructed.
Definition bridge_type.h:46
@ EdgeSW
Southwest edge is obstructed.
Definition bridge_type.h:48
@ EdgeNW
Northwest edge is obstructed.
Definition bridge_type.h:49
@ EdgeSE
Southeast edge is obstructed.
Definition bridge_type.h:47
Cheats _cheats
All the cheats.
Definition cheat.cpp:16
Types related to cheating.
uint Count() const
Count the number of set bits.
constexpr bool All(const Timpl &other) const
Test if all of the values are set.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr bool None() const
Test if none of the values are set.
constexpr Timpl & Flip()
Flip all bits.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
void MakeError(StringID message)
Makes this CommandCost behave like an error command.
Money GetCost() const
The costs as made up to this moment.
void SetEncodedMessage(EncodedString &&message)
Set the encoded message string.
bool Failed() const
Did this command fail?
StringID GetErrorMessage() const
Returns the error message of a command.
Iterate a range of enum values.
This struct contains all the info that is needed to draw and construct tracks.
Definition rail.h:134
SpriteID single_x
single piece of rail in X direction, without ground
Definition rail.h:144
uint16_t max_speed
Maximum speed for vehicles travelling on this rail type.
Definition rail.h:239
struct RailTypeInfo::@157247141350136173143103254227157213063052244122 strings
Strings associated with the rail type.
SpriteID crossing
level crossing, rail in X direction
Definition rail.h:151
SpriteID single_y
single piece of rail in Y direction, without ground
Definition rail.h:145
StringID name
Name of this rail type.
Definition rail.h:184
struct RailTypeInfo::@332027037331076264023214171276243307073252216167 base_sprites
Struct containing the main sprites.
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition road.h:123
struct RoadTypeInfo::@040007041145073342004320043002073006000034160103 gui_sprites
struct containing the sprites for the road GUI.
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition road.h:98
struct RoadTypeInfo::@262365004142063215107272155332373126354130071373 cursor
Cursors associated with the road type.
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition road.h:153
RoadType Index() const
Get the RoadType for this RoadTypeInfo.
Definition road.cpp:29
CursorID autoroad
Cursor for autorail tool.
Definition road.h:72
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:142
uint8_t sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Definition road.h:158
RoadTypeFlags flags
Bit mask of road type flags.
Definition road.h:103
FlatSet< RoadTypeLabel > alternate_labels
Road type labels this type provides in addition to the main label.
Definition road.h:128
CursorID depot
Cursor for building a depot.
Definition road.h:73
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:71
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:118
struct RoadTypeInfo::@070000167274302256150317022075324310363002361255 strings
Strings associated with the rail type.
StringID name
Name of this rail type.
Definition road.h:79
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:62
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:74
SpriteID auto_road
button for the autoroad construction
Definition road.h:63
SpriteID convert_road
button for converting road types
Definition road.h:66
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:70
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:61
SpriteID build_depot
button for building depots
Definition road.h:64
SpriteID build_tunnel
button for building a tunnel
Definition road.h:65
static constexpr TimerGame< struct Calendar >::Date INVALID_DATE
Iterate over all vehicles on a tile.
CommandCost CommandCostWithParam(StringID str, uint64_t value)
Return an error status, with string and parameter.
Definition command.cpp:415
Functions related to commands.
CommandCost & ExtractCommandCost(Tret &ret)
Extract the CommandCost from a command proc result.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Auto
don't allow building on structures
@ NoWater
don't allow building on water
@ Execute
execute the given command
@ Bankrupt
company bankrupts, skip money check, skip vehicle on tile check in some cases
EnumBitSet< DoCommandFlag, uint16_t > DoCommandFlags
Bitset of DoCommandFlag elements.
Definition of stuff that is very close to a company, like the company struct itself.
std::array< StringParameter, 2 > GetParamsForOwnedBy(Owner owner, TileIndex tile)
Get the right StringParameters for STR_ERROR_OWNED_BY.
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
Money GetAvailableMoneyForCommand()
This functions returns the money which can be used to execute a command.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
bool IsLocalCompany()
Is the current company the local company?
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
GUI Functions related to companies.
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
static constexpr Owner OWNER_TOWN
A town owns the tile, or a town is expanding.
static constexpr Owner OWNER_NONE
The tile has no ownership.
static constexpr Owner INVALID_OWNER
An invalid owner.
static constexpr Owner OWNER_WATER
The tile/execution is done by "water".
Some simple functions to help with accessing containers.
bool include(Container &container, typename Container::const_reference &item)
Helper function to append an item to a container if it is not already contained.
Base for all depots (except hangars).
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:27
void ShowDepotWindow(TileIndex tile, VehicleType type)
Opens a depot window.
static constexpr uint8_t MINIMAL_DEPOT_BRIDGE_HEIGHT
Minimal height for a bridge above any depot tile.
Definition depot_type.h:21
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DiagDirections AxisToDiagDirs(Axis a)
Converts an Axis to DiagDirections.
Direction ReverseDir(Direction d)
Return the reverse of a direction.
bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Axis OtherAxis(Axis a)
Select the other axis as provided.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
EnumIndexArray< T, DiagDirection, DiagDirection::End > DiagDirectionIndexArray
Array with DiagDirection as index.
Axis
Enumeration for the two axis X and Y.
@ X
The X axis.
@ Y
The y axis.
DiagDirection
Enumeration for diagonal directions.
@ Invalid
Flag for an invalid DiagDirection.
@ SW
Southwest.
@ NW
Northwest.
@ End
Used for iterations.
@ NE
Northeast, upper right on your monitor.
@ SE
Southeast.
EnumBitSet< DiagDirection, uint8_t > DiagDirections
Bitset of DiagDirection elements.
Prices _price
Prices and also the fractional part.
Definition economy.cpp:109
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
static const uint ROAD_STOP_TRACKBIT_FACTOR
Multiplier for how many regular track bits a bay stop counts.
static const uint ROAD_DEPOT_TRACKBIT_FACTOR
Multiplier for how many regular track bits a road depot counts.
@ Construction
Construction costs.
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
@ ClearDepotRoad
Price for destroying road vehicle depots.
@ BuildFoundation
Price for building foundation under other constructions e.g. roads, rails, depots,...
@ BuildDepotRoad
Price for building road vehicle depots.
EffectVehicle * CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular location.
Base class for all effect vehicles.
Functions related to effect vehicles.
@ EV_BULLDOZER
Bulldozer at roadworks.
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
Definition elrail.cpp:554
Header file for electrified rail specific functions.
bool HasRailCatenaryDrawn(RailType rt)
Test if we should draw rail catenary.
Definition elrail_func.h:32
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
bool _generating_world
Whether we are generating the map or not.
Definition genworld.cpp:70
Functions related to world/map generation.
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:1032
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
@ Grey
Grey.
Definition gfx_type.h:299
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
HouseZone
Concentric rings of zoning around the centre of a town.
Definition house.h:59
@ TownEdge
Edge of the town; roads without pavement.
Definition house.h:60
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
std::tuple< Slope, int > GetFoundationSlope(TileIndex tile)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
const TileTypeProcs _tile_type_road_procs
TileTypeProcs definitions for TileType::Road tiles.
Definition landscape.cpp:56
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
uint ApplyPixelFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
Definition landscape.h:128
int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
Definition landscape.h:55
Command definitions related to landscape (slopes etc.).
@ Arctic
Landscape with snow levels.
@ Toyland
Landscape with funky industries and vehicles.
@ Tropic
Landscape with distinct rainforests and deserts,.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition map.cpp:185
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition map.cpp:168
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
Definition map_func.h:474
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition map_func.h:407
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition map_func.h:615
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
Definition map_func.h:559
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:429
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:419
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:574
@ First
The first client ID.
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Definition newgrf.cpp:75
Base for the NewGRF implementation.
bool HasGrfMiscBit(GrfMiscBit bit)
Check for grf miscellaneous bits.
Definition newgrf.h:229
@ WithTrack
Electrified depot graphics with tram track were loaded.
Definition newgrf.h:202
@ DesertPavedRoads
Show pavement and lights in desert towns.
Definition newgrf.h:70
@ Any
Use first found.
SpriteID GetCustomRailSprite(const RailTypeInfo *rti, TileIndex tile, RailSpriteType rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
NewGRF handling of rail types.
SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadSpriteType rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
NewGRF handling of road types.
@ All
Match if all bits are triggered.
@ FullDetail
Also draw details of track and roads.
Definition openttd.h:50
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Menu
In the main menu.
Definition openttd.h:19
@ Crossing
Level crossing overlay images.
Definition rail.h:50
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:320
bool RailNoLevelCrossings(RailType rt)
Test if a RailType disallows build of level crossings.
Definition rail.h:418
static const int INF
Big number compared to tilesprite size.
Command definitions for rail.
static RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition rail_map.h:36
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition rail_map.h:136
void MakeRailNormal(Tile t, Owner o, TrackBits b, RailType r)
Make the given tile a normal rail.
Definition rail_map.h:624
@ Normal
Normal rail tile without signals.
Definition rail_map.h:24
void SetTrackReservation(Tile t, TrackBits b)
Sets the reserved track bits of the tile.
Definition rail_map.h:209
TrackBits GetRailReservationTrackBits(Tile t)
Returns the reserved track bits of the tile.
Definition rail_map.h:194
Pseudo random number generator.
bool Chance16(const uint32_t a, const uint32_t b, const std::source_location location=std::source_location::current())
Flips a coin with given probability.
RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
Clean up unnecessary RoadBits of a planned tile.
Definition road.cpp:58
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition road.cpp:164
Road specific functions.
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:232
@ Catenary
Bit number for adding catenary.
Definition road.h:25
@ Hidden
Bit number for hidden from construction.
Definition road.h:28
RoadTypes _roadtypes_hidden_mask
Bitset of hidden roadtypes.
Definition road_cmd.cpp:57
Money RoadClearCost(RoadType roadtype)
Returns the cost of clearing the specified roadtype.
Definition road.h:253
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:217
Money RoadConvertCost(RoadType from, RoadType to)
Calculates the cost of road conversion.
Definition road.h:271
@ Ground
Required: Main group of ground images.
Definition road.h:41
@ CatenaryFront
Optional: Catenary front.
Definition road.h:43
@ Overlay
Optional: Images for overlaying track.
Definition road.h:40
@ UI
Optional: Cursor and toolbar icon images.
Definition road.h:39
@ CatenaryRear
Optional: Catenary back.
Definition road.h:44
@ Depot
Optional: Depot images.
Definition road.h:47
@ Oneway
Optional: One-way indicator images.
Definition road.h:50
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Definition road_cmd.cpp:56
bool RoadNoLevelCrossing(RoadType roadtype)
Test if road disallows level crossings.
Definition road.h:285
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition road.h:242
void ResetRoadTypes()
Reset all road type information to its default values.
Definition road_cmd.cpp:64
static VehicleEnterTileStates VehicleEnterTile_Road(Vehicle *v, TileIndex tile, int x, int y)
Tile callback function for a vehicle entering a tile.
std::vector< RoadVehicle * > RoadVehicleList
Helper type for lists/vectors of road vehicles.
Definition road_cmd.cpp:53
void InitRoadTypes()
Resolve sprites of custom road types.
Definition road_cmd.cpp:112
static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
Tile callback function signature of the terraforming callback.
CommandCost CmdBuildRoad(DoCommandFlags flags, TileIndex tile, RoadBits pieces, RoadType rt, DisallowedRoadDirections toggle_drd, TownID town_id)
Build a piece of road.
Definition road_cmd.cpp:603
static Foundation GetFoundation_Road(TileIndex tile, Slope tileh)
Tile callback function signature for getting the foundation of a tile.
static Foundation GetRoadFoundation(Slope tileh, RoadBits bits)
Get the foundationtype of a RoadBits Slope combination.
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:941
static bool DrawRoadAsSnowOrDesert(bool snow_or_desert, Roadside roadside)
Should the road be drawn as a unpaved snow/desert road?
bool UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
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:538
void DrawRoadGroundSprites(const TileInfo *ti, RoadBits road, RoadBits tram, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, Roadside roadside, bool snow_or_desert)
Draw road ground sprites.
bool RoadVehiclesAreBuilt()
Verify whether a road vehicle is available.
Definition road_cmd.cpp:173
void DrawRoadCatenary(const TileInfo *ti)
Draws the catenary for the given tile.
static void DrawTile_Road(TileInfo *ti)
Tile callback function signature for drawing a tile and its contents to the screen.
CommandCost CmdBuildRoadDepot(DoCommandFlags flags, TileIndex tile, RoadType rt, DiagDirection dir)
Build a road depot.
void DrawRoadTypeCatenary(const TileInfo *ti, RoadType rt, RoadBits rb)
Draws the catenary for the RoadType of the given tile.
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
Draw the road depot sprite.
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
Definition road_cmd.cpp:184
static SpriteID GetRoadGroundSprite(const TileInfo *ti, Roadside roadside, const RoadTypeInfo *rti, uint offset, bool snow_or_desert, PaletteID *pal)
Get ground sprite to draw for a road tile.
static int GetSlopePixelZ_Road(TileIndex tile, uint x, uint y, bool ground_vehicle)
Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.
static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owner)
Tile callback function signature for changing the owner of a tile.
static bool ClickTile_Road(TileIndex tile)
Tile callback function signature for clicking a tile.
CommandCost CmdBuildLongRoad(DoCommandFlags 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:970
static const TrackBits _road_trackbits[16]
Converts RoadBits to TrackBits.
static constexpr NonSteepSlopeIndexArray< uint8_t > _road_sloped_sprites
Lookup table to convert tile's slope into corresponding road sprite offset.
static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int8_t dx, int8_t dy, uint8_t h, bool transparent)
Draws details on/around the road.
RoadTypes _roadtypes_road
Bitset of road roadtypes.
Definition road_cmd.cpp:58
std::tuple< CommandCost, Money > CmdRemoveLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, bool start_half, bool end_half)
Remove a long piece of road.
static bool CanConvertUnownedRoadType(Owner owner, RoadTramType rtt)
Checks the tile and returns whether the current player is allowed to convert the roadtype to another ...
static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlags flags)
Tile callback function signature for clearing a tile.
CommandCost CmdConvertRoad(DoCommandFlags flags, TileIndex tile, TileIndex area_start, RoadType to_type, bool diagonal)
Convert one road subtype to another.
static void GetTileDesc_Road(TileIndex tile, TileDesc &td)
Tile callback function signature for obtaining a tile description.
static void DrawRoadBits(TileInfo *ti)
Draw ground sprite and road pieces.
static const std::array< NonSteepSlopeIndexArray< RoadBits >, 2 > _invalid_tileh_slopes_road
Invalid RoadBits on slopes.
Definition road_cmd.cpp:196
static CommandCost RemoveRoad(TileIndex tile, DoCommandFlags flags, RoadBits pieces, RoadTramType rtt, bool town_check)
Delete a piece of road.
Definition road_cmd.cpp:319
static constexpr DiagDirectionIndexArray< Trackdir > _roadveh_enter_depot_dir
Given the direction the road depot is pointing, this is the direction the vehicle should be travellin...
static void TileLoop_Road(TileIndex tile)
Tile callback function signature for running periodic tile updates.
static CommandCost CheckBuildAbove_Road(TileIndex tile, DoCommandFlags flags, Axis axis, int height)
Tile callback function signature to test if a bridge can be built above a tile.
RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
Allocate a new road type label.
Definition road_cmd.cpp:133
RoadTypes _roadtypes_tram
Bitset of tram roadtypes.
Definition road_cmd.cpp:59
static uint GetRoadSpriteOffset(Slope slope, RoadBits bits)
Get the sprite offset within a spritegroup.
CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadTramType rtt, DoCommandFlags flags, bool town_check)
Is it allowed to remove the given road bits from the given tile?
Definition road_cmd.cpp:256
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.
static bool CompareRoadTypes(const RoadType &first, const RoadType &second)
Compare roadtypes based on their sorting order.
Definition road_cmd.cpp:101
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.
static TrackStatus GetTileTrackStatus_Road(TileIndex tile, TransportType mode, RoadTramType sub_mode, DiagDirection side)
Tile callback function signature for getting the possible tracks that can be taken on a given tile by...
Road related functions.
Functions related to roads.
RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition road_func.h:93
bool IsValidRoadBits(RoadBits r)
Whether the given roadtype is valid.
Definition road_func.h:23
bool HasRoadCatenaryDrawn(RoadType roadtype)
Test if we should draw road catenary.
Definition road_func.h:129
void UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(TileIndex tile, Axis road_axis)
Update adjacent level crossing tiles in this multi-track crossing, due to removal of a level crossing...
bool HasRoadCatenary(RoadType roadtype)
Test if a road type has catenary.
Definition road_func.h:118
bool IsStraightRoad(RoadBits r)
Check if we've got a straight road.
Definition road_func.h:63
RoadBits MirrorRoadBits(RoadBits r)
Calculate the mirrored RoadBits.
Definition road_func.h:51
void MarkDirtyAdjacentLevelCrossingTiles(TileIndex tile, Axis road_axis)
Find adjacent level crossing tiles in this multi-track crossing and mark them dirty.
RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition road_func.h:78
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).
RoadBits ComplementRoadBits(RoadBits r)
Calculate the complement of a RoadBits value.
Definition road_func.h:37
Functions used internally by the roads.
Sprite constructs for road depots.
static const DiagDirectionIndexArray< DrawTileSpriteSpan > _road_depot
Sprite layout for a road depot for each direction.
Definition road_land.h:31
bool MayHaveRoad(Tile t)
Test whether a tile can have road/tram types.
Definition road_map.cpp:21
RoadBits GetAnyRoadBits(Tile tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
Definition road_map.cpp:54
void SetRoadOwner(Tile t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition road_map.h:261
bool HasCrossingReservation(Tile t)
Get the reservation state of the rail crossing.
Definition road_map.h:390
static RoadTileType GetRoadTileType(Tile t)
Get the type of the road tile.
Definition road_map.h:36
bool HasTownOwnedRoad(Tile t)
Checks if given tile has town owned road.
Definition road_map.h:290
RoadType GetRoadTypeRoad(Tile t)
Get the road type for RoadTramType being RoadTramType::Road.
Definition road_map.h:152
void SetRoadDepotExitDirection(Tile tile, DiagDirection dir)
Sets the exit direction of a road depot.
Definition road_map.h:692
bool IsLevelCrossingTile(Tile t)
Return whether a tile is a level crossing tile.
Definition road_map.h:79
bool IncreaseRoadWorksCounter(Tile t)
Increase the progress counter of road works.
Definition road_map.h:529
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:112
static bool IsRoadDepotTile(Tile t)
Return whether a tile is a road depot tile.
Definition road_map.h:100
bool IsValidDisallowedRoadDirections(DisallowedRoadDirections drt)
Checks if a DisallowedRoadDirections is valid.
Definition road_map.h:301
Axis GetCrossingRoadAxis(Tile t)
Get the road axis of a level crossing.
Definition road_map.h:346
void SetDisallowedRoadDirections(Tile t, DisallowedRoadDirections drd)
Sets the disallowed directions.
Definition road_map.h:322
Track GetCrossingRailTrack(Tile tile)
Get the rail track of a level crossing.
Definition road_map.h:379
bool HasRoadTypeTram(Tile t)
Check if a tile has a road type when RoadTramType is RoadTramType::Tram.
Definition road_map.h:210
void StartRoadWorks(Tile t)
Start road works on a tile.
Definition road_map.h:541
DisallowedRoadDirections GetDisallowedRoadDirections(Tile t)
Gets the disallowed directions.
Definition road_map.h:311
bool HasTileRoadType(Tile t, RoadTramType rtt)
Check if a tile has a road or a tram road type.
Definition road_map.h:221
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
Definition road_map.h:576
static bool IsRoadDepot(Tile t)
Return whether a tile is a road depot.
Definition road_map.h:90
RoadType GetRoadTypeTram(Tile t)
Get the road type for RoadTramType being RoadTramType::Tram.
Definition road_map.h:163
void MakeRoadNormal(Tile t, RoadBits bits, RoadType road_rt, RoadType tram_rt, TownID town, Owner road, Owner tram)
Make a normal road tile.
Definition road_map.h:646
Roadside GetRoadside(Tile tile)
Get the decorations of a road.
Definition road_map.h:499
RoadTileType
The different types of road tiles.
Definition road_map.h:22
@ Normal
Normal road.
Definition road_map.h:23
@ Depot
Depot (one entrance).
Definition road_map.h:25
@ Crossing
Level crossing.
Definition road_map.h:24
void MakeRoadCrossing(Tile t, Owner road, Owner tram, Owner rail, Axis roaddir, RailType rat, RoadType road_rt, RoadType tram_rt, TownID town)
Make a level crossing.
Definition road_map.h:672
void ToggleSnowOrDesert(Tile t)
Toggle the snow/desert state of a road tile.
Definition road_map.h:476
RoadBits GetAllRoadBits(Tile tile)
Get all set RoadBits on the given tile.
Definition road_map.h:125
Axis GetCrossingRailAxis(Tile t)
Get the rail axis of a level crossing.
Definition road_map.h:358
RoadType GetRoadType(Tile t, RoadTramType rtt)
Get the road type for the given RoadTramType.
Definition road_map.h:175
static bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Definition road_map.h:58
void TerminateRoadWorks(Tile t)
Terminate road works on a tile.
Definition road_map.h:562
RoadBits GetCrossingRoadBits(Tile tile)
Get the road bits of a level crossing.
Definition road_map.h:369
void SetRoadType(Tile t, RoadTramType rtt, RoadType rt)
Set the road type of a tile.
Definition road_map.h:615
Owner GetRoadOwner(Tile t, RoadTramType rtt)
Get the owner of a specific road type.
Definition road_map.h:244
bool IsCrossingBarred(Tile t)
Check if the level crossing is barred.
Definition road_map.h:426
void SetRoadside(Tile tile, Roadside s)
Set the decorations of a road.
Definition road_map.h:509
bool IsRoadOwner(Tile t, RoadTramType rtt, Owner o)
Check if a specific road type is owned by an owner.
Definition road_map.h:278
void MakeRoadDepot(Tile tile, Owner owner, DepotID depot_id, DiagDirection dir, RoadType rt)
Make a road depot.
Definition road_map.h:706
void SetCrossingReservation(Tile t, bool b)
Set the reservation state of the rail crossing.
Definition road_map.h:403
void SetRoadBits(Tile t, RoadBits r, RoadTramType rtt)
Set the present road bits for a specific road type.
Definition road_map.h:137
Roadside
The possible road side decorations.
Definition road_map.h:483
@ Paved
Road with paved sidewalks.
Definition road_map.h:486
@ Barren
Road on barren land.
Definition road_map.h:484
@ GrassRoadWorks
Road on grass with road works.
Definition road_map.h:490
@ StreetLights
Road with street lights on paved sidewalks.
Definition road_map.h:487
@ Trees
Road with trees on paved sidewalks.
Definition road_map.h:489
@ Grass
Road on grass.
Definition road_map.h:485
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:69
static bool IsNormalRoad(Tile t)
Return whether a tile is a normal road.
Definition road_map.h:48
bool IsOnSnowOrDesert(Tile t)
Check if a road tile has snow/desert.
Definition road_map.h:467
bool HasRoadWorks(Tile t)
Check if a tile has road works.
Definition road_map.h:519
EnumBitSet< RoadType, uint64_t > RoadTypes
Bitset of RoadType elements.
Definition road_type.h:33
static constexpr RoadBits ROAD_X
Full road along the x-axis (south-west + north-east).
Definition road_type.h:67
@ Northbound
All northbound traffic is disallowed.
Definition road_type.h:80
@ Southbound
All southbound traffic is disallowed.
Definition road_type.h:79
EnumBitSet< RoadBit, uint8_t > RoadBits
Bitset of RoadBit elements.
Definition road_type.h:65
@ SW
South-west part.
Definition road_type.h:59
@ NW
North-west part.
Definition road_type.h:58
@ NE
North-east part.
Definition road_type.h:61
@ SE
South-east part.
Definition road_type.h:60
EnumBitSet< DisallowedRoadDirection, uint8_t > DisallowedRoadDirections
Bitset of DisallowedRoadDirection elements.
Definition road_type.h:85
static constexpr RoadBits ROAD_ALL
Full 4-way crossing.
Definition road_type.h:75
static constexpr RoadBits ROAD_Y
Full road along the y-axis (north-west + south-east).
Definition road_type.h:68
static constexpr RoadTramTypes ROADTRAMTYPES_ALL
All possible RoadTramTypes.
Definition road_type.h:49
RoadType
The different roadtypes we support.
Definition road_type.h:24
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:29
@ ROADTYPE_TRAM
Trams.
Definition road_type.h:27
@ ROADTYPE_ROAD
Basic road type.
Definition road_type.h:26
@ ROADTYPE_END
Used for iterations.
Definition road_type.h:28
RoadTramType
The different types of road type.
Definition road_type.h:38
@ Tram
Tram type.
Definition road_type.h:40
@ Road
Road type.
Definition road_type.h:39
All the roadtype-specific information is stored here.
static const RoadTypeInfo _original_roadtypes[]
Global Roadtype definition.
Definition roadtypes.h:18
Road vehicle states.
@ RVSB_IN_DEPOT
The vehicle is in a depot.
Definition roadveh.h:38
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
static constexpr int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height).
Definition slope_func.h:170
bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Definition slope_func.h:98
uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
Definition slope_func.h:423
Corner GetHighestSlopeCorner(Slope s)
Returns the highest corner of a slope (one corner raised or a steep slope).
Definition slope_func.h:136
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition slope_func.h:36
Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
Definition slope_func.h:377
Slope SlopeWithOneCornerRaised(Corner corner)
Returns the slope with a specific corner raised.
Definition slope_func.h:109
@ E
East tile corner.
Definition slope_type.h:24
@ W
West tile corner.
Definition slope_type.h:22
@ N
North tile corner.
Definition slope_type.h:25
Slope
Enumeration for the slope-type.
Definition slope_type.h:53
@ SLOPE_ELEVATED
bit mask containing all 'simple' slopes
Definition slope_type.h:66
@ SLOPE_SW
south and west corner are raised
Definition slope_type.h:61
@ SLOPE_FLAT
a flat tile
Definition slope_type.h:54
@ SLOPE_NE
north and east corner are raised
Definition slope_type.h:63
@ SLOPE_SE
south and east corner are raised
Definition slope_type.h:62
@ SLOPE_NW
north and west corner are raised
Definition slope_type.h:60
static constexpr uint8_t NUM_SLOPES
The total number of possible slope types.
Definition slope_type.h:86
Foundation
Enumeration for Foundations.
Definition slope_type.h:119
@ Leveled
The tile is leveled up to a flat slope.
Definition slope_type.h:121
@ None
The tile has no foundation, the slope remains unchanged.
Definition slope_type.h:120
@ InclinedY
The tile has an along Y-axis inclined foundation.
Definition slope_type.h:123
@ InclinedX
The tile has an along X-axis inclined foundation.
Definition slope_type.h:122
static const uint32_t VALID_LEVEL_CROSSING_SLOPES
Constant bitset with safe slopes for building a level crossing.
Definition slope_type.h:112
EnumClassIndexContainer< std::array< T, SLOPE_ELEVATED >, Slope > NonSteepSlopeIndexArray
Array with non steep Slope as index.
Definition slope_type.h:104
Functions related to sound.
@ SND_21_ROAD_WORKS
31 == 0x1F Road reconstruction animation
Definition sound_type.h:78
void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence in GUI with railroad specifics.
Definition sprite.h:122
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:221
void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence on tile with railroad specifics.
Definition sprite.h:108
static const SpriteID SPR_TRAMWAY_TRAM
Definition sprites.h:304
static const SpriteID SPR_TRAMWAY_DEPOT_WITH_TRACK
Definition sprites.h:312
static const SpriteID SPR_TRAMWAY_BACK_WIRES_SLOPED
Definition sprites.h:315
static const uint16_t ONEWAY_SLOPE_N_OFFSET
Definition sprites.h:326
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition sprites.h:1794
static const SpriteID SPR_TRAMWAY_DEPOT_NO_TRACK
Definition sprites.h:319
static const SpriteID SPR_ROAD_DEPOT
Definition sprites.h:666
static const SpriteID SPR_FLAT_SNOW_DESERT_TILE
Definition sprites.h:689
static const SpriteID SPR_TRAMWAY_OVERLAY
Definition sprites.h:303
static const SpriteID SPR_TRAMWAY_BASE
Definition sprites.h:302
static const SpriteID SPR_ROAD_Y
Definition sprites.h:661
static const uint16_t ONEWAY_SLOPE_S_OFFSET
Definition sprites.h:327
static const SpriteID SPR_FLAT_GRASS_TILE
Definition sprites.h:677
static const PaletteID PALETTE_TO_BARE_LAND
sets colour to bare land stuff for rail, road and crossings
Definition sprites.h:1782
static const SpriteID SPR_TRAMWAY_FRONT_WIRES_SLOPED
Definition sprites.h:316
static const SpriteID SPR_ONEWAY_BASE
Definition sprites.h:325
@ Count
by amount of cargo
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
bool IsDriveThroughStopTile(Tile t)
Is tile t a drive through road stop station or waypoint?
bool IsAnyRoadStop(Tile t)
Is the station at t a road station?
Axis GetDriveThroughStopAxis(Tile t)
Gets the axis of the drive through stop.
DiagDirection GetBayRoadStopDir(Tile t)
Gets the direction the bay road stop entrance points towards.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:261
EncodedString GetEncodedStringWithArgs(StringID str, std::span< const StringParameter > params)
Encode a string with its parameters into an encoded string.
Definition strings.cpp:101
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
constexpr bool Empty() const
Check whether the label is empty.
VehicleType type
Type of vehicle.
std::array< uint32_t, ROADTYPE_END > road
Count of company owned track bits for each road type.
std::array< uint32_t, RAILTYPE_END > rail
Count of company owned track bits for each rail type.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
T x
X coordinate.
T y
Y coordinate.
T z
Z coordinate.
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:55
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:56
A special vehicle is one of the following:
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:366
static uint Size()
Get the size of the map.
Definition map_func.h:280
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
static Pool::IterateWrapper< Vehicle > Iterate(size_t from=0)
static T * Create(Targs &&... args)
static Company * Get(auto index)
static bool CanAllocateItem(size_t n=1)
static Company * GetIfValid(auto index)
Buses, trucks and trams belong to this class.
Definition roadveh.h:105
uint8_t state
Definition roadveh.h:107
T * Next() const
Get next vehicle in the chain.
static RoadVehicle * From(Vehicle *v)
T * First() const
Get the first vehicle in the chain.
Used to only draw a part of the sprite.
Definition gfx_type.h:278
Tile description for the 'land area information' tool.
Definition tile_cmd.h:40
uint16_t rail_speed
Speed limit of rail (bridges and track).
Definition tile_cmd.h:53
StringID str
Description of the tile.
Definition tile_cmd.h:41
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:45
std::array< Owner, 4 > owner
Name of the owner(s).
Definition tile_cmd.h:43
uint16_t tram_speed
Speed limit of tram (bridges and track).
Definition tile_cmd.h:57
StringID roadtype
Type of road on the tile.
Definition tile_cmd.h:54
StringID tramtype
Type of tram on the tile.
Definition tile_cmd.h:56
StringID railtype
Type of rail on the tile.
Definition tile_cmd.h:52
uint16_t road_speed
Speed limit of road (bridges and track).
Definition tile_cmd.h:55
std::array< StringID, 4 > owner_type
Type of each owner.
Definition tile_cmd.h:44
Tile information, used while rendering the tile.
Definition tile_cmd.h:34
Slope tileh
Slope of the tile.
Definition tile_cmd.h:35
TileIndex tile
Tile index.
Definition tile_cmd.h:36
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:214
std::array< uint32_t, NUM_HOUSE_ZONES > squared_town_zone_radius
UpdateTownRadius updates this given the house count.
Definition town.h:57
Town data structure.
Definition town.h:64
TileIndex xy
town center tile
Definition town.h:65
TownCache cache
Container for all cacheable data.
Definition town.h:67
uint8_t road_build_months
fund road reconstruction in action?
Definition town.h:197
Track status of a tile.
Definition track_type.h:105
Vehicle data structure.
Direction direction
facing
VehStates vehstatus
Status.
TileIndex tile
Current tile index.
@ EnteredWormhole
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
Definition tile_cmd.h:26
EnumBitSet< VehicleEnterTileState, uint8_t > VehicleEnterTileStates
Bitset of VehicleEnterTileState elements.
Definition tile_cmd.h:31
std::tuple< Slope, int > GetTileSlopeZ(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.cpp:55
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition tile_map.cpp:135
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition tile_map.h:214
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition tile_map.h:198
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
Definition tile_map.h:312
std::tuple< Slope, int > GetTilePixelSlope(TileIndex tile)
Return the slope of a given tile.
Definition tile_map.h:289
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition tile_map.h:238
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
@ Desert
Tile is desert.
Definition tile_type.h:83
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18
TileType
The different types of tiles.
Definition tile_type.h:48
@ TunnelBridge
Tunnel entry/exit and bridge heads.
Definition tile_type.h:58
@ Station
A tile of a station or airport.
Definition tile_type.h:54
@ Railway
A tile with railway.
Definition tile_type.h:50
@ Road
A tile with road and/or tram tracks.
Definition tile_type.h:51
OrthoDiagonalTileArea CreateOrthoDiagonalArea(TileIndex corner1, TileIndex corner2, bool diagonal)
Create an Orthogonal/Diagonal tile area wrapper.
Definition tilearea.cpp:23
Type for storing the 'area' of something uses on the map.
Definition of the game-calendar-timer.
Base of the town class.
void ChangeTownRating(Town *t, int add, int max, DoCommandFlags flags)
Changes town rating of the current company.
@ TunnelBridgeRemove
Removal of a tunnel or bridge owned by the town.
Definition town.h:276
@ RoadRemove
Removal of a road owned by the town.
Definition town.h:275
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
RoadType GetTownRoadType()
Get the road type that towns should build at this current moment.
Definition town_cmd.cpp:933
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
CommandCost CheckforTownRating(DoCommandFlags flags, Town *t, TownRatingCheckType type)
Does the town authority allow the (destructive) action of the current company?
HouseZone GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition town.h:335
void SetTownIndex(Tile t, TownID index)
Set the town index for a road or house tile.
Definition town_map.h:35
static constexpr int RATING_ROAD_DOWN_STEP_EDGE
removing a roadpiece at the edge
Definition town_type.h:66
static constexpr int RATING_ROAD_DOWN_STEP_INNER
removing a roadpiece in the middle
Definition town_type.h:65
static constexpr int RATING_ROAD_MINIMUM
minimum rating after removing town owned road
Definition town_type.h:67
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition track_func.h:292
Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track Axis::X -> Track::X Axis::Y -> Track::Y Uses the fact that...
Definition track_func.h:62
Track DiagDirToDiagTrack(DiagDirection diagdir)
Maps a DiagDirection to the associated diagonal Track.
Definition track_func.h:419
EnumBitSet< Trackdir, uint16_t > TrackdirBits
Bitset of Trackdir elements.
Definition track_type.h:93
EnumBitSet< Track, uint8_t > TrackBits
Bitset of Track elements.
Definition track_type.h:43
static constexpr TrackBits TRACK_BIT_ALL
All possible tracks.
Definition track_type.h:52
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:63
@ X_NE
X-axis and direction to north-east.
Definition track_type.h:64
@ X_SW
X-axis and direction to south-west.
Definition track_type.h:72
@ Y_SE
Y-axis and direction to south-east.
Definition track_type.h:65
@ Y_NW
Y-axis and direction to north-west.
Definition track_type.h:73
Track
These are used to specify a single track.
Definition track_type.h:19
@ X
Track along the x-axis (north-east to south-west).
Definition track_type.h:21
@ Upper
Track in the upper corner of the tile (north).
Definition track_type.h:23
@ Y
Track along the y-axis (north-west to south-east).
Definition track_type.h:22
@ Right
Track in the right corner of the tile (east).
Definition track_type.h:26
@ Left
Track in the left corner of the tile (west).
Definition track_type.h:25
@ Lower
Track in the lower corner of the tile (south).
Definition track_type.h:24
Base for the train class.
bool TrainOnCrossing(TileIndex tile)
Check if a level crossing tile has a train on it.
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...
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...
DisplayOptions _display_opt
What do we want to draw/do?
@ Houses
town buildings
@ Buildings
company buildings - depots, stations, HQ, ...
TransportType
Available types of transport.
@ Rail
Transport by train.
@ Road
Transport by road vehicle.
Header file for things common for tunnels and bridges.
void SetTunnelBridgeOwner(TileIndex begin, TileIndex end, Owner owner)
Sets the ownership of the bridge/tunnel ramps.
void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
Mark bridge tiles dirty.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles).
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition vehicle.cpp:559
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it,...
Definition vehicle.cpp:1564
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore)
Finds vehicle in tunnel / bridge.
Definition vehicle.cpp:583
@ Hidden
Vehicle is not visible.
Functions related to vehicles.
@ Road
Road vehicle type.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition viewport.cpp:665
void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32_t x, int32_t 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:557
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:580
Functions related to (drawing on) viewports.
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
static constexpr int BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).
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:3377
Entry point for OpenTTD to YAPF's cache.
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
@ Detail
All zoom levels below or equal to this will result in details on the screen, like road-work,...
Definition zoom_type.h:44