From ad3a34e9ef139e4589bef902bf153c7e518c5ea5 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Mon, 19 May 2025 13:48:17 +0100 Subject: [PATCH] Add: [Script] ScriptVehicleList_Waypoint (#13456) Creates a list of vehicles that have orders to a given waypoint. --- src/script/api/ai_changelog.hpp | 1 + src/script/api/game_changelog.hpp | 1 + src/script/api/script_vehiclelist.cpp | 16 ++++++++++++++++ src/script/api/script_vehiclelist.hpp | 14 ++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index fac33894bb..d359902418 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -27,6 +27,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 581cf3dd22..ffb3578ebf 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -27,6 +27,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 994c47756b..9b52e90934 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" @@ -68,6 +69,21 @@ ScriptVehicleList_Station::ScriptVehicleList_Station(HSQUIRRELVM vm) ); } +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 d16edeabd4..a6b7330626 100644 --- a/src/script/api/script_vehiclelist.hpp +++ b/src/script/api/script_vehiclelist.hpp @@ -79,6 +79,20 @@ public: #endif /* DOXYGEN_API */ }; +/** + * 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