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