1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Implement function to retrieve all active vehicles.

This commit is contained in:
Sandu Liviu Catalin 2016-03-26 18:17:38 +02:00
parent aeba86bddf
commit b5215b38e3

View File

@ -1253,6 +1253,7 @@ static const Object & Vehicle_FindByID(Int32 id)
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static const Object & Vehicle_FindByTag(CSStr tag)
{
// Perform a validity check on the specified tag
@ -1276,6 +1277,35 @@ static const Object & Vehicle_FindByTag(CSStr tag)
return NullObject();
}
// ------------------------------------------------------------------------------------------------
static Array Vehicle_FindActive()
{
// Remember the initial stack size
StackGuard sg;
// Obtain the ends of the entity pool
Core::Vehicles::const_iterator itr = _Core->GetVehicles().cbegin();
Core::Vehicles::const_iterator end = _Core->GetVehicles().cend();
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
// Process each entity in the pool
for (; itr != end; ++itr)
{
// Is this entity instance active?
if (VALID_ENTITY(itr->mID))
{
// Push the script object on the stack
sq_pushobject(DefaultVM::Get(), (HSQOBJECT &)((*itr).mObj));
// Append the object at the back of the array
if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -1)))
{
STHROWF("Unable to append entity instance to the list");
}
}
}
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
}
// ================================================================================================
void Register_CVehicle(HSQUIRRELVM vm)
{
@ -1416,6 +1446,7 @@ void Register_CVehicle(HSQUIRRELVM vm)
// Static Functions
.StaticFunc(_SC("FindByID"), &Vehicle_FindByID)
.StaticFunc(_SC("FindByTag"), &Vehicle_FindByTag)
.StaticFunc(_SC("FindActive"), &Vehicle_FindActive)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Float32, Int32, Int32) >
(_SC("CreateEx"), &Vehicle_CreateEx)