mirror of https://github.com/OpenTTD/OpenTTD
Change: [Script] ScriptVehicleList_Station accepts an optional VehicleType parameter (#14260)
parent
87fa1e41d5
commit
c16d5f3a8d
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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()); }
|
||||
);
|
||||
|
|
|
@ -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 */
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue