diff options
author | peter1138 <peter1138@openttd.org> | 2019-03-29 23:44:28 +0000 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-04-22 22:57:00 +0200 |
commit | c56fce70b440a95914bf374f68ac045ca97b3610 (patch) | |
tree | 38ce50aa9334ddb6bc9ea17c33b6c1c25d9d73fe | |
parent | 27a956ba6204e400e82fe10056bf730f286b23fe (diff) | |
download | openttd-c56fce70b440a95914bf374f68ac045ca97b3610.tar.xz |
Codechange: Replace CMD_SET_GROUP_REPLACE_PROTECTION with generic CMD_SET_GROUP_FLAG.
-rw-r--r-- | src/command.cpp | 4 | ||||
-rw-r--r-- | src/command_type.h | 2 | ||||
-rw-r--r-- | src/group.h | 1 | ||||
-rw-r--r-- | src/group_cmd.cpp | 30 | ||||
-rw-r--r-- | src/group_gui.cpp | 2 | ||||
-rw-r--r-- | src/script/api/script_group.cpp | 2 |
6 files changed, 24 insertions, 17 deletions
diff --git a/src/command.cpp b/src/command.cpp index 7c7ca13e4..dd6ce1cbf 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -193,7 +193,7 @@ CommandProc CmdDeleteGroup; CommandProc CmdAddVehicleGroup; CommandProc CmdAddSharedVehicleGroup; CommandProc CmdRemoveAllVehiclesGroup; -CommandProc CmdSetGroupReplaceProtection; +CommandProc CmdSetGroupFlag; CommandProc CmdSetGroupLivery; CommandProc CmdMoveOrder; @@ -359,7 +359,7 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdAddVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_VEHICLE_GROUP DEF_CMD(CmdAddSharedVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_SHARE_VEHICLE_GROUP DEF_CMD(CmdRemoveAllVehiclesGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_REMOVE_ALL_VEHICLES_GROUP - DEF_CMD(CmdSetGroupReplaceProtection, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_GROUP_REPLACE_PROTECTION + DEF_CMD(CmdSetGroupFlag, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_GROUP_FLAG DEF_CMD(CmdSetGroupLivery, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_GROUP_LIVERY DEF_CMD(CmdMoveOrder, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_MOVE_ORDER DEF_CMD(CmdChangeTimetable, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CHANGE_TIMETABLE diff --git a/src/command_type.h b/src/command_type.h index 2419d7b31..732932b7a 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -324,7 +324,7 @@ enum Commands { CMD_ADD_VEHICLE_GROUP, ///< add a vehicle to a group CMD_ADD_SHARED_VEHICLE_GROUP, ///< add all other shared vehicles to a group which are missing CMD_REMOVE_ALL_VEHICLES_GROUP, ///< remove all vehicles from a group - CMD_SET_GROUP_REPLACE_PROTECTION, ///< set the autoreplace-protection for a group + CMD_SET_GROUP_FLAG, ///< set/clear a flag for a group CMD_SET_GROUP_LIVERY, ///< set the livery for a group CMD_MOVE_ORDER, ///< move an order diff --git a/src/group.h b/src/group.h index 57d15b448..bd6f47bdf 100644 --- a/src/group.h +++ b/src/group.h @@ -64,6 +64,7 @@ struct GroupStatistics { enum GroupFlags : uint8 { GF_REPLACE_PROTECTION, ///< If set to true, the global autoreplace has no effect on the group + GF_END, }; /** Group data. */ diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 219470c20..2c2cfeaab 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -664,44 +664,50 @@ CommandCost CmdSetGroupLivery(TileIndex tile, DoCommandFlag flags, uint32 p1, ui } /** - * Set replace protection for a group and its sub-groups. + * Set group flag for a group and its sub-groups. * @param g initial group. - * @param protect 1 to set or 0 to clear protection. + * @param set 1 to set or 0 to clear protection. */ -static void SetGroupReplaceProtection(Group *g, bool protect, bool children) +static void SetGroupFlag(Group *g, GroupFlags flag, bool set, bool children) { - if (protect) { - SetBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION); + if (set) { + SetBit(g->flags, flag); } else { - ClrBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION); + ClrBit(g->flags, flag); } if (!children) return; for (Group *pg : Group::Iterate()) { - if (pg->parent == g->index) SetGroupReplaceProtection(pg, protect, true); + if (pg->parent == g->index) SetGroupFlag(pg, flag, set, true); } } /** - * (Un)set global replace protection from a group + * (Un)set group flag from a group * @param tile unused * @param flags type of operation * @param p1 index of group array - * - p1 bit 0-15 : GroupID + * - p1 bit 0-15 : GroupID + * - p1 bit 16-18 : Flag to set, by value not bit. * @param p2 * - p2 bit 0 : 1 to set or 0 to clear protection. * - p2 bit 1 : 1 to apply to sub-groups. * @param text unused * @return the cost of this operation or an error */ -CommandCost CmdSetGroupReplaceProtection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) +CommandCost CmdSetGroupFlag(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - Group *g = Group::GetIfValid(p1); + Group *g = Group::GetIfValid(GB(p1, 0, 16)); if (g == nullptr || g->owner != _current_company) return CMD_ERROR; + /* GroupFlags are stored in as an 8 bit bitfield but passed here by value, + * so 3 bits is sufficient to cover each possible value. */ + GroupFlags flag = (GroupFlags)GB(p1, 16, 3); + if (flag >= GroupFlags::GF_END) return CMD_ERROR; + if (flags & DC_EXEC) { - SetGroupReplaceProtection(g, HasBit(p2, 0), HasBit(p2, 1)); + SetGroupFlag(g, flag, HasBit(p2, 0), HasBit(p2, 1)); SetWindowDirty(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack()); InvalidateWindowData(WC_REPLACE_VEHICLE, g->vehicle_type); diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 0f463e030..1a6deae2c 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -798,7 +798,7 @@ public: case WID_GL_REPLACE_PROTECTION: { const Group *g = Group::GetIfValid(this->vli.index); if (g != nullptr) { - DoCommandP(0, this->vli.index, (HasBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION) ? 0 : 1) | (_ctrl_pressed << 1), CMD_SET_GROUP_REPLACE_PROTECTION); + DoCommandP(0, this->vli.index | (GroupFlags::GF_REPLACE_PROTECTION << 16), (HasBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION) ? 0 : 1) | (_ctrl_pressed << 1), CMD_SET_GROUP_FLAG); } break; } diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index ae2e4137b..9cf6c7c95 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -89,7 +89,7 @@ { EnforcePrecondition(false, IsValidGroup(group_id)); - return ScriptObject::DoCommand(0, group_id, enable ? 1 : 0, CMD_SET_GROUP_REPLACE_PROTECTION); + return ScriptObject::DoCommand(0, group_id | GroupFlags::GF_REPLACE_PROTECTION, enable ? 1 : 0, CMD_SET_GROUP_FLAG); } /* static */ bool ScriptGroup::GetAutoReplaceProtection(GroupID group_id) |