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_depotlist.cpp Implementation of ScriptDepotList and friends. */
9 
10 #include "../../stdafx.h"
11 #include "script_depotlist.hpp"
12 #include "../../depot_base.h"
13 #include "../../station_base.h"
14 
15 #include "../../safeguards.h"
16 
ScriptDepotList(ScriptTile::TransportType transport_type)17 ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
18 {
19 	::TileType tile_type;
20 	switch (transport_type) {
21 		default: return;
22 
23 		case ScriptTile::TRANSPORT_ROAD:  tile_type = ::MP_ROAD; break;
24 		case ScriptTile::TRANSPORT_RAIL:  tile_type = ::MP_RAILWAY; break;
25 		case ScriptTile::TRANSPORT_WATER: tile_type = ::MP_WATER; break;
26 
27 		case ScriptTile::TRANSPORT_AIR: {
28 			/* Hangars are not seen as real depots by the depot code. */
29 			for (const Station *st : Station::Iterate()) {
30 				if (st->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) {
31 					for (uint i = 0; i < st->airport.GetNumHangars(); i++) {
32 						this->AddItem(st->airport.GetHangarTile(i));
33 					}
34 				}
35 			}
36 			return;
37 		}
38 	}
39 
40 	/* Handle 'standard' depots. */
41 	for (const Depot *depot : Depot::Iterate()) {
42 		if ((::GetTileOwner(depot->xy) == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && ::IsTileType(depot->xy, tile_type)) this->AddItem(depot->xy);
43 	}
44 }
45