mirror of https://github.com/OpenTTD/OpenTTD
Feature: Per-group wagon removal flag.
parent
c56fce70b4
commit
a05bc04b63
|
@ -741,6 +741,9 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1
|
||||||
const Company *c = Company::Get(_current_company);
|
const Company *c = Company::Get(_current_company);
|
||||||
bool wagon_removal = c->settings.renew_keep_length;
|
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 */
|
/* Test whether any replacement is set, before issuing a whole lot of commands that would end in nothing changed */
|
||||||
Vehicle *w = v;
|
Vehicle *w = v;
|
||||||
bool any_replacements = false;
|
bool any_replacements = false;
|
||||||
|
|
|
@ -375,8 +375,15 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
|
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
|
||||||
const Company *c = Company::Get(_local_company);
|
bool remove_wagon;
|
||||||
SetDParam(0, c->settings.renew_keep_length ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,9 +535,16 @@ public:
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: // toggle renew_keep_length
|
case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: {
|
||||||
DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_CHANGE_COMPANY_SETTING);
|
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;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WID_RV_START_REPLACE: { // Start replacing
|
case WID_RV_START_REPLACE: { // Start replacing
|
||||||
if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
|
if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
|
||||||
|
|
|
@ -63,7 +63,8 @@ struct GroupStatistics {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum GroupFlags : uint8 {
|
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,
|
GF_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -315,7 +315,6 @@ CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
Group *g = new Group(_current_company);
|
Group *g = new Group(_current_company);
|
||||||
ClrBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION);
|
|
||||||
g->vehicle_type = vt;
|
g->vehicle_type = vt;
|
||||||
g->parent = INVALID_GROUP;
|
g->parent = INVALID_GROUP;
|
||||||
|
|
||||||
|
@ -323,10 +322,12 @@ CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||||
const Company *c = Company::Get(_current_company);
|
const Company *c = Company::Get(_current_company);
|
||||||
g->livery.colour1 = c->livery[LS_DEFAULT].colour1;
|
g->livery.colour1 = c->livery[LS_DEFAULT].colour1;
|
||||||
g->livery.colour2 = c->livery[LS_DEFAULT].colour2;
|
g->livery.colour2 = c->livery[LS_DEFAULT].colour2;
|
||||||
|
if (c->settings.renew_keep_length) SetBit(g->flags, GroupFlags::GF_REPLACE_WAGON_REMOVAL);
|
||||||
} else {
|
} else {
|
||||||
g->parent = pg->index;
|
g->parent = pg->index;
|
||||||
g->livery.colour1 = pg->livery.colour1;
|
g->livery.colour1 = pg->livery.colour1;
|
||||||
g->livery.colour2 = pg->livery.colour2;
|
g->livery.colour2 = pg->livery.colour2;
|
||||||
|
g->flags = pg->flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
_new_group_id = g->index;
|
_new_group_id = g->index;
|
||||||
|
|
|
@ -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. */
|
/* Compute station catchment areas. This is needed here in case UpdateStationAcceptance is called below. */
|
||||||
Station::RecomputeCatchmentForAll();
|
Station::RecomputeCatchmentForAll();
|
||||||
|
|
||||||
|
|
|
@ -325,6 +325,7 @@ enum SaveLoadVersion : uint16 {
|
||||||
SLV_VEH_MOTION_COUNTER, ///< 288 PR#8591 Desync safe motion counter
|
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_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_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
|
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue