1
0
Fork 0

Codechange: explicitly initialise Group member variables

pull/13608/head
Rubidium 2025-02-18 16:58:58 +01:00 committed by rubidium42
parent b4a4ca83ff
commit 63e99871c1
2 changed files with 18 additions and 25 deletions

View File

@ -22,13 +22,13 @@ extern GroupPool _group_pool; ///< Pool of groups.
/** Statistics and caches on the vehicles in a group. */
struct GroupStatistics {
Money profit_last_year; ///< Sum of profits for all vehicles.
Money profit_last_year_min_age; ///< Sum of profits for vehicles considered for profit statistics.
std::map<EngineID, uint16_t> num_engines; ///< Caches the number of engines of each type the company owns.
uint16_t num_vehicle; ///< Number of vehicles.
uint16_t num_vehicle_min_age; ///< Number of vehicles considered for profit statistics;
bool autoreplace_defined; ///< Are any autoreplace rules set?
bool autoreplace_finished; ///< Have all autoreplacement finished?
Money profit_last_year = 0; ///< Sum of profits for all vehicles.
Money profit_last_year_min_age = 0; ///< Sum of profits for vehicles considered for profit statistics.
std::map<EngineID, uint16_t> num_engines{}; ///< Caches the number of engines of each type the company owns.
uint16_t num_vehicle = 0; ///< Number of vehicles.
uint16_t num_vehicle_min_age = 0; ///< Number of vehicles considered for profit statistics;
bool autoreplace_defined = false; ///< Are any autoreplace rules set?
bool autoreplace_finished = false; ///< Have all autoreplacement finished?
void Clear();
@ -70,20 +70,21 @@ using GroupFlags = EnumBitSet<GroupFlag, uint8_t>;
/** Group data. */
struct Group : GroupPool::PoolItem<&_group_pool> {
std::string name; ///< Group Name
Owner owner; ///< Group Owner
VehicleType vehicle_type; ///< Vehicle type of the group
std::string name{}; ///< Group Name
Owner owner = INVALID_OWNER; ///< Group Owner
VehicleType vehicle_type = VEH_INVALID; ///< Vehicle type of the group
GroupFlags flags{}; ///< Group flags
Livery livery; ///< Custom colour scheme for vehicles in this group
GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group.
Livery livery{}; ///< Custom colour scheme for vehicles in this group
GroupStatistics statistics{}; ///< NOSAVE: Statistics and caches on the vehicles in the group.
bool folded; ///< NOSAVE: Is this group folded in the group view?
bool folded = false; ///< NOSAVE: Is this group folded in the group view?
GroupID parent; ///< Parent group
uint16_t number; ///< Per-company group number.
GroupID parent = GroupID::Invalid(); ///< Parent group
uint16_t number = 0; ///< Per-company group number.
Group(CompanyID owner = CompanyID::Invalid());
Group() {}
Group(CompanyID owner, VehicleType vehicle_type) : owner(owner), vehicle_type(vehicle_type) {}
};

View File

@ -319,12 +319,6 @@ void UpdateCompanyGroupLiveries(const Company *c)
}
}
Group::Group(Owner owner)
{
this->owner = owner;
this->folded = false;
}
/**
* Create a new vehicle group.
@ -346,9 +340,7 @@ std::tuple<CommandCost, GroupID> CmdCreateGroup(DoCommandFlags flags, VehicleTyp
}
if (flags.Test(DoCommandFlag::Execute)) {
Group *g = new Group(_current_company);
g->vehicle_type = vt;
g->parent = GroupID::Invalid();
Group *g = new Group(_current_company, vt);
Company *c = Company::Get(g->owner);
g->number = c->freegroups.UseID(c->freegroups.NextID());