1
0
Fork 0

Add: [Script] ScriptVehicleList_Waypoint (#13456)

Creates a list of vehicles that have orders to a given waypoint.
pull/14285/head
SamuXarick 2025-05-19 13:48:17 +01:00 committed by GitHub
parent 1b0fd0e6fd
commit ad3a34e9ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -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