35 #include "table/strings.h" 45 std::vector<RailType> _sorted_railtypes;
71 {0,0,0,0,0,0,0,0,0,0,0,0},
75 0,
RAILTYPES_NONE,
RAILTYPES_NONE, 0, 0, 0,
RTFB_NONE, 0, 0, 0, 0, 0,
78 for (; i <
lengthof(_railtypes); i++) _railtypes[i] = empty_railtype;
86 if (cursors_base != 0) {
106 const SpriteID _signal_lookup[2][SIGTYPE_END] = {
107 {SPR_IMG_SIGNAL_ELECTRIC_NORM, SPR_IMG_SIGNAL_ELECTRIC_ENTRY, SPR_IMG_SIGNAL_ELECTRIC_EXIT,
108 SPR_IMG_SIGNAL_ELECTRIC_COMBO, SPR_IMG_SIGNAL_ELECTRIC_PBS, SPR_IMG_SIGNAL_ELECTRIC_PBS_OWAY},
110 {SPR_IMG_SIGNAL_SEMAPHORE_NORM, SPR_IMG_SIGNAL_SEMAPHORE_ENTRY, SPR_IMG_SIGNAL_SEMAPHORE_EXIT,
111 SPR_IMG_SIGNAL_SEMAPHORE_COMBO, SPR_IMG_SIGNAL_SEMAPHORE_PBS, SPR_IMG_SIGNAL_SEMAPHORE_PBS_OWAY},
118 rti->
gui_sprites.
signals[type][var][0] = (red != 0) ? red + SIGNAL_TO_SOUTH : _signal_lookup[var][type];
119 rti->
gui_sprites.
signals[type][var][1] = (green != 0) ? green + SIGNAL_TO_SOUTH : _signal_lookup[var][type] + 1;
142 ResolveRailTypeGUISprites(rti);
146 _sorted_railtypes.clear();
148 if (_railtypes[rt].label != 0 && !
HasBit(_railtypes_hidden_mask, rt)) {
149 _sorted_railtypes.push_back(rt);
152 std::sort(_sorted_railtypes.begin(), _sorted_railtypes.end(),
CompareRailTypes);
163 if (rti->
label == 0) {
190 static const byte _track_sloped_sprites[14] = {
260 if (current == future) {
270 return_cmd_error((flags & DC_NO_RAIL_OVERLAP) ? STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION : STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
429 static inline bool ValParamTrackOrientation(
Track track)
445 RailType railtype = Extract<RailType, 0, 6>(p1);
446 Track track = Extract<Track, 0, 3>(p2);
457 if (ret.
Failed())
return ret;
465 if (ret.
Failed())
return ret;
468 if (ret.
Failed())
return ret;
477 if (ret.
Failed())
return ret;
506 if (ret.
Failed())
return ret;
515 RoadType roadtype_road = GetRoadTypeRoad(tile);
516 RoadType roadtype_tram = GetRoadTypeTram(tile);
531 if (ret.
Failed())
return ret;
535 if (num_new_road_pieces > 0) {
536 cost.AddCost(num_new_road_pieces *
RoadBuildCost(roadtype_road));
540 if (num_new_tram_pieces > 0) {
541 cost.AddCost(num_new_tram_pieces *
RoadBuildCost(roadtype_tram));
550 Company::Get(road_owner)->infrastructure.road[roadtype_road] += num_new_road_pieces;
554 Company::Get(tram_owner)->infrastructure.road[roadtype_tram] += num_new_tram_pieces;
571 bool docking = IsPossibleDockingTile(tile) &&
IsDockingTile(tile);
574 if (ret.
Failed())
return ret;
578 if (ret.
Failed())
return ret;
582 cost.AddCost(-_price[PR_CLEAR_WATER]);
583 cost.AddCost(_price[PR_CLEAR_ROUGH]);
620 Track track = Extract<Track, 0, 3>(p2);
622 bool crossing =
false;
624 if (!ValParamTrackOrientation(track))
return CMD_ERROR;
641 if (ret.
Failed())
return ret;
646 if (ret.
Failed())
return ret;
673 if (ret.
Failed())
return ret;
677 if (ret.
Failed())
return ret;
680 if ((present & trackbit) == 0)
return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
768 bool flooded =
false;
777 TrackBits to_remove = lower_track & rail_bits;
778 if (to_remove != 0) {
782 if (!flooded)
return flooded;
783 rail_bits = rail_bits & ~to_remove;
784 if (rail_bits == 0) {
810 { -1, 0 }, { 0, 1 }, { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, 1 },
813 { 1, 0 }, { 0, -1 }, { 0, -1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
821 int x =
TileX(start);
822 int y =
TileY(start);
833 int trdx = _trackdelta[*trackdir].
x;
834 int trdy = _trackdelta[*trackdir].
y;
837 trdx += _trackdelta[*trackdir ^ 1].
x;
838 trdy += _trackdelta[*trackdir ^ 1].
y;
842 while ((trdx <= 0 && dx > 0) ||
843 (trdx >= 0 && dx < 0) ||
844 (trdy <= 0 && dy > 0) ||
845 (trdy >= 0 && dy < 0)) {
846 if (!
HasBit(*trackdir, 3)) {
858 trdx = _trackdelta[*trackdir].
x;
859 trdy = _trackdelta[*trackdir].
y;
882 Track track = Extract<Track, 6, 3>(p2);
883 bool remove =
HasBit(p2, 9);
884 RailType railtype = Extract<RailType, 0, 6>(p2);
891 CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
892 if (ret.
Failed())
return ret;
894 bool had_success =
false;
901 if (last_error.
GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !
remove) {
902 if (
HasBit(p2, 10))
return last_error;
907 if (last_error.
GetErrorMessage() == STR_ERROR_OWNED_BY &&
remove)
break;
913 if (tile == end_tile)
break;
921 if (had_success)
return total_cost;
978 RailType railtype = Extract<RailType, 0, 6>(p1);
998 cost.AddCost(_price[PR_BUILD_FOUNDATION]);
1002 if (cost.Failed())
return cost;
1023 cost.AddCost(_price[PR_BUILD_DEPOT_TRAIN]);
1051 Track track = Extract<Track, 0, 3>(p1);
1052 bool ctrl_pressed =
HasBit(p1, 3);
1054 SignalType sigtype = Extract<SignalType, 5, 3>(p1);
1055 bool convert_signal =
HasBit(p1, 8);
1056 SignalType cycle_start = Extract<SignalType, 9, 3>(p1);
1057 SignalType cycle_stop = Extract<SignalType, 12, 3>(p1);
1058 uint num_dir_cycle =
GB(p1, 15, 2);
1060 if (sigtype > SIGTYPE_LAST)
return CMD_ERROR;
1061 if (cycle_start > cycle_stop || cycle_stop > SIGTYPE_LAST)
return CMD_ERROR;
1072 if (ret.
Failed())
return ret;
1088 if (p2 != 0 && sigvar != GetSignalVariant(tile, track)) {
1092 }
else if (convert_signal) {
1094 if (ctrl_pressed || GetSignalVariant(tile, track) != sigvar) {
1123 SetSignalType(tile, track, sigtype);
1124 SetSignalVariant(tile, track, sigvar);
1134 SetSignalType(tile, track, sigtype);
1135 SetSignalVariant(tile, track, sigvar);
1136 while (num_dir_cycle-- > 0) CycleSignalSide(tile, track);
1138 if (convert_signal) {
1144 sigtype = GetSignalType(tile, track);
1147 SetSignalType(tile, track, sigtype);
1148 SetSignalVariant(tile, track, sigvar);
1154 }
else if (ctrl_pressed) {
1156 sigtype = (
SignalType)(GetSignalType(tile, track) + 1);
1158 if (sigtype < cycle_start || sigtype > cycle_stop) sigtype = cycle_start;
1160 SetSignalType(tile, track, sigtype);
1166 CycleSignalSide(tile, track);
1168 sigtype = GetSignalType(tile, track);
1175 SetSignalVariant(tile, track, sigvar);
1176 SetSignalType(tile, track, sigtype);
1183 if (IsPbsSignal(sigtype)) {
1203 static bool CheckSignalAutoFill(
TileIndex &tile,
Trackdir &trackdir,
int &signal_ctr,
bool remove)
1254 default:
return false;
1280 Track track = Extract<Track, 0, 3>(p2);
1281 bool mode =
HasBit(p2, 3);
1282 bool semaphores =
HasBit(p2, 4);
1283 bool remove =
HasBit(p2, 5);
1284 bool autofill =
HasBit(p2, 6);
1285 bool minimise_gaps =
HasBit(p2, 10);
1286 byte signal_density =
GB(p2, 24, 8);
1290 if (signal_density == 0 || signal_density > 20)
return CMD_ERROR;
1296 signal_density *= 2;
1299 CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
1300 if (ret.
Failed())
return ret;
1303 Trackdir start_trackdir = trackdir;
1309 if (sigtype > SIGTYPE_LAST)
return CMD_ERROR;
1315 assert(signals != 0);
1318 semaphores = GetSignalVariant(tile, track) !=
SIG_ELECTRIC;
1320 sigtype = GetSignalType(tile, track);
1327 byte signal_dir = 0;
1344 int last_used_ctr = INT_MIN;
1345 int last_suitable_ctr = 0;
1349 bool had_success =
false;
1352 if (
remove || minimise_gaps || signal_ctr % signal_density == 0) {
1355 SB(p1, 4, 1, semaphores);
1356 SB(p1, 5, 3, sigtype);
1357 if (!
remove && signal_ctr == 0)
SetBit(p1, 17);
1365 bool test_only = !
remove && minimise_gaps && signal_ctr < (last_used_ctr + signal_density);
1368 if (ret.Succeeded()) {
1370 last_suitable_ctr = signal_ctr;
1371 last_suitable_tile = tile;
1372 last_suitable_trackdir = trackdir;
1373 }
else if (!test_only && last_suitable_tile !=
INVALID_TILE) {
1389 if (ret.Succeeded()) {
1392 last_used_ctr = last_suitable_ctr;
1396 if (ret.GetErrorMessage() != STR_ERROR_THERE_IS_NO_RAILROAD_TRACK ||
1405 if (!CheckSignalAutoFill(tile, trackdir, signal_ctr,
remove))
break;
1408 if (tile == start_tile && trackdir == start_trackdir)
break;
1410 if (tile == end_tile)
break;
1424 return had_success ? total_cost : last_error;
1464 Track track = Extract<Track, 0, 3>(p1);
1476 if (ret.
Failed())
return ret;
1484 }
else if (IsPbsSignal(GetSignalType(tile, track))) {
1487 for (
int i = 0; v ==
nullptr && i < 2; i++, td =
ReverseTrackdir(td)) {
1567 RailType totype = Extract<RailType, 0, 6>(p2);
1570 bool diagonal =
HasBit(p2, 6);
1579 bool found_convertible_track =
false;
1595 error.
MakeError(STR_ERROR_CROSSING_DISALLOWED_RAIL);
1618 std::vector<Train *> vehicles_affected;
1638 vehicles_affected.push_back(v);
1675 found_convertible_track =
true;
1680 if (flags & DC_EXEC) {
1687 found_convertible_track =
true;
1698 if (endtile < tile) {
1722 vehicles_affected.push_back(v);
1750 found_convertible_track =
true;
1761 found_convertible_track =
true;
1766 for (uint i = 0; i < vehicles_affected.size(); ++i) {
1773 for (
Train *v : affected_trains) {
1779 return found_convertible_track ? cost :
error;
1786 if (ret.
Failed())
return ret;
1790 if (ret.
Failed())
return ret;
1806 delete Depot::GetByTile(tile);
1807 DoClearSquare(tile);
1843 if (ret.
Failed())
return ret;
1851 if (ret.
Failed())
return ret;
1854 if (flags &
DC_EXEC) DoClearSquare(tile);
1855 cost.
AddCost(_price[PR_CLEAR_WATER]);
1862 return RemoveTrainDepot(tile, flags);
1882 return GetSlopePixelZ(x, y);
1889 case 0: side =
false;
break;
1890 case 2: side =
true;
break;
1893 static const Point SignalPositions[2][12] = {
1896 { 8, 5}, {14, 1}, { 1, 14}, { 9, 11}, { 1, 0}, { 3, 10},
1898 {11, 4}, {14, 14}, {11, 3}, { 4, 13}, { 3, 4}, {11, 13}
1901 {14, 1}, {12, 10}, { 4, 6}, { 1, 14}, {10, 4}, { 0, 1},
1903 {14, 14}, { 5, 12}, {11, 13}, { 4, 3}, {13, 4}, { 3, 11}
1910 SignalType type = GetSignalType(tile, track);
1919 sprite += type * 16 + variant * 64 + image * 2 + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0);
1925 static uint32 _drawtile_track_palette;
1940 { CORNER_INVALID, 0, 1, 16, 1 },
1941 { CORNER_INVALID, 1, 0, 1, 16 },
1942 { CORNER_W, 8, 8, 1, 1 },
1943 { CORNER_N, 8, 8, 1, 1 },
1944 { CORNER_INVALID, 0, 1, 16, 1 },
1945 { CORNER_INVALID, 1, 0, 1, 16 },
1946 { CORNER_INVALID, 0, 1, 16, 1 },
1947 { CORNER_INVALID, 1, 0, 1, 16 },
1948 { CORNER_INVALID, 0, 15, 16, 1 },
1949 { CORNER_INVALID, 15, 0, 1, 16 },
1950 { CORNER_E, 8, 8, 1, 1 },
1951 { CORNER_S, 8, 8, 1, 1 },
1952 { CORNER_INVALID, 0, 15, 16, 1 },
1953 { CORNER_INVALID, 15, 0, 1, 16 },
1954 { CORNER_INVALID, 0, 15, 16, 1 },
1955 { CORNER_INVALID, 15, 0, 1, 16 },
1968 if (_fence_offsets[rfo].
height_ref != CORNER_INVALID) {
1972 ti->
x + _fence_offsets[rfo].
x_offs,
1973 ti->
y + _fence_offsets[rfo].
y_offs,
1974 _fence_offsets[rfo].
x_size,
1975 _fence_offsets[rfo].
y_size,
2028 uint num_sprites = 0;
2030 if (base_image == 0) {
2031 base_image = SPR_TRACK_FENCE_FLAT_X;
2035 assert(num_sprites > 0);
2037 switch (GetRailGroundType(ti->
tile)) {
2059 switch (track_corner) {
2064 default: NOT_REACHED();
2073 static const int INF = 1000;
2074 static const SubSprite _halftile_sub_sprite[4] = {
2075 { -INF , -INF , 32 - 33, INF },
2076 { -INF , 0 + 7, INF , INF },
2077 { -31 + 33, -INF , INF , INF },
2078 { -INF , -INF , INF , 30 - 23 }
2090 Corner halftile_corner = CORNER_INVALID;
2107 DrawShoreTile(ti->
tileh);
2118 default: image = SPR_FLAT_GRASS_TILE;
break;
2133 }
else if (no_combine) {
2169 DrawTrackSprite(ground +
RTO_S, PAL_NONE, ti,
SLOPE_S);
break;
2171 DrawTrackSprite(ground +
RTO_W, PAL_NONE, ti,
SLOPE_W);
break;
2221 default: image = SPR_FLAT_GRASS_TILE;
break;
2226 DrawGroundSprite(image, PAL_NONE, &(_halftile_sub_sprite[halftile_corner]));
2232 default: NOT_REACHED();
2239 DrawTrackSprite(ground + offset, PAL_NONE, ti, fake_slope);
2241 DrawTrackSprite(overlay + offset,
PALETTE_CRASH, ti, fake_slope);
2255 if (rti->UsesOverlay()) {
2256 DrawTrackBitsOverlay(ti, track, rti);
2262 Corner halftile_corner = CORNER_INVALID;
2278 bool junction =
false;
2285 DrawShoreTile(ti->
tileh);
2288 image = SPR_FLAT_WATER_TILE;
2294 default: image = SPR_FLAT_GRASS_TILE;
break;
2335 DrawShoreTile(ti->
tileh);
2337 sub = &(_halftile_sub_sprite[track_corner]);
2396 static const byte _corner_to_track_sprite[] = {3, 1, 2, 0};
2404 #define MAYBE_DRAW_SIGNAL(x, y, z, t) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, rti, t, GetSingleSignalState(tile, x), y, z) 2409 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTH, 0,
TRACK_LEFT);
2410 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTH, 1,
TRACK_LEFT);
2413 MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_NORTH, 2,
TRACK_RIGHT);
2414 MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_SOUTH, 3,
TRACK_RIGHT);
2417 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_WEST, 4,
TRACK_UPPER);
2418 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_EAST, 5,
TRACK_UPPER);
2421 MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_WEST, 6,
TRACK_LOWER);
2422 MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_EAST, 7,
TRACK_LOWER);
2425 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHWEST, 8,
TRACK_X);
2426 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHEAST, 9,
TRACK_X);
2429 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHEAST, 10,
TRACK_Y);
2430 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHWEST, 11,
TRACK_Y);
2434 static void DrawTile_Track(
TileInfo *ti)
2466 if (rti->UsesOverlay()) {
2467 image = SPR_FLAT_GRASS_TILE;
2474 if (IsSnowRailGround(ti->
tile)) {
2475 if (image != SPR_FLAT_GRASS_TILE) {
2478 image = SPR_FLAT_SNOW_DESERT_TILE;
2484 if (rti->UsesOverlay()) {
2555 void DrawTrainDepotSprite(
int x,
int y,
int dir,
RailType railtype)
2562 if (image != SPR_FLAT_GRASS_TILE) image += offset;
2567 if (rti->UsesOverlay()) {
2577 if (depot_sprite != 0) offset = depot_sprite - SPR_RAIL_DEPOT_SE_1;
2582 static int GetSlopePixelZ_Track(
TileIndex tile, uint x, uint y)
2601 static void TileLoop_Track(
TileIndex tile)
2713 default: NOT_REACHED();
2718 if (old_ground != new_ground) {
2719 SetRailGroundType(tile, new_ground);
2731 default: NOT_REACHED();
2746 default: NOT_REACHED();
2787 static bool ClickTile_Track(
TileIndex tile)
2803 td->
str = STR_LAI_RAIL_DESCRIPTION_TRACK;
2807 static const StringID signal_type[6][6] = {
2809 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_SIGNALS,
2810 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PRESIGNALS,
2811 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_EXITSIGNALS,
2812 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_COMBOSIGNALS,
2813 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PBSSIGNALS,
2814 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_NOENTRYSIGNALS
2817 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PRESIGNALS,
2818 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRESIGNALS,
2819 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_EXITSIGNALS,
2820 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_COMBOSIGNALS,
2821 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_PBSSIGNALS,
2822 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_NOENTRYSIGNALS
2825 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_EXITSIGNALS,
2826 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_EXITSIGNALS,
2827 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXITSIGNALS,
2828 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_COMBOSIGNALS,
2829 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_PBSSIGNALS,
2830 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_NOENTRYSIGNALS
2833 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_COMBOSIGNALS,
2834 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_COMBOSIGNALS,
2835 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_COMBOSIGNALS,
2836 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBOSIGNALS,
2837 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_PBSSIGNALS,
2838 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_NOENTRYSIGNALS
2841 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PBSSIGNALS,
2842 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_PBSSIGNALS,
2843 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_PBSSIGNALS,
2844 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_PBSSIGNALS,
2845 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PBSSIGNALS,
2846 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PBS_NOENTRYSIGNALS
2849 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_NOENTRYSIGNALS,
2850 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_NOENTRYSIGNALS,
2851 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_NOENTRYSIGNALS,
2852 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_NOENTRYSIGNALS,
2853 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PBS_NOENTRYSIGNALS,
2854 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NOENTRYSIGNALS
2861 primary_signal = GetSignalType(tile,
TRACK_UPPER);
2864 secondary_signal = primary_signal = GetSignalType(tile,
TRACK_LOWER);
2867 td->
str = signal_type[secondary_signal][primary_signal];
2872 td->
str = STR_LAI_RAIL_DESCRIPTION_TRAIN_DEPOT;
2894 uint num_pieces = 1;
2901 Company::Get(old_owner)->infrastructure.rail[rt] -= num_pieces;
2902 Company::Get(new_owner)->infrastructure.rail[rt] += num_pieces;
2906 Company::Get(old_owner)->infrastructure.signal -= num_sigs;
2907 Company::Get(new_owner)->infrastructure.signal += num_sigs;
2916 static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 };
2917 static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
2918 static const int8 _deltacoord_leaveoffset[8] = {
2936 case DIAGDIR_NE:
return ((
int)(v->
x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) - (length + 1)));
2937 case DIAGDIR_SE:
return -((int)(v->
y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4) + (length + 1)));
2938 case DIAGDIR_SW:
return -((int)(v->
x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) + (length + 1)));
2939 case DIAGDIR_NW:
return ((
int)(v->
y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4) - (length + 1)));
2940 default: NOT_REACHED();
2956 byte fract_coord = (x & 0xF) + ((y & 0xF) << 4);
2968 byte fract_coord_leave =
2969 ((_fractcoords_enter[dir] & 0x0F) +
2970 (length + 1) * _deltacoord_leaveoffset[dir]) +
2971 (((_fractcoords_enter[dir] >> 4) +
2972 ((length + 1) * _deltacoord_leaveoffset[dir + 4])) << 4);
2974 if (fract_coord_leave == fract_coord) {
2976 if ((v = v->
Next()) !=
nullptr) {
2981 }
else if (_fractcoords_enter[dir] == fract_coord) {
3020 switch (rail_bits) {
3028 if (z_old != z_new || tileh_old != tileh_new)
return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
3035 if (z_old != z_new)
return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
3039 if (tileh_old != tileh_new) {
3072 switch (rail_bits) {
3077 default:
return autoslope_result;
3086 for (
Corner corner = (
Corner)0; corner < CORNER_END; corner = (
Corner)(corner + 1)) {
3087 if (allowed_corner == corner)
continue;
3106 GetSlopePixelZ_Track,
3110 GetTileTrackStatus_Track,
3114 ChangeTileOwner_Track,
3117 GetFoundation_Track,
3118 TerraformTile_Track,
bool disable_elrails
when true, the elrails are disabled
Functions related to OTTD's strings.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Owner
Enum for all companies/owners.
Piece of rail on slope with north-west raised.
don't allow building on structures
static bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
VehicleSettings vehicle
options for vehicles
static bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Functions/types related to NewGRF debugging.
void InitRailTypes()
Resolve sprites of custom rail types.
Grass with a fence at the northern side.
CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
Tests if a vehicle interacts with the specified track bits.
the north corner of the tile is raised
uint32 PaletteID
The number of the palette.
Corner
Enumeration of tile corners.
CommandCost CmdRemoveSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove signals on a stretch of track.
static bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
Vehicle is stopped by the player.
void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
Add track to signal update buffer.
struct RailtypeInfo::@36 base_sprites
Struct containing the main sprites.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
int CalcNextVehicleOffset() const
Calculate the offset from this vehicle's center to the following center taking the vehicle lengths in...
static void DrawTrackFence(const TileInfo *ti, SpriteID base_image, uint num_sprites, RailFenceOffset rfo)
Draw a track fence.
NewGRF handling of rail types.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
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.
Direction direction
facing
static uint GetSaveSlopeZ(uint x, uint y, Track track)
Get surface height in point (x,y) On tiles with halftile foundations move (x,y) to a safe point wrt...
Track upper, direction west.
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Tile information, used while rendering the tile.
south and east corner are raised
Flag for an invalid track.
Slope NW, Track Y, Fence NE.
static Money RailConvertCost(RailType from, RailType to)
Calculates the cost of rail conversion.
SpriteID single_sloped
single piece of rail for slopes
Grass with a fence at the NE and SW edges.
static const TrackBits _valid_tracks_without_foundation[15]
Valid TrackBits on a specific (non-steep)-slope without foundation.
the west corner of the tile is raised
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track()
byte landscape
the landscape we're currently in
SignalType
Type of signal, i.e.
"Arrow" to the south-west
SpriteID auto_rail
button for the autorail construction
company buildings - depots, stations, HQ, ...
Track along the x-axis (north-east to south-west)
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
Slope FLAT, Track Y, Fence NE.
static const RailtypeInfo _original_railtypes[]
Global Railtype definition.
void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
Mark bridge tiles dirty.
Track in the lower corner of the tile (south)
byte _display_opt
What do we want to draw/do?
static FenceOffset _fence_offsets[]
Offsets for drawing fences.
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
CommandCost CmdBuildSignalTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build signals on a stretch of track.
static Titem * Get(size_t index)
Returns Titem with given index.
static Corner GetHalftileFoundationCorner(Foundation f)
Returns the halftile corner of a halftile-foundation.
Functions related to dates.
SpriteID build_y_rail
button for building single rail in Y direction
static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int x, int y)
Tile callback routine when vehicle enters tile.
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
CommandCost CmdBuildSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build signals, alternate between double/single, signal/semaphore, pre/exit/combo-signals, and what-else not.
Piece of rail in southern corner.
TileType
The different types of tiles.
static void DrawTrackFence_SE(const TileInfo *ti, SpriteID base_image, uint num_sprites)
Draw fence at SE border matching the tile slope.
Base for the train class.
static bool HasSignalOnTrack(TileIndex tile, Track track)
Checks for the presence of signals (either way) on the given track on the given rail tile...
RailTypeFlags flags
Bit mask of rail type flags.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Offsets for drawing fences.
static void MakeShore(TileIndex t)
Helper function to make a coast tile.
Trackdir
Enumeration for tracks and directions.
north and south corner are raised
static TrackBits GetCrossingRailBits(TileIndex tile)
Get the rail track bits of a level crossing.
uint16 cur_speed
current speed
A tile with road (or tram tracks)
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Ballast for junction 'pointing' NE.
int y_offs
Bounding box Y offset.
Depot view; Window numbers:
Slope tileh
Slope of the tile.
bool FloodHalftile(TileIndex t)
Called from water_cmd if a non-flat rail-tile gets flooded and should be converted to shore...
Full road along the x-axis (south-west + north-east)
Flag for invalid railtype.
static const TrackBits _valid_tracks_on_leveled_foundation[15]
Valid TrackBits on a specific (non-steep)-slope with leveled foundation.
Ballast for junction 'pointing' NW.
SignalState
These are states in which a signal can be.
CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a single piece of rail.
bool ValParamRailtype(const RailType rail)
Validate functions for rail building.
Grass with a fence at the eastern side.
Piece of rail on slope with north-east raised.
static bool IsOnewaySignal(TileIndex t, Track track)
One-way signals can't be passed the 'wrong' way.
static Foundation HalftileFoundation(Corner corner)
Returns the halftile foundation for single horizontal/vertical track.
static bool IsValidCorner(Corner corner)
Rangecheck for Corner enumeration.
Functions related to vehicles.
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir. ...
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
Piece of rail in western corner.
SpriteID single_e
single piece of rail in the eastern corner
static uint TileX(TileIndex tile)
Get the X component of a tile.
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it...
PathfinderSettings pf
settings for all pathfinders
Build vehicle; Window numbers:
CommandCost CmdRemoveRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build rail on a stretch of track.
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Base for all depots (except hangars)
Tile description for the 'land area information' tool.
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
RailTypeLabelList alternate_labels
Rail type labels this type provides in addition to the main label.
Tindex index
Index of this pool item.
the east corner of the tile is raised
flag for invalid roadtype
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
T * First() const
Get the first vehicle in the chain.
Also draw details of track and roads.
Slope FLAT, Track LOWER, Fence N.
Helper functions to extract data from command parameters.
void ResetRailTypes()
Reset all rail type information to its default values.
struct RailtypeInfo::@38 cursor
Cursors associated with the rail type.
bool forbid_90_deg
forbid trains to make 90 deg turns
Grass with a fence at the SW edge.
static Track DiagDirToDiagTrack(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track incidating with that diagdir.
static Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
static Track GetRailStationTrack(TileIndex t)
Get the rail track of a rail station tile.
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel ...
Contains objects such as transmitters and owned land.
static void DrawTrackFence_NW(const TileInfo *ti, SpriteID base_image, uint num_sprites)
Draw fence at NW border matching the tile slope.
Flag for an invalid DiagDirection.
static void SetHasSignals(TileIndex tile, bool signals)
Add/remove the 'has signal' bit from the RailTileType.
south and west corner are raised
static void SetTrackBits(TileIndex t, TrackBits b)
Sets the track bits of the given tile.
Slope FLAT, Track LEFT, Fence E.
static void DrawTrackDetails(const TileInfo *ti, const RailtypeInfo *rti)
Draw track fences.
Common return value for all commands.
static bool HasExactlyOneBit(T value)
Test whether value has exactly 1 bit set.
CursorID autorail
Cursor for autorail tool.
static Slope SlopeWithOneCornerRaised(Corner corner)
Returns the slope with a specific corner raised.
RailType AllocateRailType(RailTypeLabel label)
Allocate a new rail type label.
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
"Arrow" to the north-east
RoadType
The different roadtypes we support.
static bool RailNoLevelCrossings(RailType rt)
Test if a RailType disallows build of level crossings.
static uint GetSignalStates(TileIndex tile)
Set the states of the signals (Along/AgainstTrackDir)
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
SpriteID track_y
single piece of rail in Y direction, with ground
static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, int z_old, Slope tileh_old, int z_new, Slope tileh_new, TrackBits rail_bits)
Tests if autoslope is allowed.
uint16 rail_speed
Speed limit of rail (bridges and track)
static const uint TILE_SIZE
Tile size in world coordinates.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Owner owner[4]
Name of the owner(s)
static Corner GetHighestSlopeCorner(Slope s)
Returns the highest corner of a slope (one corner raised or a steep slope).
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
CursorID rail_ew
Cursor for building rail in E-W direction.
Grass with a fence at the NW and SE edges.
static TrackBits CornerToTrackBits(Corner corner)
Returns a single horizontal/vertical trackbit that is in a specific tile corner.
void MakeError(StringID message)
Makes this CommandCost behave like an error command.
static bool IsObjectType(TileIndex t, ObjectType type)
Check whether the object on a tile is of a specific type.
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
north and east corner are raised
This struct contains all the info that is needed to draw and construct tracks.
static bool HasRoadWorks(TileIndex t)
Check if a tile has road works.
Date build_date
Date of construction.
Class to backup a specific variable and restore it later.
static byte SignalOnTrack(Track track)
Maps a Track to the bits that store the status of the two signals that can be present on the given tr...
company bankrupts, skip money check, skip vehicle on tile check in some cases
Functions related to (drawing on) viewports.
Normal rail tile with signals.
SpriteID signals[SIGTYPE_END][2][2]
signal GUI sprites (type, variant, state)
static bool HasStationRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
static Foundation SpecialRailFoundation(Corner corner)
Returns the special rail foundation for single horizontal/vertical track.
int16 y
The y value of the coordinate.
RailFenceOffset
Offsets from base sprite for fence sprites.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
static Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
static uint GetPresentSignals(TileIndex tile)
Get whether the given signals are present (Along/AgainstTrackDir)
Track in the right corner of the tile (east)
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
SpriteID single_y
single piece of rail in Y direction, without ground
build a single rail track
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Snow only on higher part of slope (steep or one corner raised)
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
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.
The tile does not flood neighboured tiles.
static Slope ComplementSlope(Slope s)
Return the complement of a slope.
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
uint x
X position of the tile in unit coordinates.
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build many signals by dragging; AutoSignals.
None of the directions are disallowed.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Querying information about the upper part of a tile with halftile foundation.
Foundation
Enumeration for Foundations.
SpriteID ground
ground sprite for a 3-way switch
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
All the railtype-specific information is stored here.
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Iterator to iterate over a diagonal area of the map.
TileIndex tile
Tile index.
static uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
The tile is leveled up to a flat slope.
byte train_signal_side
show signals on left / driving / right side
Level north halftile non-continuously.
static bool IsValidTrack(Track track)
Checks if a Track is valid.
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
Header file for things common for tunnels and bridges.
Ground palette sprite of a tile, together with its sprite layout.
#define FIND_FIRST_BIT(x)
Returns the first non-zero bit in a 6-bit value (from right).
Corner height_ref
Corner to use height offset from.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
Returns the behaviour of a tile during flooding.
byte road_side
the side of the road vehicles drive on
Images for overlaying track.
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
Slope SE, Track Y, Fence SW.
Entry point for OpenTTD to YAPF's cache.
CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Convert one rail type to the other.
StringID GetErrorMessage() const
Returns the error message of a command.
bool IsType(OrderType type) const
Check whether this order is of the given type.
Track right, direction north.
Grass with a fence at the NW edge.
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore)
Finds vehicle in tunnel / bridge.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Slope FLAT, Track UPPER, Fence S.
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DoCommandFlag
List of flags for a command.
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
T * Next() const
Get next vehicle in the chain.
Piece of rail on slope with south-west raised.
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
ClientSettings _settings_client
The current settings for this game.
Standard non-electric rails.
Piece of rail in X direction.
bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg)
Determine whether a certain track on a tile is a safe position to end a path.
static const uint32 VALID_LEVEL_CROSSING_SLOPES
Constant bitset with safe slopes for building a level crossing.
bool Succeeded() const
Did this command succeed?
Track left, direction south.
Definition of base types and functions in a cross-platform compatible way.
CommandCost CmdRemoveSingleSignal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove signals.
Track y-axis, direction south-east.
Represents a diagonal tile area.
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build or remove a stretch of railroad tracks.
Map accessors for object tiles.
static const uint BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).
A number of safeguards to prevent using unsafe methods.
SpriteID build_ns_rail
button for building single rail in N-S direction
int16 x
The x value of the coordinate.
Flag for an invalid trackdir.
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
RailTypes introduces_railtypes
Bitmask of which other railtypes are introduced when this railtype is introduced. ...
The vehicle cannot enter the tile.
static Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
Removes first Trackdir from TrackdirBits and returns it.
uint y
Y position of the tile in unit coordinates.
Foundation GetRailFoundation(Slope tileh, TrackBits bits)
Checks if a track combination is valid on a specific slope and returns the needed foundation...
RoadBits
Enumeration for the road parts on a tile.
byte sorting_order
The sorting order of this railtype for the toolbar dropdown.
void ShowDepotWindow(TileIndex tile, VehicleType type)
Opens a depot window.
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
Slope SW, Track X, Fence NW.
The tile has an along Y-axis inclined foundation.
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
Grass with a fence at the NE edge.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Train * GetTrainForReservation(TileIndex tile, Track track)
Find the train which has reserved a specific path.
Bit number for using non-combined junctions.
static bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Represents the covered area of e.g.
GUI Functions related to companies.
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
TrackBits
Bitfield corresponding to Track.
static void SetSignalStates(TileIndex tile, uint state)
Set the states of the signals (Along/AgainstTrackDir)
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
SpriteID single_w
single piece of rail in the western corner
TileIndex tile
Current tile index.
SpriteID GetCustomSignalSprite(const RailtypeInfo *rti, TileIndex tile, SignalType type, SignalVariant var, SignalState state, bool gui)
Get the sprite to draw for a given signal.
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.
static const ObjectType OBJECT_OWNED_LAND
Owned land 'flag'.
CursorID rail_nwse
Cursor for building rail in Y direction.
static void SetPresentSignals(TileIndex tile, uint signals)
Set whether the given signals are present (Along/AgainstTrackDir)
Grass with a fence and shore or water on the free halftile.
Base class for tile iterators.
static Slope SlopeWithThreeCornersRaised(Corner corner)
Returns the slope with all except one corner raised.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Sprites to use and how to display them for train depot tiles.
Crossing of X and Y rail, with ballast.
SpriteID single_x
single piece of rail in X direction, without ground
SpriteID convert_rail
button for converting rail
static Track GetRailDepotTrack(TileIndex t)
Returns the track of a depot, ignoring direction.
static Money RailClearCost(RailType railtype)
Returns the 'cost' of clearing the specified railtype.
#define lengthof(x)
Return the length of an fixed size array.
bit mask containing all 'simple' slopes
static void DrawTrackFence_NE(const TileInfo *ti, SpriteID base_image, uint num_sprites)
Draw fence at NE border matching the tile slope.
Track left, direction north.
static TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
Maps a trackdir to the trackdirs that can be reached from it (ie, when entering the next tile...
static T min(const T a, const T b)
Returns the minimum of two values.
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
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.
StringID railtype
Type of rail on the tile.
RailTypeLabel label
Unique 32 bit rail type identifier.
The tile has a steep slope. The lowest corner is raised by a foundation and the upper halftile is lev...
CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a train depot.
RailTypes
The different railtypes we support, but then a bitmask of them.
Piece of rail in Y direction.
static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
Tests if a track can be build on a tile.
Functions related to autoslope.
Functions related to sound.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
static TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
bool build_on_slopes
allow building on slopes
bool Failed() const
Did this command fail?
Piece of rail on slope with south-east raised.
Slope FLAT, Track X, Fence SE.
SpriteID single_n
single piece of rail in the northern corner
void UpdateLevelCrossing(TileIndex tile, bool sound=true)
Sets correct crossing state.
Piece of rail in eastern corner.
east and west corner are raised
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.
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
static Slope RemoveHalftileSlope(Slope s)
Removes a halftile slope from a slope.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
SpriteID single_s
single piece of rail in the southern corner
Piece of rail in northern corner.
static bool HasSignals(TileIndex t)
Checks if a rail tile has signals.
Slope NE, Track X, Fence NW.
SpriteID build_depot
button for building depots
'Train' is either a loco or a wagon.
CursorID depot
Cursor for building a depot.
static Vehicle * EnsureNoShipProc(Vehicle *v, void *data)
Test-procedure for HasVehicleOnPos to check for a ship.
CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Remove a single piece of track.
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
static RoadBits GetCrossingRoadBits(TileIndex tile)
Get the road bits of a level crossing.
A pair-construct of a TileIndexDiff.
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Bit number for hiding from selection.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
uint32 rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
CursorID convert
Cursor for converting track.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
execute the given command
static bool CompareRailTypes(const RailType &first, const RailType &second)
Compare railtypes based on their sorting order.
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
The tile/execution is done by "water".
static CommandCost EnsureNoTrainOnTrack(TileIndex tile, Track track)
Tests if a vehicle interacts with the specified track.
static int GetSlopePixelZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
static byte SignalAgainstTrackdir(Trackdir trackdir)
Maps a trackdir to the bit that stores its status in the map arrays, in the direction against the tra...
PalSpriteID ground
Palette and sprite for the ground.
static T KillFirstBit(T value)
Clear the first bit in an integer.
static uint MapSize()
Get the size of the map.
static Owner GetRoadOwner(TileIndex t, RoadTramType rtt)
Get the owner of a specific road type.
static bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
Find out if the slope of the tile is suitable to build a depot of given direction.
Track along the y-axis (north-west to south-east)
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
RailType
Enumeration for all possible railtypes.
static bool IsSlopeWithThreeCornersRaised(Slope s)
Tests if a specific slope has exactly three corners raised.
Track lower, direction east.
Trackdir GetVehicleTrackdir() const
Get the tracks of the train vehicle.
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
bool IsStationTileBlocked(TileIndex tile)
Check whether a rail station tile is NOT traversable.
GUISettings gui
settings related to the GUI
Tunnel entry/exit and bridge heads.
static Track RemoveFirstTrack(TrackBits *tracks)
Removes first Track from TrackBits and returns it.
static bool IsRailDepotTile(TileIndex t)
Is this tile rail tile and a rail depot?
static Vehicle * UpdateTrainPowerProc(Vehicle *v, void *data)
Update power of train under which is the railtype being converted.
static bool HasTunnelBridgeReservation(TileIndex t)
Get the reservation state of the rail tunnel/bridge.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
CursorID rail_swne
Cursor for building rail in X direction.
Slope FLAT, Track RIGHT, Fence W.
Set of callback functions for performing tile operations of a given tile type.
uint32 TileIndex
The index/ID of a Tile.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
static byte SignalAlongTrackdir(Trackdir trackdir)
Maps a trackdir to the bit that stores its status in the map arrays, in the direction along with the ...
static const PaletteID PALETTE_TO_BARE_LAND
sets colour to bare land stuff for rail, road and crossings
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...
int x_offs
Bounding box X offset.
static bool RoadNoLevelCrossing(RoadType roadtype)
Test if road disallows level crossings.
static bool IsLevelCrossingTile(TileIndex t)
Return whether a tile is a level crossing tile.
north and west corner are raised
static Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Track
These are used to specify a single track.
Cursor and toolbar icon images.
static void DrawTrackFence_SW(const TileInfo *ti, SpriteID base_image, uint num_sprites)
Draw fence at SW border matching the tile slope.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Bit sets of the above specified bits.
static Trackdir TrackToTrackdir(Track track)
Returns a Trackdir for the given Track.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
int TicksToLeaveDepot(const Train *v)
Compute number of ticks when next wagon will leave a depot.
Old-fashioned semaphore signal.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
The tile has no foundation, the slope remains unchanged.
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
void FreeTrainTrackReservation(const Train *v)
Free the reserved path in front of a vehicle.
The tile has an along X-axis inclined foundation.
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Used inside "rail_cmd.cpp" to indicate invalid slope/track combination.
int x_size
Bounding box X size.
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Slope
Enumeration for the slope-type.
VehicleType type
Type of vehicle.
int y_size
Bounding box Y size.
SpriteID build_tunnel
button for building a tunnel
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
Ballast for junction 'pointing' SE.
"Arrow" to the south-east
static bool HasTrack(TileIndex tile, Track track)
Returns whether the given track is present on the given tile.
Normal rail tile without signals.
Ballast for junction 'pointing' SW.
bool show_track_reservation
highlight reserved tracks.
Used to only draw a part of the sprite.
Main group of ground images.
Slope SE, Track Y, Fence NE.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
SignalOffsets
Enum holding the signal offset in the sprite sheet according to the side it is representing.
static bool IsCompatibleRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType can drive on a tile with a given RailType.
RailTypes powered_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype generates power ...
Track x-axis, direction south-west.
uint GetRailtypeSpriteOffset() const
Offset between the current railtype and normal rail.
Track y-axis, direction north-west.
static uint CountBits(T value)
Counts the number of set bits in a variable.
Functions related to commands.
Coordinates of a point in 2D.
remove a single rail track
struct RailtypeInfo::@37 gui_sprites
struct containing the sprites for the rail GUI.
Iterator to iterate over a tile area (rectangle) of the map.
CompanyID _current_company
Company currently doing an action.
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.
byte GetSnowLine()
Get the current snow line, either variable or static.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static bool HasRailCatenaryDrawn(RailType rt)
Test if we should draw rail catenary.
Date build_date
Date of construction of tile contents.
uint8 train_acceleration_model
realistic acceleration for trains
header file for electrified rail specific functions
Slope SW, Track X, Fence SE.
The tile has a steep slope. The lowest corner is raised by a foundation to allow building railroad on...
RailGroundType
The ground 'under' the rail.
static uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
ConstructionSettings construction
construction of things in-game
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Functions that have tunnels and bridges in common.
static DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
Gets the disallowed directions.
static bool IsNormalRoad(TileIndex t)
Return whether a tile is a normal road.
int GetSlopeZInCorner(Slope tileh, Corner corner)
Determine the Z height of a corner relative to TileZ.
static bool AutoslopeCheckForEntranceEdge(TileIndex tile, int z_new, Slope tileh_new, DiagDirection entrance)
Autoslope check for tiles with an entrance on an edge.
StringID name
Name of this rail type.
Track lower, direction west.
Grass with a fence at the SE edge.
don't allow overlap of rails (used in buildrail)
StringID str
Description of the tile.
SpriteID tunnel
tunnel sprites base
CursorID rail_ns
Cursor for building rail in N-S direction.
Slope NE, Track X, Fence SE.
static bool HasReservedTracks(TileIndex tile, TrackBits tracks)
Check whether some of tracks is reserved on a tile.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static void DrawTrackBits(TileInfo *ti, TrackBits track)
Draw ground sprite and track bits.
DiagDirection
Enumeration for diagonal directions.
void Restore()
Restore the variable.
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Track upper, direction east.
Northeast, upper right on your monitor.
SpriteID track_ns
two pieces of rail in North and South corner (East-West direction)
GameCreationSettings game_creation
settings used during the creation of a game (map)
static bool IsPlainRail(TileIndex t)
Returns whether this is plain rails, with or without signals.
Full road along the y-axis (north-west + south-east)
static Track GetCrossingRailTrack(TileIndex tile)
Get the rail track of a level crossing.
Ballast for full junction.
Slope FLAT, Track X, Fence NW.
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
std::vector< Train * > TrainList
Helper type for lists/vectors of trains.
static bool HasDepotReservation(TileIndex t)
Get the reservation state of the depot.
static CommandCost CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
Check that the new track bits may be built.
Functions related to water (management)
static bool IsNonContinuousFoundation(Foundation f)
Tests if a foundation is a non-continuous foundation, i.e.
Track x-axis, direction north-east.
SpriteID build_x_rail
button for building single rail in X direction
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Grass with a fence at the southern side.
static TileIndex AddTileIndexDiffCWrap(TileIndex tile, TileIndexDiffC diff)
Add a TileIndexDiffC to a TileIndex and returns the new one.
static void SetTrackReservation(TileIndex t, TrackBits b)
Sets the reserved track bits of the tile.
SpriteID sprite
The 'real' sprite.
Slope NW, Track Y, Fence SW.
Track in the left corner of the tile (west)
SignalVariant
Variant of the signal, i.e.
static void MakeRoadNormal(TileIndex t, RoadBits bits, RoadType road_rt, RoadType tram_rt, TownID town, Owner road, Owner tram)
Make a normal road tile.
CommandCost CmdBuildRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build rail on a stretch of track.
Date _date
Current date in days (day counter)
bool TryPathReserve(Train *v, bool mark_as_stuck=false, bool first_tile_okay=false)
Try to reserve a path to a safe position.
static Direction ReverseDir(Direction d)
Return the reverse of a direction.
static void SetDockingTile(TileIndex t, bool b)
Set the docking tile state of a tile.
SpriteID build_ew_rail
button for building single rail in E-W direction
the south corner of the tile is raised
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
static bool IsSpecialRailFoundation(Foundation f)
Tests if a foundation is a special rail foundation for single horizontal/vertical track...
Valid changes while vehicle is driving, and possibly changing tracks.
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
void DrawBridgeMiddle(const TileInfo *ti)
Draw the middle bits of a bridge.
Class for backupping variables and making sure they are restored later.
"Arrow" to the north-west
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
static Corner OppositeCorner(Corner corner)
Returns the opposite corner.
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Order current_order
The current order (+ status, like: loading)
static bool IsBridge(TileIndex t)
Checks if this is a bridge, instead of a tunnel.
static Direction DiagDirToDir(DiagDirection dir)
Convert a DiagDirection to a Direction.
Grass with a fence at the western side.
Track right, direction south.
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-...
Track in the upper corner of the tile (north)
Slope FLAT, Track Y, Fence SW.
SpriteID snow_offset
sprite number difference between a piece of track on a snowy ground and the corresponding one on norm...
static void SetRailType(TileIndex t, RailType r)
Sets the rail type of the given tile.
std::vector< RailTypeLabel > RailTypeLabelList
List of rail type labels.
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.