mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use EnumBitSet for ConsistChangeFlags. (#13788)
parent
de45f5418b
commit
7c97460080
23
src/train.h
23
src/train.h
|
@ -41,18 +41,19 @@ enum TrainForceProceeding : uint8_t {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Flags for Train::ConsistChanged */
|
/** Flags for Train::ConsistChanged */
|
||||||
enum ConsistChangeFlags : uint8_t {
|
enum class ConsistChangeFlag : uint8_t {
|
||||||
CCF_LENGTH = 0x01, ///< Allow vehicles to change length.
|
Length, ///< Allow vehicles to change length.
|
||||||
CCF_CAPACITY = 0x02, ///< Allow vehicles to change capacity.
|
Capacity, ///< Allow vehicles to change capacity.
|
||||||
|
|
||||||
CCF_TRACK = 0, ///< Valid changes while vehicle is driving, and possibly changing tracks.
|
|
||||||
CCF_LOADUNLOAD = 0, ///< Valid changes while vehicle is loading/unloading.
|
|
||||||
CCF_AUTOREFIT = CCF_CAPACITY, ///< Valid changes for autorefitting in stations.
|
|
||||||
CCF_REFIT = CCF_LENGTH | CCF_CAPACITY, ///< Valid changes for refitting in a depot.
|
|
||||||
CCF_ARRANGE = CCF_LENGTH | CCF_CAPACITY, ///< Valid changes for arranging the consist in a depot.
|
|
||||||
CCF_SAVELOAD = CCF_LENGTH, ///< Valid changes when loading a savegame. (Everything that is not stored in the save.)
|
|
||||||
};
|
};
|
||||||
DECLARE_ENUM_AS_BIT_SET(ConsistChangeFlags)
|
|
||||||
|
using ConsistChangeFlags = EnumBitSet<ConsistChangeFlag, uint8_t>;
|
||||||
|
|
||||||
|
static constexpr ConsistChangeFlags CCF_TRACK{}; ///< Valid changes while vehicle is driving, and possibly changing tracks.
|
||||||
|
static constexpr ConsistChangeFlags CCF_LOADUNLOAD{}; ///< Valid changes while vehicle is loading/unloading.
|
||||||
|
static constexpr ConsistChangeFlags CCF_AUTOREFIT{ConsistChangeFlag::Capacity}; ///< Valid changes for autorefitting in stations.
|
||||||
|
static constexpr ConsistChangeFlags CCF_REFIT{ConsistChangeFlag::Length, ConsistChangeFlag::Capacity}; ///< Valid changes for refitting in a depot.
|
||||||
|
static constexpr ConsistChangeFlags CCF_ARRANGE{ConsistChangeFlag::Length, ConsistChangeFlag::Capacity}; ///< Valid changes for arranging the consist in a depot.
|
||||||
|
static constexpr ConsistChangeFlags CCF_SAVELOAD{ConsistChangeFlag::Length}; ///< Valid changes when loading a savegame. (Everything that is not stored in the save.)
|
||||||
|
|
||||||
uint8_t FreightWagonMult(CargoType cargo);
|
uint8_t FreightWagonMult(CargoType cargo);
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t new_cap = e_u->DetermineCapacity(u);
|
uint16_t new_cap = e_u->DetermineCapacity(u);
|
||||||
if (allowed_changes & CCF_CAPACITY) {
|
if (allowed_changes.Test(ConsistChangeFlag::Capacity)) {
|
||||||
/* Update vehicle capacity. */
|
/* Update vehicle capacity. */
|
||||||
if (u->cargo_cap > new_cap) u->cargo.Truncate(new_cap);
|
if (u->cargo_cap > new_cap) u->cargo.Truncate(new_cap);
|
||||||
u->refit_cap = std::min(new_cap, u->refit_cap);
|
u->refit_cap = std::min(new_cap, u->refit_cap);
|
||||||
|
@ -217,7 +217,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
|
||||||
if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor;
|
if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor;
|
||||||
veh_len = VEHICLE_LENGTH - Clamp(veh_len, 0, VEHICLE_LENGTH - 1);
|
veh_len = VEHICLE_LENGTH - Clamp(veh_len, 0, VEHICLE_LENGTH - 1);
|
||||||
|
|
||||||
if (allowed_changes & CCF_LENGTH) {
|
if (allowed_changes.Test(ConsistChangeFlag::Length)) {
|
||||||
/* Update vehicle length. */
|
/* Update vehicle length. */
|
||||||
u->gcache.cached_veh_length = veh_len;
|
u->gcache.cached_veh_length = veh_len;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue