diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index 23d2d3b216..dc2d160e6d 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -26,6 +26,7 @@ * \li AICargo::CC_NON_POURABLE * \li AICargo::CC_POTABLE * \li AICargo::CC_NON_POTABLE + * \li AIVehicleList_Waypoint * * Other changes: * \li AIBridge::GetBridgeID renamed to AIBridge::GetBridgeType diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 1ec9611311..6bb76799d1 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -26,6 +26,7 @@ * \li GSCargo::CC_NON_POURABLE * \li GSCargo::CC_POTABLE * \li GSCargo::CC_NON_POTABLE + * \li GSVehicleList_Waypoint * * Other changes: * \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType diff --git a/src/script/api/script_vehiclelist.cpp b/src/script/api/script_vehiclelist.cpp index 68113654e5..39bf778b07 100644 --- a/src/script/api/script_vehiclelist.cpp +++ b/src/script/api/script_vehiclelist.cpp @@ -12,6 +12,7 @@ #include "script_group.hpp" #include "script_map.hpp" #include "script_station.hpp" +#include "script_waypoint.hpp" #include "../../depot_map.h" #include "../../vehicle_base.h" #include "../../vehiclelist_func.h" @@ -48,6 +49,21 @@ ScriptVehicleList_Station::ScriptVehicleList_Station(StationID station_id) ); } +ScriptVehicleList_Waypoint::ScriptVehicleList_Waypoint(StationID waypoint_id) +{ + EnforceDeityOrCompanyModeValid_Void(); + if (!ScriptWaypoint::IsValidWaypoint(waypoint_id)) return; + + bool is_deity = ScriptCompanyMode::IsDeity(); + ::CompanyID owner = ScriptObject::GetCompany(); + + FindVehiclesWithOrder( + [is_deity, owner](const Vehicle *v) { return is_deity || v->owner == owner; }, + [waypoint_id](const Order *order) { return order->IsType(OT_GOTO_WAYPOINT) && order->GetDestination() == waypoint_id; }, + [this](const Vehicle *v) { this->AddItem(v->index.base()); } + ); +} + ScriptVehicleList_Depot::ScriptVehicleList_Depot(TileIndex tile) { EnforceDeityOrCompanyModeValid_Void(); diff --git a/src/script/api/script_vehiclelist.hpp b/src/script/api/script_vehiclelist.hpp index ad4b3cb0ef..6c90bfca0f 100644 --- a/src/script/api/script_vehiclelist.hpp +++ b/src/script/api/script_vehiclelist.hpp @@ -65,6 +65,20 @@ public: ScriptVehicleList_Station(StationID station_id); }; +/** + * Creates a list of vehicles that have orders to a given waypoint. + * @api ai game + * @ingroup ScriptList + */ +class ScriptVehicleList_Waypoint : public ScriptList { +public: + /** + * @param waypoint_id The waypoint to get the list of vehicles from, which have orders to it. + * @pre ScriptWaypoint::IsValidWaypoint(waypoint_id) + */ + ScriptVehicleList_Waypoint(StationID waypoint_id); +}; + /** * Creates a list of vehicles that have orders to a given depot. * The list is created with a tile. If the tile is part of an airport all