Merge remote-tracking branch 'upstream/master'
This commit is contained in:
180
src/rail_cmd.cpp
180
src/rail_cmd.cpp
@@ -44,9 +44,8 @@
|
||||
typedef std::vector<Train *> TrainList;
|
||||
|
||||
RailTypeInfo _railtypes[RAILTYPE_END];
|
||||
std::vector<RailType> _sorted_railtypes;
|
||||
uint8 _sorted_railtypes_size;
|
||||
TileIndex _rail_track_endtile; ///< The end of a rail track; as hidden return from the rail build/remove command for GUI purposes.
|
||||
std::vector<RailType> _sorted_railtypes; ///< Sorted list of rail types.
|
||||
TileIndex _cm_rail_track_endtile; ///< The end of a rail track; as hidden return from the rail build/remove command for GUI purposes.
|
||||
RailTypes _railtypes_hidden_mask;
|
||||
|
||||
/** Enum holding the signal offset in the sprite sheet according to the side it is representing. */
|
||||
@@ -66,12 +65,12 @@ enum SignalOffsets {
|
||||
*/
|
||||
void ResetRailTypes()
|
||||
{
|
||||
static_assert(lengthof(_original_railtypes) <= lengthof(_railtypes));
|
||||
static_assert(std::size(_original_railtypes) <= std::size(_railtypes));
|
||||
|
||||
auto insert = std::copy(std::begin(_original_railtypes), std::end(_original_railtypes), std::begin(_railtypes));
|
||||
std::fill(insert, std::end(_railtypes), RailTypeInfo{});
|
||||
|
||||
_railtypes_hidden_mask = RAILTYPES_NONE;
|
||||
_railtypes_hidden_mask = {};
|
||||
}
|
||||
|
||||
void ResolveRailTypeGUISprites(RailTypeInfo *rti)
|
||||
@@ -134,14 +133,13 @@ void InitRailTypes()
|
||||
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
||||
RailTypeInfo *rti = &_railtypes[rt];
|
||||
ResolveRailTypeGUISprites(rti);
|
||||
if (HasBit(rti->flags, RTF_HIDDEN)) SetBit(_railtypes_hidden_mask, rt);
|
||||
if (rti->flags.Test(RailTypeFlag::Hidden)) _railtypes_hidden_mask.Set(rt);
|
||||
}
|
||||
|
||||
_sorted_railtypes.clear();
|
||||
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
||||
if (_railtypes[rt].label != 0 && !HasBit(_railtypes_hidden_mask, rt)) {
|
||||
_sorted_railtypes.push_back(rt);
|
||||
}
|
||||
if (_railtypes[rt].label == 0) continue;
|
||||
_sorted_railtypes.push_back(rt);
|
||||
}
|
||||
std::sort(_sorted_railtypes.begin(), _sorted_railtypes.end(), CompareRailTypes);
|
||||
}
|
||||
@@ -161,11 +159,11 @@ RailType AllocateRailType(RailTypeLabel label)
|
||||
rti->alternate_labels.clear();
|
||||
|
||||
/* Make us compatible with ourself. */
|
||||
rti->powered_railtypes = (RailTypes)(1LL << rt);
|
||||
rti->compatible_railtypes = (RailTypes)(1LL << rt);
|
||||
rti->powered_railtypes = rt;
|
||||
rti->compatible_railtypes = rt;
|
||||
|
||||
/* We also introduce ourself. */
|
||||
rti->introduces_railtypes = (RailTypes)(1LL << rt);
|
||||
rti->introduces_railtypes = rt;
|
||||
|
||||
/* Default sort order; order of allocation, but with some
|
||||
* offsets so it's easier for NewGRF to pick a spot without
|
||||
@@ -425,7 +423,7 @@ static inline bool ValParamTrackOrientation(Track track)
|
||||
* @param auto_remove_signals false = error on signal in the way, true = auto remove signals when in the way
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType railtype, Track track, bool auto_remove_signals)
|
||||
CommandCost CmdBuildSingleRail(DoCommandFlags flags, TileIndex tile, RailType railtype, Track track, bool auto_remove_signals)
|
||||
{
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
|
||||
@@ -454,7 +452,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
|
||||
ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
cost.AddCost(ret.GetCost());
|
||||
|
||||
if (HasSignals(tile) && TracksOverlap(GetTrackBits(tile) | TrackToTrackBits(track))) {
|
||||
/* If adding the new track causes any overlap, all signals must be removed first */
|
||||
@@ -464,7 +462,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
if (HasTrack(tile, track_it) && HasSignalOnTrack(tile, track_it)) {
|
||||
CommandCost ret_remove_signals = Command<CMD_REMOVE_SINGLE_SIGNAL>::Do(flags, tile, track_it);
|
||||
if (ret_remove_signals.Failed()) return ret_remove_signals;
|
||||
cost.AddCost(ret_remove_signals);
|
||||
cost.AddCost(ret_remove_signals.GetCost());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -476,13 +474,13 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
if (HasPowerOnRail(GetRailType(tile), railtype)) {
|
||||
ret = Command<CMD_CONVERT_RAIL>::Do(flags, tile, tile, railtype, false);
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
cost.AddCost(ret.GetCost());
|
||||
} else {
|
||||
return CMD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
SetRailGroundType(tile, RAIL_GROUND_BARREN);
|
||||
TrackBits bits = GetTrackBits(tile);
|
||||
SetTrackBits(tile, bits | trackbit);
|
||||
@@ -547,7 +545,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
cost.AddCost(num_new_tram_pieces * RoadBuildCost(roadtype_tram));
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
MakeRoadCrossing(tile, road_owner, tram_owner, _current_company, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtype_road, roadtype_tram, GetTownIndex(tile));
|
||||
UpdateLevelCrossing(tile, false);
|
||||
MarkDirtyAdjacentLevelCrossingTiles(tile, GetCrossingRoadAxis(tile));
|
||||
@@ -579,18 +577,18 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
|
||||
CommandCost ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
cost.AddCost(ret.GetCost());
|
||||
|
||||
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
cost.AddCost(ret.GetCost());
|
||||
|
||||
if (water_ground) {
|
||||
cost.AddCost(-_price[PR_CLEAR_WATER]);
|
||||
cost.AddCost(_price[PR_CLEAR_ROUGH]);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
MakeRailNormal(tile, _current_company, trackbit, railtype);
|
||||
if (water_ground) {
|
||||
SetRailGroundType(tile, RAIL_GROUND_WATER);
|
||||
@@ -603,7 +601,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
MarkTileDirtyByTile(tile);
|
||||
AddTrackToSignalBuffer(tile, track, _current_company);
|
||||
YapfNotifyTrackLayoutChange(tile, track);
|
||||
@@ -621,7 +619,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
* @param track rail orientation
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track)
|
||||
CommandCost CmdRemoveSingleRail(DoCommandFlags flags, TileIndex tile, Track track)
|
||||
{
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
bool crossing = false;
|
||||
@@ -648,14 +646,14 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
|
||||
if (!(flags & DC_BANKRUPT)) {
|
||||
if (!flags.Test(DoCommandFlag::Bankrupt)) {
|
||||
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
|
||||
cost.AddCost(RailClearCost(GetRailType(tile)));
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(tile, GetCrossingRoadAxis(tile));
|
||||
|
||||
if (HasReservedTracks(tile, trackbit)) {
|
||||
@@ -696,7 +694,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
|
||||
cost.AddCost(Command<CMD_REMOVE_SINGLE_SIGNAL>::Do(flags, tile, track));
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
if (HasReservedTracks(tile, trackbit)) {
|
||||
v = GetTrainForReservation(tile, track);
|
||||
if (v != nullptr) FreeTrainTrackReservation(v);
|
||||
@@ -737,7 +735,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
|
||||
default: return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
/* if we got that far, 'owner' variable is set correctly */
|
||||
assert(Company::IsValidID(owner));
|
||||
|
||||
@@ -785,13 +783,13 @@ bool FloodHalftile(TileIndex t)
|
||||
TrackBits lower_track = CornerToTrackBits(OppositeCorner(GetHighestSlopeCorner(tileh)));
|
||||
|
||||
TrackBits to_remove = lower_track & rail_bits;
|
||||
if (to_remove != 0) {
|
||||
if (to_remove != TRACK_BIT_NONE) {
|
||||
Backup<CompanyID> cur_company(_current_company, OWNER_WATER);
|
||||
flooded = Command<CMD_REMOVE_SINGLE_RAIL>::Do(DC_EXEC, t, FindFirstTrack(to_remove)).Succeeded();
|
||||
flooded = Command<CMD_REMOVE_SINGLE_RAIL>::Do(DoCommandFlag::Execute, t, FindFirstTrack(to_remove)).Succeeded();
|
||||
cur_company.Restore();
|
||||
if (!flooded) return flooded; // not yet floodable
|
||||
rail_bits = rail_bits & ~to_remove;
|
||||
if (rail_bits == 0) {
|
||||
if (rail_bits == TRACK_BIT_NONE) {
|
||||
MakeShore(t);
|
||||
MarkTileDirtyByTile(t);
|
||||
return flooded;
|
||||
@@ -885,11 +883,11 @@ static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileInd
|
||||
* @param fail_on_obstacle false = build starting from and up to an obstacle, true = fail if an obstacle is found (used for AIs)
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
static CommandCost CmdRailTrackHelper(DoCommandFlag flags, TileIndex tile, TileIndex end_tile, RailType railtype, Track track, bool remove, bool auto_remove_signals, bool fail_on_obstacle)
|
||||
static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, TileIndex end_tile, RailType railtype, Track track, bool remove, bool auto_remove_signals, bool fail_on_obstacle)
|
||||
{
|
||||
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
||||
|
||||
_rail_track_endtile = INVALID_TILE; // CM
|
||||
_cm_rail_track_endtile = INVALID_TILE;
|
||||
|
||||
if ((!remove && !ValParamRailType(railtype)) || !ValParamTrackOrientation(track)) return CMD_ERROR;
|
||||
if (end_tile >= Map::Size() || tile >= Map::Size()) return CMD_ERROR;
|
||||
@@ -902,11 +900,13 @@ static CommandCost CmdRailTrackHelper(DoCommandFlag flags, TileIndex tile, TileI
|
||||
bool had_success = false;
|
||||
CommandCost last_error = CMD_ERROR;
|
||||
for (;;) {
|
||||
TileIndex last_endtile = _rail_track_endtile; // CM
|
||||
TileIndex last_endtile = _cm_rail_track_endtile; // CM
|
||||
ret = remove ? Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, TrackdirToTrack(trackdir)) : Command<CMD_BUILD_SINGLE_RAIL>::Do(flags, tile, railtype, TrackdirToTrack(trackdir), auto_remove_signals);
|
||||
if (!remove && !fail_on_obstacle && last_error.GetErrorMessage() == STR_ERROR_ALREADY_BUILT) had_success = true;
|
||||
|
||||
if (ret.Failed()) {
|
||||
last_error = ret;
|
||||
if (_rail_track_endtile == INVALID_TILE) _rail_track_endtile = last_endtile; // CM
|
||||
last_error = std::move(ret);
|
||||
if (_rail_track_endtile == INVALID_TILE) _cm_rail_track_endtile = last_endtile; // CM
|
||||
if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !remove) {
|
||||
if (fail_on_obstacle) return last_error;
|
||||
if (had_success) break; // Keep going if we haven't constructed any rail yet, skipping the start of the drag
|
||||
@@ -916,7 +916,7 @@ static CommandCost CmdRailTrackHelper(DoCommandFlag flags, TileIndex tile, TileI
|
||||
if (last_error.GetErrorMessage() == STR_ERROR_OWNED_BY && remove) break;
|
||||
} else {
|
||||
had_success = true;
|
||||
total_cost.AddCost(ret);
|
||||
total_cost.AddCost(ret.GetCost());
|
||||
}
|
||||
|
||||
if (tile == end_tile) break;
|
||||
@@ -944,7 +944,7 @@ static CommandCost CmdRailTrackHelper(DoCommandFlag flags, TileIndex tile, TileI
|
||||
|
||||
* @see CmdRailTrackHelper
|
||||
*/
|
||||
CommandCost CmdBuildRailroadTrack(DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RailType railtype, Track track, bool auto_remove_signals, bool fail_on_obstacle)
|
||||
CommandCost CmdBuildRailroadTrack(DoCommandFlags flags, TileIndex end_tile, TileIndex start_tile, RailType railtype, Track track, bool auto_remove_signals, bool fail_on_obstacle)
|
||||
{
|
||||
return CmdRailTrackHelper(flags, start_tile, end_tile, railtype, track, false, auto_remove_signals, fail_on_obstacle);
|
||||
}
|
||||
@@ -959,7 +959,7 @@ CommandCost CmdBuildRailroadTrack(DoCommandFlag flags, TileIndex end_tile, TileI
|
||||
* @return the cost of this operation or an error
|
||||
* @see CmdRailTrackHelper
|
||||
*/
|
||||
CommandCost CmdRemoveRailroadTrack(DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, Track track)
|
||||
CommandCost CmdRemoveRailroadTrack(DoCommandFlags flags, TileIndex end_tile, TileIndex start_tile, Track track)
|
||||
{
|
||||
return CmdRailTrackHelper(flags, start_tile, end_tile, INVALID_RAILTYPE, track, true, false, false);
|
||||
}
|
||||
@@ -975,7 +975,7 @@ CommandCost CmdRemoveRailroadTrack(DoCommandFlag flags, TileIndex end_tile, Tile
|
||||
* @todo When checking for the tile slope,
|
||||
* distinguish between "Flat land required" and "land sloped in wrong direction"
|
||||
*/
|
||||
CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType railtype, DiagDirection dir)
|
||||
CommandCost CmdBuildTrainDepot(DoCommandFlags flags, TileIndex tile, RailType railtype, DiagDirection dir)
|
||||
{
|
||||
/* check railtype and valid direction for depot (0 through 3), 4 in total */
|
||||
if (!ValParamRailType(railtype) || !IsValidDiagDirection(dir)) return CMD_ERROR;
|
||||
@@ -1021,12 +1021,11 @@ CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
if (!Depot::CanAllocateItem()) return CMD_ERROR;
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
if (rotate_existing_depot) {
|
||||
SetRailDepotExitDirection(tile, dir);
|
||||
} else {
|
||||
Depot *d = new Depot(tile);
|
||||
d->build_date = TimerGameCalendar::date;
|
||||
|
||||
MakeRailDepot(tile, _current_company, d->index, dir, railtype);
|
||||
MakeDefaultName(d);
|
||||
@@ -1064,7 +1063,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, uint8_t signals_copy)
|
||||
CommandCost CmdBuildSingleSignal(DoCommandFlags 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;
|
||||
@@ -1116,7 +1115,7 @@ CommandCost CmdBuildSingleSignal(DoCommandFlag flags, TileIndex tile, Track trac
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
Train *v = nullptr;
|
||||
/* The new/changed signal could block our path. As this can lead to
|
||||
* stale reservations, we clear the path reservation here and try
|
||||
@@ -1201,7 +1200,7 @@ CommandCost CmdBuildSingleSignal(DoCommandFlag flags, TileIndex tile, Track trac
|
||||
YapfNotifyTrackLayoutChange(tile, track);
|
||||
if (v != nullptr && v->track != TRACK_BIT_DEPOT) {
|
||||
/* Extend the train's path if it's not stopped or loading, or not at a safe position. */
|
||||
if (!(((v->vehstatus & VS_STOPPED) && v->cur_speed == 0) || v->current_order.IsType(OT_LOADING)) ||
|
||||
if (!((v->vehstatus.Test(VehState::Stopped) && v->cur_speed == 0) || v->current_order.IsType(OT_LOADING)) ||
|
||||
!IsSafeWaitingPosition(v, v->tile, v->GetVehicleTrackdir(), true, _settings_game.pf.forbid_90_deg)) {
|
||||
TryPathReserve(v, true);
|
||||
}
|
||||
@@ -1270,7 +1269,7 @@ static bool AdvanceSignalAutoFill(TileIndex &tile, Trackdir &trackdir, bool remo
|
||||
* @param signal_density user defined signals_density
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, TileIndex end_tile, Track track, SignalType sigtype, SignalVariant sigvar, bool mode, bool remove, bool autofill, bool minimise_gaps, int signal_density)
|
||||
static CommandCost CmdSignalTrackHelper(DoCommandFlags flags, TileIndex tile, TileIndex end_tile, Track track, SignalType sigtype, SignalVariant sigvar, bool mode, bool remove, bool autofill, bool minimise_gaps, int signal_density)
|
||||
{
|
||||
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
||||
|
||||
@@ -1339,14 +1338,14 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, Til
|
||||
if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
|
||||
if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
|
||||
|
||||
DoCommandFlag do_flags = test_only ? flags & ~DC_EXEC : flags;
|
||||
DoCommandFlags do_flags = test_only ? DoCommandFlags{flags}.Reset(DoCommandFlag::Execute) : flags;
|
||||
CommandCost ret = remove ? Command<CMD_REMOVE_SINGLE_SIGNAL>::Do(do_flags, tile, TrackdirToTrack(trackdir)) : Command<CMD_BUILD_SINGLE_SIGNAL>::Do(do_flags, tile, TrackdirToTrack(trackdir), sigtype, sigvar, false, signal_ctr == 0, mode, SIGTYPE_BLOCK, SIGTYPE_BLOCK, 0, signals);
|
||||
|
||||
if (test_only) return ret.Succeeded();
|
||||
|
||||
if (ret.Succeeded()) {
|
||||
had_success = true;
|
||||
total_cost.AddCost(ret);
|
||||
total_cost.AddCost(ret.GetCost());
|
||||
} else {
|
||||
/* The "No railway" error is the least important one. */
|
||||
if (ret.GetErrorMessage() != STR_ERROR_THERE_IS_NO_RAILROAD_TRACK ||
|
||||
@@ -1461,7 +1460,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, uint8_t signal_density)
|
||||
CommandCost CmdBuildSignalTrack(DoCommandFlags 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);
|
||||
}
|
||||
@@ -1473,7 +1472,7 @@ CommandCost CmdBuildSignalTrack(DoCommandFlag flags, TileIndex tile, TileIndex e
|
||||
* @param track track-orientation
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdRemoveSingleSignal(DoCommandFlag flags, TileIndex tile, Track track)
|
||||
CommandCost CmdRemoveSingleSignal(DoCommandFlags flags, TileIndex tile, Track track)
|
||||
{
|
||||
if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) || !HasTrack(tile, track)) {
|
||||
return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
@@ -1489,7 +1488,7 @@ CommandCost CmdRemoveSingleSignal(DoCommandFlag flags, TileIndex tile, Track tra
|
||||
}
|
||||
|
||||
/* Do it? */
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
Train *v = nullptr;
|
||||
if (HasReservedTracks(tile, TrackToTrackBits(track))) {
|
||||
v = GetTrainForReservation(tile, track);
|
||||
@@ -1539,7 +1538,7 @@ CommandCost CmdRemoveSingleSignal(DoCommandFlag flags, TileIndex tile, Track tra
|
||||
* @return the cost of this operation or an error
|
||||
* @see CmdSignalTrackHelper
|
||||
*/
|
||||
CommandCost CmdRemoveSignalTrack(DoCommandFlag flags, TileIndex tile, TileIndex end_tile, Track track, bool autofill)
|
||||
CommandCost CmdRemoveSignalTrack(DoCommandFlags flags, TileIndex tile, TileIndex end_tile, Track track, bool autofill)
|
||||
{
|
||||
return CmdSignalTrackHelper(flags, tile, end_tile, track, SIGTYPE_BLOCK, SIG_ELECTRIC, false, true, autofill, false, 1); // bit 5 is remove bit
|
||||
}
|
||||
@@ -1565,7 +1564,7 @@ static Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
|
||||
* @param diagonal build diagonally or not.
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_start, RailType totype, bool diagonal)
|
||||
CommandCost CmdConvertRail(DoCommandFlags flags, TileIndex tile, TileIndex area_start, RailType totype, bool diagonal)
|
||||
{
|
||||
TileIndex area_end = tile;
|
||||
|
||||
@@ -1611,7 +1610,7 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||
/* Trying to convert other's rail */
|
||||
CommandCost ret = CheckTileOwnership(tile);
|
||||
if (ret.Failed()) {
|
||||
error = ret;
|
||||
error = std::move(ret);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1623,11 +1622,11 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||
if (!IsCompatibleRail(type, totype)) {
|
||||
ret = IsPlainRailTile(tile) ? EnsureNoTrainOnTrackBits(tile, GetTrackBits(tile)) : EnsureNoVehicleOnGround(tile);
|
||||
if (ret.Failed()) {
|
||||
error = ret;
|
||||
error = std::move(ret);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (flags & DC_EXEC) { // we can safely convert, too
|
||||
if (flags.Test(DoCommandFlag::Execute)) { // we can safely convert, too
|
||||
TrackBits reserved = GetReservedTrackbits(tile);
|
||||
Track track;
|
||||
while ((track = RemoveFirstTrack(&reserved)) != INVALID_TRACK) {
|
||||
@@ -1664,7 +1663,7 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||
case MP_RAILWAY:
|
||||
switch (GetRailTileType(tile)) {
|
||||
case RAIL_TILE_DEPOT:
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
/* notify YAPF about the track layout change */
|
||||
YapfNotifyTrackLayoutChange(tile, GetRailDepotTrack(tile));
|
||||
|
||||
@@ -1677,7 +1676,7 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||
break;
|
||||
|
||||
default: // RAIL_TILE_NORMAL, RAIL_TILE_SIGNALS
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
/* notify YAPF about the track layout change */
|
||||
TrackBits tracks = GetTrackBits(tile);
|
||||
while (tracks != TRACK_BIT_NONE) {
|
||||
@@ -1707,12 +1706,12 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||
if (!IsCompatibleRail(GetRailType(tile), totype)) {
|
||||
ret = TunnelBridgeIsFree(tile, endtile);
|
||||
if (ret.Failed()) {
|
||||
error = ret;
|
||||
error = std::move(ret);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
Track track = DiagDirToDiagTrack(GetTunnelBridgeDirection(tile));
|
||||
if (HasTunnelBridgeReservation(tile)) {
|
||||
Train *v = GetTrainForReservation(tile, track);
|
||||
@@ -1753,7 +1752,7 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||
}
|
||||
|
||||
default: // MP_STATION, MP_ROAD
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
Track track = ((tt == MP_STATION) ? GetRailStationTrack(tile) : GetCrossingRailTrack(tile));
|
||||
YapfNotifyTrackLayoutChange(tile, track);
|
||||
}
|
||||
@@ -1768,7 +1767,7 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
/* Railtype changed, update trains as when entering different track */
|
||||
for (Train *v : affected_trains) {
|
||||
v->ConsistChanged(CCF_TRACK);
|
||||
@@ -1778,7 +1777,7 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||
return found_convertible_track ? cost : error;
|
||||
}
|
||||
|
||||
static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)
|
||||
static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlags flags)
|
||||
{
|
||||
if (_current_company != OWNER_WATER) {
|
||||
CommandCost ret = CheckTileOwnership(tile);
|
||||
@@ -1788,7 +1787,7 @@ static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)
|
||||
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
/* read variables before the depot is removed */
|
||||
DiagDirection dir = GetRailDepotDirection(tile);
|
||||
Owner owner = GetTileOwner(tile);
|
||||
@@ -1812,11 +1811,11 @@ static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)
|
||||
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_TRAIN]);
|
||||
}
|
||||
|
||||
static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
|
||||
static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlags flags)
|
||||
{
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
|
||||
if (flags & DC_AUTO) {
|
||||
if (flags.Test(DoCommandFlag::Auto)) {
|
||||
if (!IsTileOwner(tile, _current_company)) {
|
||||
return CommandCost(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
|
||||
}
|
||||
@@ -1840,17 +1839,17 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
|
||||
Track track = RemoveFirstTrack(&tracks);
|
||||
CommandCost ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, track);
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
cost.AddCost(ret.GetCost());
|
||||
}
|
||||
|
||||
/* When bankrupting, don't make water dirty, there could be a ship on lower halftile.
|
||||
* Same holds for non-companies clearing the tile, e.g. disasters. */
|
||||
if (water_ground && !(flags & DC_BANKRUPT) && Company::IsValidID(_current_company)) {
|
||||
if (water_ground && !flags.Test(DoCommandFlag::Bankrupt) && Company::IsValidID(_current_company)) {
|
||||
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
/* The track was removed, and left a coast tile. Now also clear the water. */
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
DoClearSquare(tile);
|
||||
}
|
||||
cost.AddCost(_price[PR_CLEAR_WATER]);
|
||||
@@ -2124,7 +2123,7 @@ static void DrawTrackBitsOverlay(TileInfo *ti, TrackBits track, const RailTypeIn
|
||||
DrawGroundSprite(image, PAL_NONE);
|
||||
}
|
||||
|
||||
bool no_combine = ti->tileh == SLOPE_FLAT && HasBit(rti->flags, RTF_NO_SPRITE_COMBINE);
|
||||
bool no_combine = ti->tileh == SLOPE_FLAT && rti->flags.Test(RailTypeFlag::NoSpriteCombine);
|
||||
SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY);
|
||||
SpriteID ground = GetCustomRailSprite(rti, ti->tile, no_combine ? RTSG_GROUND_COMPLETE : RTSG_GROUND);
|
||||
TrackBits pbs = _settings_client.gui.show_track_reservation ? GetRailReservationTrackBits(ti->tile) : TRACK_BIT_NONE;
|
||||
@@ -2611,7 +2610,7 @@ static void TileLoop_Track(TileIndex tile)
|
||||
}
|
||||
|
||||
switch (_settings_game.game_creation.landscape) {
|
||||
case LT_ARCTIC: {
|
||||
case LandscapeType::Arctic: {
|
||||
auto [slope, z] = GetTileSlopeZ(tile);
|
||||
bool half = false;
|
||||
|
||||
@@ -2667,12 +2666,15 @@ static void TileLoop_Track(TileIndex tile)
|
||||
break;
|
||||
}
|
||||
|
||||
case LT_TROPIC:
|
||||
case LandscapeType::Tropic:
|
||||
if (GetTropicZone(tile) == TROPICZONE_DESERT) {
|
||||
new_ground = RAIL_GROUND_ICE_DESERT;
|
||||
goto set_ground;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
new_ground = RAIL_GROUND_GRASS;
|
||||
@@ -2793,15 +2795,15 @@ static bool ClickTile_Track(TileIndex tile)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
|
||||
static void GetTileDesc_Track(TileIndex tile, TileDesc &td)
|
||||
{
|
||||
const RailTypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
|
||||
td->rail_speed = rti->max_speed;
|
||||
td->railtype = rti->strings.name;
|
||||
td->owner[0] = GetTileOwner(tile);
|
||||
td.rail_speed = rti->max_speed;
|
||||
td.railtype = rti->strings.name;
|
||||
td.owner[0] = GetTileOwner(tile);
|
||||
switch (GetRailTileType(tile)) {
|
||||
case RAIL_TILE_NORMAL:
|
||||
td->str = STR_LAI_RAIL_DESCRIPTION_TRACK;
|
||||
td.str = STR_LAI_RAIL_DESCRIPTION_TRACK;
|
||||
break;
|
||||
|
||||
case RAIL_TILE_SIGNALS: {
|
||||
@@ -2865,20 +2867,20 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
|
||||
secondary_signal = primary_signal = GetSignalType(tile, TRACK_LOWER);
|
||||
}
|
||||
|
||||
td->str = signal_type[secondary_signal][primary_signal];
|
||||
td.str = signal_type[secondary_signal][primary_signal];
|
||||
break;
|
||||
}
|
||||
|
||||
case RAIL_TILE_DEPOT:
|
||||
td->str = STR_LAI_RAIL_DESCRIPTION_TRAIN_DEPOT;
|
||||
td.str = STR_LAI_RAIL_DESCRIPTION_TRAIN_DEPOT;
|
||||
if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL) {
|
||||
if (td->rail_speed > 0) {
|
||||
td->rail_speed = std::min<uint16_t>(td->rail_speed, 61);
|
||||
if (td.rail_speed > 0) {
|
||||
td.rail_speed = std::min<uint16_t>(td.rail_speed, 61);
|
||||
} else {
|
||||
td->rail_speed = 61;
|
||||
td.rail_speed = 61;
|
||||
}
|
||||
}
|
||||
td->build_date = Depot::GetByTile(tile)->build_date;
|
||||
td.build_date = Depot::GetByTile(tile)->build_date;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2910,7 +2912,7 @@ static void ChangeTileOwner_Track(TileIndex tile, Owner old_owner, Owner new_own
|
||||
|
||||
SetTileOwner(tile, new_owner);
|
||||
} else {
|
||||
Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile);
|
||||
Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Execute, DoCommandFlag::Bankrupt}, tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2975,7 +2977,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
|
||||
if (fract_coord_leave == fract_coord) {
|
||||
/* Leave the depot. */
|
||||
if ((v = v->Next()) != nullptr) {
|
||||
v->vehstatus &= ~VS_HIDDEN;
|
||||
v->vehstatus.Reset(VehState::Hidden);
|
||||
v->track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
|
||||
}
|
||||
}
|
||||
@@ -2983,7 +2985,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
|
||||
/* Entering depot. */
|
||||
assert(DiagDirToDir(ReverseDiagDir(dir)) == v->direction);
|
||||
v->track = TRACK_BIT_DEPOT,
|
||||
v->vehstatus |= VS_HIDDEN;
|
||||
v->vehstatus.Set(VehState::Hidden);
|
||||
v->direction = ReverseDir(v->direction);
|
||||
if (v->Next() == nullptr) VehicleEnterDepot(v->First());
|
||||
v->tile = tile;
|
||||
@@ -3006,7 +3008,7 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
|
||||
* @param tileh_new New TileSlope.
|
||||
* @param rail_bits Trackbits.
|
||||
*/
|
||||
static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, int z_old, Slope tileh_old, int z_new, Slope tileh_new, TrackBits rail_bits)
|
||||
static CommandCost TestAutoslopeOnRailTile(TileIndex tile, DoCommandFlags 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 CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
|
||||
@@ -3040,7 +3042,7 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, int z_old
|
||||
if (tileh_old != tileh_new) {
|
||||
/* If there is flat water on the lower halftile add the cost for clearing it */
|
||||
if (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old)) cost.AddCost(_price[PR_CLEAR_WATER]);
|
||||
if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
|
||||
if (flags.Test(DoCommandFlag::Execute)) SetRailGroundType(tile, RAIL_GROUND_BARREN);
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
@@ -3053,7 +3055,7 @@ static Vehicle *EnsureNoShipProc(Vehicle *v, void *)
|
||||
return v->type == VEH_SHIP ? v : nullptr;
|
||||
}
|
||||
|
||||
static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
|
||||
static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
|
||||
{
|
||||
auto [tileh_old, z_old] = GetTileSlopeZ(tile);
|
||||
if (IsPlainRail(tile)) {
|
||||
@@ -3089,7 +3091,7 @@ static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, int
|
||||
}
|
||||
|
||||
/* Make the ground dirty */
|
||||
if ((flags & DC_EXEC) != 0) SetRailGroundType(tile, RAIL_GROUND_BARREN);
|
||||
if (flags.Test(DoCommandFlag::Execute)) SetRailGroundType(tile, RAIL_GROUND_BARREN);
|
||||
|
||||
/* allow terraforming */
|
||||
return CommandCost(EXPENSES_CONSTRUCTION, was_water ? _price[PR_CLEAR_WATER] : (Money)0);
|
||||
|
||||
Reference in New Issue
Block a user