summaryrefslogtreecommitdiff
path: root/src/group_cmd.cpp
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2019-03-26 00:07:20 +0000
committerPeterN <peter@fuzzle.org>2019-03-27 06:58:48 +0000
commit8890436af1e9dbff7279dd3cf4c3659a3ad973d6 (patch)
tree72f5d48e8ffff58e43e7dfd0933f0908f09c759a /src/group_cmd.cpp
parenta393c9469545f4bd1e6e2fd1a593d35bb98f16ca (diff)
downloadopenttd-8890436af1e9dbff7279dd3cf4c3659a3ad973d6.tar.xz
Add #6189: Groups now count the total number of vehicles in subgroups (3298)
Diffstat (limited to 'src/group_cmd.cpp')
-rw-r--r--src/group_cmd.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp
index 3c9b3850a..bb86c6b34 100644
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -808,6 +808,60 @@ 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 vehicles in the group with GroupID
+ * id_g and its sub-groups.
+ * @param company The company the group belongs to
+ * @param id_g The GroupID of the group used
+ * @param type The vehicle type of the group
+ * @return The number of vehicles in the group
+ */
+uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type)
+{
+ uint count = 0;
+ const Group *g;
+ FOR_ALL_GROUPS(g) {
+ if (g->parent == id_g) count += GetGroupNumVehicle(company, g->index, type);
+ }
+ return count + GroupStatistics::Get(company, id_g, type).num_vehicle;
+}
+
+/**
+ * Get the number of vehicles above profit minimum age in the group with GroupID
+ * id_g and its sub-groups.
+ * @param company The company the group belongs to
+ * @param id_g The GroupID of the group used
+ * @param type The vehicle type of the group
+ * @return The number of vehicles above profit minimum age in the group
+ */
+uint GetGroupNumProfitVehicle(CompanyID company, GroupID id_g, VehicleType type)
+{
+ uint count = 0;
+ const Group *g;
+ FOR_ALL_GROUPS(g) {
+ if (g->parent == id_g) count += GetGroupNumProfitVehicle(company, g->index, type);
+ }
+ return count + GroupStatistics::Get(company, id_g, type).num_profit_vehicle;
+}
+
+/**
+ * Get last year's profit for the group with GroupID
+ * id_g and its sub-groups.
+ * @param company The company the group belongs to
+ * @param id_g The GroupID of the group used
+ * @param type The vehicle type of the group
+ * @return Last year's profit for the group
+ */
+Money GetGroupProfitLastYear(CompanyID company, GroupID id_g, VehicleType type)
+{
+ Money sum = 0;
+ const Group *g;
+ FOR_ALL_GROUPS(g) {
+ if (g->parent == id_g) sum += GetGroupProfitLastYear(company, g->index, type);
+ }
+ return sum + GroupStatistics::Get(company, id_g, type).profit_last_year;
+}
+
void RemoveAllGroupsForCompany(const CompanyID company)
{
Group *g;