Changeset - r25224:92a124f03ad6
[Not reviewed]
master
0 6 0
peter1138 - 6 years ago 2019-03-29 23:24:40
peter1138@openttd.org
Codechange: Replace Group::replace_protection with Group::flags
6 files changed with 23 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/autoreplace.cpp
Show inline comments
 
@@ -11,6 +11,7 @@
 
#include "command_func.h"
 
#include "group.h"
 
#include "autoreplace_base.h"
 
#include "core/bitmath_func.hpp"
 
#include "core/pool_func.hpp"
 

	
 
#include "safeguards.h"
 
@@ -64,7 +65,7 @@ void RemoveAllEngineReplacement(EngineRe
 
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) && !Group::Get(group)->replace_protection))) {
 
	if (er == nullptr && (group == DEFAULT_GROUP || (Group::IsValidID(group) && !HasBit(Group::Get(group)->flags, GroupFlags::GF_REPLACE_PROTECTION)))) {
 
		/* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */
 
		er = GetEngineReplacement(erl, engine, ALL_GROUP);
 
	}
src/group.h
Show inline comments
 
@@ -62,13 +62,17 @@ struct GroupStatistics {
 
	static void UpdateAutoreplace(CompanyID company);
 
};
 

	
 
enum GroupFlags : uint8 {
 
	GF_REPLACE_PROTECTION, ///< If set to true, the global autoreplace has no effect on the group
 
};
 

	
 
/** Group data. */
 
struct Group : GroupPool::PoolItem<&_group_pool> {
 
	std::string name;           ///< Group Name
 
	Owner owner;                ///< Group Owner
 
	VehicleType vehicle_type;   ///< Vehicle type of the group
 

	
 
	bool replace_protection;    ///< If set to true, the global autoreplace have no effect on the group
 
	uint8 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.
 

	
src/group_cmd.cpp
Show inline comments
 
@@ -315,7 +315,7 @@ CommandCost CmdCreateGroup(TileIndex til
 

	
 
	if (flags & DC_EXEC) {
 
		Group *g = new Group(_current_company);
 
		g->replace_protection = false;
 
		ClrBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION);
 
		g->vehicle_type = vt;
 
		g->parent = INVALID_GROUP;
 

	
 
@@ -668,12 +668,18 @@ CommandCost CmdSetGroupLivery(TileIndex 
 
 * @param g initial group.
 
 * @param protect 1 to set or 0 to clear protection.
 
 */
 
static void SetGroupReplaceProtection(Group *g, bool protect)
 
static void SetGroupReplaceProtection(Group *g, bool protect, bool children)
 
{
 
	g->replace_protection = protect;
 
	if (protect) {
 
		SetBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION);
 
	} else {
 
		ClrBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION);
 
	}
 

	
 
	if (!children) return;
 

	
 
	for (Group *pg : Group::Iterate()) {
 
		if (pg->parent == g->index) SetGroupReplaceProtection(pg, protect);
 
		if (pg->parent == g->index) SetGroupReplaceProtection(pg, protect, true);
 
	}
 
}
 

	
 
@@ -695,11 +701,7 @@ CommandCost CmdSetGroupReplaceProtection
 
	if (g == nullptr || g->owner != _current_company) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (HasBit(p2, 1)) {
 
			SetGroupReplaceProtection(g, HasBit(p2, 0));
 
		} else {
 
			g->replace_protection = HasBit(p2, 0);
 
		}
 
		SetGroupReplaceProtection(g, 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
 
@@ -533,7 +533,7 @@ public:
 

	
 
		/* If not a default group and the group has replace protection, show an enabled replace sprite. */
 
		uint16 protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
 
		if (!IsDefaultGroupID(this->vli.index) && !IsAllGroupID(this->vli.index) && Group::Get(this->vli.index)->replace_protection) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
 
		if (!IsDefaultGroupID(this->vli.index) && !IsAllGroupID(this->vli.index) && HasBit(Group::Get(this->vli.index)->flags, GroupFlags::GF_REPLACE_PROTECTION)) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
 
		this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype;
 

	
 
		/* Set text of "group by" dropdown widget. */
 
@@ -601,7 +601,7 @@ public:
 

	
 
					assert(g->owner == this->owner);
 

	
 
					DrawGroupInfo(y1, r.left, r.right, g->index, this->indents[i] * LEVEL_WIDTH, g->replace_protection, g->folded || (i + 1 < (int)this->groups.size() && indents[i + 1] > this->indents[i]));
 
					DrawGroupInfo(y1, r.left, r.right, g->index, this->indents[i] * LEVEL_WIDTH, HasBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION), g->folded || (i + 1 < (int)this->groups.size() && indents[i + 1] > this->indents[i]));
 

	
 
					y1 += this->tiny_step_height;
 
				}
 
@@ -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, (g->replace_protection ? 0 : 1) | (_ctrl_pressed << 1), CMD_SET_GROUP_REPLACE_PROTECTION);
 
					DoCommandP(0, this->vli.index, (HasBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION) ? 0 : 1) | (_ctrl_pressed << 1), CMD_SET_GROUP_REPLACE_PROTECTION);
 
				}
 
				break;
 
			}
src/saveload/group_sl.cpp
Show inline comments
 
@@ -21,7 +21,7 @@ static const SaveLoad _group_desc[] = {
 
	SLE_CONDNULL(2,                                                         SL_MIN_VERSION,  SLV_164), // num_vehicle
 
	     SLE_VAR(Group, owner,              SLE_UINT8),
 
	     SLE_VAR(Group, vehicle_type,       SLE_UINT8),
 
	     SLE_VAR(Group, replace_protection, SLE_BOOL),
 
	     SLE_VAR(Group, flags,              SLE_UINT8),
 
	 SLE_CONDVAR(Group, livery.in_use,      SLE_UINT8,                     SLV_GROUP_LIVERIES, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Group, livery.colour1,     SLE_UINT8,                     SLV_GROUP_LIVERIES, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Group, livery.colour2,     SLE_UINT8,                     SLV_GROUP_LIVERIES, SL_MAX_VERSION),
src/script/api/script_group.cpp
Show inline comments
 
@@ -96,7 +96,7 @@
 
{
 
	if (!IsValidGroup(group_id)) return false;
 

	
 
	return ::Group::Get(group_id)->replace_protection;
 
	return HasBit(::Group::Get(group_id)->flags, GroupFlags::GF_REPLACE_PROTECTION);
 
}
 

	
 
/* static */ int32 ScriptGroup::GetNumEngines(GroupID group_id, EngineID engine_id)
0 comments (0 inline, 0 general)