mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 06:15:04 +00:00
Change: Use per-company group numbers. (#12297)
This is used by the default group name, replacing the use of group index.
This commit is contained in:
parent
8710e9b8c8
commit
9008d793ab
@ -6093,7 +6093,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
|
||||
GetNumEngines(): 1
|
||||
GetNumEngines(): 1
|
||||
GetNumEngines(): 0
|
||||
GetName(): Group 0
|
||||
GetName(): Group 1
|
||||
GetName(): (null : 0x00000000)
|
||||
AIVehicle.SellVehicle(): true
|
||||
AITile.DemolishTile(): true
|
||||
|
@ -146,6 +146,7 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> {
|
||||
CompanyInfrastructure infrastructure; ///< NOSAVE: Counts of company owned infrastructure.
|
||||
|
||||
FreeUnitIDGenerator freeunits[VEH_COMPANY_END];
|
||||
FreeUnitIDGenerator freegroups;
|
||||
|
||||
Money GetMaxLoan() const;
|
||||
|
||||
|
@ -424,8 +424,12 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
||||
if (new_owner == INVALID_OWNER) {
|
||||
RemoveAllGroupsForCompany(old_owner);
|
||||
} else {
|
||||
Company *c = Company::Get(old_owner);
|
||||
for (Group *g : Group::Iterate()) {
|
||||
if (g->owner == old_owner) g->owner = new_owner;
|
||||
if (g->owner == old_owner) {
|
||||
g->owner = new_owner;
|
||||
g->number = c->freegroups.UseID(c->freegroups.NextID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,7 @@ struct Group : GroupPool::PoolItem<&_group_pool> {
|
||||
bool folded; ///< NOSAVE: Is this group folded in the group view?
|
||||
|
||||
GroupID parent; ///< Parent group
|
||||
uint16_t number; ///< Per-company group number.
|
||||
|
||||
Group(CompanyID owner = INVALID_COMPANY);
|
||||
};
|
||||
|
@ -350,8 +350,9 @@ std::tuple<CommandCost, GroupID> CmdCreateGroup(DoCommandFlag flags, VehicleType
|
||||
g->vehicle_type = vt;
|
||||
g->parent = INVALID_GROUP;
|
||||
|
||||
Company *c = Company::Get(g->owner);
|
||||
g->number = c->freegroups.UseID(c->freegroups.NextID());
|
||||
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);
|
||||
@ -397,14 +398,15 @@ CommandCost CmdDeleteGroup(DoCommandFlag flags, GroupID group_id)
|
||||
/* Update backupped orders if needed */
|
||||
OrderBackup::ClearGroup(g->index);
|
||||
|
||||
/* If we set an autoreplace for the group we delete, remove it. */
|
||||
if (_current_company < MAX_COMPANIES) {
|
||||
Company *c;
|
||||
if (g->owner < MAX_COMPANIES) {
|
||||
Company *c = Company::Get(g->owner);
|
||||
|
||||
c = Company::Get(_current_company);
|
||||
/* If we set an autoreplace for the group we delete, remove it. */
|
||||
for (EngineRenew *er : EngineRenew::Iterate()) {
|
||||
if (er->group_id == g->index) RemoveEngineReplacementForCompany(c, er->from, g->index, flags);
|
||||
}
|
||||
|
||||
c->freegroups.ReleaseID(g->number);
|
||||
}
|
||||
|
||||
VehicleType vt = g->vehicle_type;
|
||||
|
@ -180,7 +180,7 @@ void BuildGuiGroupList(GUIGroupList &dst, bool fold, Owner owner, VehicleType ve
|
||||
}
|
||||
|
||||
int r = StrNaturalCompare(last_group[0].second, last_group[1].second); // Sort by name (natural sorting).
|
||||
if (r == 0) return a.group->index < b.group->index;
|
||||
if (r == 0) return a.group->number < b.group->number;
|
||||
return r < 0;
|
||||
});
|
||||
|
||||
|
@ -3286,6 +3286,17 @@ bool AfterLoadGame()
|
||||
UpdateCompanyLiveries(c);
|
||||
}
|
||||
|
||||
/* Update free group numbers data for each company, required regardless of savegame version. */
|
||||
for (Group *g : Group::Iterate()) {
|
||||
Company *c = Company::Get(g->owner);
|
||||
if (IsSavegameVersionBefore(SLV_GROUP_NUMBERS)) {
|
||||
/* Use the index as group number when converting old savegames. */
|
||||
g->number = c->freegroups.UseID(g->index);
|
||||
} else {
|
||||
c->freegroups.UseID(g->number);
|
||||
}
|
||||
}
|
||||
|
||||
AfterLoadLabelMaps();
|
||||
AfterLoadCompanyStats();
|
||||
AfterLoadStoryBook();
|
||||
|
@ -26,6 +26,7 @@ static const SaveLoad _group_desc[] = {
|
||||
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),
|
||||
SLE_CONDVAR(Group, parent, SLE_UINT16, SLV_189, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Group, number, SLE_UINT16, SLV_GROUP_NUMBERS, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
struct GRPSChunkHandler : ChunkHandler {
|
||||
|
@ -380,6 +380,7 @@ enum SaveLoadVersion : uint16_t {
|
||||
SLV_VEHICLE_ECONOMY_AGE, ///< 334 PR#12141 v14.0 Add vehicle age in economy year, for profit stats minimum age
|
||||
|
||||
SLV_COMPANY_ALLOW_LIST, ///< 335 PR#12337 Saving of list of client keys that are allowed to join this company.
|
||||
SLV_GROUP_NUMBERS, ///< 336 PR#12297 Add per-company group numbers.
|
||||
|
||||
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||
};
|
||||
|
@ -1539,7 +1539,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
|
||||
auto tmp_params = MakeParameters(g->name);
|
||||
GetStringWithArgs(builder, STR_JUST_RAW_STRING, tmp_params);
|
||||
} else {
|
||||
auto tmp_params = MakeParameters(g->index);
|
||||
auto tmp_params = MakeParameters(g->number);
|
||||
GetStringWithArgs(builder, STR_FORMAT_GROUP_NAME, tmp_params);
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user