diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 73d52ceb4..0cf6200b7 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -140,16 +140,25 @@ void GroupStatistics::Clear() assert(delta == 1 || delta == -1); GroupStatistics &stats_all = GroupStatistics::GetAllGroup(v); - GroupStatistics &stats = GroupStatistics::Get(v); - stats_all.num_vehicle += delta; - stats.num_vehicle += delta; - if (v->age > VEHICLE_PROFIT_MIN_AGE) { stats_all.num_profit_vehicle += delta; stats_all.profit_last_year += v->GetDisplayProfitLastYear() * delta; - stats.num_profit_vehicle += delta; - stats.profit_last_year += v->GetDisplayProfitLastYear() * delta; + } + + if (IsDefaultGroupID(v->group_id)) { + GroupStatistics &stats = GroupStatistics::Get(v); + stats.num_vehicle += delta; + if (v->age > VEHICLE_PROFIT_MIN_AGE) { + stats.num_profit_vehicle += delta; + stats.profit_last_year += v->GetDisplayProfitLastYear() * delta; + } + } else for (Group *g = Group::Get(v->group_id); g != NULL; g = Group::GetIfValid(g->parent)) { + g->statistics.num_vehicle += delta; + if (v->age > VEHICLE_PROFIT_MIN_AGE) { + g->statistics.num_profit_vehicle += delta; + g->statistics.profit_last_year += v->GetDisplayProfitLastYear() * delta; + } } } @@ -171,12 +180,17 @@ void GroupStatistics::Clear() /* static */ void GroupStatistics::VehicleReachedProfitAge(const Vehicle *v) { GroupStatistics &stats_all = GroupStatistics::GetAllGroup(v); - GroupStatistics &stats = GroupStatistics::Get(v); - stats_all.num_profit_vehicle++; stats_all.profit_last_year += v->GetDisplayProfitLastYear(); - stats.num_profit_vehicle++; - stats.profit_last_year += v->GetDisplayProfitLastYear(); + + if (IsDefaultGroupID(v->group_id)) { + GroupStatistics &stats = GroupStatistics::Get(v); + stats.num_profit_vehicle++; + stats.profit_last_year += v->GetDisplayProfitLastYear(); + } else for (Group *g = Group::Get(v->group_id); g != NULL; g = Group::GetIfValid(g->parent)) { + g->statistics.num_profit_vehicle++; + g->statistics.profit_last_year += v->GetDisplayProfitLastYear(); + } } /**