diff --git a/regression/regression/main.nut b/regression/regression/main.nut index c349c9b9ba..bab4bde578 100644 --- a/regression/regression/main.nut +++ b/regression/regression/main.nut @@ -1021,6 +1021,28 @@ function Regression::Order() foreach (idx, val in list) { print(" " + idx + " => " + val); } + list = AIVehicleList_Station(3, AIVehicle.VT_ROAD); + print(" Count(): " + list.Count()); + list.Valuate(AIVehicle.GetLocation); + print(" Location ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + print(" foreach():"); + foreach (idx, val in list) { + print(" " + idx + " => " + val); + } + list = AIVehicleList_Station(3, AIVehicle.VT_RAIL); + print(" Count(): " + list.Count()); + list.Valuate(AIVehicle.GetLocation); + print(" Location ListDump:"); + for (local i = list.Begin(); !list.IsEnd(); i = list.Next()) { + print(" " + i + " => " + list.GetValue(i)); + } + print(" foreach():"); + foreach (idx, val in list) { + print(" " + idx + " => " + val); + } } function Regression::RailTypeList() diff --git a/regression/regression/result.txt b/regression/regression/result.txt index 28a22d4e78..a26d24a752 100644 --- a/regression/regression/result.txt +++ b/regression/regression/result.txt @@ -9698,6 +9698,14 @@ ERROR: IsEnd() is invalid as Begin() is never called GetStopLocation(): 1 --VehicleList_Station-- + Count(): 1 + Location ListDump: + 20 => 23596 + foreach(): + 20 => 23596 + Count(): 0 + Location ListDump: + foreach(): Count(): 1 Location ListDump: 20 => 23596 @@ -9767,9 +9775,9 @@ ERROR: IsEnd() is invalid as Begin() is never called --Valuate() with excessive CPU usage-- Your script made an error: excessive CPU usage in valuator function -*FUNCTION [unknown()] regression/main.nut line [2069] +*FUNCTION [unknown()] regression/main.nut line [2091] *FUNCTION [Valuate()] NATIVE line [-1] -*FUNCTION [Start()] regression/main.nut line [2070] +*FUNCTION [Start()] regression/main.nut line [2092] [id] 0 [this] TABLE @@ -9778,7 +9786,7 @@ Your script made an error: excessive CPU usage in valuator function [this] INSTANCE Your script made an error: excessive CPU usage in valuator function -*FUNCTION [Start()] regression/main.nut line [2070] +*FUNCTION [Start()] regression/main.nut line [2092] [Infinite] CLOSURE [list] INSTANCE diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index a3da2a077d..fac33894bb 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -32,6 +32,7 @@ * \li AIBridge::GetBridgeID renamed to AIBridge::GetBridgeType * \li AIWaypoint::GetWaypointID now returns the StationID of any type of waypoint * \li AIList instances can now be saved + * \li AIVehicleList_Station accepts an optional AIVehicle::VehicleType parameter * * \b 14.0 * diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 13498b62e4..581cf3dd22 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -32,6 +32,7 @@ * \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType * \li GSWaypoint::GetWaypointID now returns the StationID of any type of waypoint * \li GSList instances can now be saved + * \li GSVehicleList_Station accepts an optional GSVehicle::VehicleType parameter * * \b 14.0 * diff --git a/src/script/api/script_vehiclelist.cpp b/src/script/api/script_vehiclelist.cpp index 68113654e5..994c47756b 100644 --- a/src/script/api/script_vehiclelist.cpp +++ b/src/script/api/script_vehiclelist.cpp @@ -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(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()); } ); diff --git a/src/script/api/script_vehiclelist.hpp b/src/script/api/script_vehiclelist.hpp index ad4b3cb0ef..d16edeabd4 100644 --- a/src/script/api/script_vehiclelist.hpp +++ b/src/script/api/script_vehiclelist.hpp @@ -58,11 +58,25 @@ public: */ class ScriptVehicleList_Station : public ScriptList { public: +#ifdef DOXYGEN_API /** * @param station_id The station to get the list of vehicles from, which have orders to it. * @pre ScriptBaseStation::IsValidBaseStation(station_id) */ ScriptVehicleList_Station(StationID station_id); + + /** + * @param station_id The station to get the list of vehicles from, which have orders to it. + * @param vehicle_type The VehicleType to get the list of vehicles for. + * @pre ScriptBaseStation::IsValidBaseStation(station_id) + */ + ScriptVehicleList_Station(StationID station_id, ScriptVehicle::VehicleType vehicle_type); +#else + /** + * The constructor wrapper from Squirrel. + */ + ScriptVehicleList_Station(HSQUIRRELVM vm); +#endif /* DOXYGEN_API */ }; /**