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_cargolist.cpp Implementation of ScriptCargoList and friends. */
10 #include "../../stdafx.h"
11 #include "script_cargolist.hpp"
12 #include "script_industry.hpp"
13 #include "script_station.hpp"
14 #include "../../cargotype.h"
15 #include "../../industry.h"
16 #include "../../station_base.h"
18 #include "../../safeguards.h"
20 ScriptCargoList::ScriptCargoList()
22 for (const CargoSpec
*cs
: CargoSpec::Iterate()) {
23 this->AddItem(cs
->Index());
27 ScriptCargoList_IndustryAccepting::ScriptCargoList_IndustryAccepting(IndustryID industry_id
)
29 if (!ScriptIndustry::IsValidIndustry(industry_id
)) return;
31 const Industry
*ind
= ::Industry::Get(industry_id
);
32 for (const auto &a
: ind
->accepted
) {
33 if (::IsValidCargoID(a
.cargo
)) {
34 this->AddItem(a
.cargo
);
39 ScriptCargoList_IndustryProducing::ScriptCargoList_IndustryProducing(IndustryID industry_id
)
41 if (!ScriptIndustry::IsValidIndustry(industry_id
)) return;
43 const Industry
*ind
= ::Industry::Get(industry_id
);
44 for (const auto &p
: ind
->produced
) {
45 if (::IsValidCargoID(p
.cargo
)) {
46 this->AddItem(p
.cargo
);
51 ScriptCargoList_StationAccepting::ScriptCargoList_StationAccepting(StationID station_id
)
53 if (!ScriptStation::IsValidStation(station_id
)) return;
55 const Station
*st
= ::Station::Get(station_id
);
56 for (CargoID i
= 0; i
< NUM_CARGO
; i
++) {
57 if (HasBit(st
->goods
[i
].status
, GoodsEntry::GES_ACCEPTANCE
)) this->AddItem(i
);