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