mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use EnumBitSet for VehicleRailFlags. (#14280)
parent
77d6f6c69f
commit
ce83f583bc
|
@ -432,7 +432,7 @@ void AddArticulatedParts(Vehicle *first)
|
|||
|
||||
if (flip_image) v->spritenum++;
|
||||
|
||||
if (v->type == VEH_TRAIN && TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed)) SetBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION);
|
||||
if (v->type == VEH_TRAIN && TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed)) Train::From(v)->flags.Set(VehicleRailFlag::Flipped);
|
||||
v->UpdatePosition();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -373,7 +373,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
|
|||
}
|
||||
|
||||
/* Try to reverse the vehicle, but do not care if it fails as the new type might not be reversible */
|
||||
if (new_veh->type == VEH_TRAIN && HasBit(Train::From(old_veh)->flags, VRF_REVERSE_DIRECTION)) {
|
||||
if (new_veh->type == VEH_TRAIN && Train::From(old_veh)->flags.Test(VehicleRailFlag::Flipped)) {
|
||||
Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DoCommandFlag::Execute, new_veh->index, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -623,7 +623,7 @@ void UpdateDisableElrailSettingState(bool disable, bool update_vehicles)
|
|||
* so add there also normal rail compatibility */
|
||||
t->compatible_railtypes.Set(RAILTYPE_RAIL);
|
||||
t->railtype = RAILTYPE_RAIL;
|
||||
SetBit(t->flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL);
|
||||
t->flags.Set(VehicleRailFlag::AllowedOnNormalRail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -717,7 +717,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
|||
|
||||
if (v->type == VEH_TRAIN) {
|
||||
const Train *t = Train::From(v);
|
||||
bool is_powered_wagon = HasBit(t->flags, VRF_POWEREDWAGON);
|
||||
bool is_powered_wagon = t->flags.Test(VehicleRailFlag::PoweredWagon);
|
||||
const Train *u = is_powered_wagon ? t->First() : t; // for powered wagons the engine defines the type of engine (i.e. railtype)
|
||||
RailType railtype = GetRailType(v->tile);
|
||||
bool powered = t->IsEngine() || is_powered_wagon;
|
||||
|
@ -725,7 +725,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
|||
|
||||
if (powered && has_power) SetBit(modflags, 5);
|
||||
if (powered && !has_power) SetBit(modflags, 6);
|
||||
if (HasBit(t->flags, VRF_TOGGLE_REVERSE)) SetBit(modflags, 8);
|
||||
if (t->flags.Test(VehicleRailFlag::Reversed)) SetBit(modflags, 8);
|
||||
}
|
||||
if (v->vehicle_flags.Test(VehicleFlag::CargoUnloading)) SetBit(modflags, 1);
|
||||
if (v->vehicle_flags.Test(VehicleFlag::BuiltAsPrototype)) SetBit(modflags, 10);
|
||||
|
@ -839,7 +839,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
|||
case 0x47: return GB(v->GetEngine()->grf_prop.local_id, 8, 8);
|
||||
case 0x48:
|
||||
if (v->type != VEH_TRAIN || v->spritenum != CUSTOM_VEHICLE_SPRITENUM) return v->spritenum;
|
||||
return HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION) ? CUSTOM_VEHICLE_SPRITENUM_REVERSED : CUSTOM_VEHICLE_SPRITENUM;
|
||||
return Train::From(v)->flags.Test(VehicleRailFlag::Flipped) ? CUSTOM_VEHICLE_SPRITENUM_REVERSED : CUSTOM_VEHICLE_SPRITENUM;
|
||||
|
||||
case 0x49: return v->day_counter;
|
||||
case 0x4A: return v->breakdowns_since_last_service;
|
||||
|
|
|
@ -2655,9 +2655,9 @@ bool AfterLoadGame()
|
|||
if (IsSavegameVersionBefore(SLV_156)) {
|
||||
/* The train's pathfinder lost flag got moved. */
|
||||
for (Train *t : Train::Iterate()) {
|
||||
if (!HasBit(t->flags, 5)) continue;
|
||||
if (!t->flags.Test(VehicleRailFlag{5})) continue;
|
||||
|
||||
ClrBit(t->flags, 5);
|
||||
t->flags.Reset(VehicleRailFlag{5});
|
||||
t->vehicle_flags.Set(VehicleFlag::PathfinderLost);
|
||||
}
|
||||
|
||||
|
@ -2696,8 +2696,8 @@ bool AfterLoadGame()
|
|||
* It was changed in savegame version 139, but savegame
|
||||
* version 158 doesn't use these bits, so it doesn't hurt
|
||||
* to clear them unconditionally. */
|
||||
ClrBit(t->flags, 1);
|
||||
ClrBit(t->flags, 2);
|
||||
t->flags.Reset(VehicleRailFlag{1});
|
||||
t->flags.Reset(VehicleRailFlag{2});
|
||||
|
||||
/* Clear both bits first. */
|
||||
ClrBit(t->gv_flags, GVF_GOINGUP_BIT);
|
||||
|
|
25
src/train.h
25
src/train.h
|
@ -22,16 +22,17 @@
|
|||
struct Train;
|
||||
|
||||
/** Rail vehicle flags. */
|
||||
enum VehicleRailFlags : uint8_t {
|
||||
VRF_REVERSING = 0,
|
||||
VRF_POWEREDWAGON = 3, ///< Wagon is powered.
|
||||
VRF_REVERSE_DIRECTION = 4, ///< Reverse the visible direction of the vehicle.
|
||||
enum VehicleRailFlag : uint8_t {
|
||||
Reversing = 0, ///< Train is slowing down to reverse.
|
||||
PoweredWagon = 3, ///< Wagon is powered.
|
||||
Flipped = 4, ///< Reverse the visible direction of the vehicle.
|
||||
|
||||
VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL = 6, ///< Electric train engine is allowed to run on normal rail. */
|
||||
VRF_TOGGLE_REVERSE = 7, ///< Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle only).
|
||||
VRF_TRAIN_STUCK = 8, ///< Train can't get a path reservation.
|
||||
VRF_LEAVING_STATION = 9, ///< Train is just leaving a station.
|
||||
AllowedOnNormalRail = 6, ///< Electric train engine is allowed to run on normal rail. */
|
||||
Reversed = 7, ///< Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle only).
|
||||
Stuck = 8, ///< Train can't get a path reservation.
|
||||
LeavingStation = 9, ///< Train is just leaving a station.
|
||||
};
|
||||
using VehicleRailFlags = EnumBitSet<VehicleRailFlag, uint16_t>;
|
||||
|
||||
/** Modes for ignoring signals. */
|
||||
enum TrainForceProceeding : uint8_t {
|
||||
|
@ -88,7 +89,7 @@ struct TrainCache {
|
|||
* 'Train' is either a loco or a wagon.
|
||||
*/
|
||||
struct Train final : public GroundVehicle<Train, VEH_TRAIN> {
|
||||
uint16_t flags = 0;
|
||||
VehicleRailFlags flags{};
|
||||
uint16_t crash_anim_pos = 0; ///< Crash animation counter.
|
||||
uint16_t wait_counter = 0; ///< Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals.
|
||||
|
||||
|
@ -205,7 +206,7 @@ protected: // These functions should not be called outside acceleration code.
|
|||
inline uint16_t GetPoweredPartPower(const Train *head) const
|
||||
{
|
||||
/* For powered wagons the engine defines the type of engine (i.e. railtype) */
|
||||
if (HasBit(this->flags, VRF_POWEREDWAGON) && HasPowerOnRail(head->railtype, GetRailType(this->tile))) {
|
||||
if (this->flags.Test(VehicleRailFlag::PoweredWagon) && HasPowerOnRail(head->railtype, GetRailType(this->tile))) {
|
||||
return RailVehInfo(this->gcache.first_engine)->pow_wag_power;
|
||||
}
|
||||
|
||||
|
@ -226,7 +227,7 @@ protected: // These functions should not be called outside acceleration code.
|
|||
}
|
||||
|
||||
/* Powered wagons have extra weight added. */
|
||||
if (HasBit(this->flags, VRF_POWEREDWAGON)) {
|
||||
if (this->flags.Test(VehicleRailFlag::PoweredWagon)) {
|
||||
weight += RailVehInfo(this->gcache.first_engine)->pow_wag_weight;
|
||||
}
|
||||
|
||||
|
@ -273,7 +274,7 @@ protected: // These functions should not be called outside acceleration code.
|
|||
*/
|
||||
inline AccelStatus GetAccelerationStatus() const
|
||||
{
|
||||
return this->vehstatus.Test(VehState::Stopped) || HasBit(this->flags, VRF_REVERSING) || HasBit(this->flags, VRF_TRAIN_STUCK) ? AS_BRAKE : AS_ACCEL;
|
||||
return this->vehstatus.Test(VehState::Stopped) || this->flags.Any({VehicleRailFlag::Reversing, VehicleRailFlag::Stuck}) ? AS_BRAKE : AS_ACCEL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -163,9 +163,9 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
|
|||
if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RAILVEH_WAGON &&
|
||||
UsesWagonOverride(u) && !HasBit(u->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER)) {
|
||||
/* wagon is powered */
|
||||
SetBit(u->flags, VRF_POWEREDWAGON); // cache 'powered' status
|
||||
u->flags.Set(VehicleRailFlag::PoweredWagon); // cache 'powered' status
|
||||
} else {
|
||||
ClrBit(u->flags, VRF_POWEREDWAGON);
|
||||
u->flags.Reset(VehicleRailFlag::PoweredWagon);
|
||||
}
|
||||
|
||||
if (!u->IsArticulatedPart()) {
|
||||
|
@ -177,7 +177,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
|
|||
|
||||
/* Some electric engines can be allowed to run on normal rail. It happens to all
|
||||
* existing electric engines when elrails are disabled and then re-enabled */
|
||||
if (HasBit(u->flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL)) {
|
||||
if (u->flags.Test(VehicleRailFlag::AllowedOnNormalRail)) {
|
||||
u->railtype = RAILTYPE_RAIL;
|
||||
u->compatible_railtypes.Set(RAILTYPE_RAIL);
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ void Train::UpdateAcceleration()
|
|||
|
||||
int Train::GetCursorImageOffset() const
|
||||
{
|
||||
if (this->gcache.cached_veh_length != 8 && HasBit(this->flags, VRF_REVERSE_DIRECTION) && !EngInfo(this->engine_type)->misc_flags.Test(EngineMiscFlag::RailFlips)) {
|
||||
if (this->gcache.cached_veh_length != 8 && this->flags.Test(VehicleRailFlag::Flipped) && !EngInfo(this->engine_type)->misc_flags.Test(EngineMiscFlag::RailFlips)) {
|
||||
int reference_width = TRAININFO_DEFAULT_VEHICLE_WIDTH;
|
||||
|
||||
const Engine *e = this->GetEngine();
|
||||
|
@ -467,7 +467,7 @@ int Train::GetDisplayImageWidth(Point *offset) const
|
|||
}
|
||||
|
||||
if (offset != nullptr) {
|
||||
if (HasBit(this->flags, VRF_REVERSE_DIRECTION) && !EngInfo(this->engine_type)->misc_flags.Test(EngineMiscFlag::RailFlips)) {
|
||||
if (this->flags.Test(VehicleRailFlag::Flipped) && !EngInfo(this->engine_type)->misc_flags.Test(EngineMiscFlag::RailFlips)) {
|
||||
offset->x = ScaleSpriteTrad(((int)this->gcache.cached_veh_length - (int)VEHICLE_LENGTH / 2) * reference_width / (int)VEHICLE_LENGTH);
|
||||
} else {
|
||||
offset->x = ScaleSpriteTrad(reference_width) / 2;
|
||||
|
@ -493,7 +493,7 @@ void Train::GetImage(Direction direction, EngineImageType image_type, VehicleSpr
|
|||
{
|
||||
uint8_t spritenum = this->spritenum;
|
||||
|
||||
if (HasBit(this->flags, VRF_REVERSE_DIRECTION)) direction = ReverseDir(direction);
|
||||
if (this->flags.Test(VehicleRailFlag::Flipped)) direction = ReverseDir(direction);
|
||||
|
||||
if (IsCustomVehicleSpriteNum(spritenum)) {
|
||||
if (spritenum == CUSTOM_VEHICLE_SPRITENUM_REVERSED) direction = ReverseDir(direction);
|
||||
|
@ -662,7 +662,7 @@ static CommandCost CmdBuildRailWagon(DoCommandFlags flags, TileIndex tile, const
|
|||
|
||||
v->group_id = DEFAULT_GROUP;
|
||||
|
||||
if (TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed)) SetBit(v->flags, VRF_REVERSE_DIRECTION);
|
||||
if (TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed)) v->flags.Set(VehicleRailFlag::Flipped);
|
||||
AddArticulatedParts(v);
|
||||
|
||||
v->UpdatePosition();
|
||||
|
@ -731,7 +731,7 @@ static void AddRearEngineToMultiheadedTrain(Train *v)
|
|||
v->SetMultiheaded();
|
||||
u->SetMultiheaded();
|
||||
v->SetNext(u);
|
||||
if (TestVehicleBuildProbability(u, u->engine_type, BuildProbabilityType::Reversed)) SetBit(u->flags, VRF_REVERSE_DIRECTION);
|
||||
if (TestVehicleBuildProbability(u, u->engine_type, BuildProbabilityType::Reversed)) u->flags.Set(VehicleRailFlag::Flipped);
|
||||
u->UpdatePosition();
|
||||
|
||||
/* Now we need to link the front and rear engines together */
|
||||
|
@ -804,7 +804,7 @@ CommandCost CmdBuildRailVehicle(DoCommandFlags flags, TileIndex tile, const Engi
|
|||
v->SetFrontEngine();
|
||||
v->SetEngine();
|
||||
|
||||
if (TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed)) SetBit(v->flags, VRF_REVERSE_DIRECTION);
|
||||
if (TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed)) v->flags.Set(VehicleRailFlag::Flipped);
|
||||
v->UpdatePosition();
|
||||
|
||||
if (rvi->railveh_type == RAILVEH_MULTIHEAD) {
|
||||
|
@ -1479,7 +1479,7 @@ void Train::UpdateDeltaXY()
|
|||
this->y_bb_offs = 0;
|
||||
|
||||
/* Set if flipped and engine is NOT flagged with custom flip handling. */
|
||||
int flipped = HasBit(this->flags, VRF_REVERSE_DIRECTION) && !EngInfo(this->engine_type)->misc_flags.Test(EngineMiscFlag::RailFlips);
|
||||
int flipped = this->flags.Test(VehicleRailFlag::Flipped) && !EngInfo(this->engine_type)->misc_flags.Test(EngineMiscFlag::RailFlips);
|
||||
/* If flipped and vehicle length is odd, we need to adjust the bounding box offset slightly. */
|
||||
int flip_offs = flipped && (this->gcache.cached_veh_length & 1);
|
||||
|
||||
|
@ -1545,9 +1545,9 @@ void Train::UpdateDeltaXY()
|
|||
*/
|
||||
static void MarkTrainAsStuck(Train *v)
|
||||
{
|
||||
if (!HasBit(v->flags, VRF_TRAIN_STUCK)) {
|
||||
if (!v->flags.Test(VehicleRailFlag::Stuck)) {
|
||||
/* It is the first time the problem occurred, set the "train stuck" flag. */
|
||||
SetBit(v->flags, VRF_TRAIN_STUCK);
|
||||
v->flags.Set(VehicleRailFlag::Stuck);
|
||||
|
||||
v->wait_counter = 0;
|
||||
|
||||
|
@ -1976,7 +1976,7 @@ void ReverseTrainDirection(Train *v)
|
|||
}
|
||||
|
||||
/* Clear path reservation in front if train is not stuck. */
|
||||
if (!HasBit(v->flags, VRF_TRAIN_STUCK)) FreeTrainTrackReservation(v);
|
||||
if (!v->flags.Test(VehicleRailFlag::Stuck)) FreeTrainTrackReservation(v);
|
||||
|
||||
/* Check if we were approaching a rail/road-crossing */
|
||||
TileIndex crossing = TrainApproachingCrossingTile(v);
|
||||
|
@ -1998,9 +1998,8 @@ void ReverseTrainDirection(Train *v)
|
|||
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
|
||||
}
|
||||
|
||||
ToggleBit(v->flags, VRF_TOGGLE_REVERSE);
|
||||
|
||||
ClrBit(v->flags, VRF_REVERSING);
|
||||
v->flags.Flip(VehicleRailFlag::Reversed);
|
||||
v->flags.Reset(VehicleRailFlag::Reversing);
|
||||
|
||||
/* recalculate cached data */
|
||||
v->ConsistChanged(CCF_TRACK);
|
||||
|
@ -2018,8 +2017,8 @@ void ReverseTrainDirection(Train *v)
|
|||
/* If we are inside a depot after reversing, don't bother with path reserving. */
|
||||
if (v->track == TRACK_BIT_DEPOT) {
|
||||
/* Can't be stuck here as inside a depot is always a safe tile. */
|
||||
if (HasBit(v->flags, VRF_TRAIN_STUCK)) SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
ClrBit(v->flags, VRF_TRAIN_STUCK);
|
||||
if (v->flags.Test(VehicleRailFlag::Stuck)) SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
v->flags.Reset(VehicleRailFlag::Stuck);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2046,9 +2045,9 @@ void ReverseTrainDirection(Train *v)
|
|||
/* Do not wait for a way out when we're still loading */
|
||||
MarkTrainAsStuck(v);
|
||||
}
|
||||
} else if (HasBit(v->flags, VRF_TRAIN_STUCK)) {
|
||||
} else if (v->flags.Test(VehicleRailFlag::Stuck)) {
|
||||
/* A train not inside a PBS block can't be stuck. */
|
||||
ClrBit(v->flags, VRF_TRAIN_STUCK);
|
||||
v->flags.Reset(VehicleRailFlag::Stuck);
|
||||
v->wait_counter = 0;
|
||||
}
|
||||
}
|
||||
|
@ -2082,7 +2081,7 @@ CommandCost CmdReverseTrainDirection(DoCommandFlags flags, VehicleID veh_id, boo
|
|||
}
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
ToggleBit(v->flags, VRF_REVERSE_DIRECTION);
|
||||
v->flags.Flip(VehicleRailFlag::Flipped);
|
||||
|
||||
front->ConsistChanged(CCF_ARRANGE);
|
||||
SetWindowDirty(WC_VEHICLE_DEPOT, front->tile);
|
||||
|
@ -2112,7 +2111,7 @@ CommandCost CmdReverseTrainDirection(DoCommandFlags flags, VehicleID veh_id, boo
|
|||
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
|
||||
|
||||
if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && v->cur_speed != 0) {
|
||||
ToggleBit(v->flags, VRF_REVERSING);
|
||||
v->flags.Flip(VehicleRailFlag::Reversing);
|
||||
} else {
|
||||
v->cur_speed = 0;
|
||||
v->SetLastSpeed();
|
||||
|
@ -2150,7 +2149,7 @@ CommandCost CmdForceTrainProceed(DoCommandFlags flags, VehicleID veh_id)
|
|||
* to proceed to the next signal. In the other cases we
|
||||
* would like to pass the signal at danger and run till the
|
||||
* next signal we encounter. */
|
||||
t->force_proceed = t->force_proceed == TFP_SIGNAL ? TFP_NONE : HasBit(t->flags, VRF_TRAIN_STUCK) || t->IsChainInDepot() ? TFP_STUCK : TFP_SIGNAL;
|
||||
t->force_proceed = t->force_proceed == TFP_SIGNAL ? TFP_NONE : t->flags.Test(VehicleRailFlag::Stuck) || t->IsChainInDepot() ? TFP_STUCK : TFP_SIGNAL;
|
||||
SetWindowDirty(WC_VEHICLE_VIEW, t->index);
|
||||
|
||||
/* Unbunching data is no longer valid. */
|
||||
|
@ -2899,8 +2898,8 @@ bool TryPathReserve(Train *v, bool mark_as_stuck, bool first_tile_okay)
|
|||
/* If we have a reserved path and the path ends at a safe tile, we are finished already. */
|
||||
if (origin.okay && (v->tile != origin.tile || first_tile_okay)) {
|
||||
/* Can't be stuck then. */
|
||||
if (HasBit(v->flags, VRF_TRAIN_STUCK)) SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
ClrBit(v->flags, VRF_TRAIN_STUCK);
|
||||
if (v->flags.Test(VehicleRailFlag::Stuck)) SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
v->flags.Reset(VehicleRailFlag::Stuck);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2925,11 +2924,11 @@ bool TryPathReserve(Train *v, bool mark_as_stuck, bool first_tile_okay)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (HasBit(v->flags, VRF_TRAIN_STUCK)) {
|
||||
if (v->flags.Test(VehicleRailFlag::Stuck)) {
|
||||
v->wait_counter = 0;
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
}
|
||||
ClrBit(v->flags, VRF_TRAIN_STUCK);
|
||||
v->flags.Reset(VehicleRailFlag::Stuck);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3118,7 +3117,7 @@ uint Train::Crash(bool flooded)
|
|||
|
||||
/* Remove the reserved path in front of the train if it is not stuck.
|
||||
* Also clear all reserved tracks the train is currently on. */
|
||||
if (!HasBit(this->flags, VRF_TRAIN_STUCK)) FreeTrainTrackReservation(this);
|
||||
if (!this->flags.Test(VehicleRailFlag::Stuck)) FreeTrainTrackReservation(this);
|
||||
for (const Train *v = this; v != nullptr; v = v->Next()) {
|
||||
ClearPathReservation(v, v->tile, v->GetVehicleTrackdir());
|
||||
if (IsTileType(v->tile, MP_TUNNELBRIDGE)) {
|
||||
|
@ -3347,7 +3346,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
|
|||
Trackdir i = FindFirstTrackdir(trackdirbits);
|
||||
|
||||
/* Don't handle stuck trains here. */
|
||||
if (HasBit(v->flags, VRF_TRAIN_STUCK)) return false;
|
||||
if (v->flags.Test(VehicleRailFlag::Stuck)) return false;
|
||||
|
||||
if (!HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(i))) {
|
||||
v->cur_speed = 0;
|
||||
|
@ -3921,14 +3920,14 @@ static bool TrainLocoHandler(Train *v, bool mode)
|
|||
}
|
||||
|
||||
if (v->force_proceed != TFP_NONE) {
|
||||
ClrBit(v->flags, VRF_TRAIN_STUCK);
|
||||
v->flags.Reset(VehicleRailFlag::Stuck);
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
}
|
||||
|
||||
/* train is broken down? */
|
||||
if (v->HandleBreakdown()) return true;
|
||||
|
||||
if (HasBit(v->flags, VRF_REVERSING) && v->cur_speed == 0) {
|
||||
if (v->flags.Test(VehicleRailFlag::Reversing) && v->cur_speed == 0) {
|
||||
ReverseTrainDirection(v);
|
||||
}
|
||||
|
||||
|
@ -3940,10 +3939,10 @@ static bool TrainLocoHandler(Train *v, bool mode)
|
|||
v->wait_counter = 0;
|
||||
v->cur_speed = 0;
|
||||
v->subspeed = 0;
|
||||
ClrBit(v->flags, VRF_LEAVING_STATION);
|
||||
v->flags.Reset(VehicleRailFlag::LeavingStation);
|
||||
ReverseTrainDirection(v);
|
||||
return true;
|
||||
} else if (HasBit(v->flags, VRF_LEAVING_STATION)) {
|
||||
} else if (v->flags.Test(VehicleRailFlag::LeavingStation)) {
|
||||
/* Try to reserve a path when leaving the station as we
|
||||
* might not be marked as wanting a reservation, e.g.
|
||||
* when an overlength train gets turned around in a station. */
|
||||
|
@ -3953,7 +3952,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
|
|||
if (UpdateSignalsOnSegment(v->tile, dir, v->owner) == SIGSEG_PBS || _settings_game.pf.reserve_paths) {
|
||||
TryPathReserve(v, true, true);
|
||||
}
|
||||
ClrBit(v->flags, VRF_LEAVING_STATION);
|
||||
v->flags.Reset(VehicleRailFlag::LeavingStation);
|
||||
}
|
||||
|
||||
v->HandleLoading(mode);
|
||||
|
@ -3970,7 +3969,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
|
|||
}
|
||||
|
||||
/* Handle stuck trains. */
|
||||
if (!mode && HasBit(v->flags, VRF_TRAIN_STUCK)) {
|
||||
if (!mode && v->flags.Test(VehicleRailFlag::Stuck)) {
|
||||
++v->wait_counter;
|
||||
|
||||
/* Should we try reversing this tick if still stuck? */
|
||||
|
@ -3981,7 +3980,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
|
|||
/* Still stuck. */
|
||||
if (turn_around) ReverseTrainDirection(v);
|
||||
|
||||
if (HasBit(v->flags, VRF_TRAIN_STUCK) && v->wait_counter > 2 * _settings_game.pf.wait_for_pbs_path * Ticks::DAY_TICKS) {
|
||||
if (v->flags.Test(VehicleRailFlag::Stuck) && v->wait_counter > 2 * _settings_game.pf.wait_for_pbs_path * Ticks::DAY_TICKS) {
|
||||
/* Show message to player. */
|
||||
if (_settings_client.gui.lost_vehicle_warn && v->owner == _local_company) {
|
||||
AddVehicleAdviceNewsItem(AdviceType::TrainStuck, GetEncodedString(STR_NEWS_TRAIN_IS_STUCK, v->index), v->index);
|
||||
|
@ -3990,7 +3989,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
|
|||
}
|
||||
/* Exit if force proceed not pressed, else reset stuck flag anyway. */
|
||||
if (v->force_proceed == TFP_NONE) return true;
|
||||
ClrBit(v->flags, VRF_TRAIN_STUCK);
|
||||
v->flags.Reset(VehicleRailFlag::Stuck);
|
||||
v->wait_counter = 0;
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
}
|
||||
|
@ -4219,7 +4218,7 @@ uint16_t Train::GetMaxWeight() const
|
|||
}
|
||||
|
||||
/* Powered wagons have extra weight added. */
|
||||
if (HasBit(this->flags, VRF_POWEREDWAGON)) {
|
||||
if (this->flags.Test(VehicleRailFlag::PoweredWagon)) {
|
||||
weight += RailVehInfo(this->gcache.first_engine)->pow_wag_weight;
|
||||
}
|
||||
|
||||
|
|
|
@ -1534,7 +1534,7 @@ void VehicleEnterDepot(Vehicle *v)
|
|||
UpdateSignalsOnSegment(t->tile, INVALID_DIAGDIR, t->owner);
|
||||
t->wait_counter = 0;
|
||||
t->force_proceed = TFP_NONE;
|
||||
ClrBit(t->flags, VRF_TOGGLE_REVERSE);
|
||||
t->flags.Reset(VehicleRailFlag::Reversed);
|
||||
t->ConsistChanged(CCF_ARRANGE);
|
||||
break;
|
||||
}
|
||||
|
@ -2361,7 +2361,7 @@ void Vehicle::LeaveStation()
|
|||
TriggerStationAnimation(st, this->tile, StationAnimationTrigger::VehicleDeparts);
|
||||
}
|
||||
|
||||
SetBit(Train::From(this)->flags, VRF_LEAVING_STATION);
|
||||
Train::From(this)->flags.Set(VehicleRailFlag::LeavingStation);
|
||||
}
|
||||
if (this->type == VEH_ROAD && !this->vehstatus.Test(VehState::Crashed)) {
|
||||
/* Trigger road stop animation */
|
||||
|
@ -2610,7 +2610,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlags flags, DepotCommandFlags command
|
|||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
|
||||
|
||||
/* If there is no depot in front and the train is not already reversing, reverse automatically (trains only) */
|
||||
if (this->type == VEH_TRAIN && (closest_depot.reverse ^ HasBit(Train::From(this)->flags, VRF_REVERSING))) {
|
||||
if (this->type == VEH_TRAIN && (closest_depot.reverse ^ Train::From(this)->flags.Test(VehicleRailFlag::Reversing))) {
|
||||
Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DoCommandFlag::Execute, this->index, false);
|
||||
}
|
||||
|
||||
|
@ -2720,7 +2720,7 @@ static void SpawnAdvancedVisualEffect(const Vehicle *v)
|
|||
}
|
||||
|
||||
Direction l_dir = v->direction;
|
||||
if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) l_dir = ReverseDir(l_dir);
|
||||
if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Flipped)) l_dir = ReverseDir(l_dir);
|
||||
Direction t_dir = ChangeDir(l_dir, DIRDIFF_90RIGHT);
|
||||
|
||||
int8_t x_center = _vehicle_smoke_pos[l_dir] * l_center;
|
||||
|
@ -2781,7 +2781,7 @@ void Vehicle::ShowVisualEffect() const
|
|||
* - the train is reversing
|
||||
* - is entering a station with an order to stop there and its speed is equal to maximum station entering speed
|
||||
*/
|
||||
if (HasBit(t->flags, VRF_REVERSING) ||
|
||||
if (t->flags.Test(VehicleRailFlag::Reversing) ||
|
||||
(IsRailStationTile(t->tile) && t->IsFrontEngine() && t->current_order.ShouldStopAtStation(t, GetStationIndex(t->tile)) &&
|
||||
t->cur_speed >= max_speed)) {
|
||||
return;
|
||||
|
@ -2890,7 +2890,7 @@ void Vehicle::ShowVisualEffect() const
|
|||
int x = _vehicle_smoke_pos[v->direction] * effect_offset;
|
||||
int y = _vehicle_smoke_pos[(v->direction + 2) % 8] * effect_offset;
|
||||
|
||||
if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) {
|
||||
if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Flipped)) {
|
||||
x = -x;
|
||||
y = -y;
|
||||
}
|
||||
|
|
|
@ -905,8 +905,8 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
|
|||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
w = Vehicle::Get(new_veh_id);
|
||||
|
||||
if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) {
|
||||
SetBit(Train::From(w)->flags, VRF_REVERSE_DIRECTION);
|
||||
if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Flipped)) {
|
||||
Train::From(w)->flags.Set(VehicleRailFlag::Flipped);
|
||||
}
|
||||
|
||||
if (v->type == VEH_TRAIN && !v->IsFrontEngine()) {
|
||||
|
|
|
@ -3135,7 +3135,7 @@ public:
|
|||
|
||||
if (v->IsInDepot() && v->IsWaitingForUnbunching()) return GetString(STR_VEHICLE_STATUS_WAITING_UNBUNCHING);
|
||||
|
||||
if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_TRAIN_STUCK) && !v->current_order.IsType(OT_LOADING)) return GetString(STR_VEHICLE_STATUS_TRAIN_STUCK);
|
||||
if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Stuck) && !v->current_order.IsType(OT_LOADING)) return GetString(STR_VEHICLE_STATUS_TRAIN_STUCK);
|
||||
|
||||
if (v->type == VEH_AIRCRAFT && HasBit(Aircraft::From(v)->flags, VAF_DEST_TOO_FAR) && !v->current_order.IsType(OT_LOADING)) return GetString(STR_VEHICLE_STATUS_AIRCRAFT_TOO_FAR);
|
||||
|
||||
|
@ -3143,7 +3143,7 @@ public:
|
|||
if (mouse_over_start_stop) {
|
||||
if (v->vehstatus.Test(VehState::Stopped)) {
|
||||
text_colour = TC_RED | TC_FORCED;
|
||||
} else if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_TRAIN_STUCK) && !v->current_order.IsType(OT_LOADING)) {
|
||||
} else if (v->type == VEH_TRAIN && Train::From(v)->flags.Test(VehicleRailFlag::Stuck) && !v->current_order.IsType(OT_LOADING)) {
|
||||
text_colour = TC_ORANGE | TC_FORCED;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue