Changeset - r25225:126e4a36a4eb
[Not reviewed]
master
0 6 0
peter1138 - 6 years ago 2019-03-29 23:44:28
peter1138@openttd.org
Codechange: Replace CMD_SET_GROUP_REPLACE_PROTECTION with generic CMD_SET_GROUP_FLAG.
6 files changed with 24 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/command.cpp
Show inline comments
 
@@ -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
src/command_type.h
Show inline comments
 
@@ -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
src/group.h
Show inline comments
 
@@ -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. */
src/group_cmd.cpp
Show inline comments
 
@@ -664,44 +664,50 @@ CommandCost CmdSetGroupLivery(TileIndex 
 
}
 

	
 
/**
 
 * 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);
src/group_gui.cpp
Show inline comments
 
@@ -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;
 
			}
src/script/api/script_group.cpp
Show inline comments
 
@@ -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)
0 comments (0 inline, 0 general)