From 75bb76163ca9649986648f5528129ff3639ee3b6 Mon Sep 17 00:00:00 2001 From: J0anJosep Date: Sun, 24 Dec 2017 23:26:03 +0100 Subject: [PATCH] Count the number of groups of a company and a vehicle type. --- src/group_cmd.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 2547d5ad26eb..a2c442d63ff1 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -997,6 +997,24 @@ uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e) return count + GroupStatistics::Get(company, id_g, e->type).num_engines[id_e]; } +/** + * Get the number of groups of a company and a certain vehicle type. + * @param company The company the group belongs to. + * @param type Vehicle Type. + * @return The number of groups of a company and vehicle type. + */ +uint GetGroupNumByVehicleType(CompanyID company, VehicleType type) +{ + uint count = 0; + Group *g; + FOR_ALL_GROUPS(g) { + if (g->owner == company && g->vehicle_type == type) count++; + } + + return count; +} + + void RemoveAllGroupsForCompany(const CompanyID company) { Group *g;