Change: [Script] ScriptVehicleList_Station accepts an optional VehicleType parameter (#14260)

This commit is contained in:
Loïc Guilloux
2025-05-13 16:41:23 +02:00
committed by GitHub
parent 87fa1e41d5
commit c16d5f3a8d
6 changed files with 71 additions and 5 deletions

View File

@@ -33,16 +33,36 @@ ScriptVehicleList::ScriptVehicleList(HSQUIRRELVM vm)
);
}
ScriptVehicleList_Station::ScriptVehicleList_Station(StationID station_id)
ScriptVehicleList_Station::ScriptVehicleList_Station(HSQUIRRELVM vm)
{
EnforceDeityOrCompanyModeValid_Void();
int nparam = sq_gettop(vm) - 1;
if (nparam < 1 || nparam > 2) throw sq_throwerror(vm, "wrong number of parameters");
SQInteger sqstationid;
if (SQ_FAILED(sq_getinteger(vm, 2, &sqstationid))) {
throw sq_throwerror(vm, "parameter 1 must be an integer");
}
StationID station_id = static_cast<StationID>(sqstationid);
if (!ScriptBaseStation::IsValidBaseStation(station_id)) return;
bool is_deity = ScriptCompanyMode::IsDeity();
::CompanyID owner = ScriptObject::GetCompany();
::VehicleType type = VEH_INVALID;
if (nparam == 2) {
SQInteger sqtype;
if (SQ_FAILED(sq_getinteger(vm, 3, &sqtype))) {
throw sq_throwerror(vm, "parameter 2 must be an integer");
}
if (sqtype < ScriptVehicle::VT_RAIL || sqtype > ScriptVehicle::VT_AIR) return;
type = static_cast<::VehicleType>(sqtype);
}
FindVehiclesWithOrder(
[is_deity, owner](const Vehicle *v) { return is_deity || v->owner == owner; },
[is_deity, owner, type](const Vehicle *v) { return (is_deity || v->owner == owner) && (type == VEH_INVALID || v->type == type); },
[station_id](const Order *order) { return (order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station_id; },
[this](const Vehicle *v) { this->AddItem(v->index.base()); }
);