1 /* $Id: script_cargomonitor.cpp 24406 2012-07-15 17:11:14Z alberth $ */
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file script_cargomonitor.cpp Code to monitor cargo pickup and deliveries by companies. */
12 #include "../../stdafx.h"
13 #include "script_cargo.hpp"
14 #include "script_cargomonitor.hpp"
15 #include "../../town.h"
16 #include "../../industry.h"
18 #include "../../safeguards.h"
20 /* static */ int32
ScriptCargoMonitor::GetTownDeliveryAmount(ScriptCompany::CompanyID company
, CargoID cargo
, TownID town_id
, bool keep_monitoring
)
22 CompanyID cid
= static_cast<CompanyID
>(company
);
23 if (cid
< OWNER_BEGIN
|| cid
>= MAX_COMPANIES
) return -1;
24 if (!ScriptCargo::IsValidCargo(cargo
)) return -1;
25 if (!::Town::IsValidID(town_id
)) return -1;
27 CargoMonitorID monitor
= EncodeCargoTownMonitor(cid
, cargo
, town_id
);
28 return GetDeliveryAmount(monitor
, keep_monitoring
);
31 /* static */ int32
ScriptCargoMonitor::GetIndustryDeliveryAmount(ScriptCompany::CompanyID company
, CargoID cargo
, IndustryID industry_id
, bool keep_monitoring
)
33 CompanyID cid
= static_cast<CompanyID
>(company
);
34 if (cid
< OWNER_BEGIN
|| cid
>= MAX_COMPANIES
) return -1;
35 if (!ScriptCargo::IsValidCargo(cargo
)) return -1;
36 if (!::Industry::IsValidID(industry_id
)) return -1;
38 CargoMonitorID monitor
= EncodeCargoIndustryMonitor(cid
, cargo
, industry_id
);
39 return GetDeliveryAmount(monitor
, keep_monitoring
);
42 /* static */ int32
ScriptCargoMonitor::GetTownPickupAmount(ScriptCompany::CompanyID company
, CargoID cargo
, TownID town_id
, bool keep_monitoring
)
44 CompanyID cid
= static_cast<CompanyID
>(company
);
45 if (cid
< OWNER_BEGIN
|| cid
>= MAX_COMPANIES
) return -1;
46 if (!ScriptCargo::IsValidCargo(cargo
)) return -1;
47 if (!::Town::IsValidID(town_id
)) return -1;
49 CargoMonitorID monitor
= EncodeCargoTownMonitor(cid
, cargo
, town_id
);
50 return GetPickupAmount(monitor
, keep_monitoring
);
53 /* static */ int32
ScriptCargoMonitor::GetIndustryPickupAmount(ScriptCompany::CompanyID company
, CargoID cargo
, IndustryID industry_id
, bool keep_monitoring
)
55 CompanyID cid
= static_cast<CompanyID
>(company
);
56 if (cid
< OWNER_BEGIN
|| cid
>= MAX_COMPANIES
) return -1;
57 if (!ScriptCargo::IsValidCargo(cargo
)) return -1;
58 if (!::Industry::IsValidID(industry_id
)) return -1;
60 CargoMonitorID monitor
= EncodeCargoIndustryMonitor(cid
, cargo
, industry_id
);
61 return GetPickupAmount(monitor
, keep_monitoring
);
64 /* static */ void ScriptCargoMonitor::StopAllMonitoring()
66 ClearCargoPickupMonitoring();
67 ClearCargoDeliveryMonitoring();