37 #include "table/strings.h" 48 uint8 _sorted_railtypes_size;
74 {0,0,0,0,0,0,0,0,0,0,0,0},
78 0,
RAILTYPES_NONE,
RAILTYPES_NONE, 0, 0, 0,
RTFB_NONE, 0, 0, 0, 0, 0,
81 for (; i <
lengthof(_railtypes); i++) _railtypes[i] = empty_railtype;
89 if (cursors_base != 0) {
109 const SpriteID _signal_lookup[2][SIGTYPE_END] = {
110 {SPR_IMG_SIGNAL_ELECTRIC_NORM, SPR_IMG_SIGNAL_ELECTRIC_ENTRY, SPR_IMG_SIGNAL_ELECTRIC_EXIT,
111 SPR_IMG_SIGNAL_ELECTRIC_COMBO, SPR_IMG_SIGNAL_ELECTRIC_PBS, SPR_IMG_SIGNAL_ELECTRIC_PBS_OWAY},
113 {SPR_IMG_SIGNAL_SEMAPHORE_NORM, SPR_IMG_SIGNAL_SEMAPHORE_ENTRY, SPR_IMG_SIGNAL_SEMAPHORE_EXIT,
114 SPR_IMG_SIGNAL_SEMAPHORE_COMBO, SPR_IMG_SIGNAL_SEMAPHORE_PBS, SPR_IMG_SIGNAL_SEMAPHORE_PBS_OWAY},
121 rti->
gui_sprites.
signals[type][var][0] = (red != 0) ? red + SIGNAL_TO_SOUTH : _signal_lookup[var][type];
122 rti->
gui_sprites.
signals[type][var][1] = (green != 0) ? green + SIGNAL_TO_SOUTH : _signal_lookup[var][type] + 1;
145 ResolveRailTypeGUISprites(rti);
149 _sorted_railtypes_size = 0;
151 if (_railtypes[rt].label != 0 && !
HasBit(_railtypes_hidden_mask, rt)) {
152 _sorted_railtypes[_sorted_railtypes_size++] = rt;
166 if (rti->
label == 0) {
193 static const byte _track_sloped_sprites[14] = {
263 if (current == future) {
273 return_cmd_error((flags & DC_NO_RAIL_OVERLAP) ? STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION : STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
432 static inline bool ValParamTrackOrientation(
Track track)
448 RailType railtype = Extract<RailType, 0, 6>(p1);
449 Track track = Extract<Track, 0, 3>(p2);
460 if (ret.
Failed())
return ret;
468 if (ret.
Failed())
return ret;
471 if (ret.
Failed())
return ret;
480 if (ret.
Failed())
return ret;
509 if (ret.
Failed())
return ret;
529 if (ret.
Failed())
return ret;
532 uint num_new_road_pieces = 2 -
CountBits(road);
538 cost.AddCost((num_new_road_pieces + num_new_tram_pieces) * _price[PR_BUILD_ROAD]);
569 if (ret.
Failed())
return ret;
573 if (ret.
Failed())
return ret;
577 cost.AddCost(-_price[PR_CLEAR_WATER]);
578 cost.AddCost(_price[PR_CLEAR_ROUGH]);
612 Track track = Extract<Track, 0, 3>(p2);
614 bool crossing =
false;
616 if (!ValParamTrackOrientation(track))
return CMD_ERROR;
633 if (ret.
Failed())
return ret;
638 if (ret.
Failed())
return ret;
664 if (ret.
Failed())
return ret;
668 if (ret.
Failed())
return ret;
671 if ((present & trackbit) == 0)
return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
757 bool flooded =
false;
766 TrackBits to_remove = lower_track & rail_bits;
767 if (to_remove != 0) {
771 if (!flooded)
return flooded;
772 rail_bits = rail_bits & ~to_remove;
773 if (rail_bits == 0) {
799 { -1, 0 }, { 0, 1 }, { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, 1 },
802 { 1, 0 }, { 0, -1 }, { 0, -1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
810 int x =
TileX(start);
811 int y =
TileY(start);
822 int trdx = _trackdelta[*trackdir].
x;
823 int trdy = _trackdelta[*trackdir].
y;
826 trdx += _trackdelta[*trackdir ^ 1].
x;
827 trdy += _trackdelta[*trackdir ^ 1].
y;
831 while ((trdx <= 0 && dx > 0) ||
832 (trdx >= 0 && dx < 0) ||
833 (trdy <= 0 && dy > 0) ||
834 (trdy >= 0 && dy < 0)) {
835 if (!
HasBit(*trackdir, 3)) {
847 trdx = _trackdelta[*trackdir].
x;
848 trdy = _trackdelta[*trackdir].
y;
871 Track track = Extract<Track, 6, 3>(p2);
872 bool remove =
HasBit(p2, 9);
873 RailType railtype = Extract<RailType, 0, 6>(p2);
880 CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
881 if (ret.
Failed())
return ret;
883 bool had_success =
false;
890 if (last_error.
GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !
remove) {
891 if (
HasBit(p2, 10))
return last_error;
896 if (last_error.
GetErrorMessage() == STR_ERROR_OWNED_BY &&
remove)
break;
902 if (tile == end_tile)
break;
910 if (had_success)
return total_cost;
967 RailType railtype = Extract<RailType, 0, 6>(p1);
987 cost.AddCost(_price[PR_BUILD_FOUNDATION]);
991 if (cost.Failed())
return cost;
1012 cost.AddCost(_price[PR_BUILD_DEPOT_TRAIN]);
1040 Track track = Extract<Track, 0, 3>(p1);
1041 bool ctrl_pressed =
HasBit(p1, 3);
1043 SignalType sigtype = Extract<SignalType, 5, 3>(p1);
1044 bool convert_signal =
HasBit(p1, 8);
1045 SignalType cycle_start = Extract<SignalType, 9, 3>(p1);
1046 SignalType cycle_stop = Extract<SignalType, 12, 3>(p1);
1047 uint num_dir_cycle =
GB(p1, 15, 2);
1049 if (sigtype > SIGTYPE_LAST)
return CMD_ERROR;
1050 if (cycle_start > cycle_stop || cycle_stop > SIGTYPE_LAST)
return CMD_ERROR;
1061 if (ret.
Failed())
return ret;
1077 if (p2 != 0 && sigvar != GetSignalVariant(tile, track)) {
1081 }
else if (convert_signal) {
1083 if (ctrl_pressed || GetSignalVariant(tile, track) != sigvar) {
1112 SetSignalType(tile, track, sigtype);
1113 SetSignalVariant(tile, track, sigvar);
1123 SetSignalType(tile, track, sigtype);
1124 SetSignalVariant(tile, track, sigvar);
1125 while (num_dir_cycle-- > 0) CycleSignalSide(tile, track);
1127 if (convert_signal) {
1133 sigtype = GetSignalType(tile, track);
1136 SetSignalType(tile, track, sigtype);
1137 SetSignalVariant(tile, track, sigvar);
1143 }
else if (ctrl_pressed) {
1145 sigtype = (
SignalType)(GetSignalType(tile, track) + 1);
1147 if (sigtype < cycle_start || sigtype > cycle_stop) sigtype = cycle_start;
1149 SetSignalType(tile, track, sigtype);
1155 CycleSignalSide(tile, track);
1157 sigtype = GetSignalType(tile, track);
1164 SetSignalVariant(tile, track, sigvar);
1165 SetSignalType(tile, track, sigtype);
1172 if (IsPbsSignal(sigtype)) {
1192 static bool CheckSignalAutoFill(
TileIndex &tile,
Trackdir &trackdir,
int &signal_ctr,
bool remove)
1243 default:
return false;
1269 Track track = Extract<Track, 0, 3>(p2);
1270 bool mode =
HasBit(p2, 3);
1271 bool semaphores =
HasBit(p2, 4);
1272 bool remove =
HasBit(p2, 5);
1273 bool autofill =
HasBit(p2, 6);
1274 bool minimise_gaps =
HasBit(p2, 10);
1275 byte signal_density =
GB(p2, 24, 8);
1279 if (signal_density == 0 || signal_density > 20)
return CMD_ERROR;
1285 signal_density *= 2;
1288 CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
1289 if (ret.
Failed())
return ret;
1292 Trackdir start_trackdir = trackdir;
1298 if (sigtype > SIGTYPE_LAST)
return CMD_ERROR;
1304 assert(signals != 0);
1307 semaphores = GetSignalVariant(tile, track) !=
SIG_ELECTRIC;
1309 sigtype = GetSignalType(tile, track);
1316 byte signal_dir = 0;
1333 int last_used_ctr = INT_MIN;
1334 int last_suitable_ctr = 0;
1338 bool had_success =
false;
1341 if (
remove || minimise_gaps || signal_ctr % signal_density == 0) {
1344 SB(p1, 4, 1, semaphores);
1345 SB(p1, 5, 3, sigtype);
1346 if (!
remove && signal_ctr == 0)
SetBit(p1, 17);
1354 bool test_only = !
remove && minimise_gaps && signal_ctr < (last_used_ctr + signal_density);
1357 if (ret.Succeeded()) {
1359 last_suitable_ctr = signal_ctr;
1360 last_suitable_tile = tile;
1361 last_suitable_trackdir = trackdir;
1362 }
else if (!test_only && last_suitable_tile !=
INVALID_TILE) {
1378 if (ret.Succeeded()) {
1381 last_used_ctr = last_suitable_ctr;
1385 if (ret.GetErrorMessage() != STR_ERROR_THERE_IS_NO_RAILROAD_TRACK ||
1394 if (!CheckSignalAutoFill(tile, trackdir, signal_ctr,
remove))
break;
1397 if (tile == start_tile && trackdir == start_trackdir)
break;
1399 if (tile == end_tile)
break;
1413 return had_success ? total_cost : last_error;
1453 Track track = Extract<Track, 0, 3>(p1);
1465 if (ret.
Failed())
return ret;
1473 }
else if (IsPbsSignal(GetSignalType(tile, track))) {
1556 RailType totype = Extract<RailType, 0, 6>(p2);
1559 bool diagonal =
HasBit(p2, 6);
1568 bool found_convertible_track =
false;
1584 error.
MakeError(STR_ERROR_CROSSING_DISALLOWED);
1627 *vehicles_affected.
Append() = v;
1664 found_convertible_track =
true;
1669 if (flags & DC_EXEC) {
1676 found_convertible_track =
true;
1687 if (endtile < tile) {
1711 *vehicles_affected.
Append() = v;
1739 found_convertible_track =
true;
1750 found_convertible_track =
true;
1755 for (uint i = 0; i < vehicles_affected.
Length(); ++i) {
1762 for (
Train **v = affected_trains.
Begin(); v != affected_trains.
End(); v++) {
1768 return found_convertible_track ? cost :
error;
1775 if (ret.
Failed())
return ret;
1779 if (ret.
Failed())
return ret;
1795 delete Depot::GetByTile(tile);
1796 DoClearSquare(tile);
1832 if (ret.
Failed())
return ret;
1840 if (ret.
Failed())
return ret;
1843 if (flags &
DC_EXEC) DoClearSquare(tile);
1844 cost.
AddCost(_price[PR_CLEAR_WATER]);
1851 return RemoveTrainDepot(tile, flags);
1871 return GetSlopePixelZ(x, y);
1878 case 0: side =
false;
break;
1879 case 2: side =
true;
break;
1882 static const Point SignalPositions[2][12] = {
1885 { 8, 5}, {14, 1}, { 1, 14}, { 9, 11}, { 1, 0}, { 3, 10},
1887 {11, 4}, {14, 14}, {11, 3}, { 4, 13}, { 3, 4}, {11, 13}
1890 {14, 1}, {12, 10}, { 4, 6}, { 1, 14}, {10, 4}, { 0, 1},
1892 {14, 14}, { 5, 12}, {11, 13}, { 4, 3}, {13, 4}, { 3, 11}
1899 SignalType type = GetSignalType(tile, track);
1908 sprite += type * 16 + variant * 64 + image * 2 + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0);
1914 static uint32 _drawtile_track_palette;
1929 { CORNER_INVALID, 0, 1, 16, 1 },
1930 { CORNER_INVALID, 1, 0, 1, 16 },
1931 { CORNER_W, 8, 8, 1, 1 },
1932 { CORNER_N, 8, 8, 1, 1 },
1933 { CORNER_INVALID, 0, 1, 16, 1 },
1934 { CORNER_INVALID, 1, 0, 1, 16 },
1935 { CORNER_INVALID, 0, 1, 16, 1 },
1936 { CORNER_INVALID, 1, 0, 1, 16 },
1937 { CORNER_INVALID, 0, 15, 16, 1 },
1938 { CORNER_INVALID, 15, 0, 1, 16 },
1939 { CORNER_E, 8, 8, 1, 1 },
1940 { CORNER_S, 8, 8, 1, 1 },
1941 { CORNER_INVALID, 0, 15, 16, 1 },
1942 { CORNER_INVALID, 15, 0, 1, 16 },
1943 { CORNER_INVALID, 0, 15, 16, 1 },
1944 { CORNER_INVALID, 15, 0, 1, 16 },
1957 if (_fence_offsets[rfo].
height_ref != CORNER_INVALID) {
1961 ti->
x + _fence_offsets[rfo].
x_offs,
1962 ti->
y + _fence_offsets[rfo].
y_offs,
1963 _fence_offsets[rfo].
x_size,
1964 _fence_offsets[rfo].
y_size,
2017 uint num_sprites = 0;
2019 if (base_image == 0) {
2020 base_image = SPR_TRACK_FENCE_FLAT_X;
2024 assert(num_sprites > 0);
2026 switch (GetRailGroundType(ti->
tile)) {
2048 switch (track_corner) {
2053 default: NOT_REACHED();
2062 static const int INF = 1000;
2063 static const SubSprite _halftile_sub_sprite[4] = {
2064 { -INF , -INF , 32 - 33, INF },
2065 { -INF , 0 + 7, INF , INF },
2066 { -31 + 33, -INF , INF , INF },
2067 { -INF , -INF , INF , 30 - 23 }
2079 Corner halftile_corner = CORNER_INVALID;
2096 DrawShoreTile(ti->
tileh);
2107 default: image = SPR_FLAT_GRASS_TILE;
break;
2145 DrawTrackSprite(ground +
RTO_S, PAL_NONE, ti,
SLOPE_S);
break;
2147 DrawTrackSprite(ground +
RTO_W, PAL_NONE, ti,
SLOPE_W);
break;
2197 default: image = SPR_FLAT_GRASS_TILE;
break;
2202 DrawGroundSprite(image, PAL_NONE, &(_halftile_sub_sprite[halftile_corner]));
2208 default: NOT_REACHED();
2215 DrawTrackSprite(ground + offset, PAL_NONE, ti, fake_slope);
2217 DrawTrackSprite(overlay + offset,
PALETTE_CRASH, ti, fake_slope);
2231 if (rti->UsesOverlay()) {
2232 DrawTrackBitsOverlay(ti, track, rti);
2238 Corner halftile_corner = CORNER_INVALID;
2254 bool junction =
false;
2261 DrawShoreTile(ti->
tileh);
2264 image = SPR_FLAT_WATER_TILE;
2270 default: image = SPR_FLAT_GRASS_TILE;
break;
2291 (junction =
true,
false) ||
2304 DrawShoreTile(ti->
tileh);
2306 sub = &(_halftile_sub_sprite[track_corner]);
2365 static const byte _corner_to_track_sprite[] = {3, 1, 2, 0};
2373 #define MAYBE_DRAW_SIGNAL(x, y, z, t) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, rti, t, GetSingleSignalState(tile, x), y, z) 2378 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTH, 0,
TRACK_LEFT);
2379 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTH, 1,
TRACK_LEFT);
2382 MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_NORTH, 2,
TRACK_RIGHT);
2383 MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_SOUTH, 3,
TRACK_RIGHT);
2386 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_WEST, 4,
TRACK_UPPER);
2387 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_EAST, 5,
TRACK_UPPER);
2390 MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_WEST, 6,
TRACK_LOWER);
2391 MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_EAST, 7,
TRACK_LOWER);
2394 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHWEST, 8,
TRACK_X);
2395 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHEAST, 9,
TRACK_X);
2398 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHEAST, 10,
TRACK_Y);
2399 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHWEST, 11,
TRACK_Y);
2403 static void DrawTile_Track(
TileInfo *ti)
2435 if (rti->UsesOverlay()) {
2436 image = SPR_FLAT_GRASS_TILE;
2445 if (image != SPR_FLAT_GRASS_TILE) {
2448 image = SPR_FLAT_SNOW_DESERT_TILE;
2454 if (rti->UsesOverlay()) {
2525 void DrawTrainDepotSprite(
int x,
int y,
int dir,
RailType railtype)
2532 if (image != SPR_FLAT_GRASS_TILE) image += offset;
2537 if (rti->UsesOverlay()) {
2547 if (depot_sprite != 0) offset = depot_sprite - SPR_RAIL_DEPOT_SE_1;
2552 static int GetSlopePixelZ_Track(
TileIndex tile, uint x, uint y)
2571 static void TileLoop_Track(
TileIndex tile)
2683 default: NOT_REACHED();
2688 if (old_ground != new_ground) {
2689 SetRailGroundType(tile, new_ground);
2701 default: NOT_REACHED();
2716 default: NOT_REACHED();
2757 static bool ClickTile_Track(
TileIndex tile)
2773 td->
str = STR_LAI_RAIL_DESCRIPTION_TRACK;
2777 static const StringID signal_type[6][6] = {
2779 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_SIGNALS,
2780 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PRESIGNALS,
2781 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_EXITSIGNALS,
2782 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_COMBOSIGNALS,
2783 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PBSSIGNALS,
2784 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_NOENTRYSIGNALS
2787 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PRESIGNALS,
2788 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRESIGNALS,
2789 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_EXITSIGNALS,
2790 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_COMBOSIGNALS,
2791 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_PBSSIGNALS,
2792 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_NOENTRYSIGNALS
2795 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_EXITSIGNALS,
2796 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_EXITSIGNALS,
2797 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXITSIGNALS,
2798 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_COMBOSIGNALS,
2799 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_PBSSIGNALS,
2800 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_NOENTRYSIGNALS
2803 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_COMBOSIGNALS,
2804 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_COMBOSIGNALS,
2805 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_COMBOSIGNALS,
2806 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBOSIGNALS,
2807 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_PBSSIGNALS,
2808 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_NOENTRYSIGNALS
2811 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PBSSIGNALS,
2812 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_PBSSIGNALS,
2813 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_PBSSIGNALS,
2814 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_PBSSIGNALS,
2815 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PBSSIGNALS,
2816 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PBS_NOENTRYSIGNALS
2819 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_NOENTRYSIGNALS,
2820 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_NOENTRYSIGNALS,
2821 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_NOENTRYSIGNALS,
2822 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_NOENTRYSIGNALS,
2823 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PBS_NOENTRYSIGNALS,
2824 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NOENTRYSIGNALS
2831 primary_signal = GetSignalType(tile,
TRACK_UPPER);
2834 secondary_signal = primary_signal = GetSignalType(tile,
TRACK_LOWER);
2837 td->
str = signal_type[secondary_signal][primary_signal];
2842 td->
str = STR_LAI_RAIL_DESCRIPTION_TRAIN_DEPOT;
2864 uint num_pieces = 1;
2871 Company::Get(old_owner)->infrastructure.rail[rt] -= num_pieces;
2872 Company::Get(new_owner)->infrastructure.rail[rt] += num_pieces;
2876 Company::Get(old_owner)->infrastructure.signal -= num_sigs;
2877 Company::Get(new_owner)->infrastructure.signal += num_sigs;
2886 static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 };
2887 static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
2888 static const int8 _deltacoord_leaveoffset[8] = {
2906 case DIAGDIR_NE:
return ((
int)(v->
x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) - (length + 1)));
2907 case DIAGDIR_SE:
return -((int)(v->
y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4) + (length + 1)));
2908 case DIAGDIR_SW:
return -((int)(v->
x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) + (length + 1)));
2909 case DIAGDIR_NW:
return ((
int)(v->
y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4) - (length + 1)));
2910 default: NOT_REACHED();
2926 byte fract_coord = (x & 0xF) + ((y & 0xF) << 4);
2938 byte fract_coord_leave =
2939 ((_fractcoords_enter[dir] & 0x0F) +
2940 (length + 1) * _deltacoord_leaveoffset[dir]) +
2941 (((_fractcoords_enter[dir] >> 4) +
2942 ((length + 1) * _deltacoord_leaveoffset[dir + 4])) << 4);
2944 if (fract_coord_leave == fract_coord) {
2946 if ((v = v->
Next()) != NULL) {
2951 }
else if (_fractcoords_enter[dir] == fract_coord) {
2990 switch (rail_bits) {
2998 if (z_old != z_new || tileh_old != tileh_new)
return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
3005 if (z_old != z_new)
return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
3009 if (tileh_old != tileh_new) {
3042 switch (rail_bits) {
3047 default:
return autoslope_result;
3056 for (
Corner corner = (
Corner)0; corner < CORNER_END; corner = (
Corner)(corner + 1)) {
3057 if (allowed_corner == corner)
continue;
3076 GetSlopePixelZ_Track,
3080 GetTileTrackStatus_Track,
3084 ChangeTileOwner_Track,
3087 GetFoundation_Track,
3088 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.
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.
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.
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 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...
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
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.
SpriteID auto_rail
button for the autorail construction
DirectionByte direction
facing
company buildings - depots, stations, HQ, ...
RailType
Enumeration for all possible railtypes.
"Arrow" to the 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.
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.
Flag for an invalid DiagDirection.
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.
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
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.
north and south corner are raised
Track
These are used to specify a single track.
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)
static const TrackBits _valid_tracks_on_leveled_foundation[15]
Valid TrackBits on a specific (non-steep)-slope with leveled foundation.
Track right, direction south.
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.
SmallVector< Train *, 16 > TrainList
Helper type for lists/vectors of trains.
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)
void Clear()
Remove all items from the list.
const T * Begin() const
Get the pointer to the first item (const)
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
static RoadBits GetRoadBits(TileIndex t, RoadType rt)
Get the present road bits for a specific road type.
static int CDECL CompareRailTypes(const RailType *first, const RailType *second)
Compare railtypes based on their sorting order.
Northeast, upper right on your monitor.
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.
Track in the left corner of the tile (west)
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.
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.
Simple vector template class.
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 ...
struct RailtypeInfo::@39 cursor
Cursors associated with the rail type.
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.
Standard non-electric rails.
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.
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.
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.
const T * End() const
Get the pointer behind the last valid item (const)
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.
"Arrow" to the north-west
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.
T * Append(uint to_add=1)
Append an item and return it.
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...
Track upper, direction east.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
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)
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Track right, direction north.
SpriteID single_y
single piece of rail in Y direction, without ground
build a single rail track
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)
TrackBits
Bitfield corresponding to Track.
Track x-axis, direction north-east.
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.
struct RailtypeInfo::@40 strings
Strings associated with the rail type.
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.
Track along the y-axis (north-west to south-east)
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
uint Length() const
Get the number of items in the list.
static Owner GetRoadOwner(TileIndex t, RoadType rt)
Get the owner of a specific road type.
The tile is leveled up to a flat slope.
byte train_signal_side
show signals on left / driving / right side
Track upper, direction west.
Level north halftile non-continuously.
Track lower, direction west.
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.
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.
struct RailtypeInfo::@37 base_sprites
Struct containing the main sprites.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Track in the right corner of the tile (east)
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.
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?
"Arrow" to the north-east
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.
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.
Track in the lower corner of the tile (south)
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.
Trackdir
Enumeration for tracks and directions.
byte sorting_order
The sorting order of this railtype for the toolbar dropdown.
void ShowDepotWindow(TileIndex tile, VehicleType type)
Opens a depot window.
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.
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.
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 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.
DiagDirection
Enumeration for diagonal directions.
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.
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.
RoadTypes
The different roadtypes we support, but then a bitmask of them.
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 TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
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 bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
Find out if the slope of the tile is suitable to build a depot of given direction.
Flag for an invalid track.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
static bool IsSlopeWithThreeCornersRaised(Slope s)
Tests if a specific slope has exactly three corners raised.
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.
Track x-axis, direction south-west.
Slope FLAT, Track RIGHT, Fence W.
CompanyByte _current_company
Company currently doing an action.
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
int x_offs
Bounding box X offset.
Track y-axis, direction north-west.
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.
static void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner rail, Axis roaddir, RailType rat, RoadTypes rot, uint town)
Make a level crossing.
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.
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.
static bool HasTrack(TileIndex tile, Track track)
Returns whether the given track is present on the given tile.
bool Include(const T &item)
Tests whether a item is present in the vector, and appends it to the end if not.
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 ...
uint GetRailtypeSpriteOffset() const
Offset between the current railtype and normal rail.
static uint CountBits(T value)
Counts the number of set bits in a variable.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Functions related to commands.
Coordinates of a point in 2D.
remove a single rail track
Iterator to iterate over a tile area (rectangle) of the map.
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-NULL) Titem.
static bool HasRailCatenaryDrawn(RailType rt)
Test if we should draw rail catenary.
Date build_date
Date of construction of tile contents.
SmallVector< RailTypeLabel, 4 > RailTypeLabelList
List of rail type labels.
"Arrow" to the south-east
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.
struct RailtypeInfo::@38 gui_sprites
struct containing the sprites for the rail GUI.
static void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram)
Make a normal road tile.
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 RoadTypes GetRoadTypes(TileIndex t)
Get the present road types of a tile.
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.
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.
Track y-axis, direction south-east.
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.
void Restore()
Restore the variable.
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Track left, direction south.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
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.
Track left, direction north.
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.
Flag for invalid railtype.
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.
static bool HasDepotReservation(TileIndex t)
Get the reservation state of the depot.
Owner
Enum for all companies/owners.
Flag for an invalid trackdir.
static CommandCost CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
Check that the new track bits may be built.
Track along the x-axis (north-east to south-west)
Functions related to water (management)
static bool IsNonContinuousFoundation(Foundation f)
Tests if a foundation is a non-continuous foundation, i.e.
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 lower, direction east.
SignalVariant
Variant of the signal, i.e.
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 void QSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe qsort()
static Direction ReverseDir(Direction d)
Return the reverse of a direction.
SpriteID build_ew_rail
button for building single rail in E-W direction
Track in the upper corner of the tile (north)
the south corner of the tile is raised
The tile/execution is done by "water".
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
VehicleTypeByte type
Type of vehicle.
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.
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.
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-...
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.
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.