mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use EnumBitSet for GroupFlags.
parent
4b573b2703
commit
5ef495da78
|
@ -65,7 +65,7 @@ void RemoveAllEngineReplacement(EngineRenewList *erl)
|
|||
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old)
|
||||
{
|
||||
const EngineRenew *er = GetEngineReplacement(erl, engine, group);
|
||||
if (er == nullptr && (group == DEFAULT_GROUP || (Group::IsValidID(group) && !HasFlag(Group::Get(group)->flags, GroupFlags::ReplaceProtection)))) {
|
||||
if (er == nullptr && (group == DEFAULT_GROUP || (Group::IsValidID(group) && !Group::Get(group)->flags.Test(GroupFlag::ReplaceProtection)))) {
|
||||
/* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */
|
||||
er = GetEngineReplacement(erl, engine, ALL_GROUP);
|
||||
}
|
||||
|
|
|
@ -754,7 +754,7 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlag flags, VehicleID veh_id)
|
|||
bool wagon_removal = c->settings.renew_keep_length;
|
||||
|
||||
const Group *g = Group::GetIfValid(v->group_id);
|
||||
if (g != nullptr) wagon_removal = HasFlag(g->flags, GroupFlags::ReplaceWagonRemoval);
|
||||
if (g != nullptr) wagon_removal = g->flags.Test(GroupFlag::ReplaceWagonRemoval);
|
||||
|
||||
/* Test whether any replacement is set, before issuing a whole lot of commands that would end in nothing changed */
|
||||
Vehicle *w = v;
|
||||
|
|
|
@ -405,7 +405,7 @@ public:
|
|||
bool remove_wagon;
|
||||
const Group *g = Group::GetIfValid(this->sel_group);
|
||||
if (g != nullptr) {
|
||||
remove_wagon = HasFlag(g->flags, GroupFlags::ReplaceWagonRemoval);
|
||||
remove_wagon = g->flags.Test(GroupFlag::ReplaceWagonRemoval);
|
||||
SetDParam(0, STR_GROUP_NAME);
|
||||
SetDParam(1, sel_group);
|
||||
} else {
|
||||
|
@ -554,7 +554,7 @@ public:
|
|||
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
|
||||
const Group *g = Group::GetIfValid(this->sel_group);
|
||||
if (g != nullptr) {
|
||||
Command<CMD_SET_GROUP_FLAG>::Post(this->sel_group, GroupFlags::ReplaceWagonRemoval, !HasFlag(g->flags, GroupFlags::ReplaceWagonRemoval), _ctrl_pressed);
|
||||
Command<CMD_SET_GROUP_FLAG>::Post(this->sel_group, GroupFlag::ReplaceWagonRemoval, !g->flags.Test(GroupFlag::ReplaceWagonRemoval), _ctrl_pressed);
|
||||
} else {
|
||||
// toggle renew_keep_length
|
||||
Command<CMD_CHANGE_COMPANY_SETTING>::Post("company.renew_keep_length", Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1);
|
||||
|
|
11
src/group.h
11
src/group.h
|
@ -62,12 +62,11 @@ struct GroupStatistics {
|
|||
static void UpdateAutoreplace(CompanyID company);
|
||||
};
|
||||
|
||||
enum class GroupFlags : uint8_t {
|
||||
None = 0,
|
||||
ReplaceProtection = 1U << 0, ///< If set, the global autoreplace has no effect on the group
|
||||
ReplaceWagonRemoval = 1U << 1, ///< If set, autoreplace will perform wagon removal on vehicles in this group.
|
||||
enum class GroupFlag : uint8_t {
|
||||
ReplaceProtection = 0, ///< If set, the global autoreplace has no effect on the group
|
||||
ReplaceWagonRemoval = 1, ///< If set, autoreplace will perform wagon removal on vehicles in this group.
|
||||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(GroupFlags)
|
||||
using GroupFlags = EnumBitSet<GroupFlag, uint8_t>;
|
||||
|
||||
/** Group data. */
|
||||
struct Group : GroupPool::PoolItem<&_group_pool> {
|
||||
|
@ -75,7 +74,7 @@ struct Group : GroupPool::PoolItem<&_group_pool> {
|
|||
Owner owner; ///< Group Owner
|
||||
VehicleType vehicle_type; ///< Vehicle type of the group
|
||||
|
||||
GroupFlags flags = GroupFlags::None; ///< Group flags
|
||||
GroupFlags flags{}; ///< Group flags
|
||||
Livery livery; ///< Custom colour scheme for vehicles in this group
|
||||
GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group.
|
||||
|
||||
|
|
|
@ -355,7 +355,7 @@ std::tuple<CommandCost, GroupID> CmdCreateGroup(DoCommandFlag flags, VehicleType
|
|||
if (pg == nullptr) {
|
||||
g->livery.colour1 = c->livery[LS_DEFAULT].colour1;
|
||||
g->livery.colour2 = c->livery[LS_DEFAULT].colour2;
|
||||
if (c->settings.renew_keep_length) g->flags |= GroupFlags::ReplaceWagonRemoval;
|
||||
if (c->settings.renew_keep_length) g->flags.Set(GroupFlag::ReplaceWagonRemoval);
|
||||
} else {
|
||||
g->parent = pg->index;
|
||||
g->livery.colour1 = pg->livery.colour1;
|
||||
|
@ -695,12 +695,12 @@ CommandCost CmdSetGroupLivery(DoCommandFlag flags, GroupID group_id, bool primar
|
|||
* @param g initial group.
|
||||
* @param set 1 to set or 0 to clear protection.
|
||||
*/
|
||||
static void SetGroupFlag(Group *g, GroupFlags flag, bool set, bool children)
|
||||
static void SetGroupFlag(Group *g, GroupFlag flag, bool set, bool children)
|
||||
{
|
||||
if (set) {
|
||||
g->flags |= flag;
|
||||
g->flags.Set(flag);
|
||||
} else {
|
||||
g->flags &= ~flag;
|
||||
g->flags.Reset(flag);
|
||||
}
|
||||
|
||||
if (!children) return;
|
||||
|
@ -719,12 +719,12 @@ static void SetGroupFlag(Group *g, GroupFlags flag, bool set, bool children)
|
|||
* @param recursive to apply to sub-groups.
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdSetGroupFlag(DoCommandFlag flags, GroupID group_id, GroupFlags flag, bool value, bool recursive)
|
||||
CommandCost CmdSetGroupFlag(DoCommandFlag flags, GroupID group_id, GroupFlag flag, bool value, bool recursive)
|
||||
{
|
||||
Group *g = Group::GetIfValid(group_id);
|
||||
if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
|
||||
|
||||
if (flag != GroupFlags::ReplaceProtection && flag != GroupFlags::ReplaceWagonRemoval) return CMD_ERROR;
|
||||
if (flag != GroupFlag::ReplaceProtection && flag != GroupFlag::ReplaceWagonRemoval) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
SetGroupFlag(g, flag, value, recursive);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "vehiclelist_cmd.h"
|
||||
|
||||
enum Colours : uint8_t;
|
||||
enum class GroupFlags : uint8_t;
|
||||
enum class GroupFlag : uint8_t;
|
||||
|
||||
/** Action for \c CmdAlterGroup. */
|
||||
enum class AlterGroupMode : uint8_t {
|
||||
|
@ -31,7 +31,7 @@ CommandCost CmdDeleteGroup(DoCommandFlag flags, GroupID group_id);
|
|||
std::tuple<CommandCost, GroupID> CmdAddVehicleGroup(DoCommandFlag flags, GroupID group_id, VehicleID veh_id, bool add_shared, const VehicleListIdentifier &vli);
|
||||
CommandCost CmdAddSharedVehicleGroup(DoCommandFlag flags, GroupID id_g, VehicleType type);
|
||||
CommandCost CmdRemoveAllVehiclesGroup(DoCommandFlag flags, GroupID group_id);
|
||||
CommandCost CmdSetGroupFlag(DoCommandFlag flags, GroupID group_id, GroupFlags flag, bool value, bool recursive);
|
||||
CommandCost CmdSetGroupFlag(DoCommandFlag flags, GroupID group_id, GroupFlag flag, bool value, bool recursive);
|
||||
CommandCost CmdSetGroupLivery(DoCommandFlag flags, GroupID group_id, bool primary, Colours colour);
|
||||
|
||||
DEF_CMD_TRAIT(CMD_CREATE_GROUP, CmdCreateGroup, 0, CMDT_ROUTE_MANAGEMENT)
|
||||
|
|
|
@ -584,7 +584,7 @@ public:
|
|||
|
||||
/* If not a default group and the group has replace protection, show an enabled replace sprite. */
|
||||
uint16_t protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
|
||||
if (!IsDefaultGroupID(this->vli.index) && !IsAllGroupID(this->vli.index) && HasFlag(Group::Get(this->vli.index)->flags, GroupFlags::ReplaceProtection)) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
|
||||
if (!IsDefaultGroupID(this->vli.index) && !IsAllGroupID(this->vli.index) && Group::Get(this->vli.index)->flags.Test(GroupFlag::ReplaceProtection)) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
|
||||
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(protect_sprite + this->vli.vtype);
|
||||
|
||||
/* Set text of "group by" dropdown widget. */
|
||||
|
@ -650,7 +650,7 @@ public:
|
|||
|
||||
assert(g->owner == this->owner);
|
||||
|
||||
DrawGroupInfo(y1, r.left, r.right, g->index, it->level_mask, it->indent, HasFlag(g->flags, GroupFlags::ReplaceProtection), g->folded || (std::next(it) != std::end(this->groups) && std::next(it)->indent > it->indent));
|
||||
DrawGroupInfo(y1, r.left, r.right, g->index, it->level_mask, it->indent, g->flags.Test(GroupFlag::ReplaceProtection), g->folded || (std::next(it) != std::end(this->groups) && std::next(it)->indent > it->indent));
|
||||
|
||||
y1 += this->tiny_step_height;
|
||||
}
|
||||
|
@ -868,7 +868,7 @@ public:
|
|||
case WID_GL_REPLACE_PROTECTION: {
|
||||
const Group *g = Group::GetIfValid(this->vli.index);
|
||||
if (g != nullptr) {
|
||||
Command<CMD_SET_GROUP_FLAG>::Post(this->vli.index, GroupFlags::ReplaceProtection, !HasFlag(g->flags, GroupFlags::ReplaceProtection), _ctrl_pressed);
|
||||
Command<CMD_SET_GROUP_FLAG>::Post(this->vli.index, GroupFlag::ReplaceProtection, !g->flags.Test(GroupFlag::ReplaceProtection), _ctrl_pressed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -3201,11 +3201,11 @@ bool AfterLoadGame()
|
|||
if (c->settings.renew_keep_length) SetBit(wagon_removal, c->index);
|
||||
}
|
||||
for (Group *g : Group::Iterate()) {
|
||||
if (to_underlying(g->flags) != 0) {
|
||||
if (g->flags != GroupFlags{}) {
|
||||
/* Convert old replace_protection value to flag. */
|
||||
g->flags = GroupFlags::ReplaceProtection;
|
||||
g->flags = GroupFlag::ReplaceProtection;
|
||||
}
|
||||
if (HasBit(wagon_removal, g->owner)) g->flags |= GroupFlags::ReplaceWagonRemoval;
|
||||
if (HasBit(wagon_removal, g->owner)) g->flags.Set(GroupFlag::ReplaceWagonRemoval);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -98,14 +98,14 @@
|
|||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||
|
||||
return ScriptObject::Command<CMD_SET_GROUP_FLAG>::Do(group_id, GroupFlags::ReplaceProtection, enable, false);
|
||||
return ScriptObject::Command<CMD_SET_GROUP_FLAG>::Do(group_id, GroupFlag::ReplaceProtection, enable, false);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGroup::GetAutoReplaceProtection(GroupID group_id)
|
||||
{
|
||||
if (!IsValidGroup(group_id)) return false;
|
||||
|
||||
return HasFlag(::Group::Get(group_id)->flags, GroupFlags::ReplaceProtection);
|
||||
return ::Group::Get(group_id)->flags.Test(GroupFlag::ReplaceProtection);
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptGroup::GetNumEngines(GroupID group_id, EngineID engine_id)
|
||||
|
|
Loading…
Reference in New Issue