2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file script_cargomonitor.cpp Code to monitor cargo pickup and deliveries by companies. */
10 #include "../../stdafx.h"
11 #include "script_cargo.hpp"
12 #include "script_cargomonitor.hpp"
13 #include "../../town.h"
14 #include "../../industry.h"
16 #include "../../safeguards.h"
18 /* static */ SQInteger
ScriptCargoMonitor::GetTownDeliveryAmount(ScriptCompany::CompanyID company
, CargoID cargo
, TownID town_id
, bool keep_monitoring
)
20 CompanyID cid
= static_cast<CompanyID
>(company
);
21 if (cid
>= MAX_COMPANIES
) return -1;
22 if (!ScriptCargo::IsValidCargo(cargo
)) return -1;
23 if (!::Town::IsValidID(town_id
)) return -1;
25 CargoMonitorID monitor
= EncodeCargoTownMonitor(cid
, cargo
, town_id
);
26 return GetDeliveryAmount(monitor
, keep_monitoring
);
29 /* static */ SQInteger
ScriptCargoMonitor::GetIndustryDeliveryAmount(ScriptCompany::CompanyID company
, CargoID cargo
, IndustryID industry_id
, bool keep_monitoring
)
31 CompanyID cid
= static_cast<CompanyID
>(company
);
32 if (cid
>= MAX_COMPANIES
) return -1;
33 if (!ScriptCargo::IsValidCargo(cargo
)) return -1;
34 if (!::Industry::IsValidID(industry_id
)) return -1;
36 CargoMonitorID monitor
= EncodeCargoIndustryMonitor(cid
, cargo
, industry_id
);
37 return GetDeliveryAmount(monitor
, keep_monitoring
);
40 /* static */ SQInteger
ScriptCargoMonitor::GetTownPickupAmount(ScriptCompany::CompanyID company
, CargoID cargo
, TownID town_id
, bool keep_monitoring
)
42 CompanyID cid
= static_cast<CompanyID
>(company
);
43 if (cid
>= MAX_COMPANIES
) return -1;
44 if (!ScriptCargo::IsValidCargo(cargo
)) return -1;
45 if (!::Town::IsValidID(town_id
)) return -1;
47 CargoMonitorID monitor
= EncodeCargoTownMonitor(cid
, cargo
, town_id
);
48 return GetPickupAmount(monitor
, keep_monitoring
);
51 /* static */ SQInteger
ScriptCargoMonitor::GetIndustryPickupAmount(ScriptCompany::CompanyID company
, CargoID cargo
, IndustryID industry_id
, bool keep_monitoring
)
53 CompanyID cid
= static_cast<CompanyID
>(company
);
54 if (cid
>= MAX_COMPANIES
) return -1;
55 if (!ScriptCargo::IsValidCargo(cargo
)) return -1;
56 if (!::Industry::IsValidID(industry_id
)) return -1;
58 CargoMonitorID monitor
= EncodeCargoIndustryMonitor(cid
, cargo
, industry_id
);
59 return GetPickupAmount(monitor
, keep_monitoring
);
62 /* static */ void ScriptCargoMonitor::StopAllMonitoring()
64 ClearCargoPickupMonitoring();
65 ClearCargoDeliveryMonitoring();