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_waypointlist.cpp Implementation of ScriptWaypointList and friends. */
9 
10 #include "../../stdafx.h"
11 #include "script_waypointlist.hpp"
12 #include "script_vehicle.hpp"
13 #include "../../vehicle_base.h"
14 #include "../../waypoint_base.h"
15 
16 #include "../../safeguards.h"
17 
ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type)18 ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type)
19 {
20 	for (const Waypoint *wp : Waypoint::Iterate()) {
21 		if ((wp->facilities & waypoint_type) &&
22 				(wp->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || wp->owner == OWNER_NONE)) this->AddItem(wp->index);
23 	}
24 }
25 
ScriptWaypointList_Vehicle(VehicleID vehicle_id)26 ScriptWaypointList_Vehicle::ScriptWaypointList_Vehicle(VehicleID vehicle_id)
27 {
28 	if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return;
29 
30 	const Vehicle *v = ::Vehicle::Get(vehicle_id);
31 
32 	for (const Order *o = v->GetFirstOrder(); o != nullptr; o = o->next) {
33 		if (o->IsType(OT_GOTO_WAYPOINT)) this->AddItem(o->GetDestination());
34 	}
35 }
36