Add: [Script] ScriptVehicleList_Waypoint (#13456)

Creates a list of vehicles that have orders to a given waypoint.
This commit is contained in:
SamuXarick
2025-05-19 13:48:17 +01:00
committed by GitHub
parent 1b0fd0e6fd
commit ad3a34e9ef
4 changed files with 32 additions and 0 deletions

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