Change: [Script] ScriptVehicleList_Station accepts an optional VehicleType parameter (#14260)
This commit is contained in:
@@ -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()); }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user