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
 
@@ -738,12 +738,15 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 
		if (!v->IsPrimaryVehicle()) return CMD_ERROR;
 
	}
 

	
 
	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;
 
	while (w != nullptr) {
 
		EngineID e;
 
		CommandCost cost = GetNewEngineType(w, c, false, e);
src/autoreplace_gui.cpp
Show inline comments
 
@@ -372,14 +372,21 @@ public:
 

	
 
			case WID_RV_SORT_DROPDOWN:
 
				SetDParam(0, _engine_sort_listing[this->window_number][this->sort_criteria]);
 
				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;
 
			}
 

	
 
			case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN:
 
				SetDParam(0, this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
 
				break;
 
@@ -525,15 +532,22 @@ public:
 
					case VEH_ROAD:
 
						ShowDropDownList(this, GetRoadTypeDropDownList(RTTB_ROAD | RTTB_TRAM, true, true), sel_roadtype, WID_RV_RAIL_ROAD_TYPE_DROPDOWN);
 
						break;
 
				}
 
				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)) {
 
					this->HandleButtonClick(WID_RV_START_REPLACE);
 
					ReplaceClick_StartReplace(false);
 
				} else {
src/group.h
Show inline comments
 
@@ -60,13 +60,14 @@ struct GroupStatistics {
 
	static void UpdateProfits();
 
	static void UpdateAfterLoad();
 
	static void UpdateAutoreplace(CompanyID company);
 
};
 

	
 
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,
 
};
 

	
 
/** Group data. */
 
struct Group : GroupPool::PoolItem<&_group_pool> {
 
	std::string name;           ///< Group Name
src/group_cmd.cpp
Show inline comments
 
@@ -312,24 +312,25 @@ CommandCost CmdCreateGroup(TileIndex til
 
		if (pg->owner != _current_company) return CMD_ERROR;
 
		if (pg->vehicle_type != vt) return CMD_ERROR;
 
	}
 

	
 
	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;
 

	
 
		if (pg == nullptr) {
 
			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;
 

	
 
		InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack());
 
		InvalidateWindowData(WC_COMPANY_COLOUR, g->owner, g->vehicle_type);
src/saveload/afterload.cpp
Show inline comments
 
@@ -3124,12 +3124,29 @@ bool AfterLoadGame()
 
		for (Industry *i : Industry::Iterate()) {
 
			i->exclusive_supplier = INVALID_OWNER;
 
			i->exclusive_consumer = INVALID_OWNER;
 
		}
 
	}
 

	
 
	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();
 

	
 
	/* Station acceptance is some kind of cache */
 
	if (IsSavegameVersionBefore(SLV_127)) {
 
		for (Station *st : Station::Iterate()) UpdateStationAcceptance(st, false);
src/saveload/saveload.h
Show inline comments
 
@@ -322,12 +322,13 @@ enum SaveLoadVersion : uint16 {
 
	SLV_END_PATCHPACKS = 286,               ///< 286  Last known patchpack to use a version just above ours.
 

	
 
	SLV_GS_INDUSTRY_CONTROL,                ///< 287  PR#7912 and PR#8115 GS industry control.
 
	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
 
};
 

	
 
/** Save or load result codes. */
 
enum SaveOrLoadResult {
0 comments (0 inline, 0 general)