diff options
author | Peter Nelson <peter1138@openttd.org> | 2019-02-13 22:18:33 +0000 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-03-03 09:15:39 +0100 |
commit | 3c047b124e28db45621de06d5556c96598352fc7 (patch) | |
tree | d347611d01fe873c42ac1a9da9220d3ef7deb4ce /src/script/api/script_group.cpp | |
parent | b62452903a3af9e51dc308fd674a788214942382 (diff) | |
download | openttd-3c047b124e28db45621de06d5556c96598352fc7.tar.xz |
Add: AI functions to get current and last year profit of a group.
Diffstat (limited to 'src/script/api/script_group.cpp')
-rw-r--r-- | src/script/api/script_group.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index 7823fb28b..023f5534c 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -17,6 +17,7 @@ #include "../../strings_func.h" #include "../../autoreplace_func.h" #include "../../settings_func.h" +#include "../../vehicle_base.h" #include "table/strings.h" #include "../../safeguards.h" @@ -148,3 +149,27 @@ return ScriptObject::DoCommand(0, group_id << 16, (::INVALID_ENGINE << 16) | engine_id, CMD_SET_AUTOREPLACE); } + +/* static */ Money ScriptGroup::GetProfitThisYear(GroupID group_id) +{ + if (!IsValidGroup(group_id)) return -1; + + Money profit = 0; + + const Vehicle *v; + FOR_ALL_VEHICLES(v) { + if (v->group_id != group_id) continue; + if (!v->IsPrimaryVehicle()) continue; + + profit += v->GetDisplayProfitThisYear(); + } + + return profit; +} + +/* static */ Money ScriptGroup::GetProfitLastYear(GroupID group_id) +{ + if (!IsValidGroup(group_id)) return -1; + + return ::Group::Get(group_id)->statistics.profit_last_year; +} |