diff options
-rw-r--r-- | src/autoreplace_cmd.cpp | 3 | ||||
-rw-r--r-- | src/autoreplace_gui.cpp | 22 | ||||
-rw-r--r-- | src/group.h | 3 | ||||
-rw-r--r-- | src/group_cmd.cpp | 3 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 17 | ||||
-rw-r--r-- | src/saveload/saveload.h | 1 |
6 files changed, 43 insertions, 6 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index fe86917c7..d9996bb11 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -741,6 +741,9 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1 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; diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index e952dcf19..d16e0916e 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -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)) { diff --git a/src/group.h b/src/group.h index bd6f47bdf..e0f0b9196 100644 --- a/src/group.h +++ b/src/group.h @@ -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, }; diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 2c2cfeaab..bbef35ae2 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -315,7 +315,6 @@ CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 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 tile, DoCommandFlag flags, uint32 p1, uint3 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; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index be6be8de6..d4b230dfd 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -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(); diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 8ad29a640..cda6af82b 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -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 }; |