Merge remote-tracking branch 'upstream/master'

This commit is contained in:
dP
2025-05-14 18:41:13 +05:00
994 changed files with 38759 additions and 34518 deletions

View File

@@ -181,7 +181,7 @@ RailType AllocateRailType(RailTypeLabel label)
return INVALID_RAILTYPE;
}
static const byte _track_sloped_sprites[14] = {
static const uint8_t _track_sloped_sprites[14] = {
14, 15, 22, 13,
0, 21, 17, 12,
23, 0, 18, 20,
@@ -242,7 +242,7 @@ static CommandCost EnsureNoTrainOnTrack(TileIndex tile, Track track)
*/
static CommandCost CheckTrackCombination(TileIndex tile, TrackBits to_build)
{
if (!IsPlainRail(tile)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
if (!IsPlainRail(tile)) return CommandCost(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
/* So, we have a tile with tracks on it (and possibly signals). Let's see
* what tracks first */
@@ -252,7 +252,7 @@ static CommandCost CheckTrackCombination(TileIndex tile, TrackBits to_build)
/* Are we really building something new? */
if (current == future) {
/* Nothing new is being built */
return_cmd_error(STR_ERROR_ALREADY_BUILT);
return CommandCost(STR_ERROR_ALREADY_BUILT);
}
/* Normally, we may overlap and any combination is valid */
@@ -395,7 +395,7 @@ static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits ex
{
/* don't allow building on the lower side of a coast */
if (GetFloodingBehaviour(tile) != FLOOD_NONE) {
if (!IsSteepSlope(tileh) && ((~_valid_tracks_on_leveled_foundation[tileh] & (rail_bits | existing)) != 0)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
if (!IsSteepSlope(tileh) && ((~_valid_tracks_on_leveled_foundation[tileh] & (rail_bits | existing)) != 0)) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
}
Foundation f_new = GetRailFoundation(tileh, rail_bits | existing);
@@ -403,7 +403,7 @@ static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits ex
/* check track/slope combination */
if ((f_new == FOUNDATION_INVALID) ||
((f_new != FOUNDATION_NONE) && (!_settings_game.construction.build_on_slopes))) {
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
}
Foundation f_old = GetRailFoundation(tileh, existing);
@@ -443,7 +443,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
if (!IsPlainRail(tile)) return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile); // just get appropriate error message
if (!IsCompatibleRail(GetRailType(tile), railtype)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
if (!IsCompatibleRail(GetRailType(tile), railtype)) return CommandCost(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
ret = CheckTrackCombination(tile, trackbit);
if (ret.Succeeded()) ret = EnsureNoTrainOnTrack(tile, track);
@@ -458,7 +458,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
if (HasSignals(tile) && TracksOverlap(GetTrackBits(tile) | TrackToTrackBits(track))) {
/* If adding the new track causes any overlap, all signals must be removed first */
if (!auto_remove_signals) return_cmd_error(STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
if (!auto_remove_signals) return CommandCost(STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
for (Track track_it = TRACK_BEGIN; track_it < TRACK_END; track_it++) {
if (HasTrack(tile, track_it) && HasSignalOnTrack(tile, track_it)) {
@@ -501,7 +501,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
case MP_ROAD: {
/* Level crossings may only be built on these slopes */
if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
if (!_settings_game.construction.crossing_with_competitor && _current_company != OWNER_DEITY) {
CommandCost ret = CheckTileOwnership(tile);
@@ -512,17 +512,17 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
if (ret.Failed()) return ret;
if (IsNormalRoad(tile)) {
if (HasRoadWorks(tile)) return_cmd_error(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
if (HasRoadWorks(tile)) return CommandCost(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
if (GetDisallowedRoadDirections(tile) != DRD_NONE) return_cmd_error(STR_ERROR_CROSSING_ON_ONEWAY_ROAD);
if (GetDisallowedRoadDirections(tile) != DRD_NONE) return CommandCost(STR_ERROR_CROSSING_ON_ONEWAY_ROAD);
if (RailNoLevelCrossings(railtype)) return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_RAIL);
if (RailNoLevelCrossings(railtype)) return CommandCost(STR_ERROR_CROSSING_DISALLOWED_RAIL);
RoadType roadtype_road = GetRoadTypeRoad(tile);
RoadType roadtype_tram = GetRoadTypeTram(tile);
if (roadtype_road != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_road)) return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
if (roadtype_tram != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_tram)) return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
if (roadtype_road != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_road)) return CommandCost(STR_ERROR_CROSSING_DISALLOWED_ROAD);
if (roadtype_tram != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_tram)) return CommandCost(STR_ERROR_CROSSING_DISALLOWED_ROAD);
RoadBits road = GetRoadBits(tile, RTT_ROAD);
RoadBits tram = GetRoadBits(tile, RTT_TRAM);
@@ -568,7 +568,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) {
_rail_track_endtile = tile;
return_cmd_error(STR_ERROR_ALREADY_BUILT);
return CommandCost(STR_ERROR_ALREADY_BUILT);
}
[[fallthrough]];
}
@@ -641,7 +641,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
switch (GetTileType(tile)) {
case MP_ROAD: {
if (!IsLevelCrossing(tile) || GetCrossingRailBits(tile) != trackbit) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
if (!IsLevelCrossing(tile) || GetCrossingRailBits(tile) != trackbit) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
if (_current_company != OWNER_WATER) {
CommandCost ret = CheckTileOwnership(tile);
@@ -675,7 +675,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
case MP_RAILWAY: {
TrackBits present;
/* There are no rails present at depots. */
if (!IsPlainRail(tile)) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
if (!IsPlainRail(tile)) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
if (_current_company != OWNER_WATER) {
CommandCost ret = CheckTileOwnership(tile);
@@ -686,7 +686,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
if (ret.Failed()) return ret;
present = GetTrackBits(tile);
if ((present & trackbit) == 0) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
if ((present & trackbit) == 0) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true;
cost.AddCost(RailClearCost(GetRailType(tile)));
@@ -734,7 +734,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
break;
}
default: return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
default: return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
}
if (flags & DC_EXEC) {
@@ -786,7 +786,7 @@ bool FloodHalftile(TileIndex t)
TrackBits to_remove = lower_track & rail_bits;
if (to_remove != 0) {
Backup<CompanyID> cur_company(_current_company, OWNER_WATER, FILE_LINE);
Backup<CompanyID> cur_company(_current_company, OWNER_WATER);
flooded = Command<CMD_REMOVE_SINGLE_RAIL>::Do(DC_EXEC, t, FindFirstTrack(to_remove)).Succeeded();
cur_company.Restore();
if (!flooded) return flooded; // not yet floodable
@@ -805,7 +805,7 @@ bool FloodHalftile(TileIndex t)
}
} else {
/* Make shore on steep slopes and 'three-corners-raised'-slopes. */
if (ApplyFoundationToSlope(GetRailFoundation(tileh, rail_bits), &tileh) == 0) {
if (ApplyFoundationToSlope(GetRailFoundation(tileh, rail_bits), tileh) == 0) {
if (IsSteepSlope(tileh) || IsSlopeWithThreeCornersRaised(tileh)) {
flooded = true;
SetRailGroundType(t, RAIL_GROUND_WATER);
@@ -993,7 +993,7 @@ CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType rai
if (tileh != SLOPE_FLAT) {
if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) {
return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
}
cost.AddCost(_price[PR_BUILD_FOUNDATION]);
}
@@ -1004,7 +1004,7 @@ CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType rai
CommandCost ret = CheckTileOwnership(tile);
if (ret.Failed()) return ret;
if (dir == GetRailDepotDirection(tile)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
if (dir == GetRailDepotDirection(tile)) return CommandCost();
ret = EnsureNoVehicleOnGround(tile);
if (ret.Failed()) return ret;
@@ -1016,7 +1016,7 @@ CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType rai
cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile));
if (cost.Failed()) return cost;
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (!Depot::CanAllocateItem()) return CMD_ERROR;
}
@@ -1064,7 +1064,7 @@ CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType rai
* @return the cost of this operation or an error
* @todo p2 should be replaced by two bits for "along" and "against" the track.
*/
CommandCost CmdBuildSingleSignal(DoCommandFlag flags, TileIndex tile, Track track, SignalType sigtype, SignalVariant sigvar, bool convert_signal, bool skip_existing_signals, bool ctrl_pressed, SignalType cycle_start, SignalType cycle_stop, uint8_t num_dir_cycle, byte signals_copy)
CommandCost CmdBuildSingleSignal(DoCommandFlag flags, TileIndex tile, Track track, SignalType sigtype, SignalVariant sigvar, bool convert_signal, bool skip_existing_signals, bool ctrl_pressed, SignalType cycle_start, SignalType cycle_stop, uint8_t num_dir_cycle, uint8_t signals_copy)
{
if (sigtype > SIGTYPE_LAST || sigvar > SIG_SEMAPHORE) return CMD_ERROR;
if (cycle_start > cycle_stop || cycle_stop > SIGTYPE_LAST) return CMD_ERROR;
@@ -1074,7 +1074,7 @@ CommandCost CmdBuildSingleSignal(DoCommandFlag flags, TileIndex tile, Track trac
/* You can only build signals on plain rail tiles, and the selected track must exist */
if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) ||
!HasTrack(tile, track)) {
return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
}
/* Protect against invalid signal copying */
if (signals_copy != 0 && (signals_copy & SignalOnTrack(track)) == 0) return CMD_ERROR;
@@ -1083,13 +1083,13 @@ CommandCost CmdBuildSingleSignal(DoCommandFlag flags, TileIndex tile, Track trac
if (ret.Failed()) return ret;
/* See if this is a valid track combination for signals (no overlap) */
if (TracksOverlap(GetTrackBits(tile))) return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
if (TracksOverlap(GetTrackBits(tile))) return CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
/* In case we don't want to change an existing signal, return without error. */
if (skip_existing_signals && HasSignalOnTrack(tile, track)) return CommandCost();
/* you can not convert a signal if no signal is on track */
if (convert_signal && !HasSignalOnTrack(tile, track)) return_cmd_error(STR_ERROR_THERE_ARE_NO_SIGNALS);
if (convert_signal && !HasSignalOnTrack(tile, track)) return CommandCost(STR_ERROR_THERE_ARE_NO_SIGNALS);
CommandCost cost;
if (!HasSignalOnTrack(tile, track)) {
@@ -1278,7 +1278,7 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, Til
if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
if (!remove && (sigtype > SIGTYPE_LAST || sigvar > SIG_SEMAPHORE)) return CMD_ERROR;
if (!IsPlainRailTile(tile)) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
if (!IsPlainRailTile(tile)) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
TileIndex start_tile = tile;
/* Interpret signal_density as the logical length of said amount of tiles in X/Y direction. */
@@ -1294,7 +1294,7 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, Til
/* Must start on a valid track to be able to avoid loops */
if (!HasTrack(tile, track)) return CMD_ERROR;
byte signals;
uint8_t signals;
/* copy the signal-style of the first rail-piece if existing */
if (HasSignalOnTrack(tile, track)) {
signals = GetPresentSignals(tile) & SignalOnTrack(track);
@@ -1310,7 +1310,7 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, Til
signals = IsPbsSignal(sigtype) ? SignalAlongTrackdir(trackdir) : SignalOnTrack(track);
}
byte signal_dir = 0;
uint8_t signal_dir = 0;
if (signals & SignalAlongTrackdir(trackdir)) SetBit(signal_dir, 0);
if (signals & SignalAgainstTrackdir(trackdir)) SetBit(signal_dir, 1);
@@ -1335,7 +1335,7 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, Til
bool had_success = false;
auto build_signal = [&](TileIndex tile, Trackdir trackdir, bool test_only) {
/* Pick the correct orientation for the track direction */
byte signals = 0;
uint8_t signals = 0;
if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
@@ -1461,7 +1461,7 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, Til
* @return the cost of this operation or an error
* @see CmdSignalTrackHelper
*/
CommandCost CmdBuildSignalTrack(DoCommandFlag flags, TileIndex tile, TileIndex end_tile, Track track, SignalType sigtype, SignalVariant sigvar, bool mode, bool autofill, bool minimise_gaps, byte signal_density)
CommandCost CmdBuildSignalTrack(DoCommandFlag flags, TileIndex tile, TileIndex end_tile, Track track, SignalType sigtype, SignalVariant sigvar, bool mode, bool autofill, bool minimise_gaps, uint8_t signal_density)
{
return CmdSignalTrackHelper(flags, tile, end_tile, track, sigtype, sigvar, mode, false, autofill, minimise_gaps, signal_density);
}
@@ -1476,10 +1476,10 @@ CommandCost CmdBuildSignalTrack(DoCommandFlag flags, TileIndex tile, TileIndex e
CommandCost CmdRemoveSingleSignal(DoCommandFlag flags, TileIndex tile, Track track)
{
if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) || !HasTrack(tile, track)) {
return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
}
if (!HasSignalOnTrack(tile, track)) {
return_cmd_error(STR_ERROR_THERE_ARE_NO_SIGNALS);
return CommandCost(STR_ERROR_THERE_ARE_NO_SIGNALS);
}
/* Only water can remove signals from anyone */
@@ -1818,13 +1818,13 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
if (flags & DC_AUTO) {
if (!IsTileOwner(tile, _current_company)) {
return_cmd_error(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
return CommandCost(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
}
if (IsPlainRail(tile)) {
return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
} else {
return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
}
}
@@ -2394,7 +2394,7 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track)
DrawGroundSprite(image, pal, &(_halftile_sub_sprite[halftile_corner]));
if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasReservedTracks(ti->tile, CornerToTrackBits(halftile_corner))) {
static const byte _corner_to_track_sprite[] = {3, 1, 2, 0};
static const uint8_t _corner_to_track_sprite[] = {3, 1, 2, 0};
DrawGroundSprite(_corner_to_track_sprite[halftile_corner] + rti->base_sprites.single_n, PALETTE_CRASH, nullptr, 0, -(int)TILE_HEIGHT);
}
}
@@ -2402,7 +2402,7 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track)
static void DrawSignals(TileIndex tile, TrackBits rails, const RailTypeInfo *rti)
{
auto MAYBE_DRAW_SIGNAL = [&](byte signalbit, SignalOffsets image, uint pos, Track track) {
auto MAYBE_DRAW_SIGNAL = [&](uint8_t signalbit, SignalOffsets image, uint pos, Track track) {
if (IsSignalPresent(tile, signalbit)) DrawSingleSignal(tile, rti, track, GetSingleSignalState(tile, signalbit), image, pos);
};
@@ -2585,11 +2585,10 @@ void DrawTrainDepotSprite(int x, int y, int dir, RailType railtype)
static int GetSlopePixelZ_Track(TileIndex tile, uint x, uint y, bool)
{
if (IsPlainRail(tile)) {
int z;
Slope tileh = GetTilePixelSlope(tile, &z);
auto [tileh, z] = GetTilePixelSlope(tile);
if (tileh == SLOPE_FLAT) return z;
z += ApplyPixelFoundationToSlope(GetRailFoundation(tileh, GetTrackBits(tile)), &tileh);
z += ApplyPixelFoundationToSlope(GetRailFoundation(tileh, GetTrackBits(tile)), tileh);
return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
} else {
return GetTileMaxPixelZ(tile);
@@ -2613,8 +2612,7 @@ static void TileLoop_Track(TileIndex tile)
switch (_settings_game.game_creation.landscape) {
case LT_ARCTIC: {
int z;
Slope slope = GetTileSlope(tile, &z);
auto [slope, z] = GetTileSlopeZ(tile);
bool half = false;
/* for non-flat track, use lower part of track
@@ -2684,7 +2682,7 @@ static void TileLoop_Track(TileIndex tile)
TrackBits rail = GetTrackBits(tile);
Owner owner = GetTileOwner(tile);
byte fences = 0;
uint8_t fences = 0;
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
static const TrackBits dir_to_trackbits[DIAGDIR_END] = {TRACK_BIT_3WAY_NE, TRACK_BIT_3WAY_SE, TRACK_BIT_3WAY_SW, TRACK_BIT_3WAY_NW};
@@ -2753,7 +2751,7 @@ static TrackStatus GetTileTrackStatus_Track(TileIndex tile, TransportType mode,
case RAIL_TILE_SIGNALS: {
trackbits = GetTrackBits(tile);
byte a = GetPresentSignals(tile);
uint8_t a = GetPresentSignals(tile);
uint b = GetSignalStates(tile);
b &= a;
@@ -2916,8 +2914,8 @@ static void ChangeTileOwner_Track(TileIndex tile, Owner old_owner, Owner new_own
}
}
static const byte _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 };
static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
static const uint8_t _fractcoords_behind[4] = { 0x8F, 0x8, 0x80, 0xF8 };
static const uint8_t _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 };
static const int8_t _deltacoord_leaveoffset[8] = {
-1, 0, 1, 0, /* x */
0, 1, 0, -1 /* y */
@@ -2956,7 +2954,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
/* Depot direction. */
DiagDirection dir = GetRailDepotDirection(tile);
byte fract_coord = (x & 0xF) + ((y & 0xF) << 4);
uint8_t fract_coord = (x & 0xF) + ((y & 0xF) << 4);
/* Make sure a train is not entering the tile from behind. */
if (_fractcoords_behind[dir] == fract_coord) return VETSB_CANNOT_ENTER;
@@ -2968,7 +2966,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
/* Calculate the point where the following wagon should be activated. */
int length = v->CalcNextVehicleOffset();
byte fract_coord_leave =
uint8_t fract_coord_leave =
((_fractcoords_enter[dir] & 0x0F) + // x
(length + 1) * _deltacoord_leaveoffset[dir]) +
(((_fractcoords_enter[dir] >> 4) + // y
@@ -3010,14 +3008,14 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
*/
static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, int z_old, Slope tileh_old, int z_new, Slope tileh_new, TrackBits rail_bits)
{
if (!_settings_game.construction.build_on_slopes || !AutoslopeEnabled()) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
if (!_settings_game.construction.build_on_slopes || !AutoslopeEnabled()) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
/* Is the slope-rail_bits combination valid in general? I.e. is it safe to call GetRailFoundation() ? */
if (CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile).Failed()) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
if (CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile).Failed()) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
/* Get the slopes on top of the foundations */
z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), &tileh_old);
z_new += ApplyFoundationToSlope(GetRailFoundation(tileh_new, rail_bits), &tileh_new);
z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), tileh_old);
z_new += ApplyFoundationToSlope(GetRailFoundation(tileh_new, rail_bits), tileh_new);
Corner track_corner;
switch (rail_bits) {
@@ -3028,14 +3026,14 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, int z_old
/* Surface slope must not be changed */
default:
if (z_old != z_new || tileh_old != tileh_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
if (z_old != z_new || tileh_old != tileh_new) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
}
/* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */
z_old += GetSlopeZInCorner(RemoveHalftileSlope(tileh_old), track_corner);
z_new += GetSlopeZInCorner(RemoveHalftileSlope(tileh_new), track_corner);
if (z_old != z_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
if (z_old != z_new) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
/* Make the ground dirty, if surface slope has changed */
@@ -3057,15 +3055,14 @@ static Vehicle *EnsureNoShipProc(Vehicle *v, void *)
static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
{
int z_old;
Slope tileh_old = GetTileSlope(tile, &z_old);
auto [tileh_old, z_old] = GetTileSlopeZ(tile);
if (IsPlainRail(tile)) {
TrackBits rail_bits = GetTrackBits(tile);
/* Is there flat water on the lower halftile that must be cleared expensively? */
bool was_water = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old));
/* Allow clearing the water only if there is no ship */
if (was_water && HasVehicleOnPos(tile, nullptr, &EnsureNoShipProc)) return_cmd_error(STR_ERROR_SHIP_IN_THE_WAY);
if (was_water && HasVehicleOnPos(tile, nullptr, &EnsureNoShipProc)) return CommandCost(STR_ERROR_SHIP_IN_THE_WAY);
/* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */
CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_bits);