37 #include "table/strings.h" 48 uint8 _sorted_railtypes_size;
73 {0,0,0,0,0,0,0,0,0,0,0,0},
77 0,
RAILTYPES_NONE,
RAILTYPES_NONE, 0, 0, 0,
RTFB_NONE, 0, 0, 0, 0, 0,
80 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);
145 _sorted_railtypes_size = 0;
147 if (_railtypes[rt].label != 0) {
148 _sorted_railtypes[_sorted_railtypes_size++] = rt;
162 if (rti->
label == 0) {
189 static const byte _track_sloped_sprites[14] = {
259 if (current == future) {
269 return_cmd_error((flags & DC_NO_RAIL_OVERLAP) ? STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION : STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
428 static inline bool ValParamTrackOrientation(
Track track)
444 RailType railtype = Extract<RailType, 0, 4>(p1);
445 Track track = Extract<Track, 0, 3>(p2);
456 if (ret.
Failed())
return ret;
464 if (ret.
Failed())
return ret;
467 if (ret.
Failed())
return ret;
476 if (ret.
Failed())
return ret;
505 if (ret.
Failed())
return ret;
525 if (ret.
Failed())
return ret;
528 uint num_new_road_pieces = 2 -
CountBits(road);
534 cost.AddCost((num_new_road_pieces + num_new_tram_pieces) * _price[PR_BUILD_ROAD]);
565 if (ret.
Failed())
return ret;
569 if (ret.
Failed())
return ret;
573 cost.AddCost(-_price[PR_CLEAR_WATER]);
574 cost.AddCost(_price[PR_CLEAR_ROUGH]);
608 Track track = Extract<Track, 0, 3>(p2);
610 bool crossing =
false;
612 if (!ValParamTrackOrientation(track))
return CMD_ERROR;
629 if (ret.
Failed())
return ret;
634 if (ret.
Failed())
return ret;
660 if (ret.
Failed())
return ret;
664 if (ret.
Failed())
return ret;
667 if ((present & trackbit) == 0)
return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
753 bool flooded =
false;
762 TrackBits to_remove = lower_track & rail_bits;
763 if (to_remove != 0) {
767 if (!flooded)
return flooded;
768 rail_bits = rail_bits & ~to_remove;
769 if (rail_bits == 0) {
795 { -1, 0 }, { 0, 1 }, { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, 1 },
798 { 1, 0 }, { 0, -1 }, { 0, -1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
806 int x =
TileX(start);
807 int y =
TileY(start);
818 int trdx = _trackdelta[*trackdir].
x;
819 int trdy = _trackdelta[*trackdir].
y;
822 trdx += _trackdelta[*trackdir ^ 1].
x;
823 trdy += _trackdelta[*trackdir ^ 1].
y;
827 while ((trdx <= 0 && dx > 0) ||
828 (trdx >= 0 && dx < 0) ||
829 (trdy <= 0 && dy > 0) ||
830 (trdy >= 0 && dy < 0)) {
831 if (!
HasBit(*trackdir, 3)) {
843 trdx = _trackdelta[*trackdir].
x;
844 trdy = _trackdelta[*trackdir].
y;
867 Track track = Extract<Track, 4, 3>(p2);
868 bool remove =
HasBit(p2, 7);
869 RailType railtype = Extract<RailType, 0, 4>(p2);
876 CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
877 if (ret.
Failed())
return ret;
879 bool had_success =
false;
886 if (last_error.
GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !
remove) {
887 if (
HasBit(p2, 8))
return last_error;
892 if (last_error.
GetErrorMessage() == STR_ERROR_OWNED_BY &&
remove)
break;
898 if (tile == end_tile)
break;
906 if (had_success)
return total_cost;
963 RailType railtype = Extract<RailType, 0, 4>(p1);
985 if (cost.
Failed())
return cost;
1006 cost.
AddCost(_price[PR_BUILD_DEPOT_TRAIN]);
1034 Track track = Extract<Track, 0, 3>(p1);
1035 bool ctrl_pressed =
HasBit(p1, 3);
1037 SignalType sigtype = Extract<SignalType, 5, 3>(p1);
1038 bool convert_signal =
HasBit(p1, 8);
1039 SignalType cycle_start = Extract<SignalType, 9, 3>(p1);
1040 SignalType cycle_stop = Extract<SignalType, 12, 3>(p1);
1041 uint num_dir_cycle =
GB(p1, 15, 2);
1043 if (sigtype > SIGTYPE_LAST)
return CMD_ERROR;
1044 if (cycle_start > cycle_stop || cycle_stop > SIGTYPE_LAST)
return CMD_ERROR;
1055 if (ret.
Failed())
return ret;
1071 if (p2 != 0 && sigvar != GetSignalVariant(tile, track)) {
1075 }
else if (convert_signal) {
1077 if (ctrl_pressed || GetSignalVariant(tile, track) != sigvar) {
1106 SetSignalType(tile, track, sigtype);
1107 SetSignalVariant(tile, track, sigvar);
1117 SetSignalType(tile, track, sigtype);
1118 SetSignalVariant(tile, track, sigvar);
1119 while (num_dir_cycle-- > 0) CycleSignalSide(tile, track);
1121 if (convert_signal) {
1127 sigtype = GetSignalType(tile, track);
1130 SetSignalType(tile, track, sigtype);
1131 SetSignalVariant(tile, track, sigvar);
1137 }
else if (ctrl_pressed) {
1139 sigtype = (
SignalType)(GetSignalType(tile, track) + 1);
1141 if (sigtype < cycle_start || sigtype > cycle_stop) sigtype = cycle_start;
1143 SetSignalType(tile, track, sigtype);
1149 CycleSignalSide(tile, track);
1151 sigtype = GetSignalType(tile, track);
1158 SetSignalVariant(tile, track, sigvar);
1159 SetSignalType(tile, track, sigtype);
1166 if (IsPbsSignal(sigtype)) {
1186 static bool CheckSignalAutoFill(
TileIndex &tile,
Trackdir &trackdir,
int &signal_ctr,
bool remove)
1237 default:
return false;
1263 Track track = Extract<Track, 0, 3>(p2);
1264 bool mode =
HasBit(p2, 3);
1265 bool semaphores =
HasBit(p2, 4);
1266 bool remove =
HasBit(p2, 5);
1267 bool autofill =
HasBit(p2, 6);
1268 bool minimise_gaps =
HasBit(p2, 10);
1269 byte signal_density =
GB(p2, 24, 8);
1273 if (signal_density == 0 || signal_density > 20)
return CMD_ERROR;
1279 signal_density *= 2;
1282 CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
1283 if (ret.
Failed())
return ret;
1286 Trackdir start_trackdir = trackdir;
1292 if (sigtype > SIGTYPE_LAST)
return CMD_ERROR;
1298 assert(signals != 0);
1301 semaphores = GetSignalVariant(tile, track) !=
SIG_ELECTRIC;
1303 sigtype = GetSignalType(tile, track);
1310 byte signal_dir = 0;
1327 int last_used_ctr = INT_MIN;
1328 int last_suitable_ctr = 0;
1332 bool had_success =
false;
1335 if (
remove || minimise_gaps || signal_ctr % signal_density == 0) {
1338 SB(p1, 4, 1, semaphores);
1339 SB(p1, 5, 3, sigtype);
1340 if (!
remove && signal_ctr == 0)
SetBit(p1, 17);
1348 bool test_only = !
remove && minimise_gaps && signal_ctr < (last_used_ctr + signal_density);
1351 if (ret.Succeeded()) {
1353 last_suitable_ctr = signal_ctr;
1354 last_suitable_tile = tile;
1355 last_suitable_trackdir = trackdir;
1356 }
else if (!test_only && last_suitable_tile !=
INVALID_TILE) {
1372 if (ret.Succeeded()) {
1375 last_used_ctr = last_suitable_ctr;
1379 if (ret.GetErrorMessage() != STR_ERROR_THERE_IS_NO_RAILROAD_TRACK ||
1388 if (!CheckSignalAutoFill(tile, trackdir, signal_ctr,
remove))
break;
1391 if (tile == start_tile && trackdir == start_trackdir)
break;
1393 if (tile == end_tile)
break;
1407 return had_success ? total_cost : last_error;
1447 Track track = Extract<Track, 0, 3>(p1);
1459 if (ret.
Failed())
return ret;
1467 }
else if (IsPbsSignal(GetSignalType(tile, track))) {
1550 RailType totype = Extract<RailType, 0, 4>(p2);
1553 bool diagonal =
HasBit(p2, 4);
1577 error.
MakeError(STR_ERROR_CROSSING_DISALLOWED);
1620 *vehicles_affected.
Append() = v;
1661 if (flags & DC_EXEC) {
1678 if (endtile < tile) {
1702 *vehicles_affected.
Append() = v;
1744 for (uint i = 0; i < vehicles_affected.
Length(); ++i) {
1751 for (
Train **v = affected_trains.
Begin(); v != affected_trains.
End(); v++) {
1757 return (cost.
GetCost() == 0) ? error : cost;
1764 if (ret.
Failed())
return ret;
1768 if (ret.
Failed())
return ret;
1784 delete Depot::GetByTile(tile);
1785 DoClearSquare(tile);
1821 if (ret.
Failed())
return ret;
1829 if (ret.
Failed())
return ret;
1832 if (flags &
DC_EXEC) DoClearSquare(tile);
1833 cost.
AddCost(_price[PR_CLEAR_WATER]);
1840 return RemoveTrainDepot(tile, flags);
1860 return GetSlopePixelZ(x, y);
1867 case 0: side =
false;
break;
1868 case 2: side =
true;
break;
1871 static const Point SignalPositions[2][12] = {
1874 { 8, 5}, {14, 1}, { 1, 14}, { 9, 11}, { 1, 0}, { 3, 10},
1876 {11, 4}, {14, 14}, {11, 3}, { 4, 13}, { 3, 4}, {11, 13}
1879 {14, 1}, {12, 10}, { 4, 6}, { 1, 14}, {10, 4}, { 0, 1},
1881 {14, 14}, { 5, 12}, {11, 13}, { 4, 3}, {13, 4}, { 3, 11}
1888 SignalType type = GetSignalType(tile, track);
1897 sprite += type * 16 + variant * 64 + image * 2 + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0);
1903 static uint32 _drawtile_track_palette;
1918 { CORNER_INVALID, 0, 1, 16, 1 },
1919 { CORNER_INVALID, 1, 0, 1, 16 },
1920 { CORNER_W, 8, 8, 1, 1 },
1921 { CORNER_N, 8, 8, 1, 1 },
1922 { CORNER_INVALID, 0, 1, 16, 1 },
1923 { CORNER_INVALID, 1, 0, 1, 16 },
1924 { CORNER_INVALID, 0, 1, 16, 1 },
1925 { CORNER_INVALID, 1, 0, 1, 16 },
1926 { CORNER_INVALID, 0, 15, 16, 1 },
1927 { CORNER_INVALID, 15, 0, 1, 16 },
1928 { CORNER_E, 8, 8, 1, 1 },
1929 { CORNER_S, 8, 8, 1, 1 },
1930 { CORNER_INVALID, 0, 15, 16, 1 },
1931 { CORNER_INVALID, 15, 0, 1, 16 },
1932 { CORNER_INVALID, 0, 15, 16, 1 },
1933 { CORNER_INVALID, 15, 0, 1, 16 },
1946 if (_fence_offsets[rfo].
height_ref != CORNER_INVALID) {
1950 ti->
x + _fence_offsets[rfo].
x_offs,
1951 ti->
y + _fence_offsets[rfo].
y_offs,
1952 _fence_offsets[rfo].
x_size,
1953 _fence_offsets[rfo].
y_size,
2006 uint num_sprites = 0;
2008 if (base_image == 0) {
2009 base_image = SPR_TRACK_FENCE_FLAT_X;
2013 assert(num_sprites > 0);
2015 switch (GetRailGroundType(ti->
tile)) {
2037 switch (track_corner) {
2042 default: NOT_REACHED();
2051 static const int INF = 1000;
2052 static const SubSprite _halftile_sub_sprite[4] = {
2053 { -INF , -INF , 32 - 33, INF },
2054 { -INF , 0 + 7, INF , INF },
2055 { -31 + 33, -INF , INF , INF },
2056 { -INF , -INF , INF , 30 - 23 }
2068 Corner halftile_corner = CORNER_INVALID;
2085 DrawShoreTile(ti->
tileh);
2096 default: image = SPR_FLAT_GRASS_TILE;
break;
2134 DrawTrackSprite(ground +
RTO_S, PAL_NONE, ti,
SLOPE_S);
break;
2136 DrawTrackSprite(ground +
RTO_W, PAL_NONE, ti,
SLOPE_W);
break;
2186 default: image = SPR_FLAT_GRASS_TILE;
break;
2191 DrawGroundSprite(image, PAL_NONE, &(_halftile_sub_sprite[halftile_corner]));
2197 default: NOT_REACHED();
2204 DrawTrackSprite(ground + offset, PAL_NONE, ti, fake_slope);
2206 DrawTrackSprite(overlay + offset,
PALETTE_CRASH, ti, fake_slope);
2220 if (rti->UsesOverlay()) {
2221 DrawTrackBitsOverlay(ti, track, rti);
2227 Corner halftile_corner = CORNER_INVALID;
2243 bool junction =
false;
2250 DrawShoreTile(ti->
tileh);
2253 image = SPR_FLAT_WATER_TILE;
2259 default: image = SPR_FLAT_GRASS_TILE;
break;
2280 (junction =
true,
false) ||
2293 DrawShoreTile(ti->
tileh);
2295 sub = &(_halftile_sub_sprite[track_corner]);
2354 static const byte _corner_to_track_sprite[] = {3, 1, 2, 0};
2362 #define MAYBE_DRAW_SIGNAL(x, y, z, t) if (IsSignalPresent(tile, x)) DrawSingleSignal(tile, rti, t, GetSingleSignalState(tile, x), y, z) 2367 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTH, 0,
TRACK_LEFT);
2368 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTH, 1,
TRACK_LEFT);
2371 MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_NORTH, 2,
TRACK_RIGHT);
2372 MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_SOUTH, 3,
TRACK_RIGHT);
2375 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_WEST, 4,
TRACK_UPPER);
2376 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_EAST, 5,
TRACK_UPPER);
2379 MAYBE_DRAW_SIGNAL(1, SIGNAL_TO_WEST, 6,
TRACK_LOWER);
2380 MAYBE_DRAW_SIGNAL(0, SIGNAL_TO_EAST, 7,
TRACK_LOWER);
2383 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHWEST, 8,
TRACK_X);
2384 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHEAST, 9,
TRACK_X);
2387 MAYBE_DRAW_SIGNAL(3, SIGNAL_TO_SOUTHEAST, 10,
TRACK_Y);
2388 MAYBE_DRAW_SIGNAL(2, SIGNAL_TO_NORTHWEST, 11,
TRACK_Y);
2392 static void DrawTile_Track(
TileInfo *ti)
2424 if (rti->UsesOverlay()) {
2425 image = SPR_FLAT_GRASS_TILE;
2434 if (image != SPR_FLAT_GRASS_TILE) {
2437 image = SPR_FLAT_SNOW_DESERT_TILE;
2443 if (rti->UsesOverlay()) {
2514 void DrawTrainDepotSprite(
int x,
int y,
int dir,
RailType railtype)
2521 if (image != SPR_FLAT_GRASS_TILE) image += offset;
2526 if (rti->UsesOverlay()) {
2536 if (depot_sprite != 0) offset = depot_sprite - SPR_RAIL_DEPOT_SE_1;
2541 static int GetSlopePixelZ_Track(
TileIndex tile, uint x, uint y)
2560 static void TileLoop_Track(
TileIndex tile)
2672 default: NOT_REACHED();
2677 if (old_ground != new_ground) {
2678 SetRailGroundType(tile, new_ground);
2690 default: NOT_REACHED();
2705 default: NOT_REACHED();
2746 static bool ClickTile_Track(
TileIndex tile)
2762 td->
str = STR_LAI_RAIL_DESCRIPTION_TRACK;
2766 static const StringID signal_type[6][6] = {
2768 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_SIGNALS,
2769 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PRESIGNALS,
2770 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_EXITSIGNALS,
2771 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_COMBOSIGNALS,
2772 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PBSSIGNALS,
2773 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_NOENTRYSIGNALS
2776 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PRESIGNALS,
2777 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRESIGNALS,
2778 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_EXITSIGNALS,
2779 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_COMBOSIGNALS,
2780 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_PBSSIGNALS,
2781 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_NOENTRYSIGNALS
2784 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_EXITSIGNALS,
2785 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_EXITSIGNALS,
2786 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXITSIGNALS,
2787 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_COMBOSIGNALS,
2788 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_PBSSIGNALS,
2789 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_NOENTRYSIGNALS
2792 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_COMBOSIGNALS,
2793 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_COMBOSIGNALS,
2794 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_COMBOSIGNALS,
2795 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBOSIGNALS,
2796 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_PBSSIGNALS,
2797 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_NOENTRYSIGNALS
2800 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_PBSSIGNALS,
2801 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_PBSSIGNALS,
2802 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_PBSSIGNALS,
2803 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_PBSSIGNALS,
2804 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PBSSIGNALS,
2805 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PBS_NOENTRYSIGNALS
2808 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NORMAL_NOENTRYSIGNALS,
2809 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PRE_NOENTRYSIGNALS,
2810 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_EXIT_NOENTRYSIGNALS,
2811 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_COMBO_NOENTRYSIGNALS,
2812 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_PBS_NOENTRYSIGNALS,
2813 STR_LAI_RAIL_DESCRIPTION_TRACK_WITH_NOENTRYSIGNALS
2820 primary_signal = GetSignalType(tile,
TRACK_UPPER);
2823 secondary_signal = primary_signal = GetSignalType(tile,
TRACK_LOWER);
2826 td->
str = signal_type[secondary_signal][primary_signal];
2831 td->
str = STR_LAI_RAIL_DESCRIPTION_TRAIN_DEPOT;
2853 uint num_pieces = 1;
2860 Company::Get(old_owner)->infrastructure.rail[rt] -= num_pieces;
2861 Company::Get(new_owner)->infrastructure.rail[rt] += num_pieces;
2865 Company::Get(old_owner)->infrastructure.signal -= num_sigs;
2866 Company::Get(new_owner)->infrastructure.signal += num_sigs;
2875 static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 };
2876 static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
2877 static const int8 _deltacoord_leaveoffset[8] = {
2895 case DIAGDIR_NE:
return ((
int)(v->
x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) - (length + 1)));
2896 case DIAGDIR_SE:
return -((int)(v->
y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4) + (length + 1)));
2897 case DIAGDIR_SW:
return -((int)(v->
x_pos & 0x0F) - ((_fractcoords_enter[dir] & 0x0F) + (length + 1)));
2899 case DIAGDIR_NW:
return ((
int)(v->
y_pos & 0x0F) - ((_fractcoords_enter[dir] >> 4) - (length + 1)));
2922 byte fract_coord_leave =
2923 ((_fractcoords_enter[dir] & 0x0F) +
2924 (length + 1) * _deltacoord_leaveoffset[dir]) +
2925 (((_fractcoords_enter[dir] >> 4) +
2926 ((length + 1) * _deltacoord_leaveoffset[dir + 4])) << 4);
2928 byte fract_coord = (x & 0xF) + ((y & 0xF) << 4);
2930 if (_fractcoords_behind[dir] == fract_coord) {
2933 }
else if (_fractcoords_enter[dir] == fract_coord) {
2945 }
else if (fract_coord_leave == fract_coord) {
2948 if ((v = v->
Next()) != NULL) {
2981 switch (rail_bits) {
2989 if (z_old != z_new || tileh_old != tileh_new)
return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
2996 if (z_old != z_new)
return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
3000 if (tileh_old != tileh_new) {
3033 switch (rail_bits) {
3038 default:
return autoslope_result;
3047 for (
Corner corner = (
Corner)0; corner < CORNER_END; corner = (
Corner)(corner + 1)) {
3048 if (allowed_corner == corner)
continue;
3067 GetSlopePixelZ_Track,
3071 GetTileTrackStatus_Track,
3075 ChangeTileOwner_Track,
3078 GetFoundation_Track,
3079 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.
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.
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
RailTypes
The different roadtypes we support, but then a bitmask of them.
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...
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.
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.
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.
Money GetCost() const
The costs as made up to this moment.
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.
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.
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.
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.
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 give 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.
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.
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.
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.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
A pair-construct of a TileIndexDiff.
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
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
struct RailtypeInfo::@37 gui_sprites
struct containing the sprites for the rail GUI.
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.
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.