Changeset - r25226:099b6b8941ab
[Not reviewed]
master
0 6 0
peter1138 - 5 years ago 2019-03-30 07:13:08
peter1138@openttd.org
Feature: Per-group wagon removal flag.
6 files changed with 43 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -741,6 +741,9 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 
	const Company *c = Company::Get(_current_company);
 
	bool wagon_removal = c->settings.renew_keep_length;
 

	
 
	const Group *g = Group::GetIfValid(v->group_id);
 
	if (g != nullptr) wagon_removal = HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL);
 

	
 
	/* Test whether any replacement is set, before issuing a whole lot of commands that would end in nothing changed */
 
	Vehicle *w = v;
 
	bool any_replacements = false;
src/autoreplace_gui.cpp
Show inline comments
 
@@ -375,8 +375,15 @@ public:
 
				break;
 

	
 
			case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
 
				const Company *c = Company::Get(_local_company);
 
				SetDParam(0, c->settings.renew_keep_length ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
 
				bool remove_wagon;
 
				const Group *g = Group::GetIfValid(this->sel_group);
 
				if (g != nullptr) {
 
					remove_wagon = HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL);
 
				} else {
 
					const Company *c = Company::Get(_local_company);
 
					remove_wagon = c->settings.renew_keep_length;
 
				}
 
				SetDParam(0, remove_wagon ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
 
				break;
 
			}
 

	
 
@@ -528,9 +535,16 @@ public:
 
				}
 
				break;
 

	
 
			case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: // toggle renew_keep_length
 
				DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_CHANGE_COMPANY_SETTING);
 
			case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
 
				const Group *g = Group::GetIfValid(this->sel_group);
 
				if (g != nullptr) {
 
					DoCommandP(0, this->sel_group | (GroupFlags::GF_REPLACE_WAGON_REMOVAL << 16), (HasBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL) ? 0 : 1) | (_ctrl_pressed << 1), CMD_SET_GROUP_FLAG);
 
				} else {
 
					// toggle renew_keep_length
 
					DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_CHANGE_COMPANY_SETTING);
 
				}
 
				break;
 
			}
 

	
 
			case WID_RV_START_REPLACE: { // Start replacing
 
				if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
src/group.h
Show inline comments
 
@@ -63,7 +63,8 @@ struct GroupStatistics {
 
};
 

	
 
enum GroupFlags : uint8 {
 
	GF_REPLACE_PROTECTION, ///< If set to true, the global autoreplace has no effect on the group
 
	GF_REPLACE_PROTECTION,    ///< If set to true, the global autoreplace has no effect on the group
 
	GF_REPLACE_WAGON_REMOVAL, ///< If set, autoreplace will perform wagon removal on vehicles in this group.
 
	GF_END,
 
};
 

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

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

	
 
@@ -323,10 +322,12 @@ CommandCost CmdCreateGroup(TileIndex til
 
			const Company *c = Company::Get(_current_company);
 
			g->livery.colour1 = c->livery[LS_DEFAULT].colour1;
 
			g->livery.colour2 = c->livery[LS_DEFAULT].colour2;
 
			if (c->settings.renew_keep_length) SetBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL);
 
		} else {
 
			g->parent = pg->index;
 
			g->livery.colour1 = pg->livery.colour1;
 
			g->livery.colour2 = pg->livery.colour2;
 
			g->flags = pg->flags;
 
		}
 

	
 
		_new_group_id = g->index;
src/saveload/afterload.cpp
Show inline comments
 
@@ -3127,6 +3127,23 @@ bool AfterLoadGame()
 
		}
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_GROUP_REPLACE_WAGON_REMOVAL)) {
 
		/* Propagate wagon removal flag for compatibility */
 
		/* Temporary bitmask of company wagon removal setting */
 
		uint16 wagon_removal = 0;
 
		for (const Company *c : Company::Iterate()) {
 
			if (c->settings.renew_keep_length) SetBit(wagon_removal, c->index);
 
		}
 
		for (Group *g : Group::Iterate()) {
 
			if (g->flags != 0) {
 
				/* Convert old replace_protection value to flag. */
 
				g->flags = 0;
 
				SetBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION);
 
			}
 
			if (HasBit(wagon_removal, g->owner)) SetBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL);
 
		}
 
	}
 

	
 
	/* Compute station catchment areas. This is needed here in case UpdateStationAcceptance is called below. */
 
	Station::RecomputeCatchmentForAll();
 

	
src/saveload/saveload.h
Show inline comments
 
@@ -325,6 +325,7 @@ enum SaveLoadVersion : uint16 {
 
	SLV_VEH_MOTION_COUNTER,                 ///< 288  PR#8591 Desync safe motion counter
 
	SLV_INDUSTRY_TEXT,                      ///< 289  PR#8576 v1.11.0-RC1  Additional GS text for industries.
 
	SLV_MAPGEN_SETTINGS_REVAMP,             ///< 290  PR#8891 v1.11  Revamp of some mapgen settings (snow coverage, desert coverage, heightmap height, custom terrain type).
 
	SLV_GROUP_REPLACE_WAGON_REMOVAL,        ///< 291  PR#7441 Per-group wagon removal flag.
 

	
 
	SL_MAX_VERSION,                         ///< Highest possible saveload version
 
};
0 comments (0 inline, 0 general)