1 /* 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/>. 6 */ 7 8 /** @file script_cargolist.cpp Implementation of ScriptCargoList and friends. */ 9 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" 17 18 #include "../../safeguards.h" 19 ScriptCargoList()20ScriptCargoList::ScriptCargoList() 21 { 22 for (const CargoSpec *cs : CargoSpec::Iterate()) { 23 this->AddItem(cs->Index()); 24 } 25 } 26 ScriptCargoList_IndustryAccepting(IndustryID industry_id)27ScriptCargoList_IndustryAccepting::ScriptCargoList_IndustryAccepting(IndustryID industry_id) 28 { 29 if (!ScriptIndustry::IsValidIndustry(industry_id)) return; 30 31 Industry *ind = ::Industry::Get(industry_id); 32 for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) { 33 CargoID cargo_id = ind->accepts_cargo[i]; 34 if (cargo_id != CT_INVALID) { 35 this->AddItem(cargo_id); 36 } 37 } 38 } 39 ScriptCargoList_IndustryProducing(IndustryID industry_id)40ScriptCargoList_IndustryProducing::ScriptCargoList_IndustryProducing(IndustryID industry_id) 41 { 42 if (!ScriptIndustry::IsValidIndustry(industry_id)) return; 43 44 Industry *ind = ::Industry::Get(industry_id); 45 for (uint i = 0; i < lengthof(ind->produced_cargo); i++) { 46 CargoID cargo_id = ind->produced_cargo[i]; 47 if (cargo_id != CT_INVALID) { 48 this->AddItem(cargo_id); 49 } 50 } 51 } 52 ScriptCargoList_StationAccepting(StationID station_id)53ScriptCargoList_StationAccepting::ScriptCargoList_StationAccepting(StationID station_id) 54 { 55 if (!ScriptStation::IsValidStation(station_id)) return; 56 57 Station *st = ::Station::Get(station_id); 58 for (CargoID i = 0; i < NUM_CARGO; i++) { 59 if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) this->AddItem(i); 60 } 61 } 62